The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
button.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 #ifndef GUI_WIDGETS_BUTTON_HPP_INCLUDED
16 #define GUI_WIDGETS_BUTTON_HPP_INCLUDED
17 
20 
21 #include "gui/widgets/control.hpp"
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 /**
30  * Simple push button.
31  */
32 class tbutton : public tcontrol, public tclickable_
33 {
34 public:
35  tbutton();
36 
37  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
38 
39  /** See @ref tcontrol::set_active. */
40  virtual void set_active(const bool active) override;
41 
42  /** See @ref tcontrol::get_active. */
43  virtual bool get_active() const override;
44 
45  /** See @ref tcontrol::get_state. */
46  virtual unsigned get_state() const override;
47 
48  /** Inherited from tclickable. */
50  {
51  connect_signal_mouse_left_click(*this, signal);
52  }
53 
54  /** Inherited from tclickable. */
56  {
58  }
59 
60  /***** ***** ***** setters / getters for members ***** ****** *****/
61 
62  void set_retval(const int retval)
63  {
64  retval_ = retval;
65  }
66 
67 private:
68  /**
69  * Possible states of the widget.
70  *
71  * Note the order of the states must be the same as defined in settings.hpp.
72  */
73  enum tstate {
79  };
80 
81  void set_state(const tstate state);
82  /**
83  * Current state of the widget.
84  *
85  * The state of the widget determines what to render and how the widget
86  * reacts to certain 'events'.
87  */
89 
90  /**
91  * The return value of the button.
92  *
93  * If this value is not 0 and the button is clicked it sets the retval of
94  * the window and the window closes itself.
95  */
96  int retval_;
97 
98  /** See @ref tcontrol::get_control_type. */
99  virtual const std::string& get_control_type() const override;
100 
101  /***** ***** ***** signal handlers ***** ****** *****/
102 
103  void signal_handler_mouse_enter(const event::tevent event, bool& handled);
104 
105  void signal_handler_mouse_leave(const event::tevent event, bool& handled);
106 
108  bool& handled);
109 
111  bool& handled);
112 
114  bool& handled);
115 };
116 
117 // }---------- DEFINITION ---------{
118 
120 {
121  explicit tbutton_definition(const config& cfg);
122 
124  {
125  explicit tresolution(const config& cfg);
126  };
127 };
128 
129 // }---------- BUILDER -----------{
130 
131 class tcontrol;
132 
133 namespace implementation
134 {
135 
137 {
138 public:
139  explicit tbuilder_button(const config& cfg);
140 
142 
143  twidget* build() const;
144 
145 private:
147  int retval_;
148 };
149 
150 } // namespace implementation
151 
152 // }------------ END --------------
153 
154 } // namespace gui2
155 
156 #endif
void signal_handler_mouse_enter(const event::tevent event, bool &handled)
Definition: button.cpp:89
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: button.cpp:58
void signal_handler_left_button_down(const event::tevent event, bool &handled)
Definition: button.cpp:107
tstate
Possible states of the widget.
Definition: button.hpp:73
void signal_handler_left_button_up(const event::tevent event, bool &handled)
Definition: button.cpp:121
void connect_click_handler(const event::tsignal_function &signal)
Inherited from tclickable.
Definition: button.hpp:49
void set_retval(const int retval)
Definition: button.hpp:62
tstate state_
Current state of the widget.
Definition: button.hpp:88
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
Base class of a resolution, contains the common keys for a resolution.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Simple push button.
Definition: button.hpp:32
virtual twidget * build() const =0
void signal_handler_mouse_leave(const event::tevent event, bool &handled)
Definition: button.cpp:98
tbuilder_button(const config &cfg)
Definition: button.cpp:240
void signal_handler_left_button_click(const event::tevent event, bool &handled)
Definition: button.cpp:130
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: button.cpp:83
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt)> tsignal_function
Callback function signature.
Definition: dispatcher.hpp:40
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
Small concept class.
Definition: clickable.hpp:39
void disconnect_click_handler(const event::tsignal_function &signal)
Inherited from tclickable.
Definition: button.hpp:55
int retval_
The return value of the button.
Definition: button.hpp:96
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
Base class for all visible items.
Definition: control.hpp:34
virtual unsigned get_state() const override
See tcontrol::get_state.
Definition: button.cpp:70
cl_event event
Definition: glew.h:3070
Base class for all widgets.
Definition: widget.hpp:49
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
virtual bool get_active() const override
See tcontrol::get_active.
Definition: button.cpp:65
Contains the implementation details for lexical_cast and shouldn't be used directly.
void set_state(const tstate state)
Definition: button.cpp:75
tbutton_definition(const config &cfg)
Definition: button.cpp:151