diff options
| author | a1xd <[email protected]> | 2021-09-06 23:24:51 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-09-23 22:33:13 -0400 |
| commit | a8d48325d5e6fe0466502b865c82317b6f7410a2 (patch) | |
| tree | a1d42734cda76cdf2a0b0c8134ef25f4729e99b3 /grapher/Models | |
| parent | increase lut points capacity to 257 (diff) | |
| download | rawaccel-a8d48325d5e6fe0466502b865c82317b6f7410a2.tar.xz rawaccel-a8d48325d5e6fe0466502b865c82317b6f7410a2.zip | |
get grapher building
Diffstat (limited to 'grapher/Models')
18 files changed, 188 insertions, 203 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 4ce6ed8..e4f924a 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -24,8 +24,7 @@ namespace grapher Button writeButton, ButtonBase resetButton, MouseWatcher mouseWatcher, - ToolStripMenuItem scaleMenuItem, - DeviceIDManager deviceIDManager) + ToolStripMenuItem scaleMenuItem) { AccelForm = accelForm; AccelCalculator = accelCalculator; @@ -38,14 +37,13 @@ namespace grapher DefaultButtonFont = WriteButton.Font; SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor); MouseWatcher = mouseWatcher; - DeviceIDManager = deviceIDManager; ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); WriteButton.Click += new System.EventHandler(OnWriteButtonClick); ResetButton.Click += new System.EventHandler(ResetDriverEventHandler); AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose); - ButtonTimerInterval = Convert.ToInt32(DriverSettings.WriteDelayMs); + ButtonTimerInterval = Convert.ToInt32(DriverConfig.WriteDelayMs); ButtonTimer = new Timer(); ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick); @@ -85,8 +83,6 @@ namespace grapher public ToolStripMenuItem ScaleMenuItem { get; } - public DeviceIDManager DeviceIDManager { get; } - private Timer ChartRefresh { get; } private Font SmallButtonFont { get; } @@ -112,21 +108,23 @@ namespace grapher } } - public DriverSettings MakeSettingsFromFields() + public Profile MakeSettingsFromFields() { - var settings = new DriverSettings(); + var settings = new Profile(); settings.rotation = ApplyOptions.Rotation.Field.Data; - settings.sensitivity = new Vec2<double> - { - x = ApplyOptions.Sensitivity.Fields.X, - y = ApplyOptions.Sensitivity.Fields.Y - }; + settings.sensitivity = ApplyOptions.Sensitivity.Fields.X; + + // TODO - separate sensitivity fields, add new label for ratio + settings.yxSensRatio = ApplyOptions.Sensitivity.Fields.Y; settings.combineMagnitudes = ApplyOptions.IsWhole; - ApplyOptions.SetArgs(ref settings.args); - settings.domainArgs = ApplyOptions.Directionality.GetDomainArgs(); + ApplyOptions.SetArgs(ref settings.argsX, ref settings.argsY); + + var (domWeights, lpNorm) = ApplyOptions.Directionality.GetDomainArgs(); + settings.domainXY = domWeights; + settings.lpNorm = lpNorm; + settings.rangeXY = ApplyOptions.Directionality.GetRangeXY(); - settings.deviceID = DeviceIDManager.ID; Settings.SetHiddenOptions(settings); @@ -141,16 +139,15 @@ namespace grapher { ButtonDelay(WriteButton); - var settings = MakeSettingsFromFields(); - SettingsErrors errors = Settings.TryActivate(settings); - if (errors.Empty()) + var cfg = DriverConfig.FromProfile(MakeSettingsFromFields()); + if (!Settings.TryActivate(cfg, out string errors)) { - RefreshActive(); - return; + error_message = errors.ToString(); } else { - error_message = errors.ToString(); + RefreshActive(); + return; } } catch (ApplicationException e) @@ -161,34 +158,24 @@ namespace grapher new MessageDialog(error_message, "bad input").ShowDialog(); } - - public void UpdateInputManagers() - { - MouseWatcher.UpdateHandles(Settings.ActiveSettings.baseSettings.deviceID); - DeviceIDManager.Update(Settings.ActiveSettings.baseSettings.deviceID); - } - public void RefreshActive() { - UpdateShownActiveValues(Settings.UserSettings); + UpdateShownActiveValues(Settings.ActiveProfile); UpdateGraph(); - UpdateInputManagers(); } public void RefreshUser() { - UpdateShownActiveValues(Settings.UserSettings); + UpdateShownActiveValues(Settings.UserProfile); } public void UpdateGraph() { - AccelCharts.Calculate( - Settings.ActiveAccel, - Settings.ActiveSettings.baseSettings); + AccelCharts.Calculate(Settings.ActiveAccel, Settings.ActiveProfile); AccelCharts.Bind(); } - public void UpdateShownActiveValues(DriverSettings args) + public void UpdateShownActiveValues(Profile args) { AccelForm.ResetAutoScroll(); AccelCharts.ShowActive(args); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 7e5ae9b..cc43aeb 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -17,7 +17,6 @@ namespace grapher.Models public static AccelGUI Construct( RawAcceleration form, - ManagedAccel activeAccel, Chart accelerationChart, Chart accelerationChartY, Chart velocityChart, @@ -34,7 +33,7 @@ namespace grapher.Models ToolStripMenuItem showLastMouseMoveMenuItem, ToolStripMenuItem streamingModeToolStripMenuItem, ToolStripMenuItem autoWriteMenuItem, - ToolStripMenuItem useSpecificDeviceMenuItem, + ToolStripMenuItem deviceMenuItem, ToolStripMenuItem scaleMenuItem, ToolStripTextBox dpiTextBox, ToolStripTextBox pollRateTextBox, @@ -492,17 +491,14 @@ namespace grapher.Models lockXYLabel, accelCharts); - var deviceIdManager = new DeviceIDManager(useSpecificDeviceMenuItem); - var settings = new SettingsManager( - activeAccel, accelCalculator.DPI, accelCalculator.PollRate, autoWriteMenuItem, showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem, streamingModeToolStripMenuItem, - deviceIdManager); + deviceMenuItem); var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, settings); @@ -515,8 +511,7 @@ namespace grapher.Models writeButton, toggleButton, mouseWatcher, - scaleMenuItem, - deviceIdManager); + scaleMenuItem); } #endregion Methods diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 574f55a..6b9cbf3 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -107,7 +107,7 @@ namespace grapher.Models.Calculations continue; } - var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); + var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, 1, simulatedInputDatum.time); var outMagnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(outMagnitude - lastOutputMagnitude, 5); @@ -193,7 +193,7 @@ namespace grapher.Models.Calculations data.MinGain = minSlope; } - public void CalculateDirectional(AccelChartData[] dataByAngle, ManagedAccel accel, DriverSettings settings, IReadOnlyCollection<IReadOnlyCollection<SimulatedMouseInput>> simulatedInputData) + public void CalculateDirectional(AccelChartData[] dataByAngle, ManagedAccel accel, Profile settings, IReadOnlyCollection<IReadOnlyCollection<SimulatedMouseInput>> simulatedInputData) { double maxRatio = 0.0; double minRatio = Double.MaxValue; @@ -219,7 +219,7 @@ namespace grapher.Models.Calculations continue; } - var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); + var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, 1, simulatedInputDatum.time); var magnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(magnitude - lastOutputMagnitude, 5); @@ -246,7 +246,7 @@ namespace grapher.Models.Calculations } var ratio = DecimalCheck(magnitude / simulatedInputDatum.velocity); - var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x); + var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : settings.sensitivity); bool indexToMeasureExtrema = (angleIndex == 0) || (angleIndex == (Constants.AngleDivisions - 1)); @@ -477,16 +477,16 @@ namespace grapher.Models.Calculations return Magnitude(x, y) / time; } - public static bool ShouldStripSens(ref DriverSettings settings) => - settings.sensitivity.x != settings.sensitivity.y; + public static bool ShouldStripSens(Profile settings) => + settings.yxSensRatio != 1; - public static bool ShouldStripRot(ref DriverSettings settings) => + public static bool ShouldStripRot(Profile settings) => settings.rotation > 0; - public static (double, double) GetSens(ref DriverSettings settings) => - (settings.sensitivity.x, settings.sensitivity.y); + public static (double, double) GetSens(Profile settings) => + (settings.sensitivity, settings.sensitivity * settings.yxSensRatio); - public static (double, double) GetRotVector(ref DriverSettings settings) => + public static (double, double) GetRotVector(Profile settings) => (Math.Cos(settings.rotation), Math.Sin(settings.rotation)); public static (double, double) StripSens(double outputX, double outputY, double sensitivityX, double sensitivityY) => diff --git a/grapher/Models/Calculations/Data/AccelDataCombined.cs b/grapher/Models/Calculations/Data/AccelDataCombined.cs index 8efb9ac..025a344 100644 --- a/grapher/Models/Calculations/Data/AccelDataCombined.cs +++ b/grapher/Models/Calculations/Data/AccelDataCombined.cs @@ -40,10 +40,10 @@ namespace grapher.Models.Calculations.Data X.Clear(); } - public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + public void CreateGraphData(ManagedAccel accel, Profile settings) { Clear(); - Calculator.Calculate(X, accel, settings.sensitivity.x, Calculator.SimulatedInputCombined); + Calculator.Calculate(X, accel, settings.sensitivity, Calculator.SimulatedInputCombined); } } } diff --git a/grapher/Models/Calculations/Data/AccelDataXYComponential.cs b/grapher/Models/Calculations/Data/AccelDataXYComponential.cs index 6231eb3..f954230 100644 --- a/grapher/Models/Calculations/Data/AccelDataXYComponential.cs +++ b/grapher/Models/Calculations/Data/AccelDataXYComponential.cs @@ -54,11 +54,12 @@ namespace grapher.Models.Calculations.Data Y.Clear(); } - public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + public void CreateGraphData(ManagedAccel accel, Profile settings) { Clear(); - Calculator.Calculate(X, accel, settings.sensitivity.x, Calculator.SimulatedInputX); - Calculator.Calculate(Y, accel, settings.sensitivity.y, Calculator.SimulatedInputY); + var sensY = settings.sensitivity * settings.yxSensRatio; + Calculator.Calculate(X, accel, settings.sensitivity, Calculator.SimulatedInputX); + Calculator.Calculate(Y, accel, sensY, Calculator.SimulatedInputY); } } } diff --git a/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs index 8bd889d..b139719 100644 --- a/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs +++ b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs @@ -67,7 +67,7 @@ namespace grapher.Models.Calculations.Data } } - public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + public void CreateGraphData(ManagedAccel accel, Profile settings) { Clear(); Calculator.CalculateDirectional(AngleToData, accel, settings, Calculator.SimulatedDirectionalInput); diff --git a/grapher/Models/Calculations/Data/IAccelData.cs b/grapher/Models/Calculations/Data/IAccelData.cs index 576e6df..2ae6716 100644 --- a/grapher/Models/Calculations/Data/IAccelData.cs +++ b/grapher/Models/Calculations/Data/IAccelData.cs @@ -10,7 +10,7 @@ namespace grapher.Models.Calculations.Data { void CalculateDots(double x, double y, double timeInMs); - void CreateGraphData(ManagedAccel accel, DriverSettings settings); + void CreateGraphData(ManagedAccel accel, Profile settings); void Clear(); diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 631c2e2..93c9218 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -121,9 +121,9 @@ namespace grapher ChartState.Bind(); } - public void ShowActive(DriverSettings driverSettings) + public void ShowActive(Profile args) { - ChartState = ChartStateManager.DetermineState(driverSettings); + ChartState = ChartStateManager.DetermineState(args); ChartState.Activate(); Bind(); } @@ -134,9 +134,9 @@ namespace grapher ChartState.Redraw(); } - public void Calculate(ManagedAccel accel, DriverSettings settings) + public void Calculate(ManagedAccel accel, Profile settings) { - ChartState.SetUpCalculate(settings); + ChartState.SetUpCalculate(); ChartState.Calculate(accel, settings); } diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index a50eaf0..eca2e43 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -35,7 +35,7 @@ namespace grapher.Models.Charts.ChartState public AccelCalculator Calculator { get; } - public virtual DriverSettings Settings { get; set; } + public virtual Profile Settings { get; set; } internal bool TwoDotsPerGraph { get; set; } @@ -48,7 +48,7 @@ namespace grapher.Models.Charts.ChartState public abstract void Activate(); - public virtual void Calculate(ManagedAccel accel, DriverSettings settings) + public virtual void Calculate(ManagedAccel accel, Profile settings) { Data.CreateGraphData(accel, settings); } @@ -60,7 +60,7 @@ namespace grapher.Models.Charts.ChartState GainChart.Update(); } - public virtual void SetUpCalculate(DriverSettings settings) + public virtual void SetUpCalculate() { Data.Clear(); Calculator.ScaleByMouseSettings(); diff --git a/grapher/Models/Charts/ChartState/ChartStateManager.cs b/grapher/Models/Charts/ChartState/ChartStateManager.cs index 3d4bbec..1e5386c 100644 --- a/grapher/Models/Charts/ChartState/ChartStateManager.cs +++ b/grapher/Models/Charts/ChartState/ChartStateManager.cs @@ -50,14 +50,14 @@ namespace grapher.Models.Charts.ChartState private XYTwoGraphState XYTwoGraphState { get; } - public ChartState DetermineState(DriverSettings settings) + public ChartState DetermineState(Profile settings) { ChartState chartState; if (settings.combineMagnitudes) { - if (settings.sensitivity.x != settings.sensitivity.y || - settings.domainArgs.domainXY.x != settings.domainArgs.domainXY.y || + if (settings.yxSensRatio != 1 || + settings.domainXY.x != settings.domainXY.y || settings.rangeXY.x != settings.rangeXY.y) { chartState = XYOneGraphState; diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index 5b6c2b8..387d1b1 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -23,7 +23,7 @@ namespace grapher.Models.Charts.ChartState Data = new AccelDataXYComponential(xPoints, yPoints, accelCalculator); } - public override DriverSettings Settings { get; set; } + public override Profile Settings { get; set; } public override void Activate() { diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs index 39856a1..e0ee686 100644 --- a/grapher/Models/Devices/DeviceIDManager.cs +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -46,7 +46,7 @@ namespace grapher.Models.Devices if (found) SetActive(anyDevice); - foreach (string id in RawInputInterop.GetDeviceIDs()) +/* foreach (string id in RawInputInterop.GetDeviceIDs()) { var deviceItem = new DeviceIDItem(string.Empty, id, this); if (!found && deviceItem.ID.Equals(devID)) @@ -54,7 +54,7 @@ namespace grapher.Models.Devices SetActive(deviceItem); found = true; } - } + }*/ if (!found) { diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index c5c2ae5..c36ceb4 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -691,7 +691,6 @@ namespace grapher.Models.Mouse AccelCharts = accelCharts; SettingsManager = setMngr; MouseData = new MouseData(); - DeviceHandles = new List<IntPtr>(); RAWINPUTDEVICE device = new RAWINPUTDEVICE(); device.WindowHandle = ContainingForm.Handle; @@ -722,10 +721,6 @@ namespace grapher.Models.Mouse private Stopwatch Stopwatch { get; } - private List<IntPtr> DeviceHandles { get; } - - private bool AnyDevice { get; set; } - private double PollTime { get => 1000 / SettingsManager.PollRateField.Data; @@ -735,16 +730,6 @@ namespace grapher.Models.Mouse #region Methods - public void UpdateHandles(string devID) - { - DeviceHandles.Clear(); - AnyDevice = string.IsNullOrEmpty(devID); - if (!AnyDevice) - { - RawInputInterop.AddHandlesFromID(devID, DeviceHandles); - } - } - public void UpdateLastMove() { MouseData.Get(out var x, out var y); @@ -758,7 +743,7 @@ 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 = AnyDevice || DeviceHandles.Contains(rawInput.Header.Device); + bool deviceMatch = SettingsManager.ActiveHandles.Contains(rawInput.Header.Device); if (relative && deviceMatch && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { @@ -772,8 +757,7 @@ namespace grapher.Models.Mouse // strip negative directional multipliers, charts calculated from positive input - Vec2<double> dirMults = SettingsManager.ActiveSettings.baseSettings - .directionalMultipliers; + Vec2<double> dirMults = SettingsManager.ActiveProfile.directionalMultipliers; if (dirMults.x > 0 && x < 0) { diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 44c9ea8..eab38a1 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -21,7 +21,6 @@ namespace grapher public static readonly LayoutBase Power = new PowerLayout(); public static readonly LayoutBase LUT = new LUTLayout(); public static readonly LayoutBase Off = new OffLayout(); - public static readonly LayoutBase Unsupported = new UnsupportedLayout(); #endregion Fields @@ -262,21 +261,22 @@ namespace grapher { AccelerationType = AccelTypeFromSettings(ref args); AccelTypeActiveValue.SetValue(AccelerationType.ActiveName); - GainSwitch.SetActiveValue(args.legacy); + GainSwitch.SetActiveValue(args.gain); Weight.SetActiveValue(args.weight); - Cap.SetActiveValue(args.cap); + Cap.SetActiveValue(args.cap.x); Offset.SetActiveValue(args.offset); - Acceleration.SetActiveValue(args.accelClassic); + Acceleration.SetActiveValue(args.acceleration); DecayRate.SetActiveValue(args.decayRate); GrowthRate.SetActiveValue(args.growthRate); Smooth.SetActiveValue(args.smooth); Scale.SetActiveValue(args.scale); Limit.SetActiveValue((args.mode == AccelMode.motivity) ? args.motivity : args.limit); - PowerClassic.SetActiveValue(args.power); - Exponent.SetActiveValue(args.exponent); + PowerClassic.SetActiveValue(args.exponentClassic); + Exponent.SetActiveValue(args.exponentPower); Midpoint.SetActiveValue(args.midpoint); - LutPanel.SetActiveValues(args.tableData.points, args.tableData.length); - LutApply.SetActiveValue(args.tableData.velocity); + LutPanel.SetActiveValues(args.data, args.length, args.mode); + // TODO - use GainSwitch only? + LutApply.SetActiveValue(args.gain); } public void ShowFull() @@ -308,17 +308,16 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - if (AccelerationType == Unsupported) throw new NotImplementedException(); - args.mode = AccelerationType.Mode; - args.legacy = !GainSwitch.CheckBox.Checked; + args.gain = GainSwitch.CheckBox.Checked; - if (Acceleration.Visible) args.accelClassic = Acceleration.Field.Data; + if (Acceleration.Visible) args.acceleration = Acceleration.Field.Data; if (DecayRate.Visible) args.decayRate = DecayRate.Field.Data; if (GrowthRate.Visible) args.growthRate = GrowthRate.Field.Data; if (Smooth.Visible) args.smooth = Smooth.Field.Data; if (Scale.Visible) args.scale = Scale.Field.Data; - if (Cap.Visible) args.cap = Cap.Field.Data; + // TODO - make field for output and in_out cap + if (Cap.Visible) args.cap.x = Cap.Field.Data; if (Limit.Visible) { if (args.mode == AccelMode.motivity) @@ -328,20 +327,27 @@ namespace grapher else { args.limit = Limit.Field.Data; - } + } } - if (PowerClassic.Visible) args.power = PowerClassic.Field.Data; - if (Exponent.Visible)args.exponent = Exponent.Field.Data; + if (PowerClassic.Visible) args.exponentClassic = PowerClassic.Field.Data; + if (Exponent.Visible) args.exponentPower = Exponent.Field.Data; if (Offset.Visible) args.offset = Offset.Field.Data; if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (Weight.Visible) args.weight = Weight.Field.Data; if (LutPanel.Visible) { (var points, var length) = LutPanel.GetPoints(); - args.tableData.points = points; - args.tableData.length = length; + args.length = length * 2; + + for (int i = 0; i < length; i++) + { + ref var p = ref points[i]; + var data_idx = i * 2; + args.data[data_idx] = p.x; + args.data[data_idx + 1] = p.y; + } } - if (LutApply.Visible) args.tableData.velocity = LutApply.ApplyType == LutApplyOptions.LutApplyType.Velocity; + } public override void AlignActiveValues() @@ -407,19 +413,9 @@ namespace grapher private LayoutBase AccelTypeFromSettings(ref AccelArgs args) { - if (args.spacedTableArgs.mode != SpacedTableMode.off) - { - if (!AccelDropdown.Items.Contains(Unsupported)) - { - AccelDropdown.Items.Add(Unsupported); - } - - return Unsupported; - } - switch (args.mode) { - case AccelMode.classic: return (args.power == 2) ? Linear : Classic; + case AccelMode.classic: return (args.exponentClassic == 2) ? Linear : Classic; case AccelMode.jump: return Jump; case AccelMode.natural: return Natural; case AccelMode.motivity: return Motivity; diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 06854b8..0d87943 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -81,30 +81,30 @@ namespace grapher.Models.Options #region Methods - public void SetArgs(ref Vec2<AccelArgs> args) + public void SetArgs(ref AccelArgs argsX, ref AccelArgs argsY) { - OptionSetX.SetArgs(ref args.x); + OptionSetX.SetArgs(ref argsX); if (ByComponentVectorXYLock.Checked) { - OptionSetX.SetArgs(ref args.y); + OptionSetX.SetArgs(ref argsY); } else { - OptionSetY.SetArgs(ref args.y); + OptionSetY.SetArgs(ref argsY); } } - public void SetActiveValues(DriverSettings settings) + public void SetActiveValues(Profile settings) { - Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); + Sensitivity.SetActiveValues(settings.sensitivity, settings.yxSensRatio); Rotation.SetActiveValue(settings.rotation); WholeVectorCheckBox.Checked = settings.combineMagnitudes; ByComponentVectorCheckBox.Checked = !settings.combineMagnitudes; - ByComponentVectorXYLock.Checked = settings.args.x.Equals(settings.args.y); - OptionSetX.SetActiveValues(ref settings.args.x); - OptionSetY.SetActiveValues(ref settings.args.y); + ByComponentVectorXYLock.Checked = settings.argsX.Equals(settings.argsY); + OptionSetX.SetActiveValues(ref settings.argsX); + OptionSetY.SetActiveValues(ref settings.argsY); Directionality.SetActiveValues(settings); diff --git a/grapher/Models/Options/Directionality/DirectionalityOptions.cs b/grapher/Models/Options/Directionality/DirectionalityOptions.cs index 9288132..35d2575 100644 --- a/grapher/Models/Options/Directionality/DirectionalityOptions.cs +++ b/grapher/Models/Options/Directionality/DirectionalityOptions.cs @@ -70,17 +70,16 @@ namespace grapher.Models.Options.Directionality private bool IsHidden { get; set; } - public DomainArgs GetDomainArgs() + public Tuple<Vec2<double>, double> GetDomainArgs() { - return new DomainArgs + var weights = new Vec2<double> { - domainXY = new Vec2<double> - { - x = Domain.Fields.X, - y = Domain.Fields.Y, - }, - lpNorm = ByComponentCheckBox.Checked ? 2 : LpNorm.Field.Data + x = Domain.Fields.X, + y = Domain.Fields.Y }; + double p = ByComponentCheckBox.Checked ? 2 : LpNorm.Field.Data; + + return new Tuple<Vec2<double>, double>(weights, p); } public Vec2<double> GetRangeXY() @@ -92,14 +91,14 @@ namespace grapher.Models.Options.Directionality }; } - public void SetActiveValues(DriverSettings settings) + public void SetActiveValues(Profile settings) { - Domain.SetActiveValues(settings.domainArgs.domainXY.x, settings.domainArgs.domainXY.y); + Domain.SetActiveValues(settings.domainXY.x, settings.domainXY.y); Range.SetActiveValues(settings.rangeXY.x, settings.rangeXY.y); if (settings.combineMagnitudes) { - LpNorm.SetActiveValue(settings.domainArgs.lpNorm); + LpNorm.SetActiveValue(settings.lpNorm); } else { diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index 3690c76..11550e4 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -111,15 +111,26 @@ namespace grapher.Models.Options.LUT // Nothing to do here. } - public void SetActiveValues(IEnumerable<Vec2<float>> activePoints, int length) + public void SetActiveValues(IEnumerable<float> rawData, int length, AccelMode mode) { - if (length > 0 && activePoints.First().x != 0) + if (mode == AccelMode.lut && length > 1 && rawData.First() != 0) { - ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints, length); + var pointsLen = length / 2; + var points = new Vec2<float>[pointsLen]; + for (int i = 0; i < pointsLen; i++) + { + var data_idx = i * 2; + points[i] = new Vec2<float> + { + x = rawData.ElementAt(data_idx), + y = rawData.ElementAt(data_idx + 1) + }; + } + ActiveValuesTextBox.Text = PointsToActiveValuesText(points, length); if (string.IsNullOrWhiteSpace(PointsTextBox.Text)) { - PointsTextBox.Text = PointsToEntryTextBoxText(activePoints, length); + PointsTextBox.Text = PointsToEntryTextBoxText(points, length); } } else @@ -135,14 +146,12 @@ namespace grapher.Models.Options.LUT private static (Vec2<float>[], int length) UserTextToPoints(string userText) { - const int MaxPoints = 256; - if (string.IsNullOrWhiteSpace(userText)) { throw new ApplicationException("Text must be entered in text box to fill Look Up Table."); } - Vec2<float>[] points = new Vec2<float>[MaxPoints]; + Vec2<float>[] points = new Vec2<float>[AccelArgs.MaxLutPoints]; var userTextSplit = userText.Trim().Trim(';').Split(';'); int index = 0; @@ -155,9 +164,9 @@ namespace grapher.Models.Options.LUT throw new ApplicationException("At least 2 points required"); } - if (pointsCount > MaxPoints) + if (pointsCount > AccelArgs.MaxLutPoints) { - throw new ApplicationException($"Number of points exceeds max ({MaxPoints})"); + throw new ApplicationException($"Number of points exceeds max ({AccelArgs.MaxLutPoints})"); } foreach(var pointEntry in userTextSplit) diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 346bc9b..d92f18a 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Text; using System.Drawing; using grapher.Models.Devices; +using System.Collections.Generic; namespace grapher.Models.Serialized { @@ -14,14 +15,13 @@ namespace grapher.Models.Serialized #region Constructors public SettingsManager( - ManagedAccel activeAccel, Field dpiField, Field pollRateField, ToolStripMenuItem autoWrite, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain, ToolStripMenuItem streamingMode, - DeviceIDManager deviceIDManager) + ToolStripMenuItem deviceMenuItem) { DpiField = dpiField; PollRateField = pollRateField; @@ -29,9 +29,14 @@ namespace grapher.Models.Serialized ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; StreamingModeMenuItem = streamingMode; - DeviceIDManager = deviceIDManager; + deviceMenuItem.Click += (s, e) => new DeviceMenuForm(this).ShowDialog(); - SetActiveFields(activeAccel); + SystemDevices = new List<MultiHandleDevice>(); + ActiveHandles = new List<IntPtr>(); + + // TODO - remove ActiveConfig/AutoWrite entirely? + // shouldn't be needed with internal profiles support + ActiveConfig = DriverConfig.GetActive(); GuiSettings = GUISettings.MaybeLoad(); @@ -45,7 +50,7 @@ namespace grapher.Models.Serialized UpdateFieldsFromGUISettings(); } - UserSettings = InitUserSettings(); + UserConfig = InitUserSettings(); } #endregion Constructors @@ -54,23 +59,39 @@ namespace grapher.Models.Serialized public GUISettings GuiSettings { get; private set; } - public ManagedAccel ActiveAccel { get; private set; } + public DriverConfig ActiveConfig { get; private set; } + + public Profile ActiveProfile + { + get => ActiveConfig.profiles[0]; + } - public ExtendedSettings ActiveSettings { get; private set; } + public ManagedAccel ActiveAccel + { + get => ActiveConfig.accels[0]; + } - public DriverSettings UserSettings { get; private set; } + public DriverConfig UserConfig { get; private set; } + + public Profile UserProfile + { + get => UserConfig.profiles[0]; + } public Field DpiField { get; private set; } public Field PollRateField { get; private set; } - public DeviceIDManager DeviceIDManager { get; } + public IList<MultiHandleDevice> SystemDevices { get; private set; } + + public List<IntPtr> ActiveHandles { get; private set; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } + private ToolStripMenuItem StreamingModeMenuItem{ get; set; } #endregion Properties @@ -78,10 +99,8 @@ namespace grapher.Models.Serialized public void DisableDriver() { - var defaultSettings = new ExtendedSettings(); - ActiveSettings = defaultSettings; - ActiveAccel.Settings = defaultSettings; - new Thread(() => ActiveAccel.Activate()).Start(); + ActiveConfig = DriverConfig.GetDefault(); + new Thread(() => DriverConfig.Deactivate()).Start(); } public void UpdateFieldsFromGUISettings() @@ -94,36 +113,31 @@ namespace grapher.Models.Serialized AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup; } - public SettingsErrors TryActivate(DriverSettings settings) + public bool TryActivate(DriverConfig settings, out string errors) { - var errors = new SettingsErrors(settings); + errors = settings.Errors(); - if (errors.Empty()) + if (errors == null) { GuiSettings = MakeGUISettingsFromFields(); GuiSettings.Save(); - UserSettings = settings; - File.WriteAllText(Constants.DefaultSettingsFileName, RaConvert.Settings(settings)); + UserConfig = settings; + ActiveConfig = settings; + File.WriteAllText(Constants.DefaultSettingsFileName, settings.ToJSON()); - ActiveSettings = new ExtendedSettings(settings); - ActiveAccel.Settings = ActiveSettings; - - new Thread(() => ActiveAccel.Activate()).Start(); + new Thread(() => ActiveConfig.Activate()).Start(); } - return errors; + return errors == null; } - public void SetHiddenOptions(DriverSettings settings) + public void SetHiddenOptions(Profile settings) { - settings.snap = UserSettings.snap; - settings.maximumSpeed = UserSettings.maximumSpeed; - settings.minimumSpeed = UserSettings.minimumSpeed; - settings.minimumTime = UserSettings.minimumTime; - settings.maximumTime = UserSettings.maximumTime; - settings.ignore = UserSettings.ignore; - settings.directionalMultipliers = UserSettings.directionalMultipliers; + settings.snap = UserProfile.snap; + settings.maximumSpeed = UserProfile.maximumSpeed; + settings.minimumSpeed = UserProfile.minimumSpeed; + settings.directionalMultipliers = UserProfile.directionalMultipliers; } public GUISettings MakeGUISettingsFromFields() @@ -139,31 +153,40 @@ namespace grapher.Models.Serialized }; } - public bool TableActive() + private void SetActiveHandles() + { + ActiveHandles.Clear(); + // TODO + foreach (var sysDev in SystemDevices) + { + ActiveHandles.AddRange(sysDev.handles); + } + } + + private void OnProfileSwitch() { - return ActiveSettings.tables.x != null || ActiveSettings.tables.y != null; + SetActiveHandles(); } - public void SetActiveFields(ManagedAccel activeAccel) + public void OnDeviceChangeMessage() { - ActiveAccel = activeAccel; - ActiveSettings = activeAccel.Settings; + SystemDevices = MultiHandleDevice.GetList(); + SetActiveHandles(); } - private DriverSettings InitUserSettings() + private DriverConfig InitUserSettings() { var path = Constants.DefaultSettingsFileName; if (File.Exists(path)) { try { - DriverSettings settings = RaConvert.Settings(File.ReadAllText(path)); + var (cfg, err) = DriverConfig.Convert(File.ReadAllText(path)); if (!GuiSettings.AutoWriteToDriverOnStartup || - TableActive() || - TryActivate(settings).Empty()) + (err == null && TryActivate(cfg, out string _))) { - return settings; + return cfg; } } @@ -173,17 +196,8 @@ namespace grapher.Models.Serialized } } - if (!TableActive()) - { - File.WriteAllText(path, RaConvert.Settings(ActiveSettings.baseSettings)); - return ActiveSettings.baseSettings; - } - else - { - var defaultSettings = new DriverSettings(); - File.WriteAllText(path, RaConvert.Settings(defaultSettings)); - return defaultSettings; - } + File.WriteAllText(path, ActiveConfig.ToJSON()); + return ActiveConfig; } #endregion Methods |