The Battle for Wesnoth  1.17.0-dev
repeating_button.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://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 #pragma once
17 
20 
23 
24 namespace gui2
25 {
26 namespace implementation
27 {
28 struct builder_repeating_button;
29 }
30 
31 // ------------ WIDGET -----------{
32 
33 /**
34  * @ingroup GUIWidgetWML
35  *
36  * A repeating_button is a control that can be pushed down and repeat a certain action.
37  * Once the button is down every x milliseconds it is down a new down event is triggered.
38  *
39  * The following states exist:
40  * * state_enabled - the repeating_button is enabled.
41  * * state_disabled - the repeating_button is disabled.
42  * * state_pressed - the left mouse repeating_button is down.
43  * * state_focussed - the mouse is over the repeating_button.
44  */
46 {
47 public:
50 
51  /**
52  * Connects a signal handler for a left mouse button down.
53  *
54  * This event is triggered when the button is pressed and, as long as the
55  * button stays down, every x ms afterwards.
56  *
57  * @param signal The signal to connect.
58  */
59  void connect_signal_mouse_left_down(const event::signal_function& signal);
60 
61  /**
62  * Disconnects a signal handler for a left mouse button down.
63  *
64  * @param signal The signal to disconnect (should be the same
65  * as send to the connect call.
66  */
67  void
68  disconnect_signal_mouse_left_down(const event::signal_function& signal);
69 
70  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
71 
72  /** See @ref styled_widget::set_active. */
73  virtual void set_active(const bool active) override;
74 
75  /** See @ref styled_widget::get_active. */
76  virtual bool get_active() const override;
77 
78  /** See @ref styled_widget::get_state. */
79  virtual unsigned get_state() const override;
80 
81  /** Inherited from clickable_item. */
82  virtual void connect_click_handler(const event::signal_function& signal) override
83  {
84  connect_signal_mouse_left_down(signal);
85  }
86 
87  /** Inherited from clickable_item. */
88  virtual void disconnect_click_handler(const event::signal_function& signal) override
89  {
90  disconnect_signal_mouse_left_down(signal);
91  }
92 
93 private:
94  /**
95  * Possible states of the widget.
96  *
97  * Note the order of the states must be the same as defined in settings.hpp.
98  */
99  enum state_t {
104  };
105 
106  void set_state(const state_t state);
107  /**
108  * Current state of the widget.
109  *
110  * The state of the widget determines what to render and how the widget
111  * reacts to certain 'events'.
112  */
114 
115  /** The timer for the repeating events. */
116  std::size_t repeat_timer_;
117 
118 public:
119  /** Static type getter that does not rely on the widget being constructed. */
120  static const std::string& type();
121 
122 private:
123  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
124  virtual const std::string& get_control_type() const override;
125 
126  /***** ***** ***** signal handlers ***** ****** *****/
127 
128  void signal_handler_mouse_enter(const event::ui_event event, bool& handled);
129 
130  void signal_handler_mouse_leave(const event::ui_event event, bool& handled);
131 
132  void signal_handler_left_button_down(const event::ui_event event,
133  bool& handled);
134 
135  void signal_handler_left_button_up(const event::ui_event event,
136  bool& handled);
137 };
138 
139 // }---------- DEFINITION ---------{
140 
142 {
143  explicit repeating_button_definition(const config& cfg);
144 
146  {
147  explicit resolution(const config& cfg);
148  };
149 };
150 
151 // }---------- BUILDER -----------{
152 
153 namespace implementation
154 {
155 
157 {
158 public:
159  explicit builder_repeating_button(const config& cfg);
160 
162 
163  virtual widget* build() const override;
164 };
165 
166 } // namespace implementation
167 
168 // }------------ END --------------
169 
170 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
state_t
Possible states of the widget.
Base class for all widgets.
Definition: widget.hpp:49
dispatcher_callback_func<> signal_function
Callback function signature.
Definition: dispatcher.hpp:198
state_t state_
Current state of the widget.
Generic file dialog.
Definition: field-fwd.hpp:23
std::size_t repeat_timer_
The timer for the repeating events.
virtual void disconnect_click_handler(const event::signal_function &signal) override
Inherited from clickable_item.
Base class for all visible items.
virtual void connect_click_handler(const event::signal_function &signal) override
Inherited from clickable_item.
Small concept class.
point resolution()
Definition: general.cpp:393
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
A repeating_button is a control that can be pushed down and repeat a certain action.
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
ui_event
The event send to the dispatcher.
Definition: handler.hpp:48