1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2025-02-18 01:14:29 +01:00
msfs-popout-panel-manager/WpfApp/PanelCoorOverlay.xaml.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2022-07-06 20:09:10 +02:00
using MSFSPopoutPanelManager.Shared;
using System;
2022-01-27 14:40:04 +01:00
using System.Windows;
namespace MSFSPopoutPanelManager.WpfApp
{
public partial class PanelCoorOverlay : Window
{
2022-07-06 20:09:10 +02:00
private const int TOP_ADJUSTMENT = 23; // half of window height
private const int LEFT_ADJUSTMENT = 27; // half of window width
2022-01-27 14:40:04 +01:00
public bool IsEditingPanelLocation { get; set; }
public IntPtr WindowHandle { get; set; }
2022-07-06 20:09:10 +02:00
public event EventHandler<EventArgs<System.Drawing.Point>> WindowLocationChanged;
2022-01-27 14:40:04 +01:00
public PanelCoorOverlay(int panelIndex)
{
InitializeComponent();
this.lblPanelIndex.Content = panelIndex;
IsEditingPanelLocation = false;
2022-07-06 20:09:10 +02:00
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 EventArgs<System.Drawing.Point>(new System.Drawing.Point(left + LEFT_ADJUSTMENT, top + TOP_ADJUSTMENT)));
2022-01-27 14:40:04 +01:00
}
private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (IsEditingPanelLocation && e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
this.DragMove();
}
}
}