1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-24 15:50:25 +01:00

Nav: Added internal ImGuiNavReadMode_Released test for key releases.

This commit is contained in:
omar 2017-10-23 11:26:30 +02:00
parent d769e2515a
commit 6f0aa766e1
2 changed files with 5 additions and 2 deletions

View File

@ -2611,6 +2611,7 @@ enum ImGuiNavReadMode
{ {
ImGuiNavReadMode_Down, ImGuiNavReadMode_Down,
ImGuiNavReadMode_Pressed, ImGuiNavReadMode_Pressed,
ImGuiNavReadMode_Released,
ImGuiNavReadMode_Repeat, ImGuiNavReadMode_Repeat,
ImGuiNavReadMode_RepeatSlow, ImGuiNavReadMode_RepeatSlow,
ImGuiNavReadMode_RepeatFast ImGuiNavReadMode_RepeatFast
@ -2625,6 +2626,8 @@ static float GetNavInputAmount(ImGuiNavInput n, ImGuiNavReadMode mode)
const float t = g.IO.NavInputsDownDuration[n]; // Duration pressed const float t = g.IO.NavInputsDownDuration[n]; // Duration pressed
if (mode == ImGuiNavReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input (we don't need it for Pressed logic) if (mode == ImGuiNavReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input (we don't need it for Pressed logic)
return (t == 0.0f) ? 1.0f : 0.0f; return (t == 0.0f) ? 1.0f : 0.0f;
if (mode == ImGuiNavReadMode_Released) // Return 1.0f when just release, no repeat, ignore analog input (we don't need it for Pressed logic)
return (t < 0.0f && g.IO.NavInputsDownDurationPrev[n] >= 0.0f) ? 1.0f : 0.0f;
if (mode == ImGuiNavReadMode_Repeat) if (mode == ImGuiNavReadMode_Repeat)
return (float)ImGui::CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f); return (float)ImGui::CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f);
if (mode == ImGuiNavReadMode_RepeatSlow) if (mode == ImGuiNavReadMode_RepeatSlow)
@ -3047,7 +3050,7 @@ void ImGui::NewFrame()
memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration)); memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f; g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f;
memcpy(g.IO.NavInputsPrev, g.IO.NavInputs, sizeof(g.IO.NavInputs)); memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration));
for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++) for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++)
g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f; g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f;

View File

@ -924,7 +924,7 @@ struct ImGuiIO
float KeysDownDuration[512]; // Duration the keyboard key has been down (0.0f == just pressed) float KeysDownDuration[512]; // Duration the keyboard key has been down (0.0f == just pressed)
float KeysDownDurationPrev[512]; // Previous duration the key has been down float KeysDownDurationPrev[512]; // Previous duration the key has been down
float NavInputsDownDuration[ImGuiNavInput_COUNT]; float NavInputsDownDuration[ImGuiNavInput_COUNT];
float NavInputsPrev[ImGuiNavInput_COUNT]; float NavInputsDownDurationPrev[ImGuiNavInput_COUNT];
IMGUI_API ImGuiIO(); IMGUI_API ImGuiIO();
}; };