52 m_sdleventListeners(),
57 m_mouseSensitivity(0.0),
58 m_acceleration(false),
65 m_joystickManager(NULL) {
74 if (!listener->isActive()) {
75 listener->setActive(
true);
76 vec.push_back(listener);
82 if (!listener->isActive()) {
83 listener->setActive(
true);
84 vec.push_front(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) {
193 std::deque<ICommandListener*>::iterator i = listeners.begin();
194 for (; i != listeners.end(); ++i) {
195 if (!(*i)->isActive())
continue;
196 (*i)->onCommand(command);
205 std::deque<IKeyListener*>::iterator i = listeners.begin();
206 for (; i != listeners.end(); ++i) {
207 if (!(*i)->isActive() || (evt.
isConsumedByWidgets() && !(*i)->isGlobalListener()))
continue;
210 (*i)->keyPressed(evt);
213 (*i)->keyReleased(evt);
226 std::deque<ITextListener*>::iterator i = listeners.begin();
227 for (; i != listeners.end(); ++i) {
228 if (!(*i)->isActive())
continue;
231 (*i)->textInput(evt);
247 std::deque<IMouseListener*>::iterator i = listeners.begin();
248 for (; i != listeners.end(); ++i) {
249 if (!(*i)->isActive() || (evt.
isConsumedByWidgets() && !(*i)->isGlobalListener()))
continue;
252 (*i)->mouseMoved(evt);
255 (*i)->mousePressed(evt);
258 (*i)->mouseReleased(evt);
261 (*i)->mouseWheelMovedDown(evt);
264 (*i)->mouseWheelMovedUp(evt);
267 (*i)->mouseWheelMovedRight(evt);
270 (*i)->mouseWheelMovedLeft(evt);
273 (*i)->mouseClicked(evt);
276 (*i)->mouseEntered(evt);
279 (*i)->mouseExited(evt);
282 (*i)->mouseDragged(evt);
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);
306 std::deque<IDropListener*>::iterator i = listeners.begin();
307 for (; i != listeners.end(); ++i) {
308 if (!(*i)->isActive())
continue;
309 (*i)->fileDropped(evt);
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;
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);
343 switch (event.type) {
352 case SDL_WINDOWEVENT:
367 case SDL_MOUSEBUTTONUP:
368 case SDL_MOUSEMOTION:
369 case SDL_MOUSEBUTTONDOWN:
377 case SDL_JOYBUTTONDOWN:
378 case SDL_JOYBUTTONUP:
379 case SDL_JOYAXISMOTION:
380 case SDL_JOYHATMOTION:
381 case SDL_JOYDEVICEADDED:
382 case SDL_JOYDEVICEREMOVED: {
388 case SDL_CONTROLLERBUTTONDOWN:
389 case SDL_CONTROLLERBUTTONUP:
390 case SDL_CONTROLLERAXISMOTION: {
398 if (has_next_event) {
410 switch (event.window.event) {
411 case SDL_WINDOWEVENT_CLOSE:
415 case SDL_WINDOWEVENT_ENTER:
419 case SDL_WINDOWEVENT_LEAVE:
423 case SDL_WINDOWEVENT_FOCUS_GAINED:
427 case SDL_WINDOWEVENT_FOCUS_LOST:
431 case SDL_WINDOWEVENT_SHOWN:
435 case SDL_WINDOWEVENT_MINIMIZED:
436 case SDL_WINDOWEVENT_HIDDEN:
489 float difference =
static_cast<float>((ticks -
m_lastTicks) + 1);
491 float dx =
static_cast<float>(tmp_x -
m_oldX);
492 float dy =
static_cast<float>(tmp_y -
m_oldY);
494 float acceleration =
static_cast<float>((distance / difference) / difference);
495 float velocity = (
m_oldVelocity + acceleration * difference)/2;
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)) {
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) {
513 }
else if ((tmp_x + x_fact) < screen.
x) {
519 if (tmp_y + y_fact > screen.
h) {
521 }
else if ((tmp_y + y_fact) < screen.
y) {
528 event.motion.x = tmp_x;
529 event.motion.y = tmp_y;
540 if (event.type == SDL_MOUSEBUTTONDOWN) {
543 }
else if (event.type == SDL_MOUSEBUTTONUP) {
559 char* tmp =
event.drop.file;
560 std::string path(tmp);
574 mouseevt.
setX(sdlevt.button.x);
575 mouseevt.
setY(sdlevt.button.y);
579 if ((sdlevt.type == SDL_MOUSEBUTTONUP) || (sdlevt.type == SDL_MOUSEBUTTONDOWN)) {
580 switch (sdlevt.button.button) {
581 case SDL_BUTTON_LEFT:
584 case SDL_BUTTON_RIGHT:
587 case SDL_BUTTON_MIDDLE:
601 if (sdlevt.button.state == SDL_RELEASED) {
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)) {
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)) {
620 if (sdlevt.wheel.y > 0) {
622 }
else if (sdlevt.wheel.y < 0) {
625 if (sdlevt.wheel.x > 0) {
627 }
else if (sdlevt.wheel.x < 0) {
640 if (sdlevt.type == SDL_KEYDOWN) {
642 }
else if (sdlevt.type == SDL_KEYUP) {
646 <<
" Invalid key event type of " << sdlevt.type <<
". Ignoring event.");
650 SDL_Keysym keysym = sdlevt.key.keysym;
656 keyevt.
setKey(
Key(static_cast<Key::KeyType>(keysym.sym)));
660 if (sdlevt.type == SDL_TEXTINPUT) {
662 Text t(sdlevt.text.text);
664 }
else if (sdlevt.type == SDL_TEXTEDITING) {
666 Text t(sdlevt.edit.text, sdlevt.edit.start, sdlevt.edit.length);
670 <<
" Invalid text event type of " << sdlevt.type <<
". Ignoring event.");
693 if (sensitivity < -0.99) {
695 }
else if (sensitivity > 10.0) {
714 return SDL_HasClipboardText();
719 if (SDL_HasClipboardText()) {
720 text = std::string(SDL_GetClipboardText());
726 SDL_SetClipboardText(text.c_str());
bool isMouseAccelerationEnabled() const
Returns if mouse acceleration is enabled or not.
#define FL_WARN(logger, msg)
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.
void setPath(const std::string &path)
Sets the path for the file that is droped.
void setClipboardText(const std::string &text)
Sets clipboard text.
std::deque< ITextListener * > m_textListeners
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.
void saveGamepadMapping(const std::string guid, const std::string &file)
Saves controller mapping for given GUID in the specified file.
T h
Height of the rectangle.
void addTextListenerFront(ITextListener *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.
void setKey(const Key &key)
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
Controller provides a way to receive events from the system Using this interface, clients can subscri...
uint8_t getJoystickCount() const
Return the number of joysticks / gamecontrollers.
bool combineEvents(SDL_Event &event1, const SDL_Event &event2)
Listener of command events.
virtual void setSource(IEventSource *source)
Sets the source of the event.
void addJoystickListenerFront(IJoystickListener *listener)
std::deque< ICommandListener * > m_commandListeners
void removeJoystickListener(IJoystickListener *listener)
TextEventType getType() const
virtual void setSource(IEventSource *source)
Sets the source of the event.
KeyEventType getType() const
virtual void setSource(IEventSource *source)
Sets the source of the event.
virtual bool isConsumed() const
Checks whether event is consumed.
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...
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.
void dispatchDropEvent(DropEvent &evt)
virtual bool isConsumedByWidgets() const
Checks whether event is consumed by widget library.
static RenderBackend * instance()
virtual void setShiftPressed(bool pressed)
Sets shift to pressed.
void removeDropListener(IDropListener *listener)
Removes an added listener from the controller.
virtual bool isConsumed() const
Checks whether event is consumed.
virtual bool isConsumed() const
Checks whether event is consumed.
std::deque< IDropListener * > m_dropListeners
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.
Represents a Joystick and if available the Gamecontroller.
Joystick * getJoystick(int32_t instanceId)
Return the joystick with the given instance id.
virtual bool isConsumed() const
Checks whether event is consumed.
CommandType
Types for different commands.
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)
void setText(const Text &text)
MouseEventType getType() const
Gets the type of the event.
virtual void setMetaPressed(bool pressed)
Sets meta to pressed.
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
Class for commands Commands are arbitrary events e.g.
Joystick Manager manages all events related to Joysticks and Gamecontrollers.
void processDropEvent(SDL_Event event)
std::deque< IMouseListener * > m_mouseListeners
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
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)
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
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.
void setKeyFilter(IKeyFilter *keyFilter)
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)
void setButton(MouseButtonType type)
void setType(TextEventType type)
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.
void fillKeyEvent(const SDL_Event &sdlevt, KeyEvent &keyevt)
Joystick * getJoystick(int32_t instanceId)
Return the joystick with the given instance id.
JoystickManager * m_joystickManager
void setType(KeyEventType type)
MouseEvent::MouseButtonType m_mostrecentbtn
virtual void consumedByWidgets()
Marks events as consumed by widget library.
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
void setJoystickSupport(bool support)
Sets the joystick support to enabled or disabled.
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.
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)
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)
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.
KeyType getValue() const
Gets the value of the key.
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.
virtual void setAltPressed(bool pressed)
Sets alt to pressed.
virtual bool isFiltered(const KeyEvent &event)=0
Check whether a keyevent should be filtered out.
std::deque< IKeyListener * > m_keyListeners
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.
void removeSdlEventListener(ISdlEventListener *listener)
Removes an added listener from the controller.