The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
repeating_button.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 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_REPEATING_BUTTON_HPP_INCLUDED
16 #define GUI_WIDGETS_REPEATING_BUTTON_HPP_INCLUDED
17 
18 #include "gui/widgets/control.hpp"
20 
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 class trepeating_button : public tcontrol, public tclickable_
30 {
31 public:
34 
35  /**
36  * Connects a signal handler for a left mouse button down.
37  *
38  * This event is triggered when the button is pressed and, as long as the
39  * button stays down, every x ms afterwards.
40  *
41  * @param signal The signal to connect.
42  */
44 
45  /**
46  * Disconnects a signal handler for a left mouse button down.
47  *
48  * @param signal The signal to disconnect (should be the same
49  * as send to the connect call.
50  */
51  void
53 
54  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
55 
56  /** See @ref tcontrol::set_active. */
57  virtual void set_active(const bool active) override;
58 
59  /** See @ref tcontrol::get_active. */
60  virtual bool get_active() const override;
61 
62  /** See @ref tcontrol::get_state. */
63  virtual unsigned get_state() const override;
64 
65  /** Inherited from tclickable. */
67  {
69  }
70 
71  /** Inherited from tclickable. */
73  {
75  }
76 
77 private:
78  /**
79  * Possible states of the widget.
80  *
81  * Note the order of the states must be the same as defined in settings.hpp.
82  */
83  enum tstate {
89  };
90 
91  void set_state(const tstate state);
92  /**
93  * Current state of the widget.
94  *
95  * The state of the widget determines what to render and how the widget
96  * reacts to certain 'events'.
97  */
99 
100  /** The timer for the repeating events. */
102 
103  /** See @ref tcontrol::get_control_type. */
104  virtual const std::string& get_control_type() const override;
105 
106  /***** ***** ***** signal handlers ***** ****** *****/
107 
108  void signal_handler_mouse_enter(const event::tevent event, bool& handled);
109 
110  void signal_handler_mouse_leave(const event::tevent event, bool& handled);
111 
113  bool& handled);
114 
116  bool& handled);
117 };
118 
119 // }---------- DEFINITION ---------{
120 
122 {
123  explicit trepeating_button_definition(const config& cfg);
124 
126  {
127  explicit tresolution(const config& cfg);
128  };
129 };
130 
131 // }---------- BUILDER -----------{
132 
133 namespace implementation
134 {
135 
137 {
138 public:
139  explicit tbuilder_repeating_button(const config& cfg);
140 
142 
143  twidget* build() const;
144 };
145 
146 } // namespace implementation
147 
148 // }------------ END --------------
149 
150 } // namespace gui2
151 
152 #endif
void signal_handler_left_button_down(const event::tevent event, bool &handled)
void signal_handler_mouse_enter(const event::tevent event, bool &handled)
virtual unsigned get_state() const override
See tcontrol::get_state.
virtual bool get_active() const override
See tcontrol::get_active.
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
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
void disconnect_signal_mouse_left_down(const event::tsignal_function &signal)
Disconnects a signal handler for a left mouse button down.
virtual twidget * build() const =0
tstate
Possible states of the widget.
void connect_signal_mouse_left_down(const event::tsignal_function &signal)
Connects a signal handler for a left mouse button down.
tstate state_
Current state of the widget.
std::function< void(tdispatcher &dispatcher, const tevent event, bool &handled, bool &halt)> tsignal_function
Callback function signature.
Definition: dispatcher.hpp:40
void connect_click_handler(const event::tsignal_function &signal)
Inherited from tclickable.
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.
void signal_handler_mouse_leave(const event::tevent event, bool &handled)
void signal_handler_left_button_up(const event::tevent event, bool &handled)
Base class for all visible items.
Definition: control.hpp:34
virtual void set_active(const bool active) override
See tcontrol::set_active.
cl_event event
Definition: glew.h:3070
Base class for all widgets.
Definition: widget.hpp:49
void set_state(const tstate state)
trepeating_button_definition(const config &cfg)
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.
size_t repeat_timer_
The timer for the repeating events.