diff options
| author | a1xd <[email protected]> | 2020-12-05 21:28:08 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-05 21:28:08 -0500 |
| commit | c8503654da5bc40a129e58914549cd394349d059 (patch) | |
| tree | e4760c579597d0e292c7b03dff95d19bb8f3c750 /grapher/Models | |
| parent | Merge pull request #45 from JacobPalecki/fix (diff) | |
| parent | update signed, add installers (diff) | |
| download | rawaccel-c8503654da5bc40a129e58914549cd394349d059.tar.xz rawaccel-c8503654da5bc40a129e58914549cd394349d059.zip | |
Merge pull request #46 from a1xd/1.3
Diffstat (limited to 'grapher/Models')
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 5 | ||||
| -rw-r--r-- | grapher/Models/AccelGUIFactory.cs | 7 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelChartData.cs | 5 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelData.cs | 6 | ||||
| -rw-r--r-- | grapher/Models/Charts/AccelCharts.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/ChartState.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/CombinedState.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/XYOneGraphState.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/XYTwoGraphState.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartXY.cs | 33 | ||||
| -rw-r--r-- | grapher/Models/Fields/Field.cs | 20 | ||||
| -rw-r--r-- | grapher/Models/Mouse/MouseWatcher.cs | 53 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 33 |
14 files changed, 87 insertions, 87 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index c08313b..c6a2dcc 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -140,7 +140,8 @@ namespace grapher combineMagnitudes = ApplyOptions.IsWhole, modes = ApplyOptions.GetModes(), args = newArgs, - minimumTime = driverSettings.minimumTime + minimumTime = driverSettings.minimumTime, + directionalMultipliers = driverSettings.directionalMultipliers }; ButtonDelay(WriteButton); @@ -153,7 +154,7 @@ namespace grapher } else { - throw new Exception($"Bad arguments: \n {SettingsManager.ErrorStringFrom(errors)}"); + throw new Exception($"Bad arguments:\n\n{errors}"); } } diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 3dc2a74..901a1b5 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -2,6 +2,7 @@ using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; +using System; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; @@ -104,8 +105,8 @@ namespace grapher.Models Label mouseLabel) { var accelCalculator = new AccelCalculator( - new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI), - new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate)); + new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI, 1), + new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate, 1)); var accelCharts = new AccelCharts( form, @@ -331,7 +332,7 @@ namespace grapher.Models showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem); - var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, accelCalculator.PollRate); + var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, settings); return new AccelGUI( form, diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 60d4c89..71ee927 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -80,6 +80,11 @@ namespace grapher.Models.Calculations public int GetVelocityIndex(double outVelocityValue) { + if (outVelocityValue < 0) + { + throw new ArgumentException($"invalid velocity: {outVelocityValue}"); + } + var log = Math.Log10(outVelocityValue); if (log < -2) { diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index 67d4f3f..d35217f 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -56,7 +56,7 @@ namespace grapher.Models.Calculations OutVelocityToPoints.Clear(); } - public void CalculateDots(int x, int y, double timeInMs) + public void CalculateDots(double x, double y, double timeInMs) { var outVelocity = AccelCalculator.Velocity(x, y, timeInMs); @@ -66,7 +66,7 @@ namespace grapher.Models.Calculations Estimated.Gain.Set(inCombVel, combGain); } - public void CalculateDotsXY(int x, int y, double timeInMs) + public void CalculateDotsXY(double x, double y, double timeInMs) { var outX = Math.Abs(x) / timeInMs; var outY = Math.Abs(y) / timeInMs; @@ -82,7 +82,7 @@ namespace grapher.Models.Calculations EstimatedY.Gain.Set(inYVelocity, yGain); } - public void CalculateDotsCombinedDiffSens(int x, int y, double timeInMs, DriverSettings settings) + public void CalculateDotsCombinedDiffSens(double x, double y, double timeInMs, DriverSettings settings) { (var xStripped, var yStripped) = AccelCalculator.StripSens(x, y, settings.sensitivity.x, settings.sensitivity.y); var outVelocity = AccelCalculator.Velocity(xStripped, yStripped, timeInMs); diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 6247811..b7abb35 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -99,7 +99,7 @@ namespace grapher #region Methods - public void MakeDots(int x, int y, double timeInMs) + public void MakeDots(double x, double y, double timeInMs) { ChartState.MakeDots(x, y, timeInMs); } diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index 270e212..0bb141e 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -40,7 +40,7 @@ namespace grapher.Models.Charts.ChartState internal bool TwoDotsPerGraph { get; set; } - public abstract void MakeDots(int x, int y, double timeInMs); + public abstract void MakeDots(double x, double y, double timeInMs); public abstract void Bind(); diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index aab8a38..9eadb87 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -30,7 +30,7 @@ namespace grapher.Models.Charts.ChartState GainChart.ClearSecondDots(); } - public override void MakeDots(int x, int y, double timeInMs) + public override void MakeDots(double x, double y, double timeInMs) { Data.CalculateDots(x, y, timeInMs); } diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index 92c799f..2b3cd9c 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -28,7 +28,7 @@ namespace grapher.Models.Charts.ChartState GainChart.SetCombined(); } - public override void MakeDots(int x, int y, double timeInMs) + public override void MakeDots(double x, double y, double timeInMs) { Data.CalculateDotsCombinedDiffSens(x, y, timeInMs, Settings); } diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index d107f87..732ea3c 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -33,7 +33,7 @@ namespace grapher.Models.Charts.ChartState GainChart.ClearSecondDots(); } - public override void MakeDots(int x, int y, double timeInMs) + public override void MakeDots(double x, double y, double timeInMs) { Data.CalculateDotsXY(x, y, timeInMs); } diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 98ba059..553ab3e 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,4 +1,5 @@ using grapher.Models.Mouse; +using System; using System.Collections; using System.Windows.Forms.DataVisualization.Charting; @@ -29,6 +30,8 @@ namespace grapher #endregion Constructors + private const double VerticalMargin = 0.1; + #region Properties public Chart ChartX { get; } @@ -219,28 +222,30 @@ namespace grapher ChartX.Series[2].IsVisibleInLegend = true; } - public void SetMinMax(double min, double max) + private void VerifyRange(double min, double max) { - if (min < max) + if (min > max) { - ChartX.ChartAreas[0].AxisY.Minimum = min * 0.95; - ChartX.ChartAreas[0].AxisY.Maximum = max * 1.05; + throw new ArgumentException($"invalid chart range: ({min}, {max})"); } } + public void SetMinMax(double min, double max) + { + VerifyRange(min, max); + ChartX.ChartAreas[0].AxisY.Minimum = min * (1 - VerticalMargin); + ChartX.ChartAreas[0].AxisY.Maximum = max * (1 + VerticalMargin); + } + public void SetMinMaxXY(double minX, double maxX, double minY, double maxY) { - if (minX < maxX) - { - ChartX.ChartAreas[0].AxisY.Minimum = minX * 0.95; - ChartX.ChartAreas[0].AxisY.Maximum = maxX * 1.05; - } + VerifyRange(minX, maxX); + ChartX.ChartAreas[0].AxisY.Minimum = minX * (1 - VerticalMargin); + ChartX.ChartAreas[0].AxisY.Maximum = maxX * (1 + VerticalMargin); - if (minY < maxY) - { - ChartY.ChartAreas[0].AxisY.Minimum = minY * 0.95; - ChartY.ChartAreas[0].AxisY.Maximum = maxY * 1.05; - } + VerifyRange(minY, maxY); + ChartX.ChartAreas[0].AxisY.Minimum = minY * (1 - VerticalMargin); + ChartX.ChartAreas[0].AxisY.Maximum = maxY * (1 + VerticalMargin); } public void SetCombined() diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs index 541bbe2..345f814 100644 --- a/grapher/Models/Fields/Field.cs +++ b/grapher/Models/Fields/Field.cs @@ -27,12 +27,16 @@ namespace grapher #region Constructors - public Field(TextBox box, Form containingForm, double defaultData) + public Field(TextBox box, Form containingForm, double defaultData, + double minData = double.MinValue, + double maxData = double.MaxValue) { DefaultText = DecimalString(defaultData); Box = box; _data = defaultData; DefaultData = defaultData; + MinData = minData; + MaxData = maxData; State = FieldState.Undefined; ContainingForm = containingForm; FormatString = Constants.DefaultFieldFormatString; @@ -69,7 +73,7 @@ namespace grapher { return DefaultData; } - } + } } public int Top @@ -122,6 +126,10 @@ namespace grapher private double DefaultData { get; set; } + private double MinData { get; } + + private double MaxData { get; } + #endregion Properties #region Methods @@ -268,12 +276,10 @@ namespace grapher private void TextToData() { - try - { - _data = Convert.ToDouble(Box.Text); - } - catch + if (double.TryParse(Box.Text, out double value) && + value <= MaxData && value >= MinData) { + _data = value; } Box.Text = DecimalString(Data); diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 6209445..cbfc119 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -677,12 +678,12 @@ namespace grapher.Models.Mouse #region Constructors - public MouseWatcher(Form containingForm, Label display, AccelCharts accelCharts, Field pollRate) + public MouseWatcher(Form containingForm, Label display, AccelCharts accelCharts, SettingsManager setMngr) { ContainingForm = containingForm; Display = display; AccelCharts = accelCharts; - PollRateField = pollRate; + SettingsManager = setMngr; MouseData = new MouseData(); RAWINPUTDEVICE device = new RAWINPUTDEVICE(); @@ -694,8 +695,6 @@ namespace grapher.Models.Mouse RAWINPUTDEVICE[] devices = new RAWINPUTDEVICE[1]; devices[0] = device; RegisterRawInputDevices(devices, 1, Marshal.SizeOf(typeof(RAWINPUTDEVICE))); - PollTime = 1; - PollRate = 1000; } #endregion Constructors @@ -708,24 +707,19 @@ namespace grapher.Models.Mouse private AccelCharts AccelCharts { get; } - private Field PollRateField { get; set; } + private SettingsManager SettingsManager { get; } private MouseData MouseData { get; } - private double PollRate { get; set; } - - private double PollTime { get; set; } + private double PollTime + { + get => 1000 / SettingsManager.PollRateField.Data; + } #endregion Properties #region Methods - public void OnMouseMove(int x, int y, double timeInMs) - { - MouseData.Set(x,y); - AccelCharts.MakeDots(x, y, timeInMs); - } - public void UpdateLastMove() { MouseData.Get(out var x, out var y); @@ -740,15 +734,30 @@ namespace grapher.Models.Mouse outSize = GetRawInputData((IntPtr)message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER))); - if (PollRateField.Data != PollRate) - { - PollRate = PollRateField.Data; - PollTime = 1000 / PollRate; - } + bool relative = !rawInput.Data.Mouse.Flags.HasFlag(RawMouseFlags.MoveAbsolute); - if (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0) + if (relative && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { - OnMouseMove(rawInput.Data.Mouse.LastX, rawInput.Data.Mouse.LastY, PollTime); + double x = rawInput.Data.Mouse.LastX; + double y = rawInput.Data.Mouse.LastY; + + // strip negative directional multipliers, charts calculated from positive input + + Vec2<double> dirMults = SettingsManager.RawAccelSettings + .AccelerationSettings.directionalMultipliers; + + if (dirMults.x > 0 && x < 0) + { + x /= dirMults.x; + } + + if (dirMults.y > 0 && y < 0) + { + y /= dirMults.y; + } + + MouseData.Set(rawInput.Data.Mouse.LastX, rawInput.Data.Mouse.LastY); + AccelCharts.MakeDots(x, y, PollTime); } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index af87a65..dcaf864 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -127,6 +127,8 @@ namespace grapher.Models.Serialized return accelSettings.sensitivity.x == 1 && accelSettings.sensitivity.y == 1 && + accelSettings.directionalMultipliers.x <= 0 && + accelSettings.directionalMultipliers.y <= 0 && accelSettings.rotation == 0 && accelSettings.modes.x == AccelMode.noaccel && wholeOrNoY; diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index f13ba81..41ebcb5 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -34,9 +34,9 @@ namespace grapher.Models.Serialized public RawAccelSettings RawAccelSettings { get; private set; } - private Field DpiField { get; set; } + public Field DpiField { get; private set; } - private Field PollRateField { get; set; } + public Field PollRateField { get; private set; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } @@ -47,35 +47,6 @@ namespace grapher.Models.Serialized #endregion Properties #region Methods - - public static string ErrorStringFrom(SettingsErrors errors) - { - StringBuilder builder = new StringBuilder(); - bool yPresent = errors.y?.Count > 0; - - if (yPresent) - { - builder.AppendLine("\nx:"); - } - - foreach (var error in errors.x) - { - builder.AppendLine(error); - } - - if (yPresent) - { - builder.AppendLine("\ny:"); - - foreach (var error in errors.y) - { - builder.AppendLine(error); - } - } - - return builder.ToString(); - } - public SettingsErrors TryUpdateActiveSettings(DriverSettings settings) { var errors = TryUpdateAccel(settings); |