Browse Source

SDL2 context: keyboard handling for basic keys.

pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
acb8029a93
  1. 6
      src/Contexts/Sdl2Context.cpp
  2. 33
      src/Contexts/Sdl2Context.h

6
src/Contexts/Sdl2Context.cpp

@ -82,6 +82,12 @@ int Sdl2Context::exec() {
_redraw = true; _redraw = true;
break; break;
} break; } break;
case SDL_KEYDOWN:
keyPressEvent(static_cast<Key>(event.key.keysym.sym), event.key.repeat);
break;
case SDL_KEYUP:
keyReleaseEvent(static_cast<Key>(event.key.keysym.sym));
break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
mouseEvent(static_cast<MouseButton>(event.button.button), mouseEvent(static_cast<MouseButton>(event.button.button),

33
src/Contexts/Sdl2Context.h

@ -30,7 +30,7 @@ namespace Magnum { namespace Contexts {
/** @nosubgrouping /** @nosubgrouping
@brief SDL2 context @brief SDL2 context
Currently doesn't have any mouse/keyboard handling. Supports keyboard and mouse handling.
You need to implement at least drawEvent() and viewportEvent() to be able to You need to implement at least drawEvent() and viewportEvent() to be able to
draw on the screen. draw on the screen.
@ -75,6 +75,37 @@ class Sdl2Context: public AbstractContext {
/*@}*/ /*@}*/
/** @{ @name Keyboard handling */
public:
/**
* @brief Key
* @see keyPressEvent(), keyReleaseEvent()
*/
enum class Key: SDL_Keycode {
Up = SDLK_UP, /**< Up arrow */
Down = SDLK_DOWN, /**< Down arrow */
Left = SDLK_LEFT, /**< Left arrow */
Right = SDLK_RIGHT, /**< Right arrow */
Plus = SDLK_PLUS, /**< Plus */
Minus = SDLK_MINUS /**< Minus */
};
protected:
/**
* @brief Key press event
* @param key Key pressed
* @param repeat Non-zero if this is a key repeat
*/
inline virtual void keyPressEvent(Key key, Uint8 repeat) {}
/**
* @brief Key release event
* @param key Key release
*/
inline virtual void keyReleaseEvent(Key key) {}
/*@}*/
/** @{ @name Mouse handling */ /** @{ @name Mouse handling */
public: public:

Loading…
Cancel
Save