diff options
| -rw-r--r-- | grapher/Form1.Designer.cs | 22 | ||||
| -rw-r--r-- | grapher/Form1.cs | 3 | ||||
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 27 | ||||
| -rw-r--r-- | grapher/Models/Serialized/GUISettings.cs | 51 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 81 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 6 | ||||
| -rw-r--r-- | grapher/packages.config | 4 | ||||
| -rw-r--r-- | settings.json | 23 | ||||
| -rw-r--r-- | wrapper/wrapper.hpp | 3 |
9 files changed, 217 insertions, 3 deletions
diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index d9cec5c..7a5eb43 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -112,6 +112,8 @@ namespace grapher this.OffsetActiveLabel = new System.Windows.Forms.Label(); this.LimitExpActiveLabel = new System.Windows.Forms.Label(); this.MidpointActiveLabel = new System.Windows.Forms.Label(); + this.startupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.VelocityChart)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.GainChart)).BeginInit(); @@ -417,7 +419,8 @@ namespace grapher this.menuStrip1.BackColor = System.Drawing.SystemColors.ControlLight; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.graphsToolStripMenuItem, - this.advancedToolStripMenuItem}); + this.advancedToolStripMenuItem, + this.startupToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1786, 24); @@ -717,6 +720,21 @@ namespace grapher this.MidpointActiveLabel.TabIndex = 47; this.MidpointActiveLabel.Text = "0"; // + // startupToolStripMenuItem + // + this.startupToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.AutoWriteMenuItem}); + this.startupToolStripMenuItem.Name = "startupToolStripMenuItem"; + this.startupToolStripMenuItem.Size = new System.Drawing.Size(57, 20); + this.startupToolStripMenuItem.Text = "Startup"; + // + // AutoWriteMenuItem + // + this.AutoWriteMenuItem.CheckOnClick = true; + this.AutoWriteMenuItem.Name = "AutoWriteMenuItem"; + this.AutoWriteMenuItem.Size = new System.Drawing.Size(229, 22); + this.AutoWriteMenuItem.Text = "Apply Settings File on Startup"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -845,6 +863,8 @@ namespace grapher private System.Windows.Forms.Label OffsetActiveLabel; private System.Windows.Forms.Label LimitExpActiveLabel; private System.Windows.Forms.Label MidpointActiveLabel; + private System.Windows.Forms.ToolStripMenuItem startupToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem AutoWriteMenuItem; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 1e38809..ef06527 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -218,7 +218,8 @@ namespace grapher midpoint, writeButton, MouseLabel, - ScaleMenuItem); + ScaleMenuItem, + AutoWriteMenuItem); } #endregion Constructor diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index e345743..a0a76c8 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -1,5 +1,6 @@ using grapher.Models.Calculations; using grapher.Models.Mouse; +using grapher.Models.Serialized; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -32,7 +33,8 @@ namespace grapher Option midpoint, Button writeButton, Label mouseMoveLabel, - ToolStripMenuItem scaleMenuItem) + ToolStripMenuItem scaleMenuItem, + ToolStripMenuItem autoWriteMenuItem) { AccelForm = accelForm; AccelCalculator = accelCalculator; @@ -51,6 +53,7 @@ namespace grapher ScaleMenuItem = scaleMenuItem; ManagedAcceleration.ReadFromDriver(); + SavedSettings = StartupLoad(AccelCalculator.DPI, AccelCalculator.PollRate, autoWriteMenuItem); UpdateGraph(); MouseWatcher = new MouseWatcher(AccelForm, mouseMoveLabel, AccelCharts); @@ -64,6 +67,8 @@ namespace grapher public RawAcceleration AccelForm { get; } + public RawAccelSettings SavedSettings { get; } + public AccelCalculator AccelCalculator { get; } public AccelCharts AccelCharts { get; } @@ -103,6 +108,7 @@ namespace grapher AccelCalculator.Calculate(AccelCharts.AccelData, ManagedAcceleration); AccelCharts.Bind(); UpdateActiveValueLabels(); + SavedSettings.Save(); } public void UpdateActiveValueLabels() @@ -118,6 +124,25 @@ namespace grapher Midpoint.SetActiveValue(ManagedAcceleration.Midpoint); } + private RawAccelSettings StartupLoad(Field dpiField, Field pollRateField, ToolStripMenuItem autoWriteMenuItem) + { + if (RawAccelSettings.Exists()) + { + var settings = RawAccelSettings.Load(); + settings.GUISettings.BindToGUI(dpiField, pollRateField, autoWriteMenuItem); + return settings; + } + else + { + return new RawAccelSettings( + ManagedAcceleration, + new GUISettings( + AccelCalculator.DPI, + AccelCalculator.PollRate, + autoWriteMenuItem)); + } + } + private void OnScaleMenuItemClick(object sender, EventArgs e) { UpdateGraph(); diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs new file mode 100644 index 0000000..8c182ae --- /dev/null +++ b/grapher/Models/Serialized/GUISettings.cs @@ -0,0 +1,51 @@ +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 + { + public GUISettings( + Field dpiField, + Field pollRateField, + ToolStripMenuItem autoWriteMenuItem) + { + BindToGUI(dpiField, pollRateField, autoWriteMenuItem); + } + + public bool AutoWriteToDriverOnStartup { get; set; } + + public int DPI { get; set; } + + public int PollRate { get; set; } + + [field: NonSerialized] + private Field DpiField { get; set; } + + [field: NonSerialized] + private Field PollRateField { get; set; } + + [field: NonSerialized] + private ToolStripMenuItem AutoWriteMenuItem { get; set; } + + public void UpdateSettings() + { + DPI = (int)DpiField.Data; + PollRate = (int)PollRateField.Data; + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked; + } + + public void BindToGUI(Field dpiField, Field pollRateField, ToolStripMenuItem autoWriteMenuItem) + { + DpiField = dpiField; + PollRateField = pollRateField; + AutoWriteMenuItem = autoWriteMenuItem; + } + } +} diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs new file mode 100644 index 0000000..d8896b6 --- /dev/null +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -0,0 +1,81 @@ +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 RawAccelSettings + { + public const string DefaultSettingsFile = @".\settings.json"; + + public RawAccelSettings( + ManagedAccel managedAccel, + GUISettings guiSettings) + { + ManagedAccel = managedAccel; + GUISettings = guiSettings; + } + + public ManagedAccel ManagedAccel { get; set; } + + public GUISettings GUISettings { get; set; } + + public static RawAccelSettings Load() + { + return Load(DefaultSettingsFile); + } + + public static RawAccelSettings Load(string file) + { + if (!Exists(file)) + { + throw new Exception($"Settings file does not exist at {file}"); + } + + object deserializedObject; + try + { + deserializedObject = JsonConvert.DeserializeObject(File.ReadAllText(file)); + } + catch + { + throw new Exception($"Settings file at {file} does not contain valid JSON."); + } + + RawAccelSettings deserializedSettings = (RawAccelSettings)deserializedObject; + + if (deserializedSettings == null) + { + throw new Exception($"Settings file at {file} does not contain valid Raw Accel Settings."); + } + + return deserializedSettings; + } + + public static bool Exists() + { + return Exists(DefaultSettingsFile); + } + + public static bool Exists(string file) + { + return File.Exists(file); + } + + public void Save() + { + Save(DefaultSettingsFile); + } + + public void Save(string file) + { + File.WriteAllText(file, JsonConvert.SerializeObject(this, Formatting.Indented)); + } + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 64f5e3c..54b73c8 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -33,6 +33,9 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Windows.Forms.DataVisualization" /> @@ -81,6 +84,8 @@ <Compile Include="Layouts\SigmoidLayout.cs" /> <Compile Include="Models\Options\Option.cs" /> <Compile Include="Models\Options\OptionXY.cs" /> + <Compile Include="Models\Serialized\GUISettings.cs" /> + <Compile Include="Models\Serialized\RawAccelSettings.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <EmbeddedResource Include="Form1.resx"> @@ -95,6 +100,7 @@ <AutoGen>True</AutoGen> <DependentUpon>Resources.resx</DependentUpon> </Compile> + <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> <LastGenOutput>Settings.Designer.cs</LastGenOutput> diff --git a/grapher/packages.config b/grapher/packages.config new file mode 100644 index 0000000..a9de8b5 --- /dev/null +++ b/grapher/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" /> +</packages>
\ No newline at end of file diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..d8bc27a --- /dev/null +++ b/settings.json @@ -0,0 +1,23 @@ +{ + "ManagedAccel": { + "Midpoint": 0.0, + "LimitExp": 2.8188211394527425, + "Offset": 0.0, + "WeightY": 0.162, + "WeightX": 0.162, + "GainCapEnabled": true, + "GainCap": 49.127, + "CapY": 9.0, + "CapX": 9.0, + "Acceleration": 0.023716, + "Type": 2, + "Rotation": 1.0, + "SensitivityY": 0.1, + "SensitivityX": 0.075 + }, + "GUISettings": { + "AutoWriteToDriverOnStartup": false, + "DPI": 0, + "PollRate": 0 + } +}
\ No newline at end of file diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp index e229735..e90b308 100644 --- a/wrapper/wrapper.hpp +++ b/wrapper/wrapper.hpp @@ -7,10 +7,13 @@ using namespace rawaccel; using namespace System; +[ Serializable ] public ref class ManagedAccel { protected: + [ NonSerialized ] mouse_modifier* modifier_instance; + [ NonSerialized ] wrapper_io* driverWriter; public: ManagedAccel(mouse_modifier* accel) |