mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
修复屏幕边界计算+缓存屏幕外包矩形
This commit is contained in:
parent
e7afd22b4e
commit
77843f6511
@ -1,5 +1,6 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
|
using System.Drawing;
|
||||||
using VPet_Simulator.Core;
|
using VPet_Simulator.Core;
|
||||||
|
|
||||||
namespace VPet_Simulator.Windows
|
namespace VPet_Simulator.Windows
|
||||||
@ -15,36 +16,43 @@ namespace VPet_Simulator.Windows
|
|||||||
this.mw = 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()
|
public double GetWindowsDistanceLeft()
|
||||||
{
|
{
|
||||||
return mw.Dispatcher.Invoke(() => mw.Left);
|
return mw.Dispatcher.Invoke(() => mw.Left - ScreenBorder.X);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetWindowsDistanceUp()
|
public double GetWindowsDistanceUp()
|
||||||
{
|
{
|
||||||
return mw.Dispatcher.Invoke(() => mw.Top);
|
return mw.Dispatcher.Invoke(() => mw.Top - ScreenBorder.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetWindowsDistanceRight()
|
public double GetWindowsDistanceRight()
|
||||||
{
|
{
|
||||||
return mw.Dispatcher.Invoke(() =>
|
return mw.Dispatcher.Invoke(() => ScreenBorder.Width + ScreenBorder.X - mw.Left - mw.Width);
|
||||||
{
|
|
||||||
var windowInteropHelper = new WindowInteropHelper(mw);
|
|
||||||
var currentScreen = Screen.FromHandle(windowInteropHelper.Handle);
|
|
||||||
var currentScreenBorder = currentScreen.Bounds;
|
|
||||||
return currentScreenBorder.Width - mw.Left - mw.Width;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetWindowsDistanceDown()
|
public double GetWindowsDistanceDown()
|
||||||
{
|
{
|
||||||
return mw.Dispatcher.Invoke(() =>
|
return mw.Dispatcher.Invoke(() => ScreenBorder.Height + ScreenBorder.Y - mw.Top - mw.Height);
|
||||||
{
|
|
||||||
var windowInteropHelper = new WindowInteropHelper(mw);
|
|
||||||
var currentScreen = Screen.FromHandle(windowInteropHelper.Handle);
|
|
||||||
var currentScreenBorder = currentScreen.Bounds;
|
|
||||||
return currentScreenBorder.Height - mw.Top - mw.Height;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveWindows(double X, double Y)
|
public void MoveWindows(double X, double Y)
|
||||||
@ -53,6 +61,7 @@ namespace VPet_Simulator.Windows
|
|||||||
{
|
{
|
||||||
mw.Left += X * ZoomRatio;
|
mw.Left += X * ZoomRatio;
|
||||||
mw.Top += Y * ZoomRatio;
|
mw.Top += Y * ZoomRatio;
|
||||||
|
ClearScreenBorderCache();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,6 +638,7 @@ namespace VPet_Simulator.Windows
|
|||||||
Main.DisplayToNomal();
|
Main.DisplayToNomal();
|
||||||
Left = (SystemParameters.PrimaryScreenWidth - Width) / 2;
|
Left = (SystemParameters.PrimaryScreenWidth - Width) / 2;
|
||||||
Top = (SystemParameters.PrimaryScreenHeight - Height) / 2;
|
Top = (SystemParameters.PrimaryScreenHeight - Height) / 2;
|
||||||
|
(Core.Controller as MWController).ClearScreenBorderCache();
|
||||||
}));
|
}));
|
||||||
m_menu.MenuItems.Add(new MenuItem("反馈中心".Translate(), (x, y) => { new winReport(this).Show(); }));
|
m_menu.MenuItems.Add(new MenuItem("反馈中心".Translate(), (x, y) => { new winReport(this).Show(); }));
|
||||||
m_menu.MenuItems.Add(new MenuItem("开发控制台".Translate(), (x, y) => { new winConsole(this).Show(); }));
|
m_menu.MenuItems.Add(new MenuItem("开发控制台".Translate(), (x, y) => { new winConsole(this).Show(); }));
|
||||||
|
Loading…
Reference in New Issue
Block a user