Canvas
-
class Canvas
User-facing drawing API.
Canvas provides high-level drawing commands that are recorded through a Device. Use save()/restore() for state management and clipRect() for clipping.
Public Functions
-
explicit Canvas(Device *device)
Construct a Canvas that records into a device.
- Parameters:
device – The device to record drawing commands into.
-
void clipRect(Rect r)
Intersect the current clip with a rectangle.
- Parameters:
r – The clipping rectangle.
Draw an image at the given position (alpha-blended).
- Parameters:
image – Shared pointer to the image.
x – X position.
y – Y position.
-
void drawLine(Point p1, Point p2, Color c, f32 width = 1.0f)
Draw a line between two points.
- Parameters:
p1 – Start point.
p2 – End point.
c – Line color.
width – Line width (default 1.0).
-
void drawPolyline(const Point *pts, i32 count, Color c, f32 width = 1.0f)
Draw a connected series of line segments.
- Parameters:
pts – Array of vertices.
count – Number of points.
c – Line color.
width – Line width (default 1.0).
-
void drawText(Point p, std::string_view text, Color c)
Draw text at the given position.
- Parameters:
p – Position of the text baseline.
text – UTF-8 text to draw.
c – Text color.
-
void fillRect(Rect r, Color c)
Fill a rectangle with a solid color.
- Parameters:
r – The rectangle to fill.
c – Fill color.
-
void restore()
Restore the most recently saved clip state.
-
void save()
Save the current clip state onto the stack.
-
explicit Canvas(Device *device)