From 79c6a885fc732a0fff0fe694a86ed6450b00794b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 23 Sep 2021 00:21:57 -0400 Subject: add indicator to last move on normalized dev read --- grapher/Constants/Constants.cs | 10 ++++++++-- grapher/Models/Mouse/MouseWatcher.cs | 29 ++++++++++++++++++++++++++-- grapher/Models/Serialized/SettingsManager.cs | 15 +++++++++----- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/grapher/Constants/Constants.cs b/grapher/Constants/Constants.cs index 0b15ce6..fa500de 100644 --- a/grapher/Constants/Constants.cs +++ b/grapher/Constants/Constants.cs @@ -128,12 +128,18 @@ namespace grapher public const string GuiConfigFileName = ".config"; - /// Text to direcitonality panel title when panel is closed. + /// Text to directionality panel title when panel is closed. public const string DirectionalityTitleClosed = "Anisotropy \u25BC"; - /// Text to direcitonality panel title when panel is open. + /// Text to directionality panel title when panel is open. public const string DirectionalityTitleOpen = "Anisotropy \u25B2"; + /// Default last mouse move label text format. + public const string MouseMoveDefaultFormat = "Last (x, y): ({0}, {1})"; + + /// Last mouse move label text format when last input was from a dpi normalized device. + public const string MouseMoveNormalizedFormat = MouseMoveDefaultFormat + "!"; + /// Style used by System.Double.Parse public const NumberStyles FloatStyle = NumberStyles.Float | NumberStyles.AllowThousands; diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 91eebb8..723f97b 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -692,6 +692,9 @@ namespace grapher.Models.Mouse SettingsManager = setMngr; MouseData = new MouseData(); + LastMoveDisplayFormat = Constants.MouseMoveDefaultFormat; + LastMoveNormalized = false; + RAWINPUTDEVICE device = new RAWINPUTDEVICE(); device.WindowHandle = ContainingForm.Handle; device.UsagePage = HIDUsagePage.Generic; @@ -721,6 +724,10 @@ namespace grapher.Models.Mouse private Stopwatch Stopwatch { get; } + private string LastMoveDisplayFormat { get; set; } + + private bool LastMoveNormalized { get; set; } + private double PollTime { get => 1000 / SettingsManager.PollRateField.Data; @@ -733,7 +740,7 @@ namespace grapher.Models.Mouse public void UpdateLastMove() { MouseData.Get(out var x, out var y); - Display.Text = $"Last (x, y): ({x}, {y})"; + Display.Text = string.Format(LastMoveDisplayFormat, x, y); } public void ReadMouseMove(Message message) @@ -743,7 +750,25 @@ namespace grapher.Models.Mouse _ = GetRawInputData(message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER))); bool relative = !rawInput.Data.Mouse.Flags.HasFlag(RawMouseFlags.MoveAbsolute); - bool deviceMatch = SettingsManager.ActiveHandles.Contains(rawInput.Header.Device); + + bool deviceMatch = false; + foreach (var (handle, normalized) in SettingsManager.ActiveNormTaggedHandles) + { + if (handle == rawInput.Header.Device) + { + deviceMatch = true; + + if (normalized != LastMoveNormalized) + { + LastMoveDisplayFormat = normalized ? + Constants.MouseMoveNormalizedFormat : + Constants.MouseMoveDefaultFormat; + LastMoveNormalized = normalized; + } + + break; + } + } if (relative && deviceMatch && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 1c8608f..43550c5 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -31,7 +31,7 @@ namespace grapher.Models.Serialized StreamingModeMenuItem = streamingMode; SystemDevices = new List(); - ActiveHandles = new List(); + ActiveNormTaggedHandles = new List<(IntPtr, bool)>(); GuiSettings = GUISettings.MaybeLoad(); @@ -114,7 +114,7 @@ namespace grapher.Models.Serialized public IList SystemDevices { get; private set; } - public List ActiveHandles { get; } + public List<(IntPtr, bool)> ActiveNormTaggedHandles { get; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } @@ -198,19 +198,24 @@ namespace grapher.Models.Serialized public void SetActiveHandles() { - ActiveHandles.Clear(); + ActiveNormTaggedHandles.Clear(); bool ActiveProfileIsFirst = ActiveProfile == ActiveConfig.profiles[0]; foreach (var sysDev in SystemDevices) { + void AddHandlesFromSysDev(bool normalized) + { + ActiveNormTaggedHandles.AddRange(sysDev.handles.Select(h => (h, normalized))); + } + var settings = ActiveConfig.devices.Find(d => d.id == sysDev.id); if (settings is null) { if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) { - ActiveHandles.AddRange(sysDev.handles); + AddHandlesFromSysDev(ActiveConfig.defaultDeviceConfig.dpi > 0); } } else if (!settings.config.disable && @@ -219,7 +224,7 @@ namespace grapher.Models.Serialized !ActiveProfileNamesSet.Contains(settings.profile))) || ActiveProfile.name == settings.profile)) { - ActiveHandles.AddRange(sysDev.handles); + AddHandlesFromSysDev(settings.config.dpi > 0); } } } -- cgit v1.2.3