The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dispatcher.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2017 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project http://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 
20 
21 #include "utils/functional.hpp"
23 
24 #include <SDL_events.h>
25 
26 #include <boost/mpl/int.hpp>
27 
28 #include <list>
29 #include <map>
30 #include <type_traits>
31 
32 namespace gui2
33 {
34 
35 struct point;
36 class widget;
37 
38 namespace event
39 {
40 
41 template<typename K, ui_event E>
42 using has_key = boost::mpl::has_key<K, boost::mpl::int_<E>>;
43 
44 struct message;
45 
46 /**
47  * Callback function signature.
48  *
49  * There are several kinds of callback signature, this only has the parameters
50  * shared by all callbacks.
51  *
52  * This function is used for the callbacks in set_event.
53  */
54 typedef std::function<void(widget& dispatcher,
55  const ui_event event,
56  bool& handled, bool& halt)> signal_function;
57 
58 /**
59  * Callback function signature.
60  *
61  * This function is used for the callbacks in set_event_mouse.
62  */
63 typedef std::function<void(widget& dispatcher,
64  const ui_event event,
65  bool& handled,
66  bool& halt,
68 
69 /**
70  * Callback function signature.
71  *
72  * This function is used for the callbacks in set_event_keyboard.
73  */
74 typedef std::function<void(widget& dispatcher,
75  const ui_event event,
76  bool& handled,
77  bool& halt,
78  const SDL_Keycode key,
79  const SDL_Keymod modifier,
81 
82 /**
83  * Callback function signature.
84  *
85  * This function is used for the callbacks in set_event_touch.
86  */
87 typedef std::function<void(widget& dispatcher,
88  const ui_event event,
89  bool& handled,
90  bool& halt,
91  const point& pos,
92  const point& distance)> signal_touch_function;
93 
94 /**
95  * Callback function signature.
96  *
97  * This function is used for the callbacks in set_event_notification.
98  * Added the dummy void* parameter which will be nullptr to get a different
99  * signature as signal_function's callback.
100  */
101 typedef std::function<void(widget& dispatcher,
102  const ui_event event,
103  bool& handled,
104  bool& halt,
106 
107 /**
108  * Callback function signature.
109  *
110  * This function is used for the callbacks in set_event_message.
111  */
112 typedef std::function<void(widget& dispatcher,
113  const ui_event event,
114  bool& handled,
115  bool& halt,
117 
118 /**
119  * Callback function signature.
120  *
121  * This function is used for the callbacks in set_event_raw_event.
122  */
123 typedef std::function<void(widget& dispatcher,
124  const ui_event event,
125  bool& handled,
126  bool& halt,
127  const SDL_Event& sdlevent)> signal_raw_event_function;
128 
129 /**
130  * Callback function signature.
131  *
132  * This function is used for the callbacks in set_event_text_input.
133  */
134 typedef std::function<void(widget& dispatcher,
135  const ui_event event,
136  bool& handled,
137  bool& halt,
138  const std::string& text,
139  int32_t current_pos,
140  int32_t select_len)> signal_text_input_function;
141 
142 /** Hotkey function handler signature. */
143 typedef std::function<bool(widget& dispatcher,
145 
146 /**
147  * Base class for event handling.
148  *
149  * A dispatcher has slots for events, when an event arrives it looks for the
150  * functions that registered themselves for that event and calls their
151  * callbacks.
152  *
153  * This class is a base class for all widgets[1], what a widget does on a
154  * callback can differ greatly, an image might ignore all events a window can
155  * track the mouse location and fire MOUSE_ENTER and MOUSE_LEAVE events to the
156  * widgets involved.
157  *
158  * [1] Not really sure whether it will be a base class for a widget or
159  * styled_widget yet.
160  */
162 {
164 
165 public:
166  dispatcher();
167  virtual ~dispatcher();
168 
169  /**
170  * Connects the dispatcher to the event handler.
171  *
172  * When a dispatcher is connected to the event handler it will get the
173  * events directly from the event handler. This is wanted for top level
174  * items like windows but not for most other widgets.
175  *
176  * So a window can call connect to register itself, it will automatically
177  * disconnect upon destruction.
178  */
179  void connect();
180 
181  /**
182  * Determines whether the location is inside an active widget.
183  *
184  * This is used to see whether a mouse event is inside the widget.
185  *
186  * @param coordinate The coordinate to test whether inside the
187  * widget.
188  *
189  * @result True if inside an active widget, false
190  * otherwise.
191  */
192  virtual bool is_at(const point& coordinate) const = 0;
193 
195  pre = 1,
196  child = 2,
197  post = 4
198  };
199 
200  bool has_event(const ui_event event, const event_queue_type event_type);
201 
202  /** Fires an event which has no extra parameters. */
203  bool fire(const ui_event event, widget& target);
204 
205  /**
206  * Fires an event which takes a coordinate parameter.
207  *
208  * @param event The event to fire.
209  * @param target The widget that should receive the event.
210  * @param coordinate The mouse position for the event.
211  */
212  bool fire(const ui_event event,
213  widget& target,
214  const point& coordinate);
215 
216  /**
217  * Fires an event which takes keyboard parameters.
218  *
219  * @param event The event to fire.
220  * @param target The widget that should receive the event.
221  * @param key The SDL key code of the key pressed.
222  * @param modifier The SDL key modifiers used.
223  * @param unicode The unicode value for the key pressed.
224  */
225  bool fire(const ui_event event,
226  widget& target,
227  const SDL_Keycode key,
228  const SDL_Keymod modifier,
229  const utf8::string& unicode);
230 
231  /**
232  * Fires an event which takes touch parameters.
233  *
234  * @param event The event to fire.
235  * @param target The widget that should receive the event.
236  * @param pos The location touched.
237  * @param distance The distance moved.
238  */
239  bool fire(const ui_event event,
240  widget& target,
241  const point& pos,
242  const point& distance);
243 
244  /**
245  * Fires an event which takes notification parameters.
246  *
247  * @note the void* parameter is a dummy needed for SFINAE.
248  *
249  * @param event The event to fire.
250  * @param target The widget that should receive the event.
251  */
252  bool fire(const ui_event event,
253  widget& target,
254  void*);
255 
256  /**
257  * Fires an event which takes message parameters.
258  *
259  * @param event The event to fire.
260  * @param target The widget that should receive the event.
261  * Normally this is the window holding the
262  * widget.
263  * @param msg The extra information needed for a window
264  * (or another widget in the chain) to handle
265  * the message.
266  */
267  bool fire(const ui_event event,
268  widget& target,
269  message& msg);
270 
271  /**
272  * Fires an event that's a raw SDL event
273  * @param event The event to fire.
274  * @param target The widget that should receive the event.
275  * Normally this is the window holding the
276  * widget.
277  * @param sdlevent The raw SDL event
278  */
279  bool fire(const ui_event event,
280  widget& target,
281  const SDL_Event& sdlevent);
282 
283  /**
284  * Fires an event which takes text input parameters
285  * @param event The event to fire.
286  * @param target The widget that should receive the event.
287  * Normally this is the window holding the
288  * widget.
289  * @param text The text involved in the event
290  * @param start The start point for IME editing
291  * @param len The selection length for IME editing
292  */
293  bool fire(const ui_event event,
294  widget& target,
295  const std::string& text,
296  int32_t start,
297  int32_t len);
298 
299  /**
300  * The position where to add a new callback in the signal handler.
301  *
302  * The signal handler has three callback queues:
303  * * pre_child These callbacks are called before a container widget sends it
304  * to the child items. Widgets without children should also use this
305  * queue.
306  * * child The callbacks for the proper child widget(s) are called.
307  * * post_child The callbacks for the parent container to be called after
308  * the child.
309  *
310  * For every queue it's possible to add a new event in the front or in the
311  * back.
312  *
313  * Whether all three queues are executed depend on the whether the
314  * callbacks modify the handled and halt flag.
315  * * When the halt flag is set execution of the current queue stops, when
316  * doing so the handled flag must be set as well.
317  * * When the handled flag is set the events in that queue are executed and
318  * no more queues afterwards.
319  *
320  * Here are some use case examples.
321  * A button that plays a sound and executes an optional user callback:
322  * * The buttons internal click handler is invoked and sets the handled
323  * flag
324  * * The callback installed by the user is in the same queue and gets
325  * executed afterwards.
326  *
327  * A toggle button may or may not be toggled:
328  * * The user inserts a callback, that validates whether the action is
329  * allowed, if not allowed it sets the halt flag (and handled), else
330  * leaves the flags untouched.
331  * * The normal buttons toggle function then might get invoked and if so
332  * sets the handled flag.
333  * * Optionally there is another user callback invoked at this point.
334  */
342  };
343 
344  /**
345  * Connect a signal for callback in set_event.
346  *
347  * The function uses some enable_if magic to avoid registering the wrong
348  * function, but the common way to use this function is:
349  * widget->connect_signal<EVENT_ID>(
350  * std::bind(&tmy_dialog::my_member, this));
351  * This allows simply adding a member of a dialog to be used as a callback
352  * for widget without a lot of magic. Note most widgets probably will get a
353  * callback like
354  * connect_signal_mouse_left_click(const signal_function& callback)
355  * which hides this function for the average use.
356  *
357  * @tparam E The event the callback needs to react to.
358  * @param signal The callback function.
359  * @param position The position to place the callback.
360  */
361  template <ui_event E>
363  connect_signal(const signal_function& signal,
364  const queue_position position = back_child)
365  {
366  signal_queue_.connect_signal(E, position, signal);
367  }
368 
369  /**
370  * Disconnect a signal for callback in set_event.
371  *
372  * @tparam E The event the callback was used for.
373  * @param signal The callback function.
374  * @param position The place where the function was added.
375  * Needed remove the event from the right
376  * place. (The function doesn't care whether
377  * was added in front or back.)
378  */
379  template <ui_event E>
381  disconnect_signal(const signal_function& signal,
382  const queue_position position = back_child)
383  {
384  signal_queue_.disconnect_signal(E, position, signal);
385  }
386 
387  /**
388  * Connect a signal for callback in set_event_mouse.
389  *
390  * @tparam E The event the callback needs to react to.
391  * @param signal The callback function.
392  * @param position The position to place the callback.
393  */
394  template <ui_event E>
396  connect_signal(const signal_mouse_function& signal,
397  const queue_position position = back_child)
398  {
399  signal_mouse_queue_.connect_signal(E, position, signal);
400  }
401 
402  /**
403  * Disconnect a signal for callback in set_event_mouse.
404  *
405  * @tparam E The event the callback was used for.
406  * @param signal The callback function.
407  * @param position The place where the function was added.
408  * Needed remove the event from the right
409  * place. (The function doesn't care whether
410  * was added in front or back.)
411  */
412  template <ui_event E>
414  disconnect_signal(const signal_mouse_function& signal,
415  const queue_position position = back_child)
416  {
417  signal_mouse_queue_.disconnect_signal(E, position, signal);
418  }
419 
420  /**
421  * Connect a signal for callback in set_event_keyboard.
422  *
423  * @tparam E The event the callback needs to react to.
424  * @param signal The callback function.
425  * @param position The position to place the callback.
426  */
427  template <ui_event E>
429  connect_signal(const signal_keyboard_function& signal,
430  const queue_position position = back_child)
431  {
432  signal_keyboard_queue_.connect_signal(E, position, signal);
433  }
434 
435  /**
436  * Disconnect a signal for callback in set_event_keyboard.
437  *
438  * @tparam E The event the callback was used for.
439  * @param signal The callback function.
440  * @param position The place where the function was added.
441  * Needed remove the event from the right
442  * place. (The function doesn't care whether
443  * was added in front or back.)
444  */
445  template <ui_event E>
447  disconnect_signal(const signal_keyboard_function& signal,
448  const queue_position position = back_child)
449  {
450  signal_keyboard_queue_.disconnect_signal(E, position, signal);
451  }
452 
453  /**
454  * Connect a signal for callback in set_event_touch.
455  *
456  * @tparam E The event the callback needs to react to.
457  * @param signal The callback function.
458  * @param position The position to place the callback.
459  */
460  template <ui_event E>
462  connect_signal(const signal_touch_function& signal,
463  const queue_position position = back_child)
464  {
465  signal_touch_queue_.connect_signal(E, position, signal);
466  }
467 
468  /**
469  * Disconnect a signal for callback in set_event_touch.
470  *
471  * @tparam E The event the callback was used for.
472  * @param signal The callback function.
473  * @param position The place where the function was added.
474  * Needed remove the event from the right
475  * place. (The function doesn't care whether
476  * was added in front or back.)
477  */
478  template <ui_event E>
480  disconnect_signal(const signal_touch_function& signal,
481  const queue_position position = back_child)
482  {
483  signal_touch_queue_.disconnect_signal(E, position, signal);
484  }
485 
486  /**
487  * Connect a signal for callback in set_event_notification.
488  *
489  * @tparam E The event the callback needs to react to.
490  * @param signal The callback function.
491  * @param position The position to place the callback. Since
492  * the message is send to a widget directly
493  * the pre and post positions make no sense
494  * and shouldn't be used.
495  */
496  template <ui_event E>
498  connect_signal(const signal_notification_function& signal,
499  const queue_position position = back_child)
500  {
501  signal_notification_queue_.connect_signal(E, position, signal);
502  }
503 
504  /**
505  * Disconnect a signal for callback in set_event_notification.
506  *
507  * @tparam E The event the callback was used for.
508  * @param signal The callback function.
509  * @param position The place where the function was added.
510  * Needed remove the event from the right
511  * place. (The function doesn't care whether
512  * was added in front or back, but it needs
513  * to know the proper queue so it's save to
514  * add with front_child and remove with
515  * back_child. But it's not save to add with
516  * front_child and remove with
517  * front_pre_child)
518  */
519  template <ui_event E>
521  disconnect_signal(const signal_notification_function& signal,
522  const queue_position position = back_child)
523  {
524  signal_notification_queue_.disconnect_signal(E, position, signal);
525  }
526 
527  /**
528  * Connect a signal for callback in set_event_message.
529  *
530  * @tparam E The event the callback needs to react to.
531  * @param signal The callback function.
532  * @param position The position to place the callback. Since
533  * the message is send to a widget directly
534  * the pre and post positions make no sense
535  * and shouldn't be used.
536  */
537  template <ui_event E>
539  connect_signal(const signal_message_function& signal,
540  const queue_position position = back_child)
541  {
542  signal_message_queue_.connect_signal(E, position, signal);
543  }
544 
545  /**
546  * Disconnect a signal for callback in set_event_message.
547  *
548  * @tparam E The event the callback was used for.
549  * @param signal The callback function.
550  * @param position The place where the function was added.
551  * Needed remove the event from the right
552  * place. (The function doesn't care whether
553  * was added in front or back, but it needs
554  * to know the proper queue so it's save to
555  * add with front_child and remove with
556  * back_child. But it's not save to add with
557  * front_child and remove with
558  * front_pre_child)
559  */
560  template <ui_event E>
562  disconnect_signal(const signal_message_function& signal,
563  const queue_position position = back_child)
564  {
565  signal_message_queue_.disconnect_signal(E, position, signal);
566  }
567 
568  /**
569  * Connect a signal for callback in set_raw_event.
570  *
571  * @tparam E The event the callback needs to react to.
572  * @param signal The callback function.
573  * @param position The position to place the callback.
574  */
575  template <ui_event E>
577  connect_signal(const signal_raw_event_function& signal,
578  const queue_position position = back_child)
579  {
580  signal_raw_event_queue_.connect_signal(E, position, signal);
581  }
582 
583  /**
584  * Disconnect a signal for callback in set_raw_event.
585  *
586  * @tparam E The event the callback was used for.
587  * @param signal The callback function.
588  * @param position The place where the function was added.
589  * Needed remove the event from the right
590  * place. (The function doesn't care whether
591  * was added in front or back.)
592  */
593  template <ui_event E>
595  disconnect_signal(const signal_raw_event_function& signal,
596  const queue_position position = back_child)
597  {
598  signal_raw_event_queue_.disconnect_signal(E, position, signal);
599  }
600 
601  /**
602  * Connect a signal for callback in set_text_input.
603  *
604  * @tparam E The event the callback needs to react to.
605  * @param signal The callback function.
606  * @param position The position to place the callback.
607  */
608  template <ui_event E>
610  connect_signal(const signal_text_input_function& signal,
611  const queue_position position = back_child)
612  {
613  signal_text_input_queue_.connect_signal(E, position, signal);
614  }
615 
616  /**
617  * Disconnect a signal for callback in set_text_input.
618  *
619  * @tparam E The event the callback was used for.
620  * @param signal The callback function.
621  * @param position The place where the function was added.
622  * Needed remove the event from the right
623  * place. (The function doesn't care whether
624  * was added in front or back.)
625  */
626  template <ui_event E>
628  disconnect_signal(const signal_text_input_function& signal,
629  const queue_position position = back_child)
630  {
631  signal_text_input_queue_.disconnect_signal(E, position, signal);
632  }
633 
634  /**
635  * The behavior of the mouse events.
636  *
637  * Normally for mouse events there's first checked whether a dispatcher has
638  * captured the mouse if so it gets the event.
639  * If not the dispatcher is searched from the back to the front in the
640  * layers and its behavior is checked.
641  * * none The event is never send to the layer and goes on the the next
642  * layer. This is used for tooltips who might cover a button but a click
643  * on the tooltips should still click the button.
644  * * all The event is always send to this layer and stops the search for a
645  * next layer.
646  * * hit If the mouse is inside the dispatcher area the event is send and
647  * no longer searched further. If not inside tests the last layer.
648  *
649  * If after these tests no dispatcher is found the event is ignored.
650  */
655  };
656 
657  /** Captures the mouse. */
659  {
661  }
662 
663  /** Releases the mouse capture. */
665  {
667  }
668 
669  /***** ***** ***** setters/getters ***** ***** *****/
670 
672  {
674  }
675 
677  {
678  return mouse_behavior_;
679  }
680 
681  void set_want_keyboard_input(const bool want_keyboard_input)
682  {
683  want_keyboard_input_ = want_keyboard_input;
684  }
685 
687  {
688  return want_keyboard_input_;
689  }
690 
691  /** Helper struct to generate the various signal types. */
692  template <class T>
693  struct signal_type
694  {
696  {
697  }
698 
699  std::list<T> pre_child;
700  std::list<T> child;
701  std::list<T> post_child;
702  };
703 
704  /** Helper struct to generate the various event queues. */
705  template <class T>
707  {
709  {
710  }
711 
712  std::map<ui_event, signal_type<T> > queue;
713 
714  void connect_signal(const ui_event event,
715  const queue_position position,
716  const T& signal)
717  {
718  switch(position) {
719  case front_pre_child:
720  queue[event].pre_child.push_front(signal);
721  break;
722  case back_pre_child:
723  queue[event].pre_child.push_back(signal);
724  break;
725 
726  case front_child:
727  queue[event].child.push_front(signal);
728  break;
729  case back_child:
730  queue[event].child.push_back(signal);
731  break;
732 
733  case front_post_child:
734  queue[event].post_child.push_front(signal);
735  break;
736  case back_post_child:
737  queue[event].post_child.push_back(signal);
738  break;
739  }
740  }
741 
742  void disconnect_signal(const ui_event event,
743  const queue_position position,
744  const T& signal)
745  {
746  signal_type<T>& signal_queue = queue[event];
747 
748  /* The function doesn't differentiate between front and back position so fall
749  * down from front to back.
750  *
751  * NOTE: This used to only remove the first signal of matching target type.
752  * That behavior could be restored in the future if needed.
753  * - vultraz, 2017-05-02
754  */
755  switch(position) {
756  case front_pre_child:
757  case back_pre_child: {
758  signal_queue.pre_child.remove_if(
759  [&signal](T& element) { return signal.target_type() == element.target_type(); }
760  );
761  } break;
762 
763  case front_child:
764  case back_child: {
765  signal_queue.child.remove_if(
766  [&signal](T& element) { return signal.target_type() == element.target_type(); }
767  );
768  } break;
769 
770  case front_post_child:
771  case back_post_child: {
772  signal_queue.post_child.remove_if(
773  [&signal](T& element) { return signal.target_type() == element.target_type(); }
774  );
775  } break;
776  }
777  }
778  };
779 
780  /**
781  * Registers a hotkey.
782  *
783  * @todo add a static function register_global_hotkey.
784  *
785  * Once that's done execute_hotkey will first try to execute a global
786  * hotkey and if that fails tries the hotkeys in this dispatcher.
787  *
788  * @param id The hotkey to register.
789  * @param function The callback function to call.
790  */
792  const hotkey_function& function);
793 
794  /**
795  * Executes a hotkey.
796  *
797  * @param id The hotkey to execute.
798  *
799  * @returns true if the hotkey is handled, false
800  * otherwise.
801  */
802  bool execute_hotkey(const hotkey::HOTKEY_COMMAND id);
803 
804 private:
805  /** The mouse behavior for the dispatcher. */
807 
808  /**
809  * Does the dispatcher want to receive keyboard input.
810  *
811  * @todo The entire mouse and keyboard handling can use a code review to
812  * seen whether it might be combined in one flag field. At the moment the
813  * keyboard doesn't look whether a dialog has the mouse focus before
814  * sending the event, so maybe we should add an active dispatcher to keep
815  * track of it. But since at the moment there are only non-modal windows
816  * and tooltips it's not a problem.
817  */
819 
820  /** Signal queue for callbacks in set_event. */
822 
823  /** Signal queue for callbacks in set_event_mouse. */
825 
826  /** Signal queue for callbacks in set_event_keyboard. */
828 
829  /** Signal queue for callbacks in set_event_touch. */
831 
832  /** Signal queue for callbacks in set_event_notification. */
834 
835  /** Signal queue for callbacks in set_event_message. */
837 
838  /** Signal queue for callbacks in set_raw_event. */
840 
841  /** Signal queue for callbacks in set_event_text_input. */
843 
844  /** Are we connected to the event handler. */
846 
847  /** The registered hotkeys for this dispatcher. */
848  std::map<hotkey::HOTKEY_COMMAND, hotkey_function> hotkeys_;
849 };
850 
851 /***** ***** ***** ***** ***** Common helpers ***** ***** ***** ***** *****/
852 
853 /*
854  * These helpers can be used to easily add callbacks to a dispatcher (widget).
855  * This is just a list of common ones all others can be used as well.
856  */
857 
858 /**
859  * Connects the signal for 'snooping' on the keypress.
860  *
861  * This callback is called before the widget itself allowing you to either
862  * snoop on the input or filter it.
863  */
864 void connect_signal_pre_key_press(dispatcher& dispatcher, const signal_keyboard_function& signal);
865 
866 /** Connects a signal handler for a left mouse button click. */
867 void connect_signal_mouse_left_click(dispatcher& dispatcher, const signal_function& signal);
868 
869 /** Disconnects a signal handler for a left mouse button click. */
870 void disconnect_signal_mouse_left_click(dispatcher& dispatcher, const signal_function& signal);
871 
872 /**
873  * Connects a signal handler for a left mouse button double click.
874  *
875  * I'm not exactly sure why this works in this queue position with toggle
876  * panels, but it does. Will revisit if it becomes an issue later (ie, if
877  * this is used with other widgets and doesn't work).
878  *
879  * - vultraz, 2017-08-23
880  */
881 void connect_signal_mouse_left_double_click(dispatcher& dispatcher, const signal_function& signal);
882 
883 /** Connects a signal handler for getting a notification upon modification. */
884 void connect_signal_notify_modified(dispatcher& dispatcher, const signal_notification_function& signal);
885 
886 } // namespace event
887 
888 } // namespace gui2
utils::enable_if_t< has_key< set_event_text_input, E >::value > disconnect_signal(const signal_text_input_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_text_input.
Definition: dispatcher.hpp:628
std::vector< char_t > string
signal_queue< signal_text_input_function > signal_text_input_queue_
Signal queue for callbacks in set_event_text_input.
Definition: dispatcher.hpp:842
Base class for event handling.
Definition: dispatcher.hpp:161
utils::enable_if_t< has_key< set_event_message, E >::value > connect_signal(const signal_message_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event_message.
Definition: dispatcher.hpp:539
void register_hotkey(const hotkey::HOTKEY_COMMAND id, const hotkey_function &function)
Registers a hotkey.
Definition: dispatcher.cpp:188
std::function< bool(widget &dispatcher, hotkey::HOTKEY_COMMAND id)> hotkey_function
Hotkey function handler signature.
Definition: dispatcher.hpp:144
utils::enable_if_t< has_key< set_event_raw_event, E >::value > connect_signal(const signal_raw_event_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_raw_event.
Definition: dispatcher.hpp:577
Base class for all widgets.
Definition: widget.hpp:48
Holds a 2D point.
Definition: point.hpp:23
void capture_mouse(dispatcher *dispatcher)
Captures the mouse.
Definition: handler.cpp:850
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, const point &coordinate)> signal_mouse_function
Callback function signature.
Definition: dispatcher.hpp:67
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:110
boost::mpl::has_key< K, boost::mpl::int_< E >> has_key
Definition: dispatcher.hpp:42
void connect_signal(const ui_event event, const queue_position position, const T &signal)
Definition: dispatcher.hpp:714
bool get_want_keyboard_input() const
Definition: dispatcher.hpp:686
bool has_event(const ui_event event, const event_queue_type event_type)
Definition: dispatcher.cpp:55
utils::enable_if_t< has_key< set_event_keyboard, E >::value > disconnect_signal(const signal_keyboard_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_event_keyboard.
Definition: dispatcher.hpp:447
Generic file dialog.
Definition: text.hpp:37
The message callbacks hold a reference to a message.
Definition: message.hpp:46
utils::enable_if_t< has_key< set_event_message, E >::value > disconnect_signal(const signal_message_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_event_message.
Definition: dispatcher.hpp:562
utils::enable_if_t< has_key< set_event_mouse, E >::value > connect_signal(const signal_mouse_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event_mouse.
Definition: dispatcher.hpp:396
void capture_mouse()
Captures the mouse.
Definition: dispatcher.hpp:658
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, const SDL_Keycode key, const SDL_Keymod modifier, const utf8::string &unicode)> signal_keyboard_function
Callback function signature.
Definition: dispatcher.hpp:80
void connect()
Connects the dispatcher to the event handler.
Definition: dispatcher.cpp:48
mouse_behavior get_mouse_behavior() const
Definition: dispatcher.hpp:676
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:224
signal_queue< signal_mouse_function > signal_mouse_queue_
Signal queue for callbacks in set_event_mouse.
Definition: dispatcher.hpp:824
virtual bool is_at(const point &coordinate) const =0
Determines whether the location is inside an active widget.
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:209
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
Definition: dispatcher.cpp:193
signal_queue< signal_function > signal_queue_
Signal queue for callbacks in set_event.
Definition: dispatcher.hpp:821
utils::enable_if_t< has_key< set_event_raw_event, E >::value > disconnect_signal(const signal_raw_event_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_raw_event.
Definition: dispatcher.hpp:595
signal_queue< signal_message_function > signal_message_queue_
Signal queue for callbacks in set_event_message.
Definition: dispatcher.hpp:836
Helper struct to generate the various event queues.
Definition: dispatcher.hpp:706
void set_mouse_behavior(const mouse_behavior mouse_behavior)
Definition: dispatcher.hpp:671
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:219
signal_queue< signal_touch_function > signal_touch_queue_
Signal queue for callbacks in set_event_touch.
Definition: dispatcher.hpp:830
std::map< ui_event, signal_type< T > > queue
Definition: dispatcher.hpp:712
std::map< hotkey::HOTKEY_COMMAND, hotkey_function > hotkeys_
The registered hotkeys for this dispatcher.
Definition: dispatcher.hpp:848
bool want_keyboard_input_
Does the dispatcher want to receive keyboard input.
Definition: dispatcher.hpp:818
utils::enable_if_t< has_key< set_event_mouse, E >::value > disconnect_signal(const signal_mouse_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_event_mouse.
Definition: dispatcher.hpp:414
bool connected_
Are we connected to the event handler.
Definition: dispatcher.hpp:845
utils::enable_if_t< has_key< set_event_notification, E >::value > connect_signal(const signal_notification_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event_notification.
Definition: dispatcher.hpp:498
utils::enable_if_t< has_key< set_event_touch, E >::value > disconnect_signal(const signal_touch_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_event_touch.
Definition: dispatcher.hpp:480
signal_queue< signal_raw_event_function > signal_raw_event_queue_
Signal queue for callbacks in set_raw_event.
Definition: dispatcher.hpp:839
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, const std::string &text, int32_t current_pos, int32_t select_len)> signal_text_input_function
Callback function signature.
Definition: dispatcher.hpp:140
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt)> signal_function
Callback function signature.
Definition: dispatcher.hpp:44
queue_position
The position where to add a new callback in the signal handler.
Definition: dispatcher.hpp:335
typename std::enable_if< B, T >::type enable_if_t
signal_queue< signal_notification_function > signal_notification_queue_
Signal queue for callbacks in set_event_notification.
Definition: dispatcher.hpp:833
utils::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:381
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard_function &signal)
Connects the signal for 'snooping' on the keypress.
Definition: dispatcher.cpp:204
utils::enable_if_t< has_key< set_event_text_input, E >::value > connect_signal(const signal_text_input_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_text_input.
Definition: dispatcher.hpp:610
mouse_behavior
The behavior of the mouse events.
Definition: dispatcher.hpp:651
signal_queue< signal_keyboard_function > signal_keyboard_queue_
Signal queue for callbacks in set_event_keyboard.
Definition: dispatcher.hpp:827
Helper struct to generate the various signal types.
Definition: dispatcher.hpp:693
utils::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:363
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:214
void release_mouse(dispatcher *dispatcher)
Releases a captured mouse.
Definition: handler.cpp:857
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, const SDL_Event &sdlevent)> signal_raw_event_function
Callback function signature.
Definition: dispatcher.hpp:127
utils::enable_if_t< has_key< set_event_notification, E >::value > disconnect_signal(const signal_notification_function &signal, const queue_position position=back_child)
Disconnect a signal for callback in set_event_notification.
Definition: dispatcher.hpp:521
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:120
void release_mouse()
Releases the mouse capture.
Definition: dispatcher.hpp:664
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, const point &pos, const point &distance)> signal_touch_function
Callback function signature.
Definition: dispatcher.hpp:92
void set_want_keyboard_input(const bool want_keyboard_input)
Definition: dispatcher.hpp:681
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, message &message)> signal_message_function
Callback function signature.
Definition: dispatcher.hpp:116
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt, void *)> signal_notification_function
Callback function signature.
Definition: dispatcher.hpp:105
utils::enable_if_t< has_key< set_event_keyboard, E >::value > connect_signal(const signal_keyboard_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event_keyboard.
Definition: dispatcher.hpp:429
utils::enable_if_t< has_key< set_event_touch, E >::value > connect_signal(const signal_touch_function &signal, const queue_position position=back_child)
Connect a signal for callback in set_event_touch.
Definition: dispatcher.hpp:462
mouse_behavior mouse_behavior_
The mouse behavior for the dispatcher.
Definition: dispatcher.hpp:806
void disconnect_signal(const ui_event event, const queue_position position, const T &signal)
Definition: dispatcher.hpp:742
ui_event
The event send to the dispatcher.
Definition: handler.hpp:55
std::string string
EXIT_STATUS start(const config &game_conf, CVideo &video, 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