tristate buttons for gui2
This commit adds the c++ code to add tristate buttons: toggle_buttons and toggle_panels can now have an arbitrary number of states instead of just 2 (selected and not selected). The number of states is determined by the number of [state] tags in the widgets definition. This doesn't add tristate definitions yet, but the plan is to use tristate buttons later for the headers of sortable lists (No-Sort, Sort-Up, Sort-Down buttons) TODO: figure out whether to remove the parameter from tcontrols constructor.
This commit is contained in:
parent
6cc2c93853
commit
1359e6a885
23 changed files with 290 additions and 278 deletions
|
@ -33,7 +33,8 @@
|
|||
text_extra_width = {EXTRA_WIDTH}
|
||||
text_font_size = {FONT_SIZE}
|
||||
|
||||
[state_enabled]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -45,9 +46,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -59,9 +60,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -73,13 +74,15 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -91,9 +94,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -105,9 +108,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -119,7 +122,8 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
#enddef
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
text_extra_width = 0
|
||||
text_font_size = 0
|
||||
|
||||
[state_enabled]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -48,9 +49,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -66,9 +67,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -84,13 +85,15 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -106,9 +109,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -124,9 +127,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -142,7 +145,8 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@
|
|||
text_extra_width = {EXTRA_WIDTH}
|
||||
text_font_size = {FONT_SIZE}
|
||||
|
||||
[state_enabled]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -55,9 +56,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -66,9 +67,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -77,13 +78,15 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -92,9 +95,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -103,9 +106,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -114,7 +117,8 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
#enddef
|
||||
|
|
|
@ -53,7 +53,8 @@
|
|||
text_extra_width = {EXTRA_WIDTH}
|
||||
text_font_size = {FONT_SIZE}
|
||||
|
||||
[state_enabled]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -63,9 +64,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -75,9 +76,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -87,13 +88,15 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -103,9 +106,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -115,9 +118,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -127,7 +130,8 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
text_extra_width = {EXTRA_WIDTH}
|
||||
text_font_size = {FONT_SIZE}
|
||||
|
||||
[state_enabled]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -44,9 +45,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -58,9 +59,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -72,13 +73,15 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -90,9 +93,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -104,9 +107,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -118,7 +121,8 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
#enddef
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
max_width = 25
|
||||
max_height = 19
|
||||
|
||||
[state_enabled]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -31,9 +32,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -43,9 +44,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -55,13 +56,15 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -71,9 +74,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -83,9 +86,9 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
|
@ -95,7 +98,8 @@
|
|||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
|
||||
|
|
|
@ -32,58 +32,61 @@
|
|||
|
||||
max_width = 0
|
||||
max_height = 0
|
||||
|
||||
[state_enabled]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
{_GUI_RECT ({GUI__BACKGROUND_COLOR_ENABLED}) }
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
{_GUI_RECT ({GUI__BACKGROUND_COLOR_DISABLED}) }
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
{_GUI_RECT ({GUI__BACKGROUND_COLOR_ENABLED}) }
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
{GUI__LISTBOX_SELECTED_CELL}
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
{GUI__LISTBOX_SELECTED_CELL}
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
{GUI__LISTBOX_SELECTED_CELL}
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
|
||||
|
|
|
@ -86,54 +86,60 @@
|
|||
max_width = 0
|
||||
max_height = 0
|
||||
|
||||
[state_enabled]
|
||||
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
###
|
||||
### Selected
|
||||
###
|
||||
|
||||
[state_enabled_selected]
|
||||
|
||||
[state]
|
||||
[enabled]
|
||||
|
||||
[draw]
|
||||
{_GUI__LISTBOX_SELECTED_CELL ({LINE_OFFSET_SIDE}) ({LINE_OFFSET_TOTAL}) ({LINE_HEIGHT}) ({BACKGROUND_OFFSET}) ("~O(65%)")}
|
||||
[/draw]
|
||||
|
||||
[/state_enabled_selected]
|
||||
[/enabled]
|
||||
|
||||
[state_disabled_selected]
|
||||
[disabled]
|
||||
|
||||
[draw]
|
||||
{_GUI__LISTBOX_SELECTED_CELL ({LINE_OFFSET_SIDE}) ({LINE_OFFSET_TOTAL}) ({LINE_HEIGHT}) ({BACKGROUND_OFFSET}) ("~O(65%)~GS()")}
|
||||
[/draw]
|
||||
|
||||
[/state_disabled_selected]
|
||||
[/disabled]
|
||||
|
||||
[state_focussed_selected]
|
||||
[focussed]
|
||||
|
||||
[draw]
|
||||
{_GUI__LISTBOX_SELECTED_CELL ({LINE_OFFSET_SIDE}) ({LINE_OFFSET_TOTAL}) ({LINE_HEIGHT}) ({BACKGROUND_OFFSET}) ("~O(65%)")}
|
||||
[/draw]
|
||||
|
||||
[/state_focussed_selected]
|
||||
[/focussed]
|
||||
[/state]
|
||||
|
||||
[/resolution]
|
||||
#enddef
|
||||
|
|
|
@ -1157,40 +1157,27 @@
|
|||
max="-1"
|
||||
super="generic/widget_definition/resolution"
|
||||
[tag]
|
||||
name="state_disabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_disabled_selected"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_enabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_enabled_selected"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_focussed"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_focussed_selected"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
name="state"
|
||||
min="1"
|
||||
max="-1"
|
||||
[tag]
|
||||
name="enabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="disabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="focussed"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[/tag]
|
||||
[/tag]
|
||||
[/tag]
|
||||
|
@ -1205,40 +1192,27 @@
|
|||
max="-1"
|
||||
super="generic/widget_definition/resolution"
|
||||
[tag]
|
||||
name="state_disabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_disabled_selected"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_enabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_enabled_selected"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_focussed"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="state_focussed_selected"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
name="state"
|
||||
min="1"
|
||||
max="-1"
|
||||
[tag]
|
||||
name="enabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="disabled"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="focussed"
|
||||
min="0"
|
||||
max="1"
|
||||
super="generic/state"
|
||||
[/tag]
|
||||
[/tag]
|
||||
[key]
|
||||
name="bottom_border"
|
||||
|
|
|
@ -69,13 +69,12 @@ ttoggle_button_definition::tresolution::tresolution(const config& cfg)
|
|||
{
|
||||
// Note the order should be the same as the enum tstate in
|
||||
// toggle_button.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_focussed")));
|
||||
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled_selected")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled_selected")));
|
||||
state.push_back(tstate_definition(cfg.child("state_focussed_selected")));
|
||||
FOREACH(const AUTO& c, cfg.child_range("state"))
|
||||
{
|
||||
state.push_back(tstate_definition(c.child("enabled")));
|
||||
state.push_back(tstate_definition(c.child("disabled")));
|
||||
state.push_back(tstate_definition(c.child("focussed")));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -86,13 +86,12 @@ ttoggle_panel_definition::tresolution::tresolution(const config& cfg)
|
|||
, right_border(cfg["right_border"])
|
||||
{
|
||||
// Note the order should be the same as the enum tstate in toggle_panel.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_focussed")));
|
||||
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled_selected")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled_selected")));
|
||||
state.push_back(tstate_definition(cfg.child("state_focussed_selected")));
|
||||
FOREACH(const AUTO& c, cfg.child_range("state"))
|
||||
{
|
||||
state.push_back(tstate_definition(c.child("enabled")));
|
||||
state.push_back(tstate_definition(c.child("disabled")));
|
||||
state.push_back(tstate_definition(c.child("focussed")));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -94,7 +94,7 @@ void taddon_uninstall_list::post_show(twindow& window)
|
|||
tgrid const* g = list.get_row_grid(k);
|
||||
const ttoggle_button& checkbox
|
||||
= find_widget<const ttoggle_button>(g, "checkbox", false);
|
||||
this->selections_[this->ids_[k]] = checkbox.get_value();
|
||||
this->selections_[this->ids_[k]] = checkbox.get_value_bool();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ void tcampaign_selection::post_show(twindow& window)
|
|||
choice_ = lexical_cast<unsigned>(tree.selected_item()->id());
|
||||
deterministic_ = find_widget<ttoggle_button>(&window,
|
||||
"checkbox_deterministic",
|
||||
false).get_value();
|
||||
false).get_value_bool();
|
||||
|
||||
preferences::set_modifications(engine_.active_mods(), false);
|
||||
} else {
|
||||
|
@ -292,7 +292,7 @@ void tcampaign_selection::post_show(twindow& window)
|
|||
.get_selected_row();
|
||||
deterministic_ = find_widget<ttoggle_button>(&window,
|
||||
"checkbox_deterministic",
|
||||
false).get_value();
|
||||
false).get_value_bool();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ void tcampaign_settings::pre_show(CVideo&, twindow& window)
|
|||
void tcampaign_settings::post_show(twindow& window)
|
||||
{
|
||||
engine_.get_state().mp_settings().show_connect =
|
||||
find_widget<ttoggle_button>(&window, "mp_connect", false).get_value();
|
||||
find_widget<ttoggle_button>(&window, "mp_connect", false).get_value_bool();
|
||||
}
|
||||
|
||||
} // end namespace gui2
|
||||
|
|
|
@ -500,6 +500,18 @@ void tfield<T, W, CT>::save(twindow& window, const bool must_be_active)
|
|||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void tfield<bool, tselectable_>::save(
|
||||
twindow& window, const bool must_be_active)
|
||||
{
|
||||
const tselectable_* selectable
|
||||
= find_widget<const tselectable_>(&window, id(), must_be_active, false);
|
||||
|
||||
if(selectable) {
|
||||
value_ = selectable->get_value_bool();
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void tfield<std::string, tcontrol, const std::string&>::save(
|
||||
twindow& window, const bool must_be_active)
|
||||
|
|
|
@ -834,8 +834,8 @@ void tlobby_main::update_playerlist()
|
|||
SCOPE_LB;
|
||||
DBG_LB << "Playerlist update: " << lobby_info_.users().size() << "\n";
|
||||
lobby_info_.update_user_statuses(selected_game_id_, active_window_room());
|
||||
lobby_info_.sort_users(player_list_.sort_by_name->get_value(),
|
||||
player_list_.sort_by_relation->get_value());
|
||||
lobby_info_.sort_users(player_list_.sort_by_name->get_value_bool(),
|
||||
player_list_.sort_by_relation->get_value_bool());
|
||||
|
||||
bool lobby = false;
|
||||
if(room_info* ri = active_window_room()) {
|
||||
|
@ -1786,7 +1786,7 @@ void tlobby_main::game_filter_reload()
|
|||
&game_info::vacant_slots,
|
||||
std::greater<size_t> >(0));
|
||||
}
|
||||
lobby_info_.set_game_filter_invert(filter_invert_->get_value());
|
||||
lobby_info_.set_game_filter_invert(filter_invert_->get_value_bool());
|
||||
}
|
||||
|
||||
void tlobby_main::game_filter_keypress_callback(const SDLKey key)
|
||||
|
@ -1812,9 +1812,9 @@ void tlobby_main::player_filter_callback(gui2::twidget& /*widget*/)
|
|||
{
|
||||
player_list_.update_sort_icons();
|
||||
preferences::set_playerlist_sort_relation(
|
||||
player_list_.sort_by_relation->get_value());
|
||||
player_list_.sort_by_relation->get_value_bool());
|
||||
preferences::set_playerlist_sort_name(
|
||||
player_list_.sort_by_name->get_value());
|
||||
player_list_.sort_by_name->get_value_bool());
|
||||
player_list_dirty_ = true;
|
||||
// window_->invalidate_layout();
|
||||
}
|
||||
|
@ -1857,7 +1857,7 @@ void tlobby_main::user_dialog_callback(user_info* info)
|
|||
void tlobby_main::skip_replay_changed_callback(twidget& w)
|
||||
{
|
||||
ttoggle_button& tb = dynamic_cast<ttoggle_button&>(w);
|
||||
preferences::set_skip_mp_replay(tb.get_value());
|
||||
preferences::set_skip_mp_replay(tb.get_value_bool());
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -76,7 +76,7 @@ static ttoggle_button * setup_pref_toggle_button(const std::string & id, bool de
|
|||
//Needed to disambiguate overloaded function
|
||||
void (*set) (const std::string &, bool) = &preferences::set;
|
||||
|
||||
connect_signal_mouse_left_click(*b, boost::bind(set, id, boost::bind(&ttoggle_button::get_value, b)));
|
||||
connect_signal_mouse_left_click(*b, boost::bind(set, id, boost::bind(&ttoggle_button::get_value_bool, b)));
|
||||
|
||||
return b;
|
||||
}
|
||||
|
|
|
@ -430,8 +430,13 @@ void tcontrol::definition_load_configuration(const std::string& control_type)
|
|||
assert(!config());
|
||||
|
||||
set_config(get_control(control_type, definition_));
|
||||
|
||||
assert(canvas().size() == config()->state.size());
|
||||
if(canvas().size() != config()->state.size())
|
||||
{
|
||||
/// @TODO: Some widgets (toggle panel, toggle button) have a variable canvas count which is determined by its definition.
|
||||
/// I think we should remove the canvas_count from tcontrols construcor and always read it from the definition.
|
||||
LOG_GUI_L << "Corrected canvas count to " << config()->state.size();
|
||||
canvas() = std::vector<tcanvas>(config()->state.size());
|
||||
}
|
||||
for(size_t i = 0; i < canvas().size(); ++i) {
|
||||
canvas(i) = config()->state[i].canvas;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define GUI_WIDGETS_SELECTABLE_HPP_INCLUDED
|
||||
|
||||
#include "utils/boost_function_guarded.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -36,11 +37,25 @@ public:
|
|||
}
|
||||
|
||||
/** Is the control selected? */
|
||||
virtual bool get_value() const = 0;
|
||||
virtual unsigned get_value() const = 0;
|
||||
|
||||
/** Select the control. */
|
||||
virtual void set_value(const bool) = 0;
|
||||
virtual void set_value(const unsigned) = 0;
|
||||
|
||||
/** The number of states, that is 2 for normal buttons, 3 for tristate buttons. */
|
||||
virtual unsigned num_states() const = 0;
|
||||
|
||||
bool get_value_bool() const
|
||||
{
|
||||
assert(num_states() == 2);
|
||||
return get_value() != 0;
|
||||
}
|
||||
|
||||
void set_value_bool(const bool value)
|
||||
{
|
||||
assert(num_states() == 2);
|
||||
return set_value(value);
|
||||
}
|
||||
/**
|
||||
* When the user does something to change the widget state this event is
|
||||
* fired. Most of the time it will be a left click on the widget.
|
||||
|
|
|
@ -38,6 +38,7 @@ REGISTER_WIDGET(toggle_button)
|
|||
ttoggle_button::ttoggle_button()
|
||||
: tcontrol(COUNT)
|
||||
, state_(ENABLED)
|
||||
, state_num_(0)
|
||||
, retval_(0)
|
||||
, callback_state_change_()
|
||||
, icon_name_()
|
||||
|
@ -56,6 +57,14 @@ ttoggle_button::ttoggle_button()
|
|||
_3));
|
||||
}
|
||||
|
||||
unsigned ttoggle_button::num_states() const
|
||||
{
|
||||
std::div_t res = std::div(this->config()->state.size(), COUNT);
|
||||
assert(res.rem == 0);
|
||||
assert(res.quot > 0);
|
||||
return res.quot;
|
||||
}
|
||||
|
||||
void ttoggle_button::set_members(const string_map& data)
|
||||
{
|
||||
// Inherit
|
||||
|
@ -70,28 +79,20 @@ void ttoggle_button::set_members(const string_map& data)
|
|||
void ttoggle_button::set_active(const bool active)
|
||||
{
|
||||
if(active) {
|
||||
if(get_value()) {
|
||||
set_state(ENABLED_SELECTED);
|
||||
} else {
|
||||
set_state(ENABLED);
|
||||
}
|
||||
set_state(ENABLED);
|
||||
} else {
|
||||
if(get_value()) {
|
||||
set_state(DISABLED_SELECTED);
|
||||
} else {
|
||||
set_state(DISABLED);
|
||||
}
|
||||
set_state(DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
bool ttoggle_button::get_active() const
|
||||
{
|
||||
return state_ != DISABLED && state_ != DISABLED_SELECTED;
|
||||
return state_ != DISABLED;
|
||||
}
|
||||
|
||||
unsigned ttoggle_button::get_state() const
|
||||
{
|
||||
return state_;
|
||||
return state_ + COUNT * state_num_;
|
||||
}
|
||||
|
||||
void ttoggle_button::update_canvas()
|
||||
|
@ -109,17 +110,14 @@ void ttoggle_button::update_canvas()
|
|||
set_is_dirty(true);
|
||||
}
|
||||
|
||||
void ttoggle_button::set_value(const bool selected)
|
||||
void ttoggle_button::set_value(const unsigned selected)
|
||||
{
|
||||
if(selected == get_value()) {
|
||||
return;
|
||||
}
|
||||
state_num_ = selected % num_states();
|
||||
set_is_dirty(true);
|
||||
|
||||
if(selected) {
|
||||
set_state(static_cast<tstate>(state_ + ENABLED_SELECTED));
|
||||
} else {
|
||||
set_state(static_cast<tstate>(state_ - ENABLED_SELECTED));
|
||||
}
|
||||
}
|
||||
|
||||
void ttoggle_button::set_retval(const int retval)
|
||||
|
@ -150,12 +148,7 @@ void ttoggle_button::signal_handler_mouse_enter(const event::tevent event,
|
|||
bool& handled)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
if(get_value()) {
|
||||
set_state(FOCUSSED_SELECTED);
|
||||
} else {
|
||||
set_state(FOCUSSED);
|
||||
}
|
||||
set_state(FOCUSSED);
|
||||
handled = true;
|
||||
}
|
||||
|
||||
|
@ -163,12 +156,7 @@ void ttoggle_button::signal_handler_mouse_leave(const event::tevent event,
|
|||
bool& handled)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
if(get_value()) {
|
||||
set_state(ENABLED_SELECTED);
|
||||
} else {
|
||||
set_state(ENABLED);
|
||||
}
|
||||
set_state(ENABLED);
|
||||
handled = true;
|
||||
}
|
||||
|
||||
|
@ -179,11 +167,7 @@ void ttoggle_button::signal_handler_left_button_click(const event::tevent event,
|
|||
|
||||
sound::play_UI_sound(settings::sound_toggle_button_click);
|
||||
|
||||
if(get_value()) {
|
||||
set_state(ENABLED);
|
||||
} else {
|
||||
set_state(ENABLED_SELECTED);
|
||||
}
|
||||
set_value(get_value() + 1);
|
||||
|
||||
if(callback_state_change_) {
|
||||
callback_state_change_(*this);
|
||||
|
|
|
@ -50,13 +50,14 @@ public:
|
|||
void update_canvas();
|
||||
|
||||
/** Inherited from tselectable_ */
|
||||
bool get_value() const
|
||||
unsigned get_value() const OVERRIDE
|
||||
{
|
||||
return state_ >= ENABLED_SELECTED;
|
||||
return state_num_;
|
||||
}
|
||||
|
||||
/** Inherited from tselectable_ */
|
||||
void set_value(const bool selected);
|
||||
unsigned num_states() const OVERRIDE;
|
||||
/** Inherited from tselectable_ */
|
||||
void set_value(const unsigned selected);
|
||||
|
||||
/***** ***** ***** setters / getters for members ***** ****** *****/
|
||||
|
||||
|
@ -91,9 +92,6 @@ private:
|
|||
ENABLED,
|
||||
DISABLED,
|
||||
FOCUSSED,
|
||||
ENABLED_SELECTED,
|
||||
DISABLED_SELECTED,
|
||||
FOCUSSED_SELECTED,
|
||||
COUNT
|
||||
};
|
||||
|
||||
|
@ -106,7 +104,10 @@ private:
|
|||
* reacts to certain 'events'.
|
||||
*/
|
||||
tstate state_;
|
||||
|
||||
/**
|
||||
* Usually 1 for selected and 0 for not selected, can also have higher values in tristate buttons.
|
||||
*/
|
||||
unsigned state_num_;
|
||||
/**
|
||||
* The return value of the button.
|
||||
*
|
||||
|
|
|
@ -38,6 +38,7 @@ REGISTER_WIDGET(toggle_panel)
|
|||
ttoggle_panel::ttoggle_panel()
|
||||
: tpanel(COUNT)
|
||||
, state_(ENABLED)
|
||||
, state_num_(0)
|
||||
, retval_(0)
|
||||
, callback_state_change_(0)
|
||||
, callback_mouse_left_double_click_()
|
||||
|
@ -76,6 +77,14 @@ ttoggle_panel::ttoggle_panel()
|
|||
event::tdispatcher::back_post_child);
|
||||
}
|
||||
|
||||
unsigned ttoggle_panel::num_states() const
|
||||
{
|
||||
std::div_t res = std::div(this->config()->state.size(), COUNT);
|
||||
assert(res.rem == 0);
|
||||
assert(res.quot > 0);
|
||||
return res.quot;
|
||||
}
|
||||
|
||||
void ttoggle_panel::set_child_members(
|
||||
const std::map<std::string /* widget id */, string_map>& data)
|
||||
{
|
||||
|
@ -112,28 +121,20 @@ const twidget* ttoggle_panel::find_at(const tpoint& coordinate,
|
|||
void ttoggle_panel::set_active(const bool active)
|
||||
{
|
||||
if(active) {
|
||||
if(get_value()) {
|
||||
set_state(ENABLED_SELECTED);
|
||||
} else {
|
||||
set_state(ENABLED);
|
||||
}
|
||||
set_state(ENABLED);
|
||||
} else {
|
||||
if(get_value()) {
|
||||
set_state(DISABLED_SELECTED);
|
||||
} else {
|
||||
set_state(DISABLED);
|
||||
}
|
||||
set_state(DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
bool ttoggle_panel::get_active() const
|
||||
{
|
||||
return state_ != DISABLED && state_ != DISABLED_SELECTED;
|
||||
return state_ != DISABLED;
|
||||
}
|
||||
|
||||
unsigned ttoggle_panel::get_state() const
|
||||
{
|
||||
return state_;
|
||||
return state_ + COUNT * state_num_;
|
||||
}
|
||||
|
||||
SDL_Rect ttoggle_panel::get_client_rect() const
|
||||
|
@ -163,17 +164,13 @@ tpoint ttoggle_panel::border_space() const
|
|||
conf->top_border + conf->bottom_border);
|
||||
}
|
||||
|
||||
void ttoggle_panel::set_value(const bool selected)
|
||||
void ttoggle_panel::set_value(const unsigned selected)
|
||||
{
|
||||
if(selected == get_value()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(selected) {
|
||||
set_state(static_cast<tstate>(state_ + ENABLED_SELECTED));
|
||||
} else {
|
||||
set_state(static_cast<tstate>(state_ - ENABLED_SELECTED));
|
||||
}
|
||||
state_num_ = selected % num_states();
|
||||
set_is_dirty(true);
|
||||
}
|
||||
|
||||
void ttoggle_panel::set_retval(const int retval)
|
||||
|
@ -239,11 +236,7 @@ void ttoggle_panel::signal_handler_mouse_enter(const event::tevent event,
|
|||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
if(get_value()) {
|
||||
set_state(FOCUSSED_SELECTED);
|
||||
} else {
|
||||
set_state(FOCUSSED);
|
||||
}
|
||||
set_state(FOCUSSED);
|
||||
handled = true;
|
||||
}
|
||||
|
||||
|
@ -252,11 +245,7 @@ void ttoggle_panel::signal_handler_mouse_leave(const event::tevent event,
|
|||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
if(get_value()) {
|
||||
set_state(ENABLED_SELECTED);
|
||||
} else {
|
||||
set_state(ENABLED);
|
||||
}
|
||||
set_state(ENABLED);
|
||||
handled = true;
|
||||
}
|
||||
|
||||
|
@ -265,7 +254,7 @@ ttoggle_panel::signal_handler_pre_left_button_click(const event::tevent event)
|
|||
{
|
||||
DBG_GUI_E << get_control_type() << "[" << id() << "]: " << event << ".\n";
|
||||
|
||||
set_value(true);
|
||||
set_value(1);
|
||||
|
||||
#if 0
|
||||
/*
|
||||
|
@ -295,11 +284,7 @@ void ttoggle_panel::signal_handler_left_button_click(const event::tevent event,
|
|||
|
||||
sound::play_UI_sound(settings::sound_toggle_panel_click);
|
||||
|
||||
if(get_value()) {
|
||||
set_state(ENABLED);
|
||||
} else {
|
||||
set_state(ENABLED_SELECTED);
|
||||
}
|
||||
set_value(get_value() + 1);
|
||||
|
||||
if(callback_state_change_) {
|
||||
callback_state_change_(*this);
|
||||
|
|
|
@ -84,13 +84,16 @@ public:
|
|||
virtual tpoint border_space() const OVERRIDE;
|
||||
|
||||
/** Inherited from tselectable_ */
|
||||
bool get_value() const
|
||||
unsigned get_value() const OVERRIDE
|
||||
{
|
||||
return state_ >= ENABLED_SELECTED;
|
||||
return state_num_;;
|
||||
}
|
||||
|
||||
/** Inherited from tselectable_ */
|
||||
void set_value(const bool selected);
|
||||
void set_value(const unsigned selected);
|
||||
|
||||
/** Inherited from tselectable_ */
|
||||
unsigned num_states() const OVERRIDE;
|
||||
|
||||
/***** ***** ***** setters / getters for members ***** ****** *****/
|
||||
|
||||
|
@ -121,9 +124,6 @@ private:
|
|||
ENABLED,
|
||||
DISABLED,
|
||||
FOCUSSED,
|
||||
ENABLED_SELECTED,
|
||||
DISABLED_SELECTED,
|
||||
FOCUSSED_SELECTED,
|
||||
COUNT
|
||||
};
|
||||
|
||||
|
@ -137,6 +137,11 @@ private:
|
|||
*/
|
||||
tstate state_;
|
||||
|
||||
/**
|
||||
* Usually 1 for selected and 0 for not selected, can also have higher values in tristate buttons.
|
||||
*/
|
||||
unsigned state_num_;
|
||||
|
||||
/**
|
||||
* The return value of the button.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue