> For the complete documentation index, see [llms.txt](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/ui/drawing.md).

# Drawing

`Draw` draws on the screen in GUI coordinates: `(0, 0)` is the top left, and the screen is `Draw.Width` x `Draw.Height` (the game's window, fullscreen or not). Coordinates are in units of the game's UI scale (`Draw.Scale`: its camera scale, 2 in a window around 1280x720), so mod UI is the size of the game's and its pixel art as crisp.

Draw from an element's `OnDraw` (see [Screens and elements](/stoneforgeteam-docs/ui/screens-and-elements.md)), from `context.DrawGui`, which runs every frame in the game's Draw GUI pass, over everything, or from `context.DrawHud`, with the game's HUD, under its windows (see [Layers](/stoneforgeteam-docs/ui/screens-and-elements.md#layers)):

```csharp
context.DrawGui += () =>
{
    if (!Gm.InGame)
        return;
    Draw.Panel(8, 8, 140, 24);
    Draw.Text(16, 14, $"Turn {Time.Turns}", Draw.White);
};
```

Drawing outside a draw pass does nothing.

| `Draw`                                                                 |                                                                                                                                      |
| ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `Panel(x, y, w, h, colour, alpha)`                                     | The game's menu background with its border.                                                                                          |
| `Frame(x, y, w, h, alpha)`                                             | The frame of the game's hover windows.                                                                                               |
| `Text(x, y, text, colour, halign, valign, alpha)`                      | Text as the game draws it, with a shadow. `TextWidth(text)`.                                                                         |
| `Text(x, y, text, colour, halign, valign, font, alpha)`                | In one of the game's fonts: `GameFont.Default` (names, descriptions, the log) or `GameFont.Digits` (numbers on bars, buttons' text). |
| `PlainText(x, y, text, colour, halign, valign, shadow)`                | Text in the font being drawn with, not the GUI's: a name over a unit in the world, say.                                              |
| `TextWrapped(x, y, text, width, colour)`                               | Wrapped at a width. `TextHeight(text, width)`.                                                                                       |
| `Rectangle(x1, y1, x2, y2, colour, alpha, outline)`                    | A filled rectangle, or its outline.                                                                                                  |
| `Circle(x, y, radius, colour, outline, alpha)`                         | A circle, filled or its outline.                                                                                                     |
| `Triangle(x1, y1, x2, y2, x3, y3, colour, alpha)`                      | A filled triangle.                                                                                                                   |
| `Line(x1, y1, x2, y2, colour, width, alpha)`                           | A line.                                                                                                                              |
| `Sprite(sprite, x, y, ...)`                                            | A game sprite (`Sprite.s_...`) or one of yours (`int`), scaled.                                                                      |
| `SpritePart(...)`                                                      | Part of a sprite, as the game draws its health bars.                                                                                 |
| `SpriteSliced(sprite, frame, x, y, w, h, cap)`                         | Stretched but for its ends (a button).                                                                                               |
| `SpriteNineSlice(sprite, frame, x, y, w, h, borders)`                  | 9-sliced to any size (a window frame).                                                                                               |
| `SpriteExt(sprite, frame, x, y, xscale, yscale, angle, colour, alpha)` | A sprite's frame as GameMaker draws one: scaled, turned, tinted.                                                                     |
| `SpriteWidth`, `SpriteHeight`, `SpriteOrigin`                          | A sprite's size in pixels; the point of it drawn at `(x, y)`, as a `Point`.                                                          |
| `SpriteExists`, `SpriteName`                                           | Whether a sprite exists; its name.                                                                                                   |

| Colours                                                                            |                                                     |
| ---------------------------------------------------------------------------------- | --------------------------------------------------- |
| `Draw.Rgb(r, g, b)`                                                                | A colour (0-255 each), as GameMaker stores them.    |
| `Draw.White`, `Draw.Black`                                                         |                                                     |
| `Draw.Muted`                                                                       | The game's muted text colour (hover texts, labels). |
| `Draw.PanelColour`                                                                 | The game's panel colour.                            |
| `AlignLeft`, `AlignCenter`, `AlignRight`, `AlignTop`, `AlignMiddle`, `AlignBottom` | For `Text`'s alignment.                             |

To draw in the game *world* rather than over the screen - next to the player, say - draw in an object's Draw event with a hook. See [Hooks](/stoneforgeteam-docs/gml-and-c-code/hooks.md#event-hooks).

For the keyboard and the mouse, see [Keyboard and mouse](/stoneforgeteam-docs/core-concepts/input.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/ui/drawing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
