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

151 lines
4.9 KiB
C#
Raw Normal View History

2023-09-04 14:12:24 +00:00
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;
2023-09-05 15:33:08 +00:00
_isPrimaryScreen = mw.Set.MoveAreaDefault;
_screenBorder = mw.Set.MoveArea;
2022-12-13 07:10:18 +00:00
}
2023-09-05 15:33:08 +00:00
private Rectangle _screenBorder;
private bool _isPrimaryScreen = true;
public bool IsPrimaryScreen
{
2023-09-04 14:12:24 +00:00
get
{
return _isPrimaryScreen;
2023-09-04 14:12:24 +00:00
}
2023-09-05 15:33:08 +00:00
private set
{
_isPrimaryScreen = value;
mw.Set.MoveAreaDefault = value;
}
2023-09-04 14:12:24 +00:00
}
2023-09-05 15:33:08 +00:00
public Rectangle ScreenBorder
{
get
{
return _screenBorder;
}
2023-09-05 14:59:30 +00:00
set
{
_screenBorder = value;
2023-09-05 15:33:08 +00:00
mw.Set.MoveArea = value;
IsPrimaryScreen = false;
2023-09-05 14:59:30 +00:00
}
}
2023-09-05 15:33:08 +00:00
public void ResetScreenBorder()
2023-09-04 14:12:24 +00:00
{
2023-09-05 15:33:08 +00:00
IsPrimaryScreen = true;
}
public double GetWindowsDistanceLeft()
2022-12-13 07:10:18 +00:00
{
return mw.Dispatcher.Invoke(() =>
{
if (IsPrimaryScreen) return mw.Left;
return mw.Left - ScreenBorder.X;
});
2023-09-04 14:12:24 +00:00
}
public double GetWindowsDistanceUp()
{
return mw.Dispatcher.Invoke(() =>
{
if (IsPrimaryScreen) return mw.Top;
return 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(() =>
{
if (IsPrimaryScreen) return System.Windows.SystemParameters.PrimaryScreenWidth - mw.Left - mw.Width;
return ScreenBorder.Width + ScreenBorder.X - mw.Left - mw.Width;
});
2022-12-13 07:10:18 +00:00
}
2023-09-04 14:12:24 +00:00
public double GetWindowsDistanceDown()
2022-12-13 07:10:18 +00:00
{
return mw.Dispatcher.Invoke(() =>
{
if (IsPrimaryScreen) return System.Windows.SystemParameters.PrimaryScreenHeight - mw.Top - mw.Height;
return 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;
});
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()
{
2023-10-25 15:57:18 +00:00
var panelWindow = new winCharacterPanel(mw);
2023-10-27 08:43:20 +00:00
panelWindow.Show();
2023-01-08 02:59:54 +00:00
}
2023-12-01 05:47:33 +00:00
public void ResetPosition()
{
mw.Dispatcher.Invoke(() =>
{
2023-12-02 10:12:03 +00:00
if (GetWindowsDistanceUp() < -0.25 * mw.Height && GetWindowsDistanceDown() < System.Windows.SystemParameters.PrimaryScreenHeight)
2023-12-01 05:47:33 +00:00
{
2023-12-02 10:12:03 +00:00
MoveWindows(0, -GetWindowsDistanceUp() / ZoomRatio);
}
else if (GetWindowsDistanceDown() < -0.25 * mw.Height && GetWindowsDistanceUp() < System.Windows.SystemParameters.PrimaryScreenHeight)
{
MoveWindows(0, GetWindowsDistanceDown() / ZoomRatio);
}
if (GetWindowsDistanceLeft() < -0.25 * mw.Width && GetWindowsDistanceRight() < System.Windows.SystemParameters.PrimaryScreenWidth)
{
MoveWindows(-GetWindowsDistanceLeft() / ZoomRatio, 0);
}
else if (GetWindowsDistanceRight() < -0.25 * mw.Width && GetWindowsDistanceLeft() < System.Windows.SystemParameters.PrimaryScreenWidth)
{
MoveWindows(GetWindowsDistanceRight() / ZoomRatio, 0);
2023-12-01 05:47:33 +00:00
}
});
}
2023-12-02 10:12:03 +00:00
public bool CheckPosition() => mw.Dispatcher.Invoke(() =>
GetWindowsDistanceUp() < -0.25 * mw.Height && GetWindowsDistanceDown() < System.Windows.SystemParameters.PrimaryScreenHeight
|| GetWindowsDistanceDown() < -0.25 * mw.Height && GetWindowsDistanceUp() < System.Windows.SystemParameters.PrimaryScreenHeight
|| GetWindowsDistanceLeft() < -0.25 * mw.Width && GetWindowsDistanceRight() < System.Windows.SystemParameters.PrimaryScreenWidth
|| GetWindowsDistanceRight() < -0.25 * mw.Width && GetWindowsDistanceLeft() < System.Windows.SystemParameters.PrimaryScreenWidth
);
public bool RePostionActive { get; set; } = true;
2023-12-01 05:47:33 +00:00
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
}
}