Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6299 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
Dec 26, 2005, 4:41:09 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: syncing PNode to Element2D again

Location:
trunk/src/lib/graphics/render2D
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r6295 r6299  
    3030
    3131using namespace std;
    32 
    33 /**
    34  * standard constructor
    35  */
    36 Element2D::Element2D()
    37 {
    38   this->init();
    39   this->setParent2D(NullElement2D::getInstance());
    40 }
    4132
    4233/**
     
    4738 * itself. Otherwise it would result in an endless Loop.
    4839 */
    49 Element2D::Element2D (Element2D* parent, E2D_LAYER layer)
    50 {
    51   this->init();
     40Element2D::Element2D (Element2D* parent, E2D_LAYER layer, short nodeFlags)
     41{
     42  this->setClassID(CL_ELEMENT_2D, "Element2D");
     43
     44  this->setVisibility(true);
     45  this->activate2D();
     46  this->setAlignment(E2D_ALIGN_NONE);
     47  this->bindNode = NULL;
     48
     49  this->parentMode = nodeFlags;
     50  this->parent = NULL;
     51  this->absDirection = 0.0;
     52  this->relDirection = 0.0;
     53  this->bRelCoorChanged = true;
     54  this->bRelDirChanged = true;
     55  this->toCoordinate = NULL;
     56  this->toDirection = NULL;
     57  this->setSize2D(1, 1);
     58
     59
    5260  this->layer = layer;
    53   // check Parenting, and if ok parent the stuff
    54   if (this->parent != NULL)
    55     this->setParent2D(parent);
    56   else if (NullElement2D::isInstanciated())
    57     this->setParent2D(NullElement2D::getInstance());
    58 }
     61  if (parent != NULL)
     62    parent->addChild2D(this);
     63}
     64
     65
     66/**
     67 * @brief the mighty NullElement
     68 * TopMost Node of them all.
     69 */
     70Element2D* Element2D::nullElement = NULL;
     71
    5972
    6073/**
     
    7487Element2D::~Element2D ()
    7588{
    76   // remove the Node, delete it's children.
    77   while (this->children.size() > 0)
    78   {
    79     Element2D* child = this->children.front();
    80     this->children.pop_front();
    81     delete child;
    82   }
     89  // remove the Element2D, delete it's children (if required).
     90  std::list<Element2D*>::iterator tmp = this->children.begin();
     91  std::list<Element2D*>::iterator deleteNode;
     92  while(!this->children.empty())
     93    while (tmp != this->children.end())
     94    {
     95      deleteNode = tmp;
     96      tmp++;
     97//      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
     98      if ((this->parentMode & E2D_PROHIBIT_CHILD_DELETE) ||
     99          ((*deleteNode)->parentMode & E2D_PROHIBIT_DELETE_WITH_PARENT))
     100      {
     101        if (this == Element2D::nullElement && (*deleteNode)->parentMode & E2D_REPARENT_TO_NULL)
     102          delete (*deleteNode);
     103        else
     104          (*deleteNode)->reparent2D();
     105      }
     106      else
     107        delete (*deleteNode);
     108    }
     109
    83110  if (this->parent != NULL)
    84111  {
    85     this->parent->eraseChild(this);
     112    this->parent->eraseChild2D(this);
    86113    this->parent = NULL;
    87114  }
     
    92119  if (this->toDirection != NULL)
    93120    delete this->toDirection;
    94 }
    95 
    96 
    97 /**
    98  * @brief initializes a Element2D
    99  */
    100 void Element2D::init()
    101 {
    102   this->setClassID(CL_ELEMENT_2D, "Element2D");
    103 
    104   this->setVisibility(true);
    105   this->setActiveness(true);
    106   this->setAlignment(E2D_ALIGN_NONE);
    107   this->layer = E2D_DEFAULT_LAYER;
    108   this->bindNode = NULL;
    109 
    110   this->setParentMode2D(E2D_PARENT_ALL);
    111   this->parent = NULL;
    112   this->absDirection = 0.0;
    113   this->relDirection = 0.0;
    114   this->bRelCoorChanged = true;
    115   this->bRelDirChanged = true;
    116   this->toCoordinate = NULL;
    117   this->toDirection = NULL;
    118   this->setSize2D(1,1);
    119 }
     121
     122  if (this == Element2D::nullElement)
     123    Element2D::nullElement = NULL;
     124}
     125
    120126
    121127/**
     
    161167  LOAD_PARAM_START_CYCLE(root, element);
    162168  {
    163     LoadParam_CYCLE(element, "parent", this, Element2D, addChild2D)
     169    LoadParam_CYCLE(element, "child", this, Element2D, addChild2D)
    164170        .describe("adds a new Child to the current Node.");
    165171  }
     
    213219
    214220/**
    215  * sets a node, this 2D-Element should be shown upon
     221 * @brief sets a node, this 2D-Element should be shown upon
    216222 * @param bindNode the name of the Node (should be existing)
    217223 */
     
    511517  {
    512518    PRINTF(5)("Element2D::addChild() - reparenting node: removing it and adding it again\n");
    513     child->parent->eraseChild(child);
    514   }
    515   child->parent = this;
    516   if (likely(this != NULL))
    517   {
    518     // ELEMENT SORTING TO LAYERS  //
    519     unsigned int childCount = this->children.size();
    520 
    521     list<Element2D*>::iterator elem;
    522     for (elem = this->children.begin(); elem != this->children.end(); elem++)
    523     {
    524       if ((*elem)->layer < child->layer)
    525       {
    526         this->children.insert(elem, child);
    527         break;
    528       }
    529     }
    530 
    531     if (childCount == this->children.size())
    532       this->children.push_back(child);
    533     ////////////////////////////////
    534     if (unlikely(this->layer > child->getLayer()))
    535     {
    536       PRINTF(2)("Layer '%s' of Child(%s) lower than parents(%s) layer '%s'. updating...\n",
    537       Element2D::layer2DToChar(child->getLayer()),child->getName(), this->getName(), Element2D::layer2DToChar(this->layer));
    538       child->setLayer(this->layer);
    539     }
    540   }
    541   child->parentCoorChanged();
     519    child->parent->eraseChild2D(child);
     520  }
     521  if (this->checkIntegrity(child))
     522  {
     523    child->parent = this;
     524    if (likely(this != NULL))
     525    {
     526     // ELEMENT SORTING TO LAYERS  //
     527     unsigned int childCount = this->children.size();
     528
     529     list<Element2D*>::iterator elem;
     530     for (elem = this->children.begin(); elem != this->children.end(); elem++)
     531     {
     532       if ((*elem)->layer < child->layer)
     533       {
     534         this->children.insert(elem, child);
     535         break;
     536       }
     537     }
     538     if (childCount == this->children.size())
     539       this->children.push_back(child);
     540     ////////////////////////////////
     541     if (unlikely(this->layer > child->getLayer()))
     542     {
     543       PRINTF(2)("Layer '%s' of Child(%s) lower than parents(%s) layer '%s'. updating...\n",
     544       Element2D::layer2DToChar(child->getLayer()),child->getName(), this->getName(), Element2D::layer2DToChar(this->layer));
     545       child->setLayer(this->layer);
     546     }
     547   }
     548   else
     549   {
     550     PRINTF(1)("Tried to reparent2D to own child '%s::%s' to '%s::%s'.\n",
     551              this->getClassName(), this->getName(), child->getClassName(), child->getName());
     552     child->parent = NULL;
     553   }
     554  }
     555  child->parentCoorChanged2D();
    542556}
    543557
     
    566580
    567581/**
     582 * !! PRIVATE FUNCTION
     583 * @brief reparents an Element2D (happens on Parents Node delete or remove and Flags are set.)
     584 */
     585void Element2D::reparent2D()
     586{
     587  if (this->parentMode & E2D_REPARENT_TO_NULL)
     588    this->setParent2D((Element2D*)NULL);
     589  else if (this->parentMode & E2D_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
     590    this->setParent2D(this->parent->getParent2D());
     591  else
     592    this->setParent2D(Element2D::getNullElement());
     593}
     594
     595
     596/**
     597 * @param child the child to be erased from this Nodes List
     598 */
     599void Element2D::eraseChild2D(Element2D* child)
     600{
     601  assert (this != NULL && child != NULL);
     602  std::list<Element2D*>::iterator childIT = std::find(this->children.begin(), this->children.end(), child);
     603  this->children.erase(childIT);
     604}
     605
     606
     607
     608/**
    568609 * remove this Element from the tree and adds all children to NullElement2D
    569610 *
     
    572613void Element2D::remove2D()
    573614{
    574   list<Element2D*>::iterator child;
    575   for (child = this->children.begin(); child != this->children.end(); child++)
    576     NullElement2D::getInstance()->addChild2D(*child);
    577 
    578   this->children.clear();
    579 
     615  list<Element2D*>::iterator child = this->children.begin();
     616  list<Element2D*>::iterator reparenter;
     617  while (child != this->children.end())
     618  {
     619    reparenter = child;
     620    child++;
     621    if (this->parentMode & E2D_REPARENT_CHILDREN_ON_REMOVE ||
     622        (*reparenter)->parentMode & E2D_REPARENT_ON_PARENTS_REMOVE)
     623    {
     624      printf("TEST----------------%s ---- %s\n", this->getClassName(), (*reparenter)->getClassName());
     625      (*reparenter)->reparent2D();
     626      printf("REPARENTED TO: %s::%s\n",(*reparenter)->getParent2D()->getClassName(),(*reparenter)->getParent2D()->getName());
     627    }
     628  }
    580629  if (this->parent != NULL)
    581630  {
    582     this->parent->eraseChild(this);
     631    this->parent->eraseChild2D(this);
    583632    this->parent = NULL;
    584633  }
    585634}
    586635
    587 /**
    588  * sets the parent of this Element2D
    589  * @param parent the Parent to set
    590  */
    591 void Element2D::setParent2D (Element2D* parent)
    592 {
    593   parent->addChild2D(this);
    594 }
    595636
    596637/**
     
    603644  if (parentNode != NULL)
    604645    parentNode->addChild2D(this);
    605 
     646  else
     647    PRINTF(2)("Not Found Element2D's (%s::%s) new Parent by Name: %s\n",
     648                this->getClassName(), this->getName(), parentName);
    606649}
    607650
     
    634677  parentNode->addChild2D(this);
    635678
    636   if (this->parentMode & PNODE_ROTATE_MOVEMENT) //! @todo implement this.
     679  if (this->parentMode & E2D_PARENT_ROTATE_MOVEMENT) //! @todo implement this.
    637680    ;//this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
    638681  else
     
    656699}
    657700
    658 /** @param child the child to be erased from this Nodes List */
    659 void Element2D::eraseChild(Element2D* child)
    660 {
    661   assert (this != NULL && child != NULL);
    662   std::list<Element2D*>::iterator childIT = std::find(this->children.begin(), this->children.end(), child);
    663   this->children.erase(childIT);
    664 }
     701/**
     702 * @param parentMode sets the parentingMode of this Node
     703 */
     704void Element2D::setParentMode2D(E2D_PARENT_MODE parentMode)
     705{
     706  this->parentMode &= (0xfff0 | parentMode);
     707}
     708
    665709
    666710/**
     
    672716  this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode));
    673717}
     718
     719
     720/**
     721 * @returns the NullElement (and if needed (most probably) creates it)
     722 */
     723Element2D* Element2D::createNullElement()
     724{
     725  if (likely(Element2D::nullElement == NULL))
     726  {
     727    Element2D::nullElement = new Element2D(NULL, E2D_LAYER_BELOW_ALL, E2D_PARENT_MODE_DEFAULT | E2D_REPARENT_TO_NULL);
     728    Element2D::nullElement->setName("NullElement");
     729  }
     730  return Element2D::nullElement;
     731}
     732
     733
     734/**
     735 * !! PRIVATE FUNCTION
     736 * @brief checks the upward integrity (e.g if Element2D is somewhere up the Node tree.)
     737 * @param checkParent the Parent to check.
     738 * @returns true if the integrity-check succeeds, false otherwise.
     739 *
     740 * If there is a second occurence of checkParent before NULL, then a loop could get
     741 * into the Tree, and we do not want this.
     742 */
     743bool Element2D::checkIntegrity(const Element2D* checkParent) const
     744{
     745  const Element2D* parent = this;
     746  while ( (parent = parent->getParent2D()) != NULL)
     747    if (unlikely(parent == checkParent))
     748      return false;
     749  return true;
     750}
     751
    674752
    675753/**
     
    796874
    797875  // UPDATE CHILDREN
    798   if(this->children.size() > 0)
     876  if(!this->children.empty() || this->parentMode & E2D_UPDATE_CHILDREN_IF_INACTIVE)
    799877  {
    800878    list<Element2D*>::iterator child;
     
    803881      /* if this node has changed, make sure, that all children are updated also */
    804882      if( likely(this->bRelCoorChanged))
    805         (*child)->parentCoorChanged ();
     883        (*child)->parentCoorChanged2D();
    806884      if( likely(this->bRelDirChanged))
    807         (*child)->parentDirChanged ();
     885        (*child)->parentDirChanged2D();
    808886
    809887      (*child)->update2D(dt);
     
    816894  this->bRelDirChanged = false;
    817895}
     896
    818897
    819898/**
     
    865944void Element2D::tick2D(float dt)
    866945{
    867   if (this->active)
     946  if (this->bActive)
    868947    this->tick(dt);
    869948  if (this->children.size() > 0)
     
    881960void Element2D::draw2D(short layer) const
    882961{
    883   if (this->visible)
     962  if (this->bVisible)
    884963    this->draw();
    885964  if (this->children.size() > 0)
     
    9301009    {
    9311010      // drawing the Dependency graph
    932       if (this != NullElement2D::getInstance())
     1011      if (this != Element2D::getNullElement())
    9331012      {
    9341013        glBegin(GL_LINES);
     
    10391118    return (E2D_DEFAULT_LAYER);
    10401119}
    1041 
    1042 
    1043 
    1044 
    1045 ///////////////////
    1046 // NullElement2D //
    1047 ///////////////////
    1048 NullElement2D* NullElement2D::singletonRef = 0;
    1049 
    1050 /**
    1051  * @brief creates the one and only NullElement2D
    1052  */
    1053 NullElement2D::NullElement2D () : Element2D(NULL, E2D_LAYER_BELOW_ALL)
    1054 {
    1055   this->setClassID(CL_NULL_ELEMENT_2D, "NullElement2D");
    1056   this->setName("NullElement2D");
    1057 
    1058   this->setParentMode2D(E2D_PARENT_ALL);
    1059   NullElement2D::singletonRef = this;
    1060 }
    1061 
    1062 
    1063 /**
    1064  *  standard deconstructor
    1065  */
    1066 NullElement2D::~NullElement2D ()
    1067 {
    1068   NullElement2D::singletonRef = NULL;
    1069 }
  • trunk/src/lib/graphics/render2D/element_2d.h

    r6142 r6299  
    11/*!
    22 * @file element_2d.h
    3  * Definition of the 2D elements rendered on top through the GraphicsEngine
     3 * Definition of the 2D elements rendered on top of all other stuff.
    44 */
    55
     
    4040typedef enum
    4141{
    42   E2D_PARENT_NONE               =   0,
    43   E2D_PARENT_LOCAL_ROTATE       =   1,    //!< Rotates all the children around their centers.
    44   E2D_PARENT_ROTATE_MOVEMENT    =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
    45 
    46   E2D_PARENT_MOVEMENT           =   4,    //!< Moves all children along with the parent.
     42  E2D_PARENT_NONE                    = 0x0000,
     43  E2D_PARENT_LOCAL_ROTATE            = 0x0001,    //!< Rotates all the children around their centers.
     44  E2D_PARENT_ROTATE_MOVEMENT         = 0x0002,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
     45
     46  E2D_PARENT_MOVEMENT                = 0x0004,    //!< Moves all children along with the parent.
    4747// special linkage modes
    48   E2D_PARENT_ALL                =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
    49   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.
     48  E2D_PARENT_ALL                     = 0x0003,    //!< Moves all children around the center of their parent, and also rotates their centers
     49  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.
     50
     51
     52  // REPARENTING
     53  E2D_REPARENT_TO_NULL               = 0x0010,    //!< Reparents to the Null, if the Parent is Removed. Meaning the Node wont have a parent anymore.
     54  E2D_REPARENT_TO_PARENTS_PARENT     = 0x0020,    //!< Reparents the Node to the parents (old) parent it the parent gets removed.
     55  /////////////////////////////////////////////   //  ELSE: Reparents to the NullParent.
     56  E2D_REPARENT_DELETE_CHILDREN       = 0x0040,    //!< Deletes the Children of the node when This Node is Removed. (Use with care).
     57  /// FIXME
     58   E2D_REPARENT_KEEP_POSITION         = 0x0080,   //!< Tries to keep the Position if the Node is reparented.
     59
     60
     61  // DELETION
     62  E2D_PROHIBIT_CHILD_DELETE          = 0x0100,    //!< Prohibits the Children from being deleted if this Node gets deleted.
     63  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
     64  E2D_REPARENT_CHILDREN_ON_REMOVE    = 0x0400,    //!< Reparents the Children of the Node if the Node gets Removed.
     65  E2D_REPARENT_ON_PARENTS_REMOVE     = 0x0800,    //!< The Node gets Reparented if its Parent gets removed. Child will be reparented according to the Reparenting-Rules.
     66
     67  // VISIBILITY/ACTIVITY
     68  E2D_HIDE_CHILDREN_IF_HIDDEN        = 0x1000,    //!< Prohibits the Children from being drawn if this node isn't visible. (used for Draw))
     69  E2D_HIDE_IF_PARENT_HIDDEN          = 0x2000,    //!< Prohibits the node from being drawn if the Parent is invisible.
     70  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.)
     71  E2D_STATIC_NODE                    = 0x8000,    //!< Used for nodes that do not have any moving children, and that do not move.
     72
    5073} E2D_PARENT_MODE;
    51 #define     E2D_DEFAULT_PARENTING_MODE  E2D_PARENT_ALL
    52 
    53 //! A Struct defining the Position of an Element in 2D-space
    54 struct Position2D
    55 {
    56   float       x;                 //!< The x-coordinate.
    57   float       y;                 //!< The y-coordinate.
    58   float       depth;             //!< The distance from the viewing plane.
    59 };
     74#define     E2D_PARENT_MODE_DEFAULT     E2D_PARENT_ALL | \
     75                                        E2D_REPARENT_KEEP_POSITION
    6076
    6177//! A class for 2D-elements
     
    7288
    7389  public:
    74     Element2D();
    75     Element2D(Element2D* parent, E2D_LAYER layer = E2D_DEFAULT_LAYER);
     90    Element2D(Element2D* parent = Element2D::getNullElement(), E2D_LAYER layer = E2D_DEFAULT_LAYER, short nodeFlags = E2D_PARENT_MODE_DEFAULT);
    7691    virtual ~Element2D();
    7792
    78     void init();
    7993    void loadParams(const TiXmlElement* root);
    8094
     95    // ACTIVATION //
     96    inline void activate2D() { this->bActive = this->bRelCoorChanged = this->bRelDirChanged = true; };
     97    inline void deactivate2D() { this->bActive = false; };
     98    inline bool get2DActiveState() { return this->bActive; };
     99
     100    // ALIGNMENT //
    81101    /** @param alignment the new Alignment of the 2D-Element */
    82102    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
     
    84104    inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
    85105
     106    // LAYERING //
    86107    void setLayer(E2D_LAYER layer);
    87108    void setLayer(const char* layer);
     
    89110    inline E2D_LAYER getLayer() const { return this->layer; };
    90111
     112    // VISIBILITY //
    91113    /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
    92     inline void setVisibility(bool visible) { this->visible = visible; };
    93     /** @param active true if the Element should be active, false otherwise (will not be ticked) */
    94     inline void setActiveness(bool active) { this->active = active; };
    95 
    96 
     114    inline void setVisibility(bool visible) { this->bVisible = visible; };
     115    /** @returns the visibility state */
     116    inline bool isVisible() { return this->bVisible; };
     117
     118
     119    // POSITIONAL (E2D-specials) //
    97120    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
    98121    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
    99122    void setBindNode(const char* bindNode);
    100123    inline const PNode* getBindNode() const { return this->bindNode; };
    101 
    102     /** @returns the visibility state */
    103     inline bool isVisible() { return this->visible; };
    104     /** @returns the active-State */
    105     inline bool isActive() { return this->active; };
    106 
    107124
    108125    inline void setSize2D(float x, float y) { this->sizeX = x, this->sizeY = y; };
     
    114131  public:
    115132    virtual void tick(float dt) {};
    116     virtual void draw() const = 0;
     133    virtual void draw() const  {};
    117134    void tick2D(float dt);
    118135    void draw2D(short layer) const;
     
    166183    void remove2D();
    167184
    168     void setParent2D (Element2D* parent);
     185    /** @param parent the new parent of this Element2D */
     186    void setParent2D (Element2D* parent) { parent->addChild2D(this); };
    169187    void setParent2D (const char* parentName);
    170188    /** @returns the parent of this Element2D */
     
    176194    void setParentSoft2D(const char* parentName, float bias = 1.0);
    177195
    178     /** @param parentMode sets the parentingMode of this Node */
    179     void setParentMode2D (E2D_PARENT_MODE parentMode) { this->parentMode = parentMode; };
     196    void setParentMode2D (E2D_PARENT_MODE parentMode);
    180197    void setParentMode2D (const char* parentingMode);
    181198    /** @returns the Parenting mode of this node */
    182199    int getParentMode2D() const { return this->parentMode; };
    183200
     201    // NULL_PARENT //
     202    /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */
     203    static Element2D* getNullElement()  { return (Element2D::nullElement != NULL)? Element2D::nullElement : Element2D::createNullElement(); };
     204
     205
    184206    void update2D (float dt);
    185207
     
    195217
    196218  private:
    197     void eraseChild(Element2D* child);
     219    void eraseChild2D(Element2D* child);
    198220    /** tells the child that the parent's Coordinate has changed */
    199     inline void parentCoorChanged () { this->bRelCoorChanged = true; }
     221    inline void parentCoorChanged2D () { this->bRelCoorChanged = true; }
    200222    /** tells the child that the parent's Direction has changed */
    201     inline void parentDirChanged () { this->bRelDirChanged = true; }
     223    inline void parentDirChanged2D () { this->bRelDirChanged = true; }
    202224    /** @returns the last calculated coordinate */
    203     inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
    204 
     225    inline Vector getLastAbsCoor2D() { return this->lastAbsCoordinate; }
     226
     227    void reparent2D();
     228    static Element2D* createNullElement();
     229    bool checkIntegrity(const Element2D* checkParent) const;
    205230
    206231
     
    212237    E2D_ALIGNMENT           alignment;          //!< How the Element is aligned around its Position
    213238
    214     bool                    visible;            //!< If the given Element2D is visible.
    215     bool                    active;             //!< If the given Element2D is active.
     239    bool                    bVisible;            //!< If the given Element2D is visible.
     240    bool                    bActive;             //!< If the given Element2D is active.
    216241    E2D_LAYER               layer;              //!< What layer this Element2D is on.
    217242
     
    238263
    239264    unsigned int            parentMode;         //!< the mode of the binding
     265
     266    static Element2D*       nullElement;        //!< The top-most Element
    240267};
    241268
    242 //! The top joint of all Element2D's every Element2D is somehow connected to this one.
    243 class NullElement2D : public Element2D {
    244 
    245   public:
    246     /** @returns a Pointer to the only object of this Class */
    247     inline static NullElement2D* getInstance() { if (!NullElement2D::singletonRef) NullElement2D::singletonRef = new NullElement2D();  return NullElement2D::singletonRef; };
    248     inline static bool isInstanciated() { return (NullElement2D::singletonRef != NULL)?true:false; };
    249     virtual ~NullElement2D ();
    250 
    251   private:
    252     NullElement2D ();
    253     virtual void draw() const {};
    254 
    255   private:
    256     static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
    257 
    258 };
    259 
    260269#endif /* _ELEMENT_2D_H */
  • trunk/src/lib/graphics/render2D/render_2d.cc

    r6222 r6299  
    5050Render2D::~Render2D ()
    5151{
    52   delete NullElement2D::getInstance();
     52  delete Element2D::getNullElement();
    5353
    5454  Render2D::singletonRef = NULL;
     
    6161void Render2D::update(float dt)
    6262{
    63   NullElement2D::getInstance()->update2D(dt);
     63  Element2D::getNullElement()->update2D(dt);
    6464}
    6565
     
    7171void Render2D::tick(float dt)
    7272{
    73   NullElement2D::getInstance()->tick2D(dt);
     73  Element2D::getNullElement()->tick2D(dt);
    7474}
    7575
     
    8181{
    8282  GraphicsEngine::enter2DMode();
    83   NullElement2D::getInstance()->draw2D(E2D_LAYER_ALL);
     83  Element2D::getNullElement()->draw2D(E2D_LAYER_ALL);
    8484  if (this->showNodes)
    85     NullElement2D::getInstance()->debugDraw2D(0);
     85    Element2D::getNullElement()->debugDraw2D(0);
    8686  GraphicsEngine::leave2DMode();
    8787}
Note: See TracChangeset for help on using the changeset viewer.