The Battle for Wesnoth  1.19.2+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 
33 {
34 public:
37 
38  /**
39  * Connects a signal handler for a left mouse button down.
40  *
41  * This event is triggered when the button is pressed and, as long as the
42  * button stays down, every x ms afterwards.
43  *
44  * @param signal The signal to connect.
45  */
47 
48  /**
49  * Disconnects a signal handler for a left mouse button down.
50  *
51  * @param signal The signal to disconnect (should be the same
52  * as send to the connect call.
53  */
54  void
56 
57  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
58 
59  /** See @ref styled_widget::set_active. */
60  virtual void set_active(const bool active) override;
61 
62  /** See @ref styled_widget::get_active. */
63  virtual bool get_active() const override;
64 
65  /** See @ref styled_widget::get_state. */
66  virtual unsigned get_state() const override;
67 
68  /** Inherited from clickable_item. */
69  virtual void connect_click_handler(const event::signal& signal) override
70  {
72  }
73 
74  /** Inherited from clickable_item. */
75  virtual void disconnect_click_handler(const event::signal& signal) override
76  {
78  }
79 
80 private:
81  /**
82  * Possible states of the widget.
83  *
84  * Note the order of the states must be the same as defined in settings.hpp.
85  */
86  enum state_t {
91  };
92 
93  void set_state(const state_t state);
94  /**
95  * Current state of the widget.
96  *
97  * The state of the widget determines what to render and how the widget
98  * reacts to certain 'events'.
99  */
101 
102  /** The timer for the repeating events. */
103  std::size_t repeat_timer_;
104 
105 public:
106  /** Static type getter that does not rely on the widget being constructed. */
107  static const std::string& type();
108 
109 private:
110  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
111  virtual const std::string& get_control_type() const override;
112 
113  /***** ***** ***** signal handlers ***** ****** *****/
114 
115  void signal_handler_mouse_enter(const event::ui_event event, bool& handled);
116 
117  void signal_handler_mouse_leave(const event::ui_event event, bool& handled);
118 
120  bool& handled);
121 
123  bool& handled);
124 };
125 
126 // }---------- DEFINITION ---------{
127 
129 {
130  explicit repeating_button_definition(const config& cfg);
131 
133  {
134  explicit resolution(const config& cfg);
135  };
136 };
137 
138 // }---------- BUILDER -----------{
139 
140 namespace implementation
141 {
142 
144 {
145 public:
146  explicit builder_repeating_button(const config& cfg);
147 
149 
150  virtual std::unique_ptr<widget> build() const override;
151 };
152 
153 } // namespace implementation
154 
155 // }------------ END --------------
156 
157 } // 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.
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)
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)