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
2022-07-23 15:23:32 -04:00

49 lines
1.5 KiB
C#

using System;
using System.Windows;
namespace MSFSPopoutPanelManager.WpfApp
{
public partial class PanelCoorOverlay : Window
{
private const int TOP_ADJUSTMENT = 23; // half of window height
private const int LEFT_ADJUSTMENT = 27; // half of window width
public bool IsEditingPanelLocation { get; set; }
public IntPtr WindowHandle { get; set; }
public event EventHandler<System.Drawing.Point> WindowLocationChanged;
public PanelCoorOverlay(int panelIndex)
{
InitializeComponent();
this.lblPanelIndex.Content = panelIndex;
IsEditingPanelLocation = false;
this.LocationChanged += PanelCoorOverlay_LocationChanged;
}
public void MoveWindow(int x, int y)
{
this.Left = x - LEFT_ADJUSTMENT;
this.Top = y - TOP_ADJUSTMENT;
}
private void PanelCoorOverlay_LocationChanged(object sender, EventArgs e)
{
if (this.Top is double.NaN || this.Left is double.NaN)
return;
var top = Convert.ToInt32(this.Top);
var left = Convert.ToInt32(this.Left);
WindowLocationChanged?.Invoke(this, new System.Drawing.Point(left + LEFT_ADJUSTMENT, top + TOP_ADJUSTMENT));
}
private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (IsEditingPanelLocation && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
this.DragMove();
}
}
}