mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Renamed and merged keyboard modifiers key enums and flags into a same set:. ImGuiKey_ModXXX -> ImGuiMod_XXX and ImGuiModFlags_XXX -> ImGuiMod_XXX. (#4921, #456)
Changed signature of GetKeyChordName() to use ImGuiKeyChord. Additionally SetActiveIdUsingAllKeyboardKeys() doesn't set ImGuiKey_ModXXX but we never need/use those and the system will be changed in upcoming commits.
This commit is contained in:
103
imgui.cpp
103
imgui.cpp
@ -384,6 +384,14 @@ CODE
|
||||
When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
|
||||
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
- 2022/09/26 (1.89) - renamed and merged keyboard modifiers key enums and flags into a same set. Kept inline redirection enums (will obsolete).
|
||||
- ImGuiKey_ModCtrl and ImGuiModFlags_Ctrl -> ImGuiMod_Ctrl
|
||||
- ImGuiKey_ModShift and ImGuiModFlags_Shift -> ImGuiMod_Shift
|
||||
- ImGuiKey_ModAlt and ImGuiModFlags_Alt -> ImGuiMod_Alt
|
||||
- ImGuiKey_ModSuper and ImGuiModFlags_Super -> ImGuiMod_Super
|
||||
the ImGuiKey_ModXXX were introduced in 1.87 and mostly used by backends.
|
||||
the ImGuiModFlags_XXX have been exposed in imgui.h but not really used by any public api only by third-party extensions.
|
||||
exceptionally commenting out the older ImGuiKeyModFlags_XXX names ahead of obsolescence schedule to reduce confusion and because they were not meant to be used anyway.
|
||||
- 2022/09/12 (1.89) - removed the bizarre legacy default argument for 'TreePush(const void* ptr = NULL)', always pass a pointer value explicitly, NULL is ok.
|
||||
- 2022/09/05 (1.89) - commented out redirecting functions/enums names that were marked obsolete in 1.77 and 1.78 (June 2020):
|
||||
- DragScalar(), DragScalarN(), DragFloat(), DragFloat2(), DragFloat3(), DragFloat4(): For old signatures ending with (..., const char* format, float power = 1.0f) -> use (..., format ImGuiSliderFlags_Logarithmic) if power != 1.0f.
|
||||
@ -431,7 +439,7 @@ CODE
|
||||
- IsKeyPressed(MY_NATIVE_KEY_XXX) -> use IsKeyPressed(ImGuiKey_XXX)
|
||||
- IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX)
|
||||
- Backend writing to io.KeyMap[],io.KeysDown[] -> backend should call io.AddKeyEvent() (+ call io.SetKeyEventNativeData() if you want legacy user code to stil function with legacy key codes).
|
||||
- Backend writing to io.KeyCtrl, io.KeyShift.. -> backend should call io.AddKeyEvent() with ImGuiKey_ModXXX values. *IF YOU PULLED CODE BETWEEN 2021/01/10 and 2021/01/27: We used to have a io.AddKeyModsEvent() function which was now replaced by io.AddKeyEvent() with ImGuiKey_ModXXX values.*
|
||||
- Backend writing to io.KeyCtrl, io.KeyShift.. -> backend should call io.AddKeyEvent() with ImGuiMod_XXX values. *IF YOU PULLED CODE BETWEEN 2021/01/10 and 2021/01/27: We used to have a io.AddKeyModsEvent() function which was now replaced by io.AddKeyEvent() with ImGuiMod_XXX values.*
|
||||
- one case won't work with backward compatibility: if your custom backend used ImGuiKey as mock native indices (e.g. "io.KeyMap[ImGuiKey_A] = ImGuiKey_A") because those values are now larger than the legacy KeyDown[] array. Will assert.
|
||||
- inputs: added ImGuiKey_ModCtrl/ImGuiKey_ModShift/ImGuiKey_ModAlt/ImGuiKey_ModSuper values to submit keyboard modifiers using io.AddKeyEvent(), instead of writing directly to io.KeyCtrl, io.KeyShift, io.KeyAlt, io.KeySuper.
|
||||
- 2022/01/05 (1.87) - inputs: renamed ImGuiKey_KeyPadEnter to ImGuiKey_KeypadEnter to align with new symbols. Kept redirection enum.
|
||||
@ -1291,7 +1299,7 @@ void ImGuiIO::ClearInputKeys()
|
||||
KeysData[n].DownDurationPrev = -1.0f;
|
||||
}
|
||||
KeyCtrl = KeyShift = KeyAlt = KeySuper = false;
|
||||
KeyMods = ImGuiModFlags_None;
|
||||
KeyMods = ImGuiMod_None;
|
||||
}
|
||||
|
||||
// Queue a new key down/up event.
|
||||
@ -1305,7 +1313,7 @@ void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
|
||||
return;
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(&g.IO == this && "Can only add events to current context.");
|
||||
IM_ASSERT(ImGui::IsNamedKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
|
||||
IM_ASSERT(ImGui::IsNamedKeyOrModKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
|
||||
IM_ASSERT(!ImGui::IsAliasKey(key)); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events.
|
||||
|
||||
// Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
|
||||
@ -4047,15 +4055,15 @@ static void UpdateAliasKey(ImGuiKey key, bool v, float analog_value)
|
||||
}
|
||||
|
||||
// [Internal] Do not use directly (should read io.KeyMods instead)
|
||||
static ImGuiModFlags GetMergedModFlags()
|
||||
static ImGuiKeyChord GetMergedModsFromBools()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiModFlags key_mods = ImGuiModFlags_None;
|
||||
if (g.IO.KeyCtrl) { key_mods |= ImGuiModFlags_Ctrl; }
|
||||
if (g.IO.KeyShift) { key_mods |= ImGuiModFlags_Shift; }
|
||||
if (g.IO.KeyAlt) { key_mods |= ImGuiModFlags_Alt; }
|
||||
if (g.IO.KeySuper) { key_mods |= ImGuiModFlags_Super; }
|
||||
return key_mods;
|
||||
ImGuiKeyChord key_chord = 0;
|
||||
if (g.IO.KeyCtrl) { key_chord |= ImGuiMod_Ctrl; }
|
||||
if (g.IO.KeyShift) { key_chord |= ImGuiMod_Shift; }
|
||||
if (g.IO.KeyAlt) { key_chord |= ImGuiMod_Alt; }
|
||||
if (g.IO.KeySuper) { key_chord |= ImGuiMod_Super; }
|
||||
return key_chord;
|
||||
}
|
||||
|
||||
static void ImGui::UpdateKeyboardInputs()
|
||||
@ -4098,10 +4106,10 @@ static void ImGui::UpdateKeyboardInputs()
|
||||
}
|
||||
if (io.BackendUsingLegacyKeyArrays == 1)
|
||||
{
|
||||
GetKeyData(ImGuiKey_ModCtrl)->Down = io.KeyCtrl;
|
||||
GetKeyData(ImGuiKey_ModShift)->Down = io.KeyShift;
|
||||
GetKeyData(ImGuiKey_ModAlt)->Down = io.KeyAlt;
|
||||
GetKeyData(ImGuiKey_ModSuper)->Down = io.KeySuper;
|
||||
GetKeyData(ImGuiMod_Ctrl)->Down = io.KeyCtrl;
|
||||
GetKeyData(ImGuiMod_Shift)->Down = io.KeyShift;
|
||||
GetKeyData(ImGuiMod_Alt)->Down = io.KeyAlt;
|
||||
GetKeyData(ImGuiMod_Super)->Down = io.KeySuper;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4132,7 +4140,7 @@ static void ImGui::UpdateKeyboardInputs()
|
||||
#endif
|
||||
|
||||
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools, update aliases
|
||||
io.KeyMods = GetMergedModFlags();
|
||||
io.KeyMods = GetMergedModsFromBools();
|
||||
for (int n = 0; n < ImGuiMouseButton_COUNT; n++)
|
||||
UpdateAliasKey(MouseButtonToKey(n), io.MouseDown[n], io.MouseDown[n] ? 1.0f : 0.0f);
|
||||
UpdateAliasKey(ImGuiKey_MouseWheelX, io.MouseWheelH != 0.0f, io.MouseWheelH);
|
||||
@ -5319,17 +5327,16 @@ void ImGui::SetItemUsingMouseWheel()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Technically this also prevents use of Gamepad D-Pad, may not be an issue.
|
||||
void ImGui::SetActiveIdUsingAllKeyboardKeys()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(g.ActiveId != 0);
|
||||
g.ActiveIdUsingNavDirMask = ~(ImU32)0;
|
||||
g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_COUNT) - 1;
|
||||
g.ActiveIdUsingKeyInputMask.SetBitRange(ImGuiKey_Keyboard_BEGIN, ImGuiKey_Keyboard_END);
|
||||
g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModCtrl);
|
||||
g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModShift);
|
||||
g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModAlt);
|
||||
g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModSuper);
|
||||
//g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModCtrl);
|
||||
//g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModShift);
|
||||
//g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModAlt);
|
||||
//g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_ModSuper);
|
||||
NavMoveRequestCancel();
|
||||
}
|
||||
|
||||
@ -7734,6 +7741,11 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c
|
||||
ImGuiKeyData* ImGui::GetKeyData(ImGuiKey key)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
// Special storage location for mods
|
||||
if (key & ImGuiMod_Mask_)
|
||||
key = ConvertSingleModFlagToKey(key);
|
||||
|
||||
int index;
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
IM_ASSERT(key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_NamedKey_END);
|
||||
@ -7779,7 +7791,7 @@ static const char* const GKeyNames[] =
|
||||
"GamepadLStickLeft", "GamepadLStickRight", "GamepadLStickUp", "GamepadLStickDown",
|
||||
"GamepadRStickLeft", "GamepadRStickRight", "GamepadRStickUp", "GamepadRStickDown",
|
||||
"MouseLeft", "MouseRight", "MouseMiddle", "MouseX1", "MouseX2", "MouseWheelX", "MouseWheelY",
|
||||
"ModCtrl", "ModShift", "ModAlt", "ModSuper",
|
||||
"ModCtrl", "ModShift", "ModAlt", "ModSuper", // ReservedForModXXX are showing the ModXXX names.
|
||||
};
|
||||
IM_STATIC_ASSERT(ImGuiKey_NamedKey_COUNT == IM_ARRAYSIZE(GKeyNames));
|
||||
|
||||
@ -7805,16 +7817,15 @@ const char* ImGui::GetKeyName(ImGuiKey key)
|
||||
return GKeyNames[key - ImGuiKey_NamedKey_BEGIN];
|
||||
}
|
||||
|
||||
void ImGui::GetKeyChordName(ImGuiModFlags mods, ImGuiKey key, char* out_buf, int out_buf_size)
|
||||
void ImGui::GetKeyChordName(ImGuiKeyChord key_chord, char* out_buf, int out_buf_size)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT((mods & ~ImGuiModFlags_All) == 0 && "Passing invalid ImGuiModFlags value!"); // A frequent mistake is to pass ImGuiKey_ModXXX instead of ImGuiModFlags_XXX
|
||||
ImFormatString(out_buf, (size_t)out_buf_size, "%s%s%s%s%s",
|
||||
(mods & ImGuiModFlags_Ctrl) ? "Ctrl+" : "",
|
||||
(mods & ImGuiModFlags_Shift) ? "Shift+" : "",
|
||||
(mods & ImGuiModFlags_Alt) ? "Alt+" : "",
|
||||
(mods & ImGuiModFlags_Super) ? (g.IO.ConfigMacOSXBehaviors ? "Cmd+" : "Super+") : "",
|
||||
GetKeyName(key));
|
||||
(key_chord & ImGuiMod_Ctrl) ? "Ctrl+" : "",
|
||||
(key_chord & ImGuiMod_Shift) ? "Shift+" : "",
|
||||
(key_chord & ImGuiMod_Alt) ? "Alt+" : "",
|
||||
(key_chord & ImGuiMod_Super) ? (g.IO.ConfigMacOSXBehaviors ? "Cmd+" : "Super+") : "",
|
||||
GetKeyName((ImGuiKey)(key_chord & ~ImGuiMod_Mask_)));
|
||||
}
|
||||
|
||||
// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime)
|
||||
@ -8146,8 +8157,8 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
||||
{
|
||||
ImGuiKey key = e->Key.Key;
|
||||
IM_ASSERT(key != ImGuiKey_None);
|
||||
const int key_data_index = (key - ImGuiKey_KeysData_OFFSET);
|
||||
ImGuiKeyData* key_data = &io.KeysData[key_data_index];
|
||||
ImGuiKeyData* key_data = GetKeyData(key);
|
||||
const int key_data_index = (int)(key_data - g.IO.KeysData);
|
||||
e->IgnoredAsSame = (key_data->Down == e->Key.Down && key_data->AnalogValue == e->Key.AnalogValue);
|
||||
if (!e->IgnoredAsSame)
|
||||
{
|
||||
@ -8159,20 +8170,20 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
||||
key_changed = true;
|
||||
key_changed_mask.SetBit(key_data_index);
|
||||
|
||||
if (key == ImGuiKey_ModCtrl || key == ImGuiKey_ModShift || key == ImGuiKey_ModAlt || key == ImGuiKey_ModSuper)
|
||||
if (key == ImGuiMod_Ctrl || key == ImGuiMod_Shift || key == ImGuiMod_Alt || key == ImGuiMod_Super)
|
||||
{
|
||||
if (key == ImGuiKey_ModCtrl) { io.KeyCtrl = key_data->Down; }
|
||||
if (key == ImGuiKey_ModShift) { io.KeyShift = key_data->Down; }
|
||||
if (key == ImGuiKey_ModAlt) { io.KeyAlt = key_data->Down; }
|
||||
if (key == ImGuiKey_ModSuper) { io.KeySuper = key_data->Down; }
|
||||
io.KeyMods = GetMergedModFlags();
|
||||
if (key == ImGuiMod_Ctrl) { io.KeyCtrl = key_data->Down; }
|
||||
if (key == ImGuiMod_Shift) { io.KeyShift = key_data->Down; }
|
||||
if (key == ImGuiMod_Alt) { io.KeyAlt = key_data->Down; }
|
||||
if (key == ImGuiMod_Super) { io.KeySuper = key_data->Down; }
|
||||
io.KeyMods = GetMergedModsFromBools();
|
||||
}
|
||||
|
||||
// Allow legacy code using io.KeysDown[GetKeyIndex()] with new backends
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
io.KeysDown[key] = key_data->Down;
|
||||
if (io.KeyMap[key] != -1)
|
||||
io.KeysDown[io.KeyMap[key]] = key_data->Down;
|
||||
io.KeysDown[key_data_index] = key_data->Down;
|
||||
if (io.KeyMap[key_data_index] != -1)
|
||||
io.KeysDown[io.KeyMap[key_data_index]] = key_data->Down;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -8333,7 +8344,7 @@ static void ImGui::ErrorCheckEndFrameSanityChecks()
|
||||
// send key release events mid-frame. This would normally trigger this assertion and lead to sheared inputs.
|
||||
// We silently accommodate for this case by ignoring/ the case where all io.KeyXXX modifiers were released (aka key_mod_flags == 0),
|
||||
// while still correctly asserting on mid-frame key press events.
|
||||
const ImGuiModFlags key_mods = GetMergedModFlags();
|
||||
const ImGuiKeyChord key_mods = GetMergedModsFromBools();
|
||||
IM_ASSERT((key_mods == 0 || g.IO.KeyMods == key_mods) && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods");
|
||||
IM_UNUSED(key_mods);
|
||||
|
||||
@ -11123,7 +11134,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
// Keyboard: Press and Release ALT to toggle menu layer
|
||||
// - Testing that only Alt is tested prevents Alt+Shift or AltGR from toggling menu layer.
|
||||
// - AltGR is normally Alt+Ctrl but we can't reliably detect it (not all backends/systems/layout emit it as Alt+Ctrl). But even on keyboards without AltGR we don't want Alt+Ctrl to open menu anyway.
|
||||
if (nav_keyboard_active && IsKeyPressed(ImGuiKey_ModAlt))
|
||||
if (nav_keyboard_active && IsKeyPressed(ImGuiMod_Alt))
|
||||
{
|
||||
g.NavWindowingToggleLayer = true;
|
||||
g.NavInputSource = ImGuiInputSource_Keyboard;
|
||||
@ -11137,11 +11148,11 @@ static void ImGui::NavUpdateWindowing()
|
||||
|
||||
// Apply layer toggle on release
|
||||
// Important: as before version <18314 we lacked an explicit IO event for focus gain/loss, we also compare mouse validity to detect old backends clearing mouse pos on focus loss.
|
||||
if (IsKeyReleased(ImGuiKey_ModAlt) && g.NavWindowingToggleLayer)
|
||||
if (IsKeyReleased(ImGuiMod_Alt) && g.NavWindowingToggleLayer)
|
||||
if (g.ActiveId == 0 || g.ActiveIdAllowOverlap)
|
||||
if (IsMousePosValid(&io.MousePos) == IsMousePosValid(&io.MousePosPrev))
|
||||
apply_toggle_layer = true;
|
||||
if (!IsKeyDown(ImGuiKey_ModAlt))
|
||||
if (!IsKeyDown(ImGuiMod_Alt))
|
||||
g.NavWindowingToggleLayer = false;
|
||||
}
|
||||
|
||||
@ -13439,7 +13450,7 @@ void ImGui::UpdateDebugToolItemPicker()
|
||||
SetMouseCursor(ImGuiMouseCursor_Hand);
|
||||
if (IsKeyPressed(ImGuiKey_Escape))
|
||||
g.DebugItemPickerActive = false;
|
||||
const bool change_mapping = g.IO.KeyMods == (ImGuiModFlags_Ctrl | ImGuiModFlags_Shift);
|
||||
const bool change_mapping = g.IO.KeyMods == (ImGuiMod_Ctrl | ImGuiMod_Shift);
|
||||
if (!change_mapping && IsMouseClicked(g.DebugItemPickerMouseButton) && hovered_id)
|
||||
{
|
||||
g.DebugItemPickerBreakId = hovered_id;
|
||||
@ -13594,7 +13605,7 @@ void ImGui::ShowStackToolWindow(bool* p_open)
|
||||
Checkbox("Ctrl+C: copy path to clipboard", &tool->CopyToClipboardOnCtrlC);
|
||||
SameLine();
|
||||
TextColored((time_since_copy >= 0.0f && time_since_copy < 0.75f && ImFmod(time_since_copy, 0.25f) < 0.25f * 0.5f) ? ImVec4(1.f, 1.f, 0.3f, 1.f) : ImVec4(), "*COPIED*");
|
||||
if (tool->CopyToClipboardOnCtrlC && IsKeyDown(ImGuiKey_ModCtrl) && IsKeyPressed(ImGuiKey_C))
|
||||
if (tool->CopyToClipboardOnCtrlC && IsKeyDown(ImGuiMod_Ctrl) && IsKeyPressed(ImGuiKey_C))
|
||||
{
|
||||
tool->CopyToClipboardLastTime = (float)g.Time;
|
||||
char* p = g.TempBuffer.Data;
|
||||
|
Reference in New Issue
Block a user