Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added clicktrough toggle to the overlay. #163

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SMT/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<MenuItem Header="View" Height="Auto">
<MenuItem x:Name="miFullScreenToggle" Header="FullScreen" IsCheckable="True" IsChecked="False" Click="FullScreenToggle_MenuItem_Click" />
<MenuItem x:Name="miResetLayout" Header="Reset Layout" Click="miResetLayout_Click" />
<MenuItem x:Name="miToggleOverlayClickTrough" Header="Toggle Overlay ClickTrough (Shift + Ctrl + Alt + T)" Click="OverlayClickTroughToggle_MenuItem_Click"/>
</MenuItem>
</Menu>

Expand Down
21 changes: 20 additions & 1 deletion SMT/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public partial class MainWindow : Window
{
public static MainWindow AppWindow;
private LogonWindow logonBrowserWindow;
private List<Overlay> overlayWindows;
private List<Overlay> overlayWindows = new();
private bool overlayWindowsAreClickTrough = false;
public bool OverlayWindowsAreClickTrough
{
get => overlayWindowsAreClickTrough;
}

private MediaPlayer mediaPlayer;
private PreferencesWindow preferencesWindow;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion SMT/Overlay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ColumnDefinition Width="20px" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" Name="overlay_ButtonRow"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Background="Transparent" Name="overlay_CharNameTextblock" HorizontalAlignment="Center" TextAlignment="Center" FontSize="10" Opacity="0.5" Margin="1" Foreground="White" Text="No char selected" />
Expand Down
55 changes: 54 additions & 1 deletion SMT/Overlay.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NHotkey.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand All @@ -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
{
/// <summary>
Expand Down Expand Up @@ -244,7 +270,7 @@

private int overlayDepth = 8;
private Dictionary<LocalCharacter, OverlaySystemData> currentPlayersSystemData = new ();
private OverlaySystemData currentPlayerSystemData;

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 273 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used
private OverlayCanvasData canvasData = new OverlayCanvasData();

private float intelUrgentPeriod = 300;
Expand Down Expand Up @@ -377,6 +403,9 @@
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;
Expand All @@ -403,11 +432,35 @@
// 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);
Expand Down
3 changes: 3 additions & 0 deletions SMT/SMT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@
<Version>7.1.3</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NHotkey.Wpf">
<Version>3.0.0</Version>
</PackageReference>
<PackageReference Include="WPFThemes.DarkBlend">
<Version>1.0.8</Version>
</PackageReference>
Expand Down
Loading