From 508d7e149287b1eecb9040fd1b6237b844011326 Mon Sep 17 00:00:00 2001 From: EVEJay Date: Fri, 14 Jun 2024 13:51:17 +0200 Subject: [PATCH] Added click trough toggle to the overlay. --- SMT/MainWindow.xaml | 1 + SMT/MainWindow.xaml.cs | 21 +++++++++++++++- SMT/Overlay.xaml | 2 +- SMT/Overlay.xaml.cs | 55 +++++++++++++++++++++++++++++++++++++++++- SMT/SMT.csproj | 3 +++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/SMT/MainWindow.xaml b/SMT/MainWindow.xaml index 86f1dcc..98e9954 100644 --- a/SMT/MainWindow.xaml +++ b/SMT/MainWindow.xaml @@ -66,6 +66,7 @@ + diff --git a/SMT/MainWindow.xaml.cs b/SMT/MainWindow.xaml.cs index 999a9d9..3d139b0 100644 --- a/SMT/MainWindow.xaml.cs +++ b/SMT/MainWindow.xaml.cs @@ -30,7 +30,12 @@ public partial class MainWindow : Window { public static MainWindow AppWindow; private LogonWindow logonBrowserWindow; - private List overlayWindows; + private List overlayWindows = new(); + private bool overlayWindowsAreClickTrough = false; + public bool OverlayWindowsAreClickTrough + { + get => overlayWindowsAreClickTrough; + } private MediaPlayer mediaPlayer; private PreferencesWindow preferencesWindow; @@ -2498,6 +2503,20 @@ private void OverlayWindow_MenuItem_Click(object sender, RoutedEventArgs e) overlayWindows.Add(newOverlayWindow); } + private void OverlayClickTroughToggle_MenuItem_Click(object sender, RoutedEventArgs e) + { + OverlayWindow_ToggleClickTrough(); + } + + public void OverlayWindow_ToggleClickTrough() + { + overlayWindowsAreClickTrough = !overlayWindowsAreClickTrough; + foreach (Overlay overlayWindow in overlayWindows) + { + overlayWindow.ToggleClickTrough(overlayWindowsAreClickTrough); + } + } + public void OnOverlayWindowClosing(object sender, CancelEventArgs e) { overlayWindows.Remove((Overlay)sender); diff --git a/SMT/Overlay.xaml b/SMT/Overlay.xaml index 510ed4a..8b9b735 100644 --- a/SMT/Overlay.xaml +++ b/SMT/Overlay.xaml @@ -26,7 +26,7 @@ - + diff --git a/SMT/Overlay.xaml.cs b/SMT/Overlay.xaml.cs index eaf8d42..2acec2d 100644 --- a/SMT/Overlay.xaml.cs +++ b/SMT/Overlay.xaml.cs @@ -1,4 +1,5 @@ -using System; +using NHotkey.Wpf; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -16,9 +17,34 @@ using System.Windows.Shapes; using Windows.Services; using Microsoft.IdentityModel.Tokens; +using NHotkey; using SMT.EVEData; using static SMT.EVEData.Navigation; +public static class WindowsServices +{ + const int WS_EX_TRANSPARENT = 0x00000020; + const int GWL_EXSTYLE = (-20); + + [DllImport("user32.dll")] + static extern int GetWindowLong(IntPtr hwnd, int index); + + [DllImport("user32.dll")] + static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle); + + public static void SetWindowExTransparent(IntPtr hwnd) + { + var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); + SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT); + } + + public static void SetWindowExNotTransparent(IntPtr hwnd) + { + var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); + SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle & ~WS_EX_TRANSPARENT); + } +} + namespace SMT { /// @@ -377,6 +403,9 @@ public Overlay(MainWindow mw) Closing += Overlay_Closing; // We can only redraw stuff when the canvas is actually resized, otherwise dimensions will be wrong! overlay_Canvas.SizeChanged += OnCanvasSizeChanged; + + // Set up hotkeys + HotkeyManager.Current.AddOrReplace("Toggle click trough overlay windows.", Key.T, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift, OnClickTroughToggle); // Update settings intelUrgentPeriod = mainWindow.MapConf.IntelFreshTime; @@ -403,11 +432,35 @@ public Overlay(MainWindow mw) // mw.EVEManager.IntelAddedEvent += OnIntelAdded; // Start the magic + ToggleClickTrough(mainWindow.OverlayWindowsAreClickTrough); RefreshCurrentView(); _ = CharacterLocationUpdateLoop(); _ = DataOverlayUpdateLoop(); } + private void OnClickTroughToggle(object sender, HotkeyEventArgs e) + { + mainWindow.OverlayWindow_ToggleClickTrough(); + } + + public void ToggleClickTrough(bool isClickTrough) + { + var hwnd = new WindowInteropHelper(this).Handle; + + if (isClickTrough) + { + WindowsServices.SetWindowExTransparent(hwnd); + overlay_ButtonRow.Height = new GridLength(0); + this.ResizeMode = ResizeMode.NoResize; + } + else + { + WindowsServices.SetWindowExNotTransparent(hwnd); + overlay_ButtonRow.Height = new GridLength(20); + this.ResizeMode = ResizeMode.CanResizeWithGrip; + } + } + protected override void OnSourceInitialized(EventArgs e) { base.OnInitialized(e); diff --git a/SMT/SMT.csproj b/SMT/SMT.csproj index 7a4f6c4..4901026 100644 --- a/SMT/SMT.csproj +++ b/SMT/SMT.csproj @@ -193,6 +193,9 @@ 7.1.3 + + 3.0.0 + 1.0.8