-
Notifications
You must be signed in to change notification settings - Fork 0
/
triangle.hpp
154 lines (126 loc) · 4.03 KB
/
triangle.hpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#pragma once
#include "config.hpp"
#include "vidget.hpp"
namespace sf
{
class TriangleShape : public sf::Shape
{
private:
sf::Vector2f radius_;
public:
explicit TriangleShape(const sf::Vector2f& size = sf::Vector2f(0, 0)) :
radius_(size.x * 1.2, size.y * 1.36)
{
update();
}
void setRadius(const sf::Vector2f& radius)
{
radius_ = radius;
update();
}
const sf::Vector2f& getRadius() const
{
return radius_;
}
virtual unsigned int getPointCount() const
{
return 3;
}
virtual sf::Vector2f getPoint(unsigned int index) const
{
static const float pi = 3.141592654f;
float angle = index * 2 * pi / getPointCount() - pi / 2;
float x = std::cos(angle) * radius_.x;
float y = std::sin(angle) * radius_.y;
return sf::Vector2f(radius_.x + x, radius_.y + y);
}
};
}
class triangle : public vidget
{
private:
sf::TriangleShape triangle_;
sf::Color colour_;
public:
triangle() :
vidget(),
colour_(255, 255, 255),
triangle_(sf::Vector2<float>(size_.x / 2, size_.y / 2))
{}
triangle(sf::Vector2<float>& point, sf::Vector2<float>& size, uint32_t& colour) :
vidget(point, size),
colour_(colour),
triangle_(sf::Vector2<float>(size_.x / 2, size_.y / 2))
{
triangle_.move(point_);
triangle_.setOutlineThickness(2.f);
triangle_.setOutlineColor(sf::Color(0, 0, 0));
triangle_.setFillColor(colour_);
}
triangle(sf::Vector2<float>& point, sf::Vector2<float>& size, uint8_t red, uint8_t green, uint8_t blue) :
vidget(point, size),
colour_(red, green, blue),
triangle_(sf::Vector2<float>(size_.x / 2, size_.y / 2))
{
triangle_.move(point_);
triangle_.setOutlineThickness(2.f);
triangle_.setOutlineColor(sf::Color(0, 0, 0));
triangle_.setFillColor(colour_);
}
triangle(float x, float y, float x_size, float y_size, uint32_t& colour) :
vidget(x, y, x_size, y_size),
colour_(colour),
triangle_(sf::Vector2<float>(size_.x / 2, size_.y / 2))
{
triangle_.move(point_);
triangle_.setOutlineThickness(2.f);
triangle_.setOutlineColor(sf::Color(0, 0, 0));
triangle_.setFillColor(colour_);
}
triangle(float x, float y, float x_size, float y_size, uint8_t red, uint8_t green, uint8_t blue) :
vidget(x, y, x_size, y_size),
colour_(red, green, blue),
triangle_(sf::Vector2<float>(size_.x / 2, size_.y / 2))
{
triangle_.move(point_);
triangle_.setOutlineThickness(2.f);
triangle_.setOutlineColor(sf::Color(0, 0, 0));
triangle_.setFillColor(colour_);
}
~triangle() = default;
triangle(const triangle& source)
{
point_ = source.point_;
size_ = source.size_;
colour_ = source.colour_;
triangle_ = source.triangle_;
}
virtual void operator=(const triangle& source)
{
point_ = source.point_;
size_ = source.size_;
colour_ = source.colour_;
triangle_ = source.triangle_;
}
void set_colour(uint8_t red, uint8_t green, uint8_t blue)
{
colour_.r = red;
colour_.g = green;
colour_.b = blue;
}
virtual bool is_pressed(sf::Vector2<int> mouse_pos)
{
if ((mouse_pos.x > point_.x) && (mouse_pos.x < point_.x + 2 * size_.x) &&
(mouse_pos.y > point_.y) && (mouse_pos.y < point_.y + 2 * size_.y))
return true;
return false;
}
virtual void draw(sf::RenderWindow& shell_) const
{
shell_.draw(triangle_);
}
virtual void action(draw_state& state)
{
state.current_tool = TRIANGLE;
}
};