DrawContext

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().

methodd:w() → number

Current screen width in pixels.

methodd:h() → number

Current screen height in pixels.

methodd:rect(x, y, w, h, r, g, b, a?) → nil

Fills a rectangle.

ParamTypeNotes
x, ynumberTop-left corner, in pixels.
w, hnumberWidth & height, in pixels.
r, g, bnumberColour channels, 0–255.
anumber (optional)Alpha 0–255. Defaults to 255 (opaque).
methodd:outline(x, y, w, h, r, g, b, a?) → nil

Draws a 1px rectangle outline.

ParamTypeNotes
x, ynumberTop-left corner, in pixels.
w, hnumberWidth & height, in pixels.
r, g, bnumberColour channels, 0–255.
anumber (optional)Alpha 0–255. Defaults to 255.
methodd:line(x1, y1, x2, y2, r, g, b, a?) → nil

Draws a line between two points.

ParamTypeNotes
x1, y1numberStart point, in pixels.
x2, y2numberEnd point, in pixels.
r, g, bnumberColour channels, 0–255.
anumber (optional)Alpha 0–255. Defaults to 255.
methodd:text(x, y, str, size, r, g, b, a?) → nil

Draws text with the built-in font.

ParamTypeNotes
x, ynumberTop-left of the text, in pixels.
strstringThe text to draw.
sizenumberText height in pixels (each glyph is ~size wide).
r, g, bnumberColour channels, 0–255.
anumber (optional)Alpha 0–255. Defaults to 255.
methodd:image(path, x, y, w, h) → boolean

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).

ParamTypeNotes
pathstringPath relative to the app folder, e.g. "addons/" .. MOD_NAME .. "/cart.png". Absolute paths and .. are refused.
x, ynumberTop-left corner, in pixels.
w, hnumberSize 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
One page of the MCCP modding reference. Every section is its own document; search covers all of them.