-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGui.h
147 lines (114 loc) · 3.52 KB
/
Gui.h
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma once
enum button_states { BTN_IDLE = 0, BTN_HOVER, BTN_ACTIVE };
namespace gui
{
const float p2pX(const float perc, const sf::VideoMode& vm);
const float p2pY(const float perc, const sf::VideoMode& vm);
const unsigned calcCharSize(const sf::VideoMode& vm, const unsigned modifier = 150.f);
class Button
{
private:
short unsigned buttonState;
short unsigned id;
sf::RectangleShape shape;
sf::Font* font;
sf::Text text;
sf::Color textIdleColor;
sf::Color textHoverColor;
sf::Color textActiveColor;
sf::Color idleColor;
sf::Color hoverColor;
sf::Color activeColor;
sf::Color outlineIdleColor;
sf::Color outlineHoverColor;
sf::Color outlineActiveColor;
public:
Button(float x, float y, float width, float height,
sf::Font* font, std::string text, unsigned character_size,
sf::Color text_idle_color, sf::Color text_hover_color, sf::Color text_active_color,
sf::Color idle_color, sf::Color hover_color, sf::Color active_color,
sf::Color outline_idle_color = sf::Color::Transparent, sf::Color outline_hover_color = sf::Color::Transparent, sf::Color outline_active_color = sf::Color::Transparent,
short unsigned id = 0);
~Button();
// Accessors
const bool isPressed() const;
const std::string getText() const;
const short unsigned& getId() const;
// Modifiers
void setText(const std::string text);
void setId(const short unsigned id);
// Functions
void update(const sf::Vector2i& mousePosWindow);
void render(sf::RenderTarget& target);
};
class DropDownList {
private:
float keytime;
float keytimeMax;
sf::Font& font;
gui::Button* activeElement;
std::vector<gui::Button*> list;
bool showList;
public:
DropDownList(
float x, float y, float width, float height,
sf::Font& font, std::string list[],
unsigned nrOfElements, unsigned default_index = 0);
~DropDownList();
// Accessors
const unsigned short& getActiveElementId() const;
const bool getKeytime();
// Functions
void updateKeytime(const float& dt);
void update(const sf::Vector2i& mousePosWindow, const float& dt);
void render(sf::RenderTarget& target);
};
class TextureSelector {
private:
float keytime;
const float keytimeMax;
float gridSize;
bool active = false;
bool hidden;
gui::Button* hide_btn;
sf::RectangleShape bounds;
sf::Sprite sheet;
sf::Texture* textureSheet;
sf::RectangleShape selector;
sf::Vector2u mousePosGrid;
sf::IntRect textureRect;
public:
TextureSelector(float x, float y, float width, float height,
float gridSize, const sf::Texture* texture_sheet,
sf::Font& font, std::string text);
~TextureSelector();
// Accessors
const bool& getActive();
const sf::IntRect& getTextureRect() const;
const bool getKeytime();
// Functions
void updateKeytime(const float& dt);
void update(const sf::Vector2i& mousePosWindow, const float& dt);
void render(sf::RenderTarget& target);
};
class ProgressBar {
private:
std::string barString;
sf::Text text;
float maxWidth;
int maxValue;
sf::RectangleShape back;
sf::RectangleShape inner;
public:
ProgressBar(
float x, float y, float width, float height,
int max_value, sf::Color innerColor, unsigned character_size,
sf::VideoMode& vm, sf::Font* font = NULL);
~ProgressBar();
// Accessors
// Modifiers
// Functions
void update(const int current_value);
void render(sf::RenderTarget & target);
};
}