1
1
#include " Gui/Menu.hpp"
2
2
#include " Gui/Theme.hpp"
3
3
#include " Gui/Gui.hpp"
4
+ #include < SFML/Graphics.hpp>
4
5
5
6
6
- sf::Color mkcolor (const std::string& hexcolor)
7
+ sf::Color hex2color (const std::string& hexcolor)
7
8
{
8
9
sf::Color color = sf::Color::Black;
9
10
if (hexcolor.size () == 7 ) // #ffffff
@@ -21,26 +22,41 @@ sf::Color mkcolor(const std::string& hexcolor)
21
22
return color;
22
23
}
23
24
25
+ struct Theme
26
+ {
27
+ sf::Color backgroundColor;
28
+ std::string texturePath;
29
+ };
24
30
25
31
int main ()
26
32
{
33
+ Theme defaultTheme = {
34
+ hex2color (" #dddbde" ),
35
+ " demo/texture-default.png"
36
+ };
37
+
38
+ Theme win98Theme = {
39
+ hex2color (" #d4d0c8" ),
40
+ " demo/texture-win98.png"
41
+ };
42
+
27
43
// Create the main window
28
44
sf::RenderWindow app (sf::VideoMode (640 , 480 ), " SFML Widgets" , sf::Style ::Close);
29
45
30
46
gui::Menu menu (app);
31
47
menu.setPosition (10 , 10 );
32
48
33
49
gui::Theme::loadFont (" demo/tahoma.ttf" );
34
- gui::Theme::loadTexture (" demo/texture.png " );
50
+ gui::Theme::loadTexture (defaultTheme. texturePath );
35
51
gui::Theme::textSize = 11 ;
36
- gui::Theme::click.textColor = mkcolor (" #191B18" );
37
- gui::Theme::click.textColorHover = mkcolor (" #191B18" );
38
- gui::Theme::click.textColorFocus = mkcolor (" #000" );
39
- gui::Theme::input.textColor = mkcolor (" #000" );
40
- gui::Theme::input.textColorHover = mkcolor (" #000" );
41
- gui::Theme::input.textColorFocus = mkcolor (" #000" );
52
+ gui::Theme::click.textColor = hex2color (" #191B18" );
53
+ gui::Theme::click.textColorHover = hex2color (" #191B18" );
54
+ gui::Theme::click.textColorFocus = hex2color (" #000" );
55
+ gui::Theme::input.textColor = hex2color (" #000" );
56
+ gui::Theme::input.textColorHover = hex2color (" #000" );
57
+ gui::Theme::input.textColorFocus = hex2color (" #000" );
42
58
gui::Theme::PADDING = 2 .f ;
43
- gui::Theme::windowBgColor = mkcolor ( " #dddbde " ) ;
59
+ gui::Theme::windowBgColor = defaultTheme. backgroundColor ;
44
60
45
61
gui::HBoxLayout* hbox = menu.addHBoxLayout ();
46
62
gui::FormLayout* form = hbox->addFormLayout ();
@@ -67,7 +83,7 @@ int main()
67
83
68
84
// Slider for rotation
69
85
gui::Slider* sliderRotation = new gui::Slider ();
70
- sliderRotation->setQuantum (1 );
86
+ sliderRotation->setStep (1 );
71
87
sliderRotation->setCallback ([&]() {
72
88
text.setRotation (sliderRotation->getValue () * 360 / 100 .f );
73
89
pbar0->setValue (sliderRotation->getValue ());
@@ -125,14 +141,23 @@ int main()
125
141
sf::Texture imgbutton;
126
142
imgbutton.loadFromFile (" demo/themed-button.png" );
127
143
128
- gui::SpriteButton* customButton = new gui::SpriteButton (imgbutton, " Play game" );
129
-
130
- customButton->setTextSize (18 );
144
+ gui::SpriteButton* customButton = new gui::SpriteButton (imgbutton, " Play" );
145
+ customButton->setTextSize (20 );
131
146
form->addRow (" Custom button" , customButton);
132
147
133
148
gui::VBoxLayout* vbox = hbox->addVBoxLayout ();
134
149
vbox->addLabel (" This pannel is on the left" );
135
150
151
+ gui::OptionsBox<Theme>* themeBox = new gui::OptionsBox<Theme>();
152
+ themeBox->addItem (" Windows 98" , win98Theme);
153
+ themeBox->addItem (" Default" , defaultTheme);
154
+ themeBox->setCallback ([&]() {
155
+ const Theme& theme = themeBox->getSelectedValue ();
156
+ gui::Theme::loadTexture (theme.texturePath );
157
+ gui::Theme::windowBgColor = theme.backgroundColor ;
158
+ });
159
+ vbox->add (themeBox);
160
+
136
161
// Textbox
137
162
gui::HBoxLayout* hbox2 = vbox->addHBoxLayout ();
138
163
gui::TextBox* textbox3 = new gui::TextBox (100 );
@@ -174,7 +199,6 @@ int main()
174
199
{
175
200
// Send events to menu
176
201
menu.onEvent (event);
177
-
178
202
if (event.type == sf::Event::Closed)
179
203
app.close ();
180
204
}
0 commit comments