methodd:w() → number
Current screen width in pixels.
The drawing surface d passed to an element's paint callback. Pixel coordinates; colors are separate r, g, b arguments (0–255) with optional a (default 255). Use d:w() / d:h() for responsive layout, like GMod's ScrW() / ScrH().
Current screen width in pixels.
Current screen height in pixels.
Fills a rectangle.
| Param | Type | Notes |
|---|---|---|
| x, y | number | Top-left corner, in pixels. |
| w, h | number | Width & height, in pixels. |
| r, g, b | number | Colour channels, 0–255. |
| a | number (optional) | Alpha 0–255. Defaults to 255 (opaque). |
Draws a 1px rectangle outline.
| Param | Type | Notes |
|---|---|---|
| x, y | number | Top-left corner, in pixels. |
| w, h | number | Width & height, in pixels. |
| r, g, b | number | Colour channels, 0–255. |
| a | number (optional) | Alpha 0–255. Defaults to 255. |
Draws a line between two points.
| Param | Type | Notes |
|---|---|---|
| x1, y1 | number | Start point, in pixels. |
| x2, y2 | number | End point, in pixels. |
| r, g, b | number | Colour channels, 0–255. |
| a | number (optional) | Alpha 0–255. Defaults to 255. |
Draws text with the built-in font.
| Param | Type | Notes |
|---|---|---|
| x, y | number | Top-left of the text, in pixels. |
| str | string | The text to draw. |
| size | number | Text height in pixels (each glyph is ~size wide). |
| r, g, b | number | Colour channels, 0–255. |
| a | number (optional) | Alpha 0–255. Defaults to 255. |
Draws a PNG or JPEG scaled into the given rectangle. Returns true if it drew, false if the image couldn't be loaded — check the result and fall back to text rather than assuming it worked. Images are loaded once and cached, so calling this every frame is cheap (the first call does the disk read).
| Param | Type | Notes |
|---|---|---|
| path | string | Path relative to the app folder, e.g. "addons/" .. MOD_NAME .. "/cart.png". Absolute paths and .. are refused. |
| x, y | number | Top-left corner, in pixels. |
| w, h | number | Size to scale the image to, in pixels. |
if not d:image("addons/" .. MOD_NAME .. "/logo.png", 20, 20, 64, 64) then
d:text(20, 20, "MyMod", 16, 230, 230, 240) -- fallback
end