Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

orxonox/trunk: syncing PNode to Element2D again

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.