-
Notifications
You must be signed in to change notification settings - Fork 2
/
shapes.h
99 lines (87 loc) · 3.11 KB
/
shapes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef SHAPES_H
#define SHAPES_H
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/xml/xml.h>
class Shape {
public:
virtual void draw(wxDC& dc) const = 0;
virtual void setPos(int left, int top) { this->left = left; this->top = top; }
virtual void setSize(int width, int height) { this->width = width; this->height = height; }
virtual void setEndPos(int left, int top) { this->width = left - this->left; this->height = top - this->top; }
virtual void setColor(const wxColour& color) { this->color = color; }
virtual wxXmlNode* toXML(wxXmlNode *root) const;
virtual const wxString typeAsString() const = 0;
virtual ~Shape() {}
protected:
Shape(int left, int top, int width, int height, const wxColour& color)
: left(left), top(top), width(width), height(height), color(color) {}
int left, top;
int width, height;
wxColour color;
};
class Line : public Shape {
public:
Line(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
const wxString typeAsString() const { return wxT("line"); }
};
class Triangle : public Shape {
public:
Triangle(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
const wxString typeAsString() const { return wxT("triangle"); }
};
class Rectangle : public Shape {
public:
Rectangle(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
const wxString typeAsString() const { return wxT("rectangle"); }
};
class Hexagon : public Shape {
public:
Hexagon(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
const wxString typeAsString() const { return wxT("hexagon"); }
};
class Octagon : public Shape {
public:
Octagon(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
const wxString typeAsString() const { return wxT("octagon"); }
};
class Circle : public Shape {
public:
Circle(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
const wxString typeAsString() const { return wxT("circle"); }
};
class Guy : public Shape {
public:
Guy(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
const wxString typeAsString() const { return wxT("guy"); }
};
class Text : public Shape {
public:
Text(int left, int top, int width, int height, const wxColour& color)
: Shape(left, top, width, height, color), text(wxT("")) {}
Text(int left, int top, int width, int height, const wxColour& color, const wxString& text)
: Shape(left, top, width, height, color) {}
void draw(wxDC& dc) const;
void setText(const wxString& text) { this->text = text; }
wxXmlNode* toXML(wxXmlNode *root) const;
const wxString typeAsString() const { return wxT("text"); }
private:
wxString text;
};
#endif