The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Mark de Wever <[email protected]>
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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
20 #include "gui/core/timer.hpp"
21 #include "gui/core/log.hpp"
22 #include "gui/widgets/helper.hpp"
23 #include "gui/widgets/widget.hpp"
24 #include "gui/widgets/window.hpp"
25 #include "hotkey/hotkey_item.hpp"
26 #include "video.hpp"
28 
29 #include <cassert>
30 
31 /**
32  * @todo The items below are not implemented yet.
33  *
34  * - Tooltips have a fixed short time until showing up.
35  * - Tooltips are shown until the widget is exited.
36  * - Help messages aren't shown yet.
37  *
38  * @note it might be that tooltips will be shown independent of a window and in
39  * their own window, therefore the code will be cleaned up after that has been
40  * determined.
41  */
42 
43 /*
44  * At some point in the future this event handler should become the main event
45  * handler. This switch controls the experimental switch for that change.
46  */
47 //#define MAIN_EVENT_HANDLER
48 
49 /* Since this code is still very experimental it's not enabled yet. */
50 //#define ENABLE
51 
52 namespace gui2
53 {
54 
55 namespace event
56 {
57 
58 /***** Static data. *****/
59 class thandler;
60 static thandler* handler = nullptr;
62 
63 #ifdef MAIN_EVENT_HANDLER
64 static unsigned draw_interval = 0;
65 static unsigned event_poll_interval = 0;
66 
67 /***** Static functions. *****/
68 
69 /**
70  * SDL_AddTimer() callback for the draw event.
71  *
72  * When this callback is called it pushes a new draw event in the event queue.
73  *
74  * @returns The new timer interval, 0 to stop.
75  */
76 static Uint32 timer_sdl_draw_event(Uint32, void*)
77 {
78  // DBG_GUI_E << "Pushing draw event in queue.\n";
79 
80  SDL_Event event;
81  SDL_UserEvent data;
82 
83  data.type = DRAW_EVENT;
84  data.code = 0;
85  data.data1 = nullptr;
86  data.data2 = nullptr;
87 
88  event.type = DRAW_EVENT;
89  event.user = data;
90 
91  SDL_PushEvent(&event);
92  return draw_interval;
93 }
94 
95 /**
96  * SDL_AddTimer() callback for the poll event.
97  *
98  * When this callback is called it will run the events in the SDL event queue.
99  *
100  * @returns The new timer interval, 0 to stop.
101  */
102 static Uint32 timer_sdl_poll_events(Uint32, void*)
103 {
104  try
105  {
106  events::pump();
107  }
108  catch(CVideo::quit&)
109  {
110  return 0;
111  }
112  return event_poll_interval;
113 }
114 #endif
115 
116 /***** thandler class. *****/
117 
118 /**
119  * This singleton class handles all events.
120  *
121  * It's a new experimental class.
122  */
124 {
125  friend bool gui2::is_in_dialog();
126 
127 public:
128  thandler();
129 
130  ~thandler();
131 
132  /** Inherited from events::sdl_handler. */
133  void handle_event(const SDL_Event& event);
134 
135  /** Inherited from events::sdl_handler. */
136  void handle_window_event(const SDL_Event& event);
137 
138  /**
139  * Connects a dispatcher.
140  *
141  * @param dispatcher The dispatcher to connect.
142  */
143  void connect(tdispatcher* dispatcher);
144 
145  /**
146  * Disconnects a dispatcher.
147  *
148  * @param dispatcher The dispatcher to disconnect.
149  */
150  void disconnect(tdispatcher* dispatcher);
151 
152  /** The dispatcher that captured the mouse focus. */
154 
155 private:
156  /**
157  * Reinitializes the state of all dispatchers.
158  *
159  * This is needed when the application gets activated, to make sure the
160  * state of mainly the mouse is set properly.
161  */
162  void activate();
163 
164  /***** Handlers *****/
165 
166  /** Fires a draw event. */
168  void draw(const bool force);
169 
170  /**
171  * Fires a video resize event.
172  *
173  * @param new_size The new size of the window.
174  */
175  void video_resize(const tpoint& new_size);
176 
177  /**
178  * Fires a generic mouse event.
179  *
180  * @param event The event to fire.
181  * @param position The position of the mouse.
182  */
183  void mouse(const tevent event, const tpoint& position);
184 
185  /**
186  * Fires a mouse button up event.
187  *
188  * @param position The position of the mouse.
189  * @param button The SDL id of the button that caused the
190  * event.
191  */
192  void mouse_button_up(const tpoint& position, const Uint8 button);
193 
194  /**
195  * Fires a mouse button down event.
196  *
197  * @param position The position of the mouse.
198  * @param button The SDL id of the button that caused the
199  * event.
200  */
201  void mouse_button_down(const tpoint& position, const Uint8 button);
202 
203  /**
204  * Fires a mouse wheel event.
205  *
206  * @param position The position of the mouse.
207  * @param scrollx The amount of horizontal scrolling.
208  * @param scrolly The amount of vertical scrolling.
209  */
210  void mouse_wheel(const tpoint& position, int scrollx, int scrolly);
211 
212  /**
213  * Gets the dispatcher that wants to receive the keyboard input.
214  *
215  * @returns The dispatcher.
216  * @retval nullptr No dispatcher found.
217  */
219 
220  /**
221  * Handles a hat motion event.
222  *
223  * @param event The SDL joystick hat event triggered.
224  */
225  void hat_motion(const SDL_Event& event);
226 
227 
228  /**
229  * Handles a joystick button down event.
230  *
231  * @param event The SDL joystick button event triggered.
232  */
233  void button_down(const SDL_Event& event);
234 
235 
236  /**
237  * Fires a key down event.
238  *
239  * @param event The SDL keyboard event triggered.
240  */
241  void key_down(const SDL_Event& event);
242 
243  /**
244  * Handles the pressing of a hotkey.
245  *
246  * @param key The hotkey item pressed.
247  *
248  * @returns True if the hotkey is handled false otherwise.
249  */
250  bool hotkey_pressed(const hotkey::hotkey_ptr key);
251 
252  /**
253  * Fires a key down event.
254  *
255  * @param key The SDL key code of the key pressed.
256  * @param modifier The SDL key modifiers used.
257  * @param unicode The unicode value for the key pressed.
258  */
259  void key_down(const SDLKey key,
260  const SDLMod modifier,
261  const utf8::string& unicode);
262 
263  /**
264  * Fires a text input event.
265  *
266  * @param unicode The unicode value for the text entered.
267  */
268  void text_input(const std::string& unicode);
269 
270  /**
271  * Fires a keyboard event which has no parameters.
272  *
273  * This can happen for example when the mouse wheel is used.
274  *
275  * @param event The event to fire.
276  */
277  void keyboard(const tevent event);
278 
279  /**
280  * The dispatchers.
281  *
282  * The order of the items in the list is also the z-order the front item
283  * being the one completely in the background and the back item the one
284  * completely in the foreground.
285  */
286  std::vector<tdispatcher*> dispatchers_;
287 
288  /**
289  * Needed to determine which dispatcher gets the keyboard events.
290  *
291  * NOTE the keyboard events aren't really wired in yet so doesn't do much.
292  */
294  friend void capture_keyboard(tdispatcher*);
295 };
296 
298  : events::sdl_handler(false)
299  , mouse_focus(nullptr)
300  , dispatchers_()
301  , keyboard_focus_(nullptr)
302 {
303  if(SDL_WasInit(SDL_INIT_TIMER) == 0) {
304  if(SDL_InitSubSystem(SDL_INIT_TIMER) == -1) {
305  assert(false);
306  }
307  }
308 
309 // The event context is created now we join it.
310 #ifdef ENABLE
311  join();
312 #endif
313 }
314 
316 {
317 #ifdef ENABLE
318  leave();
319 #endif
320 }
321 
322 void thandler::handle_event(const SDL_Event& event)
323 {
324  /** No dispatchers drop the event. */
325  if(dispatchers_.empty()) {
326  return;
327  }
328 
329  switch(event.type) {
330  case SDL_MOUSEMOTION:
331  mouse(SDL_MOUSE_MOTION, tpoint(event.motion.x, event.motion.y));
332  break;
333 
334  case SDL_MOUSEBUTTONDOWN:
335  mouse_button_down(tpoint(event.button.x, event.button.y),
336  event.button.button);
337  break;
338 
339  case SDL_MOUSEBUTTONUP:
340  mouse_button_up(tpoint(event.button.x, event.button.y),
341  event.button.button);
342  break;
343 
344  case SDL_MOUSEWHEEL:
345  mouse_wheel(get_mouse_position(), event.wheel.x, event.wheel.y);
346  break;
347 
348  case SHOW_HELPTIP_EVENT:
350  break;
351 
353  // remove_popup();
354  break;
355 
356  case DRAW_EVENT:
357  draw(false);
358  break;
359  case DRAW_ALL_EVENT:
360  draw(true);
361  break;
362 
363  case TIMER_EVENT:
364  execute_timer(reinterpret_cast<size_t>(event.user.data1));
365  break;
366 
367  case CLOSE_WINDOW_EVENT: {
368  /** @todo Convert this to a proper new style event. */
369  DBG_GUI_E << "Firing " << CLOSE_WINDOW << ".\n";
370 
371  twindow* window = twindow::window_instance(event.user.code);
372  if(window) {
374  }
375  } break;
376 
377  case SDL_JOYBUTTONDOWN:
378  button_down(event);
379  break;
380 
381  case SDL_JOYBUTTONUP:
382  break;
383 
384  case SDL_JOYAXISMOTION:
385  break;
386 
387  case SDL_JOYHATMOTION:
388  hat_motion(event);
389  break;
390 
391  case SDL_KEYDOWN:
392  key_down(event);
393  break;
394 
395  case SDL_WINDOWEVENT:
396  switch(event.window.event) {
397  case SDL_WINDOWEVENT_EXPOSED:
398  draw(true);
399  break;
400 
401  case SDL_WINDOWEVENT_RESIZED:
402  video_resize(
403  tpoint(event.window.data1, event.window.data2));
404  break;
405 
406  case SDL_WINDOWEVENT_ENTER:
407  case SDL_WINDOWEVENT_FOCUS_GAINED:
408  activate();
409  break;
410  }
411 
412  break;
413 
414  case SDL_TEXTINPUT:
415  text_input(event.text.text);
416  break;
417 
418 #if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
419  case SDL_SYSWMEVENT:
420  /* DO NOTHING */
421  break;
422 #endif
423 
424  // Silently ignored events.
425  case SDL_KEYUP:
426  case DOUBLE_CLICK_EVENT:
427  break;
428 
429  default:
430  WRN_GUI_E << "Unhandled event " << static_cast<Uint32>(event.type)
431  << ".\n";
432  break;
433  }
434 }
435 
436 void thandler::handle_window_event(const SDL_Event& event)
437 {
438  handle_event(event);
439 }
440 
442 {
443  assert(std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher)
444  == dispatchers_.end());
445 
446  if(dispatchers_.empty()) {
447  event_context = new events::event_context();
448  join();
449  }
450 
451  dispatchers_.push_back(dispatcher);
452 }
453 
455 {
456  /***** Validate pre conditions. *****/
458  = std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher);
459  assert(itor != dispatchers_.end());
460 
461  /***** Remove dispatcher. *****/
462  dispatchers_.erase(itor);
463 
464  if(dispatcher == mouse_focus) {
465  mouse_focus = nullptr;
466  }
467  if(dispatcher == keyboard_focus_) {
468  keyboard_focus_ = nullptr;
469  }
470 
471  /***** Set proper state for the other dispatchers. *****/
472  for(auto dispatcher : dispatchers_)
473  {
474  dynamic_cast<twidget&>(*dispatcher).set_is_dirty(true);
475  }
476 
477  activate();
478 
479  /***** Validate post conditions. *****/
480  assert(std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher)
481  == dispatchers_.end());
482 
483  if(dispatchers_.empty()) {
484  leave();
485  delete event_context;
486  event_context = nullptr;
487  }
488 }
489 
491 {
492  for(auto dispatcher : dispatchers_)
493  {
494  dispatcher->fire(
495  SDL_ACTIVATE, dynamic_cast<twidget&>(*dispatcher), nullptr);
496  }
497 }
498 
499 void thandler::draw(const bool force)
500 {
501  // Don't display this event since it floods the screen
502  // DBG_GUI_E << "Firing " << DRAW << ".\n";
503 
504  /*
505  * In normal draw mode the first window in not forced to be drawn the
506  * others are. So for forced mode we only need to force the first window to
507  * be drawn the others are already handled.
508  */
509  bool first = !force;
510 
511  /**
512  * @todo Need to evaluate which windows really to redraw.
513  *
514  * For now we use a hack, but would be nice to rewrite it for 1.9/1.11.
515  */
516  for(auto dispatcher : dispatchers_)
517  {
518  if(!first) {
519  /*
520  * This leaves glitches on window borders if the window beneath it
521  * has changed, on the other hand invalidating twindown::restorer_
522  * causes black borders around the window. So there's the choice
523  * between two evils.
524  */
525  dynamic_cast<twidget&>(*dispatcher).set_is_dirty(true);
526  } else {
527  first = false;
528  }
529 
530  dispatcher->fire(DRAW, dynamic_cast<twidget&>(*dispatcher));
531  }
532 
533  if(!dispatchers_.empty()) {
534  CVideo& video = dynamic_cast<twindow&>(*dispatchers_.back()).video();
535 
536  video.flip();
537  }
538 }
539 
540 void thandler::video_resize(const tpoint& new_size)
541 {
542  DBG_GUI_E << "Firing: " << SDL_VIDEO_RESIZE << ".\n";
543 
544  for(auto dispatcher : dispatchers_)
545  {
546  dispatcher->fire(SDL_VIDEO_RESIZE,
547  dynamic_cast<twidget&>(*dispatcher),
548  new_size);
549  }
550 }
551 
552 void thandler::mouse(const tevent event, const tpoint& position)
553 {
554  DBG_GUI_E << "Firing: " << event << ".\n";
555 
556  if(mouse_focus) {
557  mouse_focus->fire(
558  event, dynamic_cast<twidget&>(*mouse_focus), position);
559  } else {
560 
561  for(std::vector<tdispatcher*>::reverse_iterator ritor
562  = dispatchers_.rbegin();
563  ritor != dispatchers_.rend();
564  ++ritor) {
565 
566  if((**ritor).get_mouse_behavior() == tdispatcher::all) {
567  (**ritor)
568  .fire(event, dynamic_cast<twidget&>(**ritor), position);
569  break;
570  }
571  if((**ritor).get_mouse_behavior() == tdispatcher::none) {
572  continue;
573  }
574  if((**ritor).is_at(position)) {
575  (**ritor)
576  .fire(event, dynamic_cast<twidget&>(**ritor), position);
577  break;
578  }
579  }
580  }
581 }
582 
583 void thandler::mouse_button_up(const tpoint& position, const Uint8 button)
584 {
585  switch(button) {
586  case SDL_BUTTON_LEFT:
587  mouse(SDL_LEFT_BUTTON_UP, position);
588  break;
589  case SDL_BUTTON_MIDDLE:
590  mouse(SDL_MIDDLE_BUTTON_UP, position);
591  break;
592  case SDL_BUTTON_RIGHT:
593  mouse(SDL_RIGHT_BUTTON_UP, position);
594  break;
595 
596 
597  default:
598  WRN_GUI_E << "Unhandled 'mouse button up' event for button "
599  << static_cast<Uint32>(button) << ".\n";
600  break;
601  }
602 }
603 
604 void thandler::mouse_button_down(const tpoint& position, const Uint8 button)
605 {
606  // The wheel buttons generate and up and down event we handle the
607  // up event so ignore the mouse if it's a down event. Handle it
608  // here to avoid a warning.
609  if(button == SDL_BUTTON_WHEELUP || button == SDL_BUTTON_WHEELDOWN
610  || button == SDL_BUTTON_WHEELLEFT || button == SDL_BUTTON_WHEELRIGHT) {
611 
612  return;
613  }
614 
615  switch(button) {
616  case SDL_BUTTON_LEFT:
617  mouse(SDL_LEFT_BUTTON_DOWN, position);
618  break;
619  case SDL_BUTTON_MIDDLE:
620  mouse(SDL_MIDDLE_BUTTON_DOWN, position);
621  break;
622  case SDL_BUTTON_RIGHT:
623  mouse(SDL_RIGHT_BUTTON_DOWN, position);
624  break;
625  default:
626  WRN_GUI_E << "Unhandled 'mouse button down' event for button "
627  << static_cast<Uint32>(button) << ".\n";
628  break;
629  }
630 }
631 
632 void thandler::mouse_wheel(const tpoint& position, int x, int y)
633 {
634  if(x > 0) {
635  mouse(SDL_WHEEL_RIGHT, position);
636  } else if(x < 0) {
637  mouse(SDL_WHEEL_LEFT, position);
638  }
639 
640  if(y < 0) {
641  mouse(SDL_WHEEL_DOWN, position);
642  } else if(y > 0) {
643  mouse(SDL_WHEEL_UP, position);
644  }
645 }
646 
648 {
649  if(keyboard_focus_) {
650  return keyboard_focus_;
651  }
652 
653  for(std::vector<tdispatcher*>::reverse_iterator ritor
654  = dispatchers_.rbegin();
655  ritor != dispatchers_.rend();
656  ++ritor) {
657 
658  if((**ritor).get_want_keyboard_input()) {
659  return *ritor;
660  }
661  }
662 
663  return nullptr;
664 }
665 
666 void thandler::hat_motion(const SDL_Event& event)
667 {
668  const hotkey::hotkey_ptr& hk = hotkey::get_hotkey(event);
669  bool done = false;
670  if(!hk->null()) {
671  done = hotkey_pressed(hk);
672  }
673  if(!done) {
674  // TODO fendrin think about handling hat motions that are not bound to a
675  // hotkey.
676  }
677 }
678 
679 void thandler::button_down(const SDL_Event& event)
680 {
681  const hotkey::hotkey_ptr hk = hotkey::get_hotkey(event);
682  bool done = false;
683  if(!hk->null()) {
684  done = hotkey_pressed(hk);
685  }
686  if(!done) {
687  // TODO fendrin think about handling button down events that are not
688  // bound to a hotkey.
689  }
690 }
691 
692 void thandler::key_down(const SDL_Event& event)
693 {
694  const hotkey::hotkey_ptr hk = hotkey::get_hotkey(event);
695  bool done = false;
696  if(!hk->null()) {
697  done = hotkey_pressed(hk);
698  }
699  if(!done) {
700  key_down(event.key.keysym.sym,
701  static_cast<const SDL_Keymod>(event.key.keysym.mod),
702  "");
703  }
704 }
705 
706 void thandler::text_input(const std::string& unicode)
707 {
708  key_down(static_cast<SDLKey>(0), static_cast<SDLMod>(0), unicode);
709 }
710 
712 {
713  tdispatcher* dispatcher = keyboard_dispatcher();
714 
715  if(!dispatcher) {
716  return false;
717  }
718 
719  return dispatcher->execute_hotkey(hotkey::get_id(key->get_command()));
720 }
721 
722 void thandler::key_down(const SDLKey key,
723  const SDLMod modifier,
724  const utf8::string& unicode)
725 {
726  DBG_GUI_E << "Firing: " << SDL_KEY_DOWN << ".\n";
727 
728  if(tdispatcher* dispatcher = keyboard_dispatcher()) {
729  dispatcher->fire(SDL_KEY_DOWN,
730  dynamic_cast<twidget&>(*dispatcher),
731  key,
732  modifier,
733  unicode);
734  }
735 }
736 
738 {
739  DBG_GUI_E << "Firing: " << event << ".\n";
740 
741  if(tdispatcher* dispatcher = keyboard_dispatcher()) {
742  dispatcher->fire(event, dynamic_cast<twidget&>(*dispatcher));
743  }
744 }
745 
746 /***** tmanager class. *****/
747 
749 {
750  handler = new thandler();
751 
752 #ifdef MAIN_EVENT_HANDLER
753  draw_interval = 30;
754  SDL_AddTimer(draw_interval, timer_sdl_draw_event, nullptr);
755 
756  event_poll_interval = 10;
757  SDL_AddTimer(event_poll_interval, timer_sdl_poll_events, nullptr);
758 #endif
759 }
760 
762 {
763  delete handler;
764  handler = nullptr;
765 
766 #ifdef MAIN_EVENT_HANDLER
767  draw_interval = 0;
768  event_poll_interval = 0;
769 #endif
770 }
771 
772 /***** free functions class. *****/
773 
775 {
776  assert(handler);
777  assert(dispatcher);
778  handler->connect(dispatcher);
779 }
780 
782 {
783  assert(handler);
784  assert(dispatcher);
785  handler->disconnect(dispatcher);
786 }
787 
789 {
790  tpoint mouse = get_mouse_position();
791 
792  SDL_Event event;
793  event.type = SDL_MOUSEMOTION;
794  event.motion.type = SDL_MOUSEMOTION;
795  event.motion.x = mouse.x;
796  event.motion.y = mouse.y;
797 
798  SDL_PushEvent(&event);
799 }
800 
801 void capture_mouse(tdispatcher* dispatcher)
802 {
803  assert(handler);
804  assert(dispatcher);
805  handler->mouse_focus = dispatcher;
806 }
807 
808 void release_mouse(tdispatcher* dispatcher)
809 {
810  assert(handler);
811  assert(dispatcher);
812  if(handler->mouse_focus == dispatcher) {
813  handler->mouse_focus = nullptr;
814  }
815 }
816 
817 void capture_keyboard(tdispatcher* dispatcher)
818 {
819  assert(handler);
820  assert(dispatcher);
821  assert(dispatcher->get_want_keyboard_input());
822 
823  handler->keyboard_focus_ = dispatcher;
824 }
825 
826 std::ostream& operator<<(std::ostream& stream, const tevent event)
827 {
828  switch(event) {
829  case DRAW:
830  stream << "draw";
831  break;
832  case CLOSE_WINDOW:
833  stream << "close window";
834  break;
835  case SDL_VIDEO_RESIZE:
836  stream << "SDL video resize";
837  break;
838  case SDL_MOUSE_MOTION:
839  stream << "SDL mouse motion";
840  break;
841  case MOUSE_ENTER:
842  stream << "mouse enter";
843  break;
844  case MOUSE_LEAVE:
845  stream << "mouse leave";
846  break;
847  case MOUSE_MOTION:
848  stream << "mouse motion";
849  break;
851  stream << "SDL left button down";
852  break;
853  case SDL_LEFT_BUTTON_UP:
854  stream << "SDL left button up";
855  break;
856  case LEFT_BUTTON_DOWN:
857  stream << "left button down";
858  break;
859  case LEFT_BUTTON_UP:
860  stream << "left button up";
861  break;
862  case LEFT_BUTTON_CLICK:
863  stream << "left button click";
864  break;
866  stream << "left button double click";
867  break;
869  stream << "SDL middle button down";
870  break;
872  stream << "SDL middle button up";
873  break;
874  case MIDDLE_BUTTON_DOWN:
875  stream << "middle button down";
876  break;
877  case MIDDLE_BUTTON_UP:
878  stream << "middle button up";
879  break;
880  case MIDDLE_BUTTON_CLICK:
881  stream << "middle button click";
882  break;
884  stream << "middle button double click";
885  break;
887  stream << "SDL right button down";
888  break;
889  case SDL_RIGHT_BUTTON_UP:
890  stream << "SDL right button up";
891  break;
892  case RIGHT_BUTTON_DOWN:
893  stream << "right button down";
894  break;
895  case RIGHT_BUTTON_UP:
896  stream << "right button up";
897  break;
898  case RIGHT_BUTTON_CLICK:
899  stream << "right button click";
900  break;
902  stream << "right button double click";
903  break;
904  case SDL_WHEEL_LEFT:
905  stream << "SDL wheel left";
906  break;
907  case SDL_WHEEL_RIGHT:
908  stream << "SDL wheel right";
909  break;
910  case SDL_WHEEL_UP:
911  stream << "SDL wheel up";
912  break;
913  case SDL_WHEEL_DOWN:
914  stream << "SDL wheel down";
915  break;
916  case SDL_KEY_DOWN:
917  stream << "SDL key down";
918  break;
919 
920  case NOTIFY_REMOVAL:
921  stream << "notify removal";
922  break;
923  case NOTIFY_MODIFIED:
924  stream << "notify modified";
925  break;
927  stream << "receive keyboard focus";
928  break;
929  case LOSE_KEYBOARD_FOCUS:
930  stream << "lose keyboard focus";
931  break;
932  case SHOW_TOOLTIP:
933  stream << "show tooltip";
934  break;
936  stream << "notify remove tooltip";
937  break;
938  case SDL_ACTIVATE:
939  stream << "SDL activate";
940  break;
942  stream << "message show tooltip";
943  break;
944  case SHOW_HELPTIP:
945  stream << "show helptip";
946  break;
948  stream << "message show helptip";
949  break;
950  case REQUEST_PLACEMENT:
951  stream << "request placement";
952  break;
953  }
954 
955  return stream;
956 }
957 
958 } // namespace event
959 
961 {
962  return event::handler && !event::handler->dispatchers_.empty();
963 }
964 
965 } // namespace gui2
Define the common log macros for the gui toolkit.
Widget loses keyboard focus.
Definition: handler.hpp:144
Request for somebody to show the tooltip based on the data send.
Definition: handler.hpp:160
friend void capture_keyboard(tdispatcher *)
Captures the keyboard.
Definition: handler.cpp:817
void key_down(const SDL_Event &event)
Fires a key down event.
Definition: handler.cpp:692
tdispatcher * keyboard_dispatcher()
Gets the dispatcher that wants to receive the keyboard input.
Definition: handler.cpp:647
static thandler * handler
Definition: handler.cpp:60
See LEFT_BUTTON_DOUBLE_CLICK.
Definition: handler.hpp:116
void connect(tdispatcher *dispatcher)
Connects a dispatcher.
Definition: handler.cpp:441
#define SDLMod
Definition: compat.hpp:30
void disconnect(tdispatcher *dispatcher)
Disconnects a dispatcher.
Definition: handler.cpp:454
A SDL middle mouse button up event.
Definition: handler.hpp:96
A mouse leave event for a widget.
Definition: handler.hpp:70
A left mouse button double click event for a widget.
Definition: handler.hpp:89
A request to close the current window.
Definition: handler.hpp:57
The dialog is closed automatically since it's timeout has been triggered.
Definition: window.hpp:130
A mouse enter event for a widget.
Definition: handler.hpp:66
void mouse_button_down(const tpoint &position, const Uint8 button)
Fires a mouse button down event.
Definition: handler.cpp:604
void mouse_button_up(const tpoint &position, const Uint8 button)
Fires a mouse button up event.
Definition: handler.cpp:583
See LEFT_BUTTON_UP.
Definition: handler.hpp:100
Definition: video.hpp:58
Widget gets keyboard focus.
Definition: handler.hpp:142
void flip()
Definition: video.cpp:496
This file contains the window object, this object is a top level container which has the event manage...
#define SDL_BUTTON_WHEELDOWN
Definition: utils.hpp:39
std::ostream & operator<<(std::ostream &stream, const tevent event)
Definition: handler.cpp:826
bool is_in_dialog()
Is a dialog open?
Definition: handler.cpp:960
#define TIMER_EVENT
Definition: events.hpp:24
#define DRAW_EVENT
Definition: events.hpp:26
void video_resize(const tpoint &new_size)
Fires a video resize event.
Definition: handler.cpp:540
virtual void draw()
Definition: events.hpp:68
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
void mouse(const tevent event, const tpoint &position)
Fires a generic mouse event.
Definition: handler.cpp:552
Base class for event handling.
Definition: dispatcher.hpp:122
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
A left mouse button down event for a widget.
Definition: handler.hpp:76
void set_is_dirty(const bool is_dirty)
Definition: widget.cpp:435
static twindow * window_instance(const unsigned handle)
Returns the instance of a window.
Definition: window.cpp:454
-file util.hpp
Request the widget to show its hover helptip.
Definition: handler.hpp:165
#define SDLKey
Definition: compat.hpp:29
#define SDL_BUTTON_WHEELLEFT
Definition: utils.hpp:43
See LEFT_BUTTON_UP.
Definition: handler.hpp:112
See LEFT_BUTTON_DOWN.
Definition: handler.hpp:110
A left mouse button click event for a widget.
Definition: handler.hpp:84
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A SDL mouse motion event.
Definition: handler.hpp:64
void init_mouse_location()
Initializes the location of the mouse.
Definition: handler.cpp:788
#define SDL_BUTTON_WHEELUP
Definition: utils.hpp:35
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
#define CLOSE_WINDOW_EVENT
Definition: events.hpp:27
void keyboard(const tevent event)
Fires a keyboard event which has no parameters.
Definition: handler.cpp:737
GLuint GLuint stream
Definition: glew.h:5239
See LEFT_BUTTON_DOUBLE_CLICK.
Definition: handler.hpp:104
See LEFT_BUTTON_DOWN.
Definition: handler.hpp:98
A SDL wheel right event.
Definition: handler.hpp:120
tdispatcher * mouse_focus
The dispatcher that captured the mouse focus.
Definition: handler.cpp:153
A SDL resize request, coordinate is the new window size.
Definition: handler.hpp:59
static events::event_context * event_context
Definition: handler.cpp:61
bool fire(const tevent event, twidget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:144
Periodic redraw request.
Definition: handler.hpp:55
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
Definition: dispatcher.cpp:309
A SDL middle mouse button down event.
Definition: handler.hpp:94
const hotkey_ptr get_hotkey(const SDL_Event &event)
Iterate through the list of hotkeys and return a hotkey that matches the SDL_Event and the current ke...
int y
y coordinate.
Definition: point.hpp:34
void button_down(const SDL_Event &event)
Handles a joystick button down event.
Definition: handler.cpp:679
Request for somebody to show the helptip based on the data send.
Definition: handler.hpp:170
void text_input(const std::string &unicode)
Fires a text input event.
Definition: handler.cpp:706
virtual void join()
Definition: events.cpp:173
void set_retval(const int retval, const bool close_window=true)
Sets there return value of the window.
Definition: window.hpp:422
void release_mouse(tdispatcher *dispatcher)
Releases a captured mouse.
Definition: handler.cpp:808
tpoint get_mouse_position()
Returns the current mouse position.
Definition: helper.cpp:149
Send by a widget to notify others its contents or state are modified.
Definition: handler.hpp:133
A SDL wheel left event.
Definition: handler.hpp:118
A SDL left mouse button up event.
Definition: handler.hpp:74
A mouse motion event for a widget.
Definition: handler.hpp:68
A SDL wheel up event.
Definition: handler.hpp:122
Request for somebody to place the widget.
Definition: handler.hpp:175
tevent
The event send to the dispatcher.
Definition: handler.hpp:54
void hat_motion(const SDL_Event &event)
Handles a hat motion event.
Definition: handler.cpp:666
void pump()
Definition: events.cpp:336
tdispatcher * keyboard_focus_
Needed to determine which dispatcher gets the keyboard events.
Definition: handler.cpp:293
int x
x coordinate.
Definition: point.hpp:31
#define DRAW_ALL_EVENT
Definition: events.hpp:29
Request the widget to show its hover tooltip.
Definition: handler.hpp:146
#define DOUBLE_CLICK_EVENT
Definition: events.hpp:23
A left mouse button up event for a widget.
Definition: handler.hpp:80
std::map< std::string, tfilter >::iterator itor
Definition: filter.cpp:199
#define DBG_GUI_E
Definition: log.hpp:35
See LEFT_BUTTON_CLICK.
Definition: handler.hpp:114
#define SHOW_HELPTIP_EVENT
Definition: events.hpp:28
void connect_dispatcher(tdispatcher *dispatcher)
Connects a dispatcher to the event handler.
Definition: handler.cpp:774
#define WRN_GUI_E
Definition: log.hpp:37
A SDL left mouse button down event.
Definition: handler.hpp:72
Contains the gui2 timer routines.
Holds a 2D point.
Definition: point.hpp:24
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
A SDL right mouse button down event.
Definition: handler.hpp:106
#define HOVER_REMOVE_POPUP_EVENT
Definition: events.hpp:25
Send by a widget to notify others it's being destroyed.
Definition: handler.hpp:128
void capture_mouse(tdispatcher *dispatcher)
Captures the mouse.
Definition: handler.cpp:801
Handling of system events.
Definition: manager.hpp:42
Request the widget to show its hover tooltip.
Definition: handler.hpp:151
A SDL wheel down event.
Definition: handler.hpp:124
std::vector< tdispatcher * > dispatchers_
The dispatchers.
Definition: handler.cpp:286
bool execute_timer(const size_t id)
Executes a timer.
Definition: timer.cpp:175
See LEFT_BUTTON_CLICK.
Definition: handler.hpp:102
bool find(E event, F functor)
Tests whether an event handler is available.
cl_event event
Definition: glew.h:3070
A SDL right mouse button up event.
Definition: handler.hpp:108
void disconnect_dispatcher(tdispatcher *dispatcher)
Disconnects a dispatcher to the event handler.
Definition: handler.cpp:781
Base class for all widgets.
Definition: widget.hpp:49
GLint * first
Definition: glew.h:1496
The main application window is activated.
Definition: handler.hpp:156
void mouse_wheel(const tpoint &position, int scrollx, int scrolly)
Fires a mouse wheel event.
Definition: handler.cpp:632
void activate()
Reinitializes the state of all dispatchers.
Definition: handler.cpp:490
virtual void leave()
Definition: events.cpp:212
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
This singleton class handles all events.
Definition: handler.cpp:123
bool get_want_keyboard_input() const
Definition: dispatcher.hpp:511
bool hotkey_pressed(const hotkey::hotkey_ptr key)
Handles the pressing of a hotkey.
Definition: handler.cpp:711
void handle_event(const SDL_Event &event)
Inherited from events::sdl_handler.
Definition: handler.cpp:322
A SDL key down event.
Definition: handler.hpp:126
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void handle_window_event(const SDL_Event &event)
Inherited from events::sdl_handler.
Definition: handler.cpp:436
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id
std::string string
void capture_keyboard(tdispatcher *dispatcher)
Captures the keyboard.
Definition: handler.cpp:817
#define SDL_BUTTON_WHEELRIGHT
Definition: utils.hpp:47