nsbaci 1.0
Loading...
Searching...
No Matches
drawingTypes.h
Go to the documentation of this file.
1
12
13#ifndef NSBACI_TYPES_DRAWINGTYPES_H
14#define NSBACI_TYPES_DRAWINGTYPES_H
15
16#include <cstdint>
17#include <memory>
18#include <string>
19#include <variant>
20
25namespace nsbaci::types {
26
31struct Color {
32 uint8_t r = 0;
33 uint8_t g = 0;
34 uint8_t b = 0;
35 uint8_t a = 255; // Alpha channel for transparency
36
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) {}
40
41 constexpr bool operator==(const Color& other) const {
42 return r == other.r && g == other.g && b == other.b && a == other.a;
43 }
44};
45
46// ============== Predefined Colors ==============
47namespace Colors {
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};
63} // namespace Colors
64
69struct Point {
70 int32_t x = 0;
71 int32_t y = 0;
72
73 Point() = default;
74 Point(int32_t px, int32_t py) : x(px), y(py) {}
75
76 bool operator==(const Point& other) const {
77 return x == other.x && y == other.y;
78 }
79
80 Point operator+(const Point& other) const {
81 return Point(x + other.x, y + other.y);
82 }
83
84 Point operator-(const Point& other) const {
85 return Point(x - other.x, y - other.y);
86 }
87};
88
93struct Size {
94 int32_t width = 0;
95 int32_t height = 0;
96
97 Size() = default;
98 Size(int32_t w, int32_t h) : width(w), height(h) {}
99};
100
101// ============== Shape Definitions ==============
102
107struct Circle {
108 Point center;
109 int32_t radius = 0;
110 bool filled = false;
111
112 Circle() = default;
113 Circle(Point c, int32_t r, bool fill = false)
114 : center(c), radius(r), filled(fill) {}
115};
116
121struct Rectangle {
122 Point position; // Top-left corner
123 Size size;
124 bool filled = false;
125
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) {}
131};
132
137struct Triangle {
138 Point p1, p2, p3;
139 bool filled = false;
140
141 Triangle() = default;
142 Triangle(Point a, Point b, Point c, bool fill = false)
143 : p1(a), p2(b), p3(c), filled(fill) {}
144};
145
150struct Line {
151 Point start;
152 Point end;
153 int32_t thickness = 1;
154
155 Line() = default;
156 Line(Point s, Point e, int32_t t = 1) : start(s), end(e), thickness(t) {}
157};
158
163struct Ellipse {
164 Point center;
165 int32_t radiusX = 0;
166 int32_t radiusY = 0;
167 bool filled = false;
168
169 Ellipse() = default;
170 Ellipse(Point c, int32_t rx, int32_t ry, bool fill = false)
171 : center(c), radiusX(rx), radiusY(ry), filled(fill) {}
172};
173
178struct Pixel {
179 Point position;
180
181 Pixel() = default;
182 explicit Pixel(Point p) : position(p) {}
183 Pixel(int32_t x, int32_t y) : position(x, y) {}
184};
185
190struct DrawText {
191 Point position;
192 std::string content;
193 int32_t fontSize = 12;
194
195 DrawText() = default;
196 DrawText(Point p, std::string text, int32_t size = 12)
197 : position(p), content(std::move(text)), fontSize(size) {}
198};
199
203using Shape = std::variant<Circle, Rectangle, Triangle, Line, Ellipse, Pixel, DrawText>;
204
209struct Drawable {
210 Shape shape;
211 Color color;
212 bool visible = true;
213 int32_t zIndex = 0; // For layering
214
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) {}
218};
219
220// ============== Drawing Commands ==============
221
226enum class DrawCommandType {
227 Clear, // Clear the canvas
228 SetColor, // Set current drawing color
229 SetPosition, // Set current drawing position
230 DrawShape, // Draw a shape
231 Fill, // Fill the canvas with current color
232 SetLineWidth, // Set line thickness
233 Refresh // Force refresh/redraw
234};
235
241 DrawCommandType type;
242 Color color; // For SetColor
243 Point position; // For SetPosition
244 Shape shape; // For DrawShape
245 int32_t lineWidth = 1; // For SetLineWidth
246
247 // Factory methods for convenience
248 static DrawCommand clear() {
249 DrawCommand cmd;
250 cmd.type = DrawCommandType::Clear;
251 cmd.color = Color(255, 255, 255); // Default white
252 return cmd;
253 }
254
255 static DrawCommand clearWithColor(Color c) {
256 DrawCommand cmd;
257 cmd.type = DrawCommandType::Clear;
258 cmd.color = c;
259 return cmd;
260 }
261
262 static DrawCommand setColor(Color c) {
263 DrawCommand cmd;
264 cmd.type = DrawCommandType::SetColor;
265 cmd.color = c;
266 return cmd;
267 }
268
269 static DrawCommand setPosition(Point p) {
270 DrawCommand cmd;
271 cmd.type = DrawCommandType::SetPosition;
272 cmd.position = p;
273 return cmd;
274 }
275
276 static DrawCommand drawShape(Shape s, Color c) {
277 DrawCommand cmd;
278 cmd.type = DrawCommandType::DrawShape;
279 cmd.shape = std::move(s);
280 cmd.color = c;
281 return cmd;
282 }
283
284 static DrawCommand fill(Color c) {
285 DrawCommand cmd;
286 cmd.type = DrawCommandType::Fill;
287 cmd.color = c;
288 return cmd;
289 }
290
291 static DrawCommand setLineWidth(int32_t width) {
292 DrawCommand cmd;
293 cmd.type = DrawCommandType::SetLineWidth;
294 cmd.lineWidth = width;
295 return cmd;
296 }
297
298 static DrawCommand refresh() {
299 DrawCommand cmd;
300 cmd.type = DrawCommandType::Refresh;
301 return cmd;
302 }
303};
304
305// ============== Canvas Configuration ==============
306
312 Size size{800, 600}; // Default canvas size
313 Color backgroundColor{255, 255, 255}; // Default white background
314 std::string title = "NSBACI Canvas";
315};
316
317// ============== Predefined Positions ==============
318// These are resolved at runtime based on canvas size
319enum class StandardPosition {
320 TopLeft,
321 TopCenter,
322 TopRight,
323 CenterLeft,
324 Center,
325 CenterRight,
326 BottomLeft,
327 BottomCenter,
328 BottomRight
329};
330
337inline Point resolvePosition(StandardPosition pos, Size canvasSize) {
338 switch (pos) {
339 case StandardPosition::TopLeft:
340 return Point(0, 0);
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);
357 default:
358 return Point(0, 0);
359 }
360}
361
362} // namespace nsbaci::types
363
364#endif // NSBACI_TYPES_DRAWINGTYPES_H
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