diff options
| author | a1xd <[email protected]> | 2021-09-06 23:24:51 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-09-23 22:33:13 -0400 |
| commit | a8d48325d5e6fe0466502b865c82317b6f7410a2 (patch) | |
| tree | a1d42734cda76cdf2a0b0c8134ef25f4729e99b3 /grapher | |
| parent | increase lut points capacity to 257 (diff) | |
| download | rawaccel-a8d48325d5e6fe0466502b865c82317b6f7410a2.tar.xz rawaccel-a8d48325d5e6fe0466502b865c82317b6f7410a2.zip | |
get grapher building
Diffstat (limited to 'grapher')
24 files changed, 454 insertions, 269 deletions
diff --git a/grapher/DeviceMenuForm.Designer.cs b/grapher/DeviceMenuForm.Designer.cs new file mode 100644 index 0000000..6b05645 --- /dev/null +++ b/grapher/DeviceMenuForm.Designer.cs @@ -0,0 +1,51 @@ + +namespace grapher +{ + partial class DeviceMenuForm + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.SuspendLayout(); + // + // DeviceMenuForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(584, 361); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "DeviceMenuForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Device Menu"; + this.ResumeLayout(false); + + } + + #endregion + } +}
\ No newline at end of file diff --git a/grapher/DeviceMenuForm.cs b/grapher/DeviceMenuForm.cs new file mode 100644 index 0000000..00b36a8 --- /dev/null +++ b/grapher/DeviceMenuForm.cs @@ -0,0 +1,21 @@ +using grapher.Models.Serialized; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public partial class DeviceMenuForm : Form + { + public DeviceMenuForm(SettingsManager sm) + { + InitializeComponent(); + } + } +} diff --git a/grapher/DeviceMenuForm.resx b/grapher/DeviceMenuForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/grapher/DeviceMenuForm.resx @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root>
\ No newline at end of file diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 203397b..f15bce9 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -71,6 +71,12 @@ namespace grapher System.Windows.Forms.DataVisualization.Charting.Title title6 = new System.Windows.Forms.DataVisualization.Charting.Title(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RawAcceleration)); this.optionsPanel = new System.Windows.Forms.Panel(); + this.SmoothActiveYLabel = new System.Windows.Forms.Label(); + this.smoothLabelY = new System.Windows.Forms.Label(); + this.SmoothActiveXLabel = new System.Windows.Forms.Label(); + this.smoothLabelX = new System.Windows.Forms.Label(); + this.smoothBoxY = new System.Windows.Forms.TextBox(); + this.smoothBoxX = new System.Windows.Forms.TextBox(); this.GrowthRateActiveYLabel = new System.Windows.Forms.Label(); this.GrowthRateActiveXLabel = new System.Windows.Forms.Label(); this.DecayRateActiveYLabel = new System.Windows.Forms.Label(); @@ -209,7 +215,7 @@ namespace grapher this.streamingModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.advancedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.UseSpecificDeviceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DeviceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.chartsPanel = new System.Windows.Forms.Panel(); this.GainChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); @@ -217,12 +223,6 @@ namespace grapher this.GainChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); - this.smoothBoxX = new System.Windows.Forms.TextBox(); - this.smoothBoxY = new System.Windows.Forms.TextBox(); - this.smoothLabelX = new System.Windows.Forms.Label(); - this.SmoothActiveXLabel = new System.Windows.Forms.Label(); - this.smoothLabelY = new System.Windows.Forms.Label(); - this.SmoothActiveYLabel = new System.Windows.Forms.Label(); this.optionsPanel.SuspendLayout(); this.DirectionalityPanel.SuspendLayout(); this.menuStrip1.SuspendLayout(); @@ -358,6 +358,56 @@ namespace grapher this.optionsPanel.Size = new System.Drawing.Size(483, 956); this.optionsPanel.TabIndex = 34; // + // SmoothActiveYLabel + // + this.SmoothActiveYLabel.AutoSize = true; + this.SmoothActiveYLabel.Location = new System.Drawing.Point(414, 677); + this.SmoothActiveYLabel.Name = "SmoothActiveYLabel"; + this.SmoothActiveYLabel.Size = new System.Drawing.Size(13, 13); + this.SmoothActiveYLabel.TabIndex = 193; + this.SmoothActiveYLabel.Text = "0"; + // + // smoothLabelY + // + this.smoothLabelY.AutoSize = true; + this.smoothLabelY.Location = new System.Drawing.Point(266, 677); + this.smoothLabelY.Name = "smoothLabelY"; + this.smoothLabelY.Size = new System.Drawing.Size(43, 13); + this.smoothLabelY.TabIndex = 192; + this.smoothLabelY.Text = "Smooth"; + // + // SmoothActiveXLabel + // + this.SmoothActiveXLabel.AutoSize = true; + this.SmoothActiveXLabel.Location = new System.Drawing.Point(200, 677); + this.SmoothActiveXLabel.Name = "SmoothActiveXLabel"; + this.SmoothActiveXLabel.Size = new System.Drawing.Size(13, 13); + this.SmoothActiveXLabel.TabIndex = 191; + this.SmoothActiveXLabel.Text = "0"; + // + // smoothLabelX + // + this.smoothLabelX.AutoSize = true; + this.smoothLabelX.Location = new System.Drawing.Point(38, 677); + this.smoothLabelX.Name = "smoothLabelX"; + this.smoothLabelX.Size = new System.Drawing.Size(43, 13); + this.smoothLabelX.TabIndex = 190; + this.smoothLabelX.Text = "Smooth"; + // + // smoothBoxY + // + this.smoothBoxY.Location = new System.Drawing.Point(332, 671); + this.smoothBoxY.Name = "smoothBoxY"; + this.smoothBoxY.Size = new System.Drawing.Size(76, 20); + this.smoothBoxY.TabIndex = 189; + // + // smoothBoxX + // + this.smoothBoxX.Location = new System.Drawing.Point(106, 672); + this.smoothBoxX.Name = "smoothBoxX"; + this.smoothBoxX.Size = new System.Drawing.Size(76, 20); + this.smoothBoxX.TabIndex = 188; + // // GrowthRateActiveYLabel // this.GrowthRateActiveYLabel.AutoSize = true; @@ -1554,7 +1604,7 @@ namespace grapher // this.advancedToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.AutoWriteMenuItem, - this.UseSpecificDeviceMenuItem}); + this.DeviceMenuItem}); this.advancedToolStripMenuItem.Name = "advancedToolStripMenuItem"; this.advancedToolStripMenuItem.Size = new System.Drawing.Size(72, 20); this.advancedToolStripMenuItem.Text = "Advanced"; @@ -1568,11 +1618,11 @@ namespace grapher this.AutoWriteMenuItem.Size = new System.Drawing.Size(210, 22); this.AutoWriteMenuItem.Text = "Apply Settings On Startup"; // - // UseSpecificDeviceMenuItem + // DeviceMenuItem // - this.UseSpecificDeviceMenuItem.Name = "UseSpecificDeviceMenuItem"; - this.UseSpecificDeviceMenuItem.Size = new System.Drawing.Size(210, 22); - this.UseSpecificDeviceMenuItem.Text = "Use Specific Device"; + this.DeviceMenuItem.Name = "DeviceMenuItem"; + this.DeviceMenuItem.Size = new System.Drawing.Size(210, 22); + this.DeviceMenuItem.Text = "Device Menu"; // // chartsPanel // @@ -1826,56 +1876,6 @@ namespace grapher title6.Text = "Sensitivity"; this.AccelerationChart.Titles.Add(title6); // - // smoothBoxX - // - this.smoothBoxX.Location = new System.Drawing.Point(106, 672); - this.smoothBoxX.Name = "smoothBoxX"; - this.smoothBoxX.Size = new System.Drawing.Size(76, 20); - this.smoothBoxX.TabIndex = 188; - // - // smoothBoxY - // - this.smoothBoxY.Location = new System.Drawing.Point(332, 671); - this.smoothBoxY.Name = "smoothBoxY"; - this.smoothBoxY.Size = new System.Drawing.Size(76, 20); - this.smoothBoxY.TabIndex = 189; - // - // smoothLabelX - // - this.smoothLabelX.AutoSize = true; - this.smoothLabelX.Location = new System.Drawing.Point(38, 677); - this.smoothLabelX.Name = "smoothLabelX"; - this.smoothLabelX.Size = new System.Drawing.Size(43, 13); - this.smoothLabelX.TabIndex = 190; - this.smoothLabelX.Text = "Smooth"; - // - // SmoothActiveXLabel - // - this.SmoothActiveXLabel.AutoSize = true; - this.SmoothActiveXLabel.Location = new System.Drawing.Point(200, 677); - this.SmoothActiveXLabel.Name = "SmoothActiveXLabel"; - this.SmoothActiveXLabel.Size = new System.Drawing.Size(13, 13); - this.SmoothActiveXLabel.TabIndex = 191; - this.SmoothActiveXLabel.Text = "0"; - // - // smoothLabelY - // - this.smoothLabelY.AutoSize = true; - this.smoothLabelY.Location = new System.Drawing.Point(266, 677); - this.smoothLabelY.Name = "smoothLabelY"; - this.smoothLabelY.Size = new System.Drawing.Size(43, 13); - this.smoothLabelY.TabIndex = 192; - this.smoothLabelY.Text = "Smooth"; - // - // SmoothActiveYLabel - // - this.SmoothActiveYLabel.AutoSize = true; - this.SmoothActiveYLabel.Location = new System.Drawing.Point(414, 677); - this.SmoothActiveYLabel.Name = "SmoothActiveYLabel"; - this.SmoothActiveYLabel.Size = new System.Drawing.Size(13, 13); - this.SmoothActiveYLabel.TabIndex = 193; - this.SmoothActiveYLabel.Text = "0"; - // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2016,7 +2016,7 @@ namespace grapher private System.Windows.Forms.Label LpNormActiveValue; private System.Windows.Forms.Label RangeActiveValueY; private System.Windows.Forms.CheckBox FakeBox; - private System.Windows.Forms.ToolStripMenuItem UseSpecificDeviceMenuItem; + private System.Windows.Forms.ToolStripMenuItem DeviceMenuItem; private System.Windows.Forms.Label LUTTextLabelX; private System.Windows.Forms.Label LUTTextLabelY; private System.Windows.Forms.CheckBox gainSwitchX; diff --git a/grapher/Form1.cs b/grapher/Form1.cs index ba16a23..c492a9b 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -40,7 +40,6 @@ namespace grapher AccelGUI = AccelGUIFactory.Construct( this, - ManagedAccel.GetActive(), AccelerationChart, AccelerationChartY, VelocityChart, @@ -57,7 +56,7 @@ namespace grapher showLastMouseMoveToolStripMenuItem, streamingModeToolStripMenuItem, AutoWriteMenuItem, - UseSpecificDeviceMenuItem, + DeviceMenuItem, ScaleMenuItem, DPITextBox, PollRateTextBox, @@ -210,7 +209,7 @@ namespace grapher } else if (m.Msg == 0x00fe) // WM_INPUT_DEVICE_CHANGE { - AccelGUI.UpdateInputManagers(); + AccelGUI.Settings.OnDeviceChangeMessage(); } } diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 4ce6ed8..e4f924a 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -24,8 +24,7 @@ namespace grapher Button writeButton, ButtonBase resetButton, MouseWatcher mouseWatcher, - ToolStripMenuItem scaleMenuItem, - DeviceIDManager deviceIDManager) + ToolStripMenuItem scaleMenuItem) { AccelForm = accelForm; AccelCalculator = accelCalculator; @@ -38,14 +37,13 @@ namespace grapher DefaultButtonFont = WriteButton.Font; SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor); MouseWatcher = mouseWatcher; - DeviceIDManager = deviceIDManager; ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); WriteButton.Click += new System.EventHandler(OnWriteButtonClick); ResetButton.Click += new System.EventHandler(ResetDriverEventHandler); AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose); - ButtonTimerInterval = Convert.ToInt32(DriverSettings.WriteDelayMs); + ButtonTimerInterval = Convert.ToInt32(DriverConfig.WriteDelayMs); ButtonTimer = new Timer(); ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick); @@ -85,8 +83,6 @@ namespace grapher public ToolStripMenuItem ScaleMenuItem { get; } - public DeviceIDManager DeviceIDManager { get; } - private Timer ChartRefresh { get; } private Font SmallButtonFont { get; } @@ -112,21 +108,23 @@ namespace grapher } } - public DriverSettings MakeSettingsFromFields() + public Profile MakeSettingsFromFields() { - var settings = new DriverSettings(); + var settings = new Profile(); settings.rotation = ApplyOptions.Rotation.Field.Data; - settings.sensitivity = new Vec2<double> - { - x = ApplyOptions.Sensitivity.Fields.X, - y = ApplyOptions.Sensitivity.Fields.Y - }; + settings.sensitivity = ApplyOptions.Sensitivity.Fields.X; + + // TODO - separate sensitivity fields, add new label for ratio + settings.yxSensRatio = ApplyOptions.Sensitivity.Fields.Y; settings.combineMagnitudes = ApplyOptions.IsWhole; - ApplyOptions.SetArgs(ref settings.args); - settings.domainArgs = ApplyOptions.Directionality.GetDomainArgs(); + ApplyOptions.SetArgs(ref settings.argsX, ref settings.argsY); + + var (domWeights, lpNorm) = ApplyOptions.Directionality.GetDomainArgs(); + settings.domainXY = domWeights; + settings.lpNorm = lpNorm; + settings.rangeXY = ApplyOptions.Directionality.GetRangeXY(); - settings.deviceID = DeviceIDManager.ID; Settings.SetHiddenOptions(settings); @@ -141,16 +139,15 @@ namespace grapher { ButtonDelay(WriteButton); - var settings = MakeSettingsFromFields(); - SettingsErrors errors = Settings.TryActivate(settings); - if (errors.Empty()) + var cfg = DriverConfig.FromProfile(MakeSettingsFromFields()); + if (!Settings.TryActivate(cfg, out string errors)) { - RefreshActive(); - return; + error_message = errors.ToString(); } else { - error_message = errors.ToString(); + RefreshActive(); + return; } } catch (ApplicationException e) @@ -161,34 +158,24 @@ namespace grapher new MessageDialog(error_message, "bad input").ShowDialog(); } - - public void UpdateInputManagers() - { - MouseWatcher.UpdateHandles(Settings.ActiveSettings.baseSettings.deviceID); - DeviceIDManager.Update(Settings.ActiveSettings.baseSettings.deviceID); - } - public void RefreshActive() { - UpdateShownActiveValues(Settings.UserSettings); + UpdateShownActiveValues(Settings.ActiveProfile); UpdateGraph(); - UpdateInputManagers(); } public void RefreshUser() { - UpdateShownActiveValues(Settings.UserSettings); + UpdateShownActiveValues(Settings.UserProfile); } public void UpdateGraph() { - AccelCharts.Calculate( - Settings.ActiveAccel, - Settings.ActiveSettings.baseSettings); + AccelCharts.Calculate(Settings.ActiveAccel, Settings.ActiveProfile); AccelCharts.Bind(); } - public void UpdateShownActiveValues(DriverSettings args) + public void UpdateShownActiveValues(Profile args) { AccelForm.ResetAutoScroll(); AccelCharts.ShowActive(args); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 7e5ae9b..cc43aeb 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -17,7 +17,6 @@ namespace grapher.Models public static AccelGUI Construct( RawAcceleration form, - ManagedAccel activeAccel, Chart accelerationChart, Chart accelerationChartY, Chart velocityChart, @@ -34,7 +33,7 @@ namespace grapher.Models ToolStripMenuItem showLastMouseMoveMenuItem, ToolStripMenuItem streamingModeToolStripMenuItem, ToolStripMenuItem autoWriteMenuItem, - ToolStripMenuItem useSpecificDeviceMenuItem, + ToolStripMenuItem deviceMenuItem, ToolStripMenuItem scaleMenuItem, ToolStripTextBox dpiTextBox, ToolStripTextBox pollRateTextBox, @@ -492,17 +491,14 @@ namespace grapher.Models lockXYLabel, accelCharts); - var deviceIdManager = new DeviceIDManager(useSpecificDeviceMenuItem); - var settings = new SettingsManager( - activeAccel, accelCalculator.DPI, accelCalculator.PollRate, autoWriteMenuItem, showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem, streamingModeToolStripMenuItem, - deviceIdManager); + deviceMenuItem); var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, settings); @@ -515,8 +511,7 @@ namespace grapher.Models writeButton, toggleButton, mouseWatcher, - scaleMenuItem, - deviceIdManager); + scaleMenuItem); } #endregion Methods diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index 574f55a..6b9cbf3 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -107,7 +107,7 @@ namespace grapher.Models.Calculations continue; } - var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); + var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, 1, simulatedInputDatum.time); var outMagnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(outMagnitude - lastOutputMagnitude, 5); @@ -193,7 +193,7 @@ namespace grapher.Models.Calculations data.MinGain = minSlope; } - public void CalculateDirectional(AccelChartData[] dataByAngle, ManagedAccel accel, DriverSettings settings, IReadOnlyCollection<IReadOnlyCollection<SimulatedMouseInput>> simulatedInputData) + public void CalculateDirectional(AccelChartData[] dataByAngle, ManagedAccel accel, Profile settings, IReadOnlyCollection<IReadOnlyCollection<SimulatedMouseInput>> simulatedInputData) { double maxRatio = 0.0; double minRatio = Double.MaxValue; @@ -219,7 +219,7 @@ namespace grapher.Models.Calculations continue; } - var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); + var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, 1, simulatedInputDatum.time); var magnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(magnitude - lastOutputMagnitude, 5); @@ -246,7 +246,7 @@ namespace grapher.Models.Calculations } var ratio = DecimalCheck(magnitude / simulatedInputDatum.velocity); - var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x); + var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : settings.sensitivity); bool indexToMeasureExtrema = (angleIndex == 0) || (angleIndex == (Constants.AngleDivisions - 1)); @@ -477,16 +477,16 @@ namespace grapher.Models.Calculations return Magnitude(x, y) / time; } - public static bool ShouldStripSens(ref DriverSettings settings) => - settings.sensitivity.x != settings.sensitivity.y; + public static bool ShouldStripSens(Profile settings) => + settings.yxSensRatio != 1; - public static bool ShouldStripRot(ref DriverSettings settings) => + public static bool ShouldStripRot(Profile settings) => settings.rotation > 0; - public static (double, double) GetSens(ref DriverSettings settings) => - (settings.sensitivity.x, settings.sensitivity.y); + public static (double, double) GetSens(Profile settings) => + (settings.sensitivity, settings.sensitivity * settings.yxSensRatio); - public static (double, double) GetRotVector(ref DriverSettings settings) => + public static (double, double) GetRotVector(Profile settings) => (Math.Cos(settings.rotation), Math.Sin(settings.rotation)); public static (double, double) StripSens(double outputX, double outputY, double sensitivityX, double sensitivityY) => diff --git a/grapher/Models/Calculations/Data/AccelDataCombined.cs b/grapher/Models/Calculations/Data/AccelDataCombined.cs index 8efb9ac..025a344 100644 --- a/grapher/Models/Calculations/Data/AccelDataCombined.cs +++ b/grapher/Models/Calculations/Data/AccelDataCombined.cs @@ -40,10 +40,10 @@ namespace grapher.Models.Calculations.Data X.Clear(); } - public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + public void CreateGraphData(ManagedAccel accel, Profile settings) { Clear(); - Calculator.Calculate(X, accel, settings.sensitivity.x, Calculator.SimulatedInputCombined); + Calculator.Calculate(X, accel, settings.sensitivity, Calculator.SimulatedInputCombined); } } } diff --git a/grapher/Models/Calculations/Data/AccelDataXYComponential.cs b/grapher/Models/Calculations/Data/AccelDataXYComponential.cs index 6231eb3..f954230 100644 --- a/grapher/Models/Calculations/Data/AccelDataXYComponential.cs +++ b/grapher/Models/Calculations/Data/AccelDataXYComponential.cs @@ -54,11 +54,12 @@ namespace grapher.Models.Calculations.Data Y.Clear(); } - public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + public void CreateGraphData(ManagedAccel accel, Profile settings) { Clear(); - Calculator.Calculate(X, accel, settings.sensitivity.x, Calculator.SimulatedInputX); - Calculator.Calculate(Y, accel, settings.sensitivity.y, Calculator.SimulatedInputY); + var sensY = settings.sensitivity * settings.yxSensRatio; + Calculator.Calculate(X, accel, settings.sensitivity, Calculator.SimulatedInputX); + Calculator.Calculate(Y, accel, sensY, Calculator.SimulatedInputY); } } } diff --git a/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs index 8bd889d..b139719 100644 --- a/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs +++ b/grapher/Models/Calculations/Data/AccelDataXYDirectional.cs @@ -67,7 +67,7 @@ namespace grapher.Models.Calculations.Data } } - public void CreateGraphData(ManagedAccel accel, DriverSettings settings) + public void CreateGraphData(ManagedAccel accel, Profile settings) { Clear(); Calculator.CalculateDirectional(AngleToData, accel, settings, Calculator.SimulatedDirectionalInput); diff --git a/grapher/Models/Calculations/Data/IAccelData.cs b/grapher/Models/Calculations/Data/IAccelData.cs index 576e6df..2ae6716 100644 --- a/grapher/Models/Calculations/Data/IAccelData.cs +++ b/grapher/Models/Calculations/Data/IAccelData.cs @@ -10,7 +10,7 @@ namespace grapher.Models.Calculations.Data { void CalculateDots(double x, double y, double timeInMs); - void CreateGraphData(ManagedAccel accel, DriverSettings settings); + void CreateGraphData(ManagedAccel accel, Profile settings); void Clear(); diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 631c2e2..93c9218 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -121,9 +121,9 @@ namespace grapher ChartState.Bind(); } - public void ShowActive(DriverSettings driverSettings) + public void ShowActive(Profile args) { - ChartState = ChartStateManager.DetermineState(driverSettings); + ChartState = ChartStateManager.DetermineState(args); ChartState.Activate(); Bind(); } @@ -134,9 +134,9 @@ namespace grapher ChartState.Redraw(); } - public void Calculate(ManagedAccel accel, DriverSettings settings) + public void Calculate(ManagedAccel accel, Profile settings) { - ChartState.SetUpCalculate(settings); + ChartState.SetUpCalculate(); ChartState.Calculate(accel, settings); } diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index a50eaf0..eca2e43 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -35,7 +35,7 @@ namespace grapher.Models.Charts.ChartState public AccelCalculator Calculator { get; } - public virtual DriverSettings Settings { get; set; } + public virtual Profile Settings { get; set; } internal bool TwoDotsPerGraph { get; set; } @@ -48,7 +48,7 @@ namespace grapher.Models.Charts.ChartState public abstract void Activate(); - public virtual void Calculate(ManagedAccel accel, DriverSettings settings) + public virtual void Calculate(ManagedAccel accel, Profile settings) { Data.CreateGraphData(accel, settings); } @@ -60,7 +60,7 @@ namespace grapher.Models.Charts.ChartState GainChart.Update(); } - public virtual void SetUpCalculate(DriverSettings settings) + public virtual void SetUpCalculate() { Data.Clear(); Calculator.ScaleByMouseSettings(); diff --git a/grapher/Models/Charts/ChartState/ChartStateManager.cs b/grapher/Models/Charts/ChartState/ChartStateManager.cs index 3d4bbec..1e5386c 100644 --- a/grapher/Models/Charts/ChartState/ChartStateManager.cs +++ b/grapher/Models/Charts/ChartState/ChartStateManager.cs @@ -50,14 +50,14 @@ namespace grapher.Models.Charts.ChartState private XYTwoGraphState XYTwoGraphState { get; } - public ChartState DetermineState(DriverSettings settings) + public ChartState DetermineState(Profile settings) { ChartState chartState; if (settings.combineMagnitudes) { - if (settings.sensitivity.x != settings.sensitivity.y || - settings.domainArgs.domainXY.x != settings.domainArgs.domainXY.y || + if (settings.yxSensRatio != 1 || + settings.domainXY.x != settings.domainXY.y || settings.rangeXY.x != settings.rangeXY.y) { chartState = XYOneGraphState; diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index 5b6c2b8..387d1b1 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -23,7 +23,7 @@ namespace grapher.Models.Charts.ChartState Data = new AccelDataXYComponential(xPoints, yPoints, accelCalculator); } - public override DriverSettings Settings { get; set; } + public override Profile Settings { get; set; } public override void Activate() { diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs index 39856a1..e0ee686 100644 --- a/grapher/Models/Devices/DeviceIDManager.cs +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -46,7 +46,7 @@ namespace grapher.Models.Devices if (found) SetActive(anyDevice); - foreach (string id in RawInputInterop.GetDeviceIDs()) +/* foreach (string id in RawInputInterop.GetDeviceIDs()) { var deviceItem = new DeviceIDItem(string.Empty, id, this); if (!found && deviceItem.ID.Equals(devID)) @@ -54,7 +54,7 @@ namespace grapher.Models.Devices SetActive(deviceItem); found = true; } - } + }*/ if (!found) { diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index c5c2ae5..c36ceb4 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -691,7 +691,6 @@ namespace grapher.Models.Mouse AccelCharts = accelCharts; SettingsManager = setMngr; MouseData = new MouseData(); - DeviceHandles = new List<IntPtr>(); RAWINPUTDEVICE device = new RAWINPUTDEVICE(); device.WindowHandle = ContainingForm.Handle; @@ -722,10 +721,6 @@ namespace grapher.Models.Mouse private Stopwatch Stopwatch { get; } - private List<IntPtr> DeviceHandles { get; } - - private bool AnyDevice { get; set; } - private double PollTime { get => 1000 / SettingsManager.PollRateField.Data; @@ -735,16 +730,6 @@ namespace grapher.Models.Mouse #region Methods - public void UpdateHandles(string devID) - { - DeviceHandles.Clear(); - AnyDevice = string.IsNullOrEmpty(devID); - if (!AnyDevice) - { - RawInputInterop.AddHandlesFromID(devID, DeviceHandles); - } - } - public void UpdateLastMove() { MouseData.Get(out var x, out var y); @@ -758,7 +743,7 @@ namespace grapher.Models.Mouse _ = GetRawInputData(message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER))); bool relative = !rawInput.Data.Mouse.Flags.HasFlag(RawMouseFlags.MoveAbsolute); - bool deviceMatch = AnyDevice || DeviceHandles.Contains(rawInput.Header.Device); + bool deviceMatch = SettingsManager.ActiveHandles.Contains(rawInput.Header.Device); if (relative && deviceMatch && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { @@ -772,8 +757,7 @@ namespace grapher.Models.Mouse // strip negative directional multipliers, charts calculated from positive input - Vec2<double> dirMults = SettingsManager.ActiveSettings.baseSettings - .directionalMultipliers; + Vec2<double> dirMults = SettingsManager.ActiveProfile.directionalMultipliers; if (dirMults.x > 0 && x < 0) { diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 44c9ea8..eab38a1 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -21,7 +21,6 @@ namespace grapher public static readonly LayoutBase Power = new PowerLayout(); public static readonly LayoutBase LUT = new LUTLayout(); public static readonly LayoutBase Off = new OffLayout(); - public static readonly LayoutBase Unsupported = new UnsupportedLayout(); #endregion Fields @@ -262,21 +261,22 @@ namespace grapher { AccelerationType = AccelTypeFromSettings(ref args); AccelTypeActiveValue.SetValue(AccelerationType.ActiveName); - GainSwitch.SetActiveValue(args.legacy); + GainSwitch.SetActiveValue(args.gain); Weight.SetActiveValue(args.weight); - Cap.SetActiveValue(args.cap); + Cap.SetActiveValue(args.cap.x); Offset.SetActiveValue(args.offset); - Acceleration.SetActiveValue(args.accelClassic); + Acceleration.SetActiveValue(args.acceleration); DecayRate.SetActiveValue(args.decayRate); GrowthRate.SetActiveValue(args.growthRate); Smooth.SetActiveValue(args.smooth); Scale.SetActiveValue(args.scale); Limit.SetActiveValue((args.mode == AccelMode.motivity) ? args.motivity : args.limit); - PowerClassic.SetActiveValue(args.power); - Exponent.SetActiveValue(args.exponent); + PowerClassic.SetActiveValue(args.exponentClassic); + Exponent.SetActiveValue(args.exponentPower); Midpoint.SetActiveValue(args.midpoint); - LutPanel.SetActiveValues(args.tableData.points, args.tableData.length); - LutApply.SetActiveValue(args.tableData.velocity); + LutPanel.SetActiveValues(args.data, args.length, args.mode); + // TODO - use GainSwitch only? + LutApply.SetActiveValue(args.gain); } public void ShowFull() @@ -308,17 +308,16 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - if (AccelerationType == Unsupported) throw new NotImplementedException(); - args.mode = AccelerationType.Mode; - args.legacy = !GainSwitch.CheckBox.Checked; + args.gain = GainSwitch.CheckBox.Checked; - if (Acceleration.Visible) args.accelClassic = Acceleration.Field.Data; + if (Acceleration.Visible) args.acceleration = Acceleration.Field.Data; if (DecayRate.Visible) args.decayRate = DecayRate.Field.Data; if (GrowthRate.Visible) args.growthRate = GrowthRate.Field.Data; if (Smooth.Visible) args.smooth = Smooth.Field.Data; if (Scale.Visible) args.scale = Scale.Field.Data; - if (Cap.Visible) args.cap = Cap.Field.Data; + // TODO - make field for output and in_out cap + if (Cap.Visible) args.cap.x = Cap.Field.Data; if (Limit.Visible) { if (args.mode == AccelMode.motivity) @@ -328,20 +327,27 @@ namespace grapher else { args.limit = Limit.Field.Data; - } + } } - if (PowerClassic.Visible) args.power = PowerClassic.Field.Data; - if (Exponent.Visible)args.exponent = Exponent.Field.Data; + if (PowerClassic.Visible) args.exponentClassic = PowerClassic.Field.Data; + if (Exponent.Visible) args.exponentPower = Exponent.Field.Data; if (Offset.Visible) args.offset = Offset.Field.Data; if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (Weight.Visible) args.weight = Weight.Field.Data; if (LutPanel.Visible) { (var points, var length) = LutPanel.GetPoints(); - args.tableData.points = points; - args.tableData.length = length; + args.length = length * 2; + + for (int i = 0; i < length; i++) + { + ref var p = ref points[i]; + var data_idx = i * 2; + args.data[data_idx] = p.x; + args.data[data_idx + 1] = p.y; + } } - if (LutApply.Visible) args.tableData.velocity = LutApply.ApplyType == LutApplyOptions.LutApplyType.Velocity; + } public override void AlignActiveValues() @@ -407,19 +413,9 @@ namespace grapher private LayoutBase AccelTypeFromSettings(ref AccelArgs args) { - if (args.spacedTableArgs.mode != SpacedTableMode.off) - { - if (!AccelDropdown.Items.Contains(Unsupported)) - { - AccelDropdown.Items.Add(Unsupported); - } - - return Unsupported; - } - switch (args.mode) { - case AccelMode.classic: return (args.power == 2) ? Linear : Classic; + case AccelMode.classic: return (args.exponentClassic == 2) ? Linear : Classic; case AccelMode.jump: return Jump; case AccelMode.natural: return Natural; case AccelMode.motivity: return Motivity; diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 06854b8..0d87943 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -81,30 +81,30 @@ namespace grapher.Models.Options #region Methods - public void SetArgs(ref Vec2<AccelArgs> args) + public void SetArgs(ref AccelArgs argsX, ref AccelArgs argsY) { - OptionSetX.SetArgs(ref args.x); + OptionSetX.SetArgs(ref argsX); if (ByComponentVectorXYLock.Checked) { - OptionSetX.SetArgs(ref args.y); + OptionSetX.SetArgs(ref argsY); } else { - OptionSetY.SetArgs(ref args.y); + OptionSetY.SetArgs(ref argsY); } } - public void SetActiveValues(DriverSettings settings) + public void SetActiveValues(Profile settings) { - Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); + Sensitivity.SetActiveValues(settings.sensitivity, settings.yxSensRatio); Rotation.SetActiveValue(settings.rotation); WholeVectorCheckBox.Checked = settings.combineMagnitudes; ByComponentVectorCheckBox.Checked = !settings.combineMagnitudes; - ByComponentVectorXYLock.Checked = settings.args.x.Equals(settings.args.y); - OptionSetX.SetActiveValues(ref settings.args.x); - OptionSetY.SetActiveValues(ref settings.args.y); + ByComponentVectorXYLock.Checked = settings.argsX.Equals(settings.argsY); + OptionSetX.SetActiveValues(ref settings.argsX); + OptionSetY.SetActiveValues(ref settings.argsY); Directionality.SetActiveValues(settings); diff --git a/grapher/Models/Options/Directionality/DirectionalityOptions.cs b/grapher/Models/Options/Directionality/DirectionalityOptions.cs index 9288132..35d2575 100644 --- a/grapher/Models/Options/Directionality/DirectionalityOptions.cs +++ b/grapher/Models/Options/Directionality/DirectionalityOptions.cs @@ -70,17 +70,16 @@ namespace grapher.Models.Options.Directionality private bool IsHidden { get; set; } - public DomainArgs GetDomainArgs() + public Tuple<Vec2<double>, double> GetDomainArgs() { - return new DomainArgs + var weights = new Vec2<double> { - domainXY = new Vec2<double> - { - x = Domain.Fields.X, - y = Domain.Fields.Y, - }, - lpNorm = ByComponentCheckBox.Checked ? 2 : LpNorm.Field.Data + x = Domain.Fields.X, + y = Domain.Fields.Y }; + double p = ByComponentCheckBox.Checked ? 2 : LpNorm.Field.Data; + + return new Tuple<Vec2<double>, double>(weights, p); } public Vec2<double> GetRangeXY() @@ -92,14 +91,14 @@ namespace grapher.Models.Options.Directionality }; } - public void SetActiveValues(DriverSettings settings) + public void SetActiveValues(Profile settings) { - Domain.SetActiveValues(settings.domainArgs.domainXY.x, settings.domainArgs.domainXY.y); + Domain.SetActiveValues(settings.domainXY.x, settings.domainXY.y); Range.SetActiveValues(settings.rangeXY.x, settings.rangeXY.y); if (settings.combineMagnitudes) { - LpNorm.SetActiveValue(settings.domainArgs.lpNorm); + LpNorm.SetActiveValue(settings.lpNorm); } else { diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index 3690c76..11550e4 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -111,15 +111,26 @@ namespace grapher.Models.Options.LUT // Nothing to do here. } - public void SetActiveValues(IEnumerable<Vec2<float>> activePoints, int length) + public void SetActiveValues(IEnumerable<float> rawData, int length, AccelMode mode) { - if (length > 0 && activePoints.First().x != 0) + if (mode == AccelMode.lut && length > 1 && rawData.First() != 0) { - ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints, length); + var pointsLen = length / 2; + var points = new Vec2<float>[pointsLen]; + for (int i = 0; i < pointsLen; i++) + { + var data_idx = i * 2; + points[i] = new Vec2<float> + { + x = rawData.ElementAt(data_idx), + y = rawData.ElementAt(data_idx + 1) + }; + } + ActiveValuesTextBox.Text = PointsToActiveValuesText(points, length); if (string.IsNullOrWhiteSpace(PointsTextBox.Text)) { - PointsTextBox.Text = PointsToEntryTextBoxText(activePoints, length); + PointsTextBox.Text = PointsToEntryTextBoxText(points, length); } } else @@ -135,14 +146,12 @@ namespace grapher.Models.Options.LUT private static (Vec2<float>[], int length) UserTextToPoints(string userText) { - const int MaxPoints = 256; - if (string.IsNullOrWhiteSpace(userText)) { throw new ApplicationException("Text must be entered in text box to fill Look Up Table."); } - Vec2<float>[] points = new Vec2<float>[MaxPoints]; + Vec2<float>[] points = new Vec2<float>[AccelArgs.MaxLutPoints]; var userTextSplit = userText.Trim().Trim(';').Split(';'); int index = 0; @@ -155,9 +164,9 @@ namespace grapher.Models.Options.LUT throw new ApplicationException("At least 2 points required"); } - if (pointsCount > MaxPoints) + if (pointsCount > AccelArgs.MaxLutPoints) { - throw new ApplicationException($"Number of points exceeds max ({MaxPoints})"); + throw new ApplicationException($"Number of points exceeds max ({AccelArgs.MaxLutPoints})"); } foreach(var pointEntry in userTextSplit) diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 346bc9b..d92f18a 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Text; using System.Drawing; using grapher.Models.Devices; +using System.Collections.Generic; namespace grapher.Models.Serialized { @@ -14,14 +15,13 @@ namespace grapher.Models.Serialized #region Constructors public SettingsManager( - ManagedAccel activeAccel, Field dpiField, Field pollRateField, ToolStripMenuItem autoWrite, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain, ToolStripMenuItem streamingMode, - DeviceIDManager deviceIDManager) + ToolStripMenuItem deviceMenuItem) { DpiField = dpiField; PollRateField = pollRateField; @@ -29,9 +29,14 @@ namespace grapher.Models.Serialized ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; StreamingModeMenuItem = streamingMode; - DeviceIDManager = deviceIDManager; + deviceMenuItem.Click += (s, e) => new DeviceMenuForm(this).ShowDialog(); - SetActiveFields(activeAccel); + SystemDevices = new List<MultiHandleDevice>(); + ActiveHandles = new List<IntPtr>(); + + // TODO - remove ActiveConfig/AutoWrite entirely? + // shouldn't be needed with internal profiles support + ActiveConfig = DriverConfig.GetActive(); GuiSettings = GUISettings.MaybeLoad(); @@ -45,7 +50,7 @@ namespace grapher.Models.Serialized UpdateFieldsFromGUISettings(); } - UserSettings = InitUserSettings(); + UserConfig = InitUserSettings(); } #endregion Constructors @@ -54,23 +59,39 @@ namespace grapher.Models.Serialized public GUISettings GuiSettings { get; private set; } - public ManagedAccel ActiveAccel { get; private set; } + public DriverConfig ActiveConfig { get; private set; } + + public Profile ActiveProfile + { + get => ActiveConfig.profiles[0]; + } - public ExtendedSettings ActiveSettings { get; private set; } + public ManagedAccel ActiveAccel + { + get => ActiveConfig.accels[0]; + } - public DriverSettings UserSettings { get; private set; } + public DriverConfig UserConfig { get; private set; } + + public Profile UserProfile + { + get => UserConfig.profiles[0]; + } public Field DpiField { get; private set; } public Field PollRateField { get; private set; } - public DeviceIDManager DeviceIDManager { get; } + public IList<MultiHandleDevice> SystemDevices { get; private set; } + + public List<IntPtr> ActiveHandles { get; private set; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } + private ToolStripMenuItem StreamingModeMenuItem{ get; set; } #endregion Properties @@ -78,10 +99,8 @@ namespace grapher.Models.Serialized public void DisableDriver() { - var defaultSettings = new ExtendedSettings(); - ActiveSettings = defaultSettings; - ActiveAccel.Settings = defaultSettings; - new Thread(() => ActiveAccel.Activate()).Start(); + ActiveConfig = DriverConfig.GetDefault(); + new Thread(() => DriverConfig.Deactivate()).Start(); } public void UpdateFieldsFromGUISettings() @@ -94,36 +113,31 @@ namespace grapher.Models.Serialized AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup; } - public SettingsErrors TryActivate(DriverSettings settings) + public bool TryActivate(DriverConfig settings, out string errors) { - var errors = new SettingsErrors(settings); + errors = settings.Errors(); - if (errors.Empty()) + if (errors == null) { GuiSettings = MakeGUISettingsFromFields(); GuiSettings.Save(); - UserSettings = settings; - File.WriteAllText(Constants.DefaultSettingsFileName, RaConvert.Settings(settings)); + UserConfig = settings; + ActiveConfig = settings; + File.WriteAllText(Constants.DefaultSettingsFileName, settings.ToJSON()); - ActiveSettings = new ExtendedSettings(settings); - ActiveAccel.Settings = ActiveSettings; - - new Thread(() => ActiveAccel.Activate()).Start(); + new Thread(() => ActiveConfig.Activate()).Start(); } - return errors; + return errors == null; } - public void SetHiddenOptions(DriverSettings settings) + public void SetHiddenOptions(Profile settings) { - settings.snap = UserSettings.snap; - settings.maximumSpeed = UserSettings.maximumSpeed; - settings.minimumSpeed = UserSettings.minimumSpeed; - settings.minimumTime = UserSettings.minimumTime; - settings.maximumTime = UserSettings.maximumTime; - settings.ignore = UserSettings.ignore; - settings.directionalMultipliers = UserSettings.directionalMultipliers; + settings.snap = UserProfile.snap; + settings.maximumSpeed = UserProfile.maximumSpeed; + settings.minimumSpeed = UserProfile.minimumSpeed; + settings.directionalMultipliers = UserProfile.directionalMultipliers; } public GUISettings MakeGUISettingsFromFields() @@ -139,31 +153,40 @@ namespace grapher.Models.Serialized }; } - public bool TableActive() + private void SetActiveHandles() + { + ActiveHandles.Clear(); + // TODO + foreach (var sysDev in SystemDevices) + { + ActiveHandles.AddRange(sysDev.handles); + } + } + + private void OnProfileSwitch() { - return ActiveSettings.tables.x != null || ActiveSettings.tables.y != null; + SetActiveHandles(); } - public void SetActiveFields(ManagedAccel activeAccel) + public void OnDeviceChangeMessage() { - ActiveAccel = activeAccel; - ActiveSettings = activeAccel.Settings; + SystemDevices = MultiHandleDevice.GetList(); + SetActiveHandles(); } - private DriverSettings InitUserSettings() + private DriverConfig InitUserSettings() { var path = Constants.DefaultSettingsFileName; if (File.Exists(path)) { try { - DriverSettings settings = RaConvert.Settings(File.ReadAllText(path)); + var (cfg, err) = DriverConfig.Convert(File.ReadAllText(path)); if (!GuiSettings.AutoWriteToDriverOnStartup || - TableActive() || - TryActivate(settings).Empty()) + (err == null && TryActivate(cfg, out string _))) { - return settings; + return cfg; } } @@ -173,17 +196,8 @@ namespace grapher.Models.Serialized } } - if (!TableActive()) - { - File.WriteAllText(path, RaConvert.Settings(ActiveSettings.baseSettings)); - return ActiveSettings.baseSettings; - } - else - { - var defaultSettings = new DriverSettings(); - File.WriteAllText(path, RaConvert.Settings(defaultSettings)); - return defaultSettings; - } + File.WriteAllText(path, ActiveConfig.ToJSON()); + return ActiveConfig; } #endregion Methods diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 7b0ab02..9a9412b 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -78,6 +78,12 @@ <DependentUpon>AboutBox.cs</DependentUpon> </Compile> <Compile Include="Constants\Constants.cs" /> + <Compile Include="DeviceMenuForm.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="DeviceMenuForm.Designer.cs"> + <DependentUpon>DeviceMenuForm.cs</DependentUpon> + </Compile> <Compile Include="Layouts\LUTLayout.cs" /> <Compile Include="Layouts\MotivityLayout.cs" /> <Compile Include="Layouts\JumpLayout.cs" /> @@ -148,6 +154,9 @@ <DependentUpon>AboutBox.cs</DependentUpon> <SubType>Designer</SubType> </EmbeddedResource> + <EmbeddedResource Include="DeviceMenuForm.resx"> + <DependentUpon>DeviceMenuForm.cs</DependentUpon> + </EmbeddedResource> <EmbeddedResource Include="Form1.resx"> <DependentUpon>Form1.cs</DependentUpon> </EmbeddedResource> |