Skip to content

Commit 543f797

Browse files
committed
#158 Update GUI Editor (create element, fix align function on LayoutSystem)
1 parent 4e3b588 commit 543f797

25 files changed

+463
-23
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ namespace Skylicht
6262

6363
void CGUIEditor::showEditorRect(bool b)
6464
{
65-
m_guiData->getProperty("rectX1")->setHidden(!b);
66-
m_guiData->getProperty("rectY1")->setHidden(!b);
67-
m_guiData->getProperty("rectX2")->setHidden(!b);
68-
m_guiData->getProperty("rectY2")->setHidden(!b);
65+
m_guiData->getProperty("rectX")->setHidden(!b);
66+
m_guiData->getProperty("rectY")->setHidden(!b);
67+
m_guiData->getProperty("rectW")->setHidden(!b);
68+
m_guiData->getProperty("rectH")->setHidden(!b);
6969
}
7070

7171
void CGUIEditor::showEditorTransform(bool b)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
!@
3+
MIT License
4+
5+
Copyright (c) 2021 Skylicht Technology CO., LTD
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8+
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
9+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
20+
This file is part of the "Skylicht Engine".
21+
https://github.com/skylicht-lab/skylicht-engine
22+
!#
23+
*/
24+
25+
#include "pch.h"
26+
#include "CGUIHierachyContextMenu.h"
27+
#include "Editor/SpaceController/CGUIDesignController.h"
28+
29+
namespace Skylicht
30+
{
31+
namespace Editor
32+
{
33+
CGUIHierachyContextMenu::CGUIHierachyContextMenu(GUI::CTreeControl* tree)
34+
{
35+
tree->OnItemContextMenu = BIND_LISTENER(&CGUIHierachyContextMenu::OnTreeContextMenu, this);
36+
}
37+
38+
CGUIHierachyContextMenu::~CGUIHierachyContextMenu()
39+
{
40+
41+
}
42+
43+
void CGUIHierachyContextMenu::OnTreeContextMenu(GUI::CBase* row)
44+
{
45+
GUI::CTreeRowItem* rowItem = dynamic_cast<GUI::CTreeRowItem*>(row);
46+
if (rowItem != NULL)
47+
{
48+
CGUIHierachyNode* node = (CGUIHierachyNode*)rowItem->getNode()->getTagData();
49+
if (node != NULL)
50+
{
51+
CGUIDesignController::getInstance()->onContextMenu(node);
52+
}
53+
}
54+
}
55+
}
56+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
!@
3+
MIT License
4+
5+
Copyright (c) 2021 Skylicht Technology CO., LTD
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8+
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
9+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
20+
This file is part of the "Skylicht Engine".
21+
https://github.com/skylicht-lab/skylicht-engine
22+
!#
23+
*/
24+
25+
#pragma once
26+
27+
#include "SkylichtEngine.h"
28+
29+
#include "Editor/Space/CSpace.h"
30+
#include "CGUIHierarchyController.h"
31+
32+
namespace Skylicht
33+
{
34+
namespace Editor
35+
{
36+
class CGUIHierachyContextMenu
37+
{
38+
public:
39+
CGUIHierachyContextMenu(GUI::CTreeControl* tree);
40+
41+
virtual ~CGUIHierachyContextMenu();
42+
43+
public:
44+
45+
void OnTreeContextMenu(GUI::CBase* row);
46+
};
47+
}
48+
}

Projects/Editor/Source/Editor/Space/GUIHierarchy/CSpaceGUIHierarchy.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace Skylicht
7070
m_tree->setMultiSelected(true);
7171

7272
m_hierarchyController = new CGUIHierarchyController(window->getCanvas(), m_tree, m_editor);
73+
m_hierarchyContextMenu = new CGUIHierachyContextMenu(m_tree);
7374

7475
CGUIDesignController::getInstance()->setSpaceHierarchy(this);
7576
CGUIDesignController::getInstance()->rebuildGUIHierachy();
@@ -82,6 +83,7 @@ namespace Skylicht
8283
controller->setSpaceHierarchy(NULL);
8384

8485
delete m_hierarchyController;
86+
delete m_hierarchyContextMenu;
8587
}
8688

8789
void CSpaceGUIHierarchy::update()
@@ -101,6 +103,7 @@ namespace Skylicht
101103

102104
void CSpaceGUIHierarchy::addToTreeNode(CGUIHierachyNode* node)
103105
{
106+
m_hierarchyController->addToTreeNode(node);
104107
}
105108

106109
void CSpaceGUIHierarchy::rename(CGUIHierachyNode* node)

Projects/Editor/Source/Editor/Space/GUIHierarchy/CSpaceGUIHierarchy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This file is part of the "Skylicht Engine".
2929

3030
#include "CGUIHierachyNode.h"
3131
#include "CGUIHierarchyController.h"
32+
#include "CGUIHierachyContextMenu.h"
3233

