From 7c0305ae2c99c191baf61eb920025826057d5753 Mon Sep 17 00:00:00 2001
From: a1xd <68629610+a1xd@users.noreply.github.com>
Date: Wed, 15 Sep 2021 06:41:57 -0400
Subject: add device menu
---
grapher/DeviceMenuForm.Designer.cs | 51 ----
grapher/DeviceMenuForm.cs | 402 ++++++++++++++++++++++++++-
grapher/DeviceMenuForm.resx | 120 --------
grapher/Models/AccelGUI.cs | 23 +-
grapher/Models/AccelGUIFactory.cs | 6 +-
grapher/Models/Devices/DeviceDialogItem.cs | 26 ++
grapher/Models/Devices/DeviceIDItem.cs | 73 -----
grapher/Models/Devices/DeviceIDManager.cs | 68 -----
grapher/Models/Serialized/SettingsManager.cs | 67 ++++-
grapher/grapher.csproj | 9 +-
10 files changed, 501 insertions(+), 344 deletions(-)
delete mode 100644 grapher/DeviceMenuForm.Designer.cs
delete mode 100644 grapher/DeviceMenuForm.resx
create mode 100644 grapher/Models/Devices/DeviceDialogItem.cs
delete mode 100644 grapher/Models/Devices/DeviceIDItem.cs
delete mode 100644 grapher/Models/Devices/DeviceIDManager.cs
(limited to 'grapher')
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
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- 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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ 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.Default.GetHashCode(Name);
- hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ID);
- return hashCode;
- }
- }
-}
diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs
deleted file mode 100644
index e0ee686..0000000
--- a/grapher/Models/Devices/DeviceIDManager.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Management;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace grapher.Models.Devices
-{
- public class DeviceIDManager
- {
- public DeviceIDManager(ToolStripMenuItem deviceIDs)
- {
- DeviceIDsMenuItem = deviceIDs;
- DeviceIDsMenuItem.Checked = false;
- }
-
- public ToolStripMenuItem DeviceIDsMenuItem { get; }
-
- public string ID { get => SelectedDeviceID.ID; }
-
- public DeviceIDItem SelectedDeviceID { get; private set; }
-
- public Dictionary DeviceIDs { get; private set; }
-
- public void SetActive(DeviceIDItem deviceIDItem)
- {
- if (SelectedDeviceID != null)
- {
- SelectedDeviceID.SetDeactivated();
- }
-
- SelectedDeviceID = deviceIDItem;
- SelectedDeviceID.SetActivated();
- }
-
- public void Update(string devID)
- {
- DeviceIDsMenuItem.DropDownItems.Clear();
-
- bool found = string.IsNullOrEmpty(devID);
-
- var anyDevice = new DeviceIDItem("Any", string.Empty, this);
-
- if (found) SetActive(anyDevice);
-
-/* foreach (string id in RawInputInterop.GetDeviceIDs())
- {
- var deviceItem = new DeviceIDItem(string.Empty, id, this);
- if (!found && deviceItem.ID.Equals(devID))
- {
- SetActive(deviceItem);
- found = true;
- }
- }*/
-
- if (!found)
- {
- var deviceItem = new DeviceIDItem(string.Empty, devID, this);
- deviceItem.SetDisconnected();
- SetActive(deviceItem);
- }
- }
-
- }
-}
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs
index 3789c05..8c8bf15 100644
--- a/grapher/Models/Serialized/SettingsManager.cs
+++ b/grapher/Models/Serialized/SettingsManager.cs
@@ -21,8 +21,7 @@ namespace grapher.Models.Serialized
ToolStripMenuItem autoWrite,
ToolStripMenuItem showLastMouseMove,
ToolStripMenuItem showVelocityAndGain,
- ToolStripMenuItem streamingMode,
- ToolStripMenuItem deviceMenuItem)
+ ToolStripMenuItem streamingMode)
{
DpiField = dpiField;
PollRateField = pollRateField;
@@ -30,7 +29,6 @@ namespace grapher.Models.Serialized
ShowLastMouseMoveMenuItem = showLastMouseMove;
ShowVelocityAndGainMoveMenuItem = showVelocityAndGain;
StreamingModeMenuItem = streamingMode;
- deviceMenuItem.Click += (s, e) => new DeviceMenuForm(this).ShowDialog();
SystemDevices = new List();
ActiveHandles = new List();
@@ -47,14 +45,17 @@ namespace grapher.Models.Serialized
UpdateFieldsFromGUISettings();
}
- UserConfig = InitActiveAndGetUserConfig();
+ UserConfigField = InitActiveAndGetUserConfig();
}
#endregion Constructors
#region Fields
+ private EventHandler DeviceChangeField;
+
private DriverConfig ActiveConfigField;
+ private DriverConfig UserConfigField;
#endregion Fields
@@ -62,6 +63,12 @@ namespace grapher.Models.Serialized
public GUISettings GuiSettings { get; private set; }
+ public event EventHandler DeviceChange
+ {
+ add => DeviceChangeField += value;
+ remove => DeviceChangeField -= value;
+ }
+
public DriverConfig ActiveConfig
{
get => ActiveConfigField;
@@ -87,11 +94,16 @@ namespace grapher.Models.Serialized
get => ActiveConfig.accels[0];
}
- public DriverConfig UserConfig { get; private set; }
+ public DriverConfig UserConfig
+ {
+ get => UserConfigField;
+ private set => UserConfigField = value;
+ }
public Profile UserProfile
{
- get => UserConfig.profiles[0];
+ get => UserConfigField.profiles[0];
+ private set => UserConfigField.SetProfileAt(0, value);
}
public HashSet ActiveProfileNamesSet { get; private set; }
@@ -133,12 +145,12 @@ namespace grapher.Models.Serialized
public bool TryActivate(Profile settings, out string errors)
{
- var old = ActiveProfile;
- ActiveProfile = settings;
- bool success = TryActivate(ActiveConfig, out errors);
+ var old = UserProfile;
+ UserProfile = settings;
+ bool success = TryActivate(UserConfig, out errors);
if (!success)
{
- ActiveProfile = old;
+ UserProfile = old;
}
return success;
}
@@ -183,7 +195,7 @@ namespace grapher.Models.Serialized
};
}
- private void SetActiveHandles()
+ public void SetActiveHandles()
{
ActiveHandles.Clear();
@@ -217,6 +229,37 @@ namespace grapher.Models.Serialized
}
}
+ public void Submit(DeviceConfig newDefaultConfig, DeviceDialogItem[] items)
+ {
+ UserConfig.defaultDeviceConfig = newDefaultConfig;
+ foreach (var item in items)
+ {
+ if (item.overrideDefaultConfig)
+ {
+ if (item.oldSettings is null)
+ {
+ UserConfig.devices.Add(
+ new DeviceSettings
+ {
+ name = item.device.name,
+ profile = item.newProfile,
+ id = item.device.id,
+ config = item.newConfig
+ });
+ }
+ else
+ {
+ item.oldSettings.config = item.newConfig;
+ item.oldSettings.profile = item.newProfile;
+ }
+ }
+ else if (!(item.oldSettings is null))
+ {
+ UserConfig.devices.Remove(item.oldSettings);
+ }
+ }
+ }
+
public void OnProfileSelectionChange()
{
SetActiveHandles();
@@ -226,6 +269,8 @@ namespace grapher.Models.Serialized
{
SystemDevices = MultiHandleDevice.GetList();
SetActiveHandles();
+
+ DeviceChangeField?.Invoke(this, EventArgs.Empty);
}
private DriverConfig InitActiveAndGetUserConfig()
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 @@
Form
-
- DeviceMenuForm.cs
-
@@ -109,8 +106,7 @@
-
-
+
@@ -158,9 +154,6 @@
AboutBox.cs
Designer
-
- DeviceMenuForm.cs
-
Form1.cs
--
cgit v1.2.3