The Battle for Wesnoth  1.19.0-dev
repeating_button.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
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  */
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
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& signal) override
83  {
85  }
86 
87  /** Inherited from clickable_item. */
88  virtual void disconnect_click_handler(const event::signal& signal) override
89  {
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 
133  bool& handled);
134 
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 std::unique_ptr<widget> build() const override;
164 };
165 
166 } // namespace implementation
167 
168 // }------------ END --------------
169 
170 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
Small concept class.
A repeating_button is a control that can be pushed down and repeat a certain action.
void set_state(const state_t state)
virtual unsigned get_state() const override
See styled_widget::get_state.
repeating_button(const implementation::builder_repeating_button &builder)
virtual void disconnect_click_handler(const event::signal &signal) override
Inherited from clickable_item.
state_t state_
Current state of the widget.
virtual void connect_click_handler(const event::signal &signal) override
Inherited from clickable_item.
std::size_t repeat_timer_
The timer for the repeating events.
virtual void set_active(const bool active) override
See styled_widget::set_active.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
state_t
Possible states of the widget.
void signal_handler_left_button_down(const event::ui_event event, bool &handled)
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
void connect_signal_mouse_left_down(const event::signal &signal)
Connects a signal handler for a left mouse button down.
virtual bool get_active() const override
See styled_widget::get_active.
void disconnect_signal_mouse_left_down(const event::signal &signal)
Disconnects a signal handler for a left mouse button down.
void signal_handler_mouse_leave(const event::ui_event event, bool &handled)
void signal_handler_left_button_up(const event::ui_event event, bool &handled)
void signal_handler_mouse_enter(const event::ui_event event, bool &handled)
Base class for all visible items.
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
dispatcher_callback<> signal
Used for events in event_category::general.
Definition: dispatcher.hpp:58
Generic file dialog.
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual std::unique_ptr< widget > build() const override
virtual std::unique_ptr< widget > build() const=0
repeating_button_definition(const config &cfg)
Base class of a resolution, contains the common keys for a resolution.