how dumb, imgui has a repeat feature for shortcuts, removed a lot of nonsense
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -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<ImGuiKeyChord, State> 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);
|
||||
|
||||
@@ -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<int>
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user