Browse Source

Modified Sdl2WindowContext for source compatibility with others.

Stripped off key repeat and separate function for mouse wheel handling.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
07df630b24
  1. 14
      src/Contexts/Sdl2WindowContext.cpp
  2. 62
      src/Contexts/Sdl2WindowContext.h

14
src/Contexts/Sdl2WindowContext.cpp

@ -83,23 +83,23 @@ int Sdl2WindowContext::exec() {
break;
} break;
case SDL_KEYDOWN:
keyPressEvent(static_cast<Key>(event.key.keysym.sym), event.key.repeat);
keyPressEvent(static_cast<Key>(event.key.keysym.sym), Modifiers(), {});
break;
case SDL_KEYUP:
keyReleaseEvent(static_cast<Key>(event.key.keysym.sym));
keyReleaseEvent(static_cast<Key>(event.key.keysym.sym), Modifiers(), {});
break;
case SDL_MOUSEBUTTONDOWN:
mousePressEvent(static_cast<MouseButton>(event.button.button), {event.button.x, event.button.y});
mousePressEvent(static_cast<MouseButton>(event.button.button), Modifiers(), {event.button.x, event.button.y});
break;
case SDL_MOUSEBUTTONUP:
mouseReleaseEvent(static_cast<MouseButton>(event.button.button), {event.button.x, event.button.y});
mouseReleaseEvent(static_cast<MouseButton>(event.button.button), Modifiers(), {event.button.x, event.button.y});
break;
case SDL_MOUSEWHEEL:
mouseWheelEvent({event.wheel.x, event.wheel.y});
if(event.wheel.y != 0)
mousePressEvent(event.wheel.y < 0 ? MouseButton::WheelUp : MouseButton::WheelDown, Modifiers(), {event.wheel.x, event.wheel.y});
break;
case SDL_MOUSEMOTION:
mouseMotionEvent({event.motion.x, event.motion.y},
{event.motion.xrel, event.motion.yrel});
mouseMotionEvent(Modifiers(), {event.motion.x, event.motion.y});
break;
case SDL_QUIT:
return 0;

62
src/Contexts/Sdl2WindowContext.h

@ -24,6 +24,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_scancode.h>
#include <Corrade/Containers/EnumSet.h>
#include "AbstractWindowContext.h"
@ -83,6 +84,21 @@ class Sdl2WindowContext: public AbstractWindowContext {
/** @{ @name Keyboard handling */
public:
/**
* @brief %Modifier
*
* @see Modifiers, keyPressEvent(), keyReleaseEvent(),
* mousePressEvent(), mouseReleaseEvent(), mouseMotionEvent()
*/
enum class Modifier: unsigned int {};
/**
* @brief Set of modifiers
*
* @see keyPressEvent(), keyReleaseEvent()
*/
typedef Corrade::Containers::EnumSet<Modifier, unsigned int> Modifiers;
/**
* @brief Key
*
@ -101,15 +117,18 @@ class Sdl2WindowContext: public AbstractWindowContext {
/**
* @brief Key press event
* @param key Key pressed
* @param repeat Non-zero if this is a key repeat
* @param modifiers Active modifiers (not yet implemented)
* @param position Cursor position (not yet implemented)
*/
virtual void keyPressEvent(Key key, Uint8 repeat);
virtual void keyPressEvent(Key key, Modifiers modifiers, const Math::Vector2<int>& position);
/**
* @brief Key release event
* @param key Key released
* @param modifiers Active modifiers (not yet implemented)
* @param position Cursor position (not yet implemented)
*/
virtual void keyReleaseEvent(Key key);
virtual void keyReleaseEvent(Key key, Modifiers modifiers, const Math::Vector2<int>& position);
/*@}*/
@ -124,7 +143,9 @@ class Sdl2WindowContext: public AbstractWindowContext {
enum class MouseButton: Uint8 {
Left = SDL_BUTTON_LEFT, /**< Left button */
Middle = SDL_BUTTON_MIDDLE, /**< Middle button */
Right = SDL_BUTTON_RIGHT /**< Right button */
Right = SDL_BUTTON_RIGHT, /**< Right button */
WheelUp = 4, /**< Wheel up */
WheelDown = 5 /**< Wheel down */
};
/**
@ -141,41 +162,33 @@ class Sdl2WindowContext: public AbstractWindowContext {
/**
* @brief Mouse press event
* @param button Button pressed
* @param modifiers Active modifiers (not yet implemented)
* @param position Cursor position
*
* Called when mouse button is pressed. Default implementation does
* nothing.
*/
virtual void mousePressEvent(MouseButton button, const Math::Vector2<int>& position);
virtual void mousePressEvent(MouseButton button, Modifiers modifiers, const Math::Vector2<int>& position);
/**
* @brief Mouse release event
* @param button Button released
* @param modifiers Active modifiers (not yet implemented)
* @param position Cursor position
*
* Called when mouse button is released. Default implementation does
* nothing.
*/
virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2<int>& position);
/**
* @brief Mouse wheel event
* @param direction Wheel rotation direction. Negative Y is up and
* positive X is right.
*
* Called when mouse wheel is rotated. Default implementation does
* nothing.
*/
virtual void mouseWheelEvent(const Math::Vector2<int>& direction);
virtual void mouseReleaseEvent(MouseButton button, Modifiers modifiers, const Math::Vector2<int>& position);
/**
* @brief Mouse motion event
* @param modifiers Active modifiers (not yet implemented)
* @param position Mouse position relative to the window
* @param delta Mouse position relative to last motion event
*
* Called when mouse is moved. Default implementation does nothing.
*/
virtual void mouseMotionEvent(const Math::Vector2<int>& position, const Math::Vector2<int>& delta);
virtual void mouseMotionEvent(Modifiers modifiers, const Math::Vector2<int>& position);
/*@}*/
@ -188,13 +201,14 @@ class Sdl2WindowContext: public AbstractWindowContext {
bool _redraw;
};
CORRADE_ENUMSET_OPERATORS(Sdl2WindowContext::Modifiers)
/* Implementations for inline functions with unused parameters */
inline void Sdl2WindowContext::keyPressEvent(Key, Uint8) {}
inline void Sdl2WindowContext::keyReleaseEvent(Key) {}
inline void Sdl2WindowContext::mousePressEvent(MouseButton, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseWheelEvent(const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseMotionEvent(const Math::Vector2<int>&, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::keyPressEvent(Key, Modifiers, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseMotionEvent(Modifiers, const Math::Vector2<int>&) {}
}}

Loading…
Cancel
Save