1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-25 07:10:10 +00:00
msfs-popout-panel-manager/WpfApp/PanelCoorOverlay.xaml.cs

65 lines
2.3 KiB
C#
Raw Normal View History

2022-07-23 20:04:06 +00:00
using MSFSPopoutPanelManager.Shared;
using MSFSPopoutPanelManager.WindowsAgent;
using System;
2022-01-27 13:40:04 +00:00
using System.Windows;
2022-07-23 20:04:06 +00:00
using System.Windows.Interop;
2022-01-27 13:40:04 +00:00
namespace MSFSPopoutPanelManager.WpfApp
{
public partial class PanelCoorOverlay : Window
{
private const int TOP_ADJUSTMENT = 15; // half of window height
private const int LEFT_ADJUSTMENT = 15; // half of window width
2022-07-23 20:04:06 +00:00
private int _xCoor;
private int _yCoor;
2022-07-06 18:09:10 +00:00
2022-01-27 13:40:04 +00:00
public bool IsEditingPanelLocation { get; set; }
public IntPtr WindowHandle { get; set; }
2022-07-23 19:23:32 +00:00
public event EventHandler<System.Drawing.Point> WindowLocationChanged;
2022-07-06 18:09:10 +00:00
2022-01-27 13:40:04 +00:00
public PanelCoorOverlay(int panelIndex)
{
InitializeComponent();
this.lblPanelIndex.Content = panelIndex;
IsEditingPanelLocation = false;
2022-07-23 20:04:06 +00:00
this.Topmost = true;
2022-07-06 18:09:10 +00:00
this.LocationChanged += PanelCoorOverlay_LocationChanged;
}
public void MoveWindow(int x, int y)
{
2022-07-23 20:04:06 +00:00
_xCoor = x - LEFT_ADJUSTMENT;
_yCoor = y - TOP_ADJUSTMENT;
2022-07-10 23:58:54 +00:00
}
2022-07-06 18:09:10 +00:00
private void PanelCoorOverlay_LocationChanged(object sender, EventArgs e)
{
if (this.Top is double.NaN || this.Left is double.NaN)
return;
2022-07-23 20:04:06 +00:00
// Fixed broken window left/top coordinate for DPI Awareness Per Monitor
var handle = new WindowInteropHelper(this).Handle;
var rect = WindowActionManager.GetWindowRect(handle);
WindowLocationChanged?.Invoke(this, new System.Drawing.Point(rect.X + LEFT_ADJUSTMENT, rect.Y + TOP_ADJUSTMENT));
2022-01-27 13:40:04 +00:00
}
private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (IsEditingPanelLocation && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
this.DragMove();
}
2022-07-23 20:04:06 +00:00
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Fixed broken window left/top coordinate for DPI Awareness Per Monitor
var handle = new WindowInteropHelper(this).Handle;
2022-08-13 06:14:49 +00:00
WindowActionManager.MoveWindow(handle, _xCoor, _yCoor, Convert.ToInt32(this.Width), Convert.ToInt32(this.Height));
2022-07-23 20:04:06 +00:00
WindowActionManager.ApplyAlwaysOnTop(handle, PanelType.WPFWindow, true);
}
2022-01-27 13:40:04 +00:00
}
}