From 25c05e1827b2df6e940c5652af5e0b2dd05ac3e0 Mon Sep 17 00:00:00 2001 From: yuwui Date: Wed, 5 Feb 2020 20:49:06 +0100 Subject: [PATCH 1/3] Implement config switcher --- TabletDriverGUI/App.xaml | 4 +- TabletDriverGUI/Area.cs | 6 +- TabletDriverGUI/Configuration.cs | 88 +- TabletDriverGUI/MainWindow.Settings.cs | 74 +- TabletDriverGUI/MainWindow.xaml | 2782 ++++++++--------- TabletDriverGUI/MainWindow.xaml.cs | 40 +- TabletDriverGUI/NativeMethods.cs | 18 +- TabletDriverGUI/WindowAreaEditor.xaml | 199 +- TabletDriverGUI/WindowButtonMapping.xaml | 122 +- TabletDriverGUI/WindowMessageBox.xaml | 53 +- TabletDriverGUI/WindowTabletView.xaml | 76 +- TabletDriverGUI/WindowTabletViewSettings.xaml | 259 +- TabletDriverGUI/WindowWacomArea.xaml | 91 +- 13 files changed, 1884 insertions(+), 1928 deletions(-) diff --git a/TabletDriverGUI/App.xaml b/TabletDriverGUI/App.xaml index e13b539..f355586 100644 --- a/TabletDriverGUI/App.xaml +++ b/TabletDriverGUI/App.xaml @@ -1,6 +1,6 @@  - - + + diff --git a/TabletDriverGUI/Area.cs b/TabletDriverGUI/Area.cs index d2ed205..f56596a 100644 --- a/TabletDriverGUI/Area.cs +++ b/TabletDriverGUI/Area.cs @@ -56,12 +56,9 @@ public double Rotation } public bool IsEnabled; - - private double _rotation; private readonly double[] _rotationMatrix; - private readonly Point[] _corners; - + private readonly Point[] _corners; // // Constructors @@ -238,6 +235,5 @@ public override string ToString() Utils.GetNumberString(Height) + "]"; } - } } diff --git a/TabletDriverGUI/Configuration.cs b/TabletDriverGUI/Configuration.cs index 25bd26b..f704dac 100644 --- a/TabletDriverGUI/Configuration.cs +++ b/TabletDriverGUI/Configuration.cs @@ -10,19 +10,20 @@ namespace TabletDriverGUI public class Configuration { public int ConfigVersion; - public string TabletName; - public Area ScreenArea; + [XmlArray("ScreenAreas")] [XmlArrayItem("ScreenArea")] public Area[] ScreenAreas; - public Area SelectedScreenArea; + public Area SelectedScreenArea; public Area TabletArea; + [XmlArray("TabletAreas")] [XmlArrayItem("TabletArea")] public Area[] TabletAreas; + public Area SelectedTabletArea; public Area TabletFullArea; @@ -37,6 +38,7 @@ public enum OutputPositioning Absolute = 0, Relative = 1 } + public enum OutputModes { Standard = 0, @@ -63,6 +65,7 @@ public class AntiSmoothingSetting public double Velocity; public double Shape; public double Compensation; + public AntiSmoothingSetting() { Enabled = false; @@ -70,10 +73,12 @@ public AntiSmoothingSetting() Shape = 0.5; Compensation = 0; } - }; + } + [XmlArray("AntiSmoothingSettingsList")] [XmlArrayItem("AntiSmoothingSettings")] public AntiSmoothingSetting[] AntiSmoothingSettings; + public bool AntiSmoothingOnlyWhenHover; public double AntiSmoothingDragMultiplier; @@ -83,11 +88,13 @@ public AntiSmoothingSetting() [XmlArray("ButtonMap")] [XmlArrayItem("Button")] public string[] ButtonMap; + public bool DisableButtons; [XmlArray("TabletButtonMap")] [XmlArrayItem("Button")] public string[] TabletButtonMap; + public bool DisableTabletButtons; public double PressureSensitivity; @@ -123,6 +130,7 @@ public class TabletViewSettings public Point OffsetPressure; public bool FadeInOut; public bool Borderless; + public TabletViewSettings() { BackgroundColor = "#FFFFFF"; @@ -141,7 +149,8 @@ public TabletViewSettings() FadeInOut = false; Borderless = false; } - }; + } + public TabletViewSettings TabletView; public bool AutomaticRestart; @@ -157,17 +166,15 @@ public class Preset { public string Name; public Action Action; + public Preset(string name, Action action) { Name = name; Action = action; } - public override string ToString() - { - return Name; - } - } + public override string ToString() => Name; + } public Configuration() { @@ -176,6 +183,7 @@ public Configuration() // Screen Map ScreenArea = null; ScreenAreas = new Area[3]; + for (int i = 0; i < ScreenAreas.Length; i++) { ScreenAreas[i] = new Area(0, 0, 0, 0) @@ -183,14 +191,17 @@ public Configuration() IsEnabled = false }; } + ScreenAreas[0].IsEnabled = true; ScreenAreas[1] = new Area(1000, 500, 500, 250); // Tablet area TabletArea = null; TabletAreas = new Area[ScreenAreas.Length]; + for (int i = 0; i < GetAreaCount(); i++) TabletAreas[i] = new Area(100, 56, 50, 28); + TabletFullArea = new Area(100, 50, 50, 25); Mode = OutputModes.Standard; ForceAspectRatio = true; @@ -203,7 +214,9 @@ public Configuration() DisableButtons = false; TabletButtonMap = new string[16]; + for (int i = 0; i < 16; i++) TabletButtonMap[i] = ""; + DisableTabletButtons = false; PressureSensitivity = 0; @@ -222,12 +235,14 @@ public Configuration() AntiSmoothingEnabled = false; AntiSmoothingSettings = new AntiSmoothingSetting[5]; + for (int i = 0; i < AntiSmoothingSettings.Length; i++) AntiSmoothingSettings[i] = new AntiSmoothingSetting(); + AntiSmoothingDragMultiplier = 1.0; AntiSmoothingOnlyWhenHover = false; - CustomCommands = new string[] { "" }; + CustomCommands = new string[0]; WindowWidth = 700; WindowHeight = 700; @@ -252,6 +267,7 @@ public int GetAreaCount() { if (ScreenAreas.Length <= TabletAreas.Length) return ScreenAreas.Length; + return TabletAreas.Length; } @@ -259,10 +275,7 @@ public int GetAreaCount() // // Get maximum number of areas // - public int GetMaxAreaCount() - { - return 5; - } + public int GetMaxAreaCount() => 5; // @@ -311,21 +324,15 @@ public void SetAntiSmoothingSetting(int index, bool enabled, double velocity, do // public void Write(string filename) { - var fileWriter = new StreamWriter(filename); + var serializer = new XmlSerializer(typeof(Configuration)); + var xmlWriterSettings = new XmlWriterSettings { Indent = true }; - XmlSerializer serializer = new XmlSerializer(typeof(Configuration)); - XmlWriterSettings xmlWriterSettings = new XmlWriterSettings() { Indent = true }; - XmlWriter writer = XmlWriter.Create(fileWriter, xmlWriterSettings); - try - { - serializer.Serialize(writer, this); - } - catch (Exception) + using (var file = new StreamWriter(filename)) { - fileWriter.Close(); - throw; + var writer = XmlWriter.Create(file, xmlWriterSettings); + + serializer.Serialize(file, this); } - fileWriter.Close(); } // @@ -333,25 +340,26 @@ public void Write(string filename) // public static Configuration CreateFromFile(string filename) { - Configuration config = null; + if (!File.Exists(filename)) + throw new FileNotFoundException("Could not find configuration file", filename); + var serializer = new XmlSerializer(typeof(Configuration)); - var settings = new XmlWriterSettings() { Indent = true }; - var reader = XmlReader.Create(filename); - try + using (var file = File.OpenRead(filename)) { - config = (Configuration)serializer.Deserialize(reader); + return (Configuration)serializer.Deserialize(file); } - catch (Exception) - { - reader.Close(); - throw; - } - reader.Close(); - return config; } - } + public static string GetSelectedConfig() + { + if (!File.Exists("config/.current")) + return "config/configs/default.xml"; + return File.ReadAllText("config/.current").Trim('\r', '\n', '\t', ' '); + } + public static void SetSelectedConfig(string path) + => File.WriteAllText("config/.current", path); + } } diff --git a/TabletDriverGUI/MainWindow.Settings.cs b/TabletDriverGUI/MainWindow.Settings.cs index 5ad54af..d675497 100644 --- a/TabletDriverGUI/MainWindow.Settings.cs +++ b/TabletDriverGUI/MainWindow.Settings.cs @@ -24,7 +24,6 @@ public partial class MainWindow : Window WindowTabletView tabletView; - // // Create setting UI components // @@ -118,12 +117,6 @@ private void CreateSettingElements() } }; - - - - - - // // Anti-smoothing presets // @@ -786,14 +779,17 @@ private void UpdateSettingsToConfiguration() if (config.RunAtStartup != oldValue) SetRunAtStartup(config.RunAtStartup); - // // Custom commands // - List commandList = new List(); + var commandList = new List(); + foreach (string command in textCustomCommands.Text.Split('\n')) + { if (command.Trim().Length > 0) commandList.Add(command.Trim()); + } + config.CustomCommands = commandList.ToArray(); @@ -805,10 +801,8 @@ private void UpdateSettingsToConfiguration() // Update canvases UpdateCanvasElements(); - } - // // Initialize configuration // @@ -1469,5 +1463,63 @@ private void TabControl_SelectionChanged(object sender, SelectionChangedEventArg } } + + + private string[] configFiles; + + private string[] GetAvailableConfigs() + => Directory.GetFiles("config/configs/", "*.xml"); + + private void UpdateConfigList() + { + configComboBox.Items.Clear(); + + configComboBox.Items.Add("New Config"); + + foreach (var file in (configFiles = GetAvailableConfigs())) + { + configComboBox.Items.Add(Path.GetFileNameWithoutExtension(file)); + } + + configComboBox.Text = Path.GetFileNameWithoutExtension(configFilename); + } + + private void ConfigComboBox_MouseDown(object sender, MouseButtonEventArgs e) + => UpdateConfigList(); + + private void ConfigComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (e.AddedItems.Count == 0 || configFilename.Length == 0 || isLoadingSettings) return; + + var idx = configComboBox.SelectedIndex; + + if (idx == 0) // new config + { + var dialog = new SaveFileDialog + { + InitialDirectory = Directory.GetCurrentDirectory(), + AddExtension = true, + DefaultExt = "xml", + Filter = "XML File|*.xml", + Title = "New Config" + }; + + if (dialog.ShowDialog() != true) + return; + + config.Write(configFilename = dialog.FileName); + + UpdateConfigList(); + } + else + { + Configuration.SetSelectedConfig(configFiles[idx-1]); + + LoadConfig(); + + InitializeConfiguration(); + LoadSettingsFromConfiguration(); + } + } } } diff --git a/TabletDriverGUI/MainWindow.xaml b/TabletDriverGUI/MainWindow.xaml index f20350b..f1c5db3 100644 --- a/TabletDriverGUI/MainWindow.xaml +++ b/TabletDriverGUI/MainWindow.xaml @@ -6,1478 +6,1388 @@ mc:Ignorable="d" Keyboard.PreviewKeyDown="Window_PreviewKeyDown" Title="TabletDriverGUI" Height="750" Width="770"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - Screen Map - - - - You can drag the screen area with a mouse. - - - Control + Drag = Move area in X direction. - - - Shift + Drag = Move area Y direction. - - - Alt + Drag = Move area 80 pixels at a time. - - - Mouse scroll = Resize area 10 pixels per scroll. - - - Control + Mouse scroll = Resize area 100 pixels per scroll. - - - Use the "Move Area To" to set move screen area to single monitor or full desktop. - - - Right-clicking the area will show more options - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Tablet Area - - - - You can drag the tablet area with a mouse. - - - Control + Drag = Move area in X direction. - - - Shift + Drag = Move area Y direction. - - - Alt + Drag = Move area 5 mm at a time. - - - Mouse scroll = Resize area 1 mm per scroll. - - - Control + Mouse scroll = Resize area 10 mm per scroll. - - - For left handed mode, enable the "Left handed (Inverted)" checkbox or use a rotation value of 180 degrees. - - - Click Wacom Area button to type in the Wacom driver area settings. - - - Draw Area will allow you to set the tablet area by clicking two points with a pen. - - - Right-clicking the area will show more options. - - - - - - - - - - - - - - - - - - - - - - - Left handed - - (Invert) - - + + + + + + + - - + + + + + + + + + + + + + Screen Map + + + - You can drag the screen area with a mouse. + + - Control + Drag = Move area in X direction. + + - Shift + Drag = Move area Y direction. + + - Alt + Drag = Move area 80 pixels at a time. + + - Mouse scroll = Resize area 10 pixels per scroll. + + - Control + Mouse scroll = Resize area 100 pixels per scroll. + + - Use the "Move Area To" to set move screen area to single monitor or full desktop. + + - Right-clicking the area will show more options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Tablet Area + + + - You can drag the tablet area with a mouse. + + - Control + Drag = Move area in X direction. + + - Shift + Drag = Move area Y direction. + + - Alt + Drag = Move area 5 mm at a time. + + - Mouse scroll = Resize area 1 mm per scroll. + + - Control + Mouse scroll = Resize area 10 mm per scroll. + + - For left handed mode, enable the "Left handed (Inverted)" checkbox or use a rotation value of 180 degrees. + + - Click Wacom Area button to type in the Wacom driver area settings. + + - Draw Area will allow you to set the tablet area by clicking two points with a pen. + + - Right-clicking the area will show more options. + + + + + + + + + + + + + + + + + + + Left handed + + (Invert) + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Absolute (Pen) + Relative (Mouse) + + + + + + + + Mode + + Standard: Gaming and other programs that don't need pen pressure. + + Windows Ink: Enables pen pressure for applications that support Windows Ink. + + Compatibility: Use this mode if you have problems with cursor movement in standard mode. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Force aspect ratio + + + + + + + + + + + + + + + + + + - 0 - + + + + + + + + + + + + + + + + Pen Buttons + + + - You can disable a single button by clicking "Clear" in the mapping dialog. + + - The "Disable buttons" checkbox will disable all pen buttons. + + - Use negative number in scroll sensitivity to invert the direction. + + - Scroll acceleration 1.0 = No acceleration. + + + + + + + + + + + + + + + + + + + + + + + + Disable buttons + + + + + + + + + + Mouse Scroll + + + - Use negative number in sensitivity to invert the direction. + + - Acceleration 1.0 = No acceleration. Recommended range is from 1 to 5. + + - Stop cursor: cursor will be stopped when scrolling. + + - Drag scroll: scrolls only when the pen tip is pressed down. + + + + + + + + + 0.5 + + + + + + + + 1.0 + + + + + + Stop cursor + + + + + Drag scroll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Absolute (Pen) - Relative (Mouse) - + + + + + + + + + + + + + + + Smoothing Filter + + + Smoothing filter adds latency to the input, so don't enable it if you want to have the lowest possible input latency. + + Check the checkbox to enable the filter. + + "Only when buttons down" enables the filter only when pen buttons or tip are pressed down. + + + + Recommendations + + + On Wacom tablets you can use latency value between 10 and 15 to have a similar smoothing as in the Wacom drivers. + + You can test out different filter values, but recommended maximum for osu! is around 50 milliseconds. + + Filter latency value lower than 4 milliseconds isn't recommended. It is just better to disable the smoothing filter. + + You don't have to change the filter rate, but you can use the highest rate your computer can run without performance problems. + + + + + + + + + + + + + + 0 + + + + + + + + 1000 Hz + 500 Hz + 333 Hz + 250 Hz + 125 Hz + + + + + + + Only when buttons down + + + + - - - - - Mode - - Standard: Gaming and other programs that don't need pen pressure. - - Windows Ink: Enables pen pressure for applications that support Windows Ink. - - Compatibility: Use this mode if you have problems with cursor movement in standard mode. - - - - - - - - + + + + + + + Noise Reduction Filter + + + It is recommend to use this filter only with older Wacom tablets. + + + WARNING! This filter will cause more latency on smaller tablet areas (<20 mm), so consider using a larger area to increase the performance. + + + Check the checkbox to enable the filter. + + + + Buffer + + + Buffer value means how many latest pen positions will be stored in buffer. + + Lower buffer value means lower latency, but lower noise reduction. + + At 133 RPS report rate the buffer size of 10 means maximum latency of 75 milliseconds. + + + + Threshold + + + Threshold value sets the movement distance threshold per pen position report. + + The amount of noise reduction will be at the maximum if the pen movement is shorter than the threshold value. + + Noise reduction and latency will be almost zero if the pen position movement is double the distance of the threshold value. + + At 133 RPS report rate a 0.5 mm threshold value means speeds of ~66.5 mm/s and the noise reduction and latency will be almost zero at ~133 mm/s. + + + + Recommendations + + + Recommended values: Samples = 5 - 20, Threshold = 0.2 - 1.0 mm. + + You can use "Benchmark" command in the console to test out your tablet's noise performance. + + Tablet benchmark will give you a recommended threshold value, but you can use larger value if you hover. + + + + + + + + + + + + + + 10 + + + + + + 1.0 + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Force aspect ratio - - - - + + + + + + Anti-smoothing Filter + + + It is recommend to use this filter only with tablets that do the pen position smoothing in hardware/firmware. + + + WARNING! Some tablets will send broken position data when the pen buttons are pressed, so don't press buttons... + + + + WARNING! Do not use this filter with small tablet areas (<20 mm). Most tablets will send invalid data at low speeds. + + + Check the checkbox to enable the filter. + + + Shape + + Shape value is the how the filter handles pen acceleration. Start with a neutral 0.5 shape value and try to keep it around that. + + Use a lower value when there are are too much artifacts in sharp corners and increase the value if corners are too smooth. + + + Compensation + + Compensation value is the amount of latency compensation. + + You can test out the compensation value by spinning the pen in circles with different speeds. + + Circle size shouldn't change too much with different spinning speeds. + + Use lower compensation value if there are too much artifacting at high speeds. + + Try to find a balance between response time and artifacting. + + + Only when hovering + + This feature is mainly meant for Wacom CTL-490, but might be useful with other tablets too. + + + Recommended value ranges + + Shape: 0.1 - 2.0 + + Compensation: 10 - 30 ms + + + + + + + + + + Enabled + + + + + + + Only when hovering + + + + + + + + 1.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Pen Buttons + + + + + - - - You can disable a single button by clicking "Clear" in the mapping dialog. - - - The "Disable buttons" checkbox will disable all pen buttons. - - - Use negative number in scroll sensitivity to invert the direction. - - - Scroll acceleration 1.0 = No acceleration. - - - - - - - - - - - - - - - - - - - - - - - - - - Disable buttons - - + + + + + + + + + Desktop Size + + + - In some cases you may have to disable the auto size and manually type in the main monitor resolution. + + - If you don't have problems with screen mapping, leave the automatic desktop size enabled. + + + + + + + + 1920 + + + + + + + + 1080 + + + + + Auto + + - + - - - - - - - Mouse Scroll - - - - Use negative number in sensitivity to invert the direction. - - - Acceleration 1.0 = No acceleration. Recommended range is from 1 to 5. - - - Stop cursor: cursor will be stopped when scrolling. - - - Drag scroll: scrolls only when the pen tip is pressed down. + + + + + - - - - - - - - 0.5 - - - - - - - - 1.0 - - - - - - Stop cursor - - - - - Drag scroll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + Custom commands + + + + These commands/settings are applied to the driver after the GUI settings. + + You can autocomplete a command by pressing control+space. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Anti-smoothing Filter - - - It is recommend to use this filter only with tablets that do the pen position smoothing in hardware/firmware. - - - WARNING! Some tablets will send broken position data when the pen buttons are pressed, so don't press buttons... - - - - WARNING! Do not use this filter with small tablet areas (<20 mm). Most tablets will send invalid data at low speeds. - - - Check the checkbox to enable the filter. - - - Shape - - Shape value is the how the filter handles pen acceleration. Start with a neutral 0.5 shape value and try to keep it around that. - - Use a lower value when there are are too much artifacts in sharp corners and increase the value if corners are too smooth. - - - Compensation - - Compensation value is the amount of latency compensation. - - You can test out the compensation value by spinning the pen in circles with different speeds. - - Circle size shouldn't change too much with different spinning speeds. - - Use lower compensation value if there are too much artifacting at high speeds. - - Try to find a balance between response time and artifacting. - - - Only when hovering - - This feature is mainly meant for Wacom CTL-490, but might be useful with other tablets too. - - - Recommended value ranges - - Shape: 0.1 - 2.0 - - Compensation: 10 - 30 ms - - - - - - - - - - - - Enabled + + + + + + + + Auto Restart - - - - - Only when hovering - + + + Run at Windows startup - - - - - - - - 1.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Desktop Size - - - - In some cases you may have to disable the auto size and manually type in the main monitor resolution. - - - If you don't have problems with screen mapping, leave the automatic desktop size enabled. - - - - - - - - - 1920 - - - - - - - - 1080 - - - - - Auto - - - - - - - - - - - - - - - - - - - Custom commands - - - - These commands/settings are applied to the driver after the GUI settings. - - You can autocomplete a command by pressing control+space. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debug - - - - - - - - - - - - - - - - - - - - - - - - Auto Restart - - - - - Run at Windows startup - - - - + + - - + + + + - - - - - - - - - - 0.0.0 - - - - - + + + + + 0.0.0 + + + + diff --git a/TabletDriverGUI/MainWindow.xaml.cs b/TabletDriverGUI/MainWindow.xaml.cs index 4328492..4a0facf 100644 --- a/TabletDriverGUI/MainWindow.xaml.cs +++ b/TabletDriverGUI/MainWindow.xaml.cs @@ -194,24 +194,35 @@ private void MainWindow_Closing(object sender, System.ComponentModel.CancelEvent StopDriver(); } - // Window loaded -> Start driver - private void MainWindow_Loaded(object sender, RoutedEventArgs e) + private void LoadConfig() { - // Configuration filename - configFilename = "config/config.xml"; + configFilename = Configuration.GetSelectedConfig(); // Load configuration try { config = Configuration.CreateFromFile(configFilename); } - catch (Exception) + catch (FileNotFoundException) { driver.ConsoleAddLine("New config created!"); isFirstStart = true; config = new Configuration(); } + } + + // Window loaded -> Start driver + private void MainWindow_Loaded(object sender, RoutedEventArgs e) + { + // Ensure config directories exist + Directory.CreateDirectory("config/configs"); + + // Load config + LoadConfig(); + + // Update available configs + UpdateConfigList(); // Create setting elements CreateSettingElements(); @@ -222,12 +233,8 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) // Initialize configuration InitializeConfiguration(); - // Hide the window if the GUI is started as minimized - if (WindowState == WindowState.Minimized) - { - Hide(); - } + if (WindowState == WindowState.Minimized) Hide(); // // Allow input field events @@ -236,16 +243,13 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) // Start the driver StartDriver(); - } - // // Window key down // private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { - // Control + S -> Save settings if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.S) { @@ -321,10 +325,8 @@ private void Window_PreviewKeyDown(object sender, KeyEventArgs e) e.Handled = true; } } - } - // // Process command line arguments // @@ -351,8 +353,6 @@ void ProcessCommandLineArguments() #endregion - - #region Notify icon stuff // @@ -416,8 +416,6 @@ void NotifyExit(object sender, EventArgs e) #endregion - - #region Statusbar // @@ -475,9 +473,6 @@ private void TimerStatusbar_Tick(object sender, EventArgs e) #endregion - - - #region WndProc // @@ -515,7 +510,6 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b #endregion - private void MouseTest(object sender, MouseButtonEventArgs e) { SetStatus("Event: " + e.RoutedEvent.ToString() + ", Mouse at " + ((UIElement)sender).ToString() + "! " + e.ChangedButton.ToString() + " " + e.ButtonState.ToString()); diff --git a/TabletDriverGUI/NativeMethods.cs b/TabletDriverGUI/NativeMethods.cs index 5a0ce3b..c6c3c2d 100644 --- a/TabletDriverGUI/NativeMethods.cs +++ b/TabletDriverGUI/NativeMethods.cs @@ -48,14 +48,24 @@ public int Width public const int HWND_BROADCAST = 0xffff; public static readonly int WM_SHOWTABLETDRIVERGUI = RegisterWindowMessage("WM_SHOWTABLETDRIVERGUI"); +#pragma warning disable CA1401 // Disable visibility warnings + [DllImport("user32")] public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); - [DllImport("user32")] + + [DllImport("user32", CharSet = CharSet.Unicode)] public static extern int RegisterWindowMessage(string message); [DllImport("user32.dll", SetLastError = true)] public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect); + // + // GDI + // + [DllImport("gdi32.dll")] + public static extern bool DeleteObject(IntPtr hObject); + +#pragma warning restore CA1401 // Restore visibility warnings // // Multimedia timer @@ -67,11 +77,5 @@ public int Width [DllImport("winmm.dll", SetLastError = true, EntryPoint = "timeKillEvent")] internal static extern void TimeKillEvent(UInt32 uTimerId); - - // - // GDI - // - [DllImport("gdi32.dll")] - public static extern bool DeleteObject(IntPtr hObject); } } diff --git a/TabletDriverGUI/WindowAreaEditor.xaml b/TabletDriverGUI/WindowAreaEditor.xaml index f63366b..ada28d0 100644 --- a/TabletDriverGUI/WindowAreaEditor.xaml +++ b/TabletDriverGUI/WindowAreaEditor.xaml @@ -6,115 +6,112 @@ xmlns:local="clr-namespace:TabletDriverGUI" mc:Ignorable="d" Title="Area Editor" Height="270" Width="500"> - - + + - - - - - + + + + + + + + + + + + 123 + + + - - - + + + + 123 + + + - - - - 123 - - - - - - - - 123 - - - + + + + 123 + + + - - - - 123 - - - + + + + 123 + + + + + - - - - 123 - - - - - + + + + + + 123 + + + - - + + + + 123 + + + - - - - 123 - - - - - - - - 123 - - - - - - - - 123 - - - + + + + 123 + + + - - - - 123 - + + + + 123 + + + + + + + + - - - - - - - - + diff --git a/TabletDriverGUI/WindowButtonMapping.xaml b/TabletDriverGUI/WindowButtonMapping.xaml index e99202c..bd25003 100644 --- a/TabletDriverGUI/WindowButtonMapping.xaml +++ b/TabletDriverGUI/WindowButtonMapping.xaml @@ -7,64 +7,70 @@ mc:Ignorable="d" Title="Button Mapping" Height="350" Width="350" SizeToContent="WidthAndHeight"> - - - - - - - None - - - - CTRL+SHIFT+Z - + + + + + + + None + + + + + CTRL+SHIFT+Z + + - - - None - - + + + None + + - - CTRL+SHIFT+Z - - - - - - - + + + CTRL+SHIFT+Z + + + + + + + + diff --git a/TabletDriverGUI/WindowMessageBox.xaml b/TabletDriverGUI/WindowMessageBox.xaml index f208c05..55cb885 100644 --- a/TabletDriverGUI/WindowMessageBox.xaml +++ b/TabletDriverGUI/WindowMessageBox.xaml @@ -10,30 +10,31 @@ Width="300" MinWidth="300" SizeToContent="WidthAndHeight"> - - - - - - - - - + + + + + + + + + diff --git a/TabletDriverGUI/WindowTabletView.xaml b/TabletDriverGUI/WindowTabletView.xaml index 10dd1bb..207601b 100644 --- a/TabletDriverGUI/WindowTabletView.xaml +++ b/TabletDriverGUI/WindowTabletView.xaml @@ -11,7 +11,7 @@ SizeToContent="WidthAndHeight" ResizeMode="NoResize"> - - - - Test Tablet - 100x55mm - 1920x1080 - + + + Test Tablet - 100x55mm - 1920x1080 + - - - Input - + + + Input + - - - Output - + + + Output + - - - ±100ms - - + + + ±100ms + + diff --git a/TabletDriverGUI/WindowTabletViewSettings.xaml b/TabletDriverGUI/WindowTabletViewSettings.xaml index 1858696..bb64697 100644 --- a/TabletDriverGUI/WindowTabletViewSettings.xaml +++ b/TabletDriverGUI/WindowTabletViewSettings.xaml @@ -7,137 +7,132 @@ Title="Tablet View Settings" Height="900" Width="300" SizeToContent="Height" - ResizeMode="NoResize" - > - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - #FFFFFF - - - #ffffff - - - #ffffff - - - #ffffff - - - - #ffffff - - - - #ffffff - - - - 30 - - - - 30 - - - - 30 - - - - Arial - - - - 25 - - - - - - - - - 0 - 0 - - - - - - - - - - 0 - 0 - - - - Fade in/out when input is detected/lost - Borderless window - - - - - - - + + + + + + + + + + + + + + + + + + + + + #FFFFFF + + + #ffffff + + + #ffffff + + + #ffffff + + + + #ffffff + + + + #ffffff + + + + 30 + + + + 30 + + + + 30 + + + + Arial + + + + 25 + + + + + + + + + 0 + 0 + + + + + + + + + + 0 + 0 + + + + Fade in/out when input is detected/lost + Borderless window + + + + + + diff --git a/TabletDriverGUI/WindowWacomArea.xaml b/TabletDriverGUI/WindowWacomArea.xaml index 67ddd25..9a640b7 100644 --- a/TabletDriverGUI/WindowWacomArea.xaml +++ b/TabletDriverGUI/WindowWacomArea.xaml @@ -8,53 +8,46 @@ Title="Wacom Intuos/Bamboo area" Height="350" Width="350" MinWidth="350" SizeToContent="WidthAndHeight"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + From 1f2ecaf6bfe0b422bf6a16d48942f8320804b74b Mon Sep 17 00:00:00 2001 From: yuwui Date: Wed, 5 Feb 2020 21:49:51 +0100 Subject: [PATCH 3/3] Save config on reset --- TabletDriverGUI/MainWindow.Settings.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/TabletDriverGUI/MainWindow.Settings.cs b/TabletDriverGUI/MainWindow.Settings.cs index 66126ba..d46e376 100644 --- a/TabletDriverGUI/MainWindow.Settings.cs +++ b/TabletDriverGUI/MainWindow.Settings.cs @@ -1269,17 +1269,18 @@ private void MainMenuClick(object sender, RoutedEventArgs e) // else if (sender == mainMenuResetToDefault) { - WindowMessageBox messageBox = new WindowMessageBox( + var msgBox = new WindowMessageBox( "Are you sure?", "Reset to default settings?", "Yes", "No"); - messageBox.ShowDialog(); - if (messageBox.DialogResult == true) - { - config = null; + if (msgBox.ShowDialog() == true) + { isFirstStart = true; config = new Configuration(); + // Save config + config.Write(configFilename); + // Initialize configuration InitializeConfiguration();