Browse Source

refactoring Actor
replaced insertChildAfter and insertChildBefore with insertSiblingAfter/insertSiblingBefore

dmuratshin 9 years ago
parent
commit
fefa2a1d88
2 changed files with 40 additions and 8 deletions
  1. 32 5
      oxygine/src/Actor.cpp
  2. 8 3
      oxygine/src/Actor.h

+ 32 - 5
oxygine/src/Actor.cpp

@@ -762,9 +762,9 @@ namespace oxygine
         return false;
     }
 
-    bool Actor::isDescendant(spActor actor)
+    bool Actor::isDescendant(const spActor& actor) const
     {
-        Actor* act = actor.get();
+        const Actor* act = actor.get();
         while (act)
         {
             if (act == this)
@@ -878,6 +878,30 @@ namespace oxygine
         setParent(actor.get(), this);
     }
 
+    void Actor::insertSiblingBefore(spActor actor)
+    {
+        OX_ASSERT(actor != this);
+        OX_ASSERT(actor);
+        OX_ASSERT(_parent);
+        if (!_parent)
+            return;
+        actor->detach();
+        _parent->_children.insert_before(actor, spActor(this));
+        setParent(actor.get(), _parent);
+    }
+
+    void Actor::insertSiblingAfter(spActor actor)
+    {
+        OX_ASSERT(actor != this);
+        OX_ASSERT(actor);
+        OX_ASSERT(_parent);
+        if (!_parent)
+            return;
+        actor->detach();
+        _parent->_children.insert_after(actor, spActor(this));
+        setParent(actor.get(), _parent);
+    }
+
     void Actor::attachTo(spActor parent)
     {
         OX_ASSERT(parent != this);
@@ -921,9 +945,12 @@ namespace oxygine
 
 
         if (sibling)
-            insertChildAfter(actor, sibling);
+            sibling->insertSiblingAfter(actor);
         else
-            insertChildBefore(actor, 0);
+        {
+            _children.append(spActor(actor));
+            setParent(actor, this);
+        }
     }
 
     void Actor::prependChild(spActor actor)
@@ -934,7 +961,7 @@ namespace oxygine
     void Actor::prependChild(Actor* actor)
     {
         if (getFirstChild())
-            insertChildBefore(actor, getFirstChild());
+            getFirstChild()->insertSiblingBefore(actor);
         else
             addChild(actor);
     }

+ 8 - 3
oxygine/src/Actor.h

@@ -223,12 +223,17 @@ namespace oxygine
 
         virtual bool isOn(const Vector2& localPosition);
         /**Returns true if actor is child or located deeper in current subtree*/
-        bool isDescendant(spActor actor);
+        bool isDescendant(const spActor& actor) const;
 
-        /**Inserts the specified actor before "where" actor as a child*/
+        /**DEPRECATED, use insertSiblingBefore Inserts the specified actor before "where" actor as a child*/
+        OXYGINE_DEPRECATED
         void insertChildBefore(spActor actor, spActor where);
-        /**Inserts the specified actor after "where" actor as a child*/
+        /**DEPRECATED, use insertSiblingAfter Inserts the specified actor after "where" actor as a child*/
+        OXYGINE_DEPRECATED
         void insertChildAfter(spActor actor, spActor where);
+
+        void insertSiblingBefore(spActor);
+        void insertSiblingAfter(spActor);
         void prependChild(spActor actor);
         void prependChild(Actor* actor);
         void addChild(spActor actor);