-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBar.cpp
More file actions
81 lines (65 loc) · 1.5 KB
/
Bar.cpp
File metadata and controls
81 lines (65 loc) · 1.5 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
70
71
72
73
74
75
76
77
78
79
80
#include "Bar.hpp"
////////////////////////////////////////////////////////////////////////////////////////////////
Bar::Bar() : focusedObject(nullptr)
{
}
Bar::Bar(const sf::Vector2f& position, const sf::Vector2f& size) :
UIEntity(position, size)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////
// BASE BAR
void Bar::draw(sf::RenderWindow& window) const
{
window.setView(view);
window.draw(background);
for (std::shared_ptr<UIObject> object : objects)
{
object->draw(window);
}
}
void Bar::reset()
{
if(focusedObject) focusedObject->reset();
}
void Bar::addObject(std::shared_ptr<UIObject> object)
{
objects.push_back(object);
}
void Bar::setBackground(const RoundedRect& background)
{
this->background = background;
}
void Bar::update(sf::RenderWindow& window, const sf::Vector2f& mousePos, const UserInput& userInput)
{
window.setView(view);
sf::Vector2f localPos = getLocalPos(window, mousePos);
if (this->contains(mousePos))
{
this->active = true;
if (focusedObject == nullptr)
{
for (std::shared_ptr<UIObject> object : objects)
{
if (object->contains(localPos))
{
focusedObject = object;
break;
}
}
}
}
if (focusedObject)
{
focusedObject->update(window, localPos, userInput);
if (!focusedObject->isActive())
{
focusedObject = nullptr;
}
}
else
{
this->active = false;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////