summaryrefslogtreecommitdiffhomepage
path: root/main/keyboard.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-08 22:14:29 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-08 22:14:29 +0200
commitcaacf24af8a51807105cd35407201d525a4e59f4 (patch)
tree640fa38bbb09dcf2ca2eaed14d4acd2dba10b3e3 /main/keyboard.cpp
parentdf73742cdd427e68057603746864abd3d2b545c2 (diff)
a
Diffstat (limited to 'main/keyboard.cpp')
-rw-r--r--main/keyboard.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/main/keyboard.cpp b/main/keyboard.cpp
new file mode 100644
index 00000000..14daa19c
--- /dev/null
+++ b/main/keyboard.cpp
@@ -0,0 +1,43 @@
+#include "app.hpp"
+namespace Magnum::Examples {
+
+void app::do_key(KeyEvent::Key k, KeyEvent::Modifiers m, bool pressed, bool repeated)
+{
+ //using Mods = KeyEvent::Modifiers;
+
+ (void)m;
+ (void)repeated;
+
+ const key x = progn(switch (k) {
+ using enum KeyEvent::Key;
+ using enum key;
+
+ case W: return camera_up;
+ case A: return camera_left;
+ case S: return camera_down;
+ case D: return camera_right;
+ case Home: return camera_reset;
+ case Esc: return quit;
+ default: return MAX;
+ });
+
+ if (x != key::MAX)
+ keys[x] = pressed;
+}
+
+app::~app()
+{
+ loader_::destroy();
+}
+
+void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ do_key(event.key(), event.modifiers(), true, event.isRepeated());
+}
+
+void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ do_key(event.key(), event.modifiers(), false, false);
+}
+
+} // namespace Magnum::Examples