The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
combobox.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
19 
20 #include "gui/widgets/control.hpp"
22 
23 namespace gui2
24 {
25 
26 // ------------ WIDGET -----------{
27 
28 /**
29  * Simple push button.
30  */
31 class tcombobox : public tcontrol, public tselectable_
32 {
33 public:
34  tcombobox();
35 
36  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
37 
38  /** See @ref tcontrol::set_active. */
39  virtual void set_active(const bool active) override;
40 
41  /** See @ref tcontrol::get_active. */
42  virtual bool get_active() const override;
43 
44  /** See @ref tcontrol::get_state. */
45  virtual unsigned get_state() const override;
46 
47  /** Inherited from tclickable. */
49  {
50  connect_signal_mouse_left_click(*this, signal);
51  }
52 
53  /** Inherited from tclickable. */
55  {
57  }
58 
59  /***** ***** ***** setters / getters for members ***** ****** *****/
60 
61  void set_retval(const int retval)
62  {
63  retval_ = retval;
64  }
65  void set_values(const std::vector<std::string>& values, int selected = 0);
66  void set_selected(int selected);
67 
68  /** See tselectable_::set_callback_state_change. */
69  std::function<void(twidget&)> callback_state_change_;
70 
71  /** Inherited from tselectable_ */
72  virtual unsigned get_value() const override { return selected_; }
73 
74  /** Inherited from tselectable_ */
75  virtual void set_value(const unsigned value ) override { set_selected(value); }
76 
77  /** Inherited from tselectable_ */
78  virtual unsigned num_states() const override { return values_.size(); }
79 
80  /** Inherited from tselectable_ */
81  virtual void set_callback_state_change(std::function<void(twidget&)> callback)
82  {
83  selected_callback_ = callback;
84  }
85 
86  /** Returns the value of the selected row */
88 
89 private:
90  /**
91  * Possible states of the widget.
92  *
93  * Note the order of the states must be the same as defined in settings.hpp.
94  */
95  enum tstate {
101  };
102 
103  void set_state(const tstate state);
104  /**
105  * Current state of the widget.
106  *
107  * The state of the widget determines what to render and how the widget
108  * reacts to certain 'events'.
109  */
111 
112  /**
113  * The return value of the button.
114  *
115  * If this value is not 0 and the button is clicked it sets the retval of
116  * the window and the window closes itself.
117  */
118  int retval_;
119  /**
120  */
121  std::vector<std::string> values_;
122  /**
123  */
125 
126  std::function<void(twidget&)> selected_callback_;
127 
128  /** See @ref tcontrol::get_control_type. */
129  virtual const std::string& get_control_type() const override;
130 
131  /***** ***** ***** signal handlers ***** ****** *****/
132 
133  void signal_handler_mouse_enter(const event::tevent event, bool& handled);
134 
135  void signal_handler_mouse_leave(const event::tevent event, bool& handled);
136 
138  bool& handled);
139 
141  bool& handled);
142 
144  bool& handled);
145 };
146 
147 // }---------- DEFINITION ---------{
148 
150 {
151  explicit tcombobox_definition(const config& cfg);
152 
154  {
155  explicit tresolution(const config& cfg);
156  };
157 };
158 
159 // }---------- BUILDER -----------{
160 
161 class tcontrol;
162 
163 namespace implementation
164 {
165 
167 {
168 public:
169  explicit tbuilder_combobox(const config& cfg);
170 
172 
173  twidget* build() const;
174 
175 private:
177  int retval_;
178  std::vector<std::string> options_;
179 };
180 
181 } // namespace implementation
182 
183 // }------------ END --------------
184 
185 } // namespace gui2
void signal_handler_mouse_leave(const event::tevent event, bool &handled)
Definition: combobox.cpp:104
virtual unsigned get_state() const override
See tcontrol::get_state.
Definition: combobox.cpp:76
std::function< void(twidget &)> callback_state_change_
See tselectable_::set_callback_state_change.
Definition: combobox.hpp:69
void signal_handler_left_button_up(const event::tevent event, bool &handled)
Definition: combobox.cpp:127
virtual unsigned get_value() const override
Inherited from tselectable_.
Definition: combobox.hpp:72
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
virtual void set_callback_state_change(std::function< void(twidget &)> callback)
Inherited from tselectable_.
Definition: combobox.hpp:81
void set_state(const tstate state)
Definition: combobox.cpp:81
Base class of a resolution, contains the common keys for a resolution.
GLboolean GLenum GLenum GLvoid * values
Definition: glew.h:3799
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
virtual twidget * build() const =0
void disconnect_click_handler(const event::tsignal_function &signal)
Inherited from tclickable.
Definition: combobox.hpp:54
std::function< void(twidget &)> selected_callback_
Definition: combobox.hpp:126
int retval_
The return value of the button.
Definition: combobox.hpp:118
GLsizei const GLfloat * value
Definition: glew.h:1817
std::string selected
Definition: game_config.cpp:84
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: combobox.cpp:64
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt)> tsignal_function
Callback function signature.
Definition: dispatcher.hpp:40
void signal_handler_mouse_enter(const event::tevent event, bool &handled)
Definition: combobox.cpp:95
virtual unsigned num_states() const override
Inherited from tselectable_.
Definition: combobox.hpp:78
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
std::string get_value_string() const
Returns the value of the selected row.
Definition: combobox.hpp:87
void signal_handler_left_button_down(const event::tevent event, bool &handled)
Definition: combobox.cpp:113
void connect_click_handler(const event::tsignal_function &signal)
Inherited from tclickable.
Definition: combobox.hpp:48
Small abstract helper class.
Definition: selectable.hpp:32
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: combobox.cpp:89
void signal_handler_left_button_click(const event::tevent event, bool &handled)
Definition: combobox.cpp:136
std::vector< std::string > options_
Definition: combobox.hpp:178
void set_values(const std::vector< std::string > &values, int selected=0)
Definition: combobox.cpp:165
tstate
Possible states of the widget.
Definition: combobox.hpp:95
void set_retval(const int retval)
Definition: combobox.hpp:61
tcombobox_definition(const config &cfg)
Definition: combobox.cpp:190
void disconnect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Disconnects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:717
virtual void set_value(const unsigned value) override
Inherited from tselectable_.
Definition: combobox.hpp:75
std::vector< std::string > values_
Definition: combobox.hpp:121
Base class for all visible items.
Definition: control.hpp:34
Simple push button.
Definition: combobox.hpp:31
tstate state_
Current state of the widget.
Definition: combobox.hpp:110
cl_event event
Definition: glew.h:3070
Base class for all widgets.
Definition: widget.hpp:49
void set_selected(int selected)
Definition: combobox.cpp:177
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual bool get_active() const override
See tcontrol::get_active.
Definition: combobox.cpp:71