Index: trunk/src/lib/graphics/render2D/element_2d.h
===================================================================
--- trunk/src/lib/graphics/render2D/element_2d.h	(revision 6142)
+++ trunk/src/lib/graphics/render2D/element_2d.h	(revision 6299)
@@ -1,5 +1,5 @@
 /*!
  * @file element_2d.h
- * Definition of the 2D elements rendered on top through the GraphicsEngine
+ * Definition of the 2D elements rendered on top of all other stuff.
  */
 
@@ -40,22 +40,38 @@
 typedef enum
 {
-  E2D_PARENT_NONE               =   0,
-  E2D_PARENT_LOCAL_ROTATE       =   1,    //!< Rotates all the children around their centers.
-  E2D_PARENT_ROTATE_MOVEMENT    =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
-
-  E2D_PARENT_MOVEMENT           =   4,    //!< Moves all children along with the parent.
+  E2D_PARENT_NONE                    = 0x0000,
+  E2D_PARENT_LOCAL_ROTATE            = 0x0001,    //!< Rotates all the children around their centers.
+  E2D_PARENT_ROTATE_MOVEMENT         = 0x0002,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
+
+  E2D_PARENT_MOVEMENT                = 0x0004,    //!< Moves all children along with the parent.
 // special linkage modes
-  E2D_PARENT_ALL                =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
-  E2D_PARENT_ROTATE_AND_MOVE    =   5     //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.
+  E2D_PARENT_ALL                     = 0x0003,    //!< Moves all children around the center of their parent, and also rotates their centers
+  E2D_PARENT_ROTATE_AND_MOVE         = 0x0005,    //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.
+
+
+  // REPARENTING
+  E2D_REPARENT_TO_NULL               = 0x0010,    //!< Reparents to the Null, if the Parent is Removed. Meaning the Node wont have a parent anymore.
+  E2D_REPARENT_TO_PARENTS_PARENT     = 0x0020,    //!< Reparents the Node to the parents (old) parent it the parent gets removed.
+  /////////////////////////////////////////////   //  ELSE: Reparents to the NullParent.
+  E2D_REPARENT_DELETE_CHILDREN       = 0x0040,    //!< Deletes the Children of the node when This Node is Removed. (Use with care).
+  /// FIXME
+   E2D_REPARENT_KEEP_POSITION         = 0x0080,   //!< Tries to keep the Position if the Node is reparented.
+
+
+  // DELETION
+  E2D_PROHIBIT_CHILD_DELETE          = 0x0100,    //!< Prohibits the Children from being deleted if this Node gets deleted.
+  E2D_PROHIBIT_DELETE_WITH_PARENT    = 0x0200,    //!< Prohibits the Node to be deleted if the Parent is. Child will be reparented according to the Repaenting-Rules
+  E2D_REPARENT_CHILDREN_ON_REMOVE    = 0x0400,    //!< Reparents the Children of the Node if the Node gets Removed.
+  E2D_REPARENT_ON_PARENTS_REMOVE     = 0x0800,    //!< The Node gets Reparented if its Parent gets removed. Child will be reparented according to the Reparenting-Rules.
+
+  // VISIBILITY/ACTIVITY
+  E2D_HIDE_CHILDREN_IF_HIDDEN        = 0x1000,    //!< Prohibits the Children from being drawn if this node isn't visible. (used for Draw))
+  E2D_HIDE_IF_PARENT_HIDDEN          = 0x2000,    //!< Prohibits the node from being drawn if the Parent is invisible.
+  E2D_UPDATE_CHILDREN_IF_INACTIVE    = 0x4000,    //!< Updates the Children of this Node even if the Parent is Inactive (note if this's parent is inactive children won't be updated.)
+  E2D_STATIC_NODE                    = 0x8000,    //!< Used for nodes that do not have any moving children, and that do not move.
+
 } E2D_PARENT_MODE;
-#define     E2D_DEFAULT_PARENTING_MODE  E2D_PARENT_ALL
-
-//! A Struct defining the Position of an Element in 2D-space
-struct Position2D
-{
-  float       x;                 //!< The x-coordinate.
-  float       y;                 //!< The y-coordinate.
-  float       depth;             //!< The distance from the viewing plane.
-};
+#define     E2D_PARENT_MODE_DEFAULT     E2D_PARENT_ALL | \
+					E2D_REPARENT_KEEP_POSITION
 
 //! A class for 2D-elements
@@ -72,11 +88,15 @@
 
   public:
-    Element2D();
-    Element2D(Element2D* parent, E2D_LAYER layer = E2D_DEFAULT_LAYER);
+    Element2D(Element2D* parent = Element2D::getNullElement(), E2D_LAYER layer = E2D_DEFAULT_LAYER, short nodeFlags = E2D_PARENT_MODE_DEFAULT);
     virtual ~Element2D();
 
-    void init();
     void loadParams(const TiXmlElement* root);
 
