Skip to content

Commit

Permalink
Update ui control event priority by GUI Element render order
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Aug 21, 2024
1 parent b40ae55 commit 40951c1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
Binary file modified Assets/SampleGUIDemo/Main.gui
Binary file not shown.
2 changes: 1 addition & 1 deletion Projects/Editor/Source/Selection/CGUISelecting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace Skylicht
}
else
{
// no select gui
// no select gui
controller->deselectAllOnHierachy();
selection->clear();
}
Expand Down
7 changes: 6 additions & 1 deletion Projects/Skylicht/Engine/Source/Graphics2D/CCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ namespace Skylicht
CGUIElement* entity = NULL;
CGUIElement* parent = NULL;

int renderOrder = 0;

while (renderEntity.size() > 0)
{
entity = renderEntity.top();
Expand Down Expand Up @@ -217,6 +219,9 @@ namespace Skylicht

entity->render(camera);

// update render order for UI Hitest
entity->m_renderOrder = renderOrder++;

if (mask != NULL)
mask->endMaskTest();

Expand Down Expand Up @@ -254,7 +259,7 @@ namespace Skylicht
up = look.crossProduct(right);
up.normalize();

// billboard matrix
// billboard matrix
f32* matData = billboardMatrix.pointer();

matData[0] = right.X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Skylicht
m_drawBorder(false),
m_enableMaterial(false),
m_materialId(0),
m_renderOrder(0),
m_applyCurrentMask(NULL)
{
CEntityPrefab* entityPrefab = m_canvas->getEntityManager();
Expand All @@ -66,6 +67,7 @@ namespace Skylicht
m_drawBorder(false),
m_enableMaterial(false),
m_materialId(0),
m_renderOrder(0),
m_applyCurrentMask(NULL)
{
CEntityPrefab* entityPrefab = m_canvas->getEntityManager();
Expand Down
7 changes: 7 additions & 0 deletions Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace Skylicht
bool m_visible;
bool m_enableMaterial;

int m_renderOrder;

ArrayMaterial m_materials;

int m_materialId;
Expand Down Expand Up @@ -158,6 +160,11 @@ namespace Skylicht
return m_transform->Depth;
}

inline int getRenderOrder()
{
return m_renderOrder;
}

inline void setDock(EGUIDock dock)
{
m_guiAlign->Dock = dock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Skylicht
m_enable(true),
m_hover(NULL),
m_canvas(NULL),
m_skip(NULL),
m_inMotion(false),
m_outMotion(false),
m_pointerDown(false)
Expand Down Expand Up @@ -232,7 +233,7 @@ namespace Skylicht

std::sort(m_raycastUIObjects.begin(), m_raycastUIObjects.end(), [](CUIBase*& a, CUIBase*& b)
{
return a->getElement()->getDepth() > b->getElement()->getDepth();
return a->getElement()->getRenderOrder() > b->getElement()->getRenderOrder();
});

if (m_hover != m_raycastUIObjects[0])
Expand Down Expand Up @@ -317,6 +318,7 @@ namespace Skylicht
m_hover->onPointerOut(x, y);
m_hover = NULL;
}

m_skip = NULL;
m_pointerDown = false;
}
Expand Down

0 comments on commit 40951c1

Please sign in to comment.