The Draw namespace contains all primitive drawing functions for rendering basic shapes and graphics. These functions provide the foundation for all higher-level UI widgets and graphics operations.
All drawing operations use 32-bit RGBA color values in the format 0xAABBGGRR.
Functions
fill()
void Draw::fill(uint32_t color)
Fills the entire canvas with a solid color.
32-bit RGBA color value (0xAABBGGRR format)
Draw::fill(Colors::Black); // Fill with black
Draw::fill(0xFF0000FF); // Fill with red
Draw::fill(0x80FFFFFF); // Fill with semi-transparent white
rect()
void Draw::rect(int x, int y, int width, int height, uint32_t color)
Draws a filled rectangle.
Rectangle width in pixels
Rectangle height in pixels
Draw::rect(100, 50, 200, 100, Colors::Blue);
roundedRect()
void Draw::roundedRect(int x, int y, int width, int height, int radius, uint32_t color)
Draws a filled rounded rectangle.
Rectangle width in pixels
Rectangle height in pixels
Draw::roundedRect(50, 50, 150, 75, 10, Colors::Green);
roundedRectBorder()
void Draw::roundedRectBorder(int x, int y, int width, int height, int radius, int borderWidth, uint32_t color)
Draws a rounded rectangle border/outline.
Rectangle width in pixels
Rectangle height in pixels
Border thickness in pixels
Draw::roundedRectBorder(10, 10, 100, 50, 5, 2, Colors::White);
circle()
void Draw::circle(int cx, int cy, int radius, uint32_t color)
Draws a filled circle.
Draw::circle(200, 150, 25, Colors::Red);
line()
void Draw::line(int x1, int y1, int x2, int y2, int thickness, uint32_t color)
Draws a line between two points.
Draw::line(0, 0, 100, 100, 3, Colors::Yellow);
Example Usage
Basic Shapes
// Clear background
Draw::fill(Colors::Black);
// Draw a red rectangle
Draw::rect(50, 50, 200, 100, Colors::Red);
// Draw a blue circle
Draw::circle(150, 100, 30, Colors::Blue);
// Draw a yellow line
Draw::line(0, 0, 300, 300, 2, Colors::Yellow);
Rounded UI Elements
// Draw a button background
Draw::roundedRect(100, 50, 120, 40, 8, Colors::Primary);
// Draw a button border
Draw::roundedRectBorder(100, 50, 120, 40, 8, 2, Colors::White);
class MyWidget : public Widget {
void render() override {
// Draw widget background
Draw::roundedRect(x_, y_, width_, height_, 10, backgroundColor_);
// Draw widget border
Draw::roundedRectBorder(x_, y_, width_, height_, 10, 2, borderColor_);
// Draw content
Draw::circle(x_ + width_/2, y_ + height_/2, 15, Colors::White);
}
};