+    // ACTIVATION //
+    inline void activate2D() { this->bActive = this->bRelCoorChanged = this->bRelDirChanged = true; };
+    inline void deactivate2D() { this->bActive = false; };
+    inline bool get2DActiveState() { return this->bActive; };
+
+    // ALIGNMENT //
     /** @param alignment the new Alignment of the 2D-Element */
     inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
@@ -84,4 +104,5 @@
     inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
 
+    // LAYERING //
     void setLayer(E2D_LAYER layer);
     void setLayer(const char* layer);
@@ -89,20 +110,16 @@
     inline E2D_LAYER getLayer() const { return this->layer; };
 
+    // VISIBILITY //
     /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
-    inline void setVisibility(bool visible) { this->visible = visible; };
-    /** @param active true if the Element should be active, false otherwise (will not be ticked) */
-    inline void setActiveness(bool active) { this->active = active; };
-
-
+    inline void setVisibility(bool visible) { this->bVisible = visible; };
+    /** @returns the visibility state */
+    inline bool isVisible() { return this->bVisible; };
+
+
+    // POSITIONAL (E2D-specials) //
     /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
     inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
     void setBindNode(const char* bindNode);
     inline const PNode* getBindNode() const { return this->bindNode; };
-
-    /** @returns the visibility state */
-    inline bool isVisible() { return this->visible; };
-    /** @returns the active-State */
-    inline bool isActive() { return this->active; };
-
 
     inline void setSize2D(float x, float y) { this->sizeX = x, this->sizeY = y; };
@@ -114,5 +131,5 @@
   public:
     virtual void tick(float dt) {};
-    virtual void draw() const = 0;
+    virtual void draw() const  {};
     void tick2D(float dt);
     void draw2D(short layer) const;
@@ -166,5 +183,6 @@
     void remove2D();
 
-    void setParent2D (Element2D* parent);
+    /** @param parent the new parent of this Element2D */
+    void setParent2D (Element2D* parent) { parent->addChild2D(this); };
     void setParent2D (const char* parentName);
     /** @returns the parent of this Element2D */
@@ -176,10 +194,14 @@
     void setParentSoft2D(const char* parentName, float bias = 1.0);
 
-    /** @param parentMode sets the parentingMode of this Node */
-    void setParentMode2D (E2D_PARENT_MODE parentMode) { this->parentMode = parentMode; };
+    void setParentMode2D (E2D_PARENT_MODE parentMode);
     void setParentMode2D (const char* parentingMode);
     /** @returns the Parenting mode of this node */
     int getParentMode2D() const { return this->parentMode; };
 
+    // NULL_PARENT //
+    /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */
+    static Element2D* getNullElement()  { return (Element2D::nullElement != NULL)? Element2D::nullElement : Element2D::createNullElement(); };
+
+
     void update2D (float dt);
 
@@ -195,12 +217,15 @@
 
   private:
-    void eraseChild(Element2D* child);
+    void eraseChild2D(Element2D* child);
     /** tells the child that the parent's Coordinate has changed */
-    inline void parentCoorChanged () { this->bRelCoorChanged = true; }
+    inline void parentCoorChanged2D () { this->bRelCoorChanged = true; }
     /** tells the child that the parent's Direction has changed */
-    inline void parentDirChanged () { this->bRelDirChanged = true; }
+    inline void parentDirChanged2D () { this->bRelDirChanged = true; }
     /** @returns the last calculated coordinate */
-    inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
-
+    inline Vector getLastAbsCoor2D() { return this->lastAbsCoordinate; }
+
+    void reparent2D();
+    static Element2D* createNullElement();
+    bool checkIntegrity(const Element2D* checkParent) const;
 
 
@@ -212,6 +237,6 @@
     E2D_ALIGNMENT           alignment;          //!< How the Element is aligned around its Position
 
-    bool                    visible;            //!< If the given Element2D is visible.
-    bool                    active;             //!< If the given Element2D is active.
+    bool                    bVisible;            //!< If the given Element2D is visible.
+    bool                    bActive;             //!< If the given Element2D is active.
     E2D_LAYER               layer;              //!< What layer this Element2D is on.
 
@@ -238,23 +263,7 @@
 
     unsigned int            parentMode;         //!< the mode of the binding
+
+    static Element2D*       nullElement;        //!< The top-most Element
 };
 
-//! The top joint of all Element2D's every Element2D is somehow connected to this one.
-class NullElement2D : public Element2D {
-
-  public:
-    /** @returns a Pointer to the only object of this Class */
-    inline static NullElement2D* getInstance() { if (!NullElement2D::singletonRef) NullElement2D::singletonRef = new NullElement2D();  return NullElement2D::singletonRef; };
-    inline static bool isInstanciated() { return (NullElement2D::singletonRef != NULL)?true:false; };
-    virtual ~NullElement2D ();
-
-  private:
-    NullElement2D ();
-    virtual void draw() const {};
-
-  private:
-    static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
-
-};
-
 #endif /* _ELEMENT_2D_H */
