96 lines
2.9 KiB
C++
96 lines
2.9 KiB
C++
|
|
#include "Platform/Win32/EditorWindow.h"
|
||
|
|
#include "Platform/Win32/EditorWindowConstants.h"
|
||
|
|
#include "Platform/Win32/EditorWindowRuntimeSupport.h"
|
||
|
|
|
||
|
|
#include <XCEngine/UI/Types.h>
|
||
|
|
|
||
|
|
namespace XCEngine::UI::Editor::App {
|
||
|
|
|
||
|
|
using namespace EditorWindowSupport;
|
||
|
|
using ::XCEngine::UI::UIPoint;
|
||
|
|
|
||
|
|
bool EditorWindow::ApplyWindowResize(UINT width, UINT height) {
|
||
|
|
if (!m_render.ready || width == 0u || height == 0u) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
const Host::D3D12WindowRenderLoopResizeResult resizeResult =
|
||
|
|
m_render.windowRenderLoop.ApplyResize(width, height);
|
||
|
|
m_composition.shellRuntime.SetViewportSurfacePresentationEnabled(
|
||
|
|
resizeResult.hasViewportSurfacePresentation);
|
||
|
|
|
||
|
|
if (!resizeResult.windowRendererWarning.empty()) {
|
||
|
|
LogRuntimeTrace("present", resizeResult.windowRendererWarning);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!resizeResult.interopWarning.empty()) {
|
||
|
|
LogRuntimeTrace("present", resizeResult.interopWarning);
|
||
|
|
}
|
||
|
|
|
||
|
|
return resizeResult.hasViewportSurfacePresentation;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool EditorWindow::QueryCurrentClientPixelSize(UINT& outWidth, UINT& outHeight) const {
|
||
|
|
outWidth = 0u;
|
||
|
|
outHeight = 0u;
|
||
|
|
if (m_window.hwnd == nullptr || !IsWindow(m_window.hwnd)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
RECT clientRect = {};
|
||
|
|
if (!GetClientRect(m_window.hwnd, &clientRect)) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
const LONG width = clientRect.right - clientRect.left;
|
||
|
|
const LONG height = clientRect.bottom - clientRect.top;
|
||
|
|
if (width <= 0 || height <= 0) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
outWidth = static_cast<UINT>(width);
|
||
|
|
outHeight = static_cast<UINT>(height);
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool EditorWindow::ResolveRenderClientPixelSize(UINT& outWidth, UINT& outHeight) const {
|
||
|
|
if (m_chrome.runtime.TryGetPredictedClientPixelSize(outWidth, outHeight)) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
return QueryCurrentClientPixelSize(outWidth, outHeight);
|
||
|
|
}
|
||
|
|
|
||
|
|
float EditorWindow::GetDpiScale() const {
|
||
|
|
return m_chrome.runtime.GetDpiScale(kBaseDpiScale);
|
||
|
|
}
|
||
|
|
|
||
|
|
float EditorWindow::PixelsToDips(float pixels) const {
|
||
|
|
const float dpiScale = GetDpiScale();
|
||
|
|
return dpiScale > 0.0f ? pixels / dpiScale : pixels;
|
||
|
|
}
|
||
|
|
|
||
|
|
UIPoint EditorWindow::ConvertClientPixelsToDips(LONG x, LONG y) const {
|
||
|
|
return UIPoint(
|
||
|
|
PixelsToDips(static_cast<float>(x)),
|
||
|
|
PixelsToDips(static_cast<float>(y)));
|
||
|
|
}
|
||
|
|
|
||
|
|
UIPoint EditorWindow::ConvertScreenPixelsToClientDips(const POINT& screenPoint) const {
|
||
|
|
POINT clientPoint = screenPoint;
|
||
|
|
if (m_window.hwnd != nullptr) {
|
||
|
|
ScreenToClient(m_window.hwnd, &clientPoint);
|
||
|
|
}
|
||
|
|
|
||
|
|
const float dpiScale = m_chrome.runtime.GetDpiScale(kBaseDpiScale);
|
||
|
|
return UIPoint(
|
||
|
|
dpiScale > 0.0f
|
||
|
|
? static_cast<float>(clientPoint.x) / dpiScale
|
||
|
|
: static_cast<float>(clientPoint.x),
|
||
|
|
dpiScale > 0.0f
|
||
|
|
? static_cast<float>(clientPoint.y) / dpiScale
|
||
|
|
: static_cast<float>(clientPoint.y));
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace XCEngine::UI::Editor::App
|