Browse Source

Platform: added *Application::KeyEvent::keyName().

The SDL2 variant works better than expected, however the GLFW variant
underdelivers -- no key names for modifier keys, the accent keys are not
UTF-8... I don't care ATM, will solve it once someone actually
complains.
pull/165/merge
Vladimír Vondruš 10 years ago
parent
commit
8e632130b8
  1. 10
      src/Magnum/Platform/GlfwApplication.cpp
  2. 8
      src/Magnum/Platform/GlfwApplication.h
  3. 8
      src/Magnum/Platform/Sdl2Application.cpp
  4. 27
      src/Magnum/Platform/Sdl2Application.h

10
src/Magnum/Platform/GlfwApplication.cpp

@ -27,6 +27,7 @@
#include "GlfwApplication.h"
#include <tuple>
#include <Corrade/Utility/String.h>
#include "Magnum/Version.h"
#include "Magnum/Platform/Context.h"
@ -245,6 +246,15 @@ GlfwApplication::Configuration::Configuration():
GlfwApplication::Configuration::~Configuration() = default;
std::string GlfwApplication::KeyEvent::keyName(const Key key) {
/* It can return null, so beware */
return Utility::String::fromArray(glfwGetKeyName(int(key), 0));
}
std::string GlfwApplication::KeyEvent::keyName() const {
return keyName(_key);
}
template class BasicScreen<GlfwApplication>;
template class BasicScreenedApplication<GlfwApplication>;

8
src/Magnum/Platform/GlfwApplication.h

@ -744,9 +744,15 @@ class GlfwApplication::KeyEvent: public GlfwApplication::InputEvent {
Menu = GLFW_KEY_MENU /**< Menu */
};
/** @brief Key */
/** @copydoc Sdl2Application::KeyEvent::keyName(Key) */
static std::string keyName(Key key);
/** @copydoc Sdl2Application::KeyEvent::key() */
constexpr Key key() const { return _key; }
/** @copydoc Sdl2Application::KeyEvent::keyName() const */
std::string keyName() const;
/** @brief Modifiers */
constexpr Modifiers modifiers() const { return _modifiers; }

8
src/Magnum/Platform/Sdl2Application.cpp

@ -552,6 +552,14 @@ Sdl2Application::Configuration::Configuration():
Sdl2Application::Configuration::~Configuration() = default;
std::string Sdl2Application::KeyEvent::keyName(const Key key) {
return SDL_GetKeyName(SDL_Keycode(key));
}
std::string Sdl2Application::KeyEvent::keyName() const {
return keyName(_key);
}
Sdl2Application::InputEvent::Modifiers Sdl2Application::MouseEvent::modifiers() {
if(_modifiersLoaded) return _modifiers;
_modifiersLoaded = true;

27
src/Magnum/Platform/Sdl2Application.h

@ -1212,9 +1212,34 @@ class Sdl2Application::KeyEvent: public Sdl2Application::InputEvent {
Z = SDLK_z /**< Letter Z */
};
/** @brief Key */
/**
* @brief Name for given key
*
* Human-readable localized UTF-8 name for given @p key, intended for
* displaying to the user in e.g. key binding configuration. If there
* is no name for given key, empty string is returned.
* @see @ref keyName(Key)
*/
static std::string keyName(Key key);
/**
* @brief Key
*
* @see @ref keyName()
*/
constexpr Key key() const { return _key; }
/**
* @brief Key name
*
* Human-readable localized UTF-8 name for the key returned by
* @ref key(), intended for displaying to the user in e.g.
* key binding configuration. If there is no name for that key, empty
* string is returned.
* @see @ref keyName(Key)
*/
std::string keyName() const;
/** @brief Modifiers */
constexpr Modifiers modifiers() const { return _modifiers; }

Loading…
Cancel
Save