From 5c9bab0c954b380c649c3fc61d2e1f2f3e7d545d Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Fri, 26 Oct 2018 23:29:37 -0700 Subject: [PATCH] Improve detection for very brief mouse button presses. --- .../ImGuiController.cs | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/ImGui.NET.SampleProgram/ImGuiController.cs b/src/ImGui.NET.SampleProgram/ImGuiController.cs index 467b4c4..363ee32 100644 --- a/src/ImGui.NET.SampleProgram/ImGuiController.cs +++ b/src/ImGui.NET.SampleProgram/ImGuiController.cs @@ -332,13 +332,34 @@ namespace ImGuiNET Vector2 mousePosition = snapshot.MousePosition; - io.MousePos = mousePosition; - io.MouseDown[0] = snapshot.IsMouseDown(MouseButton.Left); - io.MouseDown[1] = snapshot.IsMouseDown(MouseButton.Right); - io.MouseDown[2] = snapshot.IsMouseDown(MouseButton.Middle); + // Determine if any of the mouse buttons were pressed during this snapshot period, even if they are no longer held. + bool leftPressed = false; + bool middlePressed = false; + bool rightPressed = false; + foreach (MouseEvent me in snapshot.MouseEvents) + { + if (me.Down) + { + switch (me.MouseButton) + { + case MouseButton.Left: + leftPressed = true; + break; + case MouseButton.Middle: + middlePressed = true; + break; + case MouseButton.Right: + rightPressed = true; + break; + } + } + } - float delta = snapshot.WheelDelta; - io.MouseWheel = delta; + io.MouseDown[0] = leftPressed || snapshot.IsMouseDown(MouseButton.Left); + io.MouseDown[1] = middlePressed || snapshot.IsMouseDown(MouseButton.Right); + io.MouseDown[2] = rightPressed || snapshot.IsMouseDown(MouseButton.Middle); + io.MousePos = mousePosition; + io.MouseWheel = snapshot.WheelDelta; IReadOnlyList keyCharPresses = snapshot.KeyCharPresses; for (int i = 0; i < keyCharPresses.Count; i++)