diff --git a/README.md b/README.md index d7acb0f..1a84096 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The GUI minimizes to system tray / notification area. You can reopen the GUI by ## Download -### http://hwk.fi/TabletDriver/TabletDriverV0.1.0.zip +### http://hwk.fi/TabletDriver/TabletDriverV0.1.1.zip # @@ -31,7 +31,7 @@ The GUI minimizes to system tray / notification area. You can reopen the GUI by - Wacom CTL-480 - Wacom CTH-480 - Wacom CTL-490 - - XP Pen G430 + - XP Pen G430 (New 2016-2017 "Model B") - XP Pen G640 - Huion 420 - Huion H640P @@ -39,6 +39,8 @@ The GUI minimizes to system tray / notification area. You can reopen the GUI by ### Configured, but not properly tested: - Huion H420 + - Wacom CTL-4100 USB + - Wacom CTL-4100 Bluetooth - Wacom CTH-470 - Wacom CTH-670 - Wacom CTL-671 @@ -63,10 +65,12 @@ The GUI minimizes to system tray / notification area. You can reopen the GUI by 6. Start the TabletDriverGUI.exe ## Updating to a new version + 1. Unzip the new version 2. Start the TabletDriverGUI.exe ## Uninstallation + 1. Uncheck the "Run at Windows startup" option in the GUI. 2. Run `remove_vmulti_driver.bat` 3. Run `remove_huion_64.bat`, which is in the `driver_huion` directory. @@ -87,6 +91,15 @@ If you want to compile the code and don't want to install anything from the Tabl ## Changelog +>**v0.1.1:** +> - Added support for Wacom CTL-4100 (USB and Bluetooth) +> - Added settings import / export to the main menu. +> - Added Wacom backup reader to the Wacom area tool. +> - Added tablet benchmark tools to the console output context menu (Right click). +> - Moved the `config.xml` to the `config` folder. +> - Added noise reduction filter (`Noise` command, not in the GUI) +> - Code refactoring + >**v0.1.0:** > - Added `Bench` / `Benchmark` command. > - Added `-hide` GUI command line parameter. GUI will start as minimized when you run `TabletDriverGUI.exe -hide` diff --git a/TabletDriverGUI/Configuration.cs b/TabletDriverGUI/Configuration.cs index 9f91ed9..bd98f71 100644 --- a/TabletDriverGUI/Configuration.cs +++ b/TabletDriverGUI/Configuration.cs @@ -26,9 +26,9 @@ public enum OutputModes public Area ScreenArea; - public double FilterLatency; - public int FilterInterval; - public bool FilterEnabled; + public double SmoothingLatency; + public int SmoothingInterval; + public bool SmoothingEnabled; public Area DesktopSize; public bool AutomaticDesktopSize; @@ -78,15 +78,15 @@ public Configuration() ButtonMap = new int[] { 1, 2, 3 }; DisableButtons = false; - FilterEnabled = false; - FilterLatency = 0; - FilterInterval = 4; + SmoothingEnabled = false; + SmoothingLatency = 0; + SmoothingInterval = 4; CommandsAfter = new string[] { "" }; CommandsBefore = new string[] { "" }; WindowWidth = 800; - WindowHeight = 690; + WindowHeight = 710; RunAtStartup = false; diff --git a/TabletDriverGUI/MainWindow.xaml b/TabletDriverGUI/MainWindow.xaml index 4bc8fae..7e47861 100644 --- a/TabletDriverGUI/MainWindow.xaml +++ b/TabletDriverGUI/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:TabletDriverGUI" mc:Ignorable="d" - Title="TabletDriverGUI" Height="670" Width="800" + Title="TabletDriverGUI" Height="670" Width="750" > - - + + + + + + + + + + + + + + + @@ -48,6 +61,7 @@ - - You can disable single button by selecting "Disable" from the list. + - You can disable a single button by selecting "Disable" from the list. - The "Disable buttons" checkbox will disable all tablet buttons. @@ -330,7 +345,7 @@ - 0 @@ -339,7 +354,7 @@ - + 500 Hz @@ -350,7 +365,7 @@ - @@ -475,6 +490,8 @@ + + diff --git a/TabletDriverGUI/MainWindow.xaml.cs b/TabletDriverGUI/MainWindow.xaml.cs index 0fe8ee7..19e74b7 100644 --- a/TabletDriverGUI/MainWindow.xaml.cs +++ b/TabletDriverGUI/MainWindow.xaml.cs @@ -24,7 +24,7 @@ public partial class MainWindow : Window { // Version - public string Version = "0.1.0"; + public string Version = "0.1.1"; // Console stuff private List commandHistory; @@ -45,6 +45,7 @@ public partial class MainWindow : Window // Config private Configuration config; + private string configFilename; private bool isFirstStart = false; private bool isLoadingSettings; @@ -60,9 +61,6 @@ public partial class MainWindow : Window private Polygon polygonTabletAreaArrow; private TextBlock textTabletAspectRatio; - // Culture - CultureInfo cultureEnglish; - // Mouse drag private class MouseDrag { @@ -99,10 +97,6 @@ public MainWindow() // Set culture to en-US to force decimal format and etc. CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); - cultureEnglish = new CultureInfo("en-US"); - cultureEnglish.NumberFormat.PerMilleSymbol = ""; - cultureEnglish.NumberFormat.NumberGroupSeparator = ""; - cultureEnglish.NumberFormat.PercentDecimalSeparator = "."; // Create notify icon @@ -130,7 +124,6 @@ public MainWindow() commandHistory = new List { "" }; commandHistoryIndex = 0; - // Init tablet driver driver = new TabletDriver("TabletDriverService.exe"); driver.MessageReceived += OnDriverMessageReceived; @@ -187,14 +180,14 @@ public MainWindow() // - // Filter rate ComboBox + // Smoothing rate ComboBox // - comboBoxFilterRate.Items.Clear(); + comboBoxSmoothingRate.Items.Clear(); for (int i = 2; i <= 8; i++) { - comboBoxFilterRate.Items.Add((1000.0 / i).ToString("0") + " Hz"); + comboBoxSmoothingRate.Items.Add((1000.0 / i).ToString("0") + " Hz"); } - comboBoxFilterRate.SelectedIndex = 2; + comboBoxSmoothingRate.SelectedIndex = 2; // Process command line arguments ProcessCommandLineArguments(); @@ -208,6 +201,8 @@ public MainWindow() isLoadingSettings = false; } + + #region Window events // Window is closing -> Stop driver @@ -216,7 +211,7 @@ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEvent notifyIcon.Visible = false; try { - config.Write("Config.xml"); + config.Write(configFilename); } catch (Exception) { @@ -227,10 +222,14 @@ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEvent // Window loaded -> Start driver private void MainWindow_Loaded(object sender, RoutedEventArgs e) { + + // Configuration filename + configFilename = "config/config.xml"; + // Load configuration try { - config = Configuration.CreateFromFile("Config.xml"); + config = Configuration.CreateFromFile(configFilename); } catch (Exception) { @@ -374,10 +373,10 @@ private void LoadSettingsFromConfiguration() // // Tablet area // - textTabletAreaWidth.Text = GetNumberString(config.TabletArea.Width); - textTabletAreaHeight.Text = GetNumberString(config.TabletArea.Height); - textTabletAreaX.Text = GetNumberString(config.TabletArea.X); - textTabletAreaY.Text = GetNumberString(config.TabletArea.Y); + textTabletAreaWidth.Text = Utils.GetNumberString(config.TabletArea.Width); + textTabletAreaHeight.Text = Utils.GetNumberString(config.TabletArea.Height); + textTabletAreaX.Text = Utils.GetNumberString(config.TabletArea.X); + textTabletAreaY.Text = Utils.GetNumberString(config.TabletArea.Y); checkBoxForceAspect.IsChecked = config.ForceAspectRatio; checkBoxForceFullArea.IsChecked = config.ForceFullArea; switch (config.OutputMode) @@ -392,9 +391,7 @@ private void LoadSettingsFromConfiguration() radioModeDigitizer.IsChecked = true; break; } - - textTabletAreaRotation.Text = GetNumberString(config.TabletArea.Rotation); - + textTabletAreaRotation.Text = Utils.GetNumberString(config.TabletArea.Rotation); // @@ -419,10 +416,10 @@ private void LoadSettingsFromConfiguration() // // Screen area // - textScreenAreaWidth.Text = GetNumberString(config.ScreenArea.Width, "0"); - textScreenAreaHeight.Text = GetNumberString(config.ScreenArea.Height, "0"); - textScreenAreaX.Text = GetNumberString(config.ScreenArea.X, "0"); - textScreenAreaY.Text = GetNumberString(config.ScreenArea.Y, "0"); + textScreenAreaWidth.Text = Utils.GetNumberString(config.ScreenArea.Width, "0"); + textScreenAreaHeight.Text = Utils.GetNumberString(config.ScreenArea.Height, "0"); + textScreenAreaX.Text = Utils.GetNumberString(config.ScreenArea.X, "0"); + textScreenAreaY.Text = Utils.GetNumberString(config.ScreenArea.Y, "0"); // @@ -430,8 +427,8 @@ private void LoadSettingsFromConfiguration() // if (config.AutomaticDesktopSize) { - textDesktopWidth.Text = GetNumberString(GetVirtualDesktopSize().Width); - textDesktopHeight.Text = GetNumberString(GetVirtualDesktopSize().Height); + textDesktopWidth.Text = Utils.GetNumberString(GetVirtualDesktopSize().Width); + textDesktopHeight.Text = Utils.GetNumberString(GetVirtualDesktopSize().Height); config.DesktopSize.Width = GetVirtualDesktopSize().Width; config.DesktopSize.Height = GetVirtualDesktopSize().Height; textDesktopWidth.IsEnabled = false; @@ -439,8 +436,8 @@ private void LoadSettingsFromConfiguration() } else { - textDesktopWidth.Text = GetNumberString(config.DesktopSize.Width); - textDesktopHeight.Text = GetNumberString(config.DesktopSize.Height); + textDesktopWidth.Text = Utils.GetNumberString(config.DesktopSize.Width); + textDesktopHeight.Text = Utils.GetNumberString(config.DesktopSize.Height); } checkBoxAutomaticDesktopSize.IsChecked = config.AutomaticDesktopSize; @@ -449,7 +446,7 @@ private void LoadSettingsFromConfiguration() if (config.ForceAspectRatio) { config.TabletArea.Height = config.TabletArea.Width / (config.ScreenArea.Width / config.ScreenArea.Height); - textTabletAreaHeight.Text = GetNumberString(config.TabletArea.Height); + textTabletAreaHeight.Text = Utils.GetNumberString(config.TabletArea.Height); textTabletAreaHeight.IsEnabled = false; } @@ -458,8 +455,8 @@ private void LoadSettingsFromConfiguration() // Move tablet area to a valid position // config.TabletArea.MoveInside(config.TabletFullArea); - textTabletAreaX.Text = GetNumberString(config.TabletArea.X); - textTabletAreaY.Text = GetNumberString(config.TabletArea.Y); + textTabletAreaX.Text = Utils.GetNumberString(config.TabletArea.X); + textTabletAreaY.Text = Utils.GetNumberString(config.TabletArea.Y); // @@ -479,24 +476,25 @@ private void LoadSettingsFromConfiguration() // - // Filter + // Smoothing filter // - checkBoxFilter.IsChecked = config.FilterEnabled; - textFilterLatency.Text = GetNumberString(config.FilterLatency); - comboBoxFilterRate.SelectedIndex = config.FilterInterval - 2; - if (config.FilterEnabled) + checkBoxSmoothing.IsChecked = config.SmoothingEnabled; + textSmoothingLatency.Text = Utils.GetNumberString(config.SmoothingLatency); + comboBoxSmoothingRate.SelectedIndex = config.SmoothingInterval - 2; + if (config.SmoothingEnabled) { - textFilterLatency.IsEnabled = true; - comboBoxFilterRate.IsEnabled = true; + textSmoothingLatency.IsEnabled = true; + comboBoxSmoothingRate.IsEnabled = true; } else { - textFilterLatency.IsEnabled = false; - comboBoxFilterRate.IsEnabled = false; + textSmoothingLatency.IsEnabled = false; + comboBoxSmoothingRate.IsEnabled = false; } - + // // Run at startup + // checkRunAtStartup.IsChecked = config.RunAtStartup; @@ -519,8 +517,11 @@ private void LoadSettingsFromConfiguration() } textCommandsAfter.Text = tmp; + + // Update canvases UpdateCanvasElements(); + isLoadingSettings = false; } @@ -535,20 +536,21 @@ private void UpdateSettingsToConfiguration() bool oldValue; // Tablet area - if (ParseNumber(textTabletAreaWidth.Text, out double value)) - config.TabletArea.Width = value; - if (ParseNumber(textTabletAreaHeight.Text, out value)) - config.TabletArea.Height = value; - if (ParseNumber(textTabletAreaX.Text, out value)) - config.TabletArea.X = value; - if (ParseNumber(textTabletAreaY.Text, out value)) - config.TabletArea.Y = value; - if (ParseNumber(textTabletAreaRotation.Text, out value)) - config.TabletArea.Rotation = value; + if (Utils.ParseNumber(textTabletAreaWidth.Text, out double val)) + config.TabletArea.Width = val; + if (Utils.ParseNumber(textTabletAreaHeight.Text, out val)) + config.TabletArea.Height = val; + if (Utils.ParseNumber(textTabletAreaX.Text, out val)) + config.TabletArea.X = val; + if (Utils.ParseNumber(textTabletAreaY.Text, out val)) + config.TabletArea.Y = val; + if (Utils.ParseNumber(textTabletAreaRotation.Text, out val)) + config.TabletArea.Rotation = val; config.ForceAspectRatio = (bool)checkBoxForceAspect.IsChecked; config.ForceFullArea = (bool)checkBoxForceFullArea.IsChecked; + // Output Mode if (radioModeAbsolute.IsChecked == true) config.OutputMode = Configuration.OutputModes.Absolute; if (radioModeRelative.IsChecked == true) config.OutputMode = Configuration.OutputModes.Relative; if (radioModeDigitizer.IsChecked == true) config.OutputMode = Configuration.OutputModes.Digitizer; @@ -568,37 +570,35 @@ private void UpdateSettingsToConfiguration() // Fit area to full area config.TabletArea.ScaleInside(config.TabletFullArea); - textTabletAreaWidth.Text = GetNumberString(config.TabletArea.Width); - textTabletAreaHeight.Text = GetNumberString(config.TabletArea.Height); + textTabletAreaWidth.Text = Utils.GetNumberString(config.TabletArea.Width); + textTabletAreaHeight.Text = Utils.GetNumberString(config.TabletArea.Height); - // Center - //config.TabletArea.X = config.TabletFullArea.Width / 2.0; - //config.TabletArea.Y = config.TabletFullArea.Height / 2.0; } + // Force the tablet area to be inside of the full area config.TabletArea.MoveInside(config.TabletFullArea); // Screen area - if (ParseNumber(textScreenAreaWidth.Text, out value)) - config.ScreenArea.Width = value; - if (ParseNumber(textScreenAreaHeight.Text, out value)) - config.ScreenArea.Height = value; - if (ParseNumber(textScreenAreaX.Text, out value)) - config.ScreenArea.X = value; - if (ParseNumber(textScreenAreaY.Text, out value)) - config.ScreenArea.Y = value; + if (Utils.ParseNumber(textScreenAreaWidth.Text, out val)) + config.ScreenArea.Width = val; + if (Utils.ParseNumber(textScreenAreaHeight.Text, out val)) + config.ScreenArea.Height = val; + if (Utils.ParseNumber(textScreenAreaX.Text, out val)) + config.ScreenArea.X = val; + if (Utils.ParseNumber(textScreenAreaY.Text, out val)) + config.ScreenArea.Y = val; // Desktop size - if (ParseNumber(textDesktopWidth.Text, out value)) - config.DesktopSize.Width = value; - if (ParseNumber(textDesktopHeight.Text, out value)) - config.DesktopSize.Height = value; + if (Utils.ParseNumber(textDesktopWidth.Text, out val)) + config.DesktopSize.Width = val; + if (Utils.ParseNumber(textDesktopHeight.Text, out val)) + config.DesktopSize.Height = val; config.AutomaticDesktopSize = (bool)checkBoxAutomaticDesktopSize.IsChecked; if (config.AutomaticDesktopSize == true) { - textDesktopWidth.Text = GetNumberString(GetVirtualDesktopSize().Width); - textDesktopHeight.Text = GetNumberString(GetVirtualDesktopSize().Height); + textDesktopWidth.Text = Utils.GetNumberString(GetVirtualDesktopSize().Width); + textDesktopHeight.Text = Utils.GetNumberString(GetVirtualDesktopSize().Height); config.DesktopSize.Width = GetVirtualDesktopSize().Width; config.DesktopSize.Height = GetVirtualDesktopSize().Height; } @@ -608,7 +608,7 @@ private void UpdateSettingsToConfiguration() if (config.ForceAspectRatio) { config.TabletArea.Height = config.TabletArea.Width / (config.ScreenArea.Width / config.ScreenArea.Height); - textTabletAreaHeight.Text = GetNumberString(config.TabletArea.Height); + textTabletAreaHeight.Text = Utils.GetNumberString(config.TabletArea.Height); } @@ -621,20 +621,20 @@ private void UpdateSettingsToConfiguration() // Filter - config.FilterEnabled = (bool)checkBoxFilter.IsChecked; - config.FilterInterval = comboBoxFilterRate.SelectedIndex + 2; - if (ParseNumber(textFilterLatency.Text, out value)) - config.FilterLatency = value; + config.SmoothingEnabled = (bool)checkBoxSmoothing.IsChecked; + config.SmoothingInterval = comboBoxSmoothingRate.SelectedIndex + 2; + if (Utils.ParseNumber(textSmoothingLatency.Text, out val)) + config.SmoothingLatency = val; - if (config.FilterEnabled) + if (config.SmoothingEnabled) { - textFilterLatency.IsEnabled = true; - comboBoxFilterRate.IsEnabled = true; + textSmoothingLatency.IsEnabled = true; + comboBoxSmoothingRate.IsEnabled = true; } else { - textFilterLatency.IsEnabled = false; - comboBoxFilterRate.IsEnabled = false; + textSmoothingLatency.IsEnabled = false; + comboBoxSmoothingRate.IsEnabled = false; } // @@ -665,33 +665,6 @@ private void UpdateSettingsToConfiguration() } - // - // String to Number - // - private bool ParseNumber(string str, out double value) - { - value = 0; - if (double.TryParse(str, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, cultureEnglish.NumberFormat, out double tmp)) - { - value = tmp; - return true; - } - return false; - } - - // - // Number to String - // - private string GetNumberString(double value) - { - return GetNumberString(value, "0.##"); - } - private string GetNumberString(double value, string format) - { - return value.ToString(format, cultureEnglish.NumberFormat); - } - - // // Set run at startup // @@ -939,7 +912,7 @@ void UpdateScreenMapCanvas() Canvas.SetTop(rectangleScreenMap, offsetY + config.ScreenArea.Y * scale); // Screen aspect ratio text - textScreenAspectRatio.Text = GetNumberString(config.ScreenArea.Width / config.ScreenArea.Height, "0.###") + ":1"; + textScreenAspectRatio.Text = Utils.GetNumberString(config.ScreenArea.Width / config.ScreenArea.Height, "0.###") + ":1"; Canvas.SetLeft(textScreenAspectRatio, offsetX + (config.ScreenArea.X + config.ScreenArea.Width / 2.0) * scale - textScreenAspectRatio.ActualWidth / 2.0 @@ -1055,7 +1028,7 @@ void UpdateTabletAreaCanvas() // // Tablet area aspect ratio text // - textTabletAspectRatio.Text = GetNumberString(config.TabletArea.Width / config.TabletArea.Height, "0.###") + ":1"; + textTabletAspectRatio.Text = Utils.GetNumberString(config.TabletArea.Width / config.TabletArea.Height, "0.###") + ":1"; Canvas.SetLeft(textTabletAspectRatio, offsetX + (config.TabletArea.X) * scale - textTabletAspectRatio.ActualWidth / 2.0); Canvas.SetTop(textTabletAspectRatio, offsetY + (config.TabletArea.Y) * scale - textTabletAspectRatio.ActualHeight / 2.0); @@ -1101,10 +1074,10 @@ private void Canvas_MouseUp(object sender, MouseButtonEventArgs e) mouseDrag.IsMouseDown = false; LoadSettingsFromConfiguration(); isLoadingSettings = true; - textScreenAreaX.Text = GetNumberString(config.ScreenArea.X, "0"); - textScreenAreaY.Text = GetNumberString(config.ScreenArea.Y, "0"); - textTabletAreaX.Text = GetNumberString(config.TabletArea.X); - textTabletAreaY.Text = GetNumberString(config.TabletArea.Y); + textScreenAreaX.Text = Utils.GetNumberString(config.ScreenArea.X, "0"); + textScreenAreaY.Text = Utils.GetNumberString(config.ScreenArea.Y, "0"); + textTabletAreaX.Text = Utils.GetNumberString(config.TabletArea.X); + textTabletAreaY.Text = Utils.GetNumberString(config.TabletArea.Y); isLoadingSettings = false; canvasScreenMap.ReleaseMouseCapture(); canvasTabletArea.ReleaseMouseCapture(); @@ -1216,8 +1189,8 @@ private void CheckboxChanged(object sender, RoutedEventArgs e) // Disable desktop size settings when automatic is checked if (checkBoxAutomaticDesktopSize.IsChecked == true) { - textDesktopWidth.Text = GetNumberString(GetVirtualDesktopSize().Width); - textDesktopHeight.Text = GetNumberString(GetVirtualDesktopSize().Height); + textDesktopWidth.Text = Utils.GetNumberString(GetVirtualDesktopSize().Width); + textDesktopHeight.Text = Utils.GetNumberString(GetVirtualDesktopSize().Height); textDesktopWidth.IsEnabled = false; textDesktopHeight.IsEnabled = false; } @@ -1296,18 +1269,18 @@ private void ComboBoxMonitor_SelectionChanged(object sender, SelectionChangedEve { textScreenAreaX.Text = "0"; textScreenAreaY.Text = "0"; - textScreenAreaWidth.Text = GetNumberString(config.DesktopSize.Width); - textScreenAreaHeight.Text = GetNumberString(config.DesktopSize.Height); + textScreenAreaWidth.Text = Utils.GetNumberString(config.DesktopSize.Width); + textScreenAreaHeight.Text = Utils.GetNumberString(config.DesktopSize.Height); } else if (index > 0) { index--; if (index >= 0 && index < screens.Length) { - textScreenAreaX.Text = GetNumberString(screens[index].Bounds.X - minX); - textScreenAreaY.Text = GetNumberString(screens[index].Bounds.Y - minY); - textScreenAreaWidth.Text = GetNumberString(screens[index].Bounds.Width); - textScreenAreaHeight.Text = GetNumberString(screens[index].Bounds.Height); + textScreenAreaX.Text = Utils.GetNumberString(screens[index].Bounds.X - minX); + textScreenAreaY.Text = Utils.GetNumberString(screens[index].Bounds.Y - minY); + textScreenAreaWidth.Text = Utils.GetNumberString(screens[index].Bounds.Width); + textScreenAreaHeight.Text = Utils.GetNumberString(screens[index].Bounds.Height); } } UpdateSettingsToConfiguration(); @@ -1320,7 +1293,7 @@ private void SaveSettings(object sender, RoutedEventArgs e) { try { - config.Write("Config.xml"); + config.Write(configFilename); SendSettingsToDriver(); SetStatus("Settings saved!"); } @@ -1343,6 +1316,74 @@ private void ApplySettings(object sender, RoutedEventArgs e) SetStatus("Settings applied!"); } + + // + // Main Menu Click + // + private void MainMenuClick(object sender, RoutedEventArgs e) + { + + // Import + if (sender == mainMenuImport) + { + OpenFileDialog dialog = new OpenFileDialog + { + InitialDirectory = Directory.GetCurrentDirectory(), + Filter = "XML File|*.xml" + }; + if (dialog.ShowDialog() == true) + { + try + { + Configuration tmpConfig = Configuration.CreateFromFile(dialog.FileName); + config = tmpConfig; + LoadSettingsFromConfiguration(); + SetStatus("Settings imported!"); + } + catch (Exception) + { + MessageBox.Show("Settings import failed!", "ERROR!", + MessageBoxButton.OK, MessageBoxImage.Error); + } + } + } + + // Export + else if (sender == mainMenuExport) + { + SaveFileDialog dialog = new SaveFileDialog + { + InitialDirectory = Directory.GetCurrentDirectory(), + AddExtension = true, + DefaultExt = "xml", + Filter = "XML File|*.xml" + + }; + if (dialog.ShowDialog() == true) + { + try + { + UpdateSettingsToConfiguration(); + config.Write(dialog.FileName); + SetStatus("Settings exported!"); + } + catch (Exception) + { + MessageBox.Show("Settings export failed!", "ERROR!", + MessageBoxButton.OK, MessageBoxImage.Error); + } + } + + } + + // Exit + else if (sender == mainMenuExit) + { + Close(); + } + + } + #endregion @@ -1515,10 +1556,10 @@ private void ParseDriverStatus(string line) // if (variableName == "width") { - if (ParseNumber(stringValue, out double value)) + if (Utils.ParseNumber(stringValue, out double val)) { - config.TabletFullArea.Width = value; - config.TabletFullArea.X = value / 2.0; + config.TabletFullArea.Width = val; + config.TabletFullArea.X = val / 2.0; LoadSettingsFromConfiguration(); UpdateSettingsToConfiguration(); if (isFirstStart) @@ -1531,10 +1572,10 @@ private void ParseDriverStatus(string line) // if (variableName == "height") { - if (ParseNumber(stringValue, out double value)) + if (Utils.ParseNumber(stringValue, out double val)) { - config.TabletFullArea.Height = value; - config.TabletFullArea.Y = value / 2.0; + config.TabletFullArea.Height = val; + config.TabletFullArea.Y = val / 2.0; LoadSettingsFromConfiguration(); UpdateSettingsToConfiguration(); if (isFirstStart) @@ -1571,18 +1612,18 @@ private void SendSettingsToDriver() // Screen area driver.SendCommand("ScreenArea " + - GetNumberString(config.ScreenArea.Width) + " " + GetNumberString(config.ScreenArea.Height) + " " + - GetNumberString(config.ScreenArea.X) + " " + GetNumberString(config.ScreenArea.Y) + Utils.GetNumberString(config.ScreenArea.Width) + " " + Utils.GetNumberString(config.ScreenArea.Height) + " " + + Utils.GetNumberString(config.ScreenArea.X) + " " + Utils.GetNumberString(config.ScreenArea.Y) ); // Tablet area driver.SendCommand("Area " + - GetNumberString(config.TabletArea.Width) + " " + GetNumberString(config.TabletArea.Height) + " " + - GetNumberString(config.TabletArea.X) + " " + GetNumberString(config.TabletArea.Y) + Utils.GetNumberString(config.TabletArea.Width) + " " + Utils.GetNumberString(config.TabletArea.Height) + " " + + Utils.GetNumberString(config.TabletArea.X) + " " + Utils.GetNumberString(config.TabletArea.Y) ); // Rotation - driver.SendCommand("Rotate " + GetNumberString(config.TabletArea.Rotation)); + driver.SendCommand("Rotate " + Utils.GetNumberString(config.TabletArea.Rotation)); // Output Mode switch (config.OutputMode) @@ -1592,7 +1633,7 @@ private void SendSettingsToDriver() break; case Configuration.OutputModes.Relative: driver.SendCommand("Mode Relative"); - driver.SendCommand("Sensitivity " + GetNumberString(config.ScreenArea.Width / config.TabletArea.Width)); + driver.SendCommand("Sensitivity " + Utils.GetNumberString(config.ScreenArea.Width / config.TabletArea.Width)); break; case Configuration.OutputModes.Digitizer: driver.SendCommand("Mode Digitizer"); @@ -1610,15 +1651,15 @@ private void SendSettingsToDriver() driver.SendCommand("ButtonMap " + String.Join(" ", config.ButtonMap)); } - // Filter - if (config.FilterEnabled) + // Smoothing filter + if (config.SmoothingEnabled) { - driver.SendCommand("Filter " + GetNumberString(config.FilterLatency)); - driver.SendCommand("FilterInterval " + GetNumberString(config.FilterInterval)); + driver.SendCommand("Smoothing " + Utils.GetNumberString(config.SmoothingLatency)); + driver.SendCommand("SmoothingInterval " + Utils.GetNumberString(config.SmoothingInterval)); } else { - driver.SendCommand("Filter 0"); + driver.SendCommand("Smoothing 0"); } // Commands after settings @@ -1902,6 +1943,42 @@ private void ConsoleMenuClick(object sender, RoutedEventArgs e) } } + // Run benchmark + else if (sender == menuRunBenchmark) + { + ConsoleSendCommand("Benchmark"); + } + + // Copy Benchmark + else if (sender == menuCopyBenchmark) + { + string clipboard = ""; + List rows; + driver.ConsoleLock(); + rows = SearchRows(driver.ConsoleBuffer, " [STATUS] BENCHMARK ", 0, 0); + driver.ConsoleUnlock(); + foreach (string row in rows) + { + Match m = Regex.Match(row, " BENCHMARK ([0-9\\.]+) ([0-9\\.]+) ([0-9\\.]+) (.*)$"); + if (m.Success) + { + string tabletName = m.Groups[4].ToString(); + string totalPackets = m.Groups[1].ToString(); + string noiseWidth = m.Groups[2].ToString(); + string noiseHeight = m.Groups[3].ToString(); + clipboard = + "Tablet(" + tabletName + ") " + + "Noise(" + noiseWidth + " mm x " + noiseHeight + " mm) " + + "Packets(" + totalPackets + ")\r\n"; + } + } + + if (clipboard.Length > 0) + { + Clipboard.SetText(clipboard); + SetStatus("Benchmark result copied to clipboard"); + } + } // Open startup log else if (sender == menuOpenStartup) @@ -1967,11 +2044,11 @@ private void ConsoleMenuClick(object sender, RoutedEventArgs e) private void ButtonWacomArea_Click(object sender, RoutedEventArgs e) { WacomArea wacom = new WacomArea(); - wacom.textWacomLeft.Text = GetNumberString((config.TabletArea.X - config.TabletArea.Width / 2) * 100.0, "0"); - wacom.textWacomRight.Text = GetNumberString((config.TabletArea.X + config.TabletArea.Width / 2) * 100.0, "0"); + wacom.textWacomLeft.Text = Utils.GetNumberString((config.TabletArea.X - config.TabletArea.Width / 2) * 100.0, "0"); + wacom.textWacomRight.Text = Utils.GetNumberString((config.TabletArea.X + config.TabletArea.Width / 2) * 100.0, "0"); - wacom.textWacomTop.Text = GetNumberString((config.TabletArea.Y - config.TabletArea.Height / 2) * 100.0, "0"); - wacom.textWacomBottom.Text = GetNumberString((config.TabletArea.Y + config.TabletArea.Height / 2) * 100.0, "0"); + wacom.textWacomTop.Text = Utils.GetNumberString((config.TabletArea.Y - config.TabletArea.Height / 2) * 100.0, "0"); + wacom.textWacomBottom.Text = Utils.GetNumberString((config.TabletArea.Y + config.TabletArea.Height / 2) * 100.0, "0"); wacom.ShowDialog(); @@ -1979,10 +2056,10 @@ private void ButtonWacomArea_Click(object sender, RoutedEventArgs e) if (wacom.DialogResult == true) { if ( - ParseNumber(wacom.textWacomLeft.Text, out double left) && - ParseNumber(wacom.textWacomRight.Text, out double right) && - ParseNumber(wacom.textWacomTop.Text, out double top) && - ParseNumber(wacom.textWacomBottom.Text, out double bottom) + Utils.ParseNumber(wacom.textWacomLeft.Text, out double left) && + Utils.ParseNumber(wacom.textWacomRight.Text, out double right) && + Utils.ParseNumber(wacom.textWacomTop.Text, out double top) && + Utils.ParseNumber(wacom.textWacomBottom.Text, out double bottom) ) { double width, height; @@ -2045,5 +2122,6 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b #endregion + } } \ No newline at end of file diff --git a/TabletDriverGUI/TabletDriverGUI.csproj b/TabletDriverGUI/TabletDriverGUI.csproj index 3bb7241..ed30a36 100644 --- a/TabletDriverGUI/TabletDriverGUI.csproj +++ b/TabletDriverGUI/TabletDriverGUI.csproj @@ -77,6 +77,7 @@ MSBuild:Compile Designer + diff --git a/TabletDriverGUI/Utils.cs b/TabletDriverGUI/Utils.cs new file mode 100644 index 0000000..1481209 --- /dev/null +++ b/TabletDriverGUI/Utils.cs @@ -0,0 +1,60 @@ +using System.Globalization; + +namespace TabletDriverGUI +{ + public class Utils + { + public static CultureInfo cultureInfo = null; + + + // + // Check and create culture info + // + public static void CheckCultureInfo() + { + if (cultureInfo == null) + { + cultureInfo = new CultureInfo("en-US"); + cultureInfo.NumberFormat.PerMilleSymbol = ""; + + cultureInfo.NumberFormat.NumberDecimalSeparator = "."; + cultureInfo.NumberFormat.NumberGroupSeparator = ""; + + cultureInfo.NumberFormat.PercentDecimalSeparator = "."; + cultureInfo.NumberFormat.PercentGroupSeparator = ""; + + cultureInfo.NumberFormat.CurrencyDecimalSeparator = "."; + cultureInfo.NumberFormat.CurrencyGroupSeparator = ""; + } + } + + // + // String to Number + // + public static bool ParseNumber(string str, out double val) + { + CheckCultureInfo(); + val = 0; + if (double.TryParse(str, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, cultureInfo.NumberFormat, out double tmp)) + { + val = tmp; + return true; + } + return false; + } + + // + // Number to String + // + public static string GetNumberString(double val) + { + CheckCultureInfo(); + return GetNumberString(val, "0.##"); + } + public static string GetNumberString(double val, string format) + { + CheckCultureInfo(); + return val.ToString(format, cultureInfo.NumberFormat); + } + } +} diff --git a/TabletDriverGUI/WacomArea.xaml b/TabletDriverGUI/WacomArea.xaml index 3433270..7e8b267 100644 --- a/TabletDriverGUI/WacomArea.xaml +++ b/TabletDriverGUI/WacomArea.xaml @@ -45,6 +45,7 @@ +