51 m_sdleventlisteners(),
57 m_mousesensitivity(0.0),
58 m_acceleration(false),
72 vec.push_back(listener);
77 vec.push_back(listener);
165 (*i)->onCommand(command);
212 (*i)->keyPressed(evt);
215 (*i)->keyReleased(evt);
263 (*i)->mouseMoved(evt);
266 (*i)->mousePressed(evt);
269 (*i)->mouseReleased(evt);
272 (*i)->mouseWheelMovedDown(evt);
275 (*i)->mouseWheelMovedUp(evt);
278 (*i)->mouseClicked(evt);
281 (*i)->mouseEntered(evt);
284 (*i)->mouseExited(evt);
287 (*i)->mouseDragged(evt);
337 ret = ret || (*i)->onSdlEvent(evt);
344 if(event1.type == event2.type) {
345 switch (event1.type) {
346 case SDL_MOUSEMOTION:
347 if(event1.motion.state == event2.motion.state) {
348 event1.motion.x = event2.motion.x;
349 event1.motion.y = event2.motion.y;
350 event1.motion.xrel += event2.motion.xrel;
351 event1.motion.yrel += event2.motion.yrel;
363 SDL_Event event, next_event;
364 bool has_next_event = (SDL_PollEvent(&event) != 0);
365 while (has_next_event) {
366 has_next_event = (SDL_PollEvent(&next_event) != 0);
370 switch (event.type) {
379 case SDL_ACTIVEEVENT:
388 case SDL_MOUSEBUTTONUP:
389 case SDL_MOUSEMOTION:
390 case SDL_MOUSEBUTTONDOWN:
404 SDL_ActiveEvent actevt =
event.active;
405 std::vector<Command*> commands;
407 if (actevt.state & SDL_APPMOUSEFOCUS) {
415 commands.push_back(cmd);
417 if (actevt.state & SDL_APPINPUTFOCUS) {
424 commands.push_back(cmd);
426 if (actevt.state & SDL_APPACTIVE) {
433 commands.push_back(cmd);
436 std::vector<Command*>::iterator it = commands.begin();
437 for (; it != commands.end(); ++it) {
454 if( dispatchAsSdl ) {
476 float difference =
static_cast<float>((ticks -
m_lastticks) + 1);
478 float dx =
static_cast<float>(tmp_x -
m_oldx);
479 float dy =
static_cast<float>(tmp_y -
m_oldy);
481 float acceleration =
static_cast<float>((distance / difference) / difference);
482 float velocity = (
m_oldvelocity + acceleration * difference)/2;
492 int16_t tmp_xrel =
static_cast<int16_t
>(tmp_x -
m_oldx);
493 int16_t tmp_yrel =
static_cast<int16_t
>(tmp_y -
m_oldy);
494 if ((tmp_xrel != 0) || (tmp_yrel != 0)) {
496 int16_t x_fact =
static_cast<int16_t
>(round(static_cast<float>(tmp_xrel * modifier)));
497 int16_t y_fact =
static_cast<int16_t
>(round(static_cast<float>(tmp_yrel * modifier)));
498 if ((tmp_x + x_fact) > screen.
w) {
500 }
else if ((tmp_x + x_fact) < screen.
x) {
506 if (tmp_y + y_fact > screen.
h) {
508 }
else if ((tmp_y + y_fact) < screen.
y) {
515 event.motion.x = tmp_x;
516 event.motion.y = tmp_y;
518 SDL_WarpMouse(tmp_x, tmp_y);
527 if (event.type == SDL_MOUSEBUTTONDOWN) {
530 }
else if (event.type == SDL_MOUSEBUTTONUP) {
541 if (event.button.button == SDL_BUTTON_WHEELDOWN || event.button.button == SDL_BUTTON_WHEELUP) {
542 if (event.type == SDL_MOUSEBUTTONUP) {
555 mouseevt.
setX(sdlevt.button.x);
556 mouseevt.
setY(sdlevt.button.y);
560 if ((sdlevt.type == SDL_MOUSEBUTTONUP) || (sdlevt.type == SDL_MOUSEBUTTONDOWN)) {
561 switch (sdlevt.button.button) {
562 case SDL_BUTTON_LEFT:
565 case SDL_BUTTON_RIGHT:
568 case SDL_BUTTON_MIDDLE:
576 if (sdlevt.type == SDL_MOUSEBUTTONUP ) {
582 switch (sdlevt.button.button) {
583 case SDL_BUTTON_WHEELDOWN:
586 case SDL_BUTTON_WHEELUP:
600 if (sdlevt.type == SDL_KEYDOWN) {
602 }
else if (sdlevt.type == SDL_KEYUP) {
606 <<
" Invalid key event type of " << sdlevt.type <<
". Ignoring event.");
609 SDL_keysym keysym = sdlevt.key.keysym;
615 keyevt.
setNumericPad(keysym.sym >= SDLK_KP0 && keysym.sym <= SDLK_KP_EQUALS);
616 keyevt.
setKey(
Key(static_cast<Key::KeyType>(keysym.sym), keysym.unicode));
644 if (sensitivity < -0.99) {
646 }
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.
void setMouseFilter(IMouseFilter *mouseFilter)
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.
IMouseFilter * m_mousefilter
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)
Controller provides a way to receive events from the system Using this interface, clients can subscri...
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.
virtual bool isFiltered(const MouseEvent &event)=0
Check whether a mouseevent should be filtered out.
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.