mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Further clarifications of the key indices passed to IsKeyXXX functions (#1159)
This commit is contained in:
31
imgui.cpp
31
imgui.cpp
@ -3148,25 +3148,26 @@ static bool IsKeyPressedMap(ImGuiKey key, bool repeat)
|
||||
return ImGui::IsKeyPressed(key_index, repeat);
|
||||
}
|
||||
|
||||
int ImGui::GetKeyIndex(ImGuiKey key)
|
||||
int ImGui::GetKeyIndex(ImGuiKey imgui_key)
|
||||
{
|
||||
IM_ASSERT(key >= 0 && key < ImGuiKey_COUNT);
|
||||
return GImGui->IO.KeyMap[key];
|
||||
IM_ASSERT(imgui_key >= 0 && imgui_key < ImGuiKey_COUNT);
|
||||
return GImGui->IO.KeyMap[imgui_key];
|
||||
}
|
||||
|
||||
bool ImGui::IsKeyDown(int key_index)
|
||||
// Note that imgui doesn't know the semantic of each entry of io.KeyDown[]. Use your own indices/enums according to how your backend/engine stored them into KeyDown[]!
|
||||
bool ImGui::IsKeyDown(int user_key_index)
|
||||
{
|
||||
if (key_index < 0) return false;
|
||||
IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(GImGui->IO.KeysDown));
|
||||
return GImGui->IO.KeysDown[key_index];
|
||||
if (user_key_index < 0) return false;
|
||||
IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(GImGui->IO.KeysDown));
|
||||
return GImGui->IO.KeysDown[user_key_index];
|
||||
}
|
||||
|
||||
bool ImGui::IsKeyPressed(int key_index, bool repeat)
|
||||
bool ImGui::IsKeyPressed(int user_key_index, bool repeat)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (key_index < 0) return false;
|
||||
IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
|
||||
const float t = g.IO.KeysDownDuration[key_index];
|
||||
if (user_key_index < 0) return false;
|
||||
IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown));
|
||||
const float t = g.IO.KeysDownDuration[user_key_index];
|
||||
if (t == 0.0f)
|
||||
return true;
|
||||
|
||||
@ -3179,12 +3180,12 @@ bool ImGui::IsKeyPressed(int key_index, bool repeat)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ImGui::IsKeyReleased(int key_index)
|
||||
bool ImGui::IsKeyReleased(int user_key_index)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (key_index < 0) return false;
|
||||
IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
|
||||
if (g.IO.KeysDownDurationPrev[key_index] >= 0.0f && !g.IO.KeysDown[key_index])
|
||||
if (user_key_index < 0) return false;
|
||||
IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown));
|
||||
if (g.IO.KeysDownDurationPrev[user_key_index] >= 0.0f && !g.IO.KeysDown[user_key_index])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user