3334
namespace Skylicht
3435
{
@@ -45,7 +46,7 @@ namespace Skylicht
4546
GUI::CTreeControl* m_tree;
4647

4748
CGUIHierarchyController* m_hierarchyController;
48-
49+
CGUIHierachyContextMenu* m_hierarchyContextMenu;
4950
public:
5051
CSpaceGUIHierarchy(GUI::CWindow* window, CEditor* editor);
5152

Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ namespace Skylicht
350350
guiCanvas->setEditorObject(true);
351351

352352
CCanvas* canvas = guiCanvas->addComponent<CCanvas>();
353+
canvas->IsInEditor = true;
354+
353355
CGUIRect* rect = canvas->createRect(SColor(255, 0, 0, 0));
354356
rect->setDock(EGUIDock::DockFill);
355357
rect->setName("Canvas");
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
!@
3+
MIT License
4+
5+
Copyright (c) 2021 Skylicht Technology CO., LTD
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8+
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
9+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
20+
This file is part of the "Skylicht Engine".
21+
https://github.com/skylicht-lab/skylicht-engine
22+
!#
23+
*/
24+
25+
#include "pch.h"
26+
#include "CContextMenuGUIElement.h"
27+
#include "CGUIDesignController.h"
28+
#include "Selection/CSelection.h"
29+
#include "Editor/SpaceController/CPropertyController.h"
30+
#include "GUI/Input/CInput.h"
31+
#include "Entity/CEntityHandleData.h"
32+
33+
namespace Skylicht
34+
{
35+
namespace Editor
36+
{
37+
CContextMenuGUIElement::CContextMenuGUIElement(GUI::CCanvas* canvas) :
38+
m_canvas(canvas),
39+
m_spaceHierarchy(NULL),
40+
m_contextNode(NULL)
41+
{
42+
m_contextMenu = new GUI::CMenu(canvas);
43+
m_contextMenu->setHidden(true);
44+
m_contextMenu->OnCommand = BIND_LISTENER(&CContextMenuGUIElement::OnContextMenuCommand, this);
45+
46+
m_contextMenu->addItem(L"Rename", L"F2");
47+
m_contextMenu->addSeparator();
48+
m_contextMenu->addItem(L"Copy", GUI::ESystemIcon::Copy, L"Ctrl + C");
49+
m_contextMenu->addItem(L"Paste", GUI::ESystemIcon::Paste, L"Ctrl + V");
50+
m_contextMenu->addItem(L"Duplicate", GUI::ESystemIcon::Duplicate, L"Ctrl + D");
51+
m_contextMenu->addItem(L"Cut", L"Ctrl + X");
52+
m_contextMenu->addSeparator();
53+
m_contextMenu->addItem(L"Delete", GUI::ESystemIcon::Trash);
54+
m_contextMenu->addSeparator();
55+
56+
GUI::CMenu* addMenu = m_contextMenu->addItem(L"Add")->getMenu();
57+
addMenu->addItem(L"GUI Element");
58+
addMenu->addItem(L"GUI Rect");
59+
addMenu->addItem(L"GUI Image");
60+
addMenu->addItem(L"GUI Text");
61+
addMenu->addItem(L"GUI Mask");
62+
addMenu->OnCommand = BIND_LISTENER(&CContextMenuGUIElement::OnContextMenuAddCommand, this);
63+
}
64+
65+
CContextMenuGUIElement::~CContextMenuGUIElement()
66+
{
67+
68+
}
69+
70+
bool CContextMenuGUIElement::onContextMenu(CSpaceGUIHierarchy* spaceHierachy, CGUIHierachyNode* node)
71+
{
72+
GUI::CInput* input = GUI::CInput::getInput();
73+
GUI::SPoint mousePos = input->getMousePosition();
74+
75+
m_contextNode = node;
76+
m_spaceHierarchy = spaceHierachy;
77+
78+
m_canvas->closeMenu();
79+
m_contextMenu->open(mousePos);
80+
return true;
81+
}
82+
83+
void CContextMenuGUIElement::OnContextMenuCommand(GUI::CBase* sender)
84+
{
85+
GUI::CMenuItem* menuItem = dynamic_cast<GUI::CMenuItem*>(sender);
86+
if (menuItem == NULL || m_contextNode == NULL)
87+
return;
88+
89+
CGUIElement* node = (CGUIElement*)m_contextNode->getTagData();
90+
91+
const std::wstring& command = menuItem->getLabel();
92+
}
93+
94+
void CContextMenuGUIElement::OnContextMenuAddCommand(GUI::CBase* sender)
95+
{
96+
GUI::CMenuItem* menuItem = dynamic_cast<GUI::CMenuItem*>(sender);
97+
if (menuItem == NULL || m_contextNode == NULL)
98+
return;
99+
100+
const std::wstring& command = menuItem->getLabel();
101+
CGUIDesignController::getInstance()->createGUINode(m_contextNode, command);
102+
}
103+
}
104+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
!@
3+
MIT License
4+
5+
Copyright (c) 2021 Skylicht Technology CO., LTD
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8+
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
9+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
20+
This file is part of the "Skylicht Engine".
21+
https://github.com/skylicht-lab/skylicht-engine
22+
!#
23+
*/
24+
25+
#pragma once
26+
27+
#include "SkylichtEngine.h"
28+
29+
#include "Scene/CScene.h"
30+
#include "GameObject/CZone.h"
31+
32+
#include "Editor/Space/CSpace.h"
33+
#include "Editor/Space/GUIHierarchy/CGUIHierachyNode.h"
34+
#include "Editor/Space/GUIHierarchy/CSpaceGUIHierarchy.h"
35+
36+
namespace Skylicht
37+
{
38+
namespace Editor
39+
{
40+
class CContextMenuGUIElement
41+
{
42+
protected:
43+
GUI::CCanvas* m_canvas;
44+
45+
CSpaceGUIHierarchy* m_spaceHierarchy;
46+
CGUIHierachyNode* m_contextNode;
47+
48+
GUI::CMenu* m_contextMenu;
49+
50+
public:
51+
CContextMenuGUIElement(GUI::CCanvas* canvas);
52+
53+
~CContextMenuGUIElement();
54+
55+
bool onContextMenu(CSpaceGUIHierarchy* spaceHierachy, CGUIHierachyNode* node);
56+
57+
protected:
58+
59+
void OnContextMenuCommand(GUI::CBase* sender);
60+
61+
void OnContextMenuAddCommand(GUI::CBase* sender);
62+
};
63+
}
64+
}

0 commit comments

Comments
 (0)