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) {}
204 std::variant<Circle, Rectangle, Triangle, Line, Ellipse, Pixel, DrawText>;
216 Drawable() =
default;
217 Drawable(
Shape s,
Color c,
bool vis =
true, int32_t z = 0)
218 : shape(std::move(s)), color(c), visible(vis), zIndex(z) {}
246 int32_t lineWidth = 1;
251 cmd.type = DrawCommandType::Clear;
252 cmd.color =
Color(255, 255, 255);
258 cmd.type = DrawCommandType::Clear;
265 cmd.type = DrawCommandType::SetColor;
272 cmd.type = DrawCommandType::SetPosition;
279 cmd.type = DrawCommandType::DrawShape;
280 cmd.shape = std::move(s);
287 cmd.type = DrawCommandType::Fill;
294 cmd.type = DrawCommandType::SetLineWidth;
295 cmd.lineWidth = width;
301 cmd.type = DrawCommandType::Refresh;
314 Color backgroundColor{255, 255, 255};
315 std::string title =
"NSBACI Canvas";
320enum class StandardPosition {
340 case StandardPosition::TopLeft:
342 case StandardPosition::TopCenter:
343 return Point(canvasSize.width / 2, 0);
344 case StandardPosition::TopRight:
345 return Point(canvasSize.width, 0);
346 case StandardPosition::CenterLeft:
347 return Point(0, canvasSize.height / 2);
348 case StandardPosition::Center:
349 return Point(canvasSize.width / 2, canvasSize.height / 2);
350 case StandardPosition::CenterRight:
351 return Point(canvasSize.width, canvasSize.height / 2);
352 case StandardPosition::BottomLeft:
353 return Point(0, canvasSize.height);
354 case StandardPosition::BottomCenter:
355 return Point(canvasSize.width / 2, canvasSize.height);
356 case StandardPosition::BottomRight:
357 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:338
DrawCommandType
Types of drawing commands that can be executed.
Definition drawingTypes.h:227
std::variant< Circle, Rectangle, Triangle, Line, Ellipse, Pixel, DrawText > Shape
Variant type for all drawable shapes.
Definition drawingTypes.h:203
Configuration for the drawing canvas.
Definition drawingTypes.h:312
RGB color representation with values from 0-255.
Definition drawingTypes.h:31
Represents a single drawing command to be executed.
Definition drawingTypes.h:241
2D point/position representation.
Definition drawingTypes.h:69
2D size representation.
Definition drawingTypes.h:93