Is there a notable difference in using surface.DrawRect or draw.RoundedBox ? Is one better to use than the other? If so what makes it better or why? Also where is it better to use one or the other?
surface.DrawRect draws a solid rectangle of the current draw color, and draw.RoundedBox draws a rectangle using a texture as corners and filling in the wrest with surface.DrawRect.
So it's a matter of style and usage, rather than which is better than the other.
[code]--[[---------------------------------------------------------
Name: RoundedBox( bordersize, x, y, w, h, color )
Desc: Draws a rounded box - ideally bordersize will be 8 or 16
Usage: color is a table with r/g/b/a elements
-----------------------------------------------------------]]
function RoundedBox( bordersize, x, y, w, h, color )
return RoundedBoxEx( bordersize, x, y, w, h, color, true, true, true, true )
end
--[[---------------------------------------------------------
Name: RoundedBox( bordersize, x, y, w, h, color )
Desc: Draws a rounded box - ideally bordersize will be 8 or 16
Usage: color is a table with r/g/b/a elements
-----------------------------------------------------------]]
function RoundedBoxEx( bordersize, x, y, w, h, color, a, b, c, d )
x = math.Round( x )
y = math.Round( y )
w = math.Round( w )
h = math.Round( h )
surface.SetDrawColor( color.r, color.g, color.b, color.a )
-- Draw as much of the rect as we can without textures
surface.DrawRect( x+bordersize, y, w-bordersize*2, h )
surface.DrawRect( x, y+bordersize, bordersize, h-bordersize*2 )
surface.DrawRect( x+w-bordersize, y+bordersize, bordersize, h-bordersize*2 )
local tex = Tex_Corner8
if ( bordersize > 8 ) then tex = Tex_Corner16 end
surface.SetTexture( tex )
if ( a ) then
surface.DrawTexturedRectRotated( x + bordersize/2 , y + bordersize/2, bordersize, bordersize, 0 )
else
surface.DrawRect( x, y, bordersize, bordersize )
end
if ( b ) then
surface.DrawTexturedRectRotated( x + w - bordersize/2 , y + bordersize/2, bordersize, bordersize, 270 )
else
surface.DrawRect( x + w - bordersize, y, bordersize, bordersize )
end
if ( c ) then
surface.DrawTexturedRectRotated( x + bordersize/2 , y + h -bordersize/2, bordersize, bordersize, 90 )
else
surface.DrawRect( x, y + h - bordersize, bordersize, bordersize )
end
if ( d ) then
surface.DrawTexturedRectRotated( x + w - bordersize/2 , y + h - bordersize/2, bordersize, bordersize, 180 )
else
surface.DrawRect( x + w - bordersize, y + h - bordersize, bordersize, bordersize )
end
end[/code]
Sorry, you need to Log In to post a reply to this thread.