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 
22 
23 namespace gui2
24 {
25 namespace implementation
26 {
27 struct builder_repeating_button;
28 }
29 
30 // ------------ WIDGET -----------{
31 
32 /**
33  * @ingroup GUIWidgetWML
34  *
35  * A repeating_button is a control that can be pushed down and repeat a certain action.
36  * Once the button is down every x milliseconds it is down a new down event is triggered.
37  *
38  * The following states exist:
39  * * state_enabled - the repeating_button is enabled.
40  * * state_disabled - the repeating_button is disabled.
41  * * state_pressed - the left mouse repeating_button is down.
42  * * state_focussed - the mouse is over the repeating_button.
43  */
45 {
46 public:
49 
50  /**
51  * Connects a signal handler for a left mouse button down.
52  *
53  * This event is triggered when the button is pressed and, as long as the
54  * button stays down, every x ms afterwards.
55  *
56  * @param signal The signal to connect.
57  */
59 
60  /**
61  * Disconnects a signal handler for a left mouse button down.
62  *
63  * @param signal The signal to disconnect (should be the same
64  * as send to the connect call.
65  */
66  void
68 
69  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
70 
71  /** See @ref styled_widget::set_active. */
72  virtual void set_active(const bool active) override;
73 
74  /** See @ref styled_widget::get_active. */
75  virtual bool get_active() const override;
76 
77  /** See @ref styled_widget::get_state. */
78  virtual unsigned get_state() const override;
79 
80  /** Inherited from clickable_item. */
81  virtual void connect_click_handler(const event::signal& signal) override
82  {
84  }
85 
86  /** Inherited from clickable_item. */
87  virtual void disconnect_click_handler(const event::signal& signal) override
88  {
90  }
91 
92 private:
93  /**
94  * Possible states of the widget.
95  *
96  * Note the order of the states must be the same as defined in settings.hpp.
97  */
98  enum state_t {
103  };
104 
105  void set_state(const state_t state);
106  /**
107  * Current state of the widget.
108  *
109  * The state of the widget determines what to render and how the widget
110  * reacts to certain 'events'.
111  */
113 
114  /** The timer for the repeating events. */
115  std::size_t repeat_timer_;
116 
117 public:
118  /** Static type getter that does not rely on the widget being constructed. */
119  static const std::string& type();
120 
121 private:
122  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
123  virtual const std::string& get_control_type() const override;
124 
125  /***** ***** ***** signal handlers ***** ****** *****/
126 
127  void signal_handler_mouse_enter(const event::ui_event event, bool& handled);
128 
129  void signal_handler_mouse_leave(const event::ui_event event, bool& handled);
130 
132  bool& handled);
133 
135  bool& handled);
136 };
137 
138 // }---------- DEFINITION ---------{
139 
141 {
142  explicit repeating_button_definition(const config& cfg);
143 
145  {
146  explicit resolution(const config& cfg);
147  };
148 };
149 
150 // }---------- BUILDER -----------{
151 
152 namespace implementation
153 {
154 
156 {
157 public:
158  explicit builder_repeating_button(const config& cfg);
159 
161 
162  virtual std::unique_ptr<widget> build() const override;
163 };
164 
165 } // namespace implementation
166 
167 // }------------ END --------------
168 
169 } // 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:56
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.