Hey guys, I was just wondering of anyone had a good working version of a draw.RoundedBoxOutlined? I tried the one below but it didn't work very well for me, the corners just stuffed up and large border sizes didn't change the edges of the box, only the corners.
[CODE]
local texOutlinedCorner = surface.GetTextureID( "gui/td/rounded-corner" )
/*---------------------------------------------------------
Name: RoundedBoxOutlined( bordersize, x, y, w, h, color, bordercol )
Desc: Draws a rounded box with a 1 pixel wide border - ideally bordersize will be 8 or 16
Usage: color is a table with r/g/b/a elements
---------------------------------------------------------*/
function draw.RoundedBoxOutlined( bordersize, x, y, w, h, color, bordercol )
x = math.Round( x )
y = math.Round( y )
w = math.Round( w )
h = math.Round( h )
draw.RoundedBox( bordersize, x, y, w, h, color )
surface.SetDrawColor( bordercol )
surface.SetTexture( texOutlinedCorner )
surface.DrawTexturedRectRotated( x + bordersize/2 , y + bordersize/2, bordersize, bordersize, 0 )
surface.DrawTexturedRectRotated( x + w - bordersize/2 , y + bordersize/2, bordersize, bordersize, 270 )
surface.DrawTexturedRectRotated( x + w - bordersize/2 , y + h - bordersize/2, bordersize, bordersize, 180 )
surface.DrawTexturedRectRotated( x + bordersize/2 , y + h -bordersize/2, bordersize, bordersize, 90 )
surface.DrawLine( x+bordersize, y, x+w-bordersize, y )
surface.DrawLine( x+bordersize, y+h-1, x+w-bordersize, y+h-1 )
surface.DrawLine( x, y+bordersize, x, y+h-bordersize )
surface.DrawLine( x+w-1, y+bordersize, x+w-1, y+h-bordersize )
end
[/CODE]
[QUOTE=Handsome Matt;43484916]Woweee, where did you find Tower Defense's old source code. IIRC you need to make sure bordersize is to a power of two, ideally 8 or 16 otherwise it will look like shit.[/QUOTE]As a matter of fact I got the code from you haha ([url]http://facepunch.com/showthread.php?t=833294[/url]) and I've tried 8 and 16 and also a bunch of other numbers and they all seem to pose the same problem. It ends up looking like a box with huge bulky corners and tiny thing edges between them.
[QUOTE=Handsome Matt;43485056]Oh. What texture are you using? Because I never provided the actual once we used: "texture is is a copy of "surface.GetTextureID( "gui/corner16" )" but outlined."
Also that 5 year old post, wowe.[/QUOTE]I'm using gui/corner16, I tried corner8 as well just to see if that would make any difference which it didn't. Also, I didn't realise that post was that old, my goodness. Why hasn't this function been added into Garry's Mod as part of the game, would be extremely useful if it were.
[QUOTE=Handsome Matt;43485114]Okay, what I said in my post was we used a modified version of gui/corner16 which was just an outline of it iirc. I don't have the file anymore however so I can't give you it.[/QUOTE]Uhh, I see. Thanks anyways, much appreciated. I'll leave this thread open overnight just in case anyone has anything to post and I'll check in the morning. Australian time :P Gnight.
I don't know if this is what you want to do, but it draws a box behind the main box giving a border effect. You can also define which borders you want on the Ex.
[lua]//
// Josh 'Acecool' Moser
//
function draw.RoundedBorderedBox( cornerDepth, x, y, w, h, color, borderSize, borderColor )
local _corners = ( isnumber( cornerDepth ) && cornerDepth > 0 && cornerDepth % 2 == 0 ) && true || false;
return draw.RoundedBorderedBoxEx( cornerDepth, x, y, w, h, color, borderSize, borderColor, _corners, _corners, _corners, _corners );
end
//
// Helper-function which gives a "border" effect by drawing two objects over eachother - Josh 'Acecool' Moser
//
function draw.RoundedBorderedBoxEx( cornerDepth, x, y, w, h, color, borderSize, borderColor, topleft, topright, bottomleft, bottomright )
draw.RoundedBoxEx( cornerDepth, x - borderSize, y - borderSize, w + borderSize * 2, h + borderSize * 2, borderColor, topleft, topright, bottomleft, bottomright );
draw.RoundedBoxEx( cornerDepth, x, y, w, h, color, topleft, topright, bottomleft, bottomright );
end[/lua]
/*
It's hooked up to the same standard, that you can take the first 5 args and copy/paste them from the top layer, from the previous 2
that were needed, simply copy and base, and it's done.
Example:
This:
draw.RoundedBorderedBox( 8, ScrW( ) / 2 - ( b + _textW ) / 2, -b, b + _textW, b + 25, Color( 50, 50, 50, 200 ), 1, Color( 250, 250, 250, 200 ) )
Is the same as:
draw.RoundedBox( 8, ScrW( ) / 2 - ( b + _textW ) / 2 - 1, -b + 1, b + _textW + 2, h or b + 25, Color( 250, 250, 250, 200 ) )
draw.RoundedBox( 8, ScrW( ) / 2 - ( b + _textW ) / 2, -b, b + _textW, h or b + 25, Color( 50, 50, 50, 200 ) )
By copying this straight into the new function, adding the dominant color, the border size and the border color:
8, ScrW( ) / 2 - ( b + _textW ) / 2, -b, b + _textW, h or b + 25
This:
draw.RoundedBorderedBox( 8, -b, -b, b*3 + _textW + 15, h or b + 25, Color( 50, 50, 50, 200 ), 1, Color( 250, 250, 250, 200 ) )
Is the same as:
draw.RoundedBox( 8, -b, -b + 1, b*3 + _textW + 15 + 1, h or b + 25, Color( 250, 250, 250, 200 ) )
draw.RoundedBox( 8, -b, -b, b*3 +_textW + 15, h or b + 25, Color( 50, 50, 50, 200 ) )
By copying this straight into the new function, adding the dominant color, the border size and the border color:
8, -b, -b, b*3 +_textW + 15, h or b + 25
This:
draw.RoundedBorderedBox( 8, ScrW( ) - w, -b, ScrW( ) - ( ScrW( ) - w - b ), h or b + 25, Color( 50, 50, 50, 200 ), 1, Color( 250, 250, 250, 200 ) )
Is the same as:
draw.RoundedBox( 8, ScrW( ) - w - 1, -b + 1, ScrW( ) - ( ScrW( ) - w - b ), h or b + 25, Color( 250, 250, 250, 200 ) )
draw.RoundedBox( 8, ScrW( ) - w, -b, ScrW( ) - ( ScrW( ) - w - b ), h or b + 25, Color( 50, 50, 50, 200 ) )
By copying this straight into the new function, adding the dominant color, the border size and the border color:
8, ScrW( ) - w, -b, ScrW( ) - ( ScrW( ) - w - b ), h or b + 25
*/
[QUOTE=Acecool;43496073]-snip-[/QUOTE] Thanks man! Much appreciated. :)
Sorry, you need to Log In to post a reply to this thread.