The Battle for Wesnoth  1.15.12+dev
repeating_button.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
19 
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  */
58  void connect_signal_mouse_left_down(const event::signal_function& signal);
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
67  disconnect_signal_mouse_left_down(const event::signal_function& signal);
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_function& signal) override
82  {
83  connect_signal_mouse_left_down(signal);
84  }
85 
86  /** Inherited from clickable_item. */
87  virtual void disconnect_click_handler(const event::signal_function& signal) override
88  {
89  disconnect_signal_mouse_left_down(signal);
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 
131  void signal_handler_left_button_down(const event::ui_event event,
132  bool& handled);
133 
134  void signal_handler_left_button_up(const event::ui_event event,
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 widget* build() const override;
163 };
164 
165 } // namespace implementation
166 
167 // }------------ END --------------
168 
169 } // 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:197
state_t state_
Current state of the widget.
Generic file dialog.
Definition: field-fwd.hpp:22
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:387
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:59
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:47