diff --git a/VisualTreeHelperExtensions.cs b/Extensions/VisualTreeHelperExtensions.cs similarity index 100% rename from VisualTreeHelperExtensions.cs rename to Extensions/VisualTreeHelperExtensions.cs diff --git a/DumpCreator.cs b/Logging/DumpCreator.cs similarity index 100% rename from DumpCreator.cs rename to Logging/DumpCreator.cs diff --git a/Logger.cs b/Logging/Logger.cs similarity index 100% rename from Logger.cs rename to Logging/Logger.cs diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 37a337e..18c0cb4 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Windows; +using WpfMaiTouchEmulator.Managers; namespace WpfMaiTouchEmulator; diff --git a/MaiTouchComConnector.cs b/Managers/MaiTouchComConnector.cs similarity index 98% rename from MaiTouchComConnector.cs rename to Managers/MaiTouchComConnector.cs index f3805fd..59fb599 100644 --- a/MaiTouchComConnector.cs +++ b/Managers/MaiTouchComConnector.cs @@ -1,7 +1,7 @@ using System.IO.Ports; using System.Windows; -namespace WpfMaiTouchEmulator; +namespace WpfMaiTouchEmulator.Managers; internal class MaiTouchComConnector(MaiTouchSensorButtonStateManager buttonState, MainWindowViewModel viewModel) { private static SerialPort? serialPort; @@ -187,7 +187,8 @@ internal class MaiTouchComConnector(MaiTouchSensorButtonStateManager buttonState { serialPort?.Write(currentState, 0, currentState.Length); } - catch (Exception ex) { + catch (Exception ex) + { if (Properties.Settings.Default.IsDebugEnabled) { Logger.Error("Error when writing to serial port on button update", ex); diff --git a/MaiTouchSensorButtonStateManager.cs b/Managers/MaiTouchSensorButtonStateManager.cs similarity index 94% rename from MaiTouchSensorButtonStateManager.cs rename to Managers/MaiTouchSensorButtonStateManager.cs index 60edf2a..d3f6eba 100644 --- a/MaiTouchSensorButtonStateManager.cs +++ b/Managers/MaiTouchSensorButtonStateManager.cs @@ -1,9 +1,9 @@ using System.Windows; using System.Windows.Controls; -namespace WpfMaiTouchEmulator; +namespace WpfMaiTouchEmulator.Managers; -public enum TouchValue: long +public enum TouchValue : long { A1 = 1 << 0, // 2^0 A2 = 1 << 1, // 2^1 @@ -77,12 +77,12 @@ internal class MaiTouchSensorButtonStateManager public void PressButton(TouchValue button) { - buttonState |= ((long)button); + buttonState |= (long)button; } public void ReleaseButton(TouchValue button) { - buttonState &= ~((long)button); + buttonState &= ~(long)button; } public byte[] GetCurrentState() diff --git a/RingButtonEmulator.cs b/Managers/RingButtonEmulator.cs similarity index 85% rename from RingButtonEmulator.cs rename to Managers/RingButtonEmulator.cs index ce00e48..bbe1700 100644 --- a/RingButtonEmulator.cs +++ b/Managers/RingButtonEmulator.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; -namespace WpfMaiTouchEmulator; +namespace WpfMaiTouchEmulator.Managers; public partial class RingButtonEmulator { [DllImport("user32.dll")] - static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); + static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, nuint dwExtraInfo); private static readonly IDictionary touchRingMapping = new Dictionary() { @@ -34,7 +34,7 @@ public partial class RingButtonEmulator { if (touchRingMapping.TryGetValue(touchValue, out var vk)) { - keybd_event(vk, 0, 0, UIntPtr.Zero); + keybd_event(vk, 0, 0, nuint.Zero); } } @@ -42,7 +42,7 @@ public partial class RingButtonEmulator { if (touchRingMapping.TryGetValue(touchValue, out var vk)) { - keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero); + keybd_event(vk, 0, KEYEVENTF_KEYUP, nuint.Zero); } } @@ -50,7 +50,7 @@ public partial class RingButtonEmulator { foreach (var vk in touchRingMapping.Values) { - keybd_event(vk, 0, KEYEVENTF_KEYUP, UIntPtr.Zero); + keybd_event(vk, 0, KEYEVENTF_KEYUP, nuint.Zero); } } } diff --git a/TouchPanelPositionManager.cs b/Managers/TouchPanelPositionManager.cs similarity index 83% rename from TouchPanelPositionManager.cs rename to Managers/TouchPanelPositionManager.cs index 8439743..5d2df10 100644 --- a/TouchPanelPositionManager.cs +++ b/Managers/TouchPanelPositionManager.cs @@ -1,16 +1,16 @@ using System.Runtime.InteropServices; using System.Windows; -namespace WpfMaiTouchEmulator; +namespace WpfMaiTouchEmulator.Managers; class TouchPanelPositionManager { [DllImport("user32.dll", SetLastError = true)] - static extern IntPtr FindWindow(string? lpClassName, string lpWindowName); + static extern nint FindWindow(string? lpClassName, string lpWindowName); [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); + static extern bool GetWindowRect(nint hWnd, out RECT lpRect); [StructLayout(LayoutKind.Sequential)] public struct RECT @@ -29,7 +29,7 @@ class TouchPanelPositionManager try { var hWnd = FindWindow(null, "Sinmai"); - if (hWnd != IntPtr.Zero) + if (hWnd != nint.Zero) { RECT rect; if (GetWindowRect(hWnd, out rect)) @@ -37,7 +37,7 @@ class TouchPanelPositionManager // Calculate the desired size and position based on the other application's window var renderRect = GetLargest916Rect(rect); var height = renderRect.Width; - var left = rect.Left + ((rect.Right - rect.Left) - renderRect.Width) / 2; // Center horizontally + var left = rect.Left + (rect.Right - rect.Left - renderRect.Width) / 2; // Center horizontally var top = rect.Bottom - height; return new Rect(left, top, renderRect.Width, height); } @@ -56,8 +56,8 @@ class TouchPanelPositionManager var originalWidth = original.Width; var originalHeight = original.Height; - var widthBasedHeight = (originalWidth * 16) / 9; - var heightBasedWidth = (originalHeight * 9) / 16; + var widthBasedHeight = originalWidth * 16 / 9; + var heightBasedWidth = originalHeight * 9 / 16; if (widthBasedHeight <= originalHeight) { diff --git a/VirtualComPortManager.cs b/Managers/VirtualComPortManager.cs similarity index 98% rename from VirtualComPortManager.cs rename to Managers/VirtualComPortManager.cs index a5fb8a4..2dae33b 100644 --- a/VirtualComPortManager.cs +++ b/Managers/VirtualComPortManager.cs @@ -2,7 +2,7 @@ using System.IO.Ports; using System.Windows; -namespace WpfMaiTouchEmulator; +namespace WpfMaiTouchEmulator.Managers; internal class VirtualComPortManager { @@ -21,7 +21,7 @@ internal class VirtualComPortManager public async Task CheckIfPortInstalled(string port, bool expectToExist) { var installed = false; - for (var i = 0; i< 3; i++) + for (var i = 0; i < 3; i++) { installed = GetInstalledPorts().Any(x => x == port); if (installed && expectToExist) diff --git a/TouchPanel.xaml b/TouchPanel.xaml index 71ecf2c..c28e882 100644 --- a/TouchPanel.xaml +++ b/TouchPanel.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:WpfMaiTouchEmulator" + xmlns:local="clr-namespace:WpfMaiTouchEmulator.Managers" mc:Ignorable="d" Title="TouchPanel" Height="800" Width="800" AllowsTransparency="True" WindowStyle="None" Background="Transparent" diff --git a/TouchPanel.xaml.cs b/TouchPanel.xaml.cs index e4fdcdd..09457db 100644 --- a/TouchPanel.xaml.cs +++ b/TouchPanel.xaml.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; +using WpfMaiTouchEmulator.Managers; namespace WpfMaiTouchEmulator; ///