From 13150015f0924ab5fb8acf5aa952afe6384e6765 Mon Sep 17 00:00:00 2001 From: mika-n Date: Fri, 19 Jul 2019 01:49:22 +0300 Subject: [PATCH] Custom curve GUI tweaks. --- DS4Windows/BezierCurveEditor/BezierCurve.cs | 40 ++++++----- DS4Windows/DS4Control/ScpUtil.cs | 2 +- DS4Windows/DS4Forms/Options.cs | 73 ++++++++------------- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/DS4Windows/BezierCurveEditor/BezierCurve.cs b/DS4Windows/BezierCurveEditor/BezierCurve.cs index 53d65f6..09d9226 100644 --- a/DS4Windows/BezierCurveEditor/BezierCurve.cs +++ b/DS4Windows/BezierCurveEditor/BezierCurve.cs @@ -49,7 +49,7 @@ namespace DS4Windows private static double SUBDIVISION_PRECISION = 0.0000001; private static int SUBDIVISION_MAX_ITERATIONS = 10; - private double mX1 = 0, mY1 = 0, mX2 = 0, mY2 = 0; // Bezier curve definition (0, 0, 0, 0 = Linear) + private double mX1 = 0, mY1 = 0, mX2 = 0, mY2 = 0; // Bezier curve definition (0, 0, 0, 0 = Linear. 99, 99, 0, 0 = Pre-defined hard-coded EnhancedPrecision curve) // Set or Get string representation of the bezier curve definition value (Note! Set doesn't initialize the lookup table. InitBezierCurve needs to be called to actually initalize the calculation) public string AsString @@ -64,8 +64,7 @@ namespace DS4Windows } } - // Custom definition set by DS4Windows options screens. This string is not validated (ie. the value is as user entered it and could be even ab invalid curve definition strimg value). - // AsString property returns the currently effective and validated value. + // Custom definition set by DS4Windows options screens. This string is not validated (ie. the value is as user entered it and could be an invalid curve definition). This value is saved in a profile XML file. public string CustomDefinition { get; set; } public string ToString() { return this.CustomDefinition; } @@ -79,40 +78,51 @@ namespace DS4Windows CustomDefinition = ""; } - public bool InitBezierCurve(string bezierCurveDefinition, AxisType gamepadAxisType) + public bool InitBezierCurve(string bezierCurveDefinition, AxisType gamepadAxisType, bool setCustomDefinitionProperty = false) { + if (setCustomDefinitionProperty) + this.CustomDefinition = bezierCurveDefinition; + this.AsString = bezierCurveDefinition; return InitBezierCurve(mX1, mY1, mX2, mY2, gamepadAxisType); } public bool InitBezierCurve(double x1, double y1, double x2, double y2, AxisType gamepadAxisType) { + bool bRetValue = true; + if (arrayBezierLUT == null) arrayBezierLUT = new byte[256]; if (x1 == 99.0) { - // If x1 is 99 then curve is a pre-defined fixed curve and not a customizable bezier curve + // If curve is "99.0, 99.0, 0.0, 0.0" then curve is a pre-defined fixed EnchPrecision curve and not a customizable bezier curve if (y1 == 99.0) return InitEnhancedPrecision(gamepadAxisType); } if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1) - return false; - //throw new Exception("INVALID VALUE. BezierCurve X1 and X2 should be in [0, 1] range"); - - mX1 = x1; - mY1 = y1; - mX2 = x2; - mY2 = y2; + { + // throw new Exception("INVALID VALUE. BezierCurve X1 and X2 should be in [0, 1] range"); + AppLogger.LogToGui($"WARNING. Invalid custom bezier curve \"{x1}, {y1}, {x2}, {y2}\" in {gamepadAxisType} axis. x1 and x2 should be in 0..1 range. Using linear curve.", true); + mX1 = mY1 = mX2 = mY2 = 0; + bRetValue = false; + } + else + { + mX1 = x1; + mY1 = y1; + mX2 = x2; + mY2 = y2; + } axisType = gamepadAxisType; // If this is linear definition then init the lookup table with 1-on-1 mapping - if(x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0) + if (x1 == 0 && y1 == 0 && ((x2 == 0 && y2 == 0) || (x2 == 1 && y2 == 1))) { for (int idx = 0; idx <= 255; idx++) arrayBezierLUT[idx] = (byte)idx; - return true; + return bRetValue; } try @@ -160,7 +170,7 @@ namespace DS4Windows arraySampleValues = null; } - return true; + return bRetValue; } // Initialize a special "hard-coded" and pre-defined EnhancedPrecision output curve as a lookup result table diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 75e968d..430e3c1 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -1717,7 +1717,7 @@ namespace DS4Windows // Set bezier curve obj of axis. 0=Linear (no curve mapping), 1-5=Pre-defined curves, 6=User supplied custom curve string value of a profile (comma separated list of 4 decimal numbers) switch (curveOptionValue) { - case 1: bezierCurveArray[device].InitBezierCurve(99.0, 99.0, 0.00, 0.00, axisType); break; // Enhanced Precision (hard-coded curve 0.99, 0.99) (Bezier EnchCurve 0.70, 0.28, 1.00, 1.00) + case 1: bezierCurveArray[device].InitBezierCurve(99.0, 99.0, 0.00, 0.00, axisType); break; // Enhanced Precision (hard-coded curve) (The same curve as bezier 0.70, 0.28, 1.00, 1.00) case 2: bezierCurveArray[device].InitBezierCurve(0.55, 0.09, 0.68, 0.53, axisType); break; // Quadric case 3: bezierCurveArray[device].InitBezierCurve(0.74, 0.12, 0.64, 0.29, axisType); break; // Cubic case 4: bezierCurveArray[device].InitBezierCurve(0.00, 0.00, 0.41, 0.96, axisType); break; // Easeout Quad diff --git a/DS4Windows/DS4Forms/Options.cs b/DS4Windows/DS4Forms/Options.cs index 8645ee3..9f4c33b 100644 --- a/DS4Windows/DS4Forms/Options.cs +++ b/DS4Windows/DS4Forms/Options.cs @@ -3289,56 +3289,41 @@ namespace DS4Windows.Forms private void tBCustomOutputCurve_Leave(object sender, EventArgs e) { - // Focus leaves the custom output curve editbox. Store the new custom curve value into LS/RS/L2/R2/SX/SZ bezierCurve object - switch (lbCurveEditorURL.Text.Substring(0, 2)) + if (loading == false) { - case "LS": - if (lsOutCurveComboBox.SelectedIndex == lsOutCurveComboBox.Items.Count - 1) - { - lsOutBezierCurveObj[device].CustomDefinition = tBCustomOutputCurve.Text; - lsOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.LSRS); - } - break; + // Focus leaves the custom output curve editbox. Store the new custom curve value into LS/RS/L2/R2/SX/SZ bezierCurve object + switch (lbCurveEditorURL.Text.Substring(0, 2)) + { + case "LS": + if (lsOutCurveComboBox.SelectedIndex == lsOutCurveComboBox.Items.Count - 1) + lsOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.LSRS, true); + break; - case "RS": - if (rsOutCurveComboBox.SelectedIndex == rsOutCurveComboBox.Items.Count - 1) - { - rsOutBezierCurveObj[device].CustomDefinition = tBCustomOutputCurve.Text; - rsOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.LSRS); - } - break; + case "RS": + if (rsOutCurveComboBox.SelectedIndex == rsOutCurveComboBox.Items.Count - 1) + rsOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.LSRS, true); + break; - case "L2": - if (cBL2OutputCurve.SelectedIndex == cBL2OutputCurve.Items.Count - 1) - { - l2OutBezierCurveObj[device].CustomDefinition = tBCustomOutputCurve.Text; - l2OutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.L2R2); - } - break; + case "L2": + if (cBL2OutputCurve.SelectedIndex == cBL2OutputCurve.Items.Count - 1) + l2OutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.L2R2, true); + break; - case "R2": - if (cBR2OutputCurve.SelectedIndex == cBR2OutputCurve.Items.Count - 1) - { - r2OutBezierCurveObj[device].CustomDefinition = tBCustomOutputCurve.Text; - r2OutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.L2R2); - } - break; + case "R2": + if (cBR2OutputCurve.SelectedIndex == cBR2OutputCurve.Items.Count - 1) + r2OutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.L2R2, true); + break; - case "SX": - if (cBSixaxisXOutputCurve.SelectedIndex == cBSixaxisXOutputCurve.Items.Count - 1) - { - sxOutBezierCurveObj[device].CustomDefinition = tBCustomOutputCurve.Text; - sxOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.SA); - } - break; + case "SX": + if (cBSixaxisXOutputCurve.SelectedIndex == cBSixaxisXOutputCurve.Items.Count - 1) + sxOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.SA, true); + break; - case "SZ": - if (cBSixaxisZOutputCurve.SelectedIndex == cBSixaxisZOutputCurve.Items.Count - 1) - { - szOutBezierCurveObj[device].CustomDefinition = tBCustomOutputCurve.Text; - szOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.SA); - } - break; + case "SZ": + if (cBSixaxisZOutputCurve.SelectedIndex == cBSixaxisZOutputCurve.Items.Count - 1) + szOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.SA, true); + break; + } } }