From 16c0cc1cbbd4c45c0e60272b895607f77621e461 Mon Sep 17 00:00:00 2001 From: X9VoiD Date: Sun, 18 Oct 2020 20:01:25 +0800 Subject: [PATCH] Fix scaling logic and add `Hold` --- PrecisionControl/PrecisionControl.cs | 43 ++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/PrecisionControl/PrecisionControl.cs b/PrecisionControl/PrecisionControl.cs index 76462ef..0a21cae 100644 --- a/PrecisionControl/PrecisionControl.cs +++ b/PrecisionControl/PrecisionControl.cs @@ -3,7 +3,7 @@ using OpenTabletDriver.Plugin.Tablet; using OpenTabletDriver.Plugin.Attributes; using System; using System.Numerics; -using System.Linq; +using OpenTabletDriver.Plugin.Output; namespace PrecisionControl { @@ -17,23 +17,50 @@ namespace PrecisionControl public Action Press => () => { - IsActive = !IsActive; + if (Property == "Toggle") + IsActive = !IsActive; + else if (Property == "Hold") + IsActive = true; SetPosition = true; }; - public Action Release => () => SetPosition = false; + public Action Release => () => + { + if (Property == "Hold") + IsActive = false; + }; - public string[] ValidProperties => new[] { "Toggle Precision Control" }; + public string[] ValidProperties => new[] { "Toggle", "Hold" }; public Vector2 Filter(Vector2 OriginalPoint) { - if (SetPosition && Info.Driver.OutputMode is OpenTabletDriver.Plugin.Output.AbsoluteOutputMode) - StartingPoint = new Vector2(OriginalPoint.X, OriginalPoint.Y); - return IsActive ? new Vector2(OriginalPoint.X * Scale + StartingPoint.X, OriginalPoint.Y * Scale + StartingPoint.Y) : OriginalPoint; + if (SetPosition) + { + StartingPoint = OriginalPoint; + SetPosition = false; + } + + if (IsActive) + { + switch (Info.Driver.OutputMode) + { + case AbsoluteOutputMode _: + var delta = (OriginalPoint - StartingPoint) * Scale; + return StartingPoint + delta; + case RelativeOutputMode _: + return OriginalPoint * Scale; + default: + return OriginalPoint; + } + } + else + { + return OriginalPoint; + } } [SliderProperty("Precision Multiplier", 0.0f, 10f, 0.3f)] - public float Scale { get; set; } + public float Scale { get; set; } = 0.3f; public FilterStage FilterStage => FilterStage.PostTranspose; }