surface.DrawRect

From GMod Wiki

Jump to: navigation, search
Function
Syntax surface.DrawRect( Number x, Number y, Number width, Number height )
Where is this used?
Description:
Draws a colored Rect, assuming the rest of its required data has been set.
Returns: nil
Part of Library: surface
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Surface.DrawRect]Surface.DrawRect [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionThis example adds draws a red rectangle 100 pixels wide, and 50 pixels tall, in the bottom left corner of the screen. To be used on a weapon HUD
Used onNewerClient.png
Code
function SWEP:DrawHUD()
	surface.SetDrawColor( 255, 0, 0, 255) --Red
	surface.DrawRect(0 , ScrH()-50, 100, 50 )
end
 
OutputN/A


DescriptionThis example draws a perfect circle on the screen
Used onNewerClient.png
Code
local centerx, centery = ScrW() / 2, ScrH() / 2
local radiusx, radiusy = 100, 100
hook.Add("HUDPaint", "DrawCircle", function()
	surface.SetDrawColor(Color(0, 255, 0, 255))
	for i = 0, math.pi * 2, 1 / math.max(radiusx, radiusy) do --double pi equals to a circle.
		surface.DrawRect( centerx + math.sin(i) * radiusx, centery + math.cos(i) * radiusy, 1, 1)
	end
end)
 
OutputN/A


Additional Notes

Note that the origin of the Rect is the (x,y), not the center. Also note that all these values are PIXELS, not a scale. (Unlike Gmod9 lua)

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox