-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPauseMenu.cpp
106 lines (85 loc) · 2.38 KB
/
PauseMenu.cpp
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
#include "stdafx.h"
#include "PauseMenu.h"
PauseMenu::PauseMenu(sf::VideoMode& vm, sf::Font& font)
: font(font)
{
// Init background
this->background.setSize(
sf::Vector2f(
static_cast<float>(vm.width),
static_cast<float>(vm.height)
)
);
this->background.setFillColor(sf::Color(20, 20, 20, 100));
// Init container
this->container.setSize(
sf::Vector2f(
static_cast<float>(vm.width) / 4.f,
static_cast<float>(vm.height) - gui::p2pY(7.f, vm)
)
);
this->container.setFillColor(sf::Color(20, 20, 20, 200));
this->container.setPosition(
static_cast<float>(vm.width) / 2.f - static_cast<float>(this->container.getSize().x) / 2.f,
gui::p2pY(7.5f, vm)
);
// Init text
this->menuText.setFont(font);
this->menuText.setFillColor(sf::Color(255, 255, 255, 200));
this->menuText.setCharacterSize(gui::calcCharSize(vm) * 4);
this->menuText.setString("PAUSED");
this->menuText.setPosition(
this->container.getPosition().x + (this->container.getSize().x / 2.f) - this->menuText.getGlobalBounds().width / 2.f,
this->container.getPosition().y + gui::p2pY(3.5f, vm)
);
}
PauseMenu::~PauseMenu()
{
auto it = this->buttons.begin();
for (; it != buttons.end(); ++it) {
delete it->second;
}
}
std::map<std::string, gui::Button*>& PauseMenu::getButtons()
{
return this->buttons;
}
// Functions
const bool PauseMenu::isButtonPressed(const std::string key)
{
return this->buttons[key]->isPressed();
}
void PauseMenu::addButton(const std::string key,
const float y,
const float width,
const float height,
const unsigned char_size, const std::string text)
{
float x = this->container.getPosition().x + this->container.getSize().x / 2.f - width / 2.f;
this->buttons[key] = new gui::Button(
x, y, width, height,
&this->font, text, char_size,
sf::Color(70, 70, 70, 200),
sf::Color(250, 250, 250, 250),
sf::Color(20, 20, 20, 50),
sf::Color(70, 70, 70, 0),
sf::Color(150, 150, 150, 0),
sf::Color(20, 20, 20, 0)
);
}
void PauseMenu::update(const sf::Vector2i& mousePosWindow)
{
for (auto& i : this->buttons)
{
i.second->update(mousePosWindow);
}
}
void PauseMenu::render(sf::RenderTarget & target)
{
target.draw(this->background);
target.draw(this->container);
for (auto& i : this->buttons) {
i.second->render(target);
}
target.draw(this->menuText);
}