mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-01 02:37:24 +01:00
Inputs, Tooltip: Rework stationary timer logic as it broke on high-framerates with lower rate of mouse inputs. (#1485)
This commit is contained in:
parent
64172685d6
commit
1029f57b8a
12
imgui.cpp
12
imgui.cpp
@ -8619,14 +8619,12 @@ static void ImGui::UpdateMouseInputs()
|
|||||||
else
|
else
|
||||||
io.MouseDelta = ImVec2(0.0f, 0.0f);
|
io.MouseDelta = ImVec2(0.0f, 0.0f);
|
||||||
|
|
||||||
// Update stationary timer. Only reset on 2 successive moving frames.
|
// Update stationary timer.
|
||||||
// FIXME: May need to expose threshold or treat touch inputs differently.
|
// FIXME: May need to rework again to have some tolerance for occasional small movement, while being functional on high-framerates.
|
||||||
const float mouse_stationary_threshold = (io.MouseSource == ImGuiMouseSource_Mouse) ? 2.0f : 3.0f; // Slightly higher threshold for ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen, may need rework.
|
const float mouse_stationary_threshold = (io.MouseSource == ImGuiMouseSource_Mouse) ? 2.0f : 3.0f; // Slightly higher threshold for ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen, may need rework.
|
||||||
g.MouseMovingFrames = (ImLengthSqr(io.MouseDelta) >= mouse_stationary_threshold * mouse_stationary_threshold) ? (g.MouseMovingFrames + 1) : 0;
|
const bool mouse_stationary = (ImLengthSqr(io.MouseDelta) <= mouse_stationary_threshold * mouse_stationary_threshold);
|
||||||
if (g.MouseMovingFrames == 0)
|
g.MouseStationaryTimer = mouse_stationary ? (g.MouseStationaryTimer + io.DeltaTime) : 0.0f;
|
||||||
g.MouseStationaryTimer += io.DeltaTime;
|
//IMGUI_DEBUG_LOG("%.4f\n", g.MouseStationaryTimer);
|
||||||
else if (g.MouseMovingFrames > 1)
|
|
||||||
g.MouseStationaryTimer = 0.0f;
|
|
||||||
|
|
||||||
// If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true.
|
// If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true.
|
||||||
if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)
|
if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)
|
||||||
|
2
imgui.h
2
imgui.h
@ -23,7 +23,7 @@
|
|||||||
// Library Version
|
// Library Version
|
||||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
|
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
|
||||||
#define IMGUI_VERSION "1.89.7 WIP"
|
#define IMGUI_VERSION "1.89.7 WIP"
|
||||||
#define IMGUI_VERSION_NUM 18967
|
#define IMGUI_VERSION_NUM 18968
|
||||||
#define IMGUI_HAS_TABLE
|
#define IMGUI_HAS_TABLE
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1978,7 +1978,6 @@ struct ImGuiContext
|
|||||||
|
|
||||||
// Mouse state
|
// Mouse state
|
||||||
ImGuiMouseCursor MouseCursor;
|
ImGuiMouseCursor MouseCursor;
|
||||||
int MouseMovingFrames;
|
|
||||||
float MouseStationaryTimer; // Time the mouse has been stationary (with some loose heuristic)
|
float MouseStationaryTimer; // Time the mouse has been stationary (with some loose heuristic)
|
||||||
ImVec2 MouseLastValidPos;
|
ImVec2 MouseLastValidPos;
|
||||||
|
|
||||||
@ -2182,7 +2181,6 @@ struct ImGuiContext
|
|||||||
HoverItemDelayTimer = HoverItemDelayClearTimer = 0.0f;
|
HoverItemDelayTimer = HoverItemDelayClearTimer = 0.0f;
|
||||||
|
|
||||||
MouseCursor = ImGuiMouseCursor_Arrow;
|
MouseCursor = ImGuiMouseCursor_Arrow;
|
||||||
MouseMovingFrames = 0;
|
|
||||||
MouseStationaryTimer = 0.0f;
|
MouseStationaryTimer = 0.0f;
|
||||||
|
|
||||||
TempInputId = 0;
|
TempInputId = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user