Browse Source

Platform: expose key repeat in *Application::KeyEvent::isRepeated().

pull/165/merge
Vladimír Vondruš 10 years ago
parent
commit
7c631d714a
  1. 2
      src/Magnum/Platform/GlfwApplication.cpp
  2. 11
      src/Magnum/Platform/GlfwApplication.h
  3. 2
      src/Magnum/Platform/Sdl2Application.cpp
  4. 11
      src/Magnum/Platform/Sdl2Application.h

2
src/Magnum/Platform/GlfwApplication.cpp

@ -162,7 +162,7 @@ int GlfwApplication::exec() {
}
void GlfwApplication::staticKeyEvent(GLFWwindow*, int key, int, int action, int mods) {
KeyEvent e(static_cast<KeyEvent::Key>(key), {static_cast<InputEvent::Modifier>(mods)});
KeyEvent e(static_cast<KeyEvent::Key>(key), {static_cast<InputEvent::Modifier>(mods)}, action == GLFW_REPEAT);
if(action == GLFW_PRESS) {
_instance->keyPressEvent(e);

11
src/Magnum/Platform/GlfwApplication.h

@ -750,13 +750,22 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
/** @brief Modifiers */
constexpr Modifiers modifiers() const { return _modifiers; }
/**
* @brief Whether the key press is repeated
*
* Returns `true` if the key press event is repeated, `false` if not or
* if this was key release event.
*/
constexpr bool isRepeated() const { return _repeated; }
private:
static Modifiers getCurrentGlfwModifiers(GLFWwindow* window);
constexpr KeyEvent(Key key, Modifiers modifiers): _key(key), _modifiers(modifiers) {}
constexpr KeyEvent(Key key, Modifiers modifiers, bool repeated): _key{key}, _modifiers{modifiers}, _repeated{repeated} {}
const Key _key;
const Modifiers _modifiers;
const bool _repeated;
};
/**

2
src/Magnum/Platform/Sdl2Application.cpp

@ -377,7 +377,7 @@ void Sdl2Application::mainLoop() {
case SDL_KEYDOWN:
case SDL_KEYUP: {
KeyEvent e(static_cast<KeyEvent::Key>(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod));
KeyEvent e(static_cast<KeyEvent::Key>(event.key.keysym.sym), fixedModifiers(event.key.keysym.mod), event.key.repeat != 0);
event.type == SDL_KEYDOWN ? keyPressEvent(e) : keyReleaseEvent(e);
} break;

11
src/Magnum/Platform/Sdl2Application.h

@ -1218,11 +1218,20 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent {
/** @brief Modifiers */
constexpr Modifiers modifiers() const { return _modifiers; }
/**
* @brief Whether the key press is repeated
*
* Returns `true` if the key press event is repeated, `false` if not or
* if this was key release event.
*/
constexpr bool isRepeated() const { return _repeated; }
private:
constexpr KeyEvent(Key key, Modifiers modifiers): _key(key), _modifiers(modifiers) {}
constexpr KeyEvent(Key key, Modifiers modifiers, bool repeated): _key{key}, _modifiers{modifiers}, _repeated{repeated} {}
const Key _key;
const Modifiers _modifiers;
const bool _repeated;
};
/**

Loading…
Cancel
Save