January 26, 2021, 12:34:31 PM

### Author Topic: [bb] BevelRect by King Dave [ 1+ years ago ]  (Read 405 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] BevelRect by King Dave [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : BevelRect
Author : King Dave
Posted : 1+ years ago

Description : This function works like the Rect command, but allows you to have beveled corners.

Code :
Code: BlitzBasic
2. ;
3. ;       x - x position
4. ;       y - y position
5. ;       width - width in pixels from x
6. ;       height - height in pixels from y
7. ;       radius - radius of circles at corners (defaults to 15)
8. ;       fill - fill the center (defaults to true)
9.
10. Function BevelRect(x,y,w,h,r=15,f=1)
11.         Local ro,go,bo,img,buf,xo,yo
12.         If Not f
13.                 ro=ColorRed()
14.                 go=ColorGreen()
15.                 bo=ColorBlue()
16.                 img=CreateImage(w,h)
17.                 buf=GraphicsBuffer()
18.                 SetBuffer ImageBuffer(img)
19.                 xo=x
20.                 yo=y
21.                 x=0
22.                 y=0
23.         EndIf
24.         Oval x,y,r,r,1
25.         Oval x+w-r,y,r,r,1
26.         Oval x,y+h-r,r,r,1
27.         Oval x+w-r,y+h-r,r,r,1
28.         Rect x+(r/2),y,w-r,h,1
29.         Rect x,y+(r/2),w,h-r,1
30.         If Not f
31.                 Color 0,0,0
32.                 x=x+1
33.                 y=y+1
34.                 w=w-2
35.                 h=h-2
36.                 Oval x,y,r,r,1
37.                 Oval x+w-r,y,r,r,1
38.                 Oval x,y+h-r,r,r,1
39.                 Oval x+w-r,y+h-r,r,r,1
40.                 Rect x+(r/2),y,w-r,h,1
41.                 Rect x,y+(r/2),w,h-r,1
42.                 Color ro,go,bo
43.                 SetBuffer buf
44.                 DrawImage img,xo,yo
45.                 FreeImage img
46.         EndIf
47. End Function

Sauer(Posted 1+ years ago)

There is a slight error with this code, in that the non filled rects will always display as white, ignoring the current drawing color.  This is a fix, created by simply setting the color to ro,rg,rb within the first If Not f check:
Code: [Select]
`Function BevelRect(x,y,w,h,r=15,f=1);By King Dave, rect command with bevelled corners Local ro,go,bo,img,buf,xo,yo If Not f ro=ColorRed() go=ColorGreen() bo=ColorBlue() img=CreateImage(w,h) buf=GraphicsBuffer() SetBuffer ImageBuffer(img) xo=x yo=y x=0 y=0 Color ro,go,bo EndIf Oval x,y,r,r,1 Oval x+w-r,y,r,r,1 Oval x,y+h-r,r,r,1 Oval x+w-r,y+h-r,r,r,1 Rect x+(r/2),y,w-r,h,1 Rect x,y+(r/2),w,h-r,1 If Not f Color 0,0,0 x=x+1 y=y+1 w=w-2 h=h-2 Oval x,y,r,r,1 Oval x+w-r,y,r,r,1 Oval x,y+h-r,r,r,1 Oval x+w-r,y+h-r,r,r,1 Rect x+(r/2),y,w-r,h,1 Rect x,y+(r/2),w,h-r,1 Color ro,go,bo SetBuffer buf DrawImage img,xo,yo FreeImage img EndIfEnd Function`

_PJ_(Posted 1+ years ago)

That's so useful, actually :)Bevelled edges always look nicer! [/i]

SimplePortal 2.3.6 © 2008-2014, SimplePortal