From 8e5019e93688c318a31ed513938498e06aa2daf4 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 18 Jan 2021 22:13:54 -0800 Subject: Add timer to mousewatcher for better low-end fidelity --- grapher/Models/Mouse/MouseWatcher.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'grapher/Models/Mouse/MouseWatcher.cs') diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index cbfc119..3cc8bd0 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -1,5 +1,6 @@ using grapher.Models.Serialized; using System; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -695,6 +696,8 @@ namespace grapher.Models.Mouse RAWINPUTDEVICE[] devices = new RAWINPUTDEVICE[1]; devices[0] = device; RegisterRawInputDevices(devices, 1, Marshal.SizeOf(typeof(RAWINPUTDEVICE))); + Stopwatch = new Stopwatch(); + Stopwatch.Start(); } #endregion Constructors @@ -711,6 +714,8 @@ namespace grapher.Models.Mouse private MouseData MouseData { get; } + private Stopwatch Stopwatch { get; } + private double PollTime { get => 1000 / SettingsManager.PollRateField.Data; @@ -738,6 +743,11 @@ namespace grapher.Models.Mouse if (relative && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { + var time = Stopwatch.Elapsed.TotalMilliseconds; + Stopwatch.Restart(); + time = time > 100 ? 100 : time; + time = time > (PollTime * 0.8) ? time : (PollTime * 0.8); + double x = rawInput.Data.Mouse.LastX; double y = rawInput.Data.Mouse.LastY; @@ -757,7 +767,7 @@ namespace grapher.Models.Mouse } MouseData.Set(rawInput.Data.Mouse.LastX, rawInput.Data.Mouse.LastY); - AccelCharts.MakeDots(x, y, PollTime); + AccelCharts.MakeDots(x, y, time); } } -- cgit v1.2.3