From a8d48325d5e6fe0466502b865c82317b6f7410a2 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Mon, 6 Sep 2021 23:24:51 -0400 Subject: get grapher building --- grapher/Models/AccelGUI.cs | 59 ++++------- grapher/Models/AccelGUIFactory.cs | 11 +- grapher/Models/Calculations/AccelCalculator.cs | 20 ++-- .../Models/Calculations/Data/AccelDataCombined.cs | 4 +- .../Calculations/Data/AccelDataXYComponential.cs | 7 +- .../Calculations/Data/AccelDataXYDirectional.cs | 2 +- grapher/Models/Calculations/Data/IAccelData.cs | 2 +- grapher/Models/Charts/AccelCharts.cs | 8 +- grapher/Models/Charts/ChartState/ChartState.cs | 6 +- .../Models/Charts/ChartState/ChartStateManager.cs | 6 +- .../Models/Charts/ChartState/XYTwoGraphState.cs | 2 +- grapher/Models/Devices/DeviceIDManager.cs | 4 +- grapher/Models/Mouse/MouseWatcher.cs | 20 +--- grapher/Models/Options/AccelTypeOptions.cs | 56 +++++----- grapher/Models/Options/ApplyOptions.cs | 18 ++-- .../Directionality/DirectionalityOptions.cs | 21 ++-- grapher/Models/Options/LUT/LUTPanelOptions.cs | 27 +++-- grapher/Models/Serialized/SettingsManager.cs | 118 ++++++++++++--------- 18 files changed, 188 insertions(+), 203 deletions(-) (limited to 'grapher/Models') 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 - { - 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> simulatedInputData) + public void CalculateDirectional(AccelChartData[] dataByAngle, ManagedAccel accel, Profile settings, IReadOnlyCollection> 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(); RAWINPUTDEVICE device = new RAWINPUTDEVICE(); device.WindowHandle = ContainingForm.Handle; @@ -722,10 +721,6 @@ namespace grapher.Models.Mouse private Stopwatch Stopwatch { get; } - private List 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 dirMults = SettingsManager.ActiveSettings.baseSettings - .directionalMultipliers; + Vec2 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 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, double> GetDomainArgs() { - return new DomainArgs + var weights = new Vec2 { - domainXY = new Vec2 - { - 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, double>(weights, p); } public Vec2 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> activePoints, int length) + public void SetActiveValues(IEnumerable 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[pointsLen]; + for (int i = 0; i < pointsLen; i++) + { + var data_idx = i * 2; + points[i] = new Vec2 + { + 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[], 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[] points = new Vec2[MaxPoints]; + Vec2[] points = new Vec2[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(); + ActiveHandles = new List(); + + // 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 SystemDevices { get; private set; } + + public List 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 -- cgit v1.2.3 From 00d39102b469b459c5803fe1a20e52d8217add08 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 7 Sep 2021 19:53:00 -0400 Subject: update SettingsManager load active config from driver only when necessary ignore devices that aren't running the active profile (in mousewatcher) --- grapher/Models/AccelGUI.cs | 3 +- grapher/Models/Serialized/SettingsManager.cs | 97 +++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 18 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index e4f924a..6ad57d9 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -139,8 +139,7 @@ namespace grapher { ButtonDelay(WriteButton); - var cfg = DriverConfig.FromProfile(MakeSettingsFromFields()); - if (!Settings.TryActivate(cfg, out string errors)) + if (!Settings.TryActivate(MakeSettingsFromFields(), out string errors)) { error_message = errors.ToString(); } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index d92f18a..3789c05 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -7,6 +7,7 @@ using System.Text; using System.Drawing; using grapher.Models.Devices; using System.Collections.Generic; +using System.Linq; namespace grapher.Models.Serialized { @@ -34,10 +35,6 @@ namespace grapher.Models.Serialized SystemDevices = new List(); ActiveHandles = new List(); - // TODO - remove ActiveConfig/AutoWrite entirely? - // shouldn't be needed with internal profiles support - ActiveConfig = DriverConfig.GetActive(); - GuiSettings = GUISettings.MaybeLoad(); if (GuiSettings is null) @@ -50,20 +47,39 @@ namespace grapher.Models.Serialized UpdateFieldsFromGUISettings(); } - UserConfig = InitUserSettings(); + UserConfig = InitActiveAndGetUserConfig(); } #endregion Constructors + #region Fields + + private DriverConfig ActiveConfigField; + + #endregion Fields + #region Properties public GUISettings GuiSettings { get; private set; } - public DriverConfig ActiveConfig { get; private set; } + public DriverConfig ActiveConfig + { + get => ActiveConfigField; + + private set + { + if (ActiveConfigField != value) + { + ActiveConfigField = value; + ActiveProfileNamesSet = new HashSet(value.profiles.Select(p => p.name)); + } + } + } public Profile ActiveProfile { - get => ActiveConfig.profiles[0]; + get => ActiveConfigField.profiles[0]; + private set => ActiveConfigField.SetProfileAt(0, value); } public ManagedAccel ActiveAccel @@ -78,13 +94,15 @@ namespace grapher.Models.Serialized get => UserConfig.profiles[0]; } + public HashSet ActiveProfileNamesSet { get; private set; } + public Field DpiField { get; private set; } public Field PollRateField { get; private set; } public IList SystemDevices { get; private set; } - public List ActiveHandles { get; private set; } + public List ActiveHandles { get; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } @@ -113,6 +131,18 @@ namespace grapher.Models.Serialized AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup; } + public bool TryActivate(Profile settings, out string errors) + { + var old = ActiveProfile; + ActiveProfile = settings; + bool success = TryActivate(ActiveConfig, out errors); + if (!success) + { + ActiveProfile = old; + } + return success; + } + public bool TryActivate(DriverConfig settings, out string errors) { errors = settings.Errors(); @@ -156,14 +186,38 @@ namespace grapher.Models.Serialized private void SetActiveHandles() { ActiveHandles.Clear(); - // TODO - foreach (var sysDev in SystemDevices) + + bool ActiveProfileIsFirst = ActiveProfile == ActiveConfig.profiles[0]; + + foreach (var dev in SystemDevices) MaybeAdd(dev); + + void MaybeAdd(MultiHandleDevice dev) { - ActiveHandles.AddRange(sysDev.handles); + foreach (var settings in ActiveConfig.devices) + { + if (settings.id == dev.id) + { + if (!settings.config.disable && + ((ActiveProfileIsFirst && + (string.IsNullOrEmpty(settings.profile) || + !ActiveProfileNamesSet.Contains(settings.profile))) || + ActiveProfile.name == settings.profile)) + { + ActiveHandles.AddRange(dev.handles); + } + + return; + } + } + + if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) + { + ActiveHandles.AddRange(dev.handles); + } } } - private void OnProfileSwitch() + public void OnProfileSelectionChange() { SetActiveHandles(); } @@ -174,7 +228,7 @@ namespace grapher.Models.Serialized SetActiveHandles(); } - private DriverConfig InitUserSettings() + private DriverConfig InitActiveAndGetUserConfig() { var path = Constants.DefaultSettingsFileName; if (File.Exists(path)) @@ -183,12 +237,22 @@ namespace grapher.Models.Serialized { var (cfg, err) = DriverConfig.Convert(File.ReadAllText(path)); - if (!GuiSettings.AutoWriteToDriverOnStartup || - (err == null && TryActivate(cfg, out string _))) + if (err == null) { + if (GuiSettings.AutoWriteToDriverOnStartup) + { + if (!TryActivate(cfg, out string _)) + { + throw new Exception("deserialization succeeded but TryActivate failed"); + } + } + else + { + ActiveConfig = DriverConfig.GetActive(); + } + return cfg; } - } catch (JsonException e) { @@ -196,6 +260,7 @@ namespace grapher.Models.Serialized } } + ActiveConfig = DriverConfig.GetActive(); File.WriteAllText(path, ActiveConfig.ToJSON()); return ActiveConfig; } -- cgit v1.2.3 From 2b568ff5a9c64c549a6d15a19aab0ca4d3a22c11 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Fri, 10 Sep 2021 23:07:02 -0700 Subject: Add y\x ratio to gui --- grapher/Models/AccelGUI.cs | 4 +- grapher/Models/Options/AccelOptionSet.cs | 2 +- grapher/Models/Options/ApplyOptions.cs | 15 +++--- grapher/Models/Options/CheckBoxOption.cs | 3 ++ grapher/Models/Options/LockableOption.cs | 89 ++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 grapher/Models/Options/LockableOption.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 6ad57d9..801fd8d 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -113,12 +113,12 @@ namespace grapher var settings = new Profile(); settings.rotation = ApplyOptions.Rotation.Field.Data; - settings.sensitivity = ApplyOptions.Sensitivity.Fields.X; + settings.sensitivity = ApplyOptions.Sensitivity.Field.Data; // TODO - separate sensitivity fields, add new label for ratio settings.yxSensRatio = ApplyOptions.Sensitivity.Fields.Y; settings.combineMagnitudes = ApplyOptions.IsWhole; - ApplyOptions.SetArgs(ref settings.argsX, ref settings.argsY); + ApplyOptions.SetArgsFromActiveValues(ref settings.argsX, ref settings.argsY); var (domWeights, lpNorm) = ApplyOptions.Directionality.GetDomainArgs(); settings.domainXY = domWeights; diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index 75eb017..3451402 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -99,7 +99,7 @@ namespace grapher.Models.Options Options.Top = TopAnchor; } - public void SetArgs(ref AccelArgs args) + public void SetArgsFromActiveValues(ref AccelArgs args) { Options.SetArgs(ref args); } diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 0d87943..5c3494c 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -65,7 +65,9 @@ namespace grapher.Models.Options public DirectionalityOptions Directionality { get; } - public OptionXY Sensitivity { get; } + public Option Sensitivity { get; } + + public Option YToXRatio { get; } public Option Rotation { get; } @@ -81,23 +83,24 @@ namespace grapher.Models.Options #region Methods - public void SetArgs(ref AccelArgs argsX, ref AccelArgs argsY) + public void SetArgsFromActiveValues(ref AccelArgs argsX, ref AccelArgs argsY) { - OptionSetX.SetArgs(ref argsX); + OptionSetX.SetArgsFromActiveValues(ref argsX); if (ByComponentVectorXYLock.Checked) { - OptionSetX.SetArgs(ref argsY); + OptionSetX.SetArgsFromActiveValues(ref argsY); } else { - OptionSetY.SetArgs(ref argsY); + OptionSetY.SetArgsFromActiveValues(ref argsY); } } public void SetActiveValues(Profile settings) { - Sensitivity.SetActiveValues(settings.sensitivity, settings.yxSensRatio); + Sensitivity.SetActiveValue(settings.sensitivity); + YToXRatio.SetActiveValue(settings.yxSensRatio); Rotation.SetActiveValue(settings.rotation); WholeVectorCheckBox.Checked = settings.combineMagnitudes; diff --git a/grapher/Models/Options/CheckBoxOption.cs b/grapher/Models/Options/CheckBoxOption.cs index abf96d3..1a4245d 100644 --- a/grapher/Models/Options/CheckBoxOption.cs +++ b/grapher/Models/Options/CheckBoxOption.cs @@ -2,6 +2,9 @@ namespace grapher.Models.Options { + /// + /// This is an option type that is just a checkbox. + /// public class CheckBoxOption : OptionBase { public CheckBoxOption( diff --git a/grapher/Models/Options/LockableOption.cs b/grapher/Models/Options/LockableOption.cs new file mode 100644 index 0000000..bf77520 --- /dev/null +++ b/grapher/Models/Options/LockableOption.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + /// + /// This is an option type that is a regular option with a checkbox that disables it. + /// + public class LockableOption : OptionBase + { + public LockableOption( + Option option, + CheckBox checkBox, + int lockedvalue) + { + Option = option; + LockBox = checkBox; + LockedValue = lockedvalue; + } + + public Option Option { get; } + + public CheckBox LockBox { get; } + + public int LockedValue { get; } + + public override int Left + { + get => Option.Left; + + set + { + Option.Left = value; + } + } + + public override int Top + { + get => Option.Top; + + set + { + Option.Top = value; + LockBox.Top = value; + } + } + + public override int Width + { + get => Option.Width; + + set + { + Option.Width = value; + } + } + + public override int Height + { + get => Option.Height; + } + + public override bool Visible + { + get => Option.Visible; + } + + public override void AlignActiveValues() + { + Option.AlignActiveValues(); + } + + public override void Hide() + { + Option.Hide(); + LockBox.Hide(); + } + + public override void Show(string Name) + { + Option.Show(Name); + LockBox.Show(); + } + } +} -- cgit v1.2.3 From affc97b1ef41437e7caba31be8e9b9212805182e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sat, 11 Sep 2021 17:38:59 -0700 Subject: YToXRatio fully works --- grapher/Models/AccelGUI.cs | 2 +- grapher/Models/AccelGUIFactory.cs | 27 ++++++++++++------ grapher/Models/Options/ApplyOptions.cs | 13 +++++---- grapher/Models/Options/LockableOption.cs | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 14 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 801fd8d..e15aba9 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -116,7 +116,7 @@ namespace grapher settings.sensitivity = ApplyOptions.Sensitivity.Field.Data; // TODO - separate sensitivity fields, add new label for ratio - settings.yxSensRatio = ApplyOptions.Sensitivity.Fields.Y; + settings.yxSensRatio = ApplyOptions.YToXRatio.Value; settings.combineMagnitudes = ApplyOptions.IsWhole; ApplyOptions.SetArgsFromActiveValues(ref settings.argsX, ref settings.argsY); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index cc43aeb..20040fb 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -83,6 +83,7 @@ namespace grapher.Models RichTextBox yLutPointsBox, Label lockXYLabel, Label sensitivityLabel, + Label yxRatioLabel, Label rotationLabel, Label weightLabelX, Label weightLabelY, @@ -112,8 +113,8 @@ namespace grapher.Models Label constantThreeLabelY, Label activeValueTitleX, Label activeValueTitleY, - Label sensitivityActiveXLabel, - Label sensitivityActiveYLabel, + Label sensitivityActiveLabel, + Label yxRatioActiveLabel, Label rotationActiveLabel, Label weightActiveXLabel, Label weightActiveYLabel, @@ -181,18 +182,27 @@ namespace grapher.Models writeButton, accelCalculator); - var sensitivity = new OptionXY( + var sensitivity = new Option( sensitivityBoxX, - sensitivityBoxY, - sensXYLock, form, 1, sensitivityLabel, - new ActiveValueLabelXY( - new ActiveValueLabel(sensitivityActiveXLabel, activeValueTitleX), - new ActiveValueLabel(sensitivityActiveYLabel, activeValueTitleX)), + 0, + new ActiveValueLabel(sensitivityActiveLabel, activeValueTitleX), "Sens Multiplier"); + var yxRatio = new LockableOption( + new Option( + sensitivityBoxY, + form, + 1, + yxRatioLabel, + 0, + new ActiveValueLabel(yxRatioActiveLabel, activeValueTitleX), + "Y/X Ratio"), + sensXYLock, + 1); + var rotation = new Option( rotationBox, form, @@ -487,6 +497,7 @@ namespace grapher.Models optionsSetY, directionalOptions, sensitivity, + yxRatio, rotation, lockXYLabel, accelCharts); diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 5c3494c..4946414 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -15,7 +15,8 @@ namespace grapher.Models.Options AccelOptionSet optionSetX, AccelOptionSet optionSetY, DirectionalityOptions directionalityOptions, - OptionXY sensitivity, + Option sensitivity, + LockableOption yxRatio, Option rotation, Label lockXYLabel, AccelCharts accelCharts) @@ -34,6 +35,7 @@ namespace grapher.Models.Options OptionSetX = optionSetX; OptionSetY = optionSetY; Sensitivity = sensitivity; + YToXRatio = yxRatio; Rotation = rotation; LockXYLabel = lockXYLabel; AccelCharts = accelCharts; @@ -44,7 +46,8 @@ namespace grapher.Models.Options ByComponentVectorXYLock.CheckedChanged += new System.EventHandler(OnByComponentXYLockChecked); ByComponentVectorXYLock.Checked = true; - Rotation.SnapTo(Sensitivity); + YToXRatio.SnapTo(Sensitivity); + Rotation.SnapTo(YToXRatio); EnableWholeApplication(); } @@ -67,7 +70,7 @@ namespace grapher.Models.Options public Option Sensitivity { get; } - public Option YToXRatio { get; } + public LockableOption YToXRatio { get; } public Option Rotation { get; } @@ -213,8 +216,8 @@ namespace grapher.Models.Options LockXYLabel.Width = (AccelCharts.Left - OptionSetX.ActiveValuesTitle.Left) / 2; OptionSetX.ActiveValuesTitle.Width = LockXYLabel.Width; LockXYLabel.Left = OptionSetX.ActiveValuesTitle.Left + OptionSetX.ActiveValuesTitle.Width; - Sensitivity.Fields.LockCheckBox.Left = LockXYLabel.Left + LockXYLabel.Width / 2 - Sensitivity.Fields.LockCheckBox.Width / 2; - ByComponentVectorXYLock.Left = Sensitivity.Fields.LockCheckBox.Left; + YToXRatio.LockBox.Left = LockXYLabel.Left + LockXYLabel.Width / 2 - YToXRatio.LockBox.Width / 2; + ByComponentVectorXYLock.Left = YToXRatio.LockBox.Left; AlignActiveValues(); } diff --git a/grapher/Models/Options/LockableOption.cs b/grapher/Models/Options/LockableOption.cs index bf77520..6e78783 100644 --- a/grapher/Models/Options/LockableOption.cs +++ b/grapher/Models/Options/LockableOption.cs @@ -20,6 +20,12 @@ namespace grapher.Models.Options Option = option; LockBox = checkBox; LockedValue = lockedvalue; + + LockBox.Click += OnLockedBoxClicked; + LockBox.AutoCheck = false; + + Option.Field.SetNewDefault(LockedValue); + SetLocked(); } public Option Option { get; } @@ -69,6 +75,25 @@ namespace grapher.Models.Options get => Option.Visible; } + public double Value + { + get => LockBox.Checked ? LockedValue : Option.Field.Data; + } + + public void SetActiveValue(double activeValue) + { + Option.SetActiveValue(activeValue); + + if (activeValue == LockedValue) + { + SetLocked(); + } + else + { + SetUnlocked(); + } + } + public override void AlignActiveValues() { Option.AlignActiveValues(); @@ -85,5 +110,28 @@ namespace grapher.Models.Options Option.Show(Name); LockBox.Show(); } + private void SetLocked() + { + LockBox.Checked = true; + Option.Field.SetToUnavailable(); + } + + private void SetUnlocked() + { + LockBox.Checked = false; + Option.Field.SetToDefault(); + } + + private void OnLockedBoxClicked(object sender, EventArgs e) + { + if (LockBox.Checked) + { + SetUnlocked(); + } + else + { + SetLocked(); + } + } } } -- cgit v1.2.3 From c0f2aa4a41de22936a5ed177c3b83792cc8231a8 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 13 Sep 2021 00:40:57 -0700 Subject: Most of Cap Type options in GUI --- grapher/Models/Options/Cap/CapOptions.cs | 147 ++++++++++++++++++++++++++ grapher/Models/Options/Cap/CapTypeOptions.cs | 93 ++++++++++++++++ grapher/Models/Options/ComboBoxOptionsBase.cs | 129 ++++++++++++++++++++++ grapher/Models/Options/LUT/LutApplyOptions.cs | 138 ++++++------------------ 4 files changed, 401 insertions(+), 106 deletions(-) create mode 100644 grapher/Models/Options/Cap/CapOptions.cs create mode 100644 grapher/Models/Options/Cap/CapTypeOptions.cs create mode 100644 grapher/Models/Options/ComboBoxOptionsBase.cs (limited to 'grapher/Models') diff --git a/grapher/Models/Options/Cap/CapOptions.cs b/grapher/Models/Options/Cap/CapOptions.cs new file mode 100644 index 0000000..144cd79 --- /dev/null +++ b/grapher/Models/Options/Cap/CapOptions.cs @@ -0,0 +1,147 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.Cap +{ + public class CapOptions : OptionBase + { + public enum CapType + { + In, + Out, + Both, + } + + public CapOptions( + ComboBox capTypeDropDown, + Option capIn, + Option capOut, + Option slope) + { + CapTypeDropdown = capTypeDropDown; + In = capIn; + Out = capOut; + Slope = slope; + + SetupCapTypeDropdown(CapTypeDropdown); + CapTypeDropdown.SelectedItem = CapType.In; + } + + public ComboBox CapTypeDropdown { get; } + + public Option In { get; } + + public Option Out { get; } + + public Option Slope { get; } + + public CapType SelectedCapType { get; private set; } + + public override int Left + { + get => In.Left; + + set + { + In.Left = value; + Out.Left = value; + Slope.Left = value; + } + } + + public override int Top + { + get => CapTypeDropdown.Top; + set + { + CapTypeDropdown.Top = value; + Layout(); + } + } + + public override int Height + { + get => BottomElement.Top + BottomElement.Height - CapTypeDropdown.Top; + } + + public override int Width + { + get => CapTypeDropdown.Width; + + set + { + CapTypeDropdown.Width = value; + In.Width = value; + Out.Width = value; + Slope.Width = value; + } + } + + public override bool Visible + { + get => CapTypeDropdown.Visible; + } + + private Option BottomElement { get; set; } + + public void Layout() + { + Layout(CapTypeDropdown.Top + CapTypeDropdown.Height + Constants.OptionVerticalSeperation); + } + + private void Layout(int top) + { + switch (SelectedCapType) + { + case CapType.In: + Slope.Show(); + In.Show(); + Out.Hide(); + + Slope.Top = top; + In.SnapTo(Slope); + BottomElement = In; + break; + case CapType.Out: + Slope.Show(); + In.Hide(); + Out.Show(); + + Slope.Top = top; + In.SnapTo(Slope); + BottomElement = In; + break; + case CapType.Both: + Slope.Hide(); + In.Show(); + Out.Show(); + + In.Top = top; + Out.SnapTo(In); + BottomElement = Out; + break; + } + } + + private void FindSelectedTypeFromDropdown() + { + SelectedCapType = (CapType)CapTypeDropdown.SelectedItem; + } + + private void OnCapTypeDropdownSelectedItemChanged(object sender, EventArgs e) + { + FindSelectedTypeFromDropdown(); + Layout(); + } + + private void SetupCapTypeDropdown(ComboBox capTypeDropDown) + { + capTypeDropDown.Items.Clear(); + capTypeDropDown.DataSource = Enum.GetValues(typeof(CapType)); + } + } +} diff --git a/grapher/Models/Options/Cap/CapTypeOptions.cs b/grapher/Models/Options/Cap/CapTypeOptions.cs new file mode 100644 index 0000000..b2cca57 --- /dev/null +++ b/grapher/Models/Options/Cap/CapTypeOptions.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.Cap +{ + public class CapTypeOptions : ComboBoxOptionsBase + { + #region Enum + + public enum CapType + { + In, + Out, + Both, + } + + #endregion Enum + + #region Classes + + public class CapTypeOption + { + public CapType Type { get; set; } + + public string Name => Type.ToString(); + + public override string ToString() => Name; + } + + #endregion Classes + + #region Static + + public static readonly CapTypeOption InCap = new CapTypeOption + { + Type = CapType.In, + }; + + public static readonly CapTypeOption OutCap = new CapTypeOption + { + Type = CapType.Out, + }; + + public static readonly CapTypeOption BothCap = new CapTypeOption + { + Type = CapType.Both, + }; + + public static readonly CapTypeOption[] AllCapTypeOptions = new CapTypeOption[] + { + InCap, + OutCap, + BothCap + }; + + #endregion Static + + #region Constructors + + public CapTypeOptions( + Label label, + ComboBox dropdown, + ActiveValueLabel activeValueLabel) + : base( + label, + dropdown, + activeValueLabel) + { + } + + #endregion Constructors + + #region Properties + + CapTypeOption CapOption + { + get + { + return OptionsDropdown.SelectedItem as CapTypeOption; + } + set + { + OptionsDropdown.SelectedItem = value; + } + } + + #endregion Properties + } +} diff --git a/grapher/Models/Options/ComboBoxOptionsBase.cs b/grapher/Models/Options/ComboBoxOptionsBase.cs new file mode 100644 index 0000000..64e0092 --- /dev/null +++ b/grapher/Models/Options/ComboBoxOptionsBase.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public abstract class ComboBoxOptionsBase : OptionBase + { + #region Constructors + + public ComboBoxOptionsBase( + Label label, + ComboBox dropdown, + ActiveValueLabel activeValueLabel) + { + OptionsDropdown = dropdown; + OptionsDropdown.Items.Clear(); + + Label = label; + Label.AutoSize = false; + Label.Width = 50; + + ActiveValueLabel = activeValueLabel; + } + + #endregion Constructors + + #region Properties + + public Label Label { get; } + + public ActiveValueLabel ActiveValueLabel { get; } + + public ComboBox OptionsDropdown { get; } + + public override bool Visible + { + get + { + return Label.Visible || ShouldShow; + } + } + + public override int Left + { + get + { + return Label.Left; + } + set + { + Label.Left = value; + OptionsDropdown.Left = Label.Left + Label.Width + Constants.OptionVerticalSeperation; + } + } + + public override int Height + { + get + { + return Label.Height; + } + } + + public override int Top + { + get + { + return Label.Top; + } + set + { + OptionsDropdown.Top = value; + Label.Top = (OptionsDropdown.Height - Label.Height) / 2 + OptionsDropdown.Top; + ActiveValueLabel.Top = value; + } + } + + public override int Width + { + get + { + return Label.Width; + } + set + { + OptionsDropdown.Width = value - Label.Width - Constants.OptionLabelBoxSeperation; + } + } + + protected bool ShouldShow { get; set; } + + #endregion Properties + + #region Methods + + public override void Hide() + { + Label.Hide(); + OptionsDropdown.Hide(); + ActiveValueLabel.Hide(); + ShouldShow = false; + } + + public override void Show(string labelText) + { + Label.Show(); + + if (!string.IsNullOrWhiteSpace(labelText)) + { + Label.Text = labelText; + } + + OptionsDropdown.Show(); + ActiveValueLabel.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + ActiveValueLabel.Align(); + } + + #endregion Methods + } +} diff --git a/grapher/Models/Options/LUT/LutApplyOptions.cs b/grapher/Models/Options/LUT/LutApplyOptions.cs index 7d8c737..61cae61 100644 --- a/grapher/Models/Options/LUT/LutApplyOptions.cs +++ b/grapher/Models/Options/LUT/LutApplyOptions.cs @@ -7,10 +7,9 @@ using System.Windows.Forms; namespace grapher.Models.Options.LUT { - public class LutApplyOptions : OptionBase + public class LutApplyOptions : ComboBoxOptionsBase { - public const string LUTApplyOptionsLabelText = "Apply as:"; - public const int LUTApplyLabelDropdownSeparation = 4; + #region Enum public enum LutApplyType { @@ -18,6 +17,10 @@ namespace grapher.Models.Options.LUT Velocity } + #endregion Enum + + #region Classes + public class LutApplyOption { public LutApplyType Type { get; set; } @@ -27,6 +30,10 @@ namespace grapher.Models.Options.LUT public override string ToString() => Name; } + #endregion Classes + + #region Static + public static readonly LutApplyOption Sensitivity = new LutApplyOption { Type = LutApplyType.Sensitivity, @@ -37,129 +44,58 @@ namespace grapher.Models.Options.LUT Type = LutApplyType.Velocity, }; + #endregion Static + + #region Constructors + public LutApplyOptions( Label label, ComboBox applyOptionsDropdown, ActiveValueLabel lutApplyActiveValue) + : base( + label, + applyOptionsDropdown, + lutApplyActiveValue) { - ApplyOptions = applyOptionsDropdown; - ApplyOptions.Items.Clear(); - ApplyOptions.Items.AddRange( + OptionsDropdown.Items.AddRange( new LutApplyOption[] { Sensitivity, Velocity, }); + } - Label = label; - Label.Text = LUTApplyOptionsLabelText; - Label.AutoSize = false; - Label.Width = 50; + #endregion Constructors - ActiveValueLabel = lutApplyActiveValue; - } + #region Properties public LutApplyType ApplyType { get => ApplyOption.Type; } public LutApplyOption ApplyOption { get { - return ApplyOptions.SelectedItem as LutApplyOption; - } - set - { - ApplyOptions.SelectedItem = value; - } - } - - public Label Label { get; } - - public ActiveValueLabel ActiveValueLabel { get; } - - public ComboBox ApplyOptions { get; } - - public override bool Visible - { - get - { - return Label.Visible || ShouldShow; - } - } - - public override int Left - { - get - { - return Label.Left; + return OptionsDropdown.SelectedItem as LutApplyOption; } set { - Label.Left = value; - ApplyOptions.Left = Label.Left + Label.Width + LUTApplyLabelDropdownSeparation; + OptionsDropdown.SelectedItem = value; } } - public override int Height - { - get - { - return Label.Height; - } - } + #endregion Properties - public override int Top - { - get - { - return Label.Top; - } - set - { - ApplyOptions.Top = value; - Label.Top = (ApplyOptions.Height - Label.Height) / 2 + ApplyOptions.Top; - ActiveValueLabel.Top = value; - } - } + #region Methods - public override int Width + public static LutApplyOption ApplyOptionFromSettings(bool applyAsVelocity) { - get - { - return Label.Width; - } - set + if (applyAsVelocity) { - ApplyOptions.Width = value - Label.Width - Constants.OptionLabelBoxSeperation; + return Velocity; } - } - - private bool ShouldShow { get; set; } - - public override void Hide() - { - Label.Hide(); - ApplyOptions.Hide(); - ActiveValueLabel.Hide(); - ShouldShow = false; - } - - public override void Show(string labelText) - { - Label.Show(); - - if (!string.IsNullOrWhiteSpace(labelText)) + else { - Label.Text = labelText; + return Sensitivity; } - - ApplyOptions.Show(); - ActiveValueLabel.Show(); - ShouldShow = true; - } - - public override void AlignActiveValues() - { - ActiveValueLabel.Align(); } public void SetActiveValue(bool applyAsVelocity) @@ -168,16 +104,6 @@ namespace grapher.Models.Options.LUT ActiveValueLabel.SetValue(ApplyOption.Name); } - public LutApplyOption ApplyOptionFromSettings(bool applyAsVelocity) - { - if (applyAsVelocity) - { - return Velocity; - } - else - { - return Sensitivity; - } - } + #endregion Methods } } -- cgit v1.2.3 From 41c79072e5713ab8750f058b6de0623b3b17f366 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 13 Sep 2021 01:02:57 -0700 Subject: Some reorganizing --- grapher/Models/Options/Cap/CapOptions.cs | 44 +++++++++------------------- grapher/Models/Options/Cap/CapTypeOptions.cs | 43 +++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 35 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/Cap/CapOptions.cs b/grapher/Models/Options/Cap/CapOptions.cs index 144cd79..2fe44b0 100644 --- a/grapher/Models/Options/Cap/CapOptions.cs +++ b/grapher/Models/Options/Cap/CapOptions.cs @@ -4,34 +4,26 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static grapher.Models.Options.Cap.CapTypeOptions; namespace grapher.Models.Options.Cap { public class CapOptions : OptionBase { - public enum CapType - { - In, - Out, - Both, - } public CapOptions( - ComboBox capTypeDropDown, + CapTypeOptions capTypeOptions, Option capIn, Option capOut, Option slope) { - CapTypeDropdown = capTypeDropDown; + CapTypeOptions = capTypeOptions; In = capIn; Out = capOut; Slope = slope; - - SetupCapTypeDropdown(CapTypeDropdown); - CapTypeDropdown.SelectedItem = CapType.In; } - public ComboBox CapTypeDropdown { get; } + public CapTypeOptions CapTypeOptions { get; } public Option In { get; } @@ -39,8 +31,6 @@ namespace grapher.Models.Options.Cap public Option Slope { get; } - public CapType SelectedCapType { get; private set; } - public override int Left { get => In.Left; @@ -55,26 +45,26 @@ namespace grapher.Models.Options.Cap public override int Top { - get => CapTypeDropdown.Top; + get => CapTypeOptions.Top; set { - CapTypeDropdown.Top = value; + CapTypeOptions.Top = value; Layout(); } } public override int Height { - get => BottomElement.Top + BottomElement.Height - CapTypeDropdown.Top; + get => BottomElement.Top + BottomElement.Height - CapTypeOptions.Top; } public override int Width { - get => CapTypeDropdown.Width; + get => CapTypeOptions.Width; set { - CapTypeDropdown.Width = value; + CapTypeOptions.Width = value; In.Width = value; Out.Width = value; Slope.Width = value; @@ -83,21 +73,21 @@ namespace grapher.Models.Options.Cap public override bool Visible { - get => CapTypeDropdown.Visible; + get => CapTypeOptions.Visible; } private Option BottomElement { get; set; } public void Layout() { - Layout(CapTypeDropdown.Top + CapTypeDropdown.Height + Constants.OptionVerticalSeperation); + Layout(CapTypeOptions.Top + CapTypeOptions.Height + Constants.OptionVerticalSeperation); } private void Layout(int top) { - switch (SelectedCapType) + switch (CapTypeOptions.SelectedCapType) { - case CapType.In: + case CapType.Input: Slope.Show(); In.Show(); Out.Hide(); @@ -106,7 +96,7 @@ namespace grapher.Models.Options.Cap In.SnapTo(Slope); BottomElement = In; break; - case CapType.Out: + case CapType.Output: Slope.Show(); In.Hide(); Out.Show(); @@ -127,14 +117,8 @@ namespace grapher.Models.Options.Cap } } - private void FindSelectedTypeFromDropdown() - { - SelectedCapType = (CapType)CapTypeDropdown.SelectedItem; - } - private void OnCapTypeDropdownSelectedItemChanged(object sender, EventArgs e) { - FindSelectedTypeFromDropdown(); Layout(); } diff --git a/grapher/Models/Options/Cap/CapTypeOptions.cs b/grapher/Models/Options/Cap/CapTypeOptions.cs index b2cca57..4ea372b 100644 --- a/grapher/Models/Options/Cap/CapTypeOptions.cs +++ b/grapher/Models/Options/Cap/CapTypeOptions.cs @@ -13,8 +13,8 @@ namespace grapher.Models.Options.Cap public enum CapType { - In, - Out, + Input, + Output, Both, } @@ -37,12 +37,12 @@ namespace grapher.Models.Options.Cap public static readonly CapTypeOption InCap = new CapTypeOption { - Type = CapType.In, + Type = CapType.Input, }; public static readonly CapTypeOption OutCap = new CapTypeOption { - Type = CapType.Out, + Type = CapType.Output, }; public static readonly CapTypeOption BothCap = new CapTypeOption @@ -70,13 +70,22 @@ namespace grapher.Models.Options.Cap dropdown, activeValueLabel) { + OptionsDropdown.Items.AddRange( + new CapTypeOption[] + { + InCap, + OutCap, + BothCap + }); } #endregion Constructors #region Properties - CapTypeOption CapOption + public CapType SelectedCapType => SelectedCapOption.Type; + + public CapTypeOption SelectedCapOption { get { @@ -89,5 +98,29 @@ namespace grapher.Models.Options.Cap } #endregion Properties + + #region Methods + + public static CapTypeOption CapTypeOptionFromSettings(ClassicCapMode capMode) + { + switch (capMode) + { + case ClassicCapMode.output: + return OutCap; + case ClassicCapMode.in_out: + return BothCap; + case ClassicCapMode.input: + default: + return InCap; + } + } + + public void SetActiveValue(ClassicCapMode capMode) + { + SelectedCapOption = CapTypeOptionFromSettings(capMode); + ActiveValueLabel.SetValue(SelectedCapOption.Name); + } + + #endregion Methods } } -- cgit v1.2.3 From 6c037f92a350d8622f3739b1033c909912860d77 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 14 Sep 2021 00:55:21 -0700 Subject: Mostly working cap type in GUI --- grapher/Models/AccelGUIFactory.cs | 123 ++++++++++++++++++++------- grapher/Models/Options/AccelTypeOptions.cs | 75 +++++++++------- grapher/Models/Options/Cap/CapOptions.cs | 107 +++++++++++++++++------ grapher/Models/Options/Cap/CapTypeOptions.cs | 11 +++ 4 files changed, 230 insertions(+), 86 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 20040fb..156606e 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -2,6 +2,7 @@ using grapher.Models.Devices; using grapher.Models.Mouse; using grapher.Models.Options; +using grapher.Models.Options.Cap; using grapher.Models.Options.Directionality; using grapher.Models.Options.LUT; using grapher.Models.Serialized; @@ -27,6 +28,8 @@ namespace grapher.Models ComboBox accelTypeDropY, ComboBox lutApplyDropdownX, ComboBox lutApplyDropdownY, + ComboBox capTypeDropdownX, + ComboBox capTypeDropdownY, Button writeButton, ButtonBase toggleButton, ToolStripMenuItem showVelocityGainToolStripMenuItem, @@ -43,8 +46,10 @@ namespace grapher.Models TextBox rotationBox, TextBox weightBoxX, TextBox weightBoxY, - TextBox capBoxX, - TextBox capBoxY, + TextBox inCapBoxX, + TextBox inCapBoxY, + TextBox outCapBoxX, + TextBox outCapBoxY, TextBox offsetBoxX, TextBox offsetBoxY, TextBox accelerationBoxX, @@ -87,8 +92,12 @@ namespace grapher.Models Label rotationLabel, Label weightLabelX, Label weightLabelY, - Label capLabelX, - Label capLabelY, + Label inCapLabelX, + Label inCapLabelY, + Label outCapLabelX, + Label outCapLabelY, + Label capTypeLabelX, + Label capTypeLabelY, Label offsetLabelX, Label offsetLabelY, Label constantOneLabelX, @@ -118,8 +127,12 @@ namespace grapher.Models Label rotationActiveLabel, Label weightActiveXLabel, Label weightActiveYLabel, - Label capActiveXLabel, - Label capActiveYLabel, + Label inCapActiveXLabel, + Label inCapActiveYLabel, + Label outCapActiveXLabel, + Label outCapActiveYLabel, + Label capTypeActiveXLabel, + Label capTypeActiveYLabel, Label offsetActiveLabelX, Label offsetActiveLabelY, Label accelerationActiveLabelX, @@ -234,24 +247,6 @@ namespace grapher.Models new ActiveValueLabel(weightActiveYLabel, activeValueTitleY), "Weight"); - var capX = new Option( - capBoxX, - form, - 0, - capLabelX, - 0, - new ActiveValueLabel(capActiveXLabel, activeValueTitleX), - "Cap"); - - var capY = new Option( - capBoxY, - form, - 0, - capLabelY, - optionSetYLeft, - new ActiveValueLabel(capActiveYLabel, activeValueTitleY), - "Cap"); - var offsetX = new Option( offsetBoxX, form, @@ -378,6 +373,76 @@ namespace grapher.Models new ActiveValueLabel(midpointActiveLabelY, activeValueTitleY), optionSetYLeft); + var inCapX = new Option( + inCapBoxX, + form, + 0, + inCapLabelX, + 0, + new ActiveValueLabel(inCapActiveXLabel, activeValueTitleX), + "Cap: Input"); + + var inCapY = new Option( + inCapBoxY, + form, + 0, + inCapLabelY, + optionSetYLeft, + new ActiveValueLabel(inCapActiveYLabel, activeValueTitleY), + "Cap"); + + var outCapX = new Option( + outCapBoxX, + form, + 0, + outCapLabelX, + 0, + new ActiveValueLabel(outCapActiveXLabel, activeValueTitleX), + "Cap: Input"); + + var outCapY = new Option( + outCapBoxY, + form, + 0, + outCapLabelY, + optionSetYLeft, + new ActiveValueLabel(outCapActiveYLabel, activeValueTitleY), + "Cap"); + + var capTypeX = new CapTypeOptions( + capTypeLabelX, + capTypeDropdownX, + new ActiveValueLabel(capTypeActiveXLabel, activeValueTitleX)); + + var capTypeY = new CapTypeOptions( + capTypeLabelY, + capTypeDropdownY, + new ActiveValueLabel(capTypeActiveYLabel, activeValueTitleY)); + + var accelCapOptionsX = new CapOptions( + capTypeX, + inCapX, + outCapX, + accelerationX); + + var accelCapOptionsY = new CapOptions( + capTypeY, + inCapY, + outCapY, + accelerationY); + + var powerCapOptionsX = new CapOptions( + capTypeX, + inCapX, + outCapX, + accelerationX); + + var powerCapOptionsY = new CapOptions( + capTypeY, + inCapY, + outCapY, + accelerationY); + var lpNorm = new Option( new Field(lpNormBox, form, 2), lpNormLabel, @@ -421,12 +486,11 @@ namespace grapher.Models var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, gainSwitchOptionX, - accelerationX, + accelCapOptionsX, + powerCapOptionsX, decayRateX, growthRateX, smoothX, - scaleX, - capX, weightX, offsetX, limitX, @@ -445,12 +509,11 @@ namespace grapher.Models var accelerationOptionsY = new AccelTypeOptions( accelTypeDropY, gainSwitchOptionY, - accelerationY, + accelCapOptionsY, + powerCapOptionsY, decayRateY, growthRateY, smoothY, - scaleY, - capY, weightY, offsetY, limitY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index eab38a1..9086b41 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -1,5 +1,6 @@ using grapher.Layouts; using grapher.Models.Options; +using grapher.Models.Options.Cap; using grapher.Models.Options.LUT; using grapher.Models.Serialized; using System; @@ -29,12 +30,11 @@ namespace grapher public AccelTypeOptions( ComboBox accelDropdown, CheckBoxOption gainSwitch, - Option acceleration, + CapOptions classicCap, + CapOptions powerCap, Option decayRate, Option growthRate, Option smooth, - Option scale, - Option cap, Option weight, Option offset, Option limit, @@ -65,12 +65,11 @@ namespace grapher AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); GainSwitch = gainSwitch; - Acceleration = acceleration; DecayRate = decayRate; GrowthRate = growthRate; Smooth = smooth; - Scale = scale; - Cap = cap; + ClassicCap = classicCap; + PowerCap = powerCap; Weight = weight; Offset = offset; Limit = limit; @@ -85,7 +84,7 @@ namespace grapher AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; AccelTypeActiveValue.Height = AccelDropdown.Height; - GainSwitch.Left = Acceleration.Field.Left; + GainSwitch.Left = DecayRate.Field.Left; LutPanel.Left = AccelDropdown.Left; LutPanel.Width = AccelDropdown.Width + AccelTypeActiveValue.Width; @@ -108,17 +107,15 @@ namespace grapher public ActiveValueLabel AccelTypeActiveValue { get; } - public Option Acceleration { get; } - public Option DecayRate { get; } public Option GrowthRate { get; } public Option Smooth { get; } - public Option Scale { get; } + public CapOptions ClassicCap { get; } - public Option Cap { get; } + public CapOptions PowerCap { get; } public Option Weight { get; } @@ -228,12 +225,11 @@ namespace grapher AccelTypeActiveValue.Hide(); GainSwitch.Hide(); - Acceleration.Hide(); DecayRate.Hide(); GrowthRate.Hide(); Smooth.Hide(); - Scale.Hide(); - Cap.Hide(); + ClassicCap.Hide(); + PowerCap.Hide(); Weight.Hide(); Offset.Hide(); Limit.Hide(); @@ -263,13 +259,20 @@ namespace grapher AccelTypeActiveValue.SetValue(AccelerationType.ActiveName); GainSwitch.SetActiveValue(args.gain); Weight.SetActiveValue(args.weight); - Cap.SetActiveValue(args.cap.x); + ClassicCap.SetActiveValues( + args.acceleration, + args.cap.x, + args.cap.y, + args.capMode); + PowerCap.SetActiveValues( + args.scale, + args.cap.x, + args.cap.y, + args.capMode); Offset.SetActiveValue(args.offset); - 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.exponentClassic); Exponent.SetActiveValue(args.exponentPower); @@ -286,8 +289,8 @@ namespace grapher AccelDropdown.Text = Constants.AccelDropDownDefaultFullText; } - Left = Acceleration.Left + Constants.DropDownLeftSeparation; - Width = Acceleration.Width - Constants.DropDownLeftSeparation; + Left = DecayRate.Left + Constants.DropDownLeftSeparation; + Width = DecayRate.Width - Constants.DropDownLeftSeparation; LutText.Expand(); HandleLUTOptionsOnResize(); @@ -300,8 +303,8 @@ namespace grapher AccelDropdown.Text = Constants.AccelDropDownDefaultShortText; } - Left = Acceleration.Field.Left; - Width = Acceleration.Field.Width; + Left = DecayRate.Field.Left; + Width = DecayRate.Field.Width; LutText.Shorten(); } @@ -311,13 +314,23 @@ namespace grapher args.mode = AccelerationType.Mode; args.gain = GainSwitch.CheckBox.Checked; - 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; - // TODO - make field for output and in_out cap - if (Cap.Visible) args.cap.x = Cap.Field.Data; + if (ClassicCap.Visible) + { + args.acceleration = ClassicCap.Slope.Field.Data; + args.cap.x = ClassicCap.In.Field.Data; + args.cap.y = ClassicCap.Out.Field.Data; + args.capMode = ClassicCap.CapTypeOptions.GetSelectedCapMode(); + } + if (PowerCap.Visible) + { + args.scale = ClassicCap.Slope.Field.Data; + args.cap.x = PowerCap.In.Field.Data; + args.cap.y = PowerCap.Out.Field.Data; + args.capMode = PowerCap.CapTypeOptions.GetSelectedCapMode(); + } if (Limit.Visible) { if (args.mode == AccelMode.motivity) @@ -354,12 +367,11 @@ namespace grapher { AccelTypeActiveValue.Align(); GainSwitch.AlignActiveValues(); - Acceleration.AlignActiveValues(); DecayRate.AlignActiveValues(); GrowthRate.AlignActiveValues(); Smooth.AlignActiveValues(); - Scale.AlignActiveValues(); - Cap.AlignActiveValues(); + ClassicCap.AlignActiveValues(); + PowerCap.AlignActiveValues(); Offset.AlignActiveValues(); Weight.AlignActiveValues(); Limit.AlignActiveValues(); @@ -373,7 +385,7 @@ namespace grapher { LutText.Left = AccelDropdown.Left; LutPanel.Left = GainSwitch.Left - 100; - LutPanel.Width = Acceleration.ActiveValueLabel.CenteringLabel.Right - LutPanel.Left; + LutPanel.Width = DecayRate.ActiveValueLabel.CenteringLabel.Right - LutPanel.Left; LutApply.Left = LutPanel.Left; LutApply.Width = AccelDropdown.Right - LutPanel.Left; } @@ -393,12 +405,11 @@ namespace grapher AccelerationType.Layout( GainSwitch, - Acceleration, + ClassicCap, + PowerCap, DecayRate, GrowthRate, Smooth, - Scale, - Cap, Weight, Offset, Limit, diff --git a/grapher/Models/Options/Cap/CapOptions.cs b/grapher/Models/Options/Cap/CapOptions.cs index 2fe44b0..e959dee 100644 --- a/grapher/Models/Options/Cap/CapOptions.cs +++ b/grapher/Models/Options/Cap/CapOptions.cs @@ -21,6 +21,11 @@ namespace grapher.Models.Options.Cap In = capIn; Out = capOut; Slope = slope; + + ShouldShow = true; + TopElement = Slope; + BottomElement = In; + CapTypeOptions.OptionsDropdown.SelectedIndexChanged += OnCapTypeDropdownSelectedItemChanged; } public CapTypeOptions CapTypeOptions { get; } @@ -45,17 +50,16 @@ namespace grapher.Models.Options.Cap public override int Top { - get => CapTypeOptions.Top; + get => TopElement.Top; set { - CapTypeOptions.Top = value; - Layout(); + Layout(value); } } public override int Height { - get => BottomElement.Top + BottomElement.Height - CapTypeOptions.Top; + get => BottomElement.Top + BottomElement.Height - TopElement.Top; } public override int Width @@ -73,45 +77,100 @@ namespace grapher.Models.Options.Cap public override bool Visible { - get => CapTypeOptions.Visible; + get => ShouldShow; + } + + private bool ShouldShow { get; set; } + + private IOption BottomElement { get; set; } + + private IOption TopElement { get; set; } + + public override void AlignActiveValues() + { + Slope.AlignActiveValues(); + CapTypeOptions.AlignActiveValues(); + In.AlignActiveValues(); + Out.AlignActiveValues(); + } + + public override void Show(string name) + { + ShouldShow = true; + Layout(Top, name); } - private Option BottomElement { get; set; } + public override void Hide() + { + ShouldShow = false; + CapTypeOptions.Hide(); + Slope.Hide(); + In.Hide(); + Out.Hide(); + } - public void Layout() + public void SetActiveValues( + double scale, + double inCap, + double outCap, + ClassicCapMode capMode) { - Layout(CapTypeOptions.Top + CapTypeOptions.Height + Constants.OptionVerticalSeperation); + Slope.SetActiveValue(scale); + In.SetActiveValue(inCap); + Out.SetActiveValue(outCap); + CapTypeOptions.SetActiveValue(capMode); } - private void Layout(int top) + private void Layout(int top, string name = null) { switch (CapTypeOptions.SelectedCapType) { case CapType.Input: - Slope.Show(); - In.Show(); - Out.Hide(); + if (ShouldShow) + { + Slope.Show(); + CapTypeOptions.Show(name); + In.Show(); + Out.Hide(); + } Slope.Top = top; - In.SnapTo(Slope); + CapTypeOptions.SnapTo(Slope); + In.SnapTo(CapTypeOptions); + + TopElement = CapTypeOptions; BottomElement = In; break; case CapType.Output: - Slope.Show(); - In.Hide(); - Out.Show(); + if (ShouldShow) + { + Slope.Show(); + CapTypeOptions.Show(name); + In.Hide(); + Out.Show(); + } Slope.Top = top; - In.SnapTo(Slope); - BottomElement = In; + CapTypeOptions.SnapTo(Slope); + Out.SnapTo(CapTypeOptions); + + TopElement = CapTypeOptions; + BottomElement = Out; break; case CapType.Both: - Slope.Hide(); - In.Show(); - Out.Show(); - - In.Top = top; + if (ShouldShow) + { + CapTypeOptions.Show(name); + Slope.Hide(); + In.Show(); + Out.Show(); + } + + CapTypeOptions.Top = top; + In.SnapTo(CapTypeOptions); Out.SnapTo(In); + + TopElement = In; BottomElement = Out; break; } @@ -119,7 +178,7 @@ namespace grapher.Models.Options.Cap private void OnCapTypeDropdownSelectedItemChanged(object sender, EventArgs e) { - Layout(); + Layout(Top); } private void SetupCapTypeDropdown(ComboBox capTypeDropDown) diff --git a/grapher/Models/Options/Cap/CapTypeOptions.cs b/grapher/Models/Options/Cap/CapTypeOptions.cs index 4ea372b..f0c5617 100644 --- a/grapher/Models/Options/Cap/CapTypeOptions.cs +++ b/grapher/Models/Options/Cap/CapTypeOptions.cs @@ -97,6 +97,17 @@ namespace grapher.Models.Options.Cap } } + public ClassicCapMode GetSelectedCapMode() + { + switch(SelectedCapType) + { + case CapType.Output: return ClassicCapMode.output; + case CapType.Both: return ClassicCapMode.in_out; + case CapType.Input: + default: return ClassicCapMode.input; + } + } + #endregion Properties #region Methods -- cgit v1.2.3 From 8878091a2cab77b0433daea7a47033e1c35e42c1 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 15 Sep 2021 23:16:43 -0700 Subject: Cap type options now fully working --- grapher/Models/AccelGUIFactory.cs | 188 ++++++++++++++++++-------- grapher/Models/Options/AccelTypeOptions.cs | 3 - grapher/Models/Options/Cap/CapOptions.cs | 62 ++++++--- grapher/Models/Options/Cap/CapTypeOptions.cs | 27 +++- grapher/Models/Options/ComboBoxOptionsBase.cs | 11 +- 5 files changed, 198 insertions(+), 93 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 156606e..4d0a483 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -28,8 +28,10 @@ namespace grapher.Models ComboBox accelTypeDropY, ComboBox lutApplyDropdownX, ComboBox lutApplyDropdownY, - ComboBox capTypeDropdownX, - ComboBox capTypeDropdownY, + ComboBox capTypeDropdownXClassic, + ComboBox capTypeDropdownYClassic, + ComboBox capTypeDropdownXPower, + ComboBox capTypeDropdownYPower, Button writeButton, ButtonBase toggleButton, ToolStripMenuItem showVelocityGainToolStripMenuItem, @@ -46,10 +48,14 @@ namespace grapher.Models TextBox rotationBox, TextBox weightBoxX, TextBox weightBoxY, - TextBox inCapBoxX, - TextBox inCapBoxY, - TextBox outCapBoxX, - TextBox outCapBoxY, + TextBox inCapBoxXClassic, + TextBox inCapBoxYClassic, + TextBox outCapBoxXClassic, + TextBox outCapBoxYClassic, + TextBox inCapBoxXPower, + TextBox inCapBoxYPower, + TextBox outCapBoxXPower, + TextBox outCapBoxYPower, TextBox offsetBoxX, TextBox offsetBoxY, TextBox accelerationBoxX, @@ -92,12 +98,18 @@ namespace grapher.Models Label rotationLabel, Label weightLabelX, Label weightLabelY, - Label inCapLabelX, - Label inCapLabelY, - Label outCapLabelX, - Label outCapLabelY, - Label capTypeLabelX, - Label capTypeLabelY, + Label inCapLabelXClassic, + Label inCapLabelYClassic, + Label outCapLabelXClassic, + Label outCapLabelYClassic, + Label capTypeLabelXClassic, + Label capTypeLabelYClassic, + Label inCapLabelXPower, + Label inCapLabelYPower, + Label outCapLabelXPower, + Label outCapLabelYPower, + Label capTypeLabelXPower, + Label capTypeLabelYPower, Label offsetLabelX, Label offsetLabelY, Label constantOneLabelX, @@ -127,12 +139,18 @@ namespace grapher.Models Label rotationActiveLabel, Label weightActiveXLabel, Label weightActiveYLabel, - Label inCapActiveXLabel, - Label inCapActiveYLabel, - Label outCapActiveXLabel, - Label outCapActiveYLabel, - Label capTypeActiveXLabel, - Label capTypeActiveYLabel, + Label inCapActiveXLabelClassic, + Label inCapActiveYLabelClassic, + Label outCapActiveXLabelClassic, + Label outCapActiveYLabelClassic, + Label capTypeActiveXLabelClassic, + Label capTypeActiveYLabelClassic, + Label inCapActiveXLabelPower, + Label inCapActiveYLabelPower, + Label outCapActiveXLabelPower, + Label outCapActiveYLabelPower, + Label capTypeActiveXLabelPower, + Label capTypeActiveYLabelPower, Label offsetActiveLabelX, Label offsetActiveLabelY, Label accelerationActiveLabelX, @@ -373,75 +391,125 @@ namespace grapher.Models new ActiveValueLabel(midpointActiveLabelY, activeValueTitleY), optionSetYLeft); - var inCapX = new Option( - inCapBoxX, + var inCapXClassic = new Option( + inCapBoxXClassic, form, 0, - inCapLabelX, + inCapLabelXClassic, 0, - new ActiveValueLabel(inCapActiveXLabel, activeValueTitleX), + new ActiveValueLabel(inCapActiveXLabelClassic, activeValueTitleX), "Cap: Input"); - var inCapY = new Option( - inCapBoxY, + var inCapYClassic = new Option( + inCapBoxYClassic, form, 0, - inCapLabelY, + inCapLabelYClassic, optionSetYLeft, - new ActiveValueLabel(inCapActiveYLabel, activeValueTitleY), + new ActiveValueLabel(inCapActiveYLabelClassic, activeValueTitleY), "Cap"); - var outCapX = new Option( - outCapBoxX, + var outCapXClassic = new Option( + outCapBoxXClassic, form, 0, - outCapLabelX, + outCapLabelXClassic, 0, - new ActiveValueLabel(outCapActiveXLabel, activeValueTitleX), + new ActiveValueLabel(outCapActiveXLabelClassic, activeValueTitleX), "Cap: Input"); - var outCapY = new Option( - outCapBoxY, + var outCapYClassic = new Option( + outCapBoxYClassic, form, 0, - outCapLabelY, + outCapLabelYClassic, optionSetYLeft, - new ActiveValueLabel(outCapActiveYLabel, activeValueTitleY), + new ActiveValueLabel(outCapActiveYLabelClassic, activeValueTitleY), "Cap"); - var capTypeX = new CapTypeOptions( - capTypeLabelX, - capTypeDropdownX, - new ActiveValueLabel(capTypeActiveXLabel, activeValueTitleX)); + var capTypeXClassic = new CapTypeOptions( + capTypeLabelXClassic, + capTypeDropdownXClassic, + new ActiveValueLabel(capTypeActiveXLabelClassic, activeValueTitleX), + 0); - var capTypeY = new CapTypeOptions( - capTypeLabelY, - capTypeDropdownY, - new ActiveValueLabel(capTypeActiveYLabel, activeValueTitleY)); + var capTypeYClassic = new CapTypeOptions( + capTypeLabelYClassic, + capTypeDropdownYClassic, + new ActiveValueLabel(capTypeActiveYLabelClassic, activeValueTitleY), + optionSetYLeft); - var accelCapOptionsX = new CapOptions( - capTypeX, - inCapX, - outCapX, + var classicCapOptionsX = new CapOptions( + capTypeXClassic, + inCapXClassic, + outCapXClassic, accelerationX); - var accelCapOptionsY = new CapOptions( - capTypeY, - inCapY, - outCapY, + var classicCapOptionsY = new CapOptions( + capTypeYClassic, + inCapYClassic, + outCapYClassic, accelerationY); + var inCapXPower = new Option( + inCapBoxXPower, + form, + 0, + inCapLabelXPower, + 0, + new ActiveValueLabel(inCapActiveXLabelPower, activeValueTitleX), + "Cap: Input"); + + var inCapYPower = new Option( + inCapBoxYPower, + form, + 0, + inCapLabelYPower, + optionSetYLeft, + new ActiveValueLabel(inCapActiveYLabelPower, activeValueTitleY), + "Cap"); + + var outCapXPower = new Option( + outCapBoxXPower, + form, + 0, + outCapLabelXPower, + 0, + new ActiveValueLabel(outCapActiveXLabelPower, activeValueTitleX), + "Cap: Input"); + + var outCapYPower = new Option( + outCapBoxYPower, + form, + 0, + outCapLabelYPower, + optionSetYLeft, + new ActiveValueLabel(outCapActiveYLabelPower, activeValueTitleY), + "Cap"); + + var capTypeXPower = new CapTypeOptions( + capTypeLabelXPower, + capTypeDropdownXPower, + new ActiveValueLabel(capTypeActiveXLabelPower, activeValueTitleX), + 0); + + var capTypeYPower = new CapTypeOptions( + capTypeLabelYPower, + capTypeDropdownYPower, + new ActiveValueLabel(capTypeActiveYLabelPower, activeValueTitleY), + optionSetYLeft); + var powerCapOptionsX = new CapOptions( - capTypeX, - inCapX, - outCapX, - accelerationX); + capTypeXPower, + inCapXPower, + outCapXPower, + scaleX); var powerCapOptionsY = new CapOptions( - capTypeY, - inCapY, - outCapY, - accelerationY); + capTypeYPower, + inCapYPower, + outCapYPower, + scaleY); var lpNorm = new Option( new Field(lpNormBox, form, 2), @@ -486,7 +554,7 @@ namespace grapher.Models var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, gainSwitchOptionX, - accelCapOptionsX, + classicCapOptionsX, powerCapOptionsX, decayRateX, growthRateX, @@ -509,7 +577,7 @@ namespace grapher.Models var accelerationOptionsY = new AccelTypeOptions( accelTypeDropY, gainSwitchOptionY, - accelCapOptionsY, + classicCapOptionsY, powerCapOptionsY, decayRateY, growthRateY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 9086b41..3d2f840 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -2,10 +2,7 @@ using grapher.Models.Options; using grapher.Models.Options.Cap; using grapher.Models.Options.LUT; -using grapher.Models.Serialized; using System; -using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; namespace grapher diff --git a/grapher/Models/Options/Cap/CapOptions.cs b/grapher/Models/Options/Cap/CapOptions.cs index e959dee..ac34abf 100644 --- a/grapher/Models/Options/Cap/CapOptions.cs +++ b/grapher/Models/Options/Cap/CapOptions.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; using static grapher.Models.Options.Cap.CapTypeOptions; @@ -10,6 +6,20 @@ namespace grapher.Models.Options.Cap { public class CapOptions : OptionBase { + #region Constants + + public const string InCapLabel = "Cap: Input"; + public const string OutCapLabel = "Cap: Output"; + + #endregion Constants + + #region Fields + + private int _top; + + #endregion Fields + + #region Constructors public CapOptions( CapTypeOptions capTypeOptions, @@ -23,11 +33,16 @@ namespace grapher.Models.Options.Cap Slope = slope; ShouldShow = true; - TopElement = Slope; + _top = Slope.Top; BottomElement = In; CapTypeOptions.OptionsDropdown.SelectedIndexChanged += OnCapTypeDropdownSelectedItemChanged; + CapTypeOptions.SelectedCapOption = InCap; } + #endregion Constructors + + #region Properties + public CapTypeOptions CapTypeOptions { get; } public Option In { get; } @@ -50,16 +65,17 @@ namespace grapher.Models.Options.Cap public override int Top { - get => TopElement.Top; + get => _top; set { + _top = value; Layout(value); } } public override int Height { - get => BottomElement.Top + BottomElement.Height - TopElement.Top; + get => BottomElement.Top + BottomElement.Height - Top; } public override int Width @@ -84,7 +100,9 @@ namespace grapher.Models.Options.Cap private IOption BottomElement { get; set; } - private IOption TopElement { get; set; } + #endregion Properties + + #region Methods public override void AlignActiveValues() { @@ -130,7 +148,7 @@ namespace grapher.Models.Options.Cap { Slope.Show(); CapTypeOptions.Show(name); - In.Show(); + ShowInCap(); Out.Hide(); } @@ -138,7 +156,6 @@ namespace grapher.Models.Options.Cap CapTypeOptions.SnapTo(Slope); In.SnapTo(CapTypeOptions); - TopElement = CapTypeOptions; BottomElement = In; break; case CapType.Output: @@ -147,14 +164,13 @@ namespace grapher.Models.Options.Cap Slope.Show(); CapTypeOptions.Show(name); In.Hide(); - Out.Show(); + ShowOutCap(); } Slope.Top = top; CapTypeOptions.SnapTo(Slope); Out.SnapTo(CapTypeOptions); - TopElement = CapTypeOptions; BottomElement = Out; break; case CapType.Both: @@ -162,29 +178,35 @@ namespace grapher.Models.Options.Cap { CapTypeOptions.Show(name); Slope.Hide(); - In.Show(); - Out.Show(); + ShowInCap(); + ShowOutCap(); } CapTypeOptions.Top = top; In.SnapTo(CapTypeOptions); Out.SnapTo(In); - TopElement = In; BottomElement = Out; break; } } - private void OnCapTypeDropdownSelectedItemChanged(object sender, EventArgs e) + private void ShowInCap() { - Layout(Top); + In.Show(InCapLabel); + } + + private void ShowOutCap() + { + Out.Show(OutCapLabel); } - private void SetupCapTypeDropdown(ComboBox capTypeDropDown) + private void OnCapTypeDropdownSelectedItemChanged(object sender, EventArgs e) { - capTypeDropDown.Items.Clear(); - capTypeDropDown.DataSource = Enum.GetValues(typeof(CapType)); + Layout(Top); + CapTypeOptions.CheckIfDefault(); } + + #endregion Methods } } diff --git a/grapher/Models/Options/Cap/CapTypeOptions.cs b/grapher/Models/Options/Cap/CapTypeOptions.cs index f0c5617..1e7bd58 100644 --- a/grapher/Models/Options/Cap/CapTypeOptions.cs +++ b/grapher/Models/Options/Cap/CapTypeOptions.cs @@ -64,7 +64,8 @@ namespace grapher.Models.Options.Cap public CapTypeOptions( Label label, ComboBox dropdown, - ActiveValueLabel activeValueLabel) + ActiveValueLabel activeValueLabel, + int left) : base( label, dropdown, @@ -77,6 +78,13 @@ namespace grapher.Models.Options.Cap OutCap, BothCap }); + + Default = OutCap; + + label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + label.Left = left; + label.Width = OptionsDropdown.Left - left - Constants.OptionLabelBoxSeperation; + label.Height = OptionsDropdown.Height; } #endregion Constructors @@ -97,6 +105,8 @@ namespace grapher.Models.Options.Cap } } + private CapTypeOption Default { get; set; } + public ClassicCapMode GetSelectedCapMode() { switch(SelectedCapType) @@ -128,10 +138,23 @@ namespace grapher.Models.Options.Cap public void SetActiveValue(ClassicCapMode capMode) { - SelectedCapOption = CapTypeOptionFromSettings(capMode); + Default = CapTypeOptionFromSettings(capMode); + SelectedCapOption = Default; ActiveValueLabel.SetValue(SelectedCapOption.Name); } + public void CheckIfDefault() + { + if (SelectedCapOption.Equals(Default)) + { + OptionsDropdown.ForeColor = System.Drawing.Color.Gray; + } + else + { + OptionsDropdown.ForeColor = System.Drawing.Color.Black; + } + } + #endregion Methods } } diff --git a/grapher/Models/Options/ComboBoxOptionsBase.cs b/grapher/Models/Options/ComboBoxOptionsBase.cs index 64e0092..6999e99 100644 --- a/grapher/Models/Options/ComboBoxOptionsBase.cs +++ b/grapher/Models/Options/ComboBoxOptionsBase.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; namespace grapher.Models.Options { @@ -61,7 +56,7 @@ namespace grapher.Models.Options { get { - return Label.Height; + return OptionsDropdown.Height; } } @@ -69,7 +64,7 @@ namespace grapher.Models.Options { get { - return Label.Top; + return OptionsDropdown.Top; } set { -- cgit v1.2.3 From 138ddb54e42e71a384e059afe69e4e8172935d6d Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Mon, 13 Sep 2021 23:00:53 -0400 Subject: fix potential leaks forms displayed with ShowDialog are only hidden when closed; Dispose must be called manually --- grapher/Models/AccelGUI.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index e15aba9..1836b65 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -154,7 +154,10 @@ namespace grapher error_message = e.Message; } - new MessageDialog(error_message, "bad input").ShowDialog(); + using (var form = new MessageDialog(error_message, "bad input")) + { + form.ShowDialog(); + } } public void RefreshActive() -- cgit v1.2.3 From 7c0305ae2c99c191baf61eb920025826057d5753 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Wed, 15 Sep 2021 06:41:57 -0400 Subject: add device menu --- grapher/Models/AccelGUI.cs | 23 ++++++++- grapher/Models/AccelGUIFactory.cs | 6 +-- grapher/Models/Devices/DeviceDialogItem.cs | 26 ++++++++++ grapher/Models/Devices/DeviceIDItem.cs | 73 ---------------------------- grapher/Models/Devices/DeviceIDManager.cs | 68 -------------------------- grapher/Models/Serialized/SettingsManager.cs | 67 ++++++++++++++++++++----- 6 files changed, 107 insertions(+), 156 deletions(-) create mode 100644 grapher/Models/Devices/DeviceDialogItem.cs delete mode 100644 grapher/Models/Devices/DeviceIDItem.cs delete mode 100644 grapher/Models/Devices/DeviceIDManager.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 1836b65..51e31a6 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -4,6 +4,7 @@ using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; using System; +using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; @@ -24,7 +25,8 @@ namespace grapher Button writeButton, ButtonBase resetButton, MouseWatcher mouseWatcher, - ToolStripMenuItem scaleMenuItem) + ToolStripMenuItem scaleMenuItem, + ToolStripMenuItem deviceMenuItem) { AccelForm = accelForm; AccelCalculator = accelCalculator; @@ -33,11 +35,13 @@ namespace grapher WriteButton = writeButton; ResetButton = (CheckBox)resetButton; ScaleMenuItem = scaleMenuItem; + DeviceMenuItem = deviceMenuItem; Settings = settings; DefaultButtonFont = WriteButton.Font; SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor); MouseWatcher = mouseWatcher; + DeviceMenuItem.Click += DeviceMenuItemClick; ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); WriteButton.Click += new System.EventHandler(OnWriteButtonClick); ResetButton.Click += new System.EventHandler(ResetDriverEventHandler); @@ -83,6 +87,8 @@ namespace grapher public ToolStripMenuItem ScaleMenuItem { get; } + public ToolStripMenuItem DeviceMenuItem { get; } + private Timer ChartRefresh { get; } private Font SmallButtonFont { get; } @@ -146,6 +152,7 @@ namespace grapher else { RefreshActive(); + Settings.SetActiveHandles(); return; } } @@ -240,10 +247,12 @@ namespace grapher { ButtonTimer.Stop(); SetButtonDefaults(); + DeviceMenuItem.Enabled = true; } private void StartButtonTimer() { + DeviceMenuItem.Enabled = false; ButtonTimer.Interval = ButtonTimerInterval; ButtonTimer.Start(); } @@ -268,6 +277,18 @@ namespace grapher MouseWatcher.UpdateLastMove(); } + private void DeviceMenuItemClick(object sender, EventArgs e) + { + using (var devMenu = new DeviceMenuForm(Settings)) + { + if (devMenu.ShowDialog() == DialogResult.OK) + { + Settings.Submit(devMenu.defaultConfig, devMenu.Items); + UpdateActiveSettingsFromFields(); + } + } + } + #endregion Methods } diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 4d0a483..91a649a 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -639,8 +639,7 @@ namespace grapher.Models autoWriteMenuItem, showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem, - streamingModeToolStripMenuItem, - deviceMenuItem); + streamingModeToolStripMenuItem); var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, settings); @@ -653,7 +652,8 @@ namespace grapher.Models writeButton, toggleButton, mouseWatcher, - scaleMenuItem); + scaleMenuItem, + deviceMenuItem); } #endregion Methods diff --git a/grapher/Models/Devices/DeviceDialogItem.cs b/grapher/Models/Devices/DeviceDialogItem.cs new file mode 100644 index 0000000..9ca5528 --- /dev/null +++ b/grapher/Models/Devices/DeviceDialogItem.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Devices +{ + public class DeviceDialogItem + { + public MultiHandleDevice device; + public DeviceSettings oldSettings; + public DeviceConfig newConfig; + public string newProfile; + public bool overrideDefaultConfig; + + public override string ToString() + { + return string.IsNullOrWhiteSpace(device.name) ? + device.id : + device.name; + } + } +} diff --git a/grapher/Models/Devices/DeviceIDItem.cs b/grapher/Models/Devices/DeviceIDItem.cs deleted file mode 100644 index 8f1587b..0000000 --- a/grapher/Models/Devices/DeviceIDItem.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace grapher.Models.Devices -{ - public class DeviceIDItem - { - public DeviceIDItem(string name, string id, DeviceIDManager manager) - { - Name = name; - ID = id; - Manager = manager; - DeviceIDMenuItem = new ToolStripMenuItem(); - DeviceIDMenuItem.Checked = false; - DeviceIDMenuItem.Text = MenuItemText(); - DeviceIDMenuItem.Click += OnClicked; - manager.DeviceIDsMenuItem.DropDownItems.Add(DeviceIDMenuItem); - } - - private ToolStripMenuItem DeviceIDMenuItem { get; } - - public string Name { get; } - - public string ID { get; } - - private DeviceIDManager Manager { get; } - - public void SetActivated() - { - DeviceIDMenuItem.Checked = true; - } - - public void SetDeactivated() - { - DeviceIDMenuItem.Checked = false; - } - - private string MenuItemText() => string.IsNullOrEmpty(ID) ? $"{Name}" : ID.Replace("&", "&&"); - - private string DisconnectedText() => $"Disconnected: {ID}"; - - public void SetDisconnected() - { - DeviceIDMenuItem.ForeColor = Color.DarkGray; - DeviceIDMenuItem.Text = DisconnectedText(); - } - - public void OnClicked(object sender, EventArgs e) - { - Manager.SetActive(this); - } - - public override bool Equals(object obj) - { - return obj is DeviceIDItem item && - Name == item.Name && - ID == item.ID; - } - - public override int GetHashCode() - { - int hashCode = -1692744877; - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Name); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ID); - return hashCode; - } - } -} diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs deleted file mode 100644 index e0ee686..0000000 --- a/grapher/Models/Devices/DeviceIDManager.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Management; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace grapher.Models.Devices -{ - public class DeviceIDManager - { - public DeviceIDManager(ToolStripMenuItem deviceIDs) - { - DeviceIDsMenuItem = deviceIDs; - DeviceIDsMenuItem.Checked = false; - } - - public ToolStripMenuItem DeviceIDsMenuItem { get; } - - public string ID { get => SelectedDeviceID.ID; } - - public DeviceIDItem SelectedDeviceID { get; private set; } - - public Dictionary DeviceIDs { get; private set; } - - public void SetActive(DeviceIDItem deviceIDItem) - { - if (SelectedDeviceID != null) - { - SelectedDeviceID.SetDeactivated(); - } - - SelectedDeviceID = deviceIDItem; - SelectedDeviceID.SetActivated(); - } - - public void Update(string devID) - { - DeviceIDsMenuItem.DropDownItems.Clear(); - - bool found = string.IsNullOrEmpty(devID); - - var anyDevice = new DeviceIDItem("Any", string.Empty, this); - - if (found) SetActive(anyDevice); - -/* foreach (string id in RawInputInterop.GetDeviceIDs()) - { - var deviceItem = new DeviceIDItem(string.Empty, id, this); - if (!found && deviceItem.ID.Equals(devID)) - { - SetActive(deviceItem); - found = true; - } - }*/ - - if (!found) - { - var deviceItem = new DeviceIDItem(string.Empty, devID, this); - deviceItem.SetDisconnected(); - SetActive(deviceItem); - } - } - - } -} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 3789c05..8c8bf15 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -21,8 +21,7 @@ namespace grapher.Models.Serialized ToolStripMenuItem autoWrite, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain, - ToolStripMenuItem streamingMode, - ToolStripMenuItem deviceMenuItem) + ToolStripMenuItem streamingMode) { DpiField = dpiField; PollRateField = pollRateField; @@ -30,7 +29,6 @@ namespace grapher.Models.Serialized ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; StreamingModeMenuItem = streamingMode; - deviceMenuItem.Click += (s, e) => new DeviceMenuForm(this).ShowDialog(); SystemDevices = new List(); ActiveHandles = new List(); @@ -47,14 +45,17 @@ namespace grapher.Models.Serialized UpdateFieldsFromGUISettings(); } - UserConfig = InitActiveAndGetUserConfig(); + UserConfigField = InitActiveAndGetUserConfig(); } #endregion Constructors #region Fields + private EventHandler DeviceChangeField; + private DriverConfig ActiveConfigField; + private DriverConfig UserConfigField; #endregion Fields @@ -62,6 +63,12 @@ namespace grapher.Models.Serialized public GUISettings GuiSettings { get; private set; } + public event EventHandler DeviceChange + { + add => DeviceChangeField += value; + remove => DeviceChangeField -= value; + } + public DriverConfig ActiveConfig { get => ActiveConfigField; @@ -87,11 +94,16 @@ namespace grapher.Models.Serialized get => ActiveConfig.accels[0]; } - public DriverConfig UserConfig { get; private set; } + public DriverConfig UserConfig + { + get => UserConfigField; + private set => UserConfigField = value; + } public Profile UserProfile { - get => UserConfig.profiles[0]; + get => UserConfigField.profiles[0]; + private set => UserConfigField.SetProfileAt(0, value); } public HashSet ActiveProfileNamesSet { get; private set; } @@ -133,12 +145,12 @@ namespace grapher.Models.Serialized public bool TryActivate(Profile settings, out string errors) { - var old = ActiveProfile; - ActiveProfile = settings; - bool success = TryActivate(ActiveConfig, out errors); + var old = UserProfile; + UserProfile = settings; + bool success = TryActivate(UserConfig, out errors); if (!success) { - ActiveProfile = old; + UserProfile = old; } return success; } @@ -183,7 +195,7 @@ namespace grapher.Models.Serialized }; } - private void SetActiveHandles() + public void SetActiveHandles() { ActiveHandles.Clear(); @@ -217,6 +229,37 @@ namespace grapher.Models.Serialized } } + public void Submit(DeviceConfig newDefaultConfig, DeviceDialogItem[] items) + { + UserConfig.defaultDeviceConfig = newDefaultConfig; + foreach (var item in items) + { + if (item.overrideDefaultConfig) + { + if (item.oldSettings is null) + { + UserConfig.devices.Add( + new DeviceSettings + { + name = item.device.name, + profile = item.newProfile, + id = item.device.id, + config = item.newConfig + }); + } + else + { + item.oldSettings.config = item.newConfig; + item.oldSettings.profile = item.newProfile; + } + } + else if (!(item.oldSettings is null)) + { + UserConfig.devices.Remove(item.oldSettings); + } + } + } + public void OnProfileSelectionChange() { SetActiveHandles(); @@ -226,6 +269,8 @@ namespace grapher.Models.Serialized { SystemDevices = MultiHandleDevice.GetList(); SetActiveHandles(); + + DeviceChangeField?.Invoke(this, EventArgs.Empty); } private DriverConfig InitActiveAndGetUserConfig() -- cgit v1.2.3 From feba2ca96fcfdc161c5ffd1c0cceb8db38b894e0 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 15 Sep 2021 23:48:32 -0700 Subject: Fix gain switch GUI --- grapher/Models/Options/CheckBoxOption.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/CheckBoxOption.cs b/grapher/Models/Options/CheckBoxOption.cs index 1a4245d..8c125ec 100644 --- a/grapher/Models/Options/CheckBoxOption.cs +++ b/grapher/Models/Options/CheckBoxOption.cs @@ -102,10 +102,10 @@ namespace grapher.Models.Options ActiveValueLabel.Show(); } - public void SetActiveValue(bool legacy) + public void SetActiveValue(bool gain) { - CheckBox.Checked = !legacy; - var activeValueString = legacy ? "Legacy" : "Gain"; + CheckBox.Checked = gain; + var activeValueString = gain ? "Gain" : "Legacy"; ActiveValueLabel.SetValue(activeValueString); } } -- cgit v1.2.3 From 7361457ed17670b37279f12fe334e7a9ce7ea34e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 16 Sep 2021 01:29:51 -0700 Subject: Get power cap working --- grapher/Models/Options/AccelTypeOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 3d2f840..b7a7b7b 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -323,7 +323,7 @@ namespace grapher } if (PowerCap.Visible) { - args.scale = ClassicCap.Slope.Field.Data; + args.scale = PowerCap.Slope.Field.Data; args.cap.x = PowerCap.In.Field.Data; args.cap.y = PowerCap.Out.Field.Data; args.capMode = PowerCap.CapTypeOptions.GetSelectedCapMode(); -- cgit v1.2.3 From 4197e030c5cfeda5592816c8028152d9b7b599e0 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 16 Sep 2021 13:07:43 -0700 Subject: Remove weight --- grapher/Models/AccelGUIFactory.cs | 26 -------------------------- grapher/Models/Options/AccelTypeOptions.cs | 9 --------- 2 files changed, 35 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 91a649a..d95489b 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -46,8 +46,6 @@ namespace grapher.Models TextBox sensitivityBoxX, TextBox sensitivityBoxY, TextBox rotationBox, - TextBox weightBoxX, - TextBox weightBoxY, TextBox inCapBoxXClassic, TextBox inCapBoxYClassic, TextBox outCapBoxXClassic, @@ -96,8 +94,6 @@ namespace grapher.Models Label sensitivityLabel, Label yxRatioLabel, Label rotationLabel, - Label weightLabelX, - Label weightLabelY, Label inCapLabelXClassic, Label inCapLabelYClassic, Label outCapLabelXClassic, @@ -137,8 +133,6 @@ namespace grapher.Models Label sensitivityActiveLabel, Label yxRatioActiveLabel, Label rotationActiveLabel, - Label weightActiveXLabel, - Label weightActiveYLabel, Label inCapActiveXLabelClassic, Label inCapActiveYLabelClassic, Label outCapActiveXLabelClassic, @@ -247,24 +241,6 @@ namespace grapher.Models var directionalityLeft = directionalityPanel.Left; - var weightX = new Option( - weightBoxX, - form, - 1, - weightLabelX, - 0, - new ActiveValueLabel(weightActiveXLabel, activeValueTitleX), - "Weight"); - - var weightY = new Option( - weightBoxY, - form, - 1, - weightLabelY, - optionSetYLeft, - new ActiveValueLabel(weightActiveYLabel, activeValueTitleY), - "Weight"); - var offsetX = new Option( offsetBoxX, form, @@ -559,7 +535,6 @@ namespace grapher.Models decayRateX, growthRateX, smoothX, - weightX, offsetX, limitX, powerClassicX, @@ -582,7 +557,6 @@ namespace grapher.Models decayRateY, growthRateY, smoothY, - weightY, offsetY, limitY, powerClassicY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index b7a7b7b..029a93e 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -32,7 +32,6 @@ namespace grapher Option decayRate, Option growthRate, Option smooth, - Option weight, Option offset, Option limit, Option powerClassic, @@ -67,7 +66,6 @@ namespace grapher Smooth = smooth; ClassicCap = classicCap; PowerCap = powerCap; - Weight = weight; Offset = offset; Limit = limit; PowerClassic = powerClassic; @@ -114,8 +112,6 @@ namespace grapher public CapOptions PowerCap { get; } - public Option Weight { get; } - public Option Offset { get; } public Option Limit { get; } @@ -227,7 +223,6 @@ namespace grapher Smooth.Hide(); ClassicCap.Hide(); PowerCap.Hide(); - Weight.Hide(); Offset.Hide(); Limit.Hide(); PowerClassic.Hide(); @@ -255,7 +250,6 @@ namespace grapher AccelerationType = AccelTypeFromSettings(ref args); AccelTypeActiveValue.SetValue(AccelerationType.ActiveName); GainSwitch.SetActiveValue(args.gain); - Weight.SetActiveValue(args.weight); ClassicCap.SetActiveValues( args.acceleration, args.cap.x, @@ -343,7 +337,6 @@ namespace grapher 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(); @@ -370,7 +363,6 @@ namespace grapher ClassicCap.AlignActiveValues(); PowerCap.AlignActiveValues(); Offset.AlignActiveValues(); - Weight.AlignActiveValues(); Limit.AlignActiveValues(); PowerClassic.AlignActiveValues(); Exponent.AlignActiveValues(); @@ -407,7 +399,6 @@ namespace grapher DecayRate, GrowthRate, Smooth, - Weight, Offset, Limit, PowerClassic, -- cgit v1.2.3 From 9cdad754cc299f44ebac1a39e89ce28d01714290 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 16 Sep 2021 13:45:51 -0700 Subject: Fix error in LUT gui --- grapher/Models/Options/LUT/LUTPanelOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index 11550e4..eedcfa8 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -126,11 +126,11 @@ namespace grapher.Models.Options.LUT y = rawData.ElementAt(data_idx + 1) }; } - ActiveValuesTextBox.Text = PointsToActiveValuesText(points, length); + ActiveValuesTextBox.Text = PointsToActiveValuesText(points, pointsLen); if (string.IsNullOrWhiteSpace(PointsTextBox.Text)) { - PointsTextBox.Text = PointsToEntryTextBoxText(points, length); + PointsTextBox.Text = PointsToEntryTextBoxText(points, pointsLen); } } else -- cgit v1.2.3 From 1fd8881608e4ce6ab21fd78d3ebb42a941cd0e93 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 16 Sep 2021 18:33:30 -0700 Subject: Add power start from one --- grapher/Models/AccelGUIFactory.cs | 24 +++++ grapher/Models/Options/AccelTypeOptions.cs | 9 ++ grapher/Models/Options/SwitchOption.cs | 162 +++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 grapher/Models/Options/SwitchOption.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index d95489b..89318e2 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -86,6 +86,10 @@ namespace grapher.Models CheckBox byComponentCheckBox, CheckBox gainSwitchX, CheckBox gainSwitchY, + CheckBox powerStartsFromZeroBoxX, + CheckBox powerStartsFromOneBoxX, + CheckBox powerStartsFromZeroBoxY, + CheckBox powerStartsFromOneBoxY, RichTextBox xLutActiveValuesBox, RichTextBox yLutActiveValuesBox, RichTextBox xLutPointsBox, @@ -124,6 +128,8 @@ namespace grapher.Models Label powerClassicLabelY, Label expLabelX, Label expLabelY, + Label powerStartsFromLabelX, + Label powerStartsFromLabelY, Label lutTextLabelX, Label lutTextLabelY, Label constantThreeLabelX, @@ -163,6 +169,8 @@ namespace grapher.Models Label powerClassicActiveLabelY, Label expActiveLabelX, Label expActiveLabelY, + Label powerStartsFromActiveLabelX, + Label powerStartsFromActiveLabelY, Label midpointActiveLabelX, Label midpointActiveLabelY, Label accelTypeActiveLabelX, @@ -487,6 +495,20 @@ namespace grapher.Models outCapYPower, scaleY); + var powerStartsFromX = new SwitchOption( + powerStartsFromLabelX, + powerStartsFromZeroBoxX, + powerStartsFromOneBoxX, + new ActiveValueLabel(powerStartsFromActiveLabelX, activeValueTitleX), + 0); + + var powerStartsFromY = new SwitchOption( + powerStartsFromLabelY, + powerStartsFromZeroBoxY, + powerStartsFromOneBoxY, + new ActiveValueLabel(powerStartsFromActiveLabelY, activeValueTitleY), + optionSetYLeft); + var lpNorm = new Option( new Field(lpNormBox, form, 2), lpNormLabel, @@ -532,6 +554,7 @@ namespace grapher.Models gainSwitchOptionX, classicCapOptionsX, powerCapOptionsX, + powerStartsFromX, decayRateX, growthRateX, smoothX, @@ -554,6 +577,7 @@ namespace grapher.Models gainSwitchOptionY, classicCapOptionsY, powerCapOptionsY, + powerStartsFromY, decayRateY, growthRateY, smoothY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 029a93e..b3153ed 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -29,6 +29,7 @@ namespace grapher CheckBoxOption gainSwitch, CapOptions classicCap, CapOptions powerCap, + SwitchOption powerStartsFrom, Option decayRate, Option growthRate, Option smooth, @@ -70,6 +71,7 @@ namespace grapher Limit = limit; PowerClassic = powerClassic; Exponent = exponent; + PowerStartsFrom = powerStartsFrom; Midpoint = midpoint; WriteButton = writeButton; AccelTypeActiveValue = accelTypeActiveValue; @@ -112,6 +114,8 @@ namespace grapher public CapOptions PowerCap { get; } + public SwitchOption PowerStartsFrom { get; } + public Option Offset { get; } public Option Limit { get; } @@ -223,6 +227,7 @@ namespace grapher Smooth.Hide(); ClassicCap.Hide(); PowerCap.Hide(); + PowerStartsFrom.Hide(); Offset.Hide(); Limit.Hide(); PowerClassic.Hide(); @@ -260,6 +265,7 @@ namespace grapher args.cap.x, args.cap.y, args.capMode); + PowerStartsFrom.SetActiveValue(!args.powerStartFromOne); Offset.SetActiveValue(args.offset); DecayRate.SetActiveValue(args.decayRate); GrowthRate.SetActiveValue(args.growthRate); @@ -322,6 +328,7 @@ namespace grapher args.cap.y = PowerCap.Out.Field.Data; args.capMode = PowerCap.CapTypeOptions.GetSelectedCapMode(); } + if (PowerStartsFrom.Visible) args.powerStartFromOne = PowerStartsFrom.Second.Checked; if (Limit.Visible) { if (args.mode == AccelMode.motivity) @@ -362,6 +369,7 @@ namespace grapher Smooth.AlignActiveValues(); ClassicCap.AlignActiveValues(); PowerCap.AlignActiveValues(); + PowerStartsFrom.AlignActiveValues(); Offset.AlignActiveValues(); Limit.AlignActiveValues(); PowerClassic.AlignActiveValues(); @@ -403,6 +411,7 @@ namespace grapher Limit, PowerClassic, Exponent, + PowerStartsFrom, Midpoint, LutText, LutPanel, diff --git a/grapher/Models/Options/SwitchOption.cs b/grapher/Models/Options/SwitchOption.cs new file mode 100644 index 0000000..79991c1 --- /dev/null +++ b/grapher/Models/Options/SwitchOption.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class SwitchOption : OptionBase + { + + #region Constructors + + public SwitchOption( + Label label, + CheckBox firstCheckBox, + CheckBox secondCheckBox, + ActiveValueLabel activeValueLabel, + int left) + { + Label = label; + First = firstCheckBox; + Second = secondCheckBox; + ActiveValueLabel = activeValueLabel; + Left = left; + + label.AutoSize = false; + label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + label.Width = First.Left - left - Constants.OptionLabelBoxSeperation; + label.Height = First.Height; + + ActiveValueLabel.Height = First.Height; + + First.CheckedChanged += OnFirstCheckedChange; + Second.CheckedChanged += OnSecondCheckedChange; + + First.Checked = true; + Second.Left = First.Left + First.Width + Constants.OptionLabelBoxSeperation; + Show(string.Empty); + } + + #endregion Constructors + + #region Properties + + public Label Label { get; } + + public CheckBox First { get; } + + public CheckBox Second { get; } + + public ActiveValueLabel ActiveValueLabel { get; } + + public override int Height + { + get => Label.Height; + } + + public override int Left + { + get => Label.Left; + set + { + Label.Left = value; + } + } + + public override bool Visible + { + get => ShouldShow; + } + + public override int Width + { + get => Second.Left + Second.Width - Label.Left; + set + { + } + } + + public override int Top + { + get => Label.Top; + set + { + Label.Top = value; + First.Top = value; + Second.Top = value; + ActiveValueLabel.Top = value; + } + } + + private bool ShouldShow { get; set; } + + #endregion Properties + + #region Methods + + public override void AlignActiveValues() + { + ActiveValueLabel.Align(); + } + + public override void Hide() + { + ShouldShow = false; + + Label.Hide(); + First.Hide(); + Second.Hide(); + ActiveValueLabel.Hide(); + } + + public override void Show(string name) + { + ShouldShow = true; + + if (!string.IsNullOrWhiteSpace(name)) + { + Label.Text = name; + } + + Label.Show(); + First.Show(); + Second.Show(); + ActiveValueLabel.Show(); + } + + public void SetActiveValue(bool shouldFirstBeChecked) + { + if (shouldFirstBeChecked) + { + First.Checked = true; + ActiveValueLabel.SetValue(First.Text); + } + else + { + Second.Checked = true; + ActiveValueLabel.SetValue(Second.Text); + } + } + + private void OnFirstCheckedChange(object sender, EventArgs e) + { + if (First.Checked) + { + Second.Checked = false; + } + } + + private void OnSecondCheckedChange(object sender, EventArgs e) + { + if (Second.Checked) + { + First.Checked = false; + } + } + + #endregion Methods + } +} -- cgit v1.2.3 From 115030165d539fde5440f6232879c7a076dea2ec Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 18 Sep 2021 05:20:53 -0400 Subject: generalize power start-from-1 starting output is determined by (gain) offset --- grapher/Models/AccelGUIFactory.cs | 82 +++++++++++++++--------------- grapher/Models/Options/AccelTypeOptions.cs | 32 ++++++------ 2 files changed, 58 insertions(+), 56 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 89318e2..bb65541 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -54,8 +54,10 @@ namespace grapher.Models TextBox inCapBoxYPower, TextBox outCapBoxXPower, TextBox outCapBoxYPower, - TextBox offsetBoxX, - TextBox offsetBoxY, + TextBox inputOffsetBoxX, + TextBox inputOffsetBoxY, + TextBox outputOffsetBoxX, + TextBox outputOffsetBoxY, TextBox accelerationBoxX, TextBox accelerationBoxY, TextBox decayRateBoxX, @@ -86,10 +88,6 @@ namespace grapher.Models CheckBox byComponentCheckBox, CheckBox gainSwitchX, CheckBox gainSwitchY, - CheckBox powerStartsFromZeroBoxX, - CheckBox powerStartsFromOneBoxX, - CheckBox powerStartsFromZeroBoxY, - CheckBox powerStartsFromOneBoxY, RichTextBox xLutActiveValuesBox, RichTextBox yLutActiveValuesBox, RichTextBox xLutPointsBox, @@ -110,8 +108,10 @@ namespace grapher.Models Label outCapLabelYPower, Label capTypeLabelXPower, Label capTypeLabelYPower, - Label offsetLabelX, - Label offsetLabelY, + Label inputOffsetLabelX, + Label inputOffsetLabelY, + Label outputOffsetLabelX, + Label outputOffsetLabelY, Label constantOneLabelX, Label constantOneLabelY, Label decayRateLabelX, @@ -128,8 +128,6 @@ namespace grapher.Models Label powerClassicLabelY, Label expLabelX, Label expLabelY, - Label powerStartsFromLabelX, - Label powerStartsFromLabelY, Label lutTextLabelX, Label lutTextLabelY, Label constantThreeLabelX, @@ -151,8 +149,10 @@ namespace grapher.Models Label outCapActiveYLabelPower, Label capTypeActiveXLabelPower, Label capTypeActiveYLabelPower, - Label offsetActiveLabelX, - Label offsetActiveLabelY, + Label inputOffsetActiveLabelX, + Label inputOffsetActiveLabelY, + Label outputOffsetActiveLabelX, + Label outputOffsetActiveLabelY, Label accelerationActiveLabelX, Label accelerationActiveLabelY, Label decayRateActiveLabelX, @@ -169,8 +169,6 @@ namespace grapher.Models Label powerClassicActiveLabelY, Label expActiveLabelX, Label expActiveLabelY, - Label powerStartsFromActiveLabelX, - Label powerStartsFromActiveLabelY, Label midpointActiveLabelX, Label midpointActiveLabelY, Label accelTypeActiveLabelX, @@ -249,22 +247,40 @@ namespace grapher.Models var directionalityLeft = directionalityPanel.Left; - var offsetX = new Option( - offsetBoxX, + var inputOffsetX = new Option( + inputOffsetBoxX, form, 0, - offsetLabelX, + inputOffsetLabelX, 0, - new ActiveValueLabel(offsetActiveLabelX, activeValueTitleX), + new ActiveValueLabel(inputOffsetActiveLabelX, activeValueTitleX), "Offset"); - var offsetY = new Option( - offsetBoxY, + var inputOffsetY = new Option( + inputOffsetBoxY, form, 0, - offsetLabelY, + inputOffsetLabelY, optionSetYLeft, - new ActiveValueLabel(offsetActiveLabelY, activeValueTitleY), + new ActiveValueLabel(inputOffsetActiveLabelY, activeValueTitleY), + "Offset"); + + var outputOffsetX = new Option( + outputOffsetBoxX, + form, + 0, + outputOffsetLabelX, + 0, + new ActiveValueLabel(outputOffsetActiveLabelX, activeValueTitleX), + "Offset"); + + var outputOffsetY = new Option( + outputOffsetBoxY, + form, + 0, + outputOffsetLabelY, + optionSetYLeft, + new ActiveValueLabel(outputOffsetActiveLabelY, activeValueTitleY), "Offset"); var accelerationX = new Option( @@ -495,20 +511,6 @@ namespace grapher.Models outCapYPower, scaleY); - var powerStartsFromX = new SwitchOption( - powerStartsFromLabelX, - powerStartsFromZeroBoxX, - powerStartsFromOneBoxX, - new ActiveValueLabel(powerStartsFromActiveLabelX, activeValueTitleX), - 0); - - var powerStartsFromY = new SwitchOption( - powerStartsFromLabelY, - powerStartsFromZeroBoxY, - powerStartsFromOneBoxY, - new ActiveValueLabel(powerStartsFromActiveLabelY, activeValueTitleY), - optionSetYLeft); - var lpNorm = new Option( new Field(lpNormBox, form, 2), lpNormLabel, @@ -554,11 +556,11 @@ namespace grapher.Models gainSwitchOptionX, classicCapOptionsX, powerCapOptionsX, - powerStartsFromX, + outputOffsetX, decayRateX, growthRateX, smoothX, - offsetX, + inputOffsetX, limitX, powerClassicX, exponentX, @@ -577,11 +579,11 @@ namespace grapher.Models gainSwitchOptionY, classicCapOptionsY, powerCapOptionsY, - powerStartsFromY, + outputOffsetY, decayRateY, growthRateY, smoothY, - offsetY, + inputOffsetY, limitY, powerClassicY, exponentY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index b3153ed..d89f2d1 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -29,11 +29,11 @@ namespace grapher CheckBoxOption gainSwitch, CapOptions classicCap, CapOptions powerCap, - SwitchOption powerStartsFrom, + Option outputOffset, Option decayRate, Option growthRate, Option smooth, - Option offset, + Option inputOffset, Option limit, Option powerClassic, Option exponent, @@ -67,11 +67,11 @@ namespace grapher Smooth = smooth; ClassicCap = classicCap; PowerCap = powerCap; - Offset = offset; + InputOffset = inputOffset; Limit = limit; PowerClassic = powerClassic; Exponent = exponent; - PowerStartsFrom = powerStartsFrom; + OutputOffset = outputOffset; Midpoint = midpoint; WriteButton = writeButton; AccelTypeActiveValue = accelTypeActiveValue; @@ -114,9 +114,9 @@ namespace grapher public CapOptions PowerCap { get; } - public SwitchOption PowerStartsFrom { get; } + public Option InputOffset { get; } - public Option Offset { get; } + public Option OutputOffset { get; } public Option Limit { get; } @@ -227,8 +227,8 @@ namespace grapher Smooth.Hide(); ClassicCap.Hide(); PowerCap.Hide(); - PowerStartsFrom.Hide(); - Offset.Hide(); + OutputOffset.Hide(); + InputOffset.Hide(); Limit.Hide(); PowerClassic.Hide(); Exponent.Hide(); @@ -265,8 +265,8 @@ namespace grapher args.cap.x, args.cap.y, args.capMode); - PowerStartsFrom.SetActiveValue(!args.powerStartFromOne); - Offset.SetActiveValue(args.offset); + OutputOffset.SetActiveValue(args.outputOffset); + InputOffset.SetActiveValue(args.inputOffset); DecayRate.SetActiveValue(args.decayRate); GrowthRate.SetActiveValue(args.growthRate); Smooth.SetActiveValue(args.smooth); @@ -328,7 +328,6 @@ namespace grapher args.cap.y = PowerCap.Out.Field.Data; args.capMode = PowerCap.CapTypeOptions.GetSelectedCapMode(); } - if (PowerStartsFrom.Visible) args.powerStartFromOne = PowerStartsFrom.Second.Checked; if (Limit.Visible) { if (args.mode == AccelMode.motivity) @@ -342,7 +341,8 @@ namespace grapher } 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 (InputOffset.Visible) args.inputOffset = InputOffset.Field.Data; + if (OutputOffset.Visible) args.outputOffset = OutputOffset.Field.Data; if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (LutPanel.Visible) { @@ -369,8 +369,8 @@ namespace grapher Smooth.AlignActiveValues(); ClassicCap.AlignActiveValues(); PowerCap.AlignActiveValues(); - PowerStartsFrom.AlignActiveValues(); - Offset.AlignActiveValues(); + OutputOffset.AlignActiveValues(); + InputOffset.AlignActiveValues(); Limit.AlignActiveValues(); PowerClassic.AlignActiveValues(); Exponent.AlignActiveValues(); @@ -407,11 +407,11 @@ namespace grapher DecayRate, GrowthRate, Smooth, - Offset, + InputOffset, Limit, PowerClassic, Exponent, - PowerStartsFrom, + OutputOffset, Midpoint, LutText, LutPanel, -- cgit v1.2.3 From 915132d15ce4c1913d18adb917124acc727d4800 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 16 Sep 2021 19:52:48 -0400 Subject: fix - gui lut mode AccelArgs::gain was not set from LutApplyOptions --- grapher/Models/Options/AccelTypeOptions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index d89f2d1..f079542 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -275,7 +275,6 @@ namespace grapher Exponent.SetActiveValue(args.exponentPower); Midpoint.SetActiveValue(args.midpoint); LutPanel.SetActiveValues(args.data, args.length, args.mode); - // TODO - use GainSwitch only? LutApply.SetActiveValue(args.gain); } @@ -309,7 +308,9 @@ namespace grapher public void SetArgs(ref AccelArgs args) { args.mode = AccelerationType.Mode; - args.gain = GainSwitch.CheckBox.Checked; + args.gain = LutPanel.Visible ? + LutApply.ApplyType == LutApplyOptions.LutApplyType.Velocity : + GainSwitch.CheckBox.Checked; if (DecayRate.Visible) args.decayRate = DecayRate.Field.Data; if (GrowthRate.Visible) args.growthRate = GrowthRate.Field.Data; -- cgit v1.2.3 From 62d9e1da9cfb5b1b85f8d6d4a7efc8828bbb1e8b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 16 Sep 2021 21:15:56 -0400 Subject: refactor SetActiveHandles method --- grapher/Models/Serialized/SettingsManager.cs | 30 +++++++++++----------------- 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 8c8bf15..cb42c4e 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -201,30 +201,24 @@ namespace grapher.Models.Serialized bool ActiveProfileIsFirst = ActiveProfile == ActiveConfig.profiles[0]; - foreach (var dev in SystemDevices) MaybeAdd(dev); - - void MaybeAdd(MultiHandleDevice dev) + foreach (var sysDev in SystemDevices) { - foreach (var settings in ActiveConfig.devices) + var settings = ActiveConfig.devices.Find(d => d.id == sysDev.id); + + if (settings is null) { - if (settings.id == dev.id) + if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) { - if (!settings.config.disable && - ((ActiveProfileIsFirst && - (string.IsNullOrEmpty(settings.profile) || - !ActiveProfileNamesSet.Contains(settings.profile))) || - ActiveProfile.name == settings.profile)) - { - ActiveHandles.AddRange(dev.handles); - } - - return; + ActiveHandles.AddRange(sysDev.handles); } } - - if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) + else if (!settings.config.disable && + ((ActiveProfileIsFirst && + (string.IsNullOrEmpty(settings.profile) || + !ActiveProfileNamesSet.Contains(settings.profile))) || + ActiveProfile.name == settings.profile)) { - ActiveHandles.AddRange(dev.handles); + ActiveHandles.AddRange(sysDev.handles); } } } -- cgit v1.2.3 From 94ce1542b03090b81a4250f7f799895c58ab286c Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 18 Sep 2021 05:34:59 -0400 Subject: rename directional multipliers changes profile layout --- grapher/Models/Mouse/MouseWatcher.cs | 6 +++++- grapher/Models/Serialized/SettingsManager.cs | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index c36ceb4..91eebb8 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -757,7 +757,11 @@ namespace grapher.Models.Mouse // strip negative directional multipliers, charts calculated from positive input - Vec2 dirMults = SettingsManager.ActiveProfile.directionalMultipliers; + Vec2 dirMults = new Vec2 + { + x = SettingsManager.ActiveProfile.lrSensRatio, + y = SettingsManager.ActiveProfile.udSensRatio + }; if (dirMults.x > 0 && x < 0) { diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index cb42c4e..aac0f3e 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -179,7 +179,8 @@ namespace grapher.Models.Serialized settings.snap = UserProfile.snap; settings.maximumSpeed = UserProfile.maximumSpeed; settings.minimumSpeed = UserProfile.minimumSpeed; - settings.directionalMultipliers = UserProfile.directionalMultipliers; + settings.lrSensRatio = UserProfile.lrSensRatio; + settings.udSensRatio = UserProfile.udSensRatio; } public GUISettings MakeGUISettingsFromFields() -- cgit v1.2.3 From d270a967b606116596114744417a182b3f16218b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 18 Sep 2021 05:39:08 -0400 Subject: rename classic_cap_mode --- grapher/Models/Options/Cap/CapOptions.cs | 2 +- grapher/Models/Options/Cap/CapTypeOptions.cs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/Cap/CapOptions.cs b/grapher/Models/Options/Cap/CapOptions.cs index ac34abf..de0f597 100644 --- a/grapher/Models/Options/Cap/CapOptions.cs +++ b/grapher/Models/Options/Cap/CapOptions.cs @@ -131,7 +131,7 @@ namespace grapher.Models.Options.Cap double scale, double inCap, double outCap, - ClassicCapMode capMode) + CapMode capMode) { Slope.SetActiveValue(scale); In.SetActiveValue(inCap); diff --git a/grapher/Models/Options/Cap/CapTypeOptions.cs b/grapher/Models/Options/Cap/CapTypeOptions.cs index 1e7bd58..6447feb 100644 --- a/grapher/Models/Options/Cap/CapTypeOptions.cs +++ b/grapher/Models/Options/Cap/CapTypeOptions.cs @@ -107,14 +107,14 @@ namespace grapher.Models.Options.Cap private CapTypeOption Default { get; set; } - public ClassicCapMode GetSelectedCapMode() + public CapMode GetSelectedCapMode() { switch(SelectedCapType) { - case CapType.Output: return ClassicCapMode.output; - case CapType.Both: return ClassicCapMode.in_out; + case CapType.Output: return CapMode.output; + case CapType.Both: return CapMode.in_out; case CapType.Input: - default: return ClassicCapMode.input; + default: return CapMode.input; } } @@ -122,21 +122,21 @@ namespace grapher.Models.Options.Cap #region Methods - public static CapTypeOption CapTypeOptionFromSettings(ClassicCapMode capMode) + public static CapTypeOption CapTypeOptionFromSettings(CapMode capMode) { switch (capMode) { - case ClassicCapMode.output: + case CapMode.output: return OutCap; - case ClassicCapMode.in_out: + case CapMode.in_out: return BothCap; - case ClassicCapMode.input: + case CapMode.input: default: return InCap; } } - public void SetActiveValue(ClassicCapMode capMode) + public void SetActiveValue(CapMode capMode) { Default = CapTypeOptionFromSettings(capMode); SelectedCapOption = Default; -- cgit v1.2.3 From 4c4eabc0cb85cfef22900773649d96f610bb25dc Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sun, 19 Sep 2021 02:08:06 -0400 Subject: fix jump fields --- grapher/Models/AccelGUIFactory.cs | 52 ++++++++++++++++++++++++++++++ grapher/Models/Options/AccelTypeOptions.cs | 19 +++++++++++ 2 files changed, 71 insertions(+) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index bb65541..e7ae672 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -54,6 +54,10 @@ namespace grapher.Models TextBox inCapBoxYPower, TextBox outCapBoxXPower, TextBox outCapBoxYPower, + TextBox inputJumpBoxX, + TextBox inputJumpBoxY, + TextBox outputJumpBoxX, + TextBox outputJumpBoxY, TextBox inputOffsetBoxX, TextBox inputOffsetBoxY, TextBox outputOffsetBoxX, @@ -108,6 +112,10 @@ namespace grapher.Models Label outCapLabelYPower, Label capTypeLabelXPower, Label capTypeLabelYPower, + Label inputJumpLabelX, + Label inputJumpLabelY, + Label outputJumpLabelX, + Label outputJumpLabelY, Label inputOffsetLabelX, Label inputOffsetLabelY, Label outputOffsetLabelX, @@ -149,6 +157,10 @@ namespace grapher.Models Label outCapActiveYLabelPower, Label capTypeActiveXLabelPower, Label capTypeActiveYLabelPower, + Label inputJumpActiveLabelX, + Label inputJumpActiveLabelY, + Label outputJumpActiveLabelX, + Label outputJumpActiveLabelY, Label inputOffsetActiveLabelX, Label inputOffsetActiveLabelY, Label outputOffsetActiveLabelX, @@ -247,6 +259,42 @@ namespace grapher.Models var directionalityLeft = directionalityPanel.Left; + var inputJumpX = new Option( + inputJumpBoxX, + form, + 0, + inputJumpLabelX, + 0, + new ActiveValueLabel(inputJumpActiveLabelX, activeValueTitleX), + "Jump"); + + var inputJumpY = new Option( + inputJumpBoxY, + form, + 0, + inputJumpLabelY, + optionSetYLeft, + new ActiveValueLabel(inputJumpActiveLabelY, activeValueTitleY), + "Jump"); + + var outputJumpX = new Option( + outputJumpBoxX, + form, + 0, + outputJumpLabelX, + 0, + new ActiveValueLabel(outputJumpActiveLabelX, activeValueTitleX), + "Jump"); + + var outputJumpY = new Option( + outputJumpBoxY, + form, + 0, + outputJumpLabelY, + optionSetYLeft, + new ActiveValueLabel(outputJumpActiveLabelY, activeValueTitleY), + "Jump"); + var inputOffsetX = new Option( inputOffsetBoxX, form, @@ -556,10 +604,12 @@ namespace grapher.Models gainSwitchOptionX, classicCapOptionsX, powerCapOptionsX, + outputJumpX, outputOffsetX, decayRateX, growthRateX, smoothX, + inputJumpX, inputOffsetX, limitX, powerClassicX, @@ -579,10 +629,12 @@ namespace grapher.Models gainSwitchOptionY, classicCapOptionsY, powerCapOptionsY, + outputJumpY, outputOffsetY, decayRateY, growthRateY, smoothY, + inputJumpY, inputOffsetY, limitY, powerClassicY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index f079542..359b6b8 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -29,10 +29,12 @@ namespace grapher CheckBoxOption gainSwitch, CapOptions classicCap, CapOptions powerCap, + Option outputJump, Option outputOffset, Option decayRate, Option growthRate, Option smooth, + Option inputJump, Option inputOffset, Option limit, Option powerClassic, @@ -67,10 +69,12 @@ namespace grapher Smooth = smooth; ClassicCap = classicCap; PowerCap = powerCap; + InputJump = inputJump; InputOffset = inputOffset; Limit = limit; PowerClassic = powerClassic; Exponent = exponent; + OutputJump = outputJump; OutputOffset = outputOffset; Midpoint = midpoint; WriteButton = writeButton; @@ -114,6 +118,10 @@ namespace grapher public CapOptions PowerCap { get; } + public Option InputJump { get; } + + public Option OutputJump { get; } + public Option InputOffset { get; } public Option OutputOffset { get; } @@ -229,6 +237,8 @@ namespace grapher PowerCap.Hide(); OutputOffset.Hide(); InputOffset.Hide(); + InputJump.Hide(); + OutputJump.Hide(); Limit.Hide(); PowerClassic.Hide(); Exponent.Hide(); @@ -265,6 +275,8 @@ namespace grapher args.cap.x, args.cap.y, args.capMode); + InputJump.SetActiveValue(args.cap.x); + OutputJump.SetActiveValue(args.cap.y); OutputOffset.SetActiveValue(args.outputOffset); InputOffset.SetActiveValue(args.inputOffset); DecayRate.SetActiveValue(args.decayRate); @@ -329,6 +341,8 @@ namespace grapher args.cap.y = PowerCap.Out.Field.Data; args.capMode = PowerCap.CapTypeOptions.GetSelectedCapMode(); } + if (InputJump.Visible) args.cap.x = InputJump.Field.Data; + if (OutputJump.Visible) args.cap.y = OutputJump.Field.Data; if (Limit.Visible) { if (args.mode == AccelMode.motivity) @@ -344,6 +358,7 @@ namespace grapher if (Exponent.Visible) args.exponentPower = Exponent.Field.Data; if (InputOffset.Visible) args.inputOffset = InputOffset.Field.Data; if (OutputOffset.Visible) args.outputOffset = OutputOffset.Field.Data; + if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (LutPanel.Visible) { @@ -372,6 +387,8 @@ namespace grapher PowerCap.AlignActiveValues(); OutputOffset.AlignActiveValues(); InputOffset.AlignActiveValues(); + OutputJump.AlignActiveValues(); + InputJump.AlignActiveValues(); Limit.AlignActiveValues(); PowerClassic.AlignActiveValues(); Exponent.AlignActiveValues(); @@ -408,10 +425,12 @@ namespace grapher DecayRate, GrowthRate, Smooth, + InputJump, InputOffset, Limit, PowerClassic, Exponent, + OutputJump, OutputOffset, Midpoint, LutText, -- cgit v1.2.3 From c64cc5e1ec3fe60392cafd63b795e5146f6dd159 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 20 Sep 2021 23:08:30 -0700 Subject: Disable output offset when both cap type selected in power --- grapher/Models/AccelGUIFactory.cs | 28 +++++++++++++---------- grapher/Models/Options/Cap/CapOptions.cs | 39 +++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 13 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index e7ae672..5fc7b8b 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -547,18 +547,6 @@ namespace grapher.Models new ActiveValueLabel(capTypeActiveYLabelPower, activeValueTitleY), optionSetYLeft); - var powerCapOptionsX = new CapOptions( - capTypeXPower, - inCapXPower, - outCapXPower, - scaleX); - - var powerCapOptionsY = new CapOptions( - capTypeYPower, - inCapYPower, - outCapYPower, - scaleY); - var lpNorm = new Option( new Field(lpNormBox, form, 2), lpNormLabel, @@ -599,6 +587,22 @@ namespace grapher.Models gainSwitchY, new ActiveValueLabel(gainSwitchActiveLabelY, activeValueTitleY)); + var powerCapOptionsX = new CapOptions( + capTypeXPower, + inCapXPower, + outCapXPower, + scaleX, + outputOffsetX, + gainSwitchOptionX); + + var powerCapOptionsY = new CapOptions( + capTypeYPower, + inCapYPower, + outCapYPower, + scaleY, + outputOffsetY, + gainSwitchOptionY); + var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, gainSwitchOptionX, diff --git a/grapher/Models/Options/Cap/CapOptions.cs b/grapher/Models/Options/Cap/CapOptions.cs index de0f597..68326e5 100644 --- a/grapher/Models/Options/Cap/CapOptions.cs +++ b/grapher/Models/Options/Cap/CapOptions.cs @@ -25,18 +25,27 @@ namespace grapher.Models.Options.Cap CapTypeOptions capTypeOptions, Option capIn, Option capOut, - Option slope) + Option slope, + Option disableOptionInBoth = null, + CheckBoxOption disableInBoth = null) { CapTypeOptions = capTypeOptions; In = capIn; Out = capOut; Slope = slope; + DisableOptionInBoth = disableOptionInBoth; + DisableInBoth = disableInBoth; ShouldShow = true; _top = Slope.Top; BottomElement = In; CapTypeOptions.OptionsDropdown.SelectedIndexChanged += OnCapTypeDropdownSelectedItemChanged; CapTypeOptions.SelectedCapOption = InCap; + + if (DisableInBoth != null) + { + DisableInBoth.CheckBox.CheckedChanged += OnDisableInBothCheckedChange; + } } #endregion Constructors @@ -51,6 +60,10 @@ namespace grapher.Models.Options.Cap public Option Slope { get; } + private Option DisableOptionInBoth { get; } + + private CheckBoxOption DisableInBoth { get; } + public override int Left { get => In.Left; @@ -189,6 +202,25 @@ namespace grapher.Models.Options.Cap BottomElement = Out; break; } + + DisableBuggedOptionIfApplicable(); + } + + private void DisableBuggedOptionIfApplicable() + { + if (DisableOptionInBoth != null) + { + if (CapTypeOptions.SelectedCapType == CapType.Both && + DisableInBoth != null && + !DisableInBoth.CheckBox.Checked) + { + DisableOptionInBoth.Field.SetToUnavailable(); + } + else + { + DisableOptionInBoth.Field.SetToDefault(); + } + } } private void ShowInCap() @@ -207,6 +239,11 @@ namespace grapher.Models.Options.Cap CapTypeOptions.CheckIfDefault(); } + private void OnDisableInBothCheckedChange(object sender, EventArgs e) + { + DisableBuggedOptionIfApplicable(); + } + #endregion Methods } } -- cgit v1.2.3 From fdab3cf830e1bf87bc0bd3b72339be14265c7338 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 20 Sep 2021 23:41:36 -0700 Subject: Change disable button to reset, update doc text --- grapher/Models/AccelGUI.cs | 4 ++-- grapher/Models/Serialized/SettingsManager.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 51e31a6..23d5017 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -203,7 +203,7 @@ namespace grapher private void SetupButtons() { WriteButton.Top = Constants.SensitivityChartAloneHeight - Constants.ButtonVerticalOffset; - + ResetButton.Appearance = Appearance.Button; ResetButton.FlatStyle = FlatStyle.System; ResetButton.TextAlign = ContentAlignment.MiddleCenter; @@ -239,7 +239,7 @@ namespace grapher private void ResetDriverEventHandler(object sender, EventArgs e) { ButtonDelay(ResetButton); - Settings.DisableDriver(); + Settings.ResetDriver(); RefreshActive(); } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index aac0f3e..1c8608f 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -127,7 +127,7 @@ namespace grapher.Models.Serialized #region Methods - public void DisableDriver() + public void ResetDriver() { ActiveConfig = DriverConfig.GetDefault(); new Thread(() => DriverConfig.Deactivate()).Start(); -- cgit v1.2.3 From 79c6a885fc732a0fff0fe694a86ed6450b00794b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 23 Sep 2021 00:21:57 -0400 Subject: add indicator to last move on normalized dev read --- grapher/Models/Mouse/MouseWatcher.cs | 29 ++++++++++++++++++++++++++-- grapher/Models/Serialized/SettingsManager.cs | 15 +++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 91eebb8..723f97b 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -692,6 +692,9 @@ namespace grapher.Models.Mouse SettingsManager = setMngr; MouseData = new MouseData(); + LastMoveDisplayFormat = Constants.MouseMoveDefaultFormat; + LastMoveNormalized = false; + RAWINPUTDEVICE device = new RAWINPUTDEVICE(); device.WindowHandle = ContainingForm.Handle; device.UsagePage = HIDUsagePage.Generic; @@ -721,6 +724,10 @@ namespace grapher.Models.Mouse private Stopwatch Stopwatch { get; } + private string LastMoveDisplayFormat { get; set; } + + private bool LastMoveNormalized { get; set; } + private double PollTime { get => 1000 / SettingsManager.PollRateField.Data; @@ -733,7 +740,7 @@ namespace grapher.Models.Mouse public void UpdateLastMove() { MouseData.Get(out var x, out var y); - Display.Text = $"Last (x, y): ({x}, {y})"; + Display.Text = string.Format(LastMoveDisplayFormat, x, y); } public void ReadMouseMove(Message message) @@ -743,7 +750,25 @@ 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 = SettingsManager.ActiveHandles.Contains(rawInput.Header.Device); + + bool deviceMatch = false; + foreach (var (handle, normalized) in SettingsManager.ActiveNormTaggedHandles) + { + if (handle == rawInput.Header.Device) + { + deviceMatch = true; + + if (normalized != LastMoveNormalized) + { + LastMoveDisplayFormat = normalized ? + Constants.MouseMoveNormalizedFormat : + Constants.MouseMoveDefaultFormat; + LastMoveNormalized = normalized; + } + + break; + } + } if (relative && deviceMatch && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 1c8608f..43550c5 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -31,7 +31,7 @@ namespace grapher.Models.Serialized StreamingModeMenuItem = streamingMode; SystemDevices = new List(); - ActiveHandles = new List(); + ActiveNormTaggedHandles = new List<(IntPtr, bool)>(); GuiSettings = GUISettings.MaybeLoad(); @@ -114,7 +114,7 @@ namespace grapher.Models.Serialized public IList SystemDevices { get; private set; } - public List ActiveHandles { get; } + public List<(IntPtr, bool)> ActiveNormTaggedHandles { get; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } @@ -198,19 +198,24 @@ namespace grapher.Models.Serialized public void SetActiveHandles() { - ActiveHandles.Clear(); + ActiveNormTaggedHandles.Clear(); bool ActiveProfileIsFirst = ActiveProfile == ActiveConfig.profiles[0]; foreach (var sysDev in SystemDevices) { + void AddHandlesFromSysDev(bool normalized) + { + ActiveNormTaggedHandles.AddRange(sysDev.handles.Select(h => (h, normalized))); + } + var settings = ActiveConfig.devices.Find(d => d.id == sysDev.id); if (settings is null) { if (ActiveProfileIsFirst && !ActiveConfig.defaultDeviceConfig.disable) { - ActiveHandles.AddRange(sysDev.handles); + AddHandlesFromSysDev(ActiveConfig.defaultDeviceConfig.dpi > 0); } } else if (!settings.config.disable && @@ -219,7 +224,7 @@ namespace grapher.Models.Serialized !ActiveProfileNamesSet.Contains(settings.profile))) || ActiveProfile.name == settings.profile)) { - ActiveHandles.AddRange(sysDev.handles); + AddHandlesFromSysDev(settings.config.dpi > 0); } } } -- cgit v1.2.3 From f9323128aeffbfd2fe2931d6e5ad29acd394d878 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 23 Sep 2021 03:11:17 -0400 Subject: change MouseMoveNormalizedFormat --- grapher/Models/Mouse/MouseWatcher.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 723f97b..fb34dd6 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -761,8 +761,8 @@ namespace grapher.Models.Mouse if (normalized != LastMoveNormalized) { LastMoveDisplayFormat = normalized ? - Constants.MouseMoveNormalizedFormat : - Constants.MouseMoveDefaultFormat; + Constants.MouseMoveNormalizedFormat : + Constants.MouseMoveDefaultFormat; LastMoveNormalized = normalized; } -- cgit v1.2.3