Skip to content

Commit 7448697

Browse files
committed
#158 Fix gizmos position with align property, move gui objects
1 parent fb4391a commit 7448697

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

Projects/Editor/Source/Editor/GUIEditor/CGUIEditor.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ namespace Skylicht
7575
CSpaceGUIDesign* guiDesign = dynamic_cast<CSpaceGUIDesign*>(space);
7676
CGUITransformGizmos* gizmos = guiDesign->getGizmos();
7777

78+
// update transform first
79+
m_gui->getCanvas()->updateEntities();
80+
81+
// apply for Gizmos
7882
gizmos->setTransform(
79-
m_gui->getPosition(),
83+
m_gui->getAlignPosition(),
8084
m_gui->getRotation(),
8185
m_gui->getScale(),
8286
m_gui->getRect()

Projects/Editor/Source/Editor/Gizmos/GUITransform/CGUITransformGizmos.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ namespace Skylicht
5959
if (selectObject == NULL)
6060
{
6161
handle->end();
62+
m_selectID = "";
6263
return;
6364
}
6465

@@ -86,7 +87,7 @@ namespace Skylicht
8687
if (parentGUI)
8788
m_parentWorld = parentGUI->getAbsoluteTransform();
8889

89-
m_position = gui->getPosition();
90+
m_position = gui->getAlignPosition();
9091
m_rotation = gui->getRotationQuaternion();
9192
m_scale = gui->getScale();
9293
m_rect = gui->getRect();
@@ -109,24 +110,27 @@ namespace Skylicht
109110
// position
110111
{
111112
core::vector3df newPos = CGUIHandles::getInstance()->positionHandle(*m_position, m_gui->getRotationQuaternion());
113+
core::vector3df delta;
112114

113115
if (newPos != *m_position)
114116
{
115-
core::vector3df delta = newPos - *m_position;
117+
delta = newPos - *m_position;
116118
updateSelectedPosition(delta);
117119

118120
m_position = newPos;
119121
m_position.notify(this);
120122

121-
m_gui->setPosition(newPos);
123+
core::vector3df p = m_gui->getPosition() + delta;
124+
m_gui->setPosition(p);
122125

123126
m_changed = true;
124127
updateProperty();
125128
}
126129

127130
if (handle->endCheck())
128131
{
129-
m_gui->setPosition(*m_position);
132+
core::vector3df p = m_gui->getPosition() + delta;
133+
m_gui->setPosition(p);
130134
handle->end();
131135

132136
// save undo/redo
@@ -139,7 +143,7 @@ namespace Skylicht
139143
{
140144
core::rectf newRect = CGUIHandles::getInstance()->rectHandle(
141145
*m_rect,
142-
m_gui->getPosition(),
146+
m_gui->getAlignPosition(),
143147
m_gui->getScale(),
144148
m_gui->getRotationQuaternion());
145149

@@ -159,6 +163,8 @@ namespace Skylicht
159163
m_gui->setRect(*m_rect);
160164
handle->end();
161165

166+
m_selectID = "";
167+
162168
// save undo/redo
163169
// if (m_changed)
164170
// saveHistorySelectedObject();
@@ -264,14 +270,39 @@ namespace Skylicht
264270
CGameObject* guiCanvas = scene->searchObjectInChild(L"GUICanvas");
265271
CCanvas* canvas = guiCanvas->getComponent<CCanvas>();
266272

267-
guis.clear();
273+
std::vector<CGUIElement*> selects;
268274

269275
std::vector<CSelectObject*>& selectList = CSelection::getInstance()->getAllSelected();
270276
for (CSelectObject* sel : selectList)
271277
{
272278
CGUIElement* gui = canvas->getGUIByID(sel->getID().c_str());
273279
if (gui)
274-
guis.push_back(gui);
280+
selects.push_back(gui);
281+
}
282+
283+
std::sort(selects.begin(), selects.end(), [](CGUIElement*& a, CGUIElement*& b)
284+
{
285+
return a->getDepth() < b->getDepth();
286+
});
287+
288+
guis.clear();
289+
290+
for (CGUIElement* sel : selects)
291+
{
292+
bool add = true;
293+
for (CGUIElement* del : guis)
294+
{
295+
if (sel->isChild(del))
296+
{
297+
add = false;
298+
break;
299+
}
300+
}
301+
302+
if (add)
303+
{
304+
guis.push_back(sel);
305+
}
275306
}
276307
}
277308
}

Projects/Skylicht/Engine/Source/Graphics2D/EntityData/CGUITransformData.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ namespace Skylicht
5858
return m_position;
5959
}
6060

61+
inline const core::vector3df& getAlignPosition()
62+
{
63+
return m_transformPosition;
64+
}
65+
6166
inline void setPosition(const core::vector3df& v)
6267
{
6368
m_position = v;

Projects/Skylicht/Engine/Source/Graphics2D/GUI/CGUIElement.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ namespace Skylicht
185185

186186
void setRelativeTransform(const core::matrix4& relative);
187187

188+
inline const core::vector3df getAlignPosition()
189+
{
190+
return m_guiTransform->getAlignPosition();
191+
}
192+
188193
inline const core::vector3df& getPosition()
189194
{
190195
return m_guiTransform->getPosition();

Projects/Skylicht/Engine/Source/Graphics2D/GUISystem/CGUILayoutSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ namespace Skylicht
230230
m[10] *= t->m_scale.Z;
231231
m[11] *= t->m_scale.Z;
232232

233-
m[12] = t->m_position.X;
234-
m[13] = t->m_position.Y;
235-
m[14] = t->m_position.Z;
233+
m[12] = t->m_transformPosition.X;
234+
m[13] = t->m_transformPosition.Y;
235+
m[14] = t->m_transformPosition.Z;
236236

237237
// update world matrix
238238
if (w->Parent)

0 commit comments

Comments
 (0)