-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangleTool.cpp
More file actions
41 lines (37 loc) · 1.31 KB
/
TriangleTool.cpp
File metadata and controls
41 lines (37 loc) · 1.31 KB
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
#include "TriangleTool.h"
void TriangleTool::onMousePressed(const sf::Vector2f& pos, sf::Mouse::Button btn) {
if (btn == sf::Mouse::Left) {
m_drawing = true;
m_start = pos;
m_current = pos;
}
}
void TriangleTool::onMouseReleased(const sf::Vector2f& pos, sf::Mouse::Button btn) {
if (btn == sf::Mouse::Left && m_drawing) {
m_drawing = false;
sf::ConvexShape tri;
tri.setPointCount(3);
tri.setPoint(0, { (m_start.x + pos.x) / 2.f, m_start.y });
tri.setPoint(1, { m_start.x, pos.y });
tri.setPoint(2, { pos.x, pos.y });
tri.setFillColor(sf::Color(0, 0, 0, 0));
tri.setOutlineColor(m_color);
tri.setOutlineThickness(m_thickness);
m_canvas->drawToCanvas(tri);
}
}
void TriangleTool::onMouseMoved(const sf::Vector2f& pos) {
if (m_drawing) m_current = pos;
}
void TriangleTool::drawPreview(sf::RenderWindow& win) {
if (!m_drawing) return;
sf::ConvexShape tri;
tri.setPointCount(3);
tri.setPoint(0, { (m_start.x + m_current.x) / 2.f, m_start.y });
tri.setPoint(1, { m_start.x, m_current.y });
tri.setPoint(2, { m_current.x, m_current.y });
tri.setFillColor(sf::Color(0, 0, 0, 0));
tri.setOutlineColor(m_color);
tri.setOutlineThickness(m_thickness);
m_canvas->drawPreview(win, tri);
}