Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(ui): UINode-aware hit-test + mask clipping (REARCH_GUI unification S2a)

esengine76e65aee3595
diff --git a/src/esengine/ecs/UIHitTestSystem.hpp b/src/esengine/ecs/UIHitTestSystem.hpp
index 4dcbf36c0..f583306a3 100644
--- a/src/esengine/ecs/UIHitTestSystem.hpp
+++ b/src/esengine/ecs/UIHitTestSystem.hpp
@@ -12,6 +12,7 @@
#include "components/Transform.hpp"
#include "components/Hierarchy.hpp"
#include "components/UIRect.hpp"
+#include "components/UINode.hpp"
#include "components/UIMask.hpp"
#include <cmath>
@@ -60,19 +61,30 @@ inline bool isClippedByMask(
auto* mask = registry.tryGet<UIMask>(ancestor);
if (mask && mask->enabled) {
auto* t = registry.tryGet<Transform>(ancestor);
- auto* rect = registry.tryGet<UIRect>(ancestor);
- if (t && rect) {
- t->ensureDecomposed();
- f32 maskW = (rect->computed_size_.x > 0.0f ? rect->computed_size_.x : rect->size.x) * t->worldScale.x;
- f32 maskH = (rect->computed_size_.y > 0.0f ? rect->computed_size_.y : rect->size.y) * t->worldScale.y;
- if (!pointInOBB(
- worldMouseX, worldMouseY,
- t->worldPosition.x, t->worldPosition.y,
- maskW, maskH,
- rect->pivot.x, rect->pivot.y,
- t->worldRotation.z, t->worldRotation.w
- )) {
- return true;
+ if (t) {
+ // Mask geometry from the modern UINode (pivot-centered) or UIRect.
+ f32 baseW = 0.0f, baseH = 0.0f, pivotX = 0.5f, pivotY = 0.5f;
+ bool haveBox = false;
+ if (auto* node = registry.tryGet<UINode>(ancestor)) {
+ baseW = node->computed_size_.x; baseH = node->computed_size_.y;
+ haveBox = true;
+ } else if (auto* rect = registry.tryGet<UIRect>(ancestor)) {
+ baseW = rect->computed_size_.x > 0.0f ? rect->computed_size_.x : rect->size.x;
+ baseH = rect->computed_size_.y > 0.0f ? rect->computed_size_.y : rect->size.y;
+ pivotX = rect->pivot.x; pivotY = rect->pivot.y;
+ haveBox = true;
+ }
+ if (haveBox) {
+ t->ensureDecomposed();
+ if (!pointInOBB(
+ worldMouseX, worldMouseY,
+ t->worldPosition.x, t->worldPosition.y,
+ baseW * t->worldScale.x, baseH * t->worldScale.y,
+ pivotX, pivotY,
+ t->worldRotation.z, t->worldRotation.w
+ )) {
+ return true;
+ }
}
}
}
diff --git a/src/esengine/ecs/UISystem.cpp b/src/esengine/ecs/UISystem.cpp
index b65550616..8a3009380 100644
--- a/src/esengine/ecs/UISystem.cpp
+++ b/src/esengine/ecs/UISystem.cpp
@@ -14,6 +14,7 @@
#include "components/Transform.hpp"
#include "components/UIInteraction.hpp"
#include "components/UIRect.hpp"
+#include "components/UINode.hpp"
namespace esengine::ecs {
@@ -42,16 +43,32 @@ void UISystem::hitTestUpdate(
auto& t = registry.get<Transform>(entity);
t.ensureDecomposed();
- auto& rect = registry.get<UIRect>(entity);
- f32 worldW = (rect.computed_size_.x > 0.0f ? rect.computed_size_.x : rect.size.x) * t.worldScale.x;
- f32 worldH = (rect.computed_size_.y > 0.0f ? rect.computed_size_.y : rect.size.y) * t.worldScale.y;
+ // Hit geometry from the modern UINode (CSS box, pivot-centered) or the
+ // legacy UIRect.
+ f32 baseW, baseH, pivotX, pivotY;
+ if (auto* node = registry.tryGet<UINode>(entity)) {
+ baseW = node->computed_size_.x;
+ baseH = node->computed_size_.y;
+ pivotX = 0.5f;
+ pivotY = 0.5f;
+ } else if (auto* rect = registry.tryGet<UIRect>(entity)) {
+ baseW = rect->computed_size_.x > 0.0f ? rect->computed_size_.x : rect->size.x;
+ baseH = rect->computed_size_.y > 0.0f ? rect->computed_size_.y : rect->size.y;
+ pivotX = rect->pivot.x;
+ pivotY = rect->pivot.y;
+ } else {
+ continue;
+ }
+
+ f32 worldW = baseW * t.worldScale.x;
+ f32 worldH = baseH * t.worldScale.y;
if (pointInOBB(
mouseWorldX, mouseWorldY,
t.worldPosition.x, t.worldPosition.y,
worldW, worldH,
- rect.pivot.x, rect.pivot.y,
+ pivotX, pivotY,
t.worldRotation.z, t.worldRotation.w
)) {
if (isClippedByMask(registry, entity, mouseWorldX, mouseWorldY)) {