mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Further clarifications of the key indices passed to IsKeyXXX functions (#1159)
This commit is contained in:
parent
9da53bcecd
commit
62c4698a73
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;
|
||||
}
|
||||
|
8
imgui.h
8
imgui.h
@ -427,10 +427,10 @@ namespace ImGui
|
||||
IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b);
|
||||
|
||||
// Inputs
|
||||
IMGUI_API int GetKeyIndex(ImGuiKey key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key]
|
||||
IMGUI_API bool IsKeyDown(int key_index); // key_index into the keys_down[] array, imgui doesn't know the semantic of each entry, uses your own indices!
|
||||
IMGUI_API bool IsKeyPressed(int key_index, bool repeat = true); // uses user's key indices as stored in the keys_down[] array. if repeat=true. uses io.KeyRepeatDelay / KeyRepeatRate
|
||||
IMGUI_API bool IsKeyReleased(int key_index); // "
|
||||
IMGUI_API int GetKeyIndex(ImGuiKey imgui_key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key]
|
||||
IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_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[]!
|
||||
IMGUI_API bool IsKeyPressed(int user_key_index, bool repeat = true); // was key pressed (went from !Down to Down). if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate
|
||||
IMGUI_API bool IsKeyReleased(int user_key_index); // was key released (went from Down to !Down)..
|
||||
IMGUI_API bool IsMouseDown(int button); // is mouse button held
|
||||
IMGUI_API bool IsMouseClicked(int button, bool repeat = false); // did mouse button clicked (went from !Down to Down)
|
||||
IMGUI_API bool IsMouseDoubleClicked(int button); // did mouse button double-clicked. a double-click returns false in IsMouseClicked(). uses io.MouseDoubleClickTime.
|
||||
|
Loading…
Reference in New Issue
Block a user