Custom curve GUI tweaks.

This commit is contained in:
mika-n 2019-07-19 01:49:22 +03:00
parent acc1b3f952
commit 13150015f0
3 changed files with 55 additions and 60 deletions

View File

@ -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");
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

View File

@ -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

View File

@ -3288,59 +3288,44 @@ namespace DS4Windows.Forms
}
private void tBCustomOutputCurve_Leave(object sender, EventArgs e)
{
if (loading == false)
{
// 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].CustomDefinition = tBCustomOutputCurve.Text;
lsOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.LSRS);
}
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);
}
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);
}
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);
}
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);
}
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);
}
szOutBezierCurveObj[device].InitBezierCurve(tBCustomOutputCurve.Text, BezierCurve.AxisType.SA, true);
break;
}
}
}
private void trackFrictionNUD_ValueChanged(object sender, EventArgs e)
{