diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-03 08:19:25 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-03 08:26:56 +0100 |
commit | 65ce220d95c50b0006ab4282604ea782cc4d0e90 (patch) | |
tree | e7d065b972ef69a7ec0340bb35a7f6f634cdffde /editor | |
parent | 38b5c32b1037602068285dc3ad906cc7b94cdcb4 (diff) |
editor: don't queue up key_GLOBALs, ever
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.hpp | 4 | ||||
-rw-r--r-- | editor/events.cpp | 11 | ||||
-rw-r--r-- | 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<floormat_main> 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<key, int> 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(); |