Code: Select all
Const pi = Atn(1)*4
/'
Draw Rounded Rectangle
'/
Sub DrawCorner(dst As Any Ptr,x As Integer,y As Integer,r As Integer,clr As UInteger=&hFFFFFF,corner As Integer)
Dim As Single aStart,aEnd
Select Case corner
Case 0 'upper left
aStart=(pi/2):aEnd=pi
Case 1 'upper right
aStart=0:aEnd=(pi/2)
Case 2 'lower right
aStart=pi*2-(pi/2):aEnd=pi*2
Case 3 'lower left
aStart=pi:aEnd=pi*2-(pi/2)
End Select
Circle dst,(x,y),r,clr,aStart,aEnd
End Sub
Sub DrawRoundRectangle( dst As Any Ptr,_
x As Integer,_
y As Integer,_
dx As Integer,_
dy As Integer,_
clr As UInteger=&hFFFFFF,_
round As Integer,_
fill As Integer=0)
'Draw straight segments
Line dst,(x+round,y) -Step(dx-round*2,0),clr
Line dst,(x+round,y+dx)-Step(dx-round*2,0),clr
Line dst,(x,y+round) -Step(0,dy-round*2),clr
Line dst,(x+dx,y+round)-Step(0,dy-round*2),clr
'Draw arc segments
DrawCorner (dst,x+round,y+round,round,clr,0)
DrawCorner (dst,x+dx-round,y+round,round,clr,1)
DrawCorner (dst,x+dx-round,y+dy-round,round,clr,2)
DrawCorner (dst,x+round,y+dy-round,round,clr,3)
If fill Then
Paint dst,(x+round,y+round),clr
End If
End Sub
ScreenRes 640,480,32
DrawRoundRectangle (0,10,10,100,100,&hc0c0c0,20)
DrawRoundRectangle (0,200,10,100,100,&hFFFF00,10,1)
DrawRoundRectangle (0,100,120,80,80,&hFF0000,30,1)
sleep
Enjoy!
-Vince