From ab65eb7c5813dceffcacfabaa067ecbfaa3f6e21 Mon Sep 17 00:00:00 2001 From: shweet Date: Wed, 19 Nov 2025 22:31:28 -0500 Subject: [PATCH] how dumb, imgui has a repeat feature for shortcuts, removed a lot of nonsense --- src/imgui/imgui_.cpp | 59 ++----------------------- src/imgui/imgui_.h | 4 +- src/imgui/window/animation_preview.cpp | 4 +- src/imgui/window/spritesheet_editor.cpp | 4 +- src/imgui/window/timeline.cpp | 28 +++++++----- src/imgui/window/tools.cpp | 2 +- 6 files changed, 25 insertions(+), 76 deletions(-) diff --git a/src/imgui/imgui_.cpp b/src/imgui/imgui_.cpp index 6485712..3926b90 100644 --- a/src/imgui/imgui_.cpp +++ b/src/imgui/imgui_.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -300,66 +299,14 @@ namespace anm2ed::imgui return ImVec2(ImGui::GetTextLineHeightWithSpacing(), ImGui::GetTextLineHeightWithSpacing()); } - bool chord_held(ImGuiKeyChord chord) - { - auto& io = ImGui::GetIO(); - - for (constexpr ImGuiKey mods[] = {ImGuiMod_Ctrl, ImGuiMod_Shift, ImGuiMod_Alt, ImGuiMod_Super}; ImGuiKey mod : mods) - { - bool required = (chord & mod) != 0; - if (bool held = io.KeyMods & mod; required && !held) return false; - } - - auto main_key = (ImGuiKey)(chord & ~ImGuiMod_Mask_); - if (main_key == ImGuiKey_None) return false; - - return ImGui::IsKeyDown(main_key); - } - - bool chord_repeating(ImGuiKeyChord chord, float delay, float rate) - { - struct State - { - float timeHeld = 0.f; - float nextRepeat = 0.f; - }; - static std::unordered_map stateMap; - - auto& io = ImGui::GetIO(); - auto& state = stateMap[chord]; - - if (chord_held(chord)) - { - state.timeHeld += io.DeltaTime; - - if (state.timeHeld <= io.DeltaTime) - { - state.nextRepeat = delay; - return true; - } - - if (state.timeHeld >= state.nextRepeat) - { - state.nextRepeat += rate; - return true; - } - } - else - { - state.timeHeld = 0.f; - state.nextRepeat = 0.f; - } - - return false; - } - - bool shortcut(ImGuiKeyChord chord, shortcut::Type type, bool isRepeat) + bool shortcut(ImGuiKeyChord chord, shortcut::Type type) { if (ImGui::GetTopMostPopupModal() != nullptr) return false; - if (isRepeat && !isRenaming) return chord_repeating(chord); int flags = type == shortcut::GLOBAL || type == shortcut::GLOBAL_SET ? ImGuiInputFlags_RouteGlobal : ImGuiInputFlags_RouteFocused; + flags |= ImGuiInputFlags_Repeat; + if (type == shortcut::GLOBAL_SET || type == shortcut::FOCUSED_SET) { ImGui::SetNextItemShortcut(chord, flags); diff --git a/src/imgui/imgui_.h b/src/imgui/imgui_.h index 8fe4df1..178103c 100644 --- a/src/imgui/imgui_.h +++ b/src/imgui/imgui_.h @@ -185,9 +185,7 @@ namespace anm2ed::imgui void external_storage_set(ImGuiSelectionExternalStorage*, int, bool); void render_checker_background(ImDrawList*, ImVec2, ImVec2, glm::vec2, float); ImVec2 icon_size_get(); - bool chord_held(ImGuiKeyChord); - bool chord_repeating(ImGuiKeyChord, float = ImGui::GetIO().KeyRepeatDelay, float = ImGui::GetIO().KeyRepeatRate); - bool shortcut(ImGuiKeyChord, types::shortcut::Type = types::shortcut::FOCUSED_SET, bool = false); + bool shortcut(ImGuiKeyChord, types::shortcut::Type = types::shortcut::FOCUSED_SET); class MultiSelectStorage : public std::set { diff --git a/src/imgui/window/animation_preview.cpp b/src/imgui/window/animation_preview.cpp index 7a629b3..83d3237 100644 --- a/src/imgui/window/animation_preview.cpp +++ b/src/imgui/window/animation_preview.cpp @@ -659,8 +659,8 @@ namespace anm2ed::imgui auto isKeyDown = isLeftDown || isRightDown || isUpDown || isDownDown; auto isKeyReleased = isLeftReleased || isRightReleased || isUpReleased || isDownReleased; - auto isZoomIn = chord_repeating(manager.chords[SHORTCUT_ZOOM_IN]); - auto isZoomOut = chord_repeating(manager.chords[SHORTCUT_ZOOM_OUT]); + auto isZoomIn = shortcut(manager.chords[SHORTCUT_ZOOM_IN], shortcut::GLOBAL); + auto isZoomOut = shortcut(manager.chords[SHORTCUT_ZOOM_OUT], shortcut::GLOBAL); auto isBegin = isMouseClicked || isKeyJustPressed; auto isDuring = isMouseDown || isKeyDown; diff --git a/src/imgui/window/spritesheet_editor.cpp b/src/imgui/window/spritesheet_editor.cpp index e38391f..e2601ef 100644 --- a/src/imgui/window/spritesheet_editor.cpp +++ b/src/imgui/window/spritesheet_editor.cpp @@ -241,8 +241,8 @@ namespace anm2ed::imgui auto isKeyDown = isLeftDown || isRightDown || isUpDown || isDownDown; auto isKeyReleased = isLeftReleased || isRightReleased || isUpReleased || isDownReleased; - auto isZoomIn = chord_repeating(string_to_chord(settings.shortcutZoomIn)); - auto isZoomOut = chord_repeating(string_to_chord(settings.shortcutZoomOut)); + auto isZoomIn = shortcut(manager.chords[SHORTCUT_ZOOM_IN], shortcut::GLOBAL); + auto isZoomOut = shortcut(manager.chords[SHORTCUT_ZOOM_OUT], shortcut::GLOBAL); auto isBegin = isMouseClicked || isKeyJustPressed; auto isDuring = isMouseDown || isKeyDown; diff --git a/src/imgui/window/timeline.cpp b/src/imgui/window/timeline.cpp index dfe8021..0ffa0d4 100644 --- a/src/imgui/window/timeline.cpp +++ b/src/imgui/window/timeline.cpp @@ -200,10 +200,7 @@ namespace anm2ed::imgui return anm2::NONE; }; - auto item_selection_clear = [&]() - { - itemSelection.clear(); - }; + auto item_selection_clear = [&]() { itemSelection.clear(); }; auto item_selection_sync = [&]() { @@ -1928,20 +1925,23 @@ namespace anm2ed::imgui { if (shortcut(manager.chords[SHORTCUT_PLAY_PAUSE], shortcut::GLOBAL)) playback.toggle(); - if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_BACK], shortcut::GLOBAL, true)) + if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_BACK], shortcut::GLOBAL)) { playback.decrement(settings.playbackIsClamp ? animation->frameNum : anm2::FRAME_NUM_MAX); document.frameTime = playback.time; } - if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_FORWARD], shortcut::GLOBAL, true)) + if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_FORWARD], shortcut::GLOBAL)) { playback.increment(settings.playbackIsClamp ? animation->frameNum : anm2::FRAME_NUM_MAX); document.frameTime = playback.time; } - if (shortcut(manager.chords[SHORTCUT_SHORTEN_FRAME], shortcut::GLOBAL)) document.snapshot("Shorten Frame"); - if (shortcut(manager.chords[SHORTCUT_SHORTEN_FRAME], shortcut::GLOBAL, true)) + static bool isShortenChordHeld = false; + auto isShortenFrame = shortcut(manager.chords[SHORTCUT_SHORTEN_FRAME], shortcut::GLOBAL); + + if (isShortenFrame && !isShortenChordHeld) document.snapshot("Shorten Frame"); + if (isShortenFrame) { if (auto frame = document.frame_get()) @@ -1950,9 +1950,12 @@ namespace anm2ed::imgui document.change(Document::FRAMES); } } + isShortenChordHeld = isShortenFrame; - if (shortcut(manager.chords[SHORTCUT_EXTEND_FRAME], shortcut::GLOBAL)) document.snapshot("Extend Frame"); - if (shortcut(manager.chords[SHORTCUT_EXTEND_FRAME], shortcut::GLOBAL, true)) + static bool isExtendChordHeld = false; + auto isExtendFrame = shortcut(manager.chords[SHORTCUT_EXTEND_FRAME], shortcut::GLOBAL); + if (isExtendFrame && !isExtendChordHeld) document.snapshot("Extend Frame"); + if (isExtendFrame) { if (auto frame = document.frame_get()) @@ -1961,8 +1964,9 @@ namespace anm2ed::imgui document.change(Document::FRAMES); } } + isExtendChordHeld = isExtendFrame; - if (shortcut(manager.chords[SHORTCUT_PREVIOUS_FRAME], shortcut::GLOBAL, true)) + if (shortcut(manager.chords[SHORTCUT_PREVIOUS_FRAME], shortcut::GLOBAL)) { if (auto item = document.item_get(); !item->frames.empty()) { @@ -1972,7 +1976,7 @@ namespace anm2ed::imgui } } - if (shortcut(manager.chords[SHORTCUT_NEXT_FRAME], shortcut::GLOBAL, true)) + if (shortcut(manager.chords[SHORTCUT_NEXT_FRAME], shortcut::GLOBAL)) { if (auto item = document.item_get(); !item->frames.empty()) { diff --git a/src/imgui/window/tools.cpp b/src/imgui/window/tools.cpp index 5aadfbb..68fcb6e 100644 --- a/src/imgui/window/tools.cpp +++ b/src/imgui/window/tools.cpp @@ -52,7 +52,7 @@ namespace anm2ed::imgui if (isSelected) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive)); - if (shortcut(manager.chords[info.shortcut], shortcut::GLOBAL_SET, true)) tool_use((tool::Type)i); + if (shortcut(manager.chords[info.shortcut], shortcut::GLOBAL)) tool_use((tool::Type)i); if (i == tool::COLOR) {