From 65ce220d95c50b0006ab4282604ea782cc4d0e90 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 3 Dec 2022 08:19:25 +0100 Subject: editor: don't queue up key_GLOBALs, ever --- editor/app.hpp | 4 ++-- editor/events.cpp | 11 ++++++++--- editor/update.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/editor/app.hpp b/editor/app.hpp index 8d4f0736..a2d036e4 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -109,8 +109,8 @@ private: static int get_key_modifiers(); void clear_keys(key min_inclusive, key max_exclusive); void clear_keys(); - void clear_non_global_keys() { clear_keys(key_noop, key_GLOBAL); } - void clear_non_repeated_keys() { clear_keys(key_NO_REPEAT, key_COUNT); } + void clear_non_global_keys(); + void clear_non_repeated_keys(); Containers::Pointer M; ImGuiIntegration::Context _imgui{NoCreate}; diff --git a/editor/events.cpp b/editor/events.cpp index 83abc96d..56d35bf9 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -135,6 +135,9 @@ auto app::resolve_keybinding(int k_, int mods_) const -> std::tuple return { key_COUNT, k & kmod_mask }; } +void app::clear_non_global_keys() { clear_keys(key_MIN, key_GLOBAL); } +void app::clear_non_repeated_keys() { clear_keys(key_NO_REPEAT, key_COUNT); } + void app::on_key_up_down(const key_event& event, bool is_down) noexcept { using KeyEvent = Platform::Sdl2Application::KeyEvent; @@ -147,14 +150,16 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept } e = {Ev::Key(event.key), Ev::Modifier(event.mods)}; auto [x, mods] = resolve_keybinding(event.key, event.mods); + static_assert(key_GLOBAL >= key_NO_REPEAT); if (x == key_COUNT) void(); + else if (x < key_GLOBAL && is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e)) + clear_non_global_keys(); else if (x >= key_NO_REPEAT) is_down && !event.is_repeated ? do_key(x, mods) : void(); - else if (is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e)) - clear_non_global_keys(); - else { + else + { keys[x] = is_down; key_modifiers[std::size_t(x)] = mods; } diff --git a/editor/update.cpp b/editor/update.cpp index 516d2536..0de85536 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -135,8 +135,8 @@ void app::update_world(float dt) void app::update(float dt) { - update_world(dt); apply_commands(keys); + update_world(dt); do_camera(dt, keys, get_key_modifiers()); update_cursor_tile(cursor.pixel); clear_non_repeated_keys(); -- cgit v1.2.3