Draw

From GMod Wiki

Jump to: navigation, search


"draw" is a library of functions used to draw HUD objects on the client's screen.

Note: the draw library is derived from surface.

Library Functions

NewerClient.png draw.DrawText
NewerClient.png draw.GetFontHeight
NewerClient.png draw.NoTexture
NewerClient.png draw.RoundedBox
NewerClient.png draw.RoundedBoxEx
NewerClient.png draw.SimpleText
NewerClient.png draw.SimpleTextOutlined
NewerClient.png draw.Text
NewerClient.png draw.TextShadow
NewerClient.png draw.TexturedQuad
NewerClient.png draw.WordBox

How to use it

These have to be called continuously to show up continuously (with every think/tick), so you can't just test them from the console. A convenient way to experiment with these would be to create a lua file (Let's call it cl_test.lua) in the garrysmod\lua directory, first we create a simple function from the draw table to draw something, then we add the function to the Gamemode.HUDPaint hook. The file's contents should look something like this:

function TestDrawHud()
	draw.WordBox( 25, 50, 50, "Hello World","Default",Color(50,50,75,100),Color(255,255,255,255))
	-- The functions you are messing around with go here
end
hook.Add("HUDPaint", "HUD_TEST", TestDrawHud)
-- Always leave a blank line at the end of the script
 


Now you have your code, But it still wont show up. Here is how you fix it. Type this into the console:


bind \ "lua_openscript_cl cl_test.lua"

Now, every time you press the key you bound the command to (if unchanged it's backslash (\)), the file (cl_test.lua) will reload and override the preexisting hook. To edit the experimental code, just Alt+Tab to the text editor, edit the text, save, go back to Garry's Mod, and press the key you bound that command to. If there are no errors, the HUD should immediately refresh to show you the effects of the updated test script.


Additional Notes and Information

So, if you use any Draw function that requires to set color or font, you have to set color or font again if you use Surface after Draw.

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox