Enrollment 28.2.0
Loading...
Searching...
No Matches
ImageShape.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include <vector>
14
15namespace inno
16{
17
21 */
22 class ImageShapeAttributes : public Serializable
23 {
24 private:
25 static constexpr unsigned char DefaultThickness = 2;
26
27 public:
29 RGBA rgba;
31 unsigned char thickness = DefaultThickness;
32
33 ImageShapeAttributes(RGBA color, unsigned char lw) noexcept
34 : rgba(std::move(color))
35 , thickness(lw)
36 {
37 }
38
39 explicit ImageShapeAttributes(RGBA color) noexcept
40 : rgba(std::move(color))
41 {
42 }
43
44 explicit ImageShapeAttributes(RGB color) noexcept
45 : rgba(std::move(color))
46 {
47 }
49 void WriteTo(Writer& writer) const final
50 {
51 writer.Write("c", rgba);
52 writer.Write("t", thickness);
53 }
54
55 ImageShapeAttributes() = default;
56 virtual ~ImageShapeAttributes() = default;
59 ImageShapeAttributes& operator=(const ImageShapeAttributes&) = default;
60 ImageShapeAttributes& operator=(ImageShapeAttributes&&) = default;
61
62 bool operator==(const ImageShapeAttributes& c) const
63 {
64 return rgba == c.rgba && thickness == c.thickness;
65 }
66
67 bool operator!=(const ImageShapeAttributes& c) const
68 {
69 return !(*this == c);
70 }
71 };
72
73#if defined SWIGPYTHON || defined SWIGRUBY
74 // The Shapes class will be ignored for python and ruby binding.
75 // Swig is not able to generate binding correctly for inline static const members
76 // for python and ruby.
77 static const ImageShapeAttributes ShapesInnoBlue = ImageShapeAttributes(Colors::InnoBlue);
78 static const ImageShapeAttributes ShapesWhite = ImageShapeAttributes(Colors::White);
79 static const ImageShapeAttributes ShapesLightGray = ImageShapeAttributes(Colors::LightGray);
80#endif
81
85 */
86 class Shapes final
87 {
88 public:
89 // NOLINTNEXTLINE(fuchsia-statically-constructed-objects)
90 inline static const ImageShapeAttributes InnoBlue = ImageShapeAttributes(Colors::InnoBlue);
91 // NOLINTNEXTLINE(fuchsia-statically-constructed-objects)
92 inline static const ImageShapeAttributes White = ImageShapeAttributes(Colors::White);
93 // NOLINTNEXTLINE(fuchsia-statically-constructed-objects)
94 inline static const ImageShapeAttributes LightGray = ImageShapeAttributes(Colors::LightGray);
95
96 Shapes(const Shapes&) = delete;
97 Shapes(Shapes&&) = delete;
98 Shapes& operator=(const Shapes&) = delete;
99 Shapes& operator=(Shapes&&) = delete;
100 Shapes() = delete;
101 ~Shapes() = delete;
102 };
103
107 */
108 class ImageShapeDrawer
109 {
110 public:
116 virtual void DrawLine(const Line& line, const ImageShapeAttributes& attr) = 0;
122 virtual void DrawCircle(const Circle& circle, const ImageShapeAttributes& attr) = 0;
128 virtual void DrawRectangle(const Rectangle& rectangle, const ImageShapeAttributes& attr) = 0;
129
130 ImageShapeDrawer() = default;
131 ImageShapeDrawer(const ImageShapeDrawer&) = delete;
132 ImageShapeDrawer(ImageShapeDrawer&&) = delete;
133 ImageShapeDrawer& operator=(const ImageShapeDrawer&) = delete;
134 ImageShapeDrawer& operator=(ImageShapeDrawer&&) = delete;
135 virtual ~ImageShapeDrawer() = default;
136 };
137
141 */
142 class ImageShape
143 {
144 public:
149 virtual void DrawIn(ImageShapeDrawer& drawer) const = 0;
150
151 ImageShape() = default;
152 ImageShape(const ImageShape&) = delete;
153 ImageShape(ImageShape&&) = delete;
154 ImageShape& operator=(const ImageShape&) = delete;
155 ImageShape& operator=(ImageShape&&) = delete;
156 virtual ~ImageShape() = default;
157 };
158
162 */
163 class RectangleShape final : public ImageShape
164 {
165 public:
170 */
171 void DrawIn(ImageShapeDrawer& drawer) const final
172 {
173 drawer.DrawRectangle(rect, a);
174 }
175
180 */
182 : rect(std::move(rectangle))
183 , a(std::move(attr))
184 {
185 }
186
187 private:
188 Rectangle rect;
190 };
191
195 */
196 class RectanglesShape final : public ImageShape
197 {
198 public:
202 */
203 void DrawIn(ImageShapeDrawer& drawer) const final
204 {
205 for (const auto& r : rectangles)
206 {
207 auto rectangleShape = RectangleShape(r, a);
208 rectangleShape.DrawIn(drawer);
209 }
210 }
211
216 */
217 RectanglesShape(std::vector<Rectangle> r, ImageShapeAttributes attr)
218 : rectangles(std::move(r))
219 , a(std::move(attr))
220 {
221 }
222
223 private:
224 std::vector<Rectangle> rectangles;
226 };
227
231 */
232 class CircleShape final : public ImageShape
233 {
234 public:
238 */
239 void DrawIn(ImageShapeDrawer& drawer) const final
240 {
241 drawer.DrawCircle(circ, a);
242 }
243
248 */
250 : circ(std::move(circle))
251 , a(std::move(attr))
252 {
253 }
254
255 private:
256 Circle circ;
258 };
259
263 */
264 class LineShape final : public ImageShape
265 {
266 public:
270 */
271 void DrawIn(ImageShapeDrawer& drawer) const final
272 {
273 drawer.DrawLine(ln, a);
274 }
275
280 */
282 : ln(std::move(line))
283 , a(std::move(attr))
284 {
285 }
286
287 private:
288 Line ln;
290 };
291} // namespace inno
CircleShape(Circle circle, ImageShapeAttributes attr)
Constructor sets given circle for drawing.
Definition ImageShape.h:248
void DrawIn(ImageShapeDrawer &drawer) const final
It draws circle in ImageShapeDrawer.
Definition ImageShape.h:238
It holds circle dimensions.
Definition ImageAttribute.h:691
It holds shape attributes such as color and line width.
Definition ImageShape.h:22
void WriteTo(Writer &writer) const final
Write itself into writer.
Definition ImageShape.h:48
unsigned char thickness
Line thickness in pixels.
Definition ImageShape.h:30
RGBA rgba
RGBA color.
Definition ImageShape.h:28
It is used by ImageShape to draw its shape.
Definition ImageShape.h:108
virtual void DrawLine(const Line &line, const ImageShapeAttributes &attr)=0
Draws line.
virtual void DrawRectangle(const Rectangle &rectangle, const ImageShapeAttributes &attr)=0
Draws rectangle.
virtual void DrawCircle(const Circle &circle, const ImageShapeAttributes &attr)=0
Draws circle.
virtual void DrawIn(ImageShapeDrawer &drawer) const =0
It draws shape in ImageShapeDrawer.
void DrawIn(ImageShapeDrawer &drawer) const final
It draws line in ImageShapeDrawer.
Definition ImageShape.h:270
LineShape(Line line, ImageShapeAttributes attr)
Constructor sets given line for drawing.
Definition ImageShape.h:280
It holds line points.
Definition ImageAttribute.h:615
It holds RGB color with transparency.
Definition ImageAttribute.h:908
It holds rectangle and draws it.
Definition ImageShape.h:163
RectangleShape(Rectangle rectangle, ImageShapeAttributes attr)
Constructor sets given rectangle for drawing.
Definition ImageShape.h:180
void DrawIn(ImageShapeDrawer &drawer) const final
It draws rectangle in ImageShapeDrawer.
Definition ImageShape.h:170
It holds rectangle vertexes, width, height.
Definition ImageAttribute.h:357
RectanglesShape(std::vector< Rectangle > r, ImageShapeAttributes attr)
Construct a new Rectangles object.
Definition ImageShape.h:216
void DrawIn(ImageShapeDrawer &drawer) const final
It draws all rectangles at once in ImageShapeDrawer.
Definition ImageShape.h:202
Provides interface for serialization of all classes.
Definition Writer.h:164