This function creates a rounded rectangle. The function input data are:
1: left X co-ordinate
2: top Y co-ordinate
3: right X co-ordinate
4: bottom Y co-ordinate
5: radius of rounded corner
6: border thickness
7: rgb red value of foreground colour
8: rgb green value of foreground colour
9: rgb blue value of foreground colour
10: Background on/off
11: rgb red value of background colour
12: rgb green value of background colour
13: rgb blue value of background colour
14: Bitmap which is copied to the new bitmap
15: The new bitmap on which the rectangle is temporarily drawn (must not exist)
16: Bitmap to which the rectangle is finally drawn
This is the function:
function MakeRoundedBox(x1,y1,x2,y2,cornrad,lthick,fr,fg,fb,boolbg,br,bg,bb,fbmp,nbmp,tbmp)
lthick#=lthick
bmpwidth=SCREEN WIDTH()
bmpheight=SCREEN HEIGHT()
create bitmap nbmp,bmpwidth,bmpheight
copy bitmap fbmp,nbmp
x1a=x1+cornrad
y1a=y1+cornrad
x2a=x2-cornrad
y2a=y2-cornrad
`background
if boolbg=1
ink rgb(br,bg,bb),0
box x1,y1a,x2,y2a
box x1a,y1,x2a,y2
for x=0 to cornrad
for y=0 to cornrad
if SQRT((x^2)+(y^2))<cornrad
dot x2a+x,y2a+y
dot x1a-x,y1a-y
dot x1a-x,y2a+y
dot x2a+x,y1a-y
endif
next y
next x
endif
`foreground
ink rgb(fr,fg,fb),0
for t=0 to lthick#-1
line x1a,y1+t,x2a,y1+t
line x1+t,y1a,x1+t,y2a
line x1a,y2-t,x2a,y2-t
line x2-t,y1a,x2-t,y2a
next t
for x=0 to cornrad
for y=0 to cornrad
if SQRT((x^2)+(y^2))>cornrad-(lthick#/2) and SQRT((x^2)+(y^2))<cornrad+(lthick#/2)
dot x2a+x,y2a+y
dot x1a-x,y1a-y
dot x1a-x,y2a+y
dot x2a+x,y1a-y
endif
next y
next x
copy bitmap nbmp,tbmp
endfunction
Example programme of how to call it:
cls
suspend for key
MakeRoundedBox(10,10,180,200,25,2,255,0,100,1,80,80,190,0,5,0)
MakeRoundedBox(89,140,389,172,18,4,69,107,82,1,180,180,30,0,5,0)
MakeRoundedBox(165,20,600,130,40,1,255,255,255,0,0,0,0,0,5,0)
suspend for key
end
function MakeRoundedBox(x1,y1,x2,y2,cornrad,lthick,fr,fg,fb,boolbg,br,bg,bb,fbmp,nbmp,tbmp)
lthick#=lthick
bmpwidth=SCREEN WIDTH()
bmpheight=SCREEN HEIGHT()
create bitmap nbmp,bmpwidth,bmpheight
copy bitmap fbmp,nbmp
x1a=x1+cornrad
y1a=y1+cornrad
x2a=x2-cornrad
y2a=y2-cornrad
`background
if boolbg=1
ink rgb(br,bg,bb),0
box x1,y1a,x2,y2a
box x1a,y1,x2a,y2
for x=0 to cornrad
for y=0 to cornrad
if SQRT((x^2)+(y^2))<cornrad
dot x2a+x,y2a+y
dot x1a-x,y1a-y
dot x1a-x,y2a+y
dot x2a+x,y1a-y
endif
next y
next x
endif
`foreground
ink rgb(fr,fg,fb),0
for t=0 to lthick#-1
line x1a,y1+t,x2a,y1+t
line x1+t,y1a,x1+t,y2a
line x1a,y2-t,x2a,y2-t
line x2-t,y1a,x2-t,y2a
next t
for x=0 to cornrad
for y=0 to cornrad
if SQRT((x^2)+(y^2))>cornrad-(lthick#/2) and SQRT((x^2)+(y^2))<cornrad+(lthick#/2)
dot x2a+x,y2a+y
dot x1a-x,y1a-y
dot x1a-x,y2a+y
dot x2a+x,y1a-y
endif
next y
next x
copy bitmap nbmp,tbmp
endfunction
And yeah I know the huge amount of variables is kind of overkill but I have wanted this for a few things now, so I wanted it to be as flexible as possible for any project I might need it in.
http://jamesmason01.googlepages.com/index.htm