Code archives/Graphics/BevelRect

This code has been declared by its author to be Public Domain code.

Download source code

BevelRect by King Dave2002
This function works like the Rect command, but allows you to have beveled corners.
;BevelRect(x,y,width,height,radius,fill)
;
;	x - x position
;	y - y position
;	width - width in pixels from x
;	height - height in pixels from y
;	radius - radius of circles at corners (defaults to 15)
;	fill - fill the center (defaults to true)

Function BevelRect(x,y,w,h,r=15,f=1)
	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
	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
	EndIf
End Function

Comments

Sauer2010
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:




_PJ_2010
That's so useful, actually :)
Bevelled edges always look nicer!


Code Archives Forum