The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
preferences_dialog.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011, 2015 by Ignacio R. Morelle <[email protected]>
3  Copyright (C) 2016 by Charles Dang <exodia339gmail.com>
4  Part of the Battle for Wesnoth Project http://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 #ifndef GUI_DIALOGS_PREFERENCES_DIALOG_HPP_INCLUDED
17 #define GUI_DIALOGS_PREFERENCES_DIALOG_HPP_INCLUDED
18 
19 #include "config.hpp"
20 #include "game_preferences.hpp"
21 #include "utils/make_enum.hpp"
22 #include "gui/dialogs/dialog.hpp"
23 #include "gui/widgets/group.hpp"
24 
25 // This file is not named preferences.hpp in order -I conflicts with
26 // src/preferences.hpp.
27 
28 namespace hotkey {
29  struct hotkey_command;
30 }
31 namespace gui2
32 {
33 
34 class tlistbox;
35 class tcombobox;
36 class tcontrol;
37 class tslider;
38 class ttext_box;
39 class ttoggle_button;
40 
41 class tpreferences : public tdialog
42 {
43 public:
44  /**
45  * Constructor.
46  */
47  tpreferences(CVideo& video, const config& game_cfg);
48 
49  /** The display function -- see @ref tdialog for more information. */
50  static bool display(CVideo& video, const config& game_cfg)
51  {
52  tpreferences(video, game_cfg).show(video);
53  return true;
54  }
55 
56  typedef std::vector<const hotkey::hotkey_command*> t_visible_hotkeys;
57 
58  void set_selected_index(std::pair<int, int> index)
59  {
60  index_ = index;
61  }
62 
63 private:
64  /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
65  virtual const std::string& window_id() const;
66 
67  /** Inherited from tdialog. */
68  void pre_show(twindow& window);
69  void post_show(twindow& /*window*/);
70 
71  /** Initializers */
72  void initialize_members(twindow& window);
73  void initialize_tabs(twindow& window, tlistbox& selector, const int index);
74  void setup_friends_list(twindow& window);
75  void setup_hotkey_list(twindow& window);
76 
77  void add_friend_list_entry(const bool is_friend,
78  ttext_box& textbox, twindow& window);
79 
80  void edit_friend_list_entry(tlistbox& friends, ttext_box& textbox);
81 
82  void remove_friend_list_entry(tlistbox& friends_list,
83  ttext_box& textbox, twindow& window);
84 
85  void add_tab(tlistbox& tab_bar, const std::string& label);
86  void add_pager_row(tlistbox& selector, const std::string& icon, const std::string& label);
87  void set_visible_page(twindow& window, unsigned int page, const std::string& pager_id);
88 
89  /** Callback for selection changes */
90  void on_page_select(twindow& window);
91  void on_tab_select(twindow& window);
92  void on_advanced_prefs_list_select(tlistbox& tree, twindow& window);
93 
94  /** Special callback functions */
95  void handle_res_select(twindow& window);
96  void fullscreen_toggle_callback(twindow& window);
97  void accl_speed_slider_callback(tslider& slider);
98  void max_autosaves_slider_callback(tslider& slider, tcontrol& status_label);
100  void animate_map_toggle_callback(ttoggle_button& toggle, ttoggle_button& toggle_water);
101  void add_hotkey_callback(tlistbox& hotkeys);
102  void remove_hotkey_callback(tlistbox& hotkeys);
103  void default_hotkey_callback(twindow& window);
104 
105  /**
106  * Sets the initial state and callback for a simple bool-state toggle button
107  * In the callback, the bool value of the widget is passeed to the setter
108  */
109  void setup_single_toggle(
110  const std::string& widget_id,
111  const bool start_value,
112  std::function<void(bool)> callback,
113  twidget& find_in,
114  const bool inverted = false);
115 
116  void single_toggle_callback(const ttoggle_button& widget,
117  std::function<void(bool)> setter,
118  const bool inverted);
119 
120  /**
121  * Sets the initial state and callback for a bool-state toggle button/slider
122  * pair. In the callback, the slider is set to active/inactive based on the
123  * button's value, which is also passed to the setter.
124  */
126  const std::string& toggle_widget,
127  const std::string& slider_widget,
128  const bool toggle_start_value,
129  const int slider_state_value,
130  std::function<void(bool)> toggle_callback,
131  std::function<void(int)> slider_callback,
132  twidget& find_in);
133 
134  void toggle_slider_pair_callback(const ttoggle_button& toggle_widget,
135  tslider& slider_widget, std::function<void(bool)> setter);
136 
137  /**
138  * Sets the initial state and callback for a standalone slider
139  * In the callback, int value of the widget is passeed to the setter
140  */
141  void setup_single_slider(
142  const std::string& widget_id,
143  const int start_value,
144  std::function<void(int)> slider_callback,
145  twidget& find_in);
146 
147  void single_slider_callback(const tslider& widget,
148  std::function<void(int)> setter);
149 
150  typedef std::pair<std::vector<std::string>, std::vector<std::string> > combo_data;
151 
152  /**
153  * Sets the initial state and callback for a combobox
154  */
155  void setup_combobox(
156  const std::string& widget_id,
157  const combo_data& options,
158  const unsigned start_value,
159  std::function<void(std::string)> callback,
160  twidget& find_in);
161 
162  void simple_combobox_callback(const tcombobox& widget,
163  std::function<void(std::string)> setter, std::vector<std::string>& vec);
164 
165  /**
166  * Sets the a radio button group
167  * Since (so far) there is only one group of these, the code is speciliazed.
168  * If (at a later date) more groups need to be added, this will have to be
169  * generalized.
170  */
172 
173  template <typename T>
174  void setup_radio_toggle(
175  const std::string& toggle_id,
176  const T& enum_value,
177  const int start_value,
178  tgroup<T>& group,
179  std::function<void(int)> callback,
180  twindow& window);
181 
182  template <typename T>
184  tgroup<T>& group,
185  std::function<void(int)> setter);
186 
187  /**
188  * Sets up a label that always displays the value of another widget.
189  */
190  template <typename T>
191  void bind_status_label(
192  T& parent,
193  const std::string& label_id,
194  twidget& find_in);
195 
196  void bind_status_label(
197  tslider& parent,
198  const std::string& label_id,
199  twidget& find_in,
200  const std::string& suffix = "");
201 
202  template <typename T>
203  void status_label_callback(T& parent_widget,
204  tcontrol& label_widget, const std::string& suffix = "");
205 
206  MAKE_ENUM(ADVANCED_PREF_TYPE,
207  (TOGGLE, "boolean")
208  (SLIDER, "int")
209  (COMBO, "combo")
210  (SPECIAL, "custom")
211  )
212 
213  std::vector<std::pair<int,int> > resolutions_;
215  std::vector<std::string> friend_names_;
216 
218 
220  t_visible_hotkeys visible_hotkeys_;
221 
222  // Special variable to keep the value of the scaling slider,
223  // to be used in post_show
225 
226  // The page/tab index pairs for setting visible pages
227  std::pair<int, int> index_;
228 };
229 
230 } // namespace gui2
231 
232 #endif /* ! GUI_DIALOGS_PREFERENCES_DIALOG_HPP_INCLUDED */
std::vector< const hotkey::hotkey_command * > t_visible_hotkeys
void setup_toggle_slider_pair(const std::string &toggle_widget, const std::string &slider_widget, const bool toggle_start_value, const int slider_state_value, std::function< void(bool)> toggle_callback, std::function< void(int)> slider_callback, twidget &find_in)
Sets the initial state and callback for a bool-state toggle button/slider pair.
void setup_combobox(const std::string &widget_id, const combo_data &options, const unsigned start_value, std::function< void(std::string)> callback, twidget &find_in)
Sets the initial state and callback for a combobox.
void simple_combobox_callback(const tcombobox &widget, std::function< void(std::string)> setter, std::vector< std::string > &vec)
void default_hotkey_callback(twindow &window)
void accl_speed_slider_callback(tslider &slider)
std::pair< std::vector< std::string >, std::vector< std::string > > combo_data
#define MAKE_ENUM(NAME, CONTENT)
Definition: make_enum.hpp:157
void fullscreen_toggle_callback(twindow &window)
Definition: video.hpp:58
std::vector< std::string > friend_names_
void set_selected_index(std::pair< int, int > index)
void initialize_members(twindow &window)
Initializers.
void setup_friends_list(twindow &window)
tgroup< preferences::LOBBY_JOINS > lobby_joins_group
Sets the a radio button group Since (so far) there is only one group of these, the code is speciliaze...
STL namespace.
void set_visible_page(twindow &window, unsigned int page, const std::string &pager_id)
void remove_friend_list_entry(tlistbox &friends_list, ttext_box &textbox, twindow &window)
void on_tab_select(twindow &window)
Class for a single line text area.
Definition: text_box.hpp:118
void toggle_radio_callback(tgroup< T > &group, std::function< void(int)> setter)
MAKE_ENUM(ADVANCED_PREF_TYPE,(TOGGLE,"boolean")(SLIDER,"int")(COMBO,"combo")(SPECIAL,"custom")) std std::vector< config > adv_preferences_cfg_
const config * game_cfg
Definition: help_impl.cpp:64
Definitions for the interface to Wesnoth Markup Language (WML).
void bind_status_label(T &parent, const std::string &label_id, twidget &find_in)
Sets up a label that always displays the value of another widget.
void add_friend_list_entry(const bool is_friend, ttext_box &textbox, twindow &window)
void add_hotkey_callback(tlistbox &hotkeys)
Keyboard shortcuts for game actions.
void post_show(twindow &)
Actions to be taken after the window has been shown.
void setup_single_toggle(const std::string &widget_id, const bool start_value, std::function< void(bool)> callback, twidget &find_in, const bool inverted=false)
Sets the initial state and callback for a simple bool-state toggle button In the callback, the bool value of the widget is passeed to the setter.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
void setup_single_slider(const std::string &widget_id, const int start_value, std::function< void(int)> slider_callback, twidget &find_in)
Sets the initial state and callback for a standalone slider In the callback, int value of the widget ...
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void single_toggle_callback(const ttoggle_button &widget, std::function< void(bool)> setter, const bool inverted)
const config & options()
bool is_friend(const std::string &nick)
std::pair< int, int > index_
Abstract base class for all dialogs.
Definition: dialog.hpp:121
void remove_hotkey_callback(tlistbox &hotkeys)
void edit_friend_list_entry(tlistbox &friends, ttext_box &textbox)
void handle_res_select(twindow &window)
Special callback functions.
void single_slider_callback(const tslider &widget, std::function< void(int)> setter)
void status_label_callback(T &parent_widget, tcontrol &label_widget, const std::string &suffix="")
void font_scaling_slider_callback(tslider &slider)
t_visible_hotkeys visible_hotkeys_
void animate_map_toggle_callback(ttoggle_button &toggle, ttoggle_button &toggle_water)
static bool display(CVideo &video, const config &game_cfg)
The display function – see tdialog for more information.
GLuint index
Definition: glew.h:1782
tpreferences(CVideo &video, const config &game_cfg)
Constructor.
void on_advanced_prefs_list_select(tlistbox &tree, twindow &window)
The listbox class.
Definition: listbox.hpp:39
void initialize_tabs(twindow &window, tlistbox &selector, const int index)
Base class for all visible items.
Definition: control.hpp:34
Simple push button.
Definition: combobox.hpp:31
void max_autosaves_slider_callback(tslider &slider, tcontrol &status_label)
void setup_hotkey_list(twindow &window)
void toggle_slider_pair_callback(const ttoggle_button &toggle_widget, tslider &slider_widget, std::function< void(bool)> setter)
void add_tab(tlistbox &tab_bar, const std::string &label)
GLboolean GLuint group
Definition: glew.h:2589
virtual const std::string & window_id() const
Inherited from tdialog, implemented by REGISTER_DIALOG.
Base class for all widgets.
Definition: widget.hpp:49
std::vector< t_string > accl_speeds_
void setup_radio_toggle(const std::string &toggle_id, const T &enum_value, const int start_value, tgroup< T > &group, std::function< void(int)> callback, twindow &window)
void add_pager_row(tlistbox &selector, const std::string &icon, const std::string &label)
void on_page_select(twindow &window)
Callback for selection changes.
A slider.
Definition: slider.hpp:30
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
Defines the MAKE_ENUM macro.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void pre_show(twindow &window)
Inherited from tdialog.