The Battle for Wesnoth  1.15.0-dev
dispatcher.cpp
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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #include "gui/core/log.hpp"
21 
22 namespace gui2
23 {
24 namespace event
25 {
26 /***** dispatcher class. *****/
27 
29  : mouse_behavior_(all)
30  , want_keyboard_input_(true)
31  , signal_queue_()
32  , signal_mouse_queue_()
33  , signal_keyboard_queue_()
34  , signal_touch_motion_queue_()
35  , signal_touch_gesture_queue_()
36  , signal_notification_queue_()
37  , signal_message_queue_()
38  , connected_(false)
39  , hotkeys_()
40 {
41 }
42 
44 {
45  if(connected_) {
47  }
48 }
49 
51 {
52  assert(!connected_);
53  connected_ = true;
54  connect_dispatcher(this);
55 }
56 
57 bool dispatcher::has_event(const ui_event event, const event_queue_type event_type)
58 {
59 #if 0
60  // Debug code to test whether the event is in the right queue.
61  std::cerr << "Event '" << event
62  << "' event "
63  << find<set_event>(event, dispatcher_implementation
64  ::has_handler(event_type, *this))
65  << " mouse "
66  << find<set_event_mouse>(event, dispatcher_implementation
67  ::has_handler(event_type, *this))
68  << " keyboard "
69  << find<set_event_touch_motion>(event, dispatcher_implementation
70  ::has_handler(event_type, *this))
71  << " touch_motion "
72  << find<set_event_touch_gesture>(event, dispatcher_implementation
73  ::has_handler(event_type, *this))
74  << " touch_gesture "
75  << find<set_event_keyboard>(event, dispatcher_implementation
76  ::has_handler(event_type, *this))
77  << " notification "
78  << find<set_event_notification>(event, dispatcher_implementation
79  ::has_handler(event_type, *this))
80  << " message "
81  << find<set_event_message>(event, dispatcher_implementation
82  ::has_handler(event_type, *this))
83  << ".\n";
84 #endif
85 
86  return find<set_event>(
87  event, dispatcher_implementation::has_handler(event_type, *this))
88  || find<set_event_mouse>(
89  event, dispatcher_implementation::has_handler(event_type, *this))
90  || find<set_event_keyboard>(
91  event, dispatcher_implementation::has_handler(event_type, *this))
92  || find<set_event_text_input>(
93  event, dispatcher_implementation::has_handler(event_type, *this))
94  || find<set_event_touch_motion>(
95  event, dispatcher_implementation::has_handler(event_type, *this))
96  || find<set_event_touch_gesture>(
97  event, dispatcher_implementation::has_handler(event_type, *this))
98  || find<set_event_notification>(
99  event, dispatcher_implementation::has_handler(event_type, *this))
100  || find<set_event_message>(
101  event, dispatcher_implementation::has_handler(event_type, *this))
102  || find<set_event_raw_event>(
103  event, dispatcher_implementation::has_handler(event_type, *this));
104 }
105 
106 /**
107  * Helper class to do a runtime test whether an event is in a set.
108  *
109  * The class is supposed to be used in combination with find function. This
110  * function is used in the fire functions to make sure an event is send to the
111  * proper handler. If not there will be a run-time assertion failure. This
112  * makes developing and testing the code easier, a wrong handler terminates
113  * Wesnoth instead of silently not working.
114  */
116 {
117 public:
118  /**
119  * If found we get executed to set the result.
120  *
121  * Since we need to return true if found we always return true.
122  */
123  template <class T>
125  {
126  return true;
127  }
128 };
129 
130 bool dispatcher::fire(const ui_event event, widget& target)
131 {
132  assert(find<set_event>(event, event_in_set()));
133  switch(event) {
137 
140  &event_executor::wants_mouse_middle_double_click, signal_function>(this, &target);
141 
144  &event_executor::wants_mouse_right_double_click, signal_function>(this, &target);
145 
146  default:
147  return fire_event<signal_function>(event, this, &target);
148  }
149 }
150 
151 bool dispatcher::fire(const ui_event event, widget& target, const point& coordinate)
152 {
153  assert(find<set_event_mouse>(event, event_in_set()));
154  return fire_event<signal_mouse_function>(event, this, &target, coordinate);
155 }
156 
157 bool dispatcher::fire(const ui_event event,
158  widget& target,
159  const SDL_Keycode key,
160  const SDL_Keymod modifier,
161  const std::string& unicode)
162 {
163  assert(find<set_event_keyboard>(event, event_in_set()));
164  return fire_event<signal_keyboard_function>(event, this, &target, key, modifier, unicode);
165 }
166 
167 bool dispatcher::fire(const ui_event event, widget& target, const point& pos, const point& distance)
168 {
169  assert(find<set_event_touch_motion>(event, event_in_set()));
170  return fire_event<signal_touch_motion_function>(event, this, &target, pos, distance);
171 }
172 
173 bool dispatcher::fire(const ui_event event, widget& target, const point& center, float dTheta, float dDist, Uint8 numFingers)
174 {
175  assert(find<set_event_touch_gesture>(event, event_in_set()));
176  return fire_event<signal_touch_gesture_function>(event, this, &target, center, dTheta, dDist, numFingers);
177 }
178 
179 bool dispatcher::fire(const ui_event event, widget& target, const SDL_Event& sdlevent)
180 {
181  assert(find<set_event_raw_event>(event, event_in_set()));
182  return fire_event<signal_raw_event_function>(event, this, &target, sdlevent);
183 }
184 
185 bool dispatcher::fire(const ui_event event, widget& target, const std::string& text, int32_t start, int32_t len)
186 {
187  assert(find<set_event_text_input>(event, event_in_set()));
188  return fire_event<signal_text_input_function>(event, this, &target, text, start, len);
189 }
190 
191 bool dispatcher::fire(const ui_event event, widget& target, void*)
192 {
193  assert(find<set_event_notification>(event, event_in_set()));
194  return fire_event<signal_notification_function>(event, this, &target, nullptr);
195 }
196 
197 bool dispatcher::fire(const ui_event event, widget& target, const message& msg)
198 {
199  assert(find<set_event_message>(event, event_in_set()));
200  return fire_event<signal_message_function>(event, this, &target, msg);
201 }
202 
204 {
205  hotkeys_[id] = function;
206 }
207 
209 {
211 
212  if(itor == hotkeys_.end()) {
213  return false;
214  }
215 
216  itor->second(dynamic_cast<widget&>(*this), id);
217 
218  /* NOTE: hotkey events used to return bool to indicate was-handled status. However,
219  * every single usecase was returning true and cluttering up the code. I changed
220  * the signature to return void, but if there's ever a need to restore the bool
221  * retval on the hotkey functions, this is where it should be handled.
222  *
223  * -- vultraz, 2017-11-27
224  */
225  return true;
226 }
227 
229 {
231 }
232 
234 {
235  dispatcher.connect_signal<LEFT_BUTTON_CLICK>(signal);
236 }
237 
239 {
240  dispatcher.disconnect_signal<LEFT_BUTTON_CLICK>(signal);
241 }
242 
244 {
246 }
247 
249 {
250  dispatcher.connect_signal<NOTIFY_MODIFIED>(signal);
251 }
252 
254 {
255  // TODO: evaluate whether draw events need go in this queue position.
256  dispatcher.connect_signal<DRAW>(signal, dispatcher::front_child);
257 }
258 
259 } // namespace event
260 
261 } // namespace gui2
262 
263 /**
264  * @page event_dispatching Event dispatching.
265  *
266  * @section introduction Introduction
267  *
268  * This page describes how the new event handling system works, since the
269  * system is still work in progress it might be out of date with the actual
270  * code. It also contains some ideas that might change later on. Some parts are
271  * explained in the interface and will be integrated in this document later.
272  *
273  * Since the event handling code hasn't been cast in stone yet some scenarios
274  * for solving the problem are discussed first and then the solution that is
275  * chosen in more detail.
276  *
277  * After SDL has generated and event it needs to be turned into an event which
278  * the widgets can use.
279  *
280  * @section handling_solution The implementation solutions.
281  *
282  * For the event handling we use a few use case scenarios and show the possible
283  * solutions.
284  *
285  * @subsection sample The sample window
286  *
287  * In our samples we use this sample window with the following components:
288  * - a window W
289  * - a container C
290  * - a button B
291  *
292  * These are arranged accordingly:
293  * @code
294  *
295  * ---------------------
296  * |W |
297  * | |
298  * | ----------------- |
299  * | |C |^| |
300  * | | |-| |
301  * | | ---------- |#| |
302  * | | |B | | | |
303  * | | ---------- | | |
304  * | | |-| |
305  * | | |v| |
306  * | ----------------- |
307  * | |
308  * ---------------------
309  *
310  * @endcode
311  *
312  * @subsection scenarios Possible scenarios
313  *
314  * The scenarios are:
315  * - An event that is wanted by none.
316  * - A mouse down event that should focus C and set the pressed state in B.
317  * - A mouse wheel event, which first should be offered to B and if not handled
318  * by B should be handled by C.
319  *
320  * @subsection all_queues Pass the event through all queues
321  *
322  * In this solution the event will be passed through all possible queues and
323  * tries sees where the event sticks. This following sections describe how the
324  * events are tried for this usage scenario.
325  *
326  * @subsubsection unhandled Unhandled event
327  *
328  * - W pre child
329  * - C pre child
330  * - B pre child
331  * - W child
332  * - C child
333  * - B child
334  * - W post child
335  * - C post child
336  * - B post child
337  *
338  * @subsubsection mouse_down Mouse down
339  *
340  * - W pre child
341  * - C pre child -> set focus -> !handled
342  * - B pre child -> set pressed state -> handled
343  *
344  * @subsubsection mouse_wheel Mouse wheel
345  *
346  * - W pre child
347  * - C pre child
348  * - B pre child -> We can't scroll so ignore
349  * - W child
350  * - C child
351  * - B child
352  * - W post child
353  * - C post child -> Scroll -> handled
354  *
355  * @subsection chain Pass the events in a chain like fashion
356  *
357  * In this solution the events are send to the pre- and post queue of all but
358  * the last possible widget and to the child of the last widget. The pre queue
359  * will be send from top to bottom, the post queue from bottom to top.
360  *
361  * @subsubsection unhandled Unhandled event
362  *
363  * - W pre child
364  * - C pre child
365  * - B child
366  * - C post child
367  * - W post child
368  *
369  * @subsubsection mouse_down Mouse down
370  *
371  * - W pre child
372  * - C pre child -> set focus -> !handled
373  * - B child -> set pressed state -> handled
374  *
375  * @subsubsection mouse_wheel Mouse wheel
376  *
377  * - W pre child
378  * - C pre child
379  * - B child -> We can't scroll so ignore
380  * - C post child -> Scroll -> handled
381  *
382  * @subsection evaluation Evaluation
383  *
384  * When using the first solution it's possible to drop the child queue since
385  * everything falls in pre or post. But there is a scenario that's a bit ugly
386  * to solve with the first solution:
387  *
388  * Assume there is a listbox with toggle panels and on the panel there are a
389  * few buttons, the wanted behavior is:
390  * - if clicked on the panel it should toggle, which may or may not be allowed.
391  * - if clicked on a button in the panel, we want to make sure the panel is
392  * selected, which again may or may not be allowed.
393  *
394  * With solution 2 it's rather easy:
395  *
396  * Click on panel:
397  * - W pre child
398  * - C child -> Test whether we can toggle -> handled, halt = !toggled
399  *
400  * Click on button in panel:
401  * - W pre child
402  * - C pre child -> Test whether we can select -> handled = halt = !selected
403  * - B child -> do button stuff -> handled
404  *
405  * Since for the different clicks, different queues are triggered it's easy to
406  * add a different handler there.
407  *
408  * With solution 1:
409  *
410  * Click on panel:
411  * - W pre child
412  * - C pre child -> handler 1 -> if last in queue -> solution 2 C child
413  *
414  * Click on button in panel:
415  * - W pre child
416  * - C pre child -> handler 2 -> if !last in queue -> solution 2 C pre child
417  * - B pre child -> do button stuff -> handled
418  *
419  * Not that different from solution 2, the two handlers are installed in the C
420  * pre event. But we need to manually check whether we're really the last,
421  * which means the code to check whether there are more handlers at a lower
422  * level is needed for both solutions. In solution 1 this test needs to be done
423  * twice versus once in solution 2. Also the fact that the queues for the
424  * events are processed in reverse order on the way back sounds more
425  * initiative.
426  *
427  * @section processing_raw_events Processing the raw events.
428  *
429  * This section describes how the events generated by SDL are send as our own
430  * events to the various widgets. The first step in sending an event is to
431  * decode it and send it to a registered dispatcher.
432  *
433  * - gui2::event::sdl_event_handler handles the SDL events.
434  * - gui2::event::dispatcher has the registered dispatchers.
435  *
436  * In general a dispatcher is a window which then needs to send this event to
437  * the widgets. The dispatcher is just a simple part which fires events and
438  * finds a handler for the event. This is not to the liking of most widgets,
439  * they don't want to handle raw events but get a polished and clean event. No
440  * button up and down and then try to figure out whether it needs to act as if
441  * it was clicked upon, no simply op and down to change the appearance and a
442  * click event to do the clicking actions. And don't even try to convince a
443  * widget to determine whether this up event was a single or double click.
444  * Widgets like to sleep with nice dreams and not having nightmares where SDL
445  * events haunt them.
446  *
447  * In order to remedy that problem there's the gui2::event::distributor
448  * class, it's the class to do the dirty job of converting the raw event into
449  * these nice polished events. The distributor is in general linked to a window,
450  * but a widget can install it's own distributor if it needs to know more of the
451  * raw events as still left in the polished events. At the time of this writing
452  * no widget needs this feature, but the toggle panel might need it.
453  *
454  * After the distributor has polished the event and send it on its way to the
455  * widget the dispatcher needs to make sure the event is properly dispatched to
456  * the widget in question and also notify its parents by means of the previously
457  * described event chain.
458  *
459  * @subsection sdl_event Get the SDL events
460  *
461  * The first step in event handling is getting the events in the first place.
462  * Events are generated by SDL and placed in a queue. The Wesnoth code processes
463  * this queue and thus handles the events. The part which does the first
464  * handling isn't described here since it's (secretly) intended to be replaced
465  * by the @ref gui2::event::sdl_event_handler class. Instead we directly jump to this
466  * class and explain what it does.
467  *
468  * The main handling function is @ref gui2::event::sdl_event_handler::handle_event which
469  * as no real surprise handles the events. The function is a simple multiplexer
470  * which lets other subfunctions to the handling of specific events.
471  *
472  * @todo Describe drawing and resizing once the code is stable and working as
473  * wanted in these areas.
474  *
475  * @subsubsection handler_mouse Mouse motion events
476  *
477  * If a dispatcher has captured the mouse it gets the event, no questions asked.
478  * If not it goes through all dispatchers and finds the first one willing to
479  * accept the mouse event.
480  *
481  * This means a mouse event is send to one dispatcher.
482  *
483  * @subsubsection handler_mouse_button_down Mouse button down events
484  *
485  * Turning the mouse wheel on a mouse generates both an down and up event. It
486  * has been decided to handle the wheel event in the button up code so wheel
487  * events are here directly dropped on the floor and forgotten.
488  *
489  * The other buttons are handled as if they're normal mouse events but are
490  * decoded per button so instead of a button_down(id) you get button_down_id.
491  *
492  * @subsubsection handler_mouse_button_up Mouse button up events
493  *
494  * The mouse wheel event is handled as if it's a keyboard event and like the
495  * button_down they are send as wheel_id events.
496  *
497  * The other mouse buttons are handled the same as the down buttons.
498  *
499  * @subsubsection handler_keyboard Keyboard events
500  *
501  * There are three types of keyboard events, the already mentioned mouse wheel
502  * events, the key down and key up event. When a key is pressed for a longer
503  * time several key down events are generated and only one key up, this means
504  * the key up is rather useless. Guess what, the multiplexer already drops that
505  * event so we never get it.
506  *
507  * If the keyboard event is a mouse wheel event it's directly send to the
508  * dispachting queue; either the dispatcher that captured the keyboard or the
509  * last dispatcher in the queue.
510  *
511  * If the event is a real keyboard action it's first tried as hotkey. In order
512  * to do so the target dispatcher is first determined, either the dispatcher
513  * that captured the keyboard or the last dispatcher in the queue. Then it's
514  * tried whether a hotkey and whether the hotkey can be processed. If the
515  * hotkey isn't processed the keyboard event is send to the dispatcher as
516  * normal keyboard event.
517  *
518  * The hotkey processing will have several queues (to be implemented in 1.9):
519  * - global hotkeys that always work eg toggling fullscreen mode.
520  * - main screen hotkeys, these work when one of the dialogs is shown without
521  * other dialogs on top of them. These hotkeys are for example
522  * preferences. The main screens are:
523  * - title screen
524  * - game
525  * - editor
526  * - mp lobby
527  * - map screen hotkeys, these work when a map is shown eg toggle grid. The
528  * screens are:
529  * - game
530  * - editor
531  * - local hotkeys, these are hotkeys that only work in a specific dialog eg
532  * recruit unit only works in the game screen.
533  *
534  * The queues are processed in from bottom to top in the list above, this
535  * allows an item to use a hotkey but have another handler function. Eg
536  * preferences in the editor might open another preferences dialog.
537  *
538  * @todo The hotkeys need to be implemented like above in 1.9.
539  *
540  * @todo This might change in the near future.
541  *
542  * @subsection distributor Event polishing and distribution
543  *
544  * The event distributor has the job to find the widget that should receive the
545  * event and which event(s) to send from a single event. In general an event is
546  * first send to the widget as-is, sending the raw events allows other
547  * distributors to be nested between this distributor and the intended target
548  * widget. Or the intended widget might not really be the intended widget but
549  * another distributor that wants to dispatch the event internally.
550  *
551  * However in the common cases this raw event isn't handled and the distributor
552  * needs to send the polished events. In the following sections the details of
553  * the conversion from raw to polished is described, it intentionally lacks the
554  * part of sending the raw events as well since it adds no value.
555  *
556  * A widget can capture the mouse, which means all mouse events are send to this
557  * widget, regardless where the mouse is. This is normally done in a mouse down
558  * event (for a button) so all events following it are send to that widget.
559  *
560  * @subsection mouse_motion Mouse motion
561  *
562  * This section describes the conversion from a raw mouse motion to the polished
563  * events it can generate:
564  * - @ref gui2::event::MOUSE_ENTER "MOUSE_ENTER"
565  * - @ref gui2::event::MOUSE_LEAVE "MOUSE_LEAVE"
566  * - @ref gui2::event::MOUSE_MOTION "MOUSE_MOTION"
567  *
568  * When the mouse is captured that widget will only receive motion events.
569  *
570  * If not captured the code checks whether the widget underneath the mouse is
571  * the same widget as at the last motion if event. If so that widget gets a
572  * motion event.
573  * If not the widget that before was underneath the mouse pointer (if any) gets
574  * a leave event and the widget newly underneath the mouse pointer (if any) gets
575  * an enter event.
576  *
577  * @subsection mouse_button Mouse buttons
578  *
579  * The mouse button code is a bit more complex and is separated in the various
580  * events to be send.
581  *
582  * @subsubsection mouse_button_down Mouse button down
583  *
584  * Some things start simple, so does the event of pressing down a mouse button.
585  * All it does is send the event to the widget as one of the following events:
586  * - @ref gui2::event::LEFT_BUTTON_DOWN "LEFT_BUTTON_DOWN"
587  * - @ref gui2::event::MIDDLE_BUTTON_DOWN "MIDDLE_BUTTON_DOWN"
588  * - @ref gui2::event::RIGHT_BUTTON_DOWN "RIGHT_BUTTON_DOWN"
589  *
590  * @todo Validate the code it seems a down event with a captured mouse doesn't
591  * really work as wanted. (Rare case but should work properly.) In general the
592  * mouse event handling needs testing to see whether the proper events are send
593  * all the time.
594  *
595  * @subsubsection mouse_button_up Mouse button up
596  *
597  * Simplicity ends here.
598  *
599  * @todo Document further.
600  *
601  * @subsubsection mouse_click Mouse click
602  *
603  * So the button up event has asked for mouse click, now we need to test whether
604  * the click will be a click or a double click. A double click is generated when
605  * the same widget is clicked twice in a short time and causes the following
606  * events:
607  * - @ref gui2::event::LEFT_BUTTON_DOUBLE_CLICK "LEFT_BUTTON_DOUBLE_CLICK"
608  * - @ref gui2::event::MIDDLE_BUTTON_DOUBLE_CLICK "MIDDLE_BUTTON_DOUBLE_CLICK"
609  * - @ref gui2::event::RIGHT_BUTTON_DOUBLE_CLICK "RIGHT_BUTTON_DOUBLE_CLICK"
610  *
611  * Otherwise one of the following single clicks is generated:
612  * - @ref gui2::event::LEFT_BUTTON_CLICK "LEFT_BUTTON_CLICK"
613  * - @ref gui2::event::MIDDLE_BUTTON_CLICK "MIDDLE_BUTTON_CLICK"
614  * - @ref gui2::event::RIGHT_BUTTON_CLICK "RIGHT_BUTTON_CLICK"
615  *
616  * @subsubsection double_click To double click or not to double click
617  *
618  * Wait a second, a widget has a field whether or not it wants a double click
619  * for a certain mouse button and now I see that it's bluntly ignored by the
620  * distributor. Indeed the distributor doesn't care about what the widget wants,
621  * it does what it wants and leaves the sorting out what's wanted to the
622  * dispatcher.
623  *
624  * The problem is that in the chain events are send to one widget that may not
625  * be interested in a double click, but another widget in the chain is. There
626  * are several solutions to this problem:
627  * -# Sending a click followed by a double click.
628  * -# Sending a click with a tag field that it actually is a double click.
629  * -# Send a double click and turn it into a click if the double click is
630  * unwanted.
631  *
632  * The first solution has the disadvantage that a toggle panel likes a click and
633  * double click, the first click selects the second deselects and now the
634  * deselected panel gets a double click. When the panel now checks whether it's
635  * selected it's not and might take the wrong action upon it.
636  *
637  * The second option is possible but would be rather intrusive in the code,
638  * since it would generate another event signature. Adding a signature just for
639  * this special case seemed a bit too much effort vs. gain. Also the widget
640  * needs to check whether a click is a click or a double click and choose a
641  * different code path for it. This in turn would mean a signal handler
642  * secretly might handle two events and lowers the transparency of the code.
643  *
644  * The third option also adds some special case handling but the scope is
645  * limited and only one part knows about the tricks done.
646  *
647  * The last option has been chosen and the dispatcher build the event chain and
648  * while building the chain it looks whether the widget wants the double click
649  * or not. It does this test by looking at the wants double click function and
650  * not test for a handler. The double click test function is made for this
651  * purpose and depending on the handler might again do the wrong thing.
652  * (A certain toggle panel might not want to do something on a double click but
653  * also not being deselected upon a double click. The latter to keep the UI
654  * consistent, a double click on a toggle panel might execute a special function
655  * or not, but always keep the panel selected. (That is if the panel can be
656  * selected.))
657  */
Define the common log macros for the gui toolkit.
bool oper(ui_event)
If found we get executed to set the result.
Definition: dispatcher.cpp:124
Base class for event handling.
Definition: dispatcher.hpp:172
void register_hotkey(const hotkey::HOTKEY_COMMAND id, const hotkey_function &function)
Registers a hotkey.
Definition: dispatcher.cpp:203
See LEFT_BUTTON_CLICK.
Definition: handler.hpp:84
bool fire_event_double_click(dispatcher *dsp, widget *wgt, F &&... params)
An SDL key down event.
Definition: handler.hpp:91
Base class for all widgets.
Definition: widget.hpp:47
See LEFT_BUTTON_DOUBLE_CLICK.
Definition: handler.hpp:85
See LEFT_BUTTON_CLICK.
Definition: handler.hpp:77
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, const SDL_Keycode key, const SDL_Keymod modifier, const std::string &unicode)> signal_keyboard_function
Callback function signature.
Definition: dispatcher.hpp:78
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
std::enable_if_t< has_key< set_event, E >::value > connect_signal(const signal_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event.
Definition: dispatcher.hpp:393
Helper class to do a runtime test whether an event is in a set.
Definition: dispatcher.cpp:115
bool has_event(const ui_event event, const event_queue_type event_type)
Definition: dispatcher.cpp:57
Generic file dialog.
Definition: field-fwd.hpp:22
Sent by a widget to notify others its contents or state are modified.
Definition: handler.hpp:96
The message callbacks hold a reference to a message.
Definition: message.hpp:45
void connect()
Connects the dispatcher to the event handler.
Definition: dispatcher.cpp:50
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:248
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:233
Periodic redraw request.
Definition: handler.hpp:57
std::enable_if_t< has_key< set_event, E >::value > disconnect_signal(const signal_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_event.
Definition: dispatcher.hpp:411
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
Definition: dispatcher.cpp:208
void disconnect_dispatcher(dispatcher *dispatcher)
Disconnects a dispatcher to the event handler.
Definition: handler.cpp:900
This file contains the definitions for the gui2::event::message class.
std::function< void(widget &dispatcher, hotkey::HOTKEY_COMMAND id)> hotkey_function
Hotkey function handler signature.
Definition: dispatcher.hpp:155
void connect_dispatcher(dispatcher *dispatcher)
Connects a dispatcher to the event handler.
Definition: handler.cpp:893
void connect_signal_mouse_left_double_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button double click.
Definition: dispatcher.cpp:243
bool wants_mouse_right_double_click() const
std::map< hotkey::HOTKEY_COMMAND, hotkey_function > hotkeys_
The registered hotkeys for this dispatcher.
Definition: dispatcher.hpp:914
bool connected_
Are we connected to the event handler.
Definition: dispatcher.hpp:911
A left mouse button double click event for a widget.
Definition: handler.hpp:71
Holds a 2D point.
Definition: point.hpp:23
hotkey_list hotkeys_
Definition: hotkey_item.cpp:40
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt)> signal_function
Callback function signature.
Definition: dispatcher.hpp:42
A helper class to find out whether dispatcher has an handler for a certain event. ...
bool wants_mouse_left_double_click() const
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard_function &signal)
Connects the signal for &#39;snooping&#39; on the keypress.
Definition: dispatcher.cpp:228
void disconnect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Disconnects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:238
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:130
EXIT_STATUS start(const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
Definition: editor_main.cpp:28
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, void *)> signal_notification_function
Callback function signature.
Definition: dispatcher.hpp:117
See LEFT_BUTTON_DOUBLE_CLICK.
Definition: handler.hpp:78
bool wants_mouse_middle_double_click() const
A left mouse button click event for a widget.
Definition: handler.hpp:70
std::string::const_iterator iterator
Definition: tokenizer.hpp:24
ui_event
The event send to the dispatcher.
Definition: handler.hpp:55
void connect_signal_on_draw(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a callback when the widget is drawn.
Definition: dispatcher.cpp:253