Skip to content

Commit e5bfb4d

Browse files
committed
#157 Implement layout system
1 parent 4896643 commit e5bfb4d

File tree

14 files changed

+314
-316
lines changed

14 files changed

+314
-316
lines changed

Projects/Skylicht/Engine/Source/Graphics2D/CCanvas.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace Skylicht
4646

4747
// add root
4848
m_root = new CGUIElement(this, NULL, m_rect);
49-
m_root->setDock(CGUIElement::DockFill);
49+
m_root->setDock(EGUIDock::DockFill);
5050

5151
m_systems.push_back(new CGUILayoutSystem());
5252
for (IEntitySystem* system : m_systems)
@@ -117,6 +117,11 @@ namespace Skylicht
117117

118118
if (maxDepth < world->Depth)
119119
maxDepth = world->Depth;
120+
121+
if (world->ParentIndex != -1)
122+
world->Parent = GET_ENTITY_DATA(entities[world->ParentIndex], CWorldTransformData);
123+
else
124+
world->Parent = NULL;
120125
}
121126
}
122127

@@ -131,21 +136,19 @@ namespace Skylicht
131136
for (int j = 0, n = m_depth[i].count(); j < n; j++)
132137
m_alives.push(entitiesPtr[j]);
133138
}
134-
}
135-
136-
void CCanvas::render(CCamera* camera)
137-
{
138-
m_renderCamera = camera;
139-
140-
// update system
141-
updateEntities();
142139

140+
// update systems
143141
for (IEntitySystem* system : m_systems)
144142
{
145143
system->beginQuery(NULL);
146144
system->onQuery(NULL, m_alives.pointer(), m_alives.count());
147145
system->update(NULL);
148146
}
147+
}
148+
149+
void CCanvas::render(CCamera* camera)
150+
{
151+
m_renderCamera = camera;
149152

150153
// render
151154
std::stack<CGUIElement*> renderEntity;

Projects/Skylicht/Engine/Source/Graphics2D/CGraphics2D.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ namespace Skylicht
214214

215215
CGUIElement* root = canvas->getRootElement();
216216

217+
// set screensize for root
218+
core::dimension2du s = getScreenSize();
219+
float w = (float)s.Width;
220+
float h = (float)s.Height;
221+
root->setRect(core::rectf(0.0f, 0.0f, w, h));
222+
223+
// update canvas layout, position...
224+
canvas->updateEntities();
225+
217226
core::matrix4 world;
218227

219228
if (canvas->isEnable3DBillboard() == true && camera->getProjectionType() != CCamera::OrthoUI)

Projects/Skylicht/Engine/Source/Graphics2D/EntityData/CGUIAlignData.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ namespace Skylicht
2929
{
3030
IMPLEMENT_DATA_TYPE_INDEX(CGUIAlignData);
3131

32-
CGUIAlignData::CGUIAlignData()
32+
CGUIAlignData::CGUIAlignData() :
33+
Vertical(EGUIVerticalAlign::Top),
34+
Horizontal(EGUIHorizontalAlign::Left),
35+
Dock(EGUIDock::NoDock)
3336
{
3437

3538
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,61 @@ This file is part of the "Skylicht Engine".
2828

2929
namespace Skylicht
3030
{
31+
enum class EGUIVerticalAlign
32+
{
33+
Top,
34+
Middle,
35+
Bottom
36+
};
37+
38+
enum class EGUIHorizontalAlign
39+
{
40+
Left,
41+
Center,
42+
Right
43+
};
44+
45+
enum class EGUIDock
46+
{
47+
NoDock,
48+
DockLeft,
49+
DockRight,
50+
DockTop,
51+
DockBottom,
52+
DockFill
53+
};
54+
55+
struct SMargin
56+
{
57+
float Left;
58+
float Top;
59+
float Right;
60+
float Bottom;
61+
62+
SMargin()
63+
{
64+
Left = 0.0f;
65+
Top = 0.0f;
66+
Right = 0.0f;
67+
Bottom = 0.0f;
68+
}
69+
};
70+
3171
class CGUIAlignData : public IEntityData
3272
{
3373
friend class CGUILayoutSystem;
3474

3575
public:
3676
DECLARE_DATA_TYPE_INDEX;
3777

78+
EGUIDock Dock;
79+
80+
SMargin Margin;
81+
82+
EGUIVerticalAlign Vertical;
83+
84+
EGUIHorizontalAlign Horizontal;
85+
3886
public:
3987
CGUIAlignData();
4088

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ namespace Skylicht
3030
IMPLEMENT_DATA_TYPE_INDEX(CGUITransformData);
3131

3232
CGUITransformData::CGUITransformData() :
33-
m_dirty(true),
33+
HasChanged(true),
34+
Parent(NULL),
3435
m_scale(1.0f, 1.0f, 1.0f)
3536
{
3637

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ namespace Skylicht
3333
friend class CGUILayoutSystem;
3434

3535
protected:
36-
core::rectf m_rect;
3736
core::vector3df m_transformPosition;
38-
bool m_dirty;
3937

4038
core::vector3df m_position;
4139
core::vector3df m_scale;
@@ -44,6 +42,12 @@ namespace Skylicht
4442
public:
4543
DECLARE_DATA_TYPE_INDEX;
4644

45+
bool HasChanged;
46+
47+
core::rectf Rect;
48+
49+
CGUITransformData* Parent;
50+
4751
public:
4852
CGUITransformData();
4953

@@ -57,7 +61,7 @@ namespace Skylicht
5761
inline void setPosition(const core::vector3df& v)
5862
{
5963
m_position = v;
60-
m_dirty = true;
64+
HasChanged = true;
6165
}
6266

6367
inline const core::vector3df& getScale()
@@ -68,7 +72,7 @@ namespace Skylicht
6872
inline void setScale(const core::vector3df& v)
6973
{
7074
m_scale = v;
71-
m_dirty = true;
75+
HasChanged = true;
7276
}
7377

7478
inline const core::vector3df& getRotation()
@@ -79,37 +83,27 @@ namespace Skylicht
7983
inline void setRotation(const core::vector3df& v)
8084
{
8185
m_rotation = v;
82-
m_dirty = true;
86+
HasChanged = true;
8387
}
8488

8589
inline float getHeight()
8690
{
87-
return m_rect.getHeight();
91+
return Rect.getHeight();
8892
}
8993

9094
inline float getWidth()
9195
{
92-
return m_rect.getWidth();
96+
return Rect.getWidth();
9397
}
9498

9599
inline const core::rectf& getRect()
96100
{
97-
return m_rect;
101+
return Rect;
98102
}
99103

100104
inline void setRect(const core::rectf& r)
101105
{
102-
m_rect = r;
103-
}
104-
105-
inline bool isChanged()
106-
{
107-
return m_dirty;
108-
}
109-
110-
inline void setChanged(bool b)
111-
{
112-
m_dirty = b;
106+
Rect = r;
113107
}
114108

115109
DECLARE_GETTYPENAME(CGUITransformData);

0 commit comments

Comments
 (0)