The Battle for Wesnoth
1.19.5+dev
gui
widgets
menu_button.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2008 - 2024
3
by Mark de Wever <koraq@xs4all.nl>
4
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY.
12
13
See the COPYING file for more details.
14
*/
15
16
#pragma once
17
18
#include "
gui/core/widget_definition.hpp
"
19
#include "
gui/dialogs/drop_down_menu.hpp
"
20
#include "
gui/widgets/styled_widget.hpp
"
21
#include "
gui/widgets/selectable_item.hpp
"
22
23
namespace
gui2
24
{
25
namespace
implementation
26
{
27
struct
builder_menu_button;
28
}
29
30
// ------------ WIDGET -----------{
31
32
class
menu_button
:
public
styled_widget
,
public
selectable_item
33
{
34
public
:
35
explicit
menu_button
(
const
implementation::builder_menu_button
& builder);
36
37
/***** ***** ***** ***** Inherited ***** ***** ***** *****/
38
39
/** See @ref styled_widget::set_active. */
40
virtual
void
set_active
(
const
bool
active)
override
;
41
42
/** See @ref styled_widget::get_active. */
43
virtual
bool
get_active
()
const override
;
44
45
/** See @ref styled_widget::get_state. */
46
virtual
unsigned
get_state
()
const override
;
47
48
/***** ***** ***** setters / getters for members ***** ****** *****/
49
50
void
set_values
(
const
std::vector<::config>& values,
unsigned
selected
= 0);
51
52
void
set_selected
(
unsigned
selected
,
bool
fire_event
=
true
);
53
54
/** Inherited from selectable_item */
55
virtual
unsigned
get_value
()
const override
{
return
selected_
; }
56
57
/** Inherited from selectable_item */
58
virtual
void
set_value
(
unsigned
value,
bool
fire_event
=
false
)
override
{
set_selected
(value,
fire_event
); }
59
60
/** Inherited from selectable_item */
61
virtual
unsigned
num_states
()
const override
{
return
values_
.size(); }
62
63
/** Returns the value of the selected row */
64
std::string
get_value_string
()
const
65
{
66
return
values_
[
selected_
][
"label"
];
67
}
68
69
/** Returns the entire config object for the selected row. */
70
const ::config&
get_value_config
()
const
71
{
72
return
values_
[
selected_
];
73
}
74
75
void
set_keep_open
(
const
bool
keep_open)
76
{
77
keep_open_
= keep_open;
78
}
79
80
private
:
81
/**
82
* Possible states of the widget.
83
*
84
* Note the order of the states must be the same as defined in settings.hpp.
85
*/
86
enum
state_t
{
87
ENABLED
,
88
DISABLED
,
89
PRESSED
,
90
FOCUSED
,
91
};
92
93
void
set_state
(
const
state_t
state);
94
95
/**
96
* Current state of the widget.
97
*
98
* The state of the widget determines what to render and how the widget
99
* reacts to certain 'events'.
100
*/
101
state_t
state_
;
102
103
std::vector<::config>
values_
;
104
105
unsigned
selected_
;
106
107
bool
keep_open_
;
108
109
public
:
110
/** Static type getter that does not rely on the widget being constructed. */
111
static
const
std::string&
type
();
112
113
private
:
114
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
115
virtual
const
std::string&
get_control_type
()
const override
;
116
117
/***** ***** ***** signal handlers ***** ****** *****/
118
119
void
signal_handler_mouse_enter
(
const
event::ui_event
event,
bool
& handled);
120
121
void
signal_handler_mouse_leave
(
const
event::ui_event
event,
bool
& handled);
122
123
void
signal_handler_left_button_down
(
const
event::ui_event
event,
bool
& handled);
124
125
void
signal_handler_left_button_up
(
const
event::ui_event
event,
bool
& handled);
126
127
void
signal_handler_left_button_click
(
const
event::ui_event
event,
bool
& handled);
128
129
void
signal_handler_sdl_wheel_up
(
const
event::ui_event
event,
bool
& handled);
130
131
void
signal_handler_sdl_wheel_down
(
const
event::ui_event
event,
bool
& handled);
132
};
133
134
// }---------- DEFINITION ---------{
135
136
struct
menu_button_definition
:
public
styled_widget_definition
137
{
138
explicit
menu_button_definition
(
const
config
& cfg);
139
140
struct
resolution
:
public
resolution_definition
141
{
142
explicit
resolution
(
const
config
& cfg);
143
};
144
};
145
146
// }---------- BUILDER -----------{
147
148
namespace
implementation
149
{
150
151
struct
builder_menu_button
:
public
builder_styled_widget
152
{
153
public
:
154
explicit
builder_menu_button
(
const
config
& cfg);
155
156
using
builder_styled_widget::build
;
157
158
virtual
std::unique_ptr<widget>
build
()
const override
;
159
160
private
:
161
std::vector<::config>
options_
;
162
};
163
164
}
// namespace implementation
165
166
// }------------ END --------------
167
168
}
// namespace gui2
config
A config object defines a single node in a WML file, with access to child nodes.
Definition:
config.hpp:172
gui2::menu_button
Definition:
menu_button.hpp:33
gui2::menu_button::get_control_type
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
gui2::menu_button::set_state
void set_state(const state_t state)
Definition:
menu_button.cpp:91
gui2::menu_button::get_value_config
const ::config & get_value_config() const
Returns the entire config object for the selected row.
Definition:
menu_button.hpp:70
gui2::menu_button::selected_
unsigned selected_
Definition:
menu_button.hpp:105
gui2::menu_button::signal_handler_left_button_click
void signal_handler_left_button_click(const event::ui_event event, bool &handled)
Definition:
menu_button.cpp:136
gui2::menu_button::state_
state_t state_
Current state of the widget.
Definition:
menu_button.hpp:101
gui2::menu_button::set_selected
void set_selected(unsigned selected, bool fire_event=true)
Definition:
menu_button.cpp:200
gui2::menu_button::signal_handler_left_button_down
void signal_handler_left_button_down(const event::ui_event event, bool &handled)
Definition:
menu_button.cpp:115
gui2::menu_button::type
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
gui2::menu_button::signal_handler_mouse_leave
void signal_handler_mouse_leave(const event::ui_event event, bool &handled)
Definition:
menu_button.cpp:107
gui2::menu_button::set_value
virtual void set_value(unsigned value, bool fire_event=false) override
Inherited from selectable_item.
Definition:
menu_button.hpp:58
gui2::menu_button::signal_handler_left_button_up
void signal_handler_left_button_up(const event::ui_event event, bool &handled)
Definition:
menu_button.cpp:128
gui2::menu_button::get_value_string
std::string get_value_string() const
Returns the value of the selected row.
Definition:
menu_button.hpp:64
gui2::menu_button::set_values
void set_values(const std::vector<::config > &values, unsigned selected=0)
Definition:
menu_button.cpp:185
gui2::menu_button::signal_handler_mouse_enter
void signal_handler_mouse_enter(const event::ui_event event, bool &handled)
Definition:
menu_button.cpp:99
gui2::menu_button::menu_button
menu_button(const implementation::builder_menu_button &builder)
Definition:
menu_button.cpp:40
gui2::menu_button::get_value
virtual unsigned get_value() const override
Inherited from selectable_item.
Definition:
menu_button.hpp:55
gui2::menu_button::get_state
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition:
menu_button.cpp:86
gui2::menu_button::set_active
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition:
menu_button.cpp:74
gui2::menu_button::signal_handler_sdl_wheel_up
void signal_handler_sdl_wheel_up(const event::ui_event event, bool &handled)
Definition:
menu_button.cpp:161
gui2::menu_button::signal_handler_sdl_wheel_down
void signal_handler_sdl_wheel_down(const event::ui_event event, bool &handled)
Definition:
menu_button.cpp:173
gui2::menu_button::num_states
virtual unsigned num_states() const override
Inherited from selectable_item.
Definition:
menu_button.hpp:61
gui2::menu_button::state_t
state_t
Possible states of the widget.
Definition:
menu_button.hpp:86
gui2::menu_button::ENABLED
@ ENABLED
Definition:
menu_button.hpp:87
gui2::menu_button::FOCUSED
@ FOCUSED
Definition:
menu_button.hpp:90
gui2::menu_button::PRESSED
@ PRESSED
Definition:
menu_button.hpp:89
gui2::menu_button::DISABLED
@ DISABLED
Definition:
menu_button.hpp:88
gui2::menu_button::set_keep_open
void set_keep_open(const bool keep_open)
Definition:
menu_button.hpp:75
gui2::menu_button::get_active
virtual bool get_active() const override
See styled_widget::get_active.
Definition:
menu_button.cpp:81
gui2::menu_button::values_
std::vector<::config > values_
Definition:
menu_button.hpp:103
gui2::menu_button::keep_open_
bool keep_open_
Definition:
menu_button.hpp:107
gui2::selectable_item
Small abstract helper class.
Definition:
selectable_item.hpp:33
gui2::styled_widget
Definition:
styled_widget.hpp:35
drop_down_menu.hpp
game_config::images::selected
std::string selected
Definition:
game_config.cpp:197
gui2::event::implementation::fire_event
bool fire_event(const ui_event event, const std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
Helper function for fire_event.
Definition:
dispatcher_private.hpp:230
gui2::event::ui_event
ui_event
The event sent to the dispatcher.
Definition:
handler.hpp:115
gui2
Generic file dialog.
Definition:
draw_manager.hpp:21
implementation
Contains the implementation details for lexical_cast and shouldn't be used directly.
selectable_item.hpp
gui2::implementation::builder_menu_button
Definition:
menu_button.hpp:152
gui2::implementation::builder_menu_button::build
virtual std::unique_ptr< widget > build() const override
Definition:
menu_button.cpp:251
gui2::implementation::builder_menu_button::options_
std::vector<::config > options_
Definition:
menu_button.hpp:161
gui2::implementation::builder_menu_button::builder_menu_button
builder_menu_button(const config &cfg)
Definition:
menu_button.cpp:242
gui2::implementation::builder_styled_widget
Definition:
styled_widget.hpp:534
gui2::implementation::builder_styled_widget::build
virtual std::unique_ptr< widget > build() const=0
gui2::menu_button_definition::resolution
Definition:
menu_button.hpp:141
gui2::menu_button_definition::resolution::resolution
resolution(const config &cfg)
Definition:
menu_button.cpp:227
gui2::menu_button_definition
Definition:
menu_button.hpp:137
gui2::menu_button_definition::menu_button_definition
menu_button_definition(const config &cfg)
Definition:
menu_button.cpp:219
gui2::resolution_definition
Definition:
widget_definition.hpp:44
gui2::styled_widget_definition
Definition:
widget_definition.hpp:78
styled_widget.hpp
widget_definition.hpp
Generated by
1.9.1