The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
selectable.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 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 #ifndef GUI_WIDGETS_SELECTABLE_HPP_INCLUDED
16 #define GUI_WIDGETS_SELECTABLE_HPP_INCLUDED
17 
18 #include "utils/functional.hpp"
19 #include <cassert>
20 
21 namespace gui2
22 {
23 
24 class twidget;
25 
26 /**
27  * Small abstract helper class.
28  *
29  * Parts of the engine inherit this class so we can have generic
30  * selectable items.
31  */
33 {
34 public:
35  virtual ~tselectable_()
36  {
37  }
38 
39  /** Is the control selected? */
40  virtual unsigned get_value() const = 0;
41 
42  /** Select the control. */
43  virtual void set_value(const unsigned) = 0;
44 
45  /** The number of states, that is 2 for normal buttons, 3 for tristate buttons. */
46  virtual unsigned num_states() const = 0;
47 
48  bool get_value_bool() const
49  {
50  assert(num_states() == 2);
51  return get_value() != 0;
52  }
53 
54  void set_value_bool(const bool value)
55  {
56  assert(num_states() == 2);
57  return set_value(value);
58  }
59  /**
60  * When the user does something to change the widget state this event is
61  * fired. Most of the time it will be a left click on the widget.
62  */
63  virtual void
64  set_callback_state_change(std::function<void(twidget&)> callback) = 0;
65 };
66 
67 } // namespace gui2
68 
69 #endif
virtual void set_callback_state_change(std::function< void(twidget &)> callback)=0
When the user does something to change the widget state this event is fired.
virtual unsigned get_value() const =0
Is the control selected?
virtual void set_value(const unsigned)=0
Select the control.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
bool get_value_bool() const
Definition: selectable.hpp:48
GLsizei const GLfloat * value
Definition: glew.h:1817
Small abstract helper class.
Definition: selectable.hpp:32
virtual ~tselectable_()
Definition: selectable.hpp:35
virtual unsigned num_states() const =0
The number of states, that is 2 for normal buttons, 3 for tristate buttons.
Base class for all widgets.
Definition: widget.hpp:49
void set_value_bool(const bool value)
Definition: selectable.hpp:54