From 747c9a7adf3f3e5896c8d46187f73ea53829f91c Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 31 Aug 2022 19:15:13 +0200 Subject: [PATCH] IsKeyPressed(), IsMouseClicked(), GetKeyPressedAmount(): add a (normally unnecessary) test for ->Down next to ->DownDuration tests, facilitating the use of key eating mechanism. Consider removing when we add support for input ownership. --- imgui.cpp | 6 ++++++ imgui.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index bf05831a..9a133239 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7817,6 +7817,8 @@ int ImGui::GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float repeat_ra { ImGuiContext& g = *GImGui; const ImGuiKeyData* key_data = GetKeyData(key); + if (!key_data->Down) // In theory this should already be encoded as (DownDuration < 0.0f), but testing this facilitate eating mechanism (until we finish work on input ownership) + return 0; const float t = key_data->DownDuration; return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate); } @@ -7849,6 +7851,8 @@ bool ImGui::IsKeyPressed(ImGuiKey key, bool repeat) bool ImGui::IsKeyPressedEx(ImGuiKey key, ImGuiInputFlags flags) { const ImGuiKeyData* key_data = GetKeyData(key); + if (!key_data->Down) // In theory this should already be encoded as (DownDuration < 0.0f), but testing this facilitate eating mechanism (until we finish work on input ownership) + return false; const float t = key_data->DownDuration; if (t < 0.0f) return false; @@ -7885,6 +7889,8 @@ bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (!g.IO.MouseDown[button]) // In theory this should already be encoded as (DownDuration < 0.0f), but testing this facilitate eating mechanism (until we finish work on input ownership) + return false; const float t = g.IO.MouseDownDuration[button]; if (t == 0.0f) return true; diff --git a/imgui.h b/imgui.h index dbbbdf52..1a67aa32 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.89 WIP" -#define IMGUI_VERSION_NUM 18811 +#define IMGUI_VERSION_NUM 18812 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE