Index: trunk/src/lib/graphics/render2D/element_2d.cc
===================================================================
--- trunk/src/lib/graphics/render2D/element_2d.cc	(revision 7331)
+++ trunk/src/lib/graphics/render2D/element_2d.cc	(revision 7332)
@@ -29,6 +29,6 @@
 #include "color.h"
 
-//#include "shell_command.h"
-//SHELL_COMMAND(debug, Element2D, debug2D);
+#include "shell_command.h"
+SHELL_COMMAND(debug, Element2D, debug2DSC);
 
 using namespace std;
@@ -99,5 +99,5 @@
       deleteNode = tmp;
       tmp++;
-//      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
+      //      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
       if ((this->parentMode & E2D_PROHIBIT_CHILD_DELETE) ||
           ((*deleteNode)->parentMode & E2D_PROHIBIT_DELETE_WITH_PARENT))
@@ -139,34 +139,34 @@
   // ELEMENT2D-native settings.
   LoadParam(root, "alignment", this, Element2D, setAlignment)
-      .describe("loads the alignment: (either: center, left, right or screen-center)");
+  .describe("loads the alignment: (either: center, left, right or screen-center)");
 
   LoadParam(root, "layer", this, Element2D, setLayer)
-      .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)");
+  .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)");
 
   LoadParam(root, "bind-node", this, Element2D, setBindNode)
-      .describe("sets a node, this 2D-Element should be shown upon (name of the node)");
+  .describe("sets a node, this 2D-Element should be shown upon (name of the node)");
 
   LoadParam(root, "visibility", this, Element2D, setVisibility)
-      .describe("if the Element is visible or not");
-
-
-// PNode-style:
+  .describe("if the Element is visible or not");
+
+
+  // PNode-style:
   LoadParam(root, "rel-coor-2d", this, Element2D, setRelCoor2D)
-      .describe("Sets The relative position of the Node to its parent.");
+  .describe("Sets The relative position of the Node to its parent.");
 
   LoadParam(root, "abs-coor-2d", this, Element2D, setAbsCoor2D)
-      .describe("Sets The absolute Position of the Node.");
+  .describe("Sets The absolute Position of the Node.");
 
   LoadParam(root, "rel-dir-2d", this, Element2D, setRelDir2D)
-      .describe("Sets The relative rotation of the Node to its parent.");
+  .describe("Sets The relative rotation of the Node to its parent.");
 
   LoadParam(root, "abs-dir-2d", this, Element2D, setAbsDir2D)
-      .describe("Sets The absolute rotation of the Node.");
+  .describe("Sets The absolute rotation of the Node.");
 
   LoadParam(root, "parent", this, Element2D, setParent2D)
-      .describe("the Name of the Parent of this Element2D");
+  .describe("the Name of the Parent of this Element2D");
 
   LoadParam(root, "parent-mode", this, Element2D, setParentMode2D)
-      .describe("the mode to connect this node to its parent ()");
+  .describe("the mode to connect this node to its parent ()");
 
   // cycling properties
@@ -174,5 +174,5 @@
   {
     LoadParam_CYCLE(element, "child", this, Element2D, addChild2D)
-        .describe("adds a new Child to the current Node.");
+    .describe("adds a new Child to the current Node.");
   }
   LOAD_PARAM_END_CYCLE(element);
@@ -282,5 +282,5 @@
 {
   this->setRelCoor2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
-                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
+                              (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
 }
 
@@ -308,5 +308,5 @@
 {
   this->setRelCoorSoft2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
-                         (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()),
+                                  (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()),
                          bias);
 }
@@ -373,5 +373,5 @@
 {
   this->setAbsCoor2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
-                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
+                              (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
 }
 
@@ -436,5 +436,5 @@
 {
   this->shiftCoor2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
-                    (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
+                             (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
 }
 
@@ -533,35 +533,40 @@
   if (this->checkIntegrity(child))
   {
+    // Setting the New Parent.
     child->parent = this;
     if (likely(this != NULL))
     {
-     // ELEMENT SORTING TO LAYERS  //
-     unsigned int childCount = this->children.size();
-
-     list<Element2D*>::iterator elem;
-     for (elem = this->children.begin(); elem != this->children.end(); elem++)
-     {
-       if ((*elem)->layer < child->layer)
-       {
-         this->children.insert(elem, child);
-         break;
-       }
-     }
-     if (childCount == this->children.size())
-       this->children.push_back(child);
-     ////////////////////////////////
-     if (unlikely(this->layer > child->getLayer()))
-     {
-       PRINTF(2)("Layer '%s' of Child(%s) lower than parents(%s) layer '%s'. updating...\n",
-       Element2D::layer2DToChar(child->getLayer()),child->getName(), this->getName(), Element2D::layer2DToChar(this->layer));
-       child->setLayer(this->layer);
-     }
-   }
-   else
-   {
-     PRINTF(1)("Tried to reparent2D to own child '%s::%s' to '%s::%s'.\n",
-              this->getClassName(), this->getName(), child->getClassName(), child->getName());
-     child->parent = NULL;
-   }
+      // Layers of Children that are smaller than this(parents) Layer will be updated, and pushed to the front.
+      if (unlikely(this->layer > child->getLayer()))
+      {
+        PRINTF(2)("Layer '%s' of Child(%s::%s) lower than parents(%s::%s) layer '%s'. updating...\n",
+                  Element2D::layer2DToChar(child->getLayer()),child->getClassName(), child->getName(),
+                  this->getClassName(), this->getName(), Element2D::layer2DToChar(this->layer));
+        child->layer = this->layer;
+        this->children.push_front(child);
+      }
+      else
+      {
+        // Inserting the Element at the right Layer depth.
+        list<Element2D*>::iterator elem;
+        for (elem = this->children.begin(); elem != this->children.end(); elem++)
+        {
+          if ((*elem)->layer <= child->layer)
+          {
+            this->children.insert(elem, child);
+            break;
+          }
+        }
+        // if we are at the Last child push it back.
+        if (elem == this->children.end())
+          this->children.push_back(child);
+      }
+    }
+    else
+    {
+      PRINTF(1)("Tried to reparent2D to own child '%s::%s' to '%s::%s'.\n",
+                this->getClassName(), this->getName(), child->getClassName(), child->getName());
+      child->parent = NULL;
+    }
   }
   child->parentCoorChanged2D();
@@ -658,5 +663,5 @@
   else
     PRINTF(2)("Not Found Element2D's (%s::%s) new Parent by Name: %s\n",
-                this->getClassName(), this->getName(), parentName.c_str());
+              this->getClassName(), this->getName(), parentName.c_str());
 }
 
@@ -787,5 +792,5 @@
   if( likely(this->parent != NULL))
   {
-      // movement for nodes with smoothMove enabled
+    // movement for nodes with smoothMove enabled
     if (unlikely(this->toCoordinate != NULL))
     {
@@ -865,10 +870,10 @@
                  projectPos+1,
                  projectPos+2);
-//       printf("%s::%s  == %f %f %f :: %f %f\n", this->getClassName(), this->getName(),
-//              this->bindNode->getAbsCoor().x,
-//              this->bindNode->getAbsCoor().y,
-//              this->bindNode->getAbsCoor().z,
-//              projectPos[0],
-//              projectPos[1]);
+      //       printf("%s::%s  == %f %f %f :: %f %f\n", this->getClassName(), this->getName(),
+      //              this->bindNode->getAbsCoor().x,
+      //              this->bindNode->getAbsCoor().y,
+      //              this->bindNode->getAbsCoor().z,
+      //              projectPos[0],
+      //              projectPos[1]);
 
       this->prevRelCoordinate.x = this->absCoordinate.x = projectPos[0] /* /(float)GraphicsEngine::getInstance()->getResolutionX() */ + this->relCoordinate.x;
@@ -890,6 +895,6 @@
         float sine = sin(this->parent->getAbsDir2D());
         float cose = cos(this->parent->getAbsDir2D());
-//        this->absCoordinate.x = this->relCoordinate.x*cose - this->relCoordinate.y*sine + this->parent->getRelCoor2D().x*(1-cose) +this->parent->getRelCoor2D().y*sine;
-//        this->absCoordinate.y = this->relCoordinate.x*sine + this->relCoordinate.y*cose + this->parent->getRelCoor2D().y*(1-cose) +this->parent->getRelCoor2D().x*sine;
+        //        this->absCoordinate.x = this->relCoordinate.x*cose - this->relCoordinate.y*sine + this->parent->getRelCoor2D().x*(1-cose) +this->parent->getRelCoor2D().y*sine;
+        //        this->absCoordinate.y = this->relCoordinate.x*sine + this->relCoordinate.y*cose + this->parent->getRelCoor2D().y*(1-cose) +this->parent->getRelCoor2D().x*sine;
 
         this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D()));
@@ -953,14 +958,14 @@
   else
     PRINT(0)(" -");
-  PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s, layer:%s\n",
-            this->getClassName(),
-            this->getName(),
-            this->absCoordinate.x,
-            this->absCoordinate.y,
-            this->relCoordinate.x,
-            this->relCoordinate.y,
-            this->getAbsDir2D(),
-            Element2D::parentingModeToString2D(parentMode),
-            Element2D::layer2DToChar(this->layer));
+  PRINT(0)("E2D(%s::%s);AC:(%0.2f, %0.2f);RC:(%0.2f, %0.2f);AD(%0.2f)->%s;Layer:(%s)\n",
+           this->getClassName(),
+           this->getName(),
+           this->absCoordinate.x,
+           this->absCoordinate.y,
+           this->relCoordinate.x,
+           this->relCoordinate.y,
+           this->getAbsDir2D(),
+           Element2D::parentingModeToString2D(parentMode),
+           Element2D::layer2DToChar(this->layer));
 
   if (depth >= 2 || depth == 0)
Index: trunk/src/lib/graphics/render2D/element_2d.h
===================================================================
--- trunk/src/lib/graphics/render2D/element_2d.h	(revision 7331)
+++ trunk/src/lib/graphics/render2D/element_2d.h	(revision 7332)
@@ -210,4 +210,5 @@
 
     void debug2D (unsigned int depth = 1, unsigned int level = 0) const;
+    void debug2DSC (unsigned int depth = 1, unsigned int level = 0) { this->debug2D(depth, level); }; // Wrapping Function for ShellCommand.
     void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,0,0), unsigned int level = 0) const;
 
