Files
XCEngine/new_editor/app/Platform/Win32/EditorFloatingWindowPlacement.cpp

47 lines
1.4 KiB
C++
Raw Normal View History

#include "Platform/Win32/EditorFloatingWindowPlacement.h"
#include <algorithm>
namespace XCEngine::UI::Editor::App {
namespace {
constexpr LONG kFloatingWindowTopOffset = 24;
}
RECT BuildEditorFloatingWindowRect(
const POINT& screenPoint,
LONG preferredWidth,
LONG preferredHeight,
LONG fallbackWidth,
LONG fallbackHeight) {
const LONG resolvedWidth = preferredWidth > 0 ? preferredWidth : fallbackWidth;
const LONG resolvedHeight = preferredHeight > 0 ? preferredHeight : fallbackHeight;
const LONG left = screenPoint.x - resolvedWidth / 2;
const LONG top = screenPoint.y - kFloatingWindowTopOffset;
RECT rect = {
left,
top,
left + resolvedWidth,
top + resolvedHeight
};
const HMONITOR monitor = MonitorFromPoint(screenPoint, MONITOR_DEFAULTTONEAREST);
MONITORINFO monitorInfo = {};
monitorInfo.cbSize = sizeof(monitorInfo);
if (monitor != nullptr && GetMonitorInfoW(monitor, &monitorInfo)) {
const RECT& workArea = monitorInfo.rcWork;
const LONG width = rect.right - rect.left;
const LONG height = rect.bottom - rect.top;
rect.left = (std::max)(workArea.left, (std::min)(rect.left, workArea.right - width));
rect.top = (std::max)(workArea.top, (std::min)(rect.top, workArea.bottom - height));
rect.right = rect.left + width;
rect.bottom = rect.top + height;
}
return rect;
}
} // namespace XCEngine::UI::Editor::App