-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
120 lines (103 loc) · 3.04 KB
/
Menu.cpp
File metadata and controls
120 lines (103 loc) · 3.04 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
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
#include "stdafx.h"
#include "Menu.h"
// protected: Functions:
void Menu::initTexture(sf::Texture& texture, const std::string file_path)
{
if (!texture.loadFromFile(file_path))
{
std::string className = typeid(*this).name();
className.erase(0, 6);
std::cout << "ERROR::" << className << "::initTexture::Failed to load" << file_path << std::endl;
}
}
// Constructors and Destructor:
Menu::Menu(sf::VideoMode& video_mode, sf::Font& font)
: font(font)
{
//Background initialization
this->background.setSize
(
sf::Vector2f
(
static_cast<float>(video_mode.width),
static_cast<float>(video_mode.height)
)
);
this->background.setFillColor(sf::Color(20, 20, 20, 100));
// Container initialization
this->container.setSize
(
sf::Vector2f
(
// static_cast<float>(video_mode.width) / 4.f,
static_cast<float>(video_mode.width) / 3.f,
// static_cast<float>(video_mode.height) / 1.2f
static_cast<float>(video_mode.height)
)
);
this->container.setFillColor(sf::Color(0, 40, 80, 80));
this->container.setPosition
(
// (static_cast<float>(video_mode.width) / 2.f) - (this->container.getSize().x / 2.f),
// (static_cast<float>(video_mode.height) / 2.f) - (this->container.getSize().y / 2.f)
0.f, 0.f
);
// Text initialization
this->menuText.setFont(font);
this->menuText.setFillColor(sf::Color(100, 100, 100, 200));
this->menuText.setCharacterSize(gui::calculateCharSize(4.f, video_mode));
// this->menuText.setString("MENU");
this->menuText.setPosition
(
(this->container.getPosition().x + (this->container.getSize().x / 2.f)) - (this->menuText.getGlobalBounds().width / 2.f),
this->container.getPosition().y + (this->menuText.getGlobalBounds().height * 2.f)
);
// Logo
this->initTexture(this->logoTexture, "D:/PNG/Logo/128x128_2.png");
this->logoSprite.setTexture(this->logoTexture);
// this->logoSprite.setScale(1.f, 1.f);
this->logoSprite.setPosition
(
(this->container.getPosition().x + (this->container.getSize().x / 2.f)) - (this->logoSprite.getGlobalBounds().width / 2.f),
this->container.getPosition().y + (this->logoSprite.getGlobalBounds().height / 4.f)
);
}
Menu::~Menu()
{
// Deleting buttons
//auto it = this->buttons.begin();
std::map<const gui::ButtonName, gui::Button*>::iterator it;
for (it = this->buttons.begin(); it != this->buttons.end(); ++it)
{
delete it->second;
}
}
//Accessors:
std::map<const gui::ButtonName, gui::Button*>& Menu::getButtons()
{
return this->buttons;
}
//Functions:
const bool Menu::isButtonPressed(const gui::ButtonName name)
{
return this->buttons[name]->isPressed();
}
void Menu::addButton
(
const gui::ButtonName name,
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[name] = new gui::Button
(
x, y, width, height,
&this->font, text, char_size,
sf::Color::Transparent, sf::Color::Transparent, sf::Color::Transparent,
sf::Color(204, 204, 204), sf::Color(255, 235, 0), sf::Color(255, 100, 0)
);
}