Merge branch 'win_minimize_pos_fix' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-win_minimize_pos_fix

This commit is contained in:
Wojtek Figat
2023-10-14 16:23:28 +02:00
3 changed files with 31 additions and 8 deletions

View File

@@ -532,6 +532,12 @@ Float2 WindowsWindow::ClientToScreen(const Float2& clientPos) const
{
ASSERT(HasHWND());
if (_minimized)
{
// Return cached position when window is not on screen
return _minimizedScreenPosition + clientPos;
}
POINT p;
p.x = static_cast<LONG>(clientPos.X);
p.y = static_cast<LONG>(clientPos.Y);
@@ -1109,6 +1115,28 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
if (SIZE_MINIMIZED == wParam)
{
// Get the minimized window position in workspace coordinates
WINDOWPLACEMENT placement;
placement.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(_handle, &placement);
// Calculate client offsets from window borders and title bar
RECT winRect = { 0, 0, static_cast<LONG>(_clientSize.X), static_cast<LONG>(_clientSize.Y) };
LONG style = GetWindowLong(_handle, GWL_STYLE);
LONG exStyle = GetWindowLong(_handle, GWL_EXSTYLE);
AdjustWindowRectEx(&winRect, style, FALSE, exStyle);
// Calculate monitor offsets from taskbar position
const HMONITOR monitor = MonitorFromWindow(_handle, MONITOR_DEFAULTTONEAREST);
MONITORINFO monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFO);
GetMonitorInfoW(monitor, &monitorInfo);
// Convert the workspace coordinates to screen space and store it
_minimizedScreenPosition = Float2(
static_cast<float>(placement.rcNormalPosition.left + monitorInfo.rcWork.left - monitorInfo.rcMonitor.left - winRect.left),
static_cast<float>(placement.rcNormalPosition.top + monitorInfo.rcWork.top - monitorInfo.rcMonitor.top - winRect.top));
_minimized = true;
_maximized = false;
}

View File

@@ -32,6 +32,7 @@ private:
Windows::HANDLE _monitor = nullptr;
Windows::LONG _clipCursorRect[4];
int32 _regionWidth = 0, _regionHeight = 0;
Float2 _minimizedScreenPosition = Float2::Zero;
public: