50 m_sdleventlisteners(),
55 m_mousesensitivity(0.0),
56 m_acceleration(false),
70 vec.push_back(listener);
75 vec.push_back(listener);
163 (*i)->onCommand(command);
210 (*i)->keyPressed(evt);
213 (*i)->keyReleased(evt);
261 (*i)->mouseMoved(evt);
264 (*i)->mousePressed(evt);
267 (*i)->mouseReleased(evt);
270 (*i)->mouseWheelMovedDown(evt);
273 (*i)->mouseWheelMovedUp(evt);
276 (*i)->mouseClicked(evt);
279 (*i)->mouseEntered(evt);
282 (*i)->mouseExited(evt);
285 (*i)->mouseDragged(evt);
335 ret = ret || (*i)->onSdlEvent(evt);
342 if(event1.type == event2.type) {
343 switch (event1.type) {
344 case SDL_MOUSEMOTION:
345 if(event1.motion.state == event2.motion.state) {
346 event1.motion.x = event2.motion.x;
347 event1.motion.y = event2.motion.y;
348 event1.motion.xrel += event2.motion.xrel;
349 event1.motion.yrel += event2.motion.yrel;
361 SDL_Event event, next_event;
362 bool has_next_event = (SDL_PollEvent(&event) != 0);
363 while (has_next_event) {
364 has_next_event = (SDL_PollEvent(&next_event) != 0);
368 switch (event.type) {
377 case SDL_ACTIVEEVENT:
386 case SDL_MOUSEBUTTONUP:
387 case SDL_MOUSEMOTION:
388 case SDL_MOUSEBUTTONDOWN:
402 SDL_ActiveEvent actevt =
event.active;
403 std::vector<Command*> commands;
405 if (actevt.state & SDL_APPMOUSEFOCUS) {
413 commands.push_back(cmd);
415 if (actevt.state & SDL_APPINPUTFOCUS) {
422 commands.push_back(cmd);
424 if (actevt.state & SDL_APPACTIVE) {
431 commands.push_back(cmd);
434 std::vector<Command*>::iterator it = commands.begin();
435 for (; it != commands.end(); ++it) {
452 if( dispatchAsSdl ) {
474 float difference =
static_cast<float>((ticks -
m_lastticks) + 1);
476 float dx =
static_cast<float>(tmp_x -
m_oldx);
477 float dy =
static_cast<float>(tmp_y -
m_oldy);
479 float acceleration =
static_cast<float>((distance / difference) / difference);
480 float velocity = (
m_oldvelocity + acceleration * difference)/2;
490 int16_t tmp_xrel =
static_cast<int16_t
>(tmp_x -
m_oldx);
491 int16_t tmp_yrel =
static_cast<int16_t
>(tmp_y -
m_oldy);
492 if ((tmp_xrel != 0) || (tmp_yrel != 0)) {
494 int16_t x_fact =
static_cast<int16_t
>(round(static_cast<float>(tmp_xrel * modifier)));
495 int16_t y_fact =
static_cast<int16_t
>(round(static_cast<float>(tmp_yrel * modifier)));
496 if ((tmp_x + x_fact) > screen.
w) {
498 }
else if ((tmp_x + x_fact) < screen.
x) {
504 if (tmp_y + y_fact > screen.
h) {
506 }
else if ((tmp_y + y_fact) < screen.
y) {
513 event.motion.x = tmp_x;
514 event.motion.y = tmp_y;
516 SDL_WarpMouse(tmp_x, tmp_y);
528 if (event.type == SDL_MOUSEBUTTONDOWN) {
531 }
else if (event.type == SDL_MOUSEBUTTONUP) {
535 if (event.button.button == SDL_BUTTON_WHEELDOWN || event.button.button == SDL_BUTTON_WHEELUP) {
536 if (event.type == SDL_MOUSEBUTTONUP) {
549 mouseevt.
setX(sdlevt.button.x);
550 mouseevt.
setY(sdlevt.button.y);
554 if ((sdlevt.type == SDL_MOUSEBUTTONUP) || (sdlevt.type == SDL_MOUSEBUTTONDOWN)) {
555 switch (sdlevt.button.button) {
556 case SDL_BUTTON_LEFT:
559 case SDL_BUTTON_RIGHT:
562 case SDL_BUTTON_MIDDLE:
570 if (sdlevt.type == SDL_MOUSEBUTTONUP ) {
576 switch (sdlevt.button.button) {
577 case SDL_BUTTON_WHEELDOWN:
580 case SDL_BUTTON_WHEELUP:
594 if (sdlevt.type == SDL_KEYDOWN) {
596 }
else if (sdlevt.type == SDL_KEYUP) {
600 <<
" Invalid key event type of " << sdlevt.type <<
". Ignoring event.");
603 SDL_keysym keysym = sdlevt.key.keysym;
609 keyevt.
setNumericPad(keysym.sym >= SDLK_KP0 && keysym.sym <= SDLK_KP_EQUALS);
610 keyevt.
setKey(
Key(static_cast<Key::KeyType>(keysym.sym), keysym.unicode));
634 if (sensitivity < -0.99) {
636 }
else if (sensitivity > 10.0) {
#define FL_WARN(logger, msg)
void removeMouseListener(IMouseListener *listener)
Removes an added listener from the controller.
KeyEventType getType() const
float getMouseSensitivity() const
Gets mouse sensitivity.
void addKeyListenerFront(IKeyListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
virtual bool isConsumed() const
Checks if the event is consumed.
T h
Height of the rectangle.
void setKey(const Key &key)
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
KeyType getValue() const
Gets the value of the key.
Controller provides a way to receive events from the system Using this interface, clients can subscri...
MouseEventType getType() const
Gets the type of the event.
std::deque< IKeyListener * > m_pending_keylisteners
std::deque< IMouseListener * > m_pending_mouselisteners
std::deque< ISdlEventListener * > m_pending_sdleventlisteners_front
bool combineEvents(SDL_Event &event1, const SDL_Event &event2)
Listener of command events.
virtual void setSource(IEventSource *source)
Sets the source of the event.
virtual void setSource(IEventSource *source)
Sets the source of the event.
MouseButtonType getButton() const
Gets the button of the mouse event.
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 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...
std::deque< IKeyListener * > m_pending_kldeletions
virtual void setControlPressed(bool pressed)
static RenderBackend * instance()
virtual void setShiftPressed(bool pressed)
virtual void setSource(IEventSource *source)
Sets the source of the event.
void removeCommandListener(ICommandListener *listener)
Removes an added listener from the controller.
void dispatchMouseEvent(MouseEvent &evt)
const Key & getKey() const
std::deque< ISdlEventListener * > m_pending_sdleventlisteners
static bool Equal(T _val1, T _val2)
virtual void setMetaPressed(bool pressed)
void addCommandListener(ICommandListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
std::deque< IKeyListener * > m_keylisteners
std::deque< ICommandListener * > m_pending_cldeletions
void removeListener(std::deque< T > &vec, T &listener)
Class for commands Commands are arbitrary events e.g.
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::deque< IMouseListener * > m_pending_mouselisteners_front
Represents a key or a character.
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
void setKeyFilter(IKeyFilter *keyFilter)
std::deque< IMouseListener * > m_mouselisteners
void setNumericPad(bool ispad)
void setButton(MouseButtonType type)
void removeKeyListener(IKeyListener *listener)
Removes an added listener from the controller.
EventManager()
Constructor.
bool isFunctionKey() const
virtual bool isConsumed() const
Checks if the event is consumed.
void setCommandType(CommandType type)
void fillKeyEvent(const SDL_Event &sdlevt, KeyEvent &keyevt)
std::deque< IMouseListener * > m_pending_mldeletions
void setType(KeyEventType type)
MouseEvent::MouseButtonType m_mostrecentbtn
std::deque< IKeyListener * > m_pending_keylisteners_front
bool isMouseAccelerationEnabled() const
Returns if mouse acceleration is enabled or not.
void addMouseListener(IMouseListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
std::deque< ISdlEventListener * > m_sdleventlisteners
void processKeyEvent(SDL_Event event)
virtual ~EventManager()
Destructor.
bool dispatchSdlEvent(SDL_Event &evt)
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.
std::deque< ICommandListener * > m_commandlisteners
void processEvents()
Process the SDL event queue.
void addMouseListenerFront(IMouseListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
std::deque< ICommandListener * > m_pending_commandlisteners_front
T w
Width of the rectangle.
std::deque< ISdlEventListener * > m_pending_sdldeletions
virtual void setAltPressed(bool pressed)
virtual bool isFiltered(const KeyEvent &event)=0
Check whether a keyevent should be filtered out.
std::deque< ICommandListener * > m_pending_commandlisteners
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 processActiveEvent(SDL_Event event)
const Rect & getArea() const
void removeSdlEventListener(ISdlEventListener *listener)
Removes an added listener from the controller.