Garry's Mod Wiki

draw.WordBox

draw.WordBox

  number, number draw.WordBox( number bordersize, number x, number y, string text, string font, table boxcolor, table textcolor, number xalign = TEXT_ALIGN_LEFT, number yalign = TEXT_ALIGN_TOP )

Description

Draws a rounded box with text in it.

This is a rendering function that requires a 2d rendering context.

This means that it will only work in 2d Rendering Hooks.

Arguments

1 number bordersize
Size of border, should be multiple of 2. Ideally this will be 8 or 16.
2 number x
The X Coordinate.
3 number y
The Y Coordinate.
4 string text
Text to draw.
5 string font
Font to draw in. See surface.CreateFont to create your own, or here for a list of default fonts.
6 table boxcolor
The box color. Uses the Color.
7 table textcolor
The text color. Uses the Color.
8 number xalign = TEXT_ALIGN_LEFT
The alignment of the X coordinate using Enums/TEXT_ALIGN.
9 number yalign = TEXT_ALIGN_TOP
The alignment of the Y coordinate using Enums/TEXT_ALIGN.

Returns

1 number
The width of the word box.
2 number
The height of the word box.

Example

Draws several boxes showing the effect of the alignment arguments.

hook.Add( "HUDPaint", "HUDPaint_DrawABox2", function() surface.SetDrawColor( Color( 255, 255, 255 ) ) surface.DrawLine( 100, 50, 100, 250 ) draw.WordBox( 4, 100, 100, "Example word box", "DermaDefault", Color( 128, 128, 128 ), Color( 255, 255, 255 ) ) draw.WordBox( 4, 100, 150, "Example word box", "DermaDefault", Color( 128, 128, 128 ), Color( 255, 255, 255 ), TEXT_ALIGN_CENTER ) draw.WordBox( 4, 100, 200, "Example word box", "DermaDefault", Color( 128, 128, 128 ), Color( 255, 255, 255 ), TEXT_ALIGN_RIGHT ) surface.SetDrawColor( Color( 255, 255, 255 ) ) surface.DrawLine( 250, 150, 650, 150 ) draw.WordBox( 4, 300, 150, "Example word box", "DermaDefault", Color( 128, 128, 128 ), Color( 255, 255, 255 ), nil ) draw.WordBox( 4, 400, 150, "Example word box", "DermaDefault", Color( 128, 128, 128 ), Color( 255, 255, 255 ), nil, TEXT_ALIGN_CENTER ) draw.WordBox( 4, 500, 150, "Example word box", "DermaDefault", Color( 128, 128, 128 ), Color( 255, 255, 255 ), nil, TEXT_ALIGN_BOTTOM ) end )
Output:
image.png

Special Pages


Wikis

?

Render Time: 69ms

DB GetPage 36
Generate Html 16
SaveChanges (1) 5
Render Body 0
Render Sidebar 9