Improve detection for very brief mouse button presses.

internals
Eric Mellino 6 years ago
parent 666b2392e4
commit 5c9bab0c95
  1. 33
      src/ImGui.NET.SampleProgram/ImGuiController.cs

@ -332,13 +332,34 @@ namespace ImGuiNET
Vector2 mousePosition = snapshot.MousePosition; Vector2 mousePosition = snapshot.MousePosition;
io.MousePos = mousePosition; // Determine if any of the mouse buttons were pressed during this snapshot period, even if they are no longer held.
io.MouseDown[0] = snapshot.IsMouseDown(MouseButton.Left); bool leftPressed = false;
io.MouseDown[1] = snapshot.IsMouseDown(MouseButton.Right); bool middlePressed = false;
io.MouseDown[2] = snapshot.IsMouseDown(MouseButton.Middle); 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.MouseDown[0] = leftPressed || snapshot.IsMouseDown(MouseButton.Left);
io.MouseWheel = delta; io.MouseDown[1] = middlePressed || snapshot.IsMouseDown(MouseButton.Right);
io.MouseDown[2] = rightPressed || snapshot.IsMouseDown(MouseButton.Middle);
io.MousePos = mousePosition;
io.MouseWheel = snapshot.WheelDelta;
IReadOnlyList<char> keyCharPresses = snapshot.KeyCharPresses; IReadOnlyList<char> keyCharPresses = snapshot.KeyCharPresses;
for (int i = 0; i < keyCharPresses.Count; i++) for (int i = 0; i < keyCharPresses.Count; i++)

Loading…
Cancel
Save