VPet/VPet-Simulator.Windows/Function/MWController.cs

90 lines
2.3 KiB
C#
Raw Normal View History

using System.Windows.Forms;
using System.Windows.Interop;
using System.Drawing;
using VPet_Simulator.Core;
2022-12-13 07:10:18 +00:00
namespace VPet_Simulator.Windows
{
2022-12-14 18:17:13 +00:00
/// <summary>
/// 窗体控制器实现
/// </summary>
2022-12-13 07:10:18 +00:00
public class MWController : IController
{
2022-12-14 18:17:13 +00:00
readonly MainWindow mw;
2022-12-13 07:10:18 +00:00
public MWController(MainWindow mw)
{
this.mw = mw;
}
private Rectangle? _screenBorder = null;
private Rectangle ScreenBorder
{
get
{
if (_screenBorder == null)
{
var windowInteropHelper = new WindowInteropHelper(mw);
var currentScreen = Screen.FromHandle(windowInteropHelper.Handle);
_screenBorder = currentScreen.Bounds;
}
return (Rectangle)_screenBorder;
}
}
public void ClearScreenBorderCache()
{
_screenBorder = null;
}
public double GetWindowsDistanceLeft()
2022-12-13 07:10:18 +00:00
{
return mw.Dispatcher.Invoke(() => mw.Left - ScreenBorder.X);
2022-12-13 07:10:18 +00:00
}
public double GetWindowsDistanceUp()
2022-12-13 07:10:18 +00:00
{
return mw.Dispatcher.Invoke(() => mw.Top - ScreenBorder.Y);
2022-12-13 07:10:18 +00:00
}
2022-12-14 18:17:13 +00:00
public double GetWindowsDistanceRight()
2022-12-13 07:10:18 +00:00
{
return mw.Dispatcher.Invoke(() => ScreenBorder.Width + ScreenBorder.X - mw.Left - mw.Width);
2022-12-13 07:10:18 +00:00
}
public double GetWindowsDistanceDown()
2022-12-13 07:10:18 +00:00
{
return mw.Dispatcher.Invoke(() => ScreenBorder.Height + ScreenBorder.Y - mw.Top - mw.Height);
2022-12-13 07:10:18 +00:00
}
2022-12-14 18:17:13 +00:00
public void MoveWindows(double X, double Y)
2022-12-13 07:10:18 +00:00
{
2022-12-14 18:17:13 +00:00
mw.Dispatcher.Invoke(() =>
{
mw.Left += X * ZoomRatio;
mw.Top += Y * ZoomRatio;
ClearScreenBorderCache();
2022-12-14 18:17:13 +00:00
});
2022-12-13 07:10:18 +00:00
}
2022-12-28 10:24:38 +00:00
public void ShowSetting()
2023-01-03 04:18:21 +00:00
{
2023-01-11 13:44:16 +00:00
mw.Topmost = false;
2023-08-10 11:34:11 +00:00
mw.ShowSetting();
2022-12-28 10:24:38 +00:00
}
2023-01-08 02:59:54 +00:00
public void ShowPanel()
{
var panelWindow = new winCharacterPanel();
panelWindow.ShowDialog();
}
2023-01-10 10:43:32 +00:00
public double ZoomRatio => mw.Set.ZoomLevel;
2023-01-08 16:57:10 +00:00
2023-01-24 06:56:16 +00:00
public int PressLength => mw.Set.PressLength;
2023-06-08 11:44:41 +00:00
public bool EnableFunction => mw.Set.EnableFunction;
2023-01-24 06:56:16 +00:00
public int InteractionCycle => mw.Set.InteractionCycle;
2023-01-21 14:16:13 +00:00
2022-12-13 07:10:18 +00:00
}
}