Inputs: Fixed swapping of keys associated to mods. Fixed warnings. (#2343, #4084, #5923, #456)

Amend 7747106.
This commit is contained in:
ocornut 2024-05-16 19:22:09 +02:00
parent 7747106647
commit 8bd5d1d42f
2 changed files with 8 additions and 9 deletions

View File

@ -1497,9 +1497,9 @@ void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
if (key == ImGuiMod_Super) { key = ImGuiMod_Ctrl; }
else if (key == ImGuiMod_Ctrl) { key = ImGuiMod_Super; }
else if (key == ImGuiKey_LeftSuper) { key = ImGuiKey_LeftCtrl; }
else if (key == ImGuiKey_LeftSuper) { key = ImGuiKey_RightCtrl; }
else if (key == ImGuiKey_RightSuper){ key = ImGuiKey_RightCtrl; }
else if (key == ImGuiKey_LeftCtrl) { key = ImGuiKey_LeftSuper; }
else if (key == ImGuiKey_LeftCtrl) { key = ImGuiKey_RightSuper; }
else if (key == ImGuiKey_RightCtrl) { key = ImGuiKey_RightSuper; }
}
// Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
@ -8284,7 +8284,7 @@ ImGuiID ImGui::GetID(const void* ptr_id)
// - Shortcut() [Internal]
//-----------------------------------------------------------------------------
ImGuiKeyChord ImGui::FixupKeyChord(ImGuiContext* ctx, ImGuiKeyChord key_chord)
ImGuiKeyChord ImGui::FixupKeyChord(ImGuiKeyChord key_chord)
{
// Add ImGuiMod_XXXX when a corresponding ImGuiKey_LeftXXX/ImGuiKey_RightXXX is specified.
ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_);
@ -8384,7 +8384,7 @@ const char* ImGui::GetKeyName(ImGuiKey key)
const char* ImGui::GetKeyChordName(ImGuiKeyChord key_chord)
{
ImGuiContext& g = *GImGui;
key_chord = FixupKeyChord(&g, key_chord);
key_chord = FixupKeyChord(key_chord);
ImFormatString(g.TempKeychordName, IM_ARRAYSIZE(g.TempKeychordName), "%s%s%s%s%s",
(key_chord & ImGuiMod_Ctrl) ? "Ctrl+" : "",
(key_chord & ImGuiMod_Shift) ? "Shift+" : "",
@ -8606,7 +8606,7 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiI
IM_ASSERT(owner_id != ImGuiKeyOwner_Any && owner_id != ImGuiKeyOwner_None);
// Add ImGuiMod_XXXX when a corresponding ImGuiKey_LeftXXX/ImGuiKey_RightXXX is specified.
key_chord = FixupKeyChord(&g, key_chord);
key_chord = FixupKeyChord(key_chord);
// [DEBUG] Debug break requested by user
if (g.DebugBreakInShortcutRouting == key_chord)
@ -8674,9 +8674,8 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiI
// Note: this cannot be turned into GetShortcutRouting() because we do the owner_id->routing_id translation, name would be more misleading.
bool ImGui::TestShortcutRouting(ImGuiKeyChord key_chord, ImGuiID owner_id)
{
ImGuiContext& g = *GImGui;
const ImGuiID routing_id = GetRoutingIdFromOwnerId(owner_id);
key_chord = FixupKeyChord(&g, key_chord);
key_chord = FixupKeyChord(key_chord);
ImGuiKeyRoutingData* routing_data = GetShortcutRoutingData(key_chord); // FIXME: Could avoid creating entry.
return routing_data->RoutingCurr == routing_id;
}
@ -9606,7 +9605,7 @@ bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord)
bool ImGui::IsKeyChordPressed(ImGuiKeyChord key_chord, ImGuiID owner_id, ImGuiInputFlags flags)
{
ImGuiContext& g = *GImGui;
key_chord = FixupKeyChord(&g, key_chord);
key_chord = FixupKeyChord(key_chord);
ImGuiKey mods = (ImGuiKey)(key_chord & ImGuiMod_Mask_);
if (g.IO.KeyMods != mods)
return false;

View File

@ -3216,7 +3216,7 @@ namespace ImGui
inline bool IsMouseKey(ImGuiKey key) { return key >= ImGuiKey_Mouse_BEGIN && key < ImGuiKey_Mouse_END; }
inline bool IsAliasKey(ImGuiKey key) { return key >= ImGuiKey_Aliases_BEGIN && key < ImGuiKey_Aliases_END; }
inline bool IsModKey(ImGuiKey key) { return key >= ImGuiKey_LeftCtrl && key <= ImGuiKey_RightSuper; }
ImGuiKeyChord FixupKeyChord(ImGuiContext* ctx, ImGuiKeyChord key_chord);
ImGuiKeyChord FixupKeyChord(ImGuiKeyChord key_chord);
inline ImGuiKey ConvertSingleModFlagToKey(ImGuiKey key)
{
if (key == ImGuiMod_Ctrl) return ImGuiKey_ReservedForModCtrl;