diff options
| author | JacobPalecki <[email protected]> | 2020-09-08 16:00:05 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-09-08 16:00:05 -0700 |
| commit | e5461fa84e65d78823d0022339fa2d8864f7e63c (patch) | |
| tree | b486ef524c93bfeb29a86403114b6805bf9decf1 /grapher/Models | |
| parent | Merge pull request #19 from JacobPalecki/gainOffset (diff) | |
| parent | Save show last mouse value (diff) | |
| download | rawaccel-e5461fa84e65d78823d0022339fa2d8864f7e63c.tar.xz rawaccel-e5461fa84e65d78823d0022339fa2d8864f7e63c.zip | |
Merge pull request #20 from JacobPalecki/GUI
GUI: Add By Component & Anisotropy; Remove Logarithm and Sigmoid; Delete Console; Some Refactoring
Diffstat (limited to 'grapher/Models')
28 files changed, 1988 insertions, 417 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index a7d5d49..3acb943 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -3,67 +3,47 @@ using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; using System; -using System.CodeDom; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using System.Windows.Forms.DataVisualization.Charting; namespace grapher { public class AccelGUI { - #region constructors + #region Constructors public AccelGUI( RawAcceleration accelForm, AccelCalculator accelCalculator, AccelCharts accelCharts, SettingsManager settings, - AccelOptions accelOptions, - OptionXY sensitivity, - Option rotation, - OptionXY weight, - CapOptions cap, - OffsetOptions offset, - Option acceleration, - Option limtOrExp, - Option midpoint, + ApplyOptions applyOptions, Button writeButton, Label mouseMoveLabel, - ToolStripMenuItem scaleMenuItem, - ToolStripMenuItem autoWriteMenuItem) + ToolStripMenuItem scaleMenuItem) { AccelForm = accelForm; AccelCalculator = accelCalculator; AccelCharts = accelCharts; - AccelerationOptions = accelOptions; - Sensitivity = sensitivity; - Rotation = rotation; - Weight = weight; - Cap = cap; - Offset = offset; - Acceleration = acceleration; - LimitOrExponent = limtOrExp; - Midpoint = midpoint; + ApplyOptions = applyOptions; WriteButton = writeButton; ScaleMenuItem = scaleMenuItem; Settings = settings; Settings.Startup(); - UpdateGraph(); + RefreshOnRead(); MouseWatcher = new MouseWatcher(AccelForm, mouseMoveLabel, AccelCharts); ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); + WriteButton.Click += new System.EventHandler(OnWriteButtonClick); + + ButtonTimer = SetupButtonTimer(); + SetupWriteButton(); } - #endregion constructors + #endregion Constructors - #region properties + #region Properties public RawAcceleration AccelForm { get; } @@ -73,67 +53,33 @@ namespace grapher public SettingsManager Settings { get; } - public AccelOptions AccelerationOptions { get; } - - public OptionXY Sensitivity { get; } - - public Option Rotation { get; } - - public OptionXY Weight { get; } - - public CapOptions Cap { get; } - - public OffsetOptions Offset { get; } - - public Option Acceleration { get; } - - public Option LimitOrExponent { get; } - - public Option Midpoint { get; } + public ApplyOptions ApplyOptions { get; } public Button WriteButton { get; } + public Timer ButtonTimer { get; } + public MouseWatcher MouseWatcher { get; } public ToolStripMenuItem ScaleMenuItem { get; } - #endregion properties + #endregion Properties - #region methods + #region Methods public void UpdateActiveSettingsFromFields() { var settings = new DriverSettings { - rotation = Rotation.Field.Data, + rotation = ApplyOptions.Rotation.Field.Data, sensitivity = new Vec2<double> { - x = Sensitivity.Fields.X, - y = Sensitivity.Fields.Y - }, - combineMagnitudes = true, - modes = new Vec2<AccelMode> - { - x = (AccelMode)AccelerationOptions.AccelerationIndex - }, - args = new Vec2<AccelArgs> - { - x = new AccelArgs - { - offset = Offset.Offset, - legacy_offset = Offset.LegacyOffset, - weight = Weight.Fields.X, - gainCap = Cap.VelocityGainCap, - scaleCap = Cap.SensitivityCapX, - accel = Acceleration.Field.Data, - rate = Acceleration.Field.Data, - powerScale = Acceleration.Field.Data, - limit = LimitOrExponent.Field.Data, - exponent = LimitOrExponent.Field.Data, - powerExponent = LimitOrExponent.Field.Data, - midpoint = Midpoint.Field.Data - } + x = ApplyOptions.Sensitivity.Fields.X, + y = ApplyOptions.Sensitivity.Fields.Y }, + combineMagnitudes = ApplyOptions.IsWhole, + modes = ApplyOptions.GetModes(), + args = ApplyOptions.GetArgs(), minimumTime = .4 }; @@ -141,10 +87,17 @@ namespace grapher { AccelForm.Invoke((MethodInvoker)delegate { + WriteButtonDelay(); UpdateGraph(); }); }); - + RefreshOnRead(); + } + + public void RefreshOnRead() + { + UpdateGraph(); + UpdateShownActiveValues(); } public void UpdateGraph() @@ -154,29 +107,66 @@ namespace grapher Settings.ActiveAccel, Settings.RawAccelSettings.AccelerationSettings); AccelCharts.Bind(); - UpdateActiveValueLabels(); } - public void UpdateActiveValueLabels() + public void UpdateShownActiveValues() { var settings = Settings.RawAccelSettings.AccelerationSettings; - - Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); - Rotation.SetActiveValue(settings.rotation); - AccelerationOptions.SetActiveValue((int)settings.modes.x); - Offset.SetActiveValue(settings.args.x.offset, settings.args.y.offset); - Weight.SetActiveValues(settings.args.x.weight, settings.args.x.weight); - Acceleration.SetActiveValue(settings.args.x.accel); // rate, powerscale - LimitOrExponent.SetActiveValue(settings.args.x.limit); //exp, powerexp - Midpoint.SetActiveValue(settings.args.x.midpoint); - //Cap.SetActiveValues(Settings.ActiveAccel.GainCap, Settings.ActiveAccel.CapX, Settings.ActiveAccel.CapY, Settings.ActiveAccel.GainCapEnabled); + + AccelCharts.ShowActive(settings); + ApplyOptions.SetActiveValues(settings); + } + + private Timer SetupButtonTimer() + { + Timer buttonTimer = new Timer(); + buttonTimer.Enabled = true; + buttonTimer.Interval = Convert.ToInt32(ManagedAccel.WriteDelay); + buttonTimer.Tick += new System.EventHandler(OnButtonTimerTick); + return buttonTimer; + } + + private void SetupWriteButton() + { + WriteButton.Top = AccelCharts.SensitivityChart.Top + AccelCharts.SensitivityChart.Height - Constants.WriteButtonVerticalOffset; + SetWriteButtonDefault(); + } + + private void SetWriteButtonDefault() + { + WriteButton.Text = Constants.WriteButtonDefaultText; + WriteButton.Enabled = true; + } + + private void SetWriteButtonDelay() + { + WriteButton.Enabled = false; + WriteButton.Text = $"{Constants.WriteButtonDelayText} : {ButtonTimer.Interval} ms"; } private void OnScaleMenuItemClick(object sender, EventArgs e) { UpdateGraph(); } - #endregion methods + + private void OnWriteButtonClick(object sender, EventArgs e) + { + UpdateActiveSettingsFromFields(); + } + + private void OnButtonTimerTick(object sender, EventArgs e) + { + ButtonTimer.Stop(); + SetWriteButtonDefault(); + } + + private void WriteButtonDelay() + { + SetWriteButtonDelay(); + ButtonTimer.Start(); + } + + #endregion Methods } } diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs new file mode 100644 index 0000000..42a7b83 --- /dev/null +++ b/grapher/Models/AccelGUIFactory.cs @@ -0,0 +1,303 @@ +using grapher.Models.Calculations; +using grapher.Models.Options; +using grapher.Models.Serialized; +using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; + +namespace grapher.Models +{ + public static class AccelGUIFactory + { + #region Methods + + public static AccelGUI Construct( + RawAcceleration form, + ManagedAccel activeAccel, + Chart accelerationChart, + Chart accelerationChartY, + Chart velocityChart, + Chart velocityChartY, + Chart gainChart, + Chart gainChartY, + ComboBox accelTypeDropX, + ComboBox accelTypeDropY, + Button writeButton, + ToolStripMenuItem showVelocityGainToolStripMenuItem, + ToolStripMenuItem showLastMouseMoveMenuItem, + ToolStripMenuItem wholeVectorToolStripMenuItem, + ToolStripMenuItem byVectorComponentToolStripMenuItem, + ToolStripMenuItem velocityGainCapToolStripMenuItem, + ToolStripMenuItem legacyCapToolStripMenuItem, + ToolStripMenuItem gainOffsetToolStripMenuItem, + ToolStripMenuItem legacyOffsetToolStripMenuItem, + ToolStripMenuItem autoWriteMenuItem, + ToolStripMenuItem scaleMenuItem, + ToolStripTextBox dpiTextBox, + ToolStripTextBox pollRateTextBox, + TextBox sensitivityBoxX, + TextBox sensitivityBoxY, + TextBox rotationBox, + TextBox weightBoxX, + TextBox weightBoxY, + TextBox capBoxX, + TextBox capBoxY, + TextBox offsetBoxX, + TextBox offsetBoxY, + TextBox accelerationBoxX, + TextBox accelerationBoxY, + TextBox limitBoxX, + TextBox limitBoxY, + TextBox midpointBoxX, + TextBox midpointBoxY, + CheckBox sensXYLock, + CheckBox byComponentXYLock, + Label lockXYLabel, + Label sensitivityLabel, + Label rotationLabel, + Label weightLabelX, + Label weightLabelY, + Label capLabelX, + Label capLabelY, + Label offsetLabelX, + Label offsetLabelY, + Label constantOneLabelX, + Label constantOneLabelY, + Label constantTwoLabelX, + Label constantTwoLabelY, + Label constantThreeLabelX, + Label constantThreeLabelY, + Label activeValueTitleX, + Label activeValueTitleY, + Label sensitivityActiveXLabel, + Label sensitivityActiveYLabel, + Label rotationActiveLabel, + Label weightActiveXLabel, + Label weightActiveYLabel, + Label capActiveXLabel, + Label capActiveYLabel, + Label offsetActiveLabelX, + Label offsetActiveLabelY, + Label accelerationActiveLabelX, + Label accelerationActiveLabelY, + Label limitExpActiveLabelX, + Label limitExpActiveLabelY, + Label midpointActiveLabelX, + Label midpointActiveLabelY, + Label accelTypeActiveLabelX, + Label accelTypeActiveLabelY, + Label optionSetXTitle, + Label optionSetYTitle, + Label mouseLabel) + { + var accelCharts = new AccelCharts( + form, + new ChartXY(accelerationChart, accelerationChartY), + new ChartXY(velocityChart, velocityChartY), + new ChartXY(gainChart, gainChartY), + showVelocityGainToolStripMenuItem, + showLastMouseMoveMenuItem, + writeButton); + + var sensitivity = new OptionXY( + sensitivityBoxX, + sensitivityBoxY, + sensXYLock, + form, + 1, + sensitivityLabel, + new ActiveValueLabelXY( + new ActiveValueLabel(sensitivityActiveXLabel, activeValueTitleX), + new ActiveValueLabel(sensitivityActiveYLabel, activeValueTitleX)), + "Sensitivity"); + + var rotation = new Option( + rotationBox, + form, + 0, + rotationLabel, + 0, + new ActiveValueLabel(rotationActiveLabel, activeValueTitleX), + "Rotation"); + + var optionSetYLeft = rotation.Left + rotation.Width; + + 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 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, + 0, + offsetLabelX, + 0, + new ActiveValueLabel(offsetActiveLabelX, activeValueTitleX), + "Offset"); + + var offsetY = new Option( + offsetBoxY, + form, + 0, + offsetLabelY, + optionSetYLeft, + new ActiveValueLabel(offsetActiveLabelY, activeValueTitleY), + "Offset"); + + var offsetOptionsX = new OffsetOptions( + gainOffsetToolStripMenuItem, + legacyOffsetToolStripMenuItem, + offsetX); + + var offsetOptionsY = new OffsetOptions( + gainOffsetToolStripMenuItem, + legacyOffsetToolStripMenuItem, + offsetY); + + var accelerationX = new Option( + new Field(accelerationBoxX, form, 0), + constantOneLabelX, + new ActiveValueLabel(accelerationActiveLabelX, activeValueTitleX), + 0); + + var accelerationY = new Option( + new Field(accelerationBoxY, form, 0), + constantOneLabelY, + new ActiveValueLabel(accelerationActiveLabelY, activeValueTitleY), + optionSetYLeft); + + var limitOrExponentX = new Option( + new Field(limitBoxX, form, 2), + constantTwoLabelX, + new ActiveValueLabel(limitExpActiveLabelX, activeValueTitleX), + 0); + + var limitOrExponentY = new Option( + new Field(limitBoxY, form, 2), + constantTwoLabelY, + new ActiveValueLabel(limitExpActiveLabelY, activeValueTitleY), + optionSetYLeft); + + var midpointX = new Option( + new Field(midpointBoxX, form, 0), + constantThreeLabelX, + new ActiveValueLabel(midpointActiveLabelX, activeValueTitleY), + 0); + + var midpointY = new Option( + new Field(midpointBoxY, form, 0), + constantThreeLabelY, + new ActiveValueLabel(midpointActiveLabelY, activeValueTitleY), + optionSetYLeft); + + var capOptionsX = new CapOptions( + velocityGainCapToolStripMenuItem, + legacyCapToolStripMenuItem, + capX); + + var capOptionsY = new CapOptions( + velocityGainCapToolStripMenuItem, + legacyCapToolStripMenuItem, + capY); + + var accelerationOptionsX = new AccelTypeOptions( + accelTypeDropX, + accelerationX, + capOptionsX, + weightX, + offsetOptionsX, + limitOrExponentX, + midpointX, + writeButton, + new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); + + var accelerationOptionsY = new AccelTypeOptions( + accelTypeDropY, + accelerationY, + capOptionsY, + weightY, + offsetOptionsY, + limitOrExponentY, + midpointY, + writeButton, + new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); + + var optionsSetX = new AccelOptionSet( + optionSetXTitle, + activeValueTitleX, + rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation, + accelerationOptionsX); + + var optionsSetY = new AccelOptionSet( + optionSetYTitle, + activeValueTitleY, + rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation, + accelerationOptionsY); + + var applyOptions = new ApplyOptions( + wholeVectorToolStripMenuItem, + byVectorComponentToolStripMenuItem, + byComponentXYLock, + optionsSetX, + optionsSetY, + sensitivity, + rotation, + lockXYLabel, + accelCharts); + + var accelCalculator = new AccelCalculator( + new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI), + new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate)); + + var settings = new SettingsManager( + activeAccel, + accelCalculator.DPI, + accelCalculator.PollRate, + autoWriteMenuItem, + showLastMouseMoveMenuItem); + + return new AccelGUI( + form, + accelCalculator, + accelCharts, + settings, + applyOptions, + writeButton, + mouseLabel, + scaleMenuItem); + } + + #endregion Methods + } +} diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 102de8d..092a7aa 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -3,19 +3,12 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace grapher.Models.Calculations { public class AccelCalculator { - public const int DefaultDPI = 1200; - public const int DefaultPollRate = 1000; - public const int Resolution = 100; - public const double MaxMultiplier = 85; - public const double XYToCombinedRatio = 1.3; + #region Structs public struct MagnitudeData { @@ -24,6 +17,9 @@ namespace grapher.Models.Calculations public int y; } + #endregion Structs + + #region Constructors public AccelCalculator(Field dpi, Field pollRate) { @@ -31,6 +27,10 @@ namespace grapher.Models.Calculations PollRate = pollRate; } + #endregion Constructors + + #region Properties + public ReadOnlyCollection<MagnitudeData> MagnitudesCombined { get; private set; } public ReadOnlyCollection<MagnitudeData> MagnitudesX { get; private set; } @@ -47,6 +47,10 @@ namespace grapher.Models.Calculations private int Increment { get; set; } + #endregion Fields + + #region Methods + public void Calculate(AccelData data, ManagedAccel accel, DriverSettings settings) { ScaleByMouseSettings(); @@ -171,12 +175,14 @@ namespace grapher.Models.Calculations public void ScaleByMouseSettings() { var dpiPollFactor = DPI.Data / PollRate.Data; - CombinedMaxVelocity = dpiPollFactor * MaxMultiplier; - Increment = (int) Math.Floor(CombinedMaxVelocity / Resolution); - XYMaxVelocity = CombinedMaxVelocity * 1.5; + CombinedMaxVelocity = dpiPollFactor * Constants.MaxMultiplier; + Increment = (int)Math.Floor(CombinedMaxVelocity / Constants.Resolution); + XYMaxVelocity = CombinedMaxVelocity * Constants.XYToCombinedRatio; MagnitudesCombined = GetMagnitudes(); MagnitudesX = GetMagnitudesX(); MagnitudesY = GetMagnitudesY(); } + + #endregion Methods } } diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 20142a7..8c0c8ea 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace grapher.Models.Calculations { public class AccelChartData { + #region Constructors + public AccelChartData() { AccelPoints = new SortedDictionary<double, double>(); @@ -17,6 +17,10 @@ namespace grapher.Models.Calculations OutVelocityToPoints = new Dictionary<double, (double, double, double)>(); } + #endregion Constructors + + #region Properties + public SortedDictionary<double, double> AccelPoints { get; } public SortedDictionary<double, double> VelocityPoints { get; } @@ -27,6 +31,10 @@ namespace grapher.Models.Calculations public Dictionary<double, (double, double, double)> OutVelocityToPoints { get; } + #endregion Properties + + #region Methods + public void Clear() { AccelPoints.Clear(); @@ -57,5 +65,7 @@ namespace grapher.Models.Calculations return values; } } + + #endregion Methods } } diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index 683c67e..eef4d01 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -1,15 +1,11 @@ using grapher.Models.Charts; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static grapher.AccelCharts; namespace grapher.Models.Calculations { public class AccelData { + #region Constructors public AccelData( EstimatedPoints combined, @@ -25,6 +21,10 @@ namespace grapher.Models.Calculations EstimatedY = y; } + #endregion Constructors + + #region Properties + public AccelChartData Combined { get; } public AccelChartData X { get; } @@ -37,6 +37,10 @@ namespace grapher.Models.Calculations private EstimatedPoints EstimatedY { get; } + #endregion Properties + + #region Methods + public void Clear() { Combined.Clear(); @@ -70,5 +74,6 @@ namespace grapher.Models.Calculations EstimatedY.Gain.Set(inYVelocity, yGain); } + #endregion Methods } } diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 1aa3909..3f228c3 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -1,23 +1,15 @@ using grapher.Models.Calculations; using grapher.Models.Charts; +using grapher.Models.Serialized; using System; -using System.Collections.Generic; using System.Drawing; -using System.Linq; -using System.Security.Permissions; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using System.Windows.Forms.DataVisualization.Charting; namespace grapher { public class AccelCharts { - public const int ChartSeparationVertical = 10; - - /// <summary> Needed to show full contents in form. Unsure why. </summary> - public const int FormHeightPadding = 35; + #region Constructors public AccelCharts( Form form, @@ -25,7 +17,8 @@ namespace grapher ChartXY velocityChart, ChartXY gainChart, ToolStripMenuItem enableVelocityAndGain, - ICollection<CheckBox> checkBoxesXY) + ToolStripMenuItem enableLastMouseMove, + Button writeButton) { Estimated = new EstimatedPoints(); EstimatedX = new EstimatedPoints(); @@ -37,7 +30,8 @@ namespace grapher VelocityChart = velocityChart; GainChart = gainChart; EnableVelocityAndGain = enableVelocityAndGain; - CheckBoxesXY = checkBoxesXY; + EnableLastValue = enableLastMouseMove; + WriteButton = writeButton; SensitivityChart.SetPointBinds(Estimated.Sensitivity, EstimatedX.Sensitivity, EstimatedY.Sensitivity); VelocityChart.SetPointBinds(Estimated.Velocity, EstimatedX.Velocity, EstimatedY.Velocity); @@ -45,21 +39,28 @@ namespace grapher SensitivityChart.SetTop(0); VelocityChart.SetHeight(SensitivityChart.Height); - VelocityChart.SetTop(SensitivityChart.Height + ChartSeparationVertical); + VelocityChart.SetTop(SensitivityChart.Height + Constants.ChartSeparationVertical); GainChart.SetHeight(SensitivityChart.Height); - GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + ChartSeparationVertical); + GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + Constants.ChartSeparationVertical); Rectangle screenRectangle = ContaingForm.RectangleToScreen(ContaingForm.ClientRectangle); FormBorderHeight = screenRectangle.Top - ContaingForm.Top; EnableVelocityAndGain.Click += new System.EventHandler(OnEnableClick); - EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableCheckStateChange); + EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableVelocityGainCheckStateChange); + + EnableLastValue.CheckedChanged += new System.EventHandler(OnEnableLastMouseMoveCheckStateChange); HideVelocityAndGain(); + SensitivityChart.Show(); Combined = false; ShowCombined(); } + #endregion Constructors + + #region Properties + public Form ContaingForm { get; } public ChartXY SensitivityChart { get; } @@ -70,6 +71,10 @@ namespace grapher public ToolStripMenuItem EnableVelocityAndGain { get; } + private ToolStripMenuItem EnableLastValue { get; } + + private Button WriteButton { get; } + public AccelData AccelData { get; } private EstimatedPoints Estimated { get; } @@ -78,12 +83,14 @@ namespace grapher private EstimatedPoints EstimatedY { get; } - private ICollection<CheckBox> CheckBoxesXY { get; } - private bool Combined { get; set; } private int FormBorderHeight { get; } + #endregion Properties + + #region Methods + public void MakeDots(int x, int y, double timeInMs) { if (Combined) @@ -96,11 +103,14 @@ namespace grapher } } - public void DrawPoints() + public void DrawLastMovement() { - SensitivityChart.DrawPoints(); - VelocityChart.DrawPoints(); - GainChart.DrawPoints(); + if (EnableLastValue.Checked) + { + SensitivityChart.DrawLastMovementValue(); + VelocityChart.DrawLastMovementValue(); + GainChart.DrawLastMovementValue(); + } } public void Bind() @@ -119,9 +129,9 @@ namespace grapher } } - public void RefreshXY() + public void ShowActive(DriverSettings driverSettings) { - if (CheckBoxesXY.All(box => box.Checked)) + if (driverSettings.combineMagnitudes) { ShowCombined(); } @@ -131,12 +141,30 @@ namespace grapher } } + public void SetWidened() + { + SensitivityChart.SetWidened(); + VelocityChart.SetWidened(); + GainChart.SetWidened(); + UpdateFormWidth(); + AlignWriteButton(); + } + + public void SetNarrowed() + { + SensitivityChart.SetNarrowed(); + VelocityChart.SetNarrowed(); + GainChart.SetNarrowed(); + UpdateFormWidth(); + AlignWriteButton(); + } + private void OnEnableClick(object sender, EventArgs e) { EnableVelocityAndGain.Checked = !EnableVelocityAndGain.Checked; } - private void OnEnableCheckStateChange(object sender, EventArgs e) + private void OnEnableVelocityGainCheckStateChange(object sender, EventArgs e) { if (EnableVelocityAndGain.Checked) { @@ -148,14 +176,24 @@ namespace grapher } } + private void OnEnableLastMouseMoveCheckStateChange(object sender, EventArgs e) + { + if (!EnableLastValue.Checked) + { + SensitivityChart.ClearLastValue(); + VelocityChart.ClearLastValue(); + GainChart.ClearLastValue(); + } + } + private void ShowVelocityAndGain() { VelocityChart.Show(); GainChart.Show(); - ContaingForm.Height = SensitivityChart.Height + - ChartSeparationVertical + + ContaingForm.Height = SensitivityChart.Height + + Constants.ChartSeparationVertical + VelocityChart.Height + - ChartSeparationVertical + + Constants.ChartSeparationVertical + GainChart.Height + FormBorderHeight; } @@ -199,5 +237,12 @@ namespace grapher { ContaingForm.Width = SensitivityChart.Left + SensitivityChart.Width; } + + private void AlignWriteButton() + { + WriteButton.Left = SensitivityChart.Left / 2 - WriteButton.Width / 2; + } + + #endregion Methods } } diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 81874a2..30be229 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,26 +1,11 @@ -using grapher.Models.Charts; -using grapher.Models.Mouse; -using System; +using grapher.Models.Mouse; using System.Collections; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; -using static grapher.AccelCharts; namespace grapher { public class ChartXY { - #region Consts - - public const int ChartSeparationHorizontal = 10; - - #endregion Consts - #region Constructors public ChartXY(Chart chartX, Chart chartY) @@ -31,10 +16,16 @@ namespace grapher ChartY.Top = ChartX.Top; ChartY.Height = ChartX.Height; ChartY.Width = ChartX.Width; - ChartY.Left = ChartX.Left + ChartX.Width + ChartSeparationHorizontal; + ChartY.Left = ChartX.Left + ChartX.Width + Constants.ChartSeparationHorizontal; SetupChart(ChartX); SetupChart(ChartY); + + Combined = false; + SetCombined(); + + Widened = false; + SetWidened(); } #endregion Constructors @@ -82,6 +73,10 @@ namespace grapher public bool Combined { get; private set; } + public bool Widened { get; private set; } + + public bool Visible { get; private set; } + private PointData CombinedPointData { get; set; } private PointData XPointData { get; set; } @@ -134,7 +129,7 @@ namespace grapher YPointData = y; } - public void DrawPoints() + public void DrawLastMovementValue() { if(Combined) { @@ -147,6 +142,12 @@ namespace grapher } } + public void ClearLastValue() + { + ChartX.Series[1].Points.Clear(); + ChartY.Series[1].Points.Clear(); + } + public void Bind(IDictionary data) { ChartX.Series[0].Points.DataBindXY(data.Keys, data.Values); @@ -171,7 +172,7 @@ namespace grapher { if (Combined) { - if (ChartX.Visible) + if (Visible) { ChartY.Show(); } @@ -180,19 +181,56 @@ namespace grapher } } + public void SetWidened() + { + if (!Widened) + { + ChartX.Width = Constants.WideChartWidth; + ChartY.Width = Constants.WideChartWidth; + + ChartX.Left = Constants.WideChartLeft; + ChartY.Left = ChartX.Left + ChartX.Width + Constants.ChartSeparationHorizontal; + + Widened = true; + } + } + + public void SetNarrowed() + { + if (Widened) + { + ChartX.Width = Constants.NarrowChartWidth; + ChartY.Width = Constants.NarrowChartWidth; + + ChartX.Left = Constants.NarrowChartLeft; + ChartY.Left = ChartX.Left + ChartX.Width + Constants.ChartSeparationHorizontal; + + Widened = false; + } + } + public void Hide() { - ChartX.Hide(); - ChartY.Hide(); + if (Visible) + { + ChartX.Hide(); + ChartY.Hide(); + Visible = false; + } } public void Show() { - ChartX.Show(); - - if (!Combined) + if (!Visible) { - ChartY.Show(); + ChartX.Show(); + + if (!Combined) + { + ChartY.Show(); + } + + Visible = true; } } diff --git a/grapher/Models/Charts/EstimatedPoints.cs b/grapher/Models/Charts/EstimatedPoints.cs index fa0718b..f7ba3ce 100644 --- a/grapher/Models/Charts/EstimatedPoints.cs +++ b/grapher/Models/Charts/EstimatedPoints.cs @@ -1,14 +1,11 @@ using grapher.Models.Mouse; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace grapher.Models.Charts { public class EstimatedPoints { + #region Constructors + public EstimatedPoints() { Sensitivity = new PointData(); @@ -16,10 +13,16 @@ namespace grapher.Models.Charts Gain = new PointData(); } + #endregion Constructors + + #region Properties + public PointData Sensitivity { get; } public PointData Velocity { get; } public PointData Gain { get; } + + #endregion Properties } } diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs index 1810081..0d1813e 100644 --- a/grapher/Models/Fields/Field.cs +++ b/grapher/Models/Fields/Field.cs @@ -1,22 +1,12 @@ 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 { public class Field { - #region Constants - - public const string DefaultFormatString = "0.#########"; - - #endregion Constants - - #region Enums + #region Enumerations public enum FieldState { @@ -27,8 +17,13 @@ namespace grapher Unavailable, } - #endregion Enums + #endregion Enumerations + + #region Fields + + private double _data; + #endregion Fields #region Constructors @@ -36,11 +31,11 @@ namespace grapher { DefaultText = DecimalString(defaultData); Box = box; - Data = defaultData; + _data = defaultData; DefaultData = defaultData; State = FieldState.Undefined; ContainingForm = containingForm; - FormatString = DefaultFormatString; + FormatString = Constants.DefaultFieldFormatString; box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown); box.Leave += new System.EventHandler(FocusLeave); @@ -55,8 +50,6 @@ namespace grapher private Form ContainingForm { get; } - public double Data { get; private set; } - public string FormatString { get; set; } public string DefaultText { get; } @@ -65,6 +58,68 @@ namespace grapher public FieldState PreviousState { get; private set; } + public double Data { + get + { + if (Box.Visible) + { + return _data; + } + else + { + return DefaultData; + } + } + } + + public int Top + { + get + { + return Box.Top; + } + set + { + Box.Top = value; + } + } + + public int Height + { + get + { + return Box.Height; + } + set + { + Box.Height = value; + } + } + + public int Left + { + get + { + return Box.Left; + } + set + { + Box.Left = value; + } + } + + public int Width + { + get + { + return Box.Width; + } + set + { + Box.Width = value; + } + } + private double DefaultData { get; } #endregion Properties @@ -81,7 +136,7 @@ namespace grapher PreviousState = FieldState.Default; } - Data = DefaultData; + _data = DefaultData; Box.Text = DefaultText; ContainingForm.ActiveControl = null; } @@ -118,7 +173,7 @@ namespace grapher { SetToEntered(); - Data = value; + _data = value; Box.Text = DecimalString(Data); } @@ -197,7 +252,7 @@ namespace grapher { try { - Data = Convert.ToDouble(Box.Text); + _data = Convert.ToDouble(Box.Text); } catch { diff --git a/grapher/Models/Fields/FieldXY.cs b/grapher/Models/Fields/FieldXY.cs index 609af9d..15e6800 100644 --- a/grapher/Models/Fields/FieldXY.cs +++ b/grapher/Models/Fields/FieldXY.cs @@ -1,38 +1,36 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace grapher { public class FieldXY { - public const int DefaultSeparation = 4; + #region Constructors - public const string ShortenedFormatString = "0.###"; - - public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData, AccelCharts accelCharts) + public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData) { XField = new Field(xBox, containingForm, defaultData); YField = new Field(yBox, containingForm, defaultData); - YField.FormatString = ShortenedFormatString; + YField.FormatString = Constants.ShortenedFormatString; LockCheckBox = lockCheckBox; LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); - AccelCharts = accelCharts; - XField.Box.Width = (YField.Box.Left + YField.Box.Width - XField.Box.Left - DefaultSeparation) / 2; + XField.Box.Width = (YField.Box.Left + YField.Box.Width - XField.Box.Left - Constants.DefaultFieldSeparation) / 2; YField.Box.Width = XField.Box.Width; DefaultWidthX = XField.Box.Width; DefaultWidthY = YField.Box.Width; - YField.Box.Left = XField.Box.Left + XField.Box.Width + DefaultSeparation; + YField.Box.Left = XField.Box.Left + XField.Box.Width + Constants.DefaultFieldSeparation; CombinedWidth = DefaultWidthX + DefaultWidthY + YField.Box.Left - (XField.Box.Left + DefaultWidthX); SetCombined(); } + + #endregion Constructors + + #region Properties + public double X { get => XField.Data; @@ -59,7 +57,58 @@ namespace grapher public Field YField { get; } - private AccelCharts AccelCharts { get; } + public int CombinedWidth { get; } + + public int Left { + get + { + return XField.Left; + } + set + { + } + } + + public int Width + { + get + { + return CombinedWidth; + } + set + { + } + } + + public int Top + { + get + { + return XField.Top; + } + set + { + } + } + + public int Height + { + get + { + return XField.Height; + } + set + { + } + } + + public bool Visible + { + get + { + return XField.Box.Visible; + } + } private bool Combined { get; set; } @@ -67,7 +116,10 @@ namespace grapher private int DefaultWidthY { get; } - private int CombinedWidth { get; } + + #endregion Properties + + #region Methods private void CheckChanged(object sender, EventArgs e) { @@ -79,8 +131,6 @@ namespace grapher { SetSeparate(); } - - AccelCharts.RefreshXY(); } public void SetCombined() @@ -89,7 +139,7 @@ namespace grapher YField.SetToUnavailable(); YField.Box.Hide(); XField.Box.Width = CombinedWidth; - XField.FormatString = Field.DefaultFormatString; + XField.FormatString = Constants.DefaultFieldFormatString; } public void SetSeparate() @@ -99,7 +149,7 @@ namespace grapher XField.Box.Width = DefaultWidthX; YField.Box.Width = DefaultWidthY; - XField.FormatString = ShortenedFormatString; + XField.FormatString = Constants.ShortenedFormatString; if (XField.State == Field.FieldState.Default) { @@ -131,5 +181,7 @@ namespace grapher XField.Box.Hide(); YField.Box.Hide(); } + + #endregion Methods } } diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index fea4e2d..405110e 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -1,16 +1,12 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace grapher.Models.Mouse { public class MouseWatcher { + #region External /// <summary> /// Enumeration containing HID usage page flags. /// </summary> @@ -677,6 +673,10 @@ namespace grapher.Models.Mouse [DllImport("user32.dll")] public static extern int GetRawInputData(IntPtr hRawInput, RawInputCommand uiCommand, out RawInput pData, ref int pcbSize, int cbSizeHeader); + #endregion External + + #region Constructors + public MouseWatcher(Form containingForm, Label display, AccelCharts accelCharts) { ContainingForm = containingForm; @@ -695,6 +695,10 @@ namespace grapher.Models.Mouse PollTime = 1; } + #endregion Constructors + + #region Properties + private Form ContainingForm { get; } private Label Display { get; } @@ -703,6 +707,10 @@ namespace grapher.Models.Mouse private double PollTime { get; } + #endregion Properties + + #region Methods + public void OnMouseMove(int x, int y, double timeInMs) { Display.Text = $"Last (x, y): ({x}, {y})"; @@ -723,5 +731,7 @@ namespace grapher.Models.Mouse } } + + #endregion Methods } } diff --git a/grapher/Models/Mouse/PointData.cs b/grapher/Models/Mouse/PointData.cs index 12a6e73..374c52e 100644 --- a/grapher/Models/Mouse/PointData.cs +++ b/grapher/Models/Mouse/PointData.cs @@ -1,13 +1,11 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace grapher.Models.Mouse { public class PointData { + #region Constructors + public PointData() { Lock = new Object(); @@ -15,6 +13,10 @@ namespace grapher.Models.Mouse Y = new double[] { 0 }; } + #endregion Constructors + + #region Properties + public Object Lock { get; } private double[] X { get; set; } @@ -29,6 +31,10 @@ namespace grapher.Models.Mouse } } + #endregion Properties + + #region Methods + public void Get(out double[] x, out double[] y) { lock(Lock) @@ -37,5 +43,7 @@ namespace grapher.Models.Mouse y = Y; } } + + #endregion Methods } } diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs new file mode 100644 index 0000000..bc0d368 --- /dev/null +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -0,0 +1,117 @@ +using grapher.Models.Serialized; +using System.Drawing; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class AccelOptionSet + { + public AccelOptionSet( + Label title, + Label activeValuesTitle, + int topAnchor, + AccelTypeOptions accelTypeOptions) + { + OptionsTitle = title; + ActiveValuesTitle = activeValuesTitle; + TopAnchor = topAnchor; + Options = accelTypeOptions; + + ActiveValuesTitle.AutoSize = false; + ActiveValuesTitle.TextAlign = ContentAlignment.MiddleCenter; + + Options.ShowFull(); + + OptionsTitle.Top = TopAnchor; + IsTitleMode = true; + SetRegularMode(); + } + + public int TopAnchor { get; } + + public Label OptionsTitle { get; } + + public Label ActiveValuesTitle { get; } + + public AccelTypeOptions Options { get; } + + + public bool IsTitleMode { get; private set; } + + public void SetRegularMode() + { + if (IsTitleMode) + { + IsTitleMode = false; + + HideTitle(); + Options.ShowFull(); + } + } + + public void SetTitleMode(string title) + { + OptionsTitle.Text = title; + + if (!IsTitleMode) + { + IsTitleMode = true; + + Options.ShowShortened(); + DisplayTitle(); + } + } + + public void Hide() + { + OptionsTitle.Hide(); + ActiveValuesTitle.Hide(); + Options.Hide(); + } + + public void Show() + { + if (IsTitleMode) + { + OptionsTitle.Show(); + } + + ActiveValuesTitle.Show(); + Options.Show(); + } + + public void DisplayTitle() + { + OptionsTitle.Show(); + + Options.Top = OptionsTitle.Top + OptionsTitle.Height + Constants.OptionVerticalSeperation; + } + + public void HideTitle() + { + OptionsTitle.Hide(); + + Options.Top = TopAnchor; + } + + public void SetArgs(ref AccelArgs args) + { + Options.SetArgs(ref args); + } + + public AccelArgs GenerateArgs() + { + return Options.GenerateArgs(); + } + + public void SetActiveValues(int mode, AccelArgs args) + { + Options.SetActiveValues(mode, args); + } + + public void AlignActiveValues() + { + Options.AlignActiveValues(); + } + } +} diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs deleted file mode 100644 index 6b98274..0000000 --- a/grapher/Models/Options/AccelOptions.cs +++ /dev/null @@ -1,91 +0,0 @@ -using grapher.Layouts; -using grapher.Models.Options; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace grapher -{ - public class AccelOptions - { - public const int PossibleOptionsCount = 4; - public const int PossibleOptionsXYCount = 2; - - public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase> - { - new LinearLayout(), - new ClassicLayout(), - new NaturalLayout(), - new LogLayout(), - new SigmoidLayout(), - new PowerLayout(), - new NaturalGainLayout(), - new SigmoidGainLayout(), - new OffLayout() - }.ToDictionary(k => k.Name); - - public AccelOptions( - ComboBox accelDropdown, - Option[] options, - OptionXY[] optionsXY, - Button writeButton, - ActiveValueLabel activeValueLabel) - { - AccelDropdown = accelDropdown; - AccelDropdown.Items.Clear(); - AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); - AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); - - if (options.Length > PossibleOptionsCount) - { - throw new Exception("Layout given too many options."); - } - - if (optionsXY.Length > PossibleOptionsXYCount) - { - throw new Exception("Layout given too many options."); - } - - Options = options; - OptionsXY = optionsXY; - WriteButton = writeButton; - ActiveValueLabel = activeValueLabel; - - Layout("Off"); - } - - public Button WriteButton { get; } - - public ComboBox AccelDropdown { get; } - - public int AccelerationIndex { get; private set; } - - public ActiveValueLabel ActiveValueLabel { get; } - - public Option[] Options { get; } - - public OptionXY[] OptionsXY { get; } - - public void SetActiveValue(int index) - { - var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name; - ActiveValueLabel.SetValue(name); - } - - private void OnIndexChanged(object sender, EventArgs e) - { - var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); - Layout(accelerationTypeString); - } - - private void Layout(string type) - { - var accelerationType = AccelerationTypes[type]; - AccelerationIndex = accelerationType.Index; - accelerationType.Layout(Options, OptionsXY, WriteButton); - } - } -} diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs new file mode 100644 index 0000000..14c2019 --- /dev/null +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -0,0 +1,281 @@ +using grapher.Layouts; +using grapher.Models.Options; +using grapher.Models.Serialized; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace grapher +{ + public class AccelTypeOptions : OptionBase + { + #region Fields + + public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase> + { + new LinearLayout(), + new ClassicLayout(), + new NaturalLayout(), + new PowerLayout(), + new NaturalGainLayout(), + new SigmoidGainLayout(), + new OffLayout() + }.ToDictionary(k => k.Name); + + #endregion Fields + + #region Constructors + + public AccelTypeOptions( + ComboBox accelDropdown, + Option acceleration, + CapOptions cap, + Option weight, + OffsetOptions offset, + Option limitOrExponent, + Option midpoint, + Button writeButton, + ActiveValueLabel accelTypeActiveValue) + { + AccelDropdown = accelDropdown; + AccelDropdown.Items.Clear(); + AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); + AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); + + Acceleration = acceleration; + Cap = cap; + Weight = weight; + Offset = offset; + LimitOrExponent = limitOrExponent; + Midpoint = midpoint; + WriteButton = writeButton; + AccelTypeActiveValue = accelTypeActiveValue; + + AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; + AccelTypeActiveValue.Height = AccelDropdown.Height; + + Layout("Off"); + ShowingDefault = true; + } + + #endregion Constructors + + #region Properties + + public Button WriteButton { get; } + + public ComboBox AccelDropdown { get; } + + public int AccelerationIndex + { + get + { + return AccelerationType.Index; + } + } + + public LayoutBase AccelerationType { get; private set; } + + public ActiveValueLabel AccelTypeActiveValue { get; } + + public Option Acceleration { get; } + + public CapOptions Cap { get; } + + public Option Weight { get; } + + public OffsetOptions Offset { get; } + + public Option LimitOrExponent { get; } + + public Option Midpoint { get; } + + public override int Top + { + get + { + return AccelDropdown.Top; + } + set + { + AccelDropdown.Top = value; + AccelTypeActiveValue.Top = value; + Layout(value + AccelDropdown.Height + Constants.OptionVerticalSeperation); + } + } + + public override int Height + { + get + { + return AccelDropdown.Height; + } + } + + public override int Left + { + get + { + return AccelDropdown.Left; + } + set + { + AccelDropdown.Left = value; + } + } + + public override int Width + { + get + { + return AccelDropdown.Width; + } + set + { + AccelDropdown.Width = value; + } + } + + public override bool Visible + { + get + { + return AccelDropdown.Visible; + } + } + + private bool ShowingDefault { get; set; } + + #endregion Properties + + #region Methods + + public override void Hide() + { + AccelDropdown.Hide(); + AccelTypeActiveValue.Hide(); + + Acceleration.Hide(); + Cap.Hide(); + Weight.Hide(); + Offset.Hide(); + LimitOrExponent.Hide(); + Midpoint.Hide(); + } + + public void Show() + { + AccelDropdown.Show(); + AccelTypeActiveValue.Show(); + Layout(); + } + + public override void Show(string name) + { + Show(); + } + + public void SetActiveValues(int index, AccelArgs args) + { + var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name; + AccelTypeActiveValue.SetValue(name); + + Weight.SetActiveValue(args.weight); + Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0); + Offset.SetActiveValue(args.offset, args.legacy_offset); + Acceleration.SetActiveValue(args.accel); + LimitOrExponent.SetActiveValue(args.exponent); + Midpoint.SetActiveValue(args.midpoint); + } + + public void ShowFull() + { + if (ShowingDefault) + { + AccelDropdown.Text = Constants.AccelDropDownDefaultFullText; + } + + Left = Acceleration.Left + Constants.DropDownLeftSeparation; + Width = Acceleration.Width - Constants.DropDownLeftSeparation; + } + + public void ShowShortened() + { + if (ShowingDefault) + { + AccelDropdown.Text = Constants.AccelDropDownDefaultShortText; + } + + Left = Acceleration.Field.Left; + Width = Acceleration.Field.Width; + } + + public void SetArgs(ref AccelArgs args) + { + args.accel = Acceleration.Field.Data; + args.rate = Acceleration.Field.Data; + args.powerScale = Acceleration.Field.Data; + args.gainCap = Cap.VelocityGainCap; + args.scaleCap = Cap.SensitivityCap; + args.limit = LimitOrExponent.Field.Data; + args.exponent = LimitOrExponent.Field.Data; + args.powerExponent = LimitOrExponent.Field.Data; + args.offset = Offset.Offset; + args.legacy_offset = Offset.LegacyOffset; + args.midpoint = Midpoint.Field.Data; + args.weight = Weight.Field.Data; + } + + public AccelArgs GenerateArgs() + { + AccelArgs args = new AccelArgs(); + SetArgs(ref args); + return args; + } + + public override void AlignActiveValues() + { + AccelTypeActiveValue.Align(); + Acceleration.AlignActiveValues(); + Cap.AlignActiveValues(); + Offset.AlignActiveValues(); + Weight.AlignActiveValues(); + LimitOrExponent.AlignActiveValues(); + Midpoint.AlignActiveValues(); + } + + private void OnIndexChanged(object sender, EventArgs e) + { + var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); + Layout(accelerationTypeString, Beneath); + ShowingDefault = false; + } + + private void Layout(string type, int top = -1) + { + AccelerationType = AccelerationTypes[type]; + Layout(top); + } + + private void Layout(int top = -1) + { + if (top < 0) + { + top = Acceleration.Top; + } + + AccelerationType.Layout( + Acceleration, + Cap, + Weight, + Offset, + LimitOrExponent, + Midpoint, + WriteButton, + top); + } + + #endregion Methods + } +} diff --git a/grapher/Models/Options/ActiveValueLabel.cs b/grapher/Models/Options/ActiveValueLabel.cs index 138775a..18a4400 100644 --- a/grapher/Models/Options/ActiveValueLabel.cs +++ b/grapher/Models/Options/ActiveValueLabel.cs @@ -1,34 +1,42 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Drawing; using System.Windows.Forms; namespace grapher.Models.Options { public class ActiveValueLabel { - public const string DefaultFormatString = "0.######"; - public static readonly Color ActiveValueFontColor = Color.FromArgb(255, 65, 65, 65); + #region Constants + + + #endregion Constants + + #region Fields private string _prefix; private string _value; + #endregion Fields + + #region Constructors + public ActiveValueLabel(Label valueLabel, Label centeringLabel) { ValueLabel = valueLabel; - ValueLabel.ForeColor = ActiveValueFontColor; - Left = centeringLabel.Left; - Width = centeringLabel.Width; ValueLabel.AutoSize = false; ValueLabel.TextAlign = ContentAlignment.MiddleCenter; + ValueLabel.ForeColor = Constants.ActiveValueFontColor; - FormatString = DefaultFormatString; + CenteringLabel = centeringLabel; + Align(); + + FormatString = Constants.DefaultActiveValueFormatString; Prefix = string.Empty; } + #endregion Constructors + + #region Properties + public Label ValueLabel { get; } public string FormatString { get; set; } @@ -79,6 +87,37 @@ namespace grapher.Models.Options } } + public int Top + { + get + { + return ValueLabel.Top; + } + set + { + ValueLabel.Top = value; + } + } + + public int Height + { + get + { + return ValueLabel.Height; + } + + set + { + ValueLabel.Height = value; + } + } + + public Label CenteringLabel { get; } + + #endregion Properties + + #region Methods + public void Hide() { ValueLabel.Hide(); @@ -103,5 +142,13 @@ namespace grapher.Models.Options { ValueLabel.Text = string.IsNullOrWhiteSpace(Prefix) ? Value: $"{Prefix}: {Value}"; } + + public void Align() + { + Left = CenteringLabel.Left; + Width = CenteringLabel.Width; + } + + #endregion Methods } } diff --git a/grapher/Models/Options/ActiveValueLabelXY.cs b/grapher/Models/Options/ActiveValueLabelXY.cs index 12506e9..9498c66 100644 --- a/grapher/Models/Options/ActiveValueLabelXY.cs +++ b/grapher/Models/Options/ActiveValueLabelXY.cs @@ -1,15 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace grapher.Models.Options +namespace grapher.Models.Options { public class ActiveValueLabelXY { - public const int ActiveLabelXYSeparation = 2; - public const string ShortenedFormatString = "0.###"; + #region Constants + + + #endregion Constants + + #region Constructors public ActiveValueLabelXY( ActiveValueLabel x, @@ -18,26 +16,57 @@ namespace grapher.Models.Options X = x; Y = y; - FullWidth = x.Width; - ShortenedWidth = (FullWidth - ActiveLabelXYSeparation) / 2; - - Y.Left = X.Left + ShortenedWidth + ActiveLabelXYSeparation; + Align(x.Width); Y.Width = ShortenedWidth; - Y.FormatString = ShortenedFormatString; + Y.FormatString = Constants.ShortenedFormatString; Combined = false; SetCombined(); } + #endregion Constructors + + #region Properties + public ActiveValueLabel X { get; } public ActiveValueLabel Y { get; } public bool Combined { get; private set; } - private int FullWidth { get; } + public int Left + { + get + { + return X.Left; + } + set + { + X.Left = value; + SetYLeft(); + } + } + + public int Height + { + get + { + return X.Height; + } + set + { + X.Height = value; + Y.Height = value; + } + } + + private int FullWidth { get; set; } + + private int ShortenedWidth { get; set; } - private int ShortenedWidth { get; } + #endregion Properties + + #region Methods public void SetValues(double x, double y) { @@ -58,7 +87,7 @@ namespace grapher.Models.Options { if (!Combined) { - X.FormatString = ActiveValueLabel.DefaultFormatString; + X.FormatString = Constants.DefaultActiveValueFormatString; X.Width = FullWidth; X.Prefix = string.Empty; Y.Hide(); @@ -71,7 +100,7 @@ namespace grapher.Models.Options { if (Combined) { - X.FormatString = ShortenedFormatString; + X.FormatString = Constants.ShortenedFormatString; X.Width = ShortenedWidth; X.Prefix = "X"; Y.Prefix = "Y"; @@ -80,5 +109,35 @@ namespace grapher.Models.Options Combined = false; } + + public void AlignActiveValues() + { + Align(X.CenteringLabel.Width); + + if (Combined) + { + X.Width = FullWidth; + } + else + { + X.Width = ShortenedWidth; + } + } + + private void Align (int width) + { + FullWidth = width; + ShortenedWidth = (FullWidth - Constants.ActiveLabelXYSeparation) / 2; + + SetYLeft(); + Y.Width = ShortenedWidth; + } + + private void SetYLeft() + { + Y.Left = X.Left + ShortenedWidth + Constants.ActiveLabelXYSeparation; + } + + #endregion Methods } } diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs new file mode 100644 index 0000000..241fe50 --- /dev/null +++ b/grapher/Models/Options/ApplyOptions.cs @@ -0,0 +1,255 @@ +using grapher.Models.Serialized; +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class ApplyOptions + { + #region Constructors + + public ApplyOptions( + ToolStripMenuItem wholeVectorMenuItem, + ToolStripMenuItem byComponentMenuItem, + CheckBox byComponentVectorXYLock, + AccelOptionSet optionSetX, + AccelOptionSet optionSetY, + OptionXY sensitivity, + Option rotation, + Label lockXYLabel, + AccelCharts accelCharts) + { + WholeVectorMenuItem = wholeVectorMenuItem; + ByComponentVectorMenuItem = byComponentMenuItem; + + WholeVectorMenuItem.Click += new System.EventHandler(OnWholeClicked); + ByComponentVectorMenuItem.Click += new System.EventHandler(OnByComponentClicked); + + WholeVectorMenuItem.CheckedChanged += new System.EventHandler(OnWholeCheckedChange); + ByComponentVectorMenuItem.CheckedChanged += new System.EventHandler(OnByComponentCheckedChange); + + ByComponentVectorXYLock = byComponentVectorXYLock; + OptionSetX = optionSetX; + OptionSetY = optionSetY; + Sensitivity = sensitivity; + Rotation = rotation; + LockXYLabel = lockXYLabel; + AccelCharts = accelCharts; + + LockXYLabel.AutoSize = false; + LockXYLabel.TextAlign = ContentAlignment.MiddleCenter; + + ByComponentVectorXYLock.CheckedChanged += new System.EventHandler(OnByComponentXYLockChecked); + ByComponentVectorXYLock.Checked = true; + + Rotation.SnapTo(Sensitivity); + + EnableWholeApplication(); + } + + #endregion Constructors + + #region Properties + + public ToolStripMenuItem WholeVectorMenuItem { get; } + + public ToolStripMenuItem ByComponentVectorMenuItem { get; } + + public CheckBox ByComponentVectorXYLock { get; } + + public AccelOptionSet OptionSetX { get; } + + public AccelOptionSet OptionSetY { get; } + + public OptionXY Sensitivity { get; } + + public Option Rotation { get; } + + public AccelCharts AccelCharts { get; } + + public Label ActiveValueTitleY { get; } + + public Label LockXYLabel { get; } + + public bool IsWhole { get; private set; } + + #endregion Properties + + #region Methods + + public Vec2<AccelMode> GetModes() + { + var xMode = (AccelMode)OptionSetX.Options.AccelerationIndex; + + return new Vec2<AccelMode> + { + x = xMode, + y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.Options.AccelerationIndex + }; + } + + public Vec2<AccelArgs> GetArgs() + { + var xArgs = OptionSetX.GenerateArgs(); + + return new Vec2<AccelArgs> + { + x = xArgs, + y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs() + }; + + } + + public void SetActiveValues( + double xSens, + double ySens, + double rotation, + int xMode, + int yMode, + AccelArgs xArgs, + AccelArgs yArgs, + bool isWhole) + { + Sensitivity.SetActiveValues(xSens, ySens); + Rotation.SetActiveValue(rotation); + OptionSetX.SetActiveValues(xMode, xArgs); + OptionSetY.SetActiveValues(yMode, yArgs); + WholeVectorMenuItem.Checked = isWhole; + ByComponentVectorMenuItem.Checked = !isWhole; + } + + public void SetActiveValues(DriverSettings settings) + { + SetActiveValues( + settings.sensitivity.x, + settings.sensitivity.x, + settings.rotation, + (int)settings.modes.x, + (int)settings.modes.y, + settings.args.x, + settings.args.y, + settings.combineMagnitudes); + } + + public void OnWholeClicked(object sender, EventArgs e) + { + if (!WholeVectorMenuItem.Checked) + { + WholeVectorMenuItem.Checked = true; + ByComponentVectorMenuItem.Checked = false; + } + } + + public void OnByComponentClicked(object sender, EventArgs e) + { + if (!ByComponentVectorMenuItem.Checked) + { + WholeVectorMenuItem.Checked = false; + ByComponentVectorMenuItem.Checked = true; + } + } + + public void OnWholeCheckedChange(object sender, EventArgs e) + { + if (WholeVectorMenuItem.Checked) + { + EnableWholeApplication(); + } + } + + public void OnByComponentCheckedChange(object sender, EventArgs e) + { + if (ByComponentVectorMenuItem.Checked) + { + EnableByComponentApplication(); + } + } + + public void ShowWholeSet() + { + OptionSetX.SetRegularMode(); + OptionSetY.Hide(); + AccelCharts.SetWidened(); + SetActiveTitlesWhole(); + } + + public void ShowByComponentAsOneSet() + { + OptionSetX.SetTitleMode("X = Y"); + OptionSetY.Hide(); + AccelCharts.SetWidened(); + SetActiveTitlesByComponents(); + } + + public void ShowByComponentAsTwoSets() + { + OptionSetX.SetTitleMode("X"); + OptionSetY.SetTitleMode("Y"); + OptionSetY.Show(); + AccelCharts.SetNarrowed(); + } + + public void ShowByComponentSet() + { + if (ByComponentVectorXYLock.Checked) + { + ShowByComponentAsOneSet(); + } + else + { + ShowByComponentAsTwoSets(); + } + } + + private void OnByComponentXYLockChecked(object sender, EventArgs e) + { + if (!IsWhole) + { + ShowByComponentSet(); + } + } + + public void EnableWholeApplication() + { + IsWhole = true; + ByComponentVectorXYLock.Hide(); + ShowWholeSet(); + } + + public void EnableByComponentApplication() + { + IsWhole = false; + ByComponentVectorXYLock.Show(); + ShowByComponentSet(); + } + + private void SetActiveTitlesWhole() + { + OptionSetX.ActiveValuesTitle.Left = OptionSetX.Options.Left + OptionSetX.Options.Width; + LockXYLabel.Width = (AccelCharts.SensitivityChart.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; + AlignActiveValues(); + } + + private void SetActiveTitlesByComponents() + { + OptionSetY.ActiveValuesTitle.Left = OptionSetY.Options.Left + OptionSetY.Options.Width; + OptionSetY.ActiveValuesTitle.Width = Constants.NarrowChartLeft - OptionSetY.ActiveValuesTitle.Left; + AlignActiveValues(); + } + + private void AlignActiveValues() + { + OptionSetX.AlignActiveValues(); + OptionSetY.AlignActiveValues(); + Sensitivity.AlignActiveValues(); + Rotation.AlignActiveValues(); + } + + #endregion Methods + } +} diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs index 87bac88..5e47d7b 100644 --- a/grapher/Models/Options/CapOptions.cs +++ b/grapher/Models/Options/CapOptions.cs @@ -1,29 +1,27 @@ using grapher.Models.Options; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace grapher { - public class CapOptions + public class CapOptions : OptionBase { + #region Constants - public const string GainCapFormatString = "0.##"; + + #endregion Constants + + #region Constructors public CapOptions( ToolStripMenuItem velocityGainCapCheck, ToolStripMenuItem legacyCapCheck, - OptionXY capOption, - OptionXY weightOption) + Option capOption) { VelocityGainCapCheck = velocityGainCapCheck; LegacyCapCheck = legacyCapCheck; CapOption = capOption; - WeightOption = weightOption; LegacyCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick); VelocityGainCapCheck.Click += new System.EventHandler(OnVelocityGainCapCheckClick); @@ -34,20 +32,24 @@ namespace grapher EnableVelocityGainCap(); } + #endregion Constructors + + #region Properties + public ToolStripMenuItem LegacyCapCheck { get; } public ToolStripMenuItem VelocityGainCapCheck { get; } - public OptionXY CapOption { get; } + public Option CapOption { get; } - public OptionXY WeightOption { get; } + public bool IsSensitivityGain { get; private set; } - public double SensitivityCapX { + public double SensitivityCap { get { if (IsSensitivityGain) { - return CapOption.Fields.X; + return CapOption.Field.Data; } else { @@ -56,52 +58,122 @@ namespace grapher } } - public double SensitivityCapY { + public double VelocityGainCap { get { if (IsSensitivityGain) { - return CapOption.Fields.Y; + return 0; } else { - return 0; + return CapOption.Field.Data; } } } - public double VelocityGainCap { + public override int Top + { + get + { + return CapOption.Top; + } + set + { + CapOption.Top = value; + } + } + + public override int Height + { get { - if (IsSensitivityGain) - { - return 0; - } - else - { - return CapOption.Fields.X; - } + return CapOption.Height; } } - public bool IsSensitivityGain { get; private set; } + public override int Left + { + get + { + return CapOption.Left; + } + set + { + CapOption.Left = value; + } + } + + public override int Width + { + get + { + return CapOption.Width; + } + set + { + CapOption.Width = value; + } + } - public void SetActiveValues(double gainCap, double sensCapX, double sensCapY, bool capGainEnabled) + public override bool Visible + { + get + { + return CapOption.Visible; + } + } + + #endregion Properties + + #region Methods + + public override void Hide() + { + CapOption.Hide(); + } + + public void Show() + { + CapOption.Show(); + } + + public override void Show(string name) + { + CapOption.Show(name); + } + + public void SnapTo(Option option) + { + Top = option.Top + option.Height + Constants.OptionVerticalSeperation; + } + + + public void SetActiveValues(double gainCap, double sensCap, bool capGainEnabled) { if (capGainEnabled) { - CapOption.ActiveValueLabels.X.FormatString = GainCapFormatString; - CapOption.ActiveValueLabels.X.Prefix = "Gain"; - CapOption.SetActiveValues(gainCap, gainCap); + CapOption.ActiveValueLabel.FormatString = Constants.GainCapFormatString; + CapOption.ActiveValueLabel.Prefix = "Gain"; + CapOption.SetActiveValue(gainCap); + LegacyCapCheck.Checked = true; + VelocityGainCapCheck.Checked = false; } else { - CapOption.ActiveValueLabels.X.FormatString = ActiveValueLabel.DefaultFormatString; - CapOption.ActiveValueLabels.X.Prefix = string.Empty; - CapOption.SetActiveValues(sensCapX, sensCapY); + CapOption.ActiveValueLabel.FormatString = Constants.DefaultActiveValueFormatString; + CapOption.ActiveValueLabel.Prefix = string.Empty; + CapOption.SetActiveValue(sensCap); + LegacyCapCheck.Checked = false; + VelocityGainCapCheck.Checked = true; } } + public override void AlignActiveValues() + { + CapOption.AlignActiveValues(); + } + void OnSensitivityCapCheckClick(object sender, EventArgs e) { if (!LegacyCapCheck.Checked) @@ -139,19 +211,15 @@ namespace grapher void EnableSensitivityCap() { IsSensitivityGain = true; - CapOption.Fields.LockCheckBox.Enabled = true; - WeightOption.Fields.LockCheckBox.Enabled = true; CapOption.SetName("Sensitivity Cap"); } void EnableVelocityGainCap() { IsSensitivityGain = false; - CapOption.Fields.LockCheckBox.Checked = true; - CapOption.Fields.LockCheckBox.Enabled = false; - WeightOption.Fields.LockCheckBox.Checked = true; - WeightOption.Fields.LockCheckBox.Enabled = false; CapOption.SetName("Velocity Gain Cap"); } + + #endregion Methods } } diff --git a/grapher/Models/Options/IOption.cs b/grapher/Models/Options/IOption.cs new file mode 100644 index 0000000..fff1623 --- /dev/null +++ b/grapher/Models/Options/IOption.cs @@ -0,0 +1,23 @@ +namespace grapher.Models.Options +{ + public interface IOption + { + int Top { get; set; } + + int Height { get; } + + int Left { get; } + + int Width { get; } + + int Beneath { get; } + + bool Visible { get; } + + void Show(string name); + + void Hide(); + + void SnapTo(IOption option); + } +} diff --git a/grapher/Models/Options/OffsetOptions.cs b/grapher/Models/Options/OffsetOptions.cs index 0b01ab9..b351ab5 100644 --- a/grapher/Models/Options/OffsetOptions.cs +++ b/grapher/Models/Options/OffsetOptions.cs @@ -1,13 +1,9 @@ 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 OffsetOptions + public class OffsetOptions : OptionBase { public OffsetOptions( ToolStripMenuItem velocityGainOffsetCheck, @@ -65,6 +61,73 @@ namespace grapher.Models.Options } } + public override int Top + { + get + { + return OffsetOption.Top; + } + set + { + OffsetOption.Top = value; + } + } + + public override int Height + { + get + { + return OffsetOption.Height; + } + } + + public override int Left + { + get + { + return OffsetOption.Left; + } + set + { + OffsetOption.Left = value; + } + } + + public override int Width + { + get + { + return OffsetOption.Width; + } + set + { + OffsetOption.Width = value; + } + } + + public override bool Visible + { + get + { + return OffsetOption.Visible; + } + } + + public override void Hide() + { + OffsetOption.Hide(); + } + + public void Show() + { + OffsetOption.Show(); + } + + public override void Show(string name) + { + OffsetOption.Show(name); + } + public void SetActiveValue(double offset, double legacyOffset) { if (offset > 0) @@ -77,6 +140,11 @@ namespace grapher.Models.Options } } + public override void AlignActiveValues() + { + OffsetOption.AlignActiveValues(); + } + public void OnVelocityGainOffsetClick(object sender, EventArgs e) { if (!VelocityGainOffsetCheck.Checked) diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs index b0ef374..5dc022b 100644 --- a/grapher/Models/Options/Option.cs +++ b/grapher/Models/Options/Option.cs @@ -1,23 +1,30 @@ using grapher.Models.Options; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace grapher { - public class Option + public class Option : OptionBase { + #region Constructors + public Option( Field field, Label label, - ActiveValueLabel activeValueLabel) + ActiveValueLabel activeValueLabel, + int left) { Field = field; Label = label; ActiveValueLabel = activeValueLabel; + Left = left; + + label.AutoSize = false; + label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + label.Width = Field.Left - left - Constants.OptionLabelBoxSeperation; + label.Height = Field.Height; + + ActiveValueLabel.Left = Field.Left + Field.Width; + ActiveValueLabel.Height = Field.Height; } public Option( @@ -25,11 +32,13 @@ namespace grapher Form containingForm, double defaultData, Label label, + int left, ActiveValueLabel activeValueLabel) : this( new Field(box, containingForm, defaultData), label, - activeValueLabel) + activeValueLabel, + left) { } @@ -38,6 +47,7 @@ namespace grapher Form containingForm, double defaultData, Label label, + int left, ActiveValueLabel activeValueLabel, string startingName) : this( @@ -45,22 +55,82 @@ namespace grapher containingForm, defaultData, label, + left, activeValueLabel) { SetName(startingName); } + #endregion Constructors + + #region Properties + public Field Field { get; } public Label Label { get; } public ActiveValueLabel ActiveValueLabel { get; } + public override int Top + { + get + { + return Field.Top; + } + set + { + Field.Top = value; + Label.Top = value; + ActiveValueLabel.Top = value; + } + } + + public override int Height + { + get + { + return Field.Height; + } + } + + public override int Left + { + get + { + return Label.Left; + } + set + { + Label.Left = value; + } + } + public override int Width + { + get + { + return Field.Left + Field.Width - Label.Left; + } + set + { + } + } + + public override bool Visible + { + get + { + return Field.Box.Visible; + } + } + + #endregion Properties + + #region Methods + public void SetName(string name) { Label.Text = name; //Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); //Centered - Label.Left = Convert.ToInt32(Field.Box.Left - Label.Width - 10); //Right-aligned } public void SetActiveValue(double value) @@ -68,7 +138,7 @@ namespace grapher ActiveValueLabel.SetValue(value); } - public void Hide() + public override void Hide() { Field.Box.Hide(); Label.Hide(); @@ -87,11 +157,18 @@ namespace grapher ActiveValueLabel.SetValue(value); } - public void Show(string name) + public override void Show(string name) { SetName(name); Show(); } + + public override void AlignActiveValues() + { + ActiveValueLabel.Align(); + } + + #endregion Methods } } diff --git a/grapher/Models/Options/OptionBase.cs b/grapher/Models/Options/OptionBase.cs new file mode 100644 index 0000000..5f6dca1 --- /dev/null +++ b/grapher/Models/Options/OptionBase.cs @@ -0,0 +1,33 @@ +namespace grapher.Models.Options +{ + public abstract class OptionBase : IOption + { + public abstract int Top { get; set; } + + public abstract int Height { get; } + + public abstract int Left { get; set; } + + public abstract int Width { get; set; } + + public int Beneath { + get + { + return Top + Height + Constants.OptionVerticalSeperation; + } + } + + public abstract bool Visible { get; } + + public abstract void Show(string Name); + + public abstract void Hide(); + + public abstract void AlignActiveValues(); + + public virtual void SnapTo(IOption option) + { + Top = option.Beneath; + } + } +} diff --git a/grapher/Models/Options/OptionXY.cs b/grapher/Models/Options/OptionXY.cs index 8e22617..6d6129a 100644 --- a/grapher/Models/Options/OptionXY.cs +++ b/grapher/Models/Options/OptionXY.cs @@ -1,20 +1,18 @@ using grapher.Models.Options; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace grapher { - public class OptionXY + public class OptionXY : OptionBase { + #region Constructors public OptionXY(FieldXY fields, Label label, ActiveValueLabelXY activeValueLabels) { Fields = fields; Label = label; ActiveValueLabels = activeValueLabels; + ActiveValueLabels.Left = fields.CombinedWidth + fields.Left; } public OptionXY( @@ -24,9 +22,8 @@ namespace grapher Form containingForm, double defaultData, Label label, - AccelCharts accelCharts, ActiveValueLabelXY activeValueLabels) - : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label, activeValueLabels) + : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData), label, activeValueLabels) { } @@ -38,8 +35,7 @@ namespace grapher double defaultData, Label label, ActiveValueLabelXY activeValueLabels, - string startingName, - AccelCharts accelCharts): + string startingName): this( xBox, yBox, @@ -47,18 +43,76 @@ namespace grapher containingForm, defaultData, label, - accelCharts, activeValueLabels) { SetName(startingName); } + #endregion Constructors + + #region Properties + public FieldXY Fields { get; } public Label Label { get; } public ActiveValueLabelXY ActiveValueLabels { get; } + public override int Top + { + get + { + return Fields.Top; + } + set + { + Fields.Top = value; + } + } + + public override int Height + { + get + { + return Fields.Height; + } + } + + public override int Left + { + get + { + return Fields.Left; + } + set + { + Fields.Left = value; + } + } + + public override int Width + { + get + { + return Fields.Width; + } + set + { + Fields.Width = value; + } + } + + public override bool Visible + { + get + { + return Fields.Visible; + } + } + #endregion Properties + + #region Methods + public void SetName(string name) { Label.Text = name; @@ -71,7 +125,12 @@ namespace grapher ActiveValueLabels.SetValues(x, y); } - public void Hide() + public override void AlignActiveValues() + { + ActiveValueLabels.AlignActiveValues(); + } + + public override void Hide() { Fields.Hide(); Fields.LockCheckBox.Hide(); @@ -85,12 +144,13 @@ namespace grapher Label.Show(); } - public void Show(string name) + public override void Show(string name) { SetName(name); Show(); } + #endregion Methods } } diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs index cdccf88..d7c9444 100644 --- a/grapher/Models/Serialized/DriverSettings.cs +++ b/grapher/Models/Serialized/DriverSettings.cs @@ -4,11 +4,17 @@ using System.Threading; namespace grapher.Models.Serialized { + #region Enumerations + public enum AccelMode { - linear, classic, natural, logarithmic, sigmoid, naturalgain, sigmoidgain, power, noaccel + linear, classic, natural, naturalgain, sigmoidgain, power, noaccel } + #endregion Enumerations + + #region Structs + [StructLayout(LayoutKind.Sequential)] public struct AccelArgs { @@ -33,10 +39,14 @@ namespace grapher.Models.Serialized public T y; } + #endregion Structs + [StructLayout(LayoutKind.Sequential)] [Serializable] public class DriverSettings { + #region Fields + private static readonly IntPtr UnmanagedSettingsHandle = Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>()); private static object UnmanagedSettingsLock = new object(); @@ -48,6 +58,10 @@ namespace grapher.Models.Serialized public Vec2<double> sensitivity; public double minimumTime; + #endregion Fields + + #region Methods + public static DriverSettings GetActive() { DriverInterop.GetActiveSettings(UnmanagedSettingsHandle); @@ -97,5 +111,7 @@ namespace grapher.Models.Serialized */ return true; } + + #endregion Methods } } diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index 7c8e9a4..2543104 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -1,17 +1,13 @@ using Newtonsoft.Json; using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace grapher.Models.Serialized { [Serializable] public class GUISettings { + #region Constructors + public GUISettings() {} public GUISettings(bool autoWrite, int dpi, int pollRate) @@ -21,6 +17,10 @@ namespace grapher.Models.Serialized PollRate = pollRate; } + #endregion Constructors + + #region Properties + [JsonProperty(Order = 1)] public bool AutoWriteToDriverOnStartup { get; set; } @@ -29,5 +29,10 @@ namespace grapher.Models.Serialized [JsonProperty(Order = 3)] public int PollRate { get; set; } + + [JsonProperty(Order = 4)] + public bool ShowLastMouseMove { get; set; } + + #endregion Properties } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 7aed917..3f5aebc 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -1,26 +1,25 @@ using Newtonsoft.Json; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace grapher.Models.Serialized { [Serializable] public class RawAccelSettings { - public const string DefaultSettingsFileName = @"settings.json"; + #region Fields + public static readonly string ExecutingDirectory = AppDomain.CurrentDomain.BaseDirectory; - public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, DefaultSettingsFileName); + public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, Constants.DefaultSettingsFileName); public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error, }; + #endregion Fields + + #region Constructors + public RawAccelSettings() { } public RawAccelSettings( @@ -31,10 +30,18 @@ namespace grapher.Models.Serialized GUISettings = guiSettings; } + #endregion Constructors + + #region Properties + public GUISettings GUISettings { get; set; } public DriverSettings AccelerationSettings { get; set; } + #endregion Properties + + #region Methods + public static RawAccelSettings Load() { return Load(DefaultSettingsFile); @@ -75,5 +82,7 @@ namespace grapher.Models.Serialized { File.WriteAllText(file, JsonConvert.SerializeObject(this, Formatting.Indented)); } + + #endregion Methods } } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index c300bde..ccffc3f 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -6,18 +6,26 @@ namespace grapher.Models.Serialized { public class SettingsManager { + #region Constructors + public SettingsManager( ManagedAccel activeAccel, Field dpiField, Field pollRateField, - ToolStripMenuItem autoWrite) + ToolStripMenuItem autoWrite, + ToolStripMenuItem showLastMouseMove) { ActiveAccel = activeAccel; DpiField = dpiField; PollRateField = pollRateField; AutoWriteMenuItem = autoWrite; + ShowLastMouseMoveMenuItem = showLastMouseMove; } + #endregion Constructors + + #region Properties + public ManagedAccel ActiveAccel { get; } public RawAccelSettings RawAccelSettings { get; private set; } @@ -28,6 +36,12 @@ namespace grapher.Models.Serialized private ToolStripMenuItem AutoWriteMenuItem { get; set; } + private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } + + #endregion Properties + + #region Methods + public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null) { settings.SendToDriverAndUpdate(ActiveAccel, () => @@ -37,7 +51,8 @@ namespace grapher.Models.Serialized { AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, }; RawAccelSettings.Save(); @@ -53,6 +68,7 @@ namespace grapher.Models.Serialized DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; + ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; } public void Startup() @@ -80,9 +96,12 @@ namespace grapher.Models.Serialized { AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, }); RawAccelSettings.Save(); } + + #endregion Methods } } |