Skip to content

Commit

Permalink
Fixed GuideGrid XAML **again**
Browse files Browse the repository at this point in the history
WPF bindings are completely stupid as a concept
Fixed overlay topmost-ness in debug mode
Made Escape cancel the hotkey rebinding process
  • Loading branch information
SamusAranX committed Aug 21, 2023
1 parent 2a00680 commit 66308a1
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 44 deletions.
12 changes: 5 additions & 7 deletions Controls/GuideGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" x:Name="GuideGridControl"
d:DesignWidth="320" d:DesignHeight="240"
DataContext="{Binding ElementName=GuideGridControl}">

d:DesignWidth="320" d:DesignHeight="240">
<UserControl.Resources>
<Grid x:Key="NoneGrid">
<Grid x:Key="NoneGrid" DataContext="{Binding ElementName=GuideGridControl}">
<!-- Outer border -->
<Border BorderThickness="1" BorderBrush="{Binding GridLineBrush}" />
</Grid>

<Grid x:Key="RuleOfThirdsGrid">
<Grid x:Key="RuleOfThirdsGrid" DataContext="{Binding ElementName=GuideGridControl}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="1" />
Expand Down Expand Up @@ -57,7 +55,7 @@
BorderBrush="{Binding GridLineBrush}" />
</Grid>

<Grid x:Key="GoldenRuleGrid">
<Grid x:Key="GoldenRuleGrid" DataContext="{Binding ElementName=GuideGridControl}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1" />
Expand Down Expand Up @@ -102,7 +100,7 @@
</Grid>
</UserControl.Resources>

<Grid>
<Grid DataContext="{Binding ElementName=GuideGridControl}">
<ContentControl Opacity="{Binding GridOpacity}">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
Expand Down
2 changes: 1 addition & 1 deletion DeadEye.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<Copyright>Copyright © 2021–2023 Emma Alyx Wunder</Copyright>
<PackageReadmeFile>README.md</PackageReadmeFile>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyVersion>0.7.5.0</AssemblyVersion>
<AssemblyVersion>0.7.5.2</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Title>DeadEye</Title>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
Expand Down
1 change: 1 addition & 0 deletions ShortcutKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public sealed class ShortcutKey

public static readonly Key[] IgnoredKeys =
{
// do not put Key.Escape in here
Key.System,
Key.LeftCtrl, Key.RightCtrl,
Key.LeftShift, Key.RightShift,
Expand Down
3 changes: 1 addition & 2 deletions Windows/ColorPickerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
xmlns:windows="clr-namespace:DeadEye.Windows"
mc:Ignorable="d" WindowStyle="None" Background="Magenta" ResizeMode="NoResize"
Title="DeadEye Color Picker Window" Height="240" Width="320"
UseLayoutRounding="True" Cursor="None"
UseLayoutRounding="True" Cursor="None" Topmost="True"
TextOptions.TextHintingMode="Fixed" TextOptions.TextFormattingMode="Display"
RenderOptions.BitmapScalingMode="NearestNeighbor"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
SourceInitialized="ColorPickerWindow_OnSourceInitialized"
Activated="ColorPickerWindow_OnActivated"
Deactivated="ColorPickerWindow_OnDeactivated"
KeyDown="ColorPickerWindow_OnKeyDown"
Expand Down
5 changes: 0 additions & 5 deletions Windows/ColorPickerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ private void OnColorPicked(ColorPickEventArgs e)
this.ColorPicked?.Invoke(this, e);
}

private void ColorPickerWindow_OnSourceInitialized(object sender, EventArgs e)
{
this.Topmost = !DebugHelper.IsDebugMode;
}

private void ColorPickerWindow_OnActivated(object? sender, EventArgs e)
{
Debug.WriteLine("got focus");
Expand Down
6 changes: 3 additions & 3 deletions Windows/ScreenshotFrameWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
xmlns:windows="clr-namespace:DeadEye.Windows"
mc:Ignorable="d" WindowStyle="None" Background="Magenta" ResizeMode="NoResize"
Title="DeadEye Screenshot Window" Height="240" Width="320"
UseLayoutRounding="True" Cursor="Cross"
UseLayoutRounding="True" Cursor="Cross" Topmost="True"
TextOptions.TextHintingMode="Fixed" TextOptions.TextFormattingMode="Display"
RenderOptions.BitmapScalingMode="NearestNeighbor"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
SourceInitialized="ScreenshotFrameWindow_OnSourceInitialized"
Deactivated="ScreenshotFrameWindow_OnDeactivated"
KeyDown="ScreenshotFrameWindow_OnKeyDown" KeyUp="ScreenshotFrameWindow_OnKeyUp"
MouseLeftButtonDown="ScreenshotFrameWindow_OnMouseLeftButtonDown"
Expand All @@ -28,7 +27,8 @@
DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}}" />

<Canvas x:Name="GridCanvas" Background="Transparent">
<ctrl:GuideGrid GridOpacity="0.6"
<ctrl:GuideGrid x:Name="GuideGrid"
GridOpacity="0.6"
GridType="{Binding Source={x:Static local:Settings.Shared}, Path=GridType}"
MarkCenter="{Binding Source={x:Static local:Settings.Shared}, Path=MarkCenter}"
Canvas.Left="{Binding SelectionBoundsClamped.Left}"
Expand Down
5 changes: 0 additions & 5 deletions Windows/ScreenshotFrameWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ private void OnScreenshot(ScreenshotEventArgs e)
this.ScreenshotTaken?.Invoke(this, e);
}

private void ScreenshotFrameWindow_OnSourceInitialized(object sender, EventArgs e)
{
this.Topmost = !DebugHelper.IsDebugMode;
}

private void ScreenshotFrameWindow_OnDeactivated(object sender, EventArgs e)
{
Debug.WriteLine("lost focus");
Expand Down
2 changes: 1 addition & 1 deletion Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
TextOptions.TextHintingMode="Fixed" TextOptions.TextFormattingMode="Display"
Title="Settings" Width="340" Height="500" SizeToContent="Height" ResizeMode="NoResize"
Background="{x:Static SystemColors.MenuBrush}"
PreviewKeyDown="SettingsWindow_OnPreviewKeyDown">
PreviewKeyDown="SettingsWindow_OnPreviewKeyDown" Deactivated="SettingsWindow_OnDeactivated">
<Window.Resources>
<DrawingImage x:Key="CrossCursor">
<DrawingImage.Drawing>
Expand Down
58 changes: 38 additions & 20 deletions Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,25 @@ private static void EnsureHotkeyStatus()
Debug.WriteLine($"Color Picker Hotkey active: {HotkeyManager.Shared.IsColorPickerHotkeyRegistered}");
}

private static void CancelRebinding()
{
Settings.Shared.WaitingForHotkey = null;
EnsureHotkeyStatus();
}

private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.Source is not TabControl || !Settings.Shared.WaitingForHotkey.HasValue)
return;

// cancel hotkey process when switching tabs
Settings.Shared.WaitingForHotkey = null;
EnsureHotkeyStatus();
// cancel hotkey rebinding when switching tabs
CancelRebinding();
}

private void SettingsWindow_OnDeactivated(object? sender, EventArgs e)
{
// cancel hotkey rebinding when window loses focus
CancelRebinding();
}

private void SettingsWindow_OnPreviewKeyDown(object sender, KeyEventArgs e)
Expand All @@ -111,24 +122,31 @@ private void SettingsWindow_OnPreviewKeyDown(object sender, KeyEventArgs e)

Debug.WriteLine($"key: {key}");

// if key is not null here, we may have found our new hotkey
if (key.HasValue && key != Key.Escape)
switch (key)
{
// we actually have a new hotkey
var newHotkey = new ShortcutKey(modifiers, key.Value);
switch (Settings.Shared.WaitingForHotkey)
{
case HotkeyType.Screenshot:
Settings.Shared.ScreenshotKey = newHotkey;
break;
case HotkeyType.ColorPicker:
Settings.Shared.ColorPickerKey = newHotkey;
break;
}

Settings.Shared.WaitingForHotkey = null;
case null:
// no non-modifier key has been pressed yet
EnsureHotkeyStatus();
break;
case Key.Escape:
// escape was pressed, cancel rebinding
CancelRebinding();
break;
default:
// we actually have a new hotkey
var newHotkey = new ShortcutKey(modifiers, key.Value);
switch (Settings.Shared.WaitingForHotkey)
{
case HotkeyType.Screenshot:
Settings.Shared.ScreenshotKey = newHotkey;
break;
case HotkeyType.ColorPicker:
Settings.Shared.ColorPickerKey = newHotkey;
break;
}

Settings.Shared.WaitingForHotkey = null;
break;
}

EnsureHotkeyStatus();
}
}

0 comments on commit 66308a1

Please sign in to comment.