FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
eventmanager.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 // Standard C++ library includes
23 #include <iostream>
24 
25 // 3rd party library includes
26 
27 // FIFE includes
28 // These includes are split up in two parts, separated by one empty line
29 // First block: files included from the FIFE root src directory
30 // Second block: files included from the same folder
31 #include "util/base/exception.h"
32 #include "util/log/logger.h"
33 #include "util/math/fife_math.h"
35 #include "eventchannel/key/key.h"
40 #include "video/renderbackend.h"
41 
42 #include "eventmanager.h"
43 
44 namespace FIFE {
45  static Logger _log(LM_EVTCHANNEL);
46 
48  m_commandListeners(),
49  m_keyListeners(),
50  m_textListeners(),
51  m_mouseListeners(),
52  m_sdleventListeners(),
53  m_keystatemap(),
54  m_keyfilter(0),
55  m_mousestate(0),
56  m_mostrecentbtn(MouseEvent::EMPTY),
57  m_mouseSensitivity(0.0),
58  m_acceleration(false),
59  m_warp(false),
60  m_enter(false),
61  m_oldX(0),
62  m_oldY(0),
63  m_lastTicks(0),
64  m_oldVelocity(0.0),
65  m_joystickManager(NULL) {
66  }
67 
69  delete m_joystickManager;
70  }
71 
72  template<typename T>
73  void addListener(std::deque<T>& vec, T& listener) {
74  if (!listener->isActive()) {
75  listener->setActive(true);
76  vec.push_back(listener);
77  }
78  }
79 
80  template<typename T>
81  void addListenerFront(std::deque<T>& vec, T& listener) {
82  if (!listener->isActive()) {
83  listener->setActive(true);
84  vec.push_front(listener);
85  }
86  }
87 
88  template<typename T>
89  void removeListener(std::deque<T>& vec, T& listener) {
90  if (listener->isActive()) {
91  listener->setActive(false);
92  for (typename std::deque<T>::iterator it = vec.begin(); it != vec.end(); ++it) {
93  if (*it == listener) {
94  vec.erase(it);
95  break;
96  }
97  }
98  }
99  }
100 
102  addListener<ICommandListener*>(m_commandListeners, listener);
103  }
104 
106  addListenerFront<ICommandListener*>(m_commandListeners, listener);
107  }
108 
110  removeListener<ICommandListener*>(m_commandListeners, listener);
111  }
112 
114  addListener<IKeyListener*>(m_keyListeners, listener);
115  }
116 
118  addListenerFront<IKeyListener*>(m_keyListeners, listener);
119  }
120 
122  removeListener<IKeyListener*>(m_keyListeners, listener);
123  }
124 
126  addListener<ITextListener*>(m_textListeners, listener);
127  }
128 
130  addListenerFront<ITextListener*>(m_textListeners, listener);
131  }
132 
134  removeListener<ITextListener*>(m_textListeners, listener);
135  }
136 
138  addListener<IMouseListener*>(m_mouseListeners, listener);
139  }
140 
142  addListenerFront<IMouseListener*>(m_mouseListeners, listener);
143  }
144 
146  removeListener<IMouseListener*>(m_mouseListeners, listener);
147  }
148 
150  addListener<ISdlEventListener*>(m_sdleventListeners, listener);
151  }
152 
154  addListenerFront<ISdlEventListener*>(m_sdleventListeners, listener);
155  }
156 
158  removeListener<ISdlEventListener*>(m_sdleventListeners, listener);
159  }
160 
162  addListener<IDropListener*>(m_dropListeners, listener);
163  }
164 
166  addListenerFront<IDropListener*>(m_dropListeners, listener);
167  }
168 
170  removeListener<IDropListener*>(m_dropListeners, listener);
171  }
172 
174  if (m_joystickManager) {
176  }
177  }
178 
180  if (m_joystickManager) {
182  }
183  }
184 
186  if (m_joystickManager) {
188  }
189  }
190 
192  std::deque<ICommandListener*> listeners = m_commandListeners;
193  std::deque<ICommandListener*>::iterator i = listeners.begin();
194  for (; i != listeners.end(); ++i) {
195  if (!(*i)->isActive()) continue;
196  (*i)->onCommand(command);
197  if (command.isConsumed()) {
198  break;
199  }
200  }
201  }
202 
204  std::deque<IKeyListener*> listeners = m_keyListeners;
205  std::deque<IKeyListener*>::iterator i = listeners.begin();
206  for (; i != listeners.end(); ++i) {
207  if (!(*i)->isActive() || (evt.isConsumedByWidgets() && !(*i)->isGlobalListener())) continue;
208  switch (evt.getType()) {
209  case KeyEvent::PRESSED:
210  (*i)->keyPressed(evt);
211  break;
212  case KeyEvent::RELEASED:
213  (*i)->keyReleased(evt);
214  break;
215  default:
216  break;
217  }
218  if (evt.isConsumed()) {
219  break;
220  }
221  }
222  }
223 
225  std::deque<ITextListener*> listeners = m_textListeners;
226  std::deque<ITextListener*>::iterator i = listeners.begin();
227  for (; i != listeners.end(); ++i) {
228  if (!(*i)->isActive()) continue;
229  switch (evt.getType()) {
230  case TextEvent::INPUT:
231  (*i)->textInput(evt);
232  break;
233  case TextEvent::EDIT:
234  (*i)->textEdit(evt);
235  break;
236  default:
237  break;
238  }
239  if (evt.isConsumed()) {
240  break;
241  }
242  }
243  }
244 
246  std::deque<IMouseListener*> listeners = m_mouseListeners;
247  std::deque<IMouseListener*>::iterator i = listeners.begin();
248  for (; i != listeners.end(); ++i) {
249  if (!(*i)->isActive() || (evt.isConsumedByWidgets() && !(*i)->isGlobalListener())) continue;
250  switch (evt.getType()) {
251  case MouseEvent::MOVED:
252  (*i)->mouseMoved(evt);
253  break;
254  case MouseEvent::PRESSED:
255  (*i)->mousePressed(evt);
256  break;
258  (*i)->mouseReleased(evt);
259  break;
261  (*i)->mouseWheelMovedDown(evt);
262  break;
264  (*i)->mouseWheelMovedUp(evt);
265  break;
267  (*i)->mouseWheelMovedRight(evt);
268  break;
270  (*i)->mouseWheelMovedLeft(evt);
271  break;
272  case MouseEvent::CLICKED:
273  (*i)->mouseClicked(evt);
274  break;
275  case MouseEvent::ENTERED:
276  (*i)->mouseEntered(evt);
277  break;
278  case MouseEvent::EXITED:
279  (*i)->mouseExited(evt);
280  break;
281  case MouseEvent::DRAGGED:
282  (*i)->mouseDragged(evt);
283  break;
284  default:
285  break;
286  }
287  if (evt.isConsumed()) {
288  break;
289  }
290  }
291  }
292 
293  bool EventManager::dispatchSdlEvent(SDL_Event& evt) {
294  bool ret = false;
295  std::deque<ISdlEventListener*> listeners = m_sdleventListeners;
296  std::deque<ISdlEventListener*>::iterator i = listeners.begin();
297  for (; i != listeners.end(); ++i) {
298  if (!(*i)->isActive()) continue;
299  ret = ret || (*i)->onSdlEvent(evt);
300  }
301  return ret;
302  }
303 
305  std::deque<IDropListener*> listeners = m_dropListeners;
306  std::deque<IDropListener*>::iterator i = listeners.begin();
307  for (; i != listeners.end(); ++i) {
308  if (!(*i)->isActive()) continue;
309  (*i)->fileDropped(evt);
310  if (evt.isConsumed()) {
311  break;
312  }
313  }
314  }
315 
316  bool EventManager::combineEvents(SDL_Event& event1, const SDL_Event& event2) {
317  if(event1.type == event2.type) {
318  switch (event1.type) {
319  case SDL_MOUSEMOTION:
320  if(event1.motion.state == event2.motion.state) {
321  event1.motion.x = event2.motion.x;
322  event1.motion.y = event2.motion.y;
323  event1.motion.xrel += event2.motion.xrel;
324  event1.motion.yrel += event2.motion.yrel;
325  return true;
326  }
327  return false;
328  }
329  }
330  return false;
331  }
332 
334  // The double SDL_PollEvent calls don't throw away events,
335  // but try to combine (mouse motion) events.
336  SDL_Event event, next_event;
337  bool has_next_event = (SDL_PollEvent(&event) != 0);
338  while (has_next_event) {
339  has_next_event = (SDL_PollEvent(&next_event) != 0);
340  if (has_next_event && combineEvents(event, next_event)) {
341  continue;
342  }
343  switch (event.type) {
344  case SDL_QUIT: {
345  Command cmd;
346  cmd.setSource(this);
348  dispatchCommand(cmd);
349  }
350  break;
351 
352  case SDL_WINDOWEVENT:
353  processWindowEvent(event);
354  break;
355 
356  case SDL_KEYDOWN:
357  case SDL_KEYUP:
358  processKeyEvent(event);
359  break;
360 
361  //case SDL_TEXTEDITING: // is buggy with SDL 2.0.1
362  case SDL_TEXTINPUT:
363  processTextEvent(event);
364  break;
365 
366  case SDL_MOUSEWHEEL:
367  case SDL_MOUSEBUTTONUP:
368  case SDL_MOUSEMOTION:
369  case SDL_MOUSEBUTTONDOWN:
370  processMouseEvent(event);
371  break;
372 
373  case SDL_DROPFILE:
374  processDropEvent(event);
375  break;
376 
377  case SDL_JOYBUTTONDOWN:
378  case SDL_JOYBUTTONUP:
379  case SDL_JOYAXISMOTION:
380  case SDL_JOYHATMOTION:
381  case SDL_JOYDEVICEADDED:
382  case SDL_JOYDEVICEREMOVED: {
383  if (m_joystickManager) {
385  }
386  break;
387  }
388  case SDL_CONTROLLERBUTTONDOWN:
389  case SDL_CONTROLLERBUTTONUP:
390  case SDL_CONTROLLERAXISMOTION: {
391  if (m_joystickManager) {
393  }
394  break;
395  }
396 
397  }
398  if (has_next_event) {
399  event = next_event;
400  }
401  }
402  }
403 
404  void EventManager::processWindowEvent(SDL_Event event) {
405  if (dispatchSdlEvent(event)) {
406  return;
407  }
408 
410  switch (event.window.event) {
411  case SDL_WINDOWEVENT_CLOSE:
412  ct = CMD_QUIT_GAME;
413  break;
414 
415  case SDL_WINDOWEVENT_ENTER:
417  break;
418 
419  case SDL_WINDOWEVENT_LEAVE:
421  break;
422 
423  case SDL_WINDOWEVENT_FOCUS_GAINED:
425  break;
426 
427  case SDL_WINDOWEVENT_FOCUS_LOST:
429  break;
430 
431  case SDL_WINDOWEVENT_SHOWN:
432  ct = CMD_APP_RESTORED;
433  break;
434 
435  case SDL_WINDOWEVENT_MINIMIZED:
436  case SDL_WINDOWEVENT_HIDDEN:
437  ct = CMD_APP_ICONIFIED;
438  break;
439 
440  default:
441  ct = CMD_UNKNOWN;
442  }
443  if (ct != CMD_UNKNOWN) {
444  Command cmd;
445  cmd.setCommandType(ct);
446  dispatchCommand(cmd);
447  }
448  }
449 
450  void EventManager::processKeyEvent(SDL_Event event) {
451  KeyEvent keyevt;
452  keyevt.setSource(this);
453  fillKeyEvent(event, keyevt);
454  m_keystatemap[keyevt.getKey().getValue()] = (keyevt.getType() == KeyEvent::PRESSED);
455  // if event is not filtered it gets dispatched, even it is a function key
456  if (!m_keyfilter || !m_keyfilter->isFiltered(keyevt)) {
457  if (dispatchSdlEvent(event))
458  keyevt.consumedByWidgets();
459  }
460 
461  dispatchKeyEvent(keyevt);
462  }
463 
464  void EventManager::processTextEvent(SDL_Event event) {
465  if (dispatchSdlEvent(event)) {
466  return;
467  }
468 
469  TextEvent txtevt;
470  txtevt.setSource(this);
471  fillTextEvent(event, txtevt);
472  dispatchTextEvent(txtevt);
473  }
474 
475  void EventManager::processMouseEvent(SDL_Event event) {
476  if (event.type == SDL_MOUSEMOTION && (!Mathf::Equal(m_mouseSensitivity, 0.0) || m_acceleration)) {
477  uint16_t tmp_x = event.motion.x;
478  uint16_t tmp_y = event.motion.y;
479  if (m_enter) {
480  m_oldX = tmp_x;
481  m_oldY = tmp_y;
482  m_oldVelocity = 0.0;
483  m_enter = false;
484  }
485 
486  float modifier;
487  if (m_acceleration) {
488  uint32_t ticks = SDL_GetTicks();
489  float difference = static_cast<float>((ticks - m_lastTicks) + 1);
490  m_lastTicks = ticks;
491  float dx = static_cast<float>(tmp_x - m_oldX);
492  float dy = static_cast<float>(tmp_y - m_oldY);
493  float distance = Mathf::Sqrt(dx * dx + dy * dy);
494  float acceleration = static_cast<float>((distance / difference) / difference);
495  float velocity = (m_oldVelocity + acceleration * difference)/2;
496  if (velocity > m_mouseSensitivity+1) {
497  velocity = m_mouseSensitivity+1;
498  }
499  m_oldVelocity = velocity;
500  modifier = velocity;
501  } else {
502  modifier = m_mouseSensitivity;
503  }
504 
505  int16_t tmp_xrel = static_cast<int16_t>(tmp_x - m_oldX);
506  int16_t tmp_yrel = static_cast<int16_t>(tmp_y - m_oldY);
507  if ((tmp_xrel != 0) || (tmp_yrel != 0)) {
508  Rect screen = RenderBackend::instance()->getArea();
509  int16_t x_fact = static_cast<int16_t>(round(static_cast<float>(tmp_xrel * modifier)));
510  int16_t y_fact = static_cast<int16_t>(round(static_cast<float>(tmp_yrel * modifier)));
511  if ((tmp_x + x_fact) > screen.w) {
512  tmp_x = screen.w;
513  } else if ((tmp_x + x_fact) < screen.x) {
514  tmp_x = screen.x;
515  } else {
516  tmp_x += x_fact;
517  }
518 
519  if (tmp_y + y_fact > screen.h) {
520  tmp_y = screen.h;
521  } else if ((tmp_y + y_fact) < screen.y) {
522  tmp_y = screen.y;
523  } else {
524  tmp_y += y_fact;
525  }
526  m_oldX = tmp_x;
527  m_oldY = tmp_y;
528  event.motion.x = tmp_x;
529  event.motion.y = tmp_y;
530  m_warp = true; //don't trigger an event handler when warping
531  SDL_WarpMouseInWindow(RenderBackend::instance()->getWindow(), tmp_x, tmp_y);
532  m_warp = false;
533  }
534  }
535 
536  MouseEvent mouseevt;
537  mouseevt.setSource(this);
538  fillMouseEvent(event, mouseevt);
539  fillModifiers(mouseevt);
540  if (event.type == SDL_MOUSEBUTTONDOWN) {
541  m_mousestate |= static_cast<int32_t>(mouseevt.getButton());
542  m_mostrecentbtn = mouseevt.getButton();
543  } else if (event.type == SDL_MOUSEBUTTONUP) {
544  m_mousestate &= ~static_cast<int32_t>(mouseevt.getButton());
545  }
546 
547  if (dispatchSdlEvent(event))
548  mouseevt.consumedByWidgets();
549 
550  dispatchMouseEvent(mouseevt);
551  }
552 
553  void EventManager::processDropEvent(SDL_Event event) {
554  // only dispatched as DropEvent
555  //if (dispatchSdlEvent(event)) {
556  // return;
557  //}
558 
559  char* tmp = event.drop.file;
560  std::string path(tmp);
561  SDL_free(tmp);
562 
563  DropEvent drop;
564  drop.setPath(path);
565  drop.setSource(this);
566  dispatchDropEvent(drop);
567  }
568 
569  void EventManager::fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt) {
570  if (m_warp) {
571  return;
572  }
573 
574  mouseevt.setX(sdlevt.button.x);
575  mouseevt.setY(sdlevt.button.y);
576 
577  mouseevt.setButton(MouseEvent::EMPTY);
578  mouseevt.setType(MouseEvent::MOVED);
579  if ((sdlevt.type == SDL_MOUSEBUTTONUP) || (sdlevt.type == SDL_MOUSEBUTTONDOWN)) {
580  switch (sdlevt.button.button) {
581  case SDL_BUTTON_LEFT:
582  mouseevt.setButton(MouseEvent::LEFT);
583  break;
584  case SDL_BUTTON_RIGHT:
585  mouseevt.setButton(MouseEvent::RIGHT);
586  break;
587  case SDL_BUTTON_MIDDLE:
588  mouseevt.setButton(MouseEvent::MIDDLE);
589  break;
590  case SDL_BUTTON_X1:
591  mouseevt.setButton(MouseEvent::X1);
592  break;
593  case SDL_BUTTON_X2:
594  mouseevt.setButton(MouseEvent::X2);
595  break;
596  default:
598  break;
599  }
600 
601  if (sdlevt.button.state == SDL_RELEASED) {
602  mouseevt.setType(MouseEvent::RELEASED);
603  } else {
604  mouseevt.setType(MouseEvent::PRESSED);
605  }
606  }
607  if (sdlevt.type == SDL_MOUSEWHEEL) {
608 #if SDL_VERSION_ATLEAST(2,0,4)
609  if (sdlevt.wheel.y > 0 || (sdlevt.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && sdlevt.wheel.y < 0)) {
611  } else if (sdlevt.wheel.y < 0 || (sdlevt.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && sdlevt.wheel.y > 0)) {
613  }
614  if (sdlevt.wheel.x > 0 || (sdlevt.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && sdlevt.wheel.x < 0)) {
616  } else if (sdlevt.wheel.x < 0 || (sdlevt.wheel.direction == SDL_MOUSEWHEEL_FLIPPED && sdlevt.wheel.x > 0)) {
618  }
619 #else
620  if (sdlevt.wheel.y > 0) {
622  } else if (sdlevt.wheel.y < 0) {
624  }
625  if (sdlevt.wheel.x > 0) {
627  } else if (sdlevt.wheel.x < 0) {
629  }
630 #endif
631  }
632 
633  if ((mouseevt.getType() == MouseEvent::MOVED) && ((m_mousestate & m_mostrecentbtn) != 0)) {
634  mouseevt.setType(MouseEvent::DRAGGED);
635  mouseevt.setButton(m_mostrecentbtn);
636  }
637  }
638 
639  void EventManager::fillKeyEvent(const SDL_Event& sdlevt, KeyEvent& keyevt) {
640  if (sdlevt.type == SDL_KEYDOWN) {
641  keyevt.setType(KeyEvent::PRESSED);
642  } else if (sdlevt.type == SDL_KEYUP) {
643  keyevt.setType(KeyEvent::RELEASED);
644  } else {
645  FL_WARN(_log, LMsg("fillKeyEvent()")
646  << " Invalid key event type of " << sdlevt.type << ". Ignoring event.");
647  return;
648  }
649 
650  SDL_Keysym keysym = sdlevt.key.keysym;
651  keyevt.setShiftPressed((keysym.mod & KMOD_SHIFT) != 0);
652  keyevt.setControlPressed((keysym.mod & KMOD_CTRL) != 0);
653  keyevt.setAltPressed((keysym.mod & KMOD_ALT) != 0);
654  keyevt.setMetaPressed((keysym.mod & KMOD_GUI) != 0); // currently gui/super keys
655  keyevt.setNumericPad((keysym.mod & KMOD_NUM) != 0);
656  keyevt.setKey(Key(static_cast<Key::KeyType>(keysym.sym)));
657  }
658 
659  void EventManager::fillTextEvent(const SDL_Event& sdlevt, TextEvent& txtevt) {
660  if (sdlevt.type == SDL_TEXTINPUT) {
661  txtevt.setType(TextEvent::INPUT);
662  Text t(sdlevt.text.text);
663  txtevt.setText(t);
664  } else if (sdlevt.type == SDL_TEXTEDITING) {
665  txtevt.setType(TextEvent::EDIT);
666  Text t(sdlevt.edit.text, sdlevt.edit.start, sdlevt.edit.length);
667  txtevt.setText(t);
668  } else {
669  FL_WARN(_log, LMsg("fillTextEvent()")
670  << " Invalid text event type of " << sdlevt.type << ". Ignoring event.");
671  }
672  }
673 
682  }
683 
685  return ES_ENGINE;
686  }
687 
689  m_keyfilter = keyFilter;
690  }
691 
692  void EventManager::setMouseSensitivity(float sensitivity) {
693  if (sensitivity < -0.99) {
694  sensitivity = -0.99;
695  } else if (sensitivity > 10.0) {
696  sensitivity = 10.0;
697  }
698  m_mouseSensitivity = sensitivity;
699  }
700 
702  return m_mouseSensitivity;
703  }
704 
706  m_acceleration = acceleration;
707  }
708 
710  return m_acceleration;
711  }
712 
714  return SDL_HasClipboardText();
715  }
716 
717  std::string EventManager::getClipboardText() const {
718  std::string text;
719  if (SDL_HasClipboardText()) {
720  text = std::string(SDL_GetClipboardText());
721  }
722  return text;
723  }
724 
725  void EventManager::setClipboardText(const std::string& text) {
726  SDL_SetClipboardText(text.c_str());
727  }
728 
729  void EventManager::setJoystickSupport(bool support) {
730  if (support && !m_joystickManager) {
732  } else if (!support && m_joystickManager) {
733  delete m_joystickManager;
734  m_joystickManager = NULL;
735  }
736  }
737 
738  Joystick* EventManager::getJoystick(int32_t instanceId) {
739  if (m_joystickManager) {
740  return m_joystickManager->getJoystick(instanceId);
741  }
742  return NULL;
743  }
744 
746  if (m_joystickManager) {
748  }
749  return 0;
750  }
751 
752  void EventManager::loadGamepadMapping(const std::string& file) {
753  if (m_joystickManager) {
755  }
756  }
757 
758  void EventManager::saveGamepadMapping(const std::string guid, const std::string& file) {
759  if (m_joystickManager) {
760  m_joystickManager->saveMapping(guid, file);
761  }
762  }
763 
764  void EventManager::saveGamepadMappings(const std::string& file) {
765  if (m_joystickManager) {
767  }
768  }
769 
770  std::string EventManager::getGamepadStringMapping(const std::string& guid) {
771  std::string mapping;
772  if (m_joystickManager) {
773  mapping = m_joystickManager->getStringMapping(guid);
774  }
775  return mapping;
776  }
777 
778  void EventManager::setGamepadStringMapping(const std::string& mapping) {
779  if (m_joystickManager) {
781  }
782  }
783 }
bool isMouseAccelerationEnabled() const
Returns if mouse acceleration is enabled or not.
#define FL_WARN(logger, msg)
Definition: logger.h:72
void addJoystickListener(IJoystickListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
void addListenerFront(std::deque< T > &vec, T &listener)
void removeMouseListener(IMouseListener *listener)
Removes an added listener from the controller.
MouseButtonType getButton() const
Gets the button of the mouse event.
Definition: mouseevent.h:95
void setPath(const std::string &path)
Sets the path for the file that is droped.
Definition: dropevent.h:62
void setClipboardText(const std::string &text)
Sets clipboard text.
virtual void setControlPressed(bool pressed)
Sets control to pressed.
Definition: inputevent.h:72
void setY(int32_t y)
Definition: mouseevent.h:119
std::deque< ITextListener * > m_textListeners
Definition: eventmanager.h:232
Listener of SDL events.
void addKeyListenerFront(IKeyListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
void saveGamepadMappings(const std::string &file)
Saves all controller mappings that were used during the season.
void processJoystickEvent(SDL_Event event)
Creates and process joystick events.
Class for mouse events.
Definition: mouseevent.h:42
void saveGamepadMapping(const std::string guid, const std::string &file)
Saves controller mapping for given GUID in the specified file.
Represents a text.
Definition: text.h:40
static T Sqrt(T _val)
Definition: fife_math.h:277
T h
Height of the rectangle.
Definition: rect.h:93
void addTextListenerFront(ITextListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
IKeyFilter * m_keyfilter
Definition: eventmanager.h:238
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: textevent.h:75
void setKey(const Key &key)
Definition: keyevent.h:72
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
Definition: logger.h:82
Listener of text events.
Definition: itextlistener.h:44
Controller provides a way to receive events from the system Using this interface, clients can subscri...
Definition: ikeyfilter.h:42
Base class for input events (like mouse and keyboard)
Definition: inputevent.h:42
uint8_t getJoystickCount() const
Return the number of joysticks / gamecontrollers.
T x
The X Coordinate.
Definition: rect.h:84
Listener of drop events.
Definition: idroplistener.h:44
bool combineEvents(SDL_Event &event1, const SDL_Event &event2)
virtual void setShiftPressed(bool pressed)
Sets shift to pressed.
Definition: inputevent.h:88
Listener of command events.
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: dropevent.h:86
void addJoystickListenerFront(IJoystickListener *listener)
std::deque< ICommandListener * > m_commandListeners
Definition: eventmanager.h:230
void removeJoystickListener(IJoystickListener *listener)
TextEventType getType() const
Definition: textevent.h:64
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: command.h:89
Class for text events.
Definition: textevent.h:45
KeyEventType getType() const
Definition: keyevent.h:65
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: mouseevent.h:135
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: dropevent.h:70
void addSdlEventListener(ISdlEventListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
static Logger _log(LM_AUDIO)
void dispatchCommand(Command &command)
Use this method to send command to command listeners.
void addDropListener(IDropListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
void addCommandListenerFront(ICommandListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
Listener of mouse events.
void setMouseAccelerationEnabled(bool acceleration)
Sets mouse acceleration if mouse acceleration is enabled, then the mouse sensitivity is used as speed...
virtual void setAltPressed(bool pressed)
Sets alt to pressed.
Definition: inputevent.h:64
void setStringMapping(const std::string &mapping)
Sets controller mapping from string and adds or updates the related controllers.
uint8_t getJoystickCount() const
Return the number of joysticks / gamecontrollers.
Listener of joystick events.
virtual void setControlPressed(bool pressed)
Sets control to pressed.
Definition: keyevent.h:77
void dispatchDropEvent(DropEvent &evt)
virtual bool isConsumedByWidgets() const
Checks whether event is consumed by widget library.
Definition: mouseevent.h:133
static RenderBackend * instance()
Definition: singleton.h:84
virtual void setShiftPressed(bool pressed)
Sets shift to pressed.
Definition: keyevent.h:81
void removeDropListener(IDropListener *listener)
Removes an added listener from the controller.
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: keyevent.h:84
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: command.h:81
std::deque< IDropListener * > m_dropListeners
Definition: eventmanager.h:235
void addDropListenerFront(IDropListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: keyevent.h:88
Represents a Joystick and if available the Gamecontroller.
Definition: joystick.h:39
Joystick * getJoystick(int32_t instanceId)
Return the joystick with the given instance id.
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: textevent.h:71
CommandType
Types for different commands.
Definition: commandids.h:41
unsigned char uint8_t
Definition: core.h:38
void removeCommandListener(ICommandListener *listener)
Removes an added listener from the controller.
void dispatchMouseEvent(MouseEvent &evt)
void processWindowEvent(SDL_Event event)
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:287
void setText(const Text &text)
Definition: textevent.h:68
MouseEventType getType() const
Gets the type of the event.
Definition: mouseevent.h:102
virtual void setMetaPressed(bool pressed)
Sets meta to pressed.
Definition: keyevent.h:79
std::string getGamepadStringMapping(const std::string &guid)
Return the controller mapping for given GUID as string.
void addCommandListener(ICommandListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
void removeListener(std::deque< T > &vec, T &listener)
const Key & getKey() const
Definition: keyevent.h:71
Class for commands Commands are arbitrary events e.g.
Definition: command.h:44
Joystick Manager manages all events related to Joysticks and Gamecontrollers.
void processDropEvent(SDL_Event event)
std::deque< IMouseListener * > m_mouseListeners
Definition: eventmanager.h:233
void setGamepadStringMapping(const std::string &mapping)
Sets controller mapping from string and adds or updates the related controllers.
float getMouseSensitivity() const
Gets mouse sensitivity.
std::map< int32_t, bool > m_keystatemap
Definition: eventmanager.h:237
void fillMouseEvent(const SDL_Event &sdlevt, MouseEvent &mouseevt)
EventSourceType getEventSourceType()
Gets the source type of this event.
void addListener(std::deque< T > &vec, T &listener)
Represents a key.
Definition: key.h:41
unsigned short uint16_t
Definition: core.h:39
T y
The Y Coordinate.
Definition: rect.h:87
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
Definition: checked.h:198
void saveMapping(const std::string guid, const std::string &file)
Saves controller mapping for given GUID in the specified file.
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: mouseevent.h:131
void setKeyFilter(IKeyFilter *keyFilter)
void setX(int32_t x)
Definition: mouseevent.h:111
std::string getClipboardText() const
Returns the clipboard text as UTF-8 string.
void dispatchTextEvent(TextEvent &evt)
void processTextEvent(SDL_Event event)
void setNumericPad(bool ispad)
Definition: keyevent.h:69
void setButton(MouseButtonType type)
Definition: mouseevent.h:96
void setType(TextEventType type)
Definition: textevent.h:65
void removeKeyListener(IKeyListener *listener)
Removes an added listener from the controller.
EventManager()
Constructor.
void processControllerEvent(SDL_Event event)
Creates and process gamecontroller events.
void addJoystickListener(IJoystickListener *listener)
void setCommandType(CommandType type)
Sets the type of this command.
Definition: command.h:64
void fillKeyEvent(const SDL_Event &sdlevt, KeyEvent &keyevt)
Joystick * getJoystick(int32_t instanceId)
Return the joystick with the given instance id.
JoystickManager * m_joystickManager
Definition: eventmanager.h:254
void setType(KeyEventType type)
Definition: keyevent.h:66
MouseEvent::MouseButtonType m_mostrecentbtn
Definition: eventmanager.h:240
virtual void consumedByWidgets()
Marks events as consumed by widget library.
Definition: mouseevent.h:132
void loadMapping(const std::string &file)
Loads controller mappings from given file and if possible, it opens the related controllers.
void addJoystickListenerFront(IJoystickListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
void fillTextEvent(const SDL_Event &sdlevt, TextEvent &txtevt)
const Rect & getArea() const
std::deque< ISdlEventListener * > m_sdleventListeners
Definition: eventmanager.h:234
void setJoystickSupport(bool support)
Sets the joystick support to enabled or disabled.
Class for drop events.
Definition: dropevent.h:43
Class for key events.
Definition: keyevent.h:45
void addMouseListener(IMouseListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
virtual bool isConsumedByWidgets() const
Checks whether event is consumed by widget library.
Definition: keyevent.h:86
void processKeyEvent(SDL_Event event)
std::string getStringMapping(const std::string &guid)
Return the controller mapping for given GUID as string.
virtual ~EventManager()
Destructor.
void removeJoystickListener(IJoystickListener *listener)
Removes an added listener from the controller.
bool isClipboardText() const
Returns if clipboard have text or not.
bool dispatchSdlEvent(SDL_Event &evt)
Listener of key events.
Definition: ikeylistener.h:44
void saveMappings(const std::string &file)
Saves all controller mappings that were used during the season.
EventSourceType
Types for different event sources.
void processMouseEvent(SDL_Event event)
void setType(MouseEventType type)
Definition: mouseevent.h:103
void fillModifiers(InputEvent &evt)
void addSdlEventListenerFront(ISdlEventListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
void setMouseSensitivity(float sensitivity)
Sets mouse sensitivity The sensitivity is limited to the range -0.99 - 10.0.
unsigned int uint32_t
Definition: core.h:40
KeyType getValue() const
Gets the value of the key.
Definition: key.h:321
void processEvents()
Process the SDL event queue.
void addTextListener(ITextListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
void addMouseListenerFront(IMouseListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
T w
Width of the rectangle.
Definition: rect.h:90
virtual void setAltPressed(bool pressed)
Sets alt to pressed.
Definition: keyevent.h:75
virtual bool isFiltered(const KeyEvent &event)=0
Check whether a keyevent should be filtered out.
std::deque< IKeyListener * > m_keyListeners
Definition: eventmanager.h:231
void loadGamepadMapping(const std::string &file)
Loads controller mappings from given file and if possible, it opens the related controllers.
void addKeyListener(IKeyListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
void dispatchKeyEvent(KeyEvent &evt)
void removeTextListener(ITextListener *listener)
Removes an added listener from the controller.
virtual void consumedByWidgets()
Marks events as consumed by widget library.
Definition: keyevent.h:85
void removeSdlEventListener(ISdlEventListener *listener)
Removes an added listener from the controller.