Browse Source

Platform: extend GLFW and SDL2 test applications.

Was checking how text input and key events are related.
gpu-preference
Vladimír Vondruš 7 years ago
parent
commit
a1356decdd
  1. 18
      src/Magnum/Platform/Test/GlfwApplicationTest.cpp
  2. 19
      src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

18
src/Magnum/Platform/Test/GlfwApplicationTest.cpp

@ -30,6 +30,24 @@ namespace Magnum { namespace Platform { namespace Test { namespace {
struct GlfwApplicationTest: Platform::Application {
explicit GlfwApplicationTest(const Arguments& arguments): Platform::Application{arguments} {}
void keyPressEvent(KeyEvent& event) override {
#if GLFW_VERSION_MAJOR*100 + GLFW_VERSION_MINOR >= 302
Debug{} << "key press event:" << event.keyName();
#endif
if(event.key() == KeyEvent::Key::F1) {
Debug{} << "starting text input";
startTextInput();
} else if(event.key() == KeyEvent::Key::Esc) {
Debug{} << "stopping text input";
stopTextInput();
}
}
void textInputEvent(TextInputEvent& event) override {
Debug{} << "text input event:" << std::string{event.text(), event.text().size()};
}
void exitEvent(ExitEvent& event) override {
Debug{} << "application exiting";
event.setAccepted(); /* Comment-out to test app exit suppression */

19
src/Magnum/Platform/Test/Sdl2ApplicationTest.cpp

@ -47,18 +47,29 @@ struct Sdl2ApplicationTest: Platform::Application {
/* For testing event coordinates */
void mousePressEvent(MouseEvent& event) override {
Debug{} << event.position();
Debug{} << "mouse press event:" << event.position();
}
/* For testing keyboard capture */
void keyPressEvent(KeyEvent& event) override {
Debug{} << event.keyName();
Debug{} << "key press event:" << event.keyName();
if(event.key() == KeyEvent::Key::F1) {
Debug{} << "starting text input";
startTextInput();
} else if(event.key() == KeyEvent::Key::Esc) {
Debug{} << "stopping text input";
stopTextInput();
}
}
void textInputEvent(TextInputEvent& event) override {
Debug{} << "text input event:" << std::string{event.text(), event.text().size()};
}
/* Should fire on currently not handled events, such as minimize/maximize.
Comment out to verify correct behavior with the override not present. */
void anyEvent(SDL_Event& event) override {
Debug{} << "any event" << event.type;
Debug{} << "any event:" << event.type;
}
};

Loading…
Cancel
Save