diff --git a/src/scene/containernode.cpp b/src/scene/containernode.cpp index bae9db0..e2c90c3 100644 --- a/src/scene/containernode.cpp +++ b/src/scene/containernode.cpp @@ -26,7 +26,7 @@ void ContainerNode::removeChild(SceneNode* node) if(*it == node) { m_children.erase(it); - break; +// break; } } } diff --git a/src/scene/containernode.h b/src/scene/containernode.h index f3a0259..8d982a6 100644 --- a/src/scene/containernode.h +++ b/src/scene/containernode.h @@ -21,7 +21,7 @@ public: */ void removeChild(SceneNode* node); /** - * @brief addedToSceneTree is called when this node is added to a SceneTree + * @brief setSceneTree is called when this node is added to a SceneTree * * @param tree */ diff --git a/src/scene/graphicalcontainernode.cpp b/src/scene/graphicalcontainernode.cpp index fda6302..8173ddf 100644 --- a/src/scene/graphicalcontainernode.cpp +++ b/src/scene/graphicalcontainernode.cpp @@ -4,3 +4,28 @@ GraphicalContainerNode::GraphicalContainerNode() { } + +void GraphicalContainerNode::addChild(GraphicalNode *node) +{ + if(node != nullptr) + { + node->setSceneTree(m_scene); + m_children.push_back(node); + node->m_parent = this; + } +} + +void GraphicalContainerNode::removeChild(GraphicalNode *node) +{ + if(node != nullptr) + { + for(auto it = m_children.begin(); it != m_children.end(); ++it) + { + if(*it == node) + { + m_children.erase(it); + } + } + } + +} diff --git a/src/scene/graphicalcontainernode.h b/src/scene/graphicalcontainernode.h index ada5315..de79ab1 100644 --- a/src/scene/graphicalcontainernode.h +++ b/src/scene/graphicalcontainernode.h @@ -11,6 +11,8 @@ protected: std::vector m_children; public: GraphicalContainerNode(); + void addChild(GraphicalNode* node); + void removeChild(GraphicalNode* node); }; #endif // GRAPHICALCONTAINERNODE_H diff --git a/src/scene/graphicalnode.cpp b/src/scene/graphicalnode.cpp index 6e5f4b1..78c0c97 100644 --- a/src/scene/graphicalnode.cpp +++ b/src/scene/graphicalnode.cpp @@ -1,7 +1,7 @@ #include "graphicalnode.h" #include "scenetree.h" -GraphicalNode::GraphicalNode() +GraphicalNode::GraphicalNode() : m_visible(true) { } diff --git a/src/scene/lightnode.h b/src/scene/lightnode.h index f03379d..5461a8b 100644 --- a/src/scene/lightnode.h +++ b/src/scene/lightnode.h @@ -9,7 +9,7 @@ class LightNode : public GraphicalNode { Light *m_light; public: - LightNode(Light* light) : m_light(light) {GraphicalNode::m_visible = true;} + LightNode(Light* light) : m_light(light) {} virtual void update() { diff --git a/src/scene/meshnode.h b/src/scene/meshnode.h index 7708063..13e8756 100644 --- a/src/scene/meshnode.h +++ b/src/scene/meshnode.h @@ -18,7 +18,7 @@ public: glm::mat4 m_movement; glm::mat4 m_acceleration; - MeshNode(Mesh* mesh) : m_geometry(mesh, glm::mat4()) {GraphicalNode::m_visible = true;} + MeshNode(Mesh* mesh) : m_geometry(mesh, glm::mat4()) {} virtual void update() { diff --git a/src/sparrowshell/sparrowshell.h b/src/sparrowshell/sparrowshell.h index 26b763a..1edd6b3 100644 --- a/src/sparrowshell/sparrowshell.h +++ b/src/sparrowshell/sparrowshell.h @@ -8,6 +8,7 @@ #include "glm/vec2.hpp" #include "sparrowshell/shellbuffer.h" #include "sparrowshell/shellscrollbar.h" +#include "scene/graphicalcontainernode.h" class Input; class MeshNode; @@ -18,7 +19,7 @@ namespace sf { class Window; } -class SparrowShell : public ContainerNode +class SparrowShell : public GraphicalContainerNode { private: sf::Window* m_window; @@ -52,8 +53,8 @@ public: void out(std::string); void setSceneTree(SceneTree* tree) { - ContainerNode::setSceneTree(tree); -// m_buffer->setSceneTree(tree); + GraphicalContainerNode::setSceneTree(tree); + m_buffer->setSceneTree(tree); } glm::ivec2 getPosition(){return m_position;}