Skip to content

Commit

Permalink
#123 Add logic for CHierachyNode
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Apr 21, 2021
1 parent 29d12b5 commit 83893ab
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 8 deletions.
149 changes: 149 additions & 0 deletions Projects/Editor/Source/Editor/Space/Hierarchy/CHierachyNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
!@
MIT License
CopyRight (c) 2021 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRight HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CHierachyNode.h"

namespace Skylicht
{
namespace Editor
{
CHierachyNode::CHierachyNode(CHierachyNode* parent) :
m_icon(GUI::ESystemIcon::None),
m_tagData(NULL),
m_guiNode(NULL),
m_parent(parent)
{

}

CHierachyNode::~CHierachyNode()
{
removeAllChild();

if (m_guiNode)
m_guiNode->remove();
}

void CHierachyNode::setName(const wchar_t* name)
{
m_name = name;

if (m_guiNode != NULL)
m_guiNode->setText(name);
}

void CHierachyNode::setIcon(Editor::GUI::ESystemIcon icon)
{
m_icon = icon;

if (m_guiNode != NULL)
m_guiNode->setIcon(icon);
}

CHierachyNode* CHierachyNode::addChild()
{
CHierachyNode* child = new CHierachyNode(this);
m_childs.push_back(child);
return child;
}

bool CHierachyNode::removeChild(CHierachyNode* child)
{
std::vector<CHierachyNode*>::iterator i = m_childs.begin(), end = m_childs.end();
while (i != end)
{
if ((*i) == child)
{
m_childs.erase(i);
delete child;
return true;
}
++i;
}
return false;
}

void CHierachyNode::removeAllChild()
{
for (CHierachyNode* i : m_childs)
{
delete i;
}
m_childs.clear();
}

void CHierachyNode::bringNextNode(CHierachyNode* position, bool behind)
{
std::vector<CHierachyNode*>::iterator i = m_parent->m_childs.begin(), end = m_parent->m_childs.end();
std::vector<CHierachyNode*>::iterator p = end;
std::vector<CHierachyNode*>::iterator m = end;

while (i != end)
{
if ((*i) == this)
m = i;

if ((*i) == position)
p = i;

if (p != end && m != end)
break;
}

if (p != end && m != end)
{
m_parent->m_childs.erase(m);

if (!behind)
{
if (p == m_parent->m_childs.begin())
{
m_parent->m_childs.insert(m_parent->m_childs.begin(), this);
}
else
{
m_parent->m_childs.insert(++p, this);
}
}
else
{
m_parent->m_childs.insert(p, this);
}

if (m_guiNode)
m_guiNode->bringNextToControl(position->getGUINode(), behind);
}
}

void CHierachyNode::nullGUI()
{
m_guiNode = NULL;
for (CHierachyNode* i : m_childs)
{
i->nullGUI();
}
}
}
}
115 changes: 115 additions & 0 deletions Projects/Editor/Source/Editor/Space/Hierarchy/CHierachyNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
!@
MIT License
CopyRight (c) 2021 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRight HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

#include "GUI/GUI.h"

namespace Skylicht
{
namespace Editor
{
class CHierachyNode
{
protected:
std::wstring m_name;

std::string m_id;

void* m_tagData;

GUI::ESystemIcon m_icon;

CHierachyNode* m_parent;

std::vector<CHierachyNode*> m_childs;

GUI::CTreeNode* m_guiNode;

public:
CHierachyNode(CHierachyNode* parent);

virtual ~CHierachyNode();

inline void setID(const char* id)
{
m_id = id;
}

inline const std::string& getID()
{
return m_id;
}

inline CHierachyNode* getParent()
{
return m_parent;
}

inline void setTagData(void* data)
{
m_tagData = data;
}

inline void* getTagData()
{
return m_tagData;
}

inline void setGUINode(GUI::CTreeNode* node)
{
m_guiNode = node;
}

inline GUI::CTreeNode* getGUINode()
{
return m_guiNode;
}

void setName(const wchar_t* name);

void setIcon(GUI::ESystemIcon icon);

inline const std::wstring& getName()
{
return m_name;
}

inline const GUI::ESystemIcon getIcon()
{
return m_icon;
}

CHierachyNode* addChild();

bool removeChild(CHierachyNode* child);

void removeAllChild();

void bringNextNode(CHierachyNode* position, bool behind);

void nullGUI();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace Skylicht
{
namespace Editor
{
CHierarchyController::CHierarchyController(GUI::CCanvas* canvas, GUI::CTreeControl* tree)
CHierarchyController::CHierarchyController(GUI::CCanvas* canvas, GUI::CTreeControl* tree) :
m_canvas(canvas),
m_tree(tree)
{

}
Expand All @@ -38,5 +40,35 @@ namespace Skylicht
{

}

void CHierarchyController::setHierarchyNode(CHierachyNode* node)
{
bool build = false;

if (m_node != node)
{
m_node->nullGUI();
m_tree->removeAllTreeNode();

build = true;
}

m_node = node;

if (build)
buildHierarchyNode();
else
updateHierarchyNode();
}

void CHierarchyController::buildHierarchyNode()
{

}

void CHierarchyController::updateHierarchyNode()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This file is part of the "Skylicht Engine".
*/

#include "GUI/GUI.h"
#include "CHierachyNode.h"

namespace Skylicht
{
Expand All @@ -34,10 +35,20 @@ namespace Skylicht
GUI::CCanvas* m_canvas;
GUI::CTreeControl* m_tree;

CHierachyNode* m_node;

public:
CHierarchyController(GUI::CCanvas* canvas, GUI::CTreeControl* tree);

virtual ~CHierarchyController();

void setHierarchyNode(CHierachyNode* node);

void updateHierarchyNode();

protected:

void buildHierarchyNode();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,10 @@ namespace Skylicht
{

}

void CSpaceHierarchy::clear()
{
m_tree->removeAllTreeNode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace Skylicht
virtual ~CSpaceHierarchy();

virtual void update();

void clear();
};
}
}
7 changes: 6 additions & 1 deletion Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ namespace Skylicht
if (m_renderRP != NULL)
delete m_renderRP;

CSceneController::getInstance()->setSpaceScene(NULL);
CSceneController* sceneController = CSceneController::getInstance();
sceneController->setScene(NULL);
sceneController->setSpaceScene(NULL);
}

void CSpaceScene::initDefaultScene()
Expand Down Expand Up @@ -106,6 +108,9 @@ namespace Skylicht

core::vector3df direction = core::vector3df(0.0f, -1.5f, 2.0f);
lightTransform->setOrientation(direction, CTransform::s_oy);

// set scene to controller
CSceneController::getInstance()->setScene(m_scene);
}

void CSpaceScene::onResize(float w, float h)
Expand Down
Loading

0 comments on commit 83893ab

Please sign in to comment.