A) When I am using examinemouse(), I always have the problem of the mouse disappearing, and not being able to leave the window boundaries. Is it possible to correct these?
B) Would there happen to be a method to draw a smooth circle, or would I have to make an image?
Mouse / Window Boundaries and Smooth Circle
-
- Enthusiast
- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
-
- Enthusiast
- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
And in answer to your second question, here's something I wrote that will draw a smoothed ellipse. It will however, also anti-alias whatever is in the background square where it draws. But it should be fine to use on plain backgrounds, and maybe elsewhere too, you'd have to try it. Its making use of the fact that resizing in PB will anti-alias automatically. The example lets you compare it to a normally drawn ellipse, and I think it is an improvement.
Code: Select all
Procedure SmoothEllipse(ImNum,x,y,width,height,colour)
tempimg=CreateImage(#PB_any,width*4,height*4)
tempimg2=GrabImage(ImNum,#PB_Any,x,y,width,height)
UseImage(tempimg2)
ResizeImage(tempimg2,ImageWidth()*4,ImageHeight()*4)
UseImage(tempimg)
StartDrawing(ImageOutput())
DrawingMode(4)
UseImage(tempimg2)
DrawImage(ImageID(),0,0)
Ellipse(width*2,height*2,width*2,height*2,colour)
Ellipse(width*2,height*2,width*2-1,height*2-1,colour)
Ellipse(width*2,height*2,width*2-2,height*2-2,colour)
Ellipse(width*2,height*2,width*2-3,height*2-3,colour)
Ellipse(width*2,height*2,width*2-4,height*2-4,colour)
Ellipse(width*2,height*2,width*2-5,height*2-5,colour)
StopDrawing()
ResizeImage(tempimg,width,height)
UseImage(ImNum)
StartDrawing(ImageOutput())
UseImage(tempimg)
DrawImage(ImageID(),x,y)
StopDrawing()
FreeImage(tempimg)
FreeImage(tempimg2)
EndProcedure
OpenWindow(0,0,0,400,400,#PB_Window_SystemMenu | #PB_Window_ScreenCentered,"test")
UseJPEGImageDecoder()
CreateImage(1,400,400)
StartDrawing(ImageOutput())
DrawingMode(0)
Box(0,0,400,400,$0000FF)
DrawingMode(4)
For temp=0 To 400 Step 20
Line(0,temp,temp,-temp,$FF0000)
Line(temp,400,400-temp,temp-400)
Line(temp,0,400-temp,400-temp)
Line(0,temp,400-temp,400-temp)
Next
Ellipse(280,280,100,100,$00FF00)
StopDrawing()
SmoothEllipse(1,84,87,200,200,$00FF00)
CreateGadgetList(WindowID())
ImageGadget(0,0,0,400,400,UseImage(1))
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
-
- Enthusiast
- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
-
- Enthusiast
- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
Actually, if that other one doesnt work for you, I have one you can try. I decided I would try to write a set of anti-aliased shape commands. Here's my first attempt at an ellipse one. Two problems: firstly, its far too slow to be used in realtime and secondly, it produces bad results when the ellipse is too thin. I think I know how to fix this, and I will hopefully make a whole set of anti-aliased shape commands and release them, but in the meantime, here's something to use. Dont forget to turn off the debugger, or it really is very slow.
Code: Select all
Procedure.f Dist(x1,y1,x2,y2)
ProcedureReturn Sqr(Pow(x2-x1,2)+Pow(y2-y1,2))
EndProcedure
Procedure SmoothEllipse(ImNum,x,y,radiusX,radiusY,colour)
UseImage(ImNum)
StartDrawing(ImageOutput())
For tempx = -radiusX To RadiusX
For tempy = -radiusY To radiusY
rdist.f=Dist(0,0,tempx,tempy)
tempang.f=ATan(tempx/tempy)
pdist.f=Sqr((Pow(radiusY,2)*Pow(radiusX,2))/(Pow(radiusX,2)*Pow(Cos(tempang),2)+Pow(radiusY,2)*Pow(Sin(tempang),2)))
tempnear.f=(pdist-rdist-(1.5))/(1.5)
If tempnear>-1 And tempnear<1
xpos=tempx+x
ypos=tempy+y
tempred=Red(colour)+((Red(Point(xpos,ypos))-Red(colour))*(Abs(tempnear)))
tempblue=Blue(colour)+((Blue(Point(xpos,ypos))-Blue(colour))*(Abs(tempnear)))
tempgreen=Green(colour)+((Green(Point(xpos,ypos))-Green(colour))*(Abs(tempnear)))
If xpos>-1 And xpos<ImageWidth() And ypos>-1 And ypos<ImageHeight()
Plot(xpos,ypos,RGB(tempred,tempgreen,tempblue))
EndIf
EndIf
Next
Next
StopDrawing()
EndProcedure
OpenWindow(0,0,0,400,400,#PB_Window_SystemMenu | #PB_Window_ScreenCentered,"test")
CreateImage(0,400,400)
SmoothEllipse(0,190,190,170,130,$A0BF9F)
SmoothEllipse(0,200,200,30,30,$FF0000)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,400,400,UseImage(0))
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
I'm sorry, I would really prefer to use it in realtime, and I haven't been able to buy PB, so the debugger is forced. The other script will be much more useful to me. :-/GreenGiant wrote:Actually, if that other one doesnt work for you, I have one you can try. I decided I would try to write a set of anti-aliased shape commands. Here's my first attempt at an ellipse one. Two problems: firstly, its far too slow to be used in realtime and secondly, it produces bad results when the ellipse is too thin. I think I know how to fix this, and I will hopefully make a whole set of anti-aliased shape commands and release them, but in the meantime, here's something to use.Dont forget to turn off the debugger, or it really is very slow.Code: Select all
Procedure.f Dist(x1,y1,x2,y2) ProcedureReturn Sqr(Pow(x2-x1,2)+Pow(y2-y1,2)) EndProcedure Procedure SmoothEllipse(ImNum,x,y,radiusX,radiusY,colour) UseImage(ImNum) StartDrawing(ImageOutput()) For tempx = -radiusX To RadiusX For tempy = -radiusY To radiusY rdist.f=Dist(0,0,tempx,tempy) tempang.f=ATan(tempx/tempy) pdist.f=Sqr((Pow(radiusY,2)*Pow(radiusX,2))/(Pow(radiusX,2)*Pow(Cos(tempang),2)+Pow(radiusY,2)*Pow(Sin(tempang),2))) tempnear.f=(pdist-rdist-(1.5))/(1.5) If tempnear>-1 And tempnear<1 xpos=tempx+x ypos=tempy+y tempred=Red(colour)+((Red(Point(xpos,ypos))-Red(colour))*(Abs(tempnear))) tempblue=Blue(colour)+((Blue(Point(xpos,ypos))-Blue(colour))*(Abs(tempnear))) tempgreen=Green(colour)+((Green(Point(xpos,ypos))-Green(colour))*(Abs(tempnear))) If xpos>-1 And xpos<ImageWidth() And ypos>-1 And ypos<ImageHeight() Plot(xpos,ypos,RGB(tempred,tempgreen,tempblue)) EndIf EndIf Next Next StopDrawing() EndProcedure OpenWindow(0,0,0,400,400,#PB_Window_SystemMenu | #PB_Window_ScreenCentered,"test") CreateImage(0,400,400) SmoothEllipse(0,190,190,170,130,$A0BF9F) SmoothEllipse(0,200,200,30,30,$FF0000) CreateGadgetList(WindowID(0)) ImageGadget(0,0,0,400,400,UseImage(0)) Repeat Until WaitWindowEvent()=#PB_Event_CloseWindow