-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelector.cpp
More file actions
69 lines (55 loc) · 1.55 KB
/
Selector.cpp
File metadata and controls
69 lines (55 loc) · 1.55 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
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
#include "stdafx.h"
#include "Selector.h"
// Constructors and Destructor:
gui::Selector::Selector(const float grid_size)
: gridSize(grid_size)
{
this->selectorRectangle.setSize(sf::Vector2f(grid_size, grid_size));
this->selectorRectangle.setFillColor(sf::Color::Transparent);
this->selectorRectangle.setOutlineColor(sf::Color::Transparent);
this->selectorRectangle.setOutlineThickness(-4.f);
}
gui::Selector::~Selector()
{
}
const sf::Vector2f gui::Selector::getPosition() const
{
return this->selectorRectangle.getPosition();
}
const sf::Vector2f gui::Selector::getCenter() const
{
return sf::Vector2f
(
this->selectorRectangle.getPosition().x + this->selectorRectangle.getGlobalBounds().width / 2.f,
this->selectorRectangle.getPosition().y + this->selectorRectangle.getGlobalBounds().height / 2.f
);
}
const sf::FloatRect gui::Selector::getGlobalBounds() const
{
return this->selectorRectangle.getGlobalBounds();
}
void gui::Selector::setColor(sf::Color color)
{
this->selectorRectangle.setOutlineColor(color);
}
// Functions:
void gui::Selector::enable()
{
this->selectorRectangle.setOutlineColor(sf::Color::Green);
}
void gui::Selector::disable()
{
this->selectorRectangle.setOutlineColor(sf::Color::Red);
}
void gui::Selector::update(sf::Vector2i mouse_position_grid, const float& dt)
{
this->selectorRectangle.setPosition
(
static_cast<float>(mouse_position_grid.x) * this->gridSize,
static_cast<float>(mouse_position_grid.y) * this->gridSize
);
}
void gui::Selector::render(sf::RenderTarget* target)
{
target->draw(this->selectorRectangle);
}