refactor(new_editor/app): reorganize host structure and add smoke test
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#include "Platform/Win32/EditorWindow.h"
|
||||
#include "Platform/Win32/EditorWindowConstants.h"
|
||||
#include "Platform/Win32/EditorWindowStyle.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <windowsx.h>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
using namespace EditorWindowSupport;
|
||||
using ::XCEngine::UI::UIColor;
|
||||
using ::XCEngine::UI::UIDrawList;
|
||||
using ::XCEngine::UI::UIPoint;
|
||||
using ::XCEngine::UI::UIRect;
|
||||
|
||||
Host::BorderlessWindowChromeHitTarget EditorWindow::HitTestBorderlessWindowChrome(
|
||||
LPARAM lParam) const {
|
||||
if (!IsBorderlessWindowEnabled() || m_window.hwnd == nullptr) {
|
||||
return Host::BorderlessWindowChromeHitTarget::None;
|
||||
}
|
||||
|
||||
RECT clientRect = {};
|
||||
if (!GetClientRect(m_window.hwnd, &clientRect)) {
|
||||
return Host::BorderlessWindowChromeHitTarget::None;
|
||||
}
|
||||
|
||||
const float clientWidthDips =
|
||||
PixelsToDips(static_cast<float>((std::max)(clientRect.right - clientRect.left, 1L)));
|
||||
const Host::BorderlessWindowChromeLayout layout =
|
||||
ResolveBorderlessWindowChromeLayout(clientWidthDips);
|
||||
return Host::HitTestBorderlessWindowChrome(
|
||||
layout,
|
||||
ConvertClientPixelsToDips(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
|
||||
}
|
||||
|
||||
Host::BorderlessWindowChromeLayout EditorWindow::ResolveBorderlessWindowChromeLayout(
|
||||
float clientWidthDips) const {
|
||||
return Host::BuildBorderlessWindowChromeLayout(
|
||||
UIRect(0.0f, 0.0f, clientWidthDips, kBorderlessTitleBarHeightDips),
|
||||
0.0f);
|
||||
}
|
||||
|
||||
void EditorWindow::AppendBorderlessWindowChrome(
|
||||
UIDrawList& drawList,
|
||||
float clientWidthDips) const {
|
||||
if (!IsBorderlessWindowEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Host::BorderlessWindowChromeLayout layout =
|
||||
ResolveBorderlessWindowChromeLayout(clientWidthDips);
|
||||
const float iconExtent = 16.0f;
|
||||
const float iconInsetLeft = 8.0f;
|
||||
const float iconTextGap = 8.0f;
|
||||
const float iconX = layout.titleBarRect.x + iconInsetLeft;
|
||||
const float iconY =
|
||||
layout.titleBarRect.y +
|
||||
(std::max)(0.0f, (layout.titleBarRect.height - iconExtent) * 0.5f);
|
||||
drawList.AddFilledRect(layout.titleBarRect, kShellSurfaceColor);
|
||||
drawList.AddLine(
|
||||
UIPoint(layout.titleBarRect.x, layout.titleBarRect.y + layout.titleBarRect.height),
|
||||
UIPoint(
|
||||
layout.titleBarRect.x + layout.titleBarRect.width,
|
||||
layout.titleBarRect.y + layout.titleBarRect.height),
|
||||
kShellBorderColor,
|
||||
1.0f);
|
||||
if (m_render.titleBarLogoIcon.IsValid()) {
|
||||
drawList.AddImage(
|
||||
UIRect(iconX, iconY, iconExtent, iconExtent),
|
||||
m_render.titleBarLogoIcon,
|
||||
UIColor(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
const std::string& titleText =
|
||||
m_window.titleText.empty() ? std::string("XCEngine Editor") : m_window.titleText;
|
||||
drawList.AddText(
|
||||
UIPoint(
|
||||
iconX + (m_render.titleBarLogoIcon.IsValid() ? (iconExtent + iconTextGap) : 4.0f),
|
||||
layout.titleBarRect.y +
|
||||
(std::max)(
|
||||
0.0f,
|
||||
(layout.titleBarRect.height - kBorderlessTitleBarFontSize) * 0.5f - 1.0f)),
|
||||
titleText,
|
||||
kShellTextColor,
|
||||
kBorderlessTitleBarFontSize);
|
||||
Host::AppendBorderlessWindowChrome(
|
||||
drawList,
|
||||
layout,
|
||||
m_chrome.chromeState,
|
||||
IsBorderlessWindowMaximized());
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
Reference in New Issue
Block a user