refactor(new_editor/app): reorganize host structure and add smoke test
This commit is contained in:
72
new_editor/app/Platform/Win32/BorderlessWindowChrome.cpp
Normal file
72
new_editor/app/Platform/Win32/BorderlessWindowChrome.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "BorderlessWindowChrome.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace XCEngine::UI::Editor::Host {
|
||||
|
||||
namespace {
|
||||
|
||||
using ::XCEngine::UI::UIPoint;
|
||||
using ::XCEngine::UI::UIRect;
|
||||
|
||||
bool IsPointInsideRect(const UIRect& rect, const UIPoint& point) {
|
||||
return rect.width > 0.0f &&
|
||||
rect.height > 0.0f &&
|
||||
point.x >= rect.x &&
|
||||
point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y &&
|
||||
point.y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
BorderlessWindowChromeLayout BuildBorderlessWindowChromeLayout(
|
||||
const UIRect& titleBarRect,
|
||||
float leadingOccupiedRight,
|
||||
const BorderlessWindowChromeMetrics& metrics) {
|
||||
BorderlessWindowChromeLayout layout = {};
|
||||
layout.titleBarRect = titleBarRect;
|
||||
if (titleBarRect.width <= 0.0f || titleBarRect.height <= 0.0f) {
|
||||
return layout;
|
||||
}
|
||||
|
||||
const float buttonWidth = (std::max)(metrics.buttonWidth, 0.0f);
|
||||
const float buttonX3 = titleBarRect.x + titleBarRect.width - metrics.buttonInsetX - buttonWidth;
|
||||
const float buttonX2 = buttonX3 - buttonWidth;
|
||||
const float buttonX1 = buttonX2 - buttonWidth;
|
||||
|
||||
layout.minimizeButtonRect = UIRect(buttonX1, titleBarRect.y, buttonWidth, titleBarRect.height);
|
||||
layout.maximizeRestoreButtonRect = UIRect(buttonX2, titleBarRect.y, buttonWidth, titleBarRect.height);
|
||||
layout.closeButtonRect = UIRect(buttonX3, titleBarRect.y, buttonWidth, titleBarRect.height);
|
||||
|
||||
const float dragLeft =
|
||||
(std::max)(titleBarRect.x, leadingOccupiedRight + metrics.dragPaddingLeft);
|
||||
const float dragRight =
|
||||
(std::max)(dragLeft, layout.minimizeButtonRect.x - metrics.dragPaddingRight);
|
||||
layout.dragRect = UIRect(
|
||||
dragLeft,
|
||||
titleBarRect.y,
|
||||
(std::max)(0.0f, dragRight - dragLeft),
|
||||
titleBarRect.height);
|
||||
return layout;
|
||||
}
|
||||
|
||||
BorderlessWindowChromeHitTarget HitTestBorderlessWindowChrome(
|
||||
const BorderlessWindowChromeLayout& layout,
|
||||
const UIPoint& point) {
|
||||
if (IsPointInsideRect(layout.closeButtonRect, point)) {
|
||||
return BorderlessWindowChromeHitTarget::CloseButton;
|
||||
}
|
||||
if (IsPointInsideRect(layout.maximizeRestoreButtonRect, point)) {
|
||||
return BorderlessWindowChromeHitTarget::MaximizeRestoreButton;
|
||||
}
|
||||
if (IsPointInsideRect(layout.minimizeButtonRect, point)) {
|
||||
return BorderlessWindowChromeHitTarget::MinimizeButton;
|
||||
}
|
||||
if (IsPointInsideRect(layout.dragRect, point)) {
|
||||
return BorderlessWindowChromeHitTarget::DragRegion;
|
||||
}
|
||||
return BorderlessWindowChromeHitTarget::None;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Host
|
||||
Reference in New Issue
Block a user