Garry's Mod Wiki

Revision Difference

surface.DrawRect#526617

<function name="DrawRect" parent="surface" type="libraryfunc"> <description> Draws a solid rectangle on the screen. <rendercontext hook="false" type="2D"></rendercontext> </description> <realm>Client and Menu</realm> <args> <arg name="x" type="number">The X integer co-ordinate.</arg> <arg name="y" type="number">The Y integer co-ordinate.</arg> <arg name="width" type="number">The integer width of the rectangle.</arg> <arg name="height" type="number">The integer height of the rectangle.</arg> </args> </function> <example> <description>Draws a white 100 by 100 rectangle, 25 pixels from the top left of the screen.</description> <code> hook.Add("HUDPaint", "MyRect", function() surface.SetDrawColor(255,255,255,255) surface.DrawRect(25, 25, 100, 100) end) </code> <output><image src="surface_drawrect.png"/></output> ⤶ </example>⤶ ⤶ <example>⤶ <description>Creates a transitional effect from top or bottom, where the alpha gets lower and lower (from the My Base Defence Gamemode Beta 2.56 source code)</description>⤶ <code>⤶ --- ...⤶ function draw.FadingBorder(width, height, xPos, yPos, heightShadowBox, opacity, oppositDirection)⤶ local maxAmountOfBars = (height - 1) / heightShadowBox * opacity⤶ ⤶ for i=0,maxAmountOfBars do⤶ local alpha⤶ if oppositDirection then⤶ -- Gradient from bottom => top⤶ alpha = math.ceil(( (255 / maxAmountOfBars) * i))⤶ else⤶ -- Gradient from top => bottom⤶ alpha = math.floor(255 - ( (255 / maxAmountOfBars) * i))⤶ end⤶ -- -⤶ local currDrawColor = surface.GetDrawColor()⤶ surface.SetDrawColor(currDrawColor.r, currDrawColor.g, currDrawColor.b, alpha)⤶ -- -⤶ surface.DrawRect(⤶ 0 + xPos,⤶ 0 + yPos + i * heightShadowBox,⤶ width,⤶ heightShadowBox⤶ )⤶ end⤶ end⤶ ⤶ --⤶ --- -⤶ -- -⤶ -- - - Paint some nice transition⤶ -- -⤶ fadingTransitionViewBuyBox = vgui.Create("DLabel", buyBoxMenu)⤶ fadingTransitionViewBuyBox:SetText("")⤶ fadingTransitionViewBuyBox:SetPos(0, 0)⤶ fadingTransitionViewBuyBox:SetSize(viewBuyBox:GetWide(), viewBuyBox:GetTall() + 36)⤶ fadingTransitionViewBuyBox:DockMargin(0, 0, 0, 0)⤶ fadingTransitionViewBuyBox:DockPadding(0, 0, 0, 0)⤶ fadingTransitionViewBuyBox.Paint = function(s, w, h)⤶ surface.SetDrawColor(15, 2, 29)⤶ -- -⤶ local height = 50⤶ local xPos = 12⤶ local yPos = 24⤶ ⤶ -- Top⤶ draw.FadingBorder(⤶ w - xPos * 2,⤶ height,⤶ xPos,⤶ yPos,⤶ 1,⤶ 0.8⤶ )⤶ -- Bottom⤶ draw.FadingBorder(⤶ w - xPos * 2,⤶ height,⤶ xPos,⤶ h - height,⤶ 1,⤶ 0.8,⤶ true⤶ )⤶ end⤶ </code>⤶ <output><image src="5598e/8d7df4a571228ae.png"/></output>⤶ <upload src="5598e/8d7df4a571228ae.png" size="282037" name="mybasedefence_beta256_buybox_menu.png" />⤶ </example>