summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-09-15 06:41:57 -0400
committera1xd <[email protected]>2021-09-23 22:34:51 -0400
commit7c0305ae2c99c191baf61eb920025826057d5753 (patch)
tree6a394d4ac8d69436f7bd8f1255f1d4fd3439280c
parentfix potential leaks (diff)
downloadrawaccel-7c0305ae2c99c191baf61eb920025826057d5753.tar.xz
rawaccel-7c0305ae2c99c191baf61eb920025826057d5753.zip
add device menu
-rw-r--r--grapher/DeviceMenuForm.Designer.cs51
-rw-r--r--grapher/DeviceMenuForm.cs402
-rw-r--r--grapher/DeviceMenuForm.resx120
-rw-r--r--grapher/Models/AccelGUI.cs23
-rw-r--r--grapher/Models/AccelGUIFactory.cs6
-rw-r--r--grapher/Models/Devices/DeviceDialogItem.cs26
-rw-r--r--grapher/Models/Devices/DeviceIDItem.cs73
-rw-r--r--grapher/Models/Devices/DeviceIDManager.cs68
-rw-r--r--grapher/Models/Serialized/SettingsManager.cs67
-rw-r--r--grapher/grapher.csproj9
10 files changed, 501 insertions, 344 deletions
diff --git a/grapher/DeviceMenuForm.Designer.cs b/grapher/DeviceMenuForm.Designer.cs
deleted file mode 100644
index 6b05645..0000000
--- a/grapher/DeviceMenuForm.Designer.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-
-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
index 00b36a8..dd946f4 100644
--- a/grapher/DeviceMenuForm.cs
+++ b/grapher/DeviceMenuForm.cs
@@ -1,21 +1,405 @@
-using grapher.Models.Serialized;
+using grapher.Models.Devices;
+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 class DeviceMenuForm : Form
{
+ #region Constructors
public DeviceMenuForm(SettingsManager sm)
{
- InitializeComponent();
+ Manager = sm;
+ defaultConfig = Manager.UserConfig.defaultDeviceConfig;
+
+ var columns = 3;
+ var rows = 9;
+ var tablePanel = new TableLayoutPanel
+ {
+ Dock = DockStyle.Fill,
+ ColumnCount = columns,
+ RowCount = rows
+ };
+
+ SuspendLayout();
+ tablePanel.SuspendLayout();
+
+ Label MakeConfigLabel(string text)
+ {
+ return new Label
+ {
+ Text = text,
+ Anchor = AnchorStyles.Left,
+ AutoSize = true,
+ };
+ }
+
+ DpiLabel = MakeConfigLabel("DPI:");
+ RateLabel = MakeConfigLabel("Polling rate:");
+ DisableLabel = MakeConfigLabel("Disable:");
+ OverrideLabel = MakeConfigLabel("Override defaults:");
+
+ var maxLabel = OverrideLabel;
+ tablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 2));
+ tablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, maxLabel.PreferredSize.Width + maxLabel.Margin.Left + maxLabel.Margin.Right));
+ tablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1));
+
+ var middleRowCount = rows - 2;
+ tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
+ for (int i = 0; i < middleRowCount; i++)
+ {
+ tablePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 1));
+ }
+ tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
+
+ var topPanel = new FlowLayoutPanel
+ {
+ AutoSize = true,
+ };
+
+ DefaultDisableCheck = new CheckBox
+ {
+ Text = "Disable by default",
+ AutoSize = true,
+ Checked = defaultConfig.disable,
+ };
+
+ topPanel.Controls.Add(DefaultDisableCheck);
+
+ tablePanel.Controls.Add(topPanel, 0, 0);
+ tablePanel.SetColumnSpan(topPanel, columns);
+
+ var bottomPanel = new FlowLayoutPanel
+ {
+ AutoSize = true,
+ Anchor = AnchorStyles.Right | AnchorStyles.Bottom,
+ };
+
+ var applyButton = new Button
+ {
+ Text = "Apply",
+ DialogResult = DialogResult.OK,
+ };
+
+ bottomPanel.Controls.AddRange(new Control[] {
+ applyButton,
+ new Button
+ {
+ Text = "Cancel",
+ DialogResult = DialogResult.Cancel,
+ },
+ });
+
+ tablePanel.Controls.Add(bottomPanel, 0, rows - 1);
+ tablePanel.SetColumnSpan(bottomPanel, columns);
+
+ IdPanel = new Panel
+ {
+ Dock = DockStyle.Fill,
+ };
+
+ IdText = new TextBox
+ {
+ ReadOnly = true,
+ BorderStyle = BorderStyle.None,
+ BackColor = this.BackColor,
+ TabStop = false,
+ TextAlign = HorizontalAlignment.Center,
+ Dock = DockStyle.Fill,
+ };
+
+ IdPanel.Controls.Add(IdText);
+ IdPanel.Controls.Add(new Label
+ {
+ // divider
+ Height = 2,
+ BorderStyle = BorderStyle.Fixed3D,
+ AutoSize = false,
+ Text = string.Empty,
+ Dock = DockStyle.Bottom,
+ });
+
+ tablePanel.Controls.Add(IdPanel, 1, 1);
+ tablePanel.SetColumnSpan(IdPanel, 2);
+
+ NumericUpDown MakeNumericInput(int val = 0, int min = 0, int max = 999999)
+ {
+ return new NumericUpDown
+ {
+ Value = val,
+ Minimum = min,
+ Maximum = max,
+ Dock = DockStyle.Fill,
+ Anchor = AnchorStyles.Left,
+ AutoSize = true,
+ };
+ }
+
+ CheckBox MakeCheck()
+ {
+ return new CheckBox
+ {
+ Text = string.Empty,
+ AutoSize = true,
+ Anchor = AnchorStyles.Left,
+ };
+ }
+
+ DpiInput = MakeNumericInput();
+ RateInput = MakeNumericInput();
+ DisableCheck = MakeCheck();
+ OverrideCheck = MakeCheck();
+
+ tablePanel.Controls.Add(OverrideLabel, 1, 2);
+ tablePanel.Controls.Add(OverrideCheck, 2, 2);
+ tablePanel.Controls.Add(DisableLabel, 1, 3);
+ tablePanel.Controls.Add(DisableCheck, 2, 3);
+ tablePanel.Controls.Add(DpiLabel, 1, 5);
+ tablePanel.Controls.Add(DpiInput, 2, 5);
+ tablePanel.Controls.Add(RateLabel, 1, 6);
+ tablePanel.Controls.Add(RateInput, 2, 6);
+
+ DeviceSelect = new ListBox
+ {
+ Dock = DockStyle.Fill,
+ IntegralHeight = false,
+ HorizontalScrollbar = true
+ };
+
+ tablePanel.Controls.Add(DeviceSelect, 0, 1);
+ tablePanel.SetRowSpan(DeviceSelect, middleRowCount);
+
+ ResetDataAndSelection();
+ SetEnabled(false);
+ SetVisible(false);
+
+ applyButton.Click += ApplyButton_Click;
+ OverrideCheck.Click += OverrideCheck_Click;
+ OverrideCheck.CheckedChanged += OverrideCheck_Checked;
+ DefaultDisableCheck.CheckedChanged += DefaultDisableCheck_Checked;
+ IdText.DoubleClick += SelectAllText;
+ DeviceSelect.SelectedIndexChanged += DeviceSelect_SelectedIndexChanged;
+ Manager.DeviceChange += OnDeviceChange;
+ Disposed += OnDispose;
+
+ var toolTip = new ToolTip();
+ toolTip.SetToolTip(IdText, "Device ID");
+
+ var rateTip = "Keep at 0 for automatic adjustment";
+ toolTip.SetToolTip(RateInput, rateTip);
+ toolTip.SetToolTip(RateLabel, rateTip);
+
+ var dpiTip = "Normalizes sensitivity and input speed to 1000 DPI";
+ toolTip.SetToolTip(DpiInput, dpiTip);
+ toolTip.SetToolTip(DpiLabel, dpiTip);
+
+
+ Name = "DeviceMenuForm";
+ Text = "Devices";
+ MaximizeBox = false;
+ MinimizeBox = false;
+ FormBorderStyle = FormBorderStyle.FixedDialog;
+ StartPosition = FormStartPosition.CenterParent;
+ AutoScaleDimensions = new SizeF(6F, 13F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(500, 300);
+
+ Controls.Add(tablePanel);
+
+ tablePanel.ResumeLayout(false);
+ ResumeLayout(false);
}
+
+ #endregion Constructors
+
+ #region Fields
+
+ public DeviceConfig defaultConfig;
+
+ #endregion Fields
+
+ #region Properties
+
+ public DeviceDialogItem[] Items { get; private set; }
+
+ private DeviceDialogItem Selected
+ {
+ get => (DeviceDialogItem)DeviceSelect.SelectedItem;
+ }
+
+ private bool AnySelected
+ {
+ get => DeviceSelect.SelectedIndex != -1;
+ }
+
+ private int LastSelectedIndex { get; set; }
+
+ private SettingsManager Manager { get; }
+
+ private ListBox DeviceSelect { get; }
+
+ private CheckBox DefaultDisableCheck { get; }
+
+ private TextBox IdText { get; }
+ private Panel IdPanel { get; }
+
+ private Label OverrideLabel { get; }
+ private CheckBox OverrideCheck { get; }
+
+ private Label DisableLabel { get; }
+ private CheckBox DisableCheck { get; }
+
+ private Label DpiLabel { get; }
+ private NumericUpDown DpiInput { get; }
+
+ private Label RateLabel { get; }
+ private NumericUpDown RateInput { get; }
+
+ #endregion Properties
+
+ #region Methods
+
+ private void ResetDataAndSelection()
+ {
+ var count = Manager.SystemDevices.Count;
+ Items = new DeviceDialogItem[count];
+
+ for (int i = 0; i < count; i++)
+ {
+ var sysDev = Manager.SystemDevices[i];
+ var settings = Manager.UserConfig.devices.Find(s => s.id == sysDev.id);
+ bool found = !(settings is null);
+
+ Items[i] = new DeviceDialogItem
+ {
+ device = sysDev,
+ overrideDefaultConfig = found,
+ oldSettings = settings,
+ newConfig = found ?
+ settings.config :
+ Manager.UserConfig.defaultDeviceConfig,
+ newProfile = found ?
+ settings.profile :
+ Manager.UserConfig.profiles[0].name
+ };
+ }
+
+ LastSelectedIndex = -1;
+ DeviceSelect.ClearSelected();
+ DeviceSelect.Items.Clear();
+ DeviceSelect.Items.AddRange(Items);
+ }
+
+ private void SetVisible(bool visible)
+ {
+ IdPanel.Visible = visible;
+ OverrideLabel.Visible = visible;
+ OverrideCheck.Visible = visible;
+ DisableLabel.Visible = visible;
+ DisableCheck.Visible = visible;
+ DpiInput.Visible = visible;
+ DpiLabel.Visible = visible;
+ RateInput.Visible = visible;
+ RateLabel.Visible = visible;
+ }
+
+ private void SetEnabled(bool enable)
+ {
+ DisableLabel.Enabled = enable;
+ DisableCheck.Enabled = enable;
+ DpiInput.Enabled = enable;
+ DpiLabel.Enabled = enable;
+ RateInput.Enabled = enable;
+ RateLabel.Enabled = enable;
+ }
+
+ private void SetInputsFromNewSelection()
+ {
+ IdText.Text = Selected.device.id;
+ OverrideCheck.Checked = Selected.overrideDefaultConfig;
+
+ SetOverrideDependentInputs();
+ }
+
+ private void SetOverrideDependentInputs()
+ {
+ var item = Selected;
+ bool oride = item.overrideDefaultConfig;
+ DisableCheck.Checked = oride ? item.newConfig.disable : defaultConfig.disable;
+ DpiInput.Value = oride ? item.newConfig.dpi : defaultConfig.dpi;
+ RateInput.Value = oride ? item.newConfig.pollingRate : defaultConfig.pollingRate;
+ }
+
+ private void UpdateLastSelected()
+ {
+ var item = Items[LastSelectedIndex];
+ bool oride = OverrideCheck.Checked;
+ item.overrideDefaultConfig = oride;
+ item.newConfig.disable = oride ? DisableCheck.Checked : defaultConfig.disable;
+ item.newConfig.dpi = oride ? (int)DpiInput.Value : defaultConfig.dpi;
+ item.newConfig.pollingRate = oride ? (int)RateInput.Value : defaultConfig.pollingRate;
+ }
+
+ private void ApplyButton_Click(object sender, EventArgs e)
+ {
+ if (AnySelected) UpdateLastSelected();
+ }
+
+ private void OverrideCheck_Checked(object sender, EventArgs e)
+ {
+ SetEnabled(OverrideCheck.Checked);
+ }
+
+ private void OverrideCheck_Click(object sender, EventArgs e)
+ {
+ UpdateLastSelected();
+ SetOverrideDependentInputs();
+ }
+
+ private void DefaultDisableCheck_Checked(object sender, EventArgs e)
+ {
+ defaultConfig.disable = DefaultDisableCheck.Checked;
+
+ if (AnySelected && !Selected.overrideDefaultConfig)
+ {
+ DisableCheck.Checked = DefaultDisableCheck.Checked;
+ }
+ }
+
+ private void DeviceSelect_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (AnySelected)
+ {
+ if (LastSelectedIndex != -1)
+ {
+ UpdateLastSelected();
+ }
+
+ SetInputsFromNewSelection();
+ }
+
+ LastSelectedIndex = DeviceSelect.SelectedIndex;
+
+ SetVisible(AnySelected);
+ }
+
+ private void OnDeviceChange(object sender, EventArgs e)
+ {
+ ResetDataAndSelection();
+ }
+
+ private void OnDispose(object sender, EventArgs e)
+ {
+ Manager.DeviceChange -= OnDeviceChange;
+ }
+
+ private static void SelectAllText(object sender, EventArgs e)
+ {
+ ((TextBoxBase)sender).SelectAll();
+ }
+
+ #endregion Methods
}
}
diff --git a/grapher/DeviceMenuForm.resx b/grapher/DeviceMenuForm.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/grapher/DeviceMenuForm.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-<?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/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs
index 1836b65..51e31a6 100644
--- a/grapher/Models/AccelGUI.cs
+++ b/grapher/Models/AccelGUI.cs
@@ -4,6 +4,7 @@ using grapher.Models.Mouse;
using grapher.Models.Options;
using grapher.Models.Serialized;
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
@@ -24,7 +25,8 @@ namespace grapher
Button writeButton,
ButtonBase resetButton,
MouseWatcher mouseWatcher,
- ToolStripMenuItem scaleMenuItem)
+ ToolStripMenuItem scaleMenuItem,
+ ToolStripMenuItem deviceMenuItem)
{
AccelForm = accelForm;
AccelCalculator = accelCalculator;
@@ -33,11 +35,13 @@ namespace grapher
WriteButton = writeButton;
ResetButton = (CheckBox)resetButton;
ScaleMenuItem = scaleMenuItem;
+ DeviceMenuItem = deviceMenuItem;
Settings = settings;
DefaultButtonFont = WriteButton.Font;
SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor);
MouseWatcher = mouseWatcher;
+ DeviceMenuItem.Click += DeviceMenuItemClick;
ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick);
WriteButton.Click += new System.EventHandler(OnWriteButtonClick);
ResetButton.Click += new System.EventHandler(ResetDriverEventHandler);
@@ -83,6 +87,8 @@ namespace grapher
public ToolStripMenuItem ScaleMenuItem { get; }
+ public ToolStripMenuItem DeviceMenuItem { get; }
+
private Timer ChartRefresh { get; }
private Font SmallButtonFont { get; }
@@ -146,6 +152,7 @@ namespace grapher
else
{
RefreshActive();
+ Settings.SetActiveHandles();
return;
}
}
@@ -240,10 +247,12 @@ namespace grapher
{
ButtonTimer.Stop();
SetButtonDefaults();
+ DeviceMenuItem.Enabled = true;
}
private void StartButtonTimer()
{
+ DeviceMenuItem.Enabled = false;
ButtonTimer.Interval = ButtonTimerInterval;
ButtonTimer.Start();
}
@@ -268,6 +277,18 @@ namespace grapher
MouseWatcher.UpdateLastMove();
}
+ private void DeviceMenuItemClick(object sender, EventArgs e)
+ {
+ using (var devMenu = new DeviceMenuForm(Settings))
+ {
+ if (devMenu.ShowDialog() == DialogResult.OK)
+ {
+ Settings.Submit(devMenu.defaultConfig, devMenu.Items);
+ UpdateActiveSettingsFromFields();
+ }
+ }
+ }
+
#endregion Methods
}
diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs
index 4d0a483..91a649a 100644
--- a/grapher/Models/AccelGUIFactory.cs
+++ b/grapher/Models/AccelGUIFactory.cs
@@ -639,8 +639,7 @@ namespace grapher.Models
autoWriteMenuItem,
showLastMouseMoveMenuItem,
showVelocityGainToolStripMenuItem,
- streamingModeToolStripMenuItem,
- deviceMenuItem);
+ streamingModeToolStripMenuItem);
var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, settings);
@@ -653,7 +652,8 @@ namespace grapher.Models
writeButton,
toggleButton,
mouseWatcher,
- scaleMenuItem);
+ scaleMenuItem,
+ deviceMenuItem);
}
#endregion Methods
diff --git a/grapher/Models/Devices/DeviceDialogItem.cs b/grapher/Models/Devices/DeviceDialogItem.cs
new file mode 100644
index 0000000..9ca5528
--- /dev/null
+++ b/grapher/Models/Devices/DeviceDialogItem.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher.Models.Devices
+{
+ public class DeviceDialogItem
+ {
+ public MultiHandleDevice device;
+ public DeviceSettings oldSettings;
+ public DeviceConfig newConfig;
+ public string newProfile;
+ public bool overrideDefaultConfig;
+
+ public override string ToString()
+ {
+ return string.IsNullOrWhiteSpace(device.name) ?
+ device.id :
+ device.name;
+ }
+ }
+}
diff --git a/grapher/Models/Devices/DeviceIDItem.cs b/grapher/Models/Devices/DeviceIDItem.cs
deleted file mode 100644
index 8f1587b..0000000
--- a/grapher/Models/Devices/DeviceIDItem.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace grapher.Models.Devices
-{
- public class DeviceIDItem
- {
- public DeviceIDItem(string name, string id, DeviceIDManager manager)
- {
- Name = name;
- ID = id;
- Manager = manager;
- DeviceIDMenuItem = new ToolStripMenuItem();
- DeviceIDMenuItem.Checked = false;
- DeviceIDMenuItem.Text = MenuItemText();
- DeviceIDMenuItem.Click += OnClicked;
- manager.DeviceIDsMenuItem.DropDownItems.Add(DeviceIDMenuItem);
- }
-
- private ToolStripMenuItem DeviceIDMenuItem { get; }
-
- public string Name { get; }
-
- public string ID { get; }
-
- private DeviceIDManager Manager { get; }
-
- public void SetActivated()
- {
- DeviceIDMenuItem.Checked = true;
- }
-
- public void SetDeactivated()
- {
- DeviceIDMenuItem.Checked = false;
- }
-
- private string MenuItemText() => string.IsNullOrEmpty(ID) ? $"{Name}" : ID.Replace("&", "&&");
-
- private string DisconnectedText() => $"Disconnected: {ID}";
-
- public void SetDisconnected()
- {
- DeviceIDMenuItem.ForeColor = Color.DarkGray;
- DeviceIDMenuItem.Text = DisconnectedText();
- }
-
- public void OnClicked(object sender, EventArgs e)
- {
- Manager.SetActive(this);
- }
-
- public override bool Equals(object obj)
- {
- return obj is DeviceIDItem item &&
- Name == item.Name &&
- ID == item.ID;
- }
-
- public override int GetHashCode()
- {
- int hashCode = -1692744877;
- hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Name);
- hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(ID);
- return hashCode;
- }
- }
-}
diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs
deleted file mode 100644
index e0ee686..0000000
--- a/grapher/Models/Devices/DeviceIDManager.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Management;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace grapher.Models.Devices
-{
- public class DeviceIDManager
- {
- public DeviceIDManager(ToolStripMenuItem deviceIDs)
- {
- DeviceIDsMenuItem = deviceIDs;
- DeviceIDsMenuItem.Checked = false;
- }
-
- public ToolStripMenuItem DeviceIDsMenuItem { get; }
-
- public string ID { get => SelectedDeviceID.ID; }
-
- public DeviceIDItem SelectedDeviceID { get; private set; }
-
- public Dictionary<string, DeviceIDItem> DeviceIDs { get; private set; }
-
- public void SetActive(DeviceIDItem deviceIDItem)
- {
- if (SelectedDeviceID != null)
- {
- SelectedDeviceID.SetDeactivated();
- }
-
- SelectedDeviceID = deviceIDItem;
- SelectedDeviceID.SetActivated();
- }
-
- public void Update(string devID)
- {
- DeviceIDsMenuItem.DropDownItems.Clear();
-
- bool found = string.IsNullOrEmpty(devID);
-
- var anyDevice = new DeviceIDItem("Any", string.Empty, this);
-
- if (found) SetActive(anyDevice);
-
-/* foreach (string id in RawInputInterop.GetDeviceIDs())
- {
- var deviceItem = new DeviceIDItem(string.Empty, id, this);
- if (!found && deviceItem.ID.Equals(devID))
- {
- SetActive(deviceItem);
- found = true;
- }
- }*/
-
- if (!found)
- {
- var deviceItem = new DeviceIDItem(string.Empty, devID, this);
- deviceItem.SetDisconnected();
- SetActive(deviceItem);
- }
- }
-
- }
-}
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs
index 3789c05..8c8bf15 100644
--- a/grapher/Models/Serialized/SettingsManager.cs
+++ b/grapher/Models/Serialized/SettingsManager.cs
@@ -21,8 +21,7 @@ namespace grapher.Models.Serialized
ToolStripMenuItem autoWrite,
ToolStripMenuItem showLastMouseMove,
ToolStripMenuItem showVelocityAndGain,
- ToolStripMenuItem streamingMode,
- ToolStripMenuItem deviceMenuItem)
+ ToolStripMenuItem streamingMode)
{
DpiField = dpiField;
PollRateField = pollRateField;
@@ -30,7 +29,6 @@ namespace grapher.Models.Serialized
ShowLastMouseMoveMenuItem = showLastMouseMove;
ShowVelocityAndGainMoveMenuItem = showVelocityAndGain;
StreamingModeMenuItem = streamingMode;
- deviceMenuItem.Click += (s, e) => new DeviceMenuForm(this).ShowDialog();
SystemDevices = new List<MultiHandleDevice>();
ActiveHandles = new List<IntPtr>();
@@ -47,14 +45,17 @@ namespace grapher.Models.Serialized
UpdateFieldsFromGUISettings();
}
- UserConfig = InitActiveAndGetUserConfig();
+ UserConfigField = InitActiveAndGetUserConfig();
}
#endregion Constructors
#region Fields
+ private EventHandler DeviceChangeField;
+
private DriverConfig ActiveConfigField;
+ private DriverConfig UserConfigField;
#endregion Fields
@@ -62,6 +63,12 @@ namespace grapher.Models.Serialized
public GUISettings GuiSettings { get; private set; }
+ public event EventHandler DeviceChange
+ {
+ add => DeviceChangeField += value;
+ remove => DeviceChangeField -= value;
+ }
+
public DriverConfig ActiveConfig
{
get => ActiveConfigField;
@@ -87,11 +94,16 @@ namespace grapher.Models.Serialized
get => ActiveConfig.accels[0];
}
- public DriverConfig UserConfig { get; private set; }
+ public DriverConfig UserConfig
+ {
+ get => UserConfigField;
+ private set => UserConfigField = value;
+ }
public Profile UserProfile
{
- get => UserConfig.profiles[0];
+ get => UserConfigField.profiles[0];
+ private set => UserConfigField.SetProfileAt(0, value);
}
public HashSet<string> ActiveProfileNamesSet { get; private set; }
@@ -133,12 +145,12 @@ namespace grapher.Models.Serialized
public bool TryActivate(Profile settings, out string errors)
{
- var old = ActiveProfile;
- ActiveProfile = settings;
- bool success = TryActivate(ActiveConfig, out errors);
+ var old = UserProfile;
+ UserProfile = settings;
+ bool success = TryActivate(UserConfig, out errors);
if (!success)
{
- ActiveProfile = old;
+ UserProfile = old;
}
return success;
}
@@ -183,7 +195,7 @@ namespace grapher.Models.Serialized
};
}
- private void SetActiveHandles()
+ public void SetActiveHandles()
{
ActiveHandles.Clear();
@@ -217,6 +229,37 @@ namespace grapher.Models.Serialized
}
}
+ public void Submit(DeviceConfig newDefaultConfig, DeviceDialogItem[] items)
+ {
+ UserConfig.defaultDeviceConfig = newDefaultConfig;
+ foreach (var item in items)
+ {
+ if (item.overrideDefaultConfig)
+ {
+ if (item.oldSettings is null)
+ {
+ UserConfig.devices.Add(
+ new DeviceSettings
+ {
+ name = item.device.name,
+ profile = item.newProfile,
+ id = item.device.id,
+ config = item.newConfig
+ });
+ }
+ else
+ {
+ item.oldSettings.config = item.newConfig;
+ item.oldSettings.profile = item.newProfile;
+ }
+ }
+ else if (!(item.oldSettings is null))
+ {
+ UserConfig.devices.Remove(item.oldSettings);
+ }
+ }
+ }
+
public void OnProfileSelectionChange()
{
SetActiveHandles();
@@ -226,6 +269,8 @@ namespace grapher.Models.Serialized
{
SystemDevices = MultiHandleDevice.GetList();
SetActiveHandles();
+
+ DeviceChangeField?.Invoke(this, EventArgs.Empty);
}
private DriverConfig InitActiveAndGetUserConfig()
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index bd6674d..702d89e 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -81,9 +81,6 @@
<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" />
@@ -109,8 +106,7 @@
<Compile Include="Models\Charts\EstimatedPoints.cs" />
<Compile Include="Models\Charts\ChartState\XYOneGraphState.cs" />
<Compile Include="Models\Charts\ChartState\XYTwoGraphState.cs" />
- <Compile Include="Models\Devices\DeviceIDItem.cs" />
- <Compile Include="Models\Devices\DeviceIDManager.cs" />
+ <Compile Include="Models\Devices\DeviceDialogItem.cs" />
<Compile Include="Models\Mouse\MouseData.cs" />
<Compile Include="Models\Mouse\MouseWatcher.cs" />
<Compile Include="Models\Mouse\PointData.cs" />
@@ -158,9 +154,6 @@
<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>