Graphics Editor
 All Classes Namespaces Files Functions Variables Pages
canvas_primitives.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 namespace editor {
10  class Color {
11  public:
12  Color();
13 
14  Color(const Color& rhs);
15 
16  Color(uint8_t r_, uint8_t g_, uint8_t b_);
17 
18  private:
19  uint8_t r;
20  uint8_t g;
21  uint8_t b;
22  };
23 
27  struct Coordinate {
28  int x;
29  int y;
30  };
31 }
32 
33 namespace editor::figures {
38  public:
39  CanvasPrimitive() = default;
40 
41  explicit CanvasPrimitive(const Color& color_);
42 
43  CanvasPrimitive(const Color& color_, int z_index_);
44 
45  void move_to_z_index(int z_index_);
46 
47  virtual std::string get_representation() = 0;
48 
49  private:
50  Color color;
51  int z_index = 0;
52  };
53 
57  class Line : public CanvasPrimitive {
58  public:
59  Line(const Color& color_, const Coordinate& point1_, const Coordinate& point2_);
60 
61  std::string get_representation() override;
62 
63  private:
64  Coordinate point1;
65  Coordinate point2;
66  };
67 
71  class Circle : public CanvasPrimitive {
72  public:
73  Circle(const Color& color_, const Coordinate& center_, double radius_);
74 
75  std::string get_representation() override;
76 
77  private:
78  Coordinate center;
79  double radius;
80  };
81 
85  class Rectangle : public CanvasPrimitive {
86  public:
87  Rectangle(const Color& color_, const Coordinate& left_top_, const Coordinate& right_bottom_);
88 
89  std::string get_representation() override;
90 
91  private:
92  Coordinate left_top;
93  Coordinate right_bottom;
94  };
95 
99  class Polygon : public CanvasPrimitive {
100  public:
101  Polygon(const Color& color_);
102 
103  Polygon(const Color& color_, const std::vector<Coordinate>& points_);
104 
105  Polygon(const Color& color_, const Coordinate& start_point);
106 
107  void add_point(const Coordinate& point);
108 
109  std::string get_representation() override;
110 
111  private:
112  std::vector<Coordinate> points;
113  };
114 }
std::string get_representation() override
Definition: canvas_primitives.cpp:71
Definition: canvas_primitives.h:37
Definition: canvas_primitives.h:99
Circle(const Color &color_, const Coordinate &center_, double radius_)
Definition: canvas_primitives.cpp:37
std::string get_representation() override
Definition: canvas_primitives.cpp:40
std::string get_representation() override
Definition: canvas_primitives.cpp:28
Definition: canvas_primitives.h:71
Rectangle(const Color &color_, const Coordinate &left_top_, const Coordinate &right_bottom_)
Definition: canvas_primitives.cpp:48
void add_point(const Coordinate &point)
Definition: canvas_primitives.cpp:67
Color()
Definition: canvas_primitives.cpp:5
Line(const Color &color_, const Coordinate &point1_, const Coordinate &point2_)
Definition: canvas_primitives.cpp:25
int y
Definition: canvas_primitives.h:29
Definition: canvas_primitives.h:85
int x
Definition: canvas_primitives.h:28
Polygon(const Color &color_)
Definition: canvas_primitives.cpp:59
Definition: canvas_primitives.h:57
Definition: canvas_primitives.h:10
void move_to_z_index(int z_index_)
Definition: canvas_primitives.cpp:20
Definition: canvas_primitives.h:27
virtual std::string get_representation()=0
std::string get_representation() override
Definition: canvas_primitives.cpp:51