13#ifndef NSBACI_TYPES_DRAWINGTYPES_H
14#define NSBACI_TYPES_DRAWINGTYPES_H
37 constexpr Color() =
default;
38 constexpr Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255)
39 : r(red), g(green), b(blue), a(alpha) {}
41 constexpr bool operator==(
const Color& other)
const {
42 return r == other.r && g == other.g && b == other.b && a == other.a;
48inline constexpr Color BLACK{0, 0, 0};
49inline constexpr Color WHITE{255, 255, 255};
50inline constexpr Color RED{255, 0, 0};
51inline constexpr Color GREEN{0, 255, 0};
52inline constexpr Color BLUE{0, 0, 255};
53inline constexpr Color YELLOW{255, 255, 0};
54inline constexpr Color CYAN{0, 255, 255};
55inline constexpr Color MAGENTA{255, 0, 255};
56inline constexpr Color ORANGE{255, 165, 0};
57inline constexpr Color PINK{255, 192, 203};
58inline constexpr Color PURPLE{128, 0, 128};
59inline constexpr Color GRAY{128, 128, 128};
60inline constexpr Color LIGHT_GRAY{192, 192, 192};
61inline constexpr Color DARK_GRAY{64, 64, 64};
62inline constexpr Color BROWN{139, 69, 19};
74 Point(int32_t px, int32_t py) : x(px), y(py) {}
76 bool operator==(
const Point& other)
const {
77 return x == other.x && y == other.y;
80 Point operator+(
const Point& other)
const {
81 return Point(x + other.x, y + other.y);
84 Point operator-(
const Point& other)
const {
85 return Point(x - other.x, y - other.y);
98 Size(int32_t w, int32_t h) : width(w), height(h) {}
113 Circle(
Point c, int32_t r,
bool fill =
false)
114 : center(c), radius(r), filled(fill) {}
126 Rectangle() =
default;
127 Rectangle(
Point pos,
Size s,
bool fill =
false)
128 : position(pos), size(s), filled(fill) {}
129 Rectangle(int32_t x, int32_t y, int32_t w, int32_t h,
bool fill =
false)
130 : position(x, y), size(w, h), filled(fill) {}
141 Triangle() =
default;
143 : p1(a), p2(b), p3(c), filled(fill) {}
153 int32_t thickness = 1;
156 Line(
Point s,
Point e, int32_t t = 1) : start(s), end(e), thickness(t) {}
170 Ellipse(
Point c, int32_t rx, int32_t ry,
bool fill =
false)
171 : center(c), radiusX(rx), radiusY(ry), filled(fill) {}
182 explicit Pixel(
Point p) : position(p) {}
183 Pixel(int32_t x, int32_t y) : position(x, y) {}
193 int32_t fontSize = 12;
195 DrawText() =
default;
196 DrawText(
Point p, std::string text, int32_t size = 12)
197 : position(p), content(std::move(text)), fontSize(size) {}
203using Shape = std::variant<Circle, Rectangle, Triangle, Line, Ellipse, Pixel, DrawText>;
215 Drawable() =
default;
216 Drawable(
Shape s,
Color c,
bool vis =
true, int32_t z = 0)
217 : shape(std::move(s)), color(c), visible(vis), zIndex(z) {}
245 int32_t lineWidth = 1;
250 cmd.type = DrawCommandType::Clear;
251 cmd.color =
Color(255, 255, 255);
257 cmd.type = DrawCommandType::Clear;
264 cmd.type = DrawCommandType::SetColor;
271 cmd.type = DrawCommandType::SetPosition;
278 cmd.type = DrawCommandType::DrawShape;
279 cmd.shape = std::move(s);
286 cmd.type = DrawCommandType::Fill;
293 cmd.type = DrawCommandType::SetLineWidth;
294 cmd.lineWidth = width;
300 cmd.type = DrawCommandType::Refresh;
313 Color backgroundColor{255, 255, 255};
314 std::string title =
"NSBACI Canvas";
319enum class StandardPosition {
339 case StandardPosition::TopLeft:
341 case StandardPosition::TopCenter:
342 return Point(canvasSize.width / 2, 0);
343 case StandardPosition::TopRight:
344 return Point(canvasSize.width, 0);
345 case StandardPosition::CenterLeft:
346 return Point(0, canvasSize.height / 2);
347 case StandardPosition::Center:
348 return Point(canvasSize.width / 2, canvasSize.height / 2);
349 case StandardPosition::CenterRight:
350 return Point(canvasSize.width, canvasSize.height / 2);
351 case StandardPosition::BottomLeft:
352 return Point(0, canvasSize.height);
353 case StandardPosition::BottomCenter:
354 return Point(canvasSize.width / 2, canvasSize.height);
355 case StandardPosition::BottomRight:
356 return Point(canvasSize.width, canvasSize.height);
Type definitions namespace for nsbaci (runtime-specific).
Point resolvePosition(StandardPosition pos, Size canvasSize)
Resolve a standard position to actual coordinates.
Definition drawingTypes.h:337
std::variant< Circle, Rectangle, Triangle, Line, Ellipse, Pixel, DrawText > Shape
Variant type for all drawable shapes.
Definition drawingTypes.h:203
DrawCommandType
Types of drawing commands that can be executed.
Definition drawingTypes.h:226
Configuration for the drawing canvas.
Definition drawingTypes.h:311
RGB color representation with values from 0-255.
Definition drawingTypes.h:31
Represents a single drawing command to be executed.
Definition drawingTypes.h:240
2D point/position representation.
Definition drawingTypes.h:69
2D size representation.
Definition drawingTypes.h:93