-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathTheme.cpp
121 lines (93 loc) · 2.37 KB
/
Theme.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "Theme.hpp"
namespace gui
{
static sf::Cursor& getDefaultCursor()
{
static sf::Cursor cursor;
cursor.loadFromSystem(sf::Cursor::Arrow);
return cursor;
}
size_t Theme::textSize = 12;
Theme::Style Theme::click;
Theme::Style Theme::input;
sf::Color Theme::windowBgColor;
int Theme::borderSize = 1.f;
int Theme::minWidgetWidth = 86;
float Theme::PADDING = 1.f;
float Theme::MARGIN = 7.f;
sf::Keyboard::Key Theme::nextWidgetKey = sf::Keyboard::Down;
sf::Keyboard::Key Theme::previousWidgetKey = sf::Keyboard::Up;
sf::Font Theme::m_font;
sf::Texture Theme::m_texture;
sf::IntRect Theme::m_subrects[_TEXTURE_ID_COUNT];
sf::Cursor& Theme::cursor = getDefaultCursor();
bool Theme::loadFont(const std::string& filename)
{
return m_font.loadFromFile(filename);
}
bool Theme::loadTexture(const std::string& filename)
{
if (m_texture.loadFromFile(filename))
{
sf::IntRect subrect;
subrect.width = m_texture.getSize().x;
subrect.height = m_texture.getSize().y / _TEXTURE_ID_COUNT;
for (int i = 0; i < _TEXTURE_ID_COUNT; ++i)
{
m_subrects[i] = subrect;
subrect.top += subrect.height;
}
borderSize = subrect.width / 3;
return true;
}
return false;
}
const sf::Font& Theme::getFont()
{
return m_font;
}
const sf::Texture& Theme::getTexture()
{
return m_texture;
}
const sf::IntRect& Theme::getTextureRect(Box::Type type, State state)
{
TextureID id(BOX_DEFAULT);
switch (state)
{
case StateDefault:
id = type == Box::Click ? BOX_DEFAULT : BOX_INPUT_DEFAULT;
break;
case StateHovered:
id = type == Box::Click ? BOX_HOVERED : BOX_INPUT_DEFAULT;
break;
case StatePressed:
id = type == Box::Click ? BOX_PRESSED : BOX_INPUT_FOCUSED;
break;
case StateFocused:
id = type == Box::Click ? BOX_FOCUSED : BOX_INPUT_FOCUSED;
break;
}
return m_subrects[id];
}
const sf::IntRect& Theme::getCrossTextureRect()
{
return m_subrects[CROSS];
}
const sf::IntRect& Theme::getArrowTextureRect()
{
return m_subrects[ARROW];
}
const sf::IntRect& Theme::getProgressBarTextureRect()
{
return m_subrects[PROGRESS_BAR];
}
float Theme::getBoxHeight()
{
return getLineSpacing() + borderSize * 2 + PADDING * 2;
}
int Theme::getLineSpacing()
{
return m_font.getLineSpacing(textSize);
}
}