Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/render2D/element_2d.h @ 5399

Last change on this file since 5399 was 5399, checked in by bensch, 19 years ago

orxonox/trunk: GL-GUI not rendered by Element2D anymore, lets see, if this proves usefull… i am not sure

File size: 10.8 KB
Line 
1/*!
2 * @file element_2d.h
3 * Definition of the 2D elements rendered on top through the GraphicsEngine
4 *
5 * @todo reimplement it, so it looks just like PNode.
6*/
7
8#ifndef _ELEMENT_2D_H
9#define _ELEMENT_2D_H
10
11#include "base_object.h"
12
13#include "vector.h"
14
15// FORWARD DECLARATION
16class PNode;
17class TiXmlElement;
18template<class T> class tList;
19
20//!< An enumerator defining the Depth of a 2D-element.
21typedef enum
22{
23  E2D_LAYER_BELOW_ALL           =     0,        //!< Will be rendered below the 3D-scene. @todo make this work.
24  E2D_LAYER_BOTTOM              =     1,        //!< Will be rendered on the bottom Layer
25  E2D_LAYER_MEDIUM              =     2,        //!< Will be rendered on the medium Layer.
26  E2D_LAYER_TOP                 =     3,        //!< Will be rendered on top of everything else
27
28  E2D_LAYER_COUNT               =     4,         //!< The count of Layers.
29
30  E2D_LAYER_EXTERN              =    -1,         //!< In a Layers handeled externally.
31
32  E2D_LAYER_ALL                 =     5,
33} E2D_LAYER;
34#define E2D_DEFAULT_LAYER       E2D_LAYER_MEDIUM
35
36typedef enum
37{
38  E2D_ALIGN_NONE                =     0,
39  E2D_ALIGN_LEFT                =     1,
40  E2D_ALIGN_RIGHT               =     2,
41  E2D_ALIGN_CENTER              =     4,
42  E2D_ALIGN_SCREEN_CENTER       =     8
43} E2D_ALIGNMENT;
44
45typedef enum
46{
47  E2D_PARENT_NONE               =   0,
48  E2D_PARENT_LOCAL_ROTATE       =   1,    //!< Rotates all the children around their centers.
49  E2D_PARENT_ROTATE_MOVEMENT    =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
50
51  E2D_PARENT_MOVEMENT           =   4,    //!< Moves all children along with the parent.
52// special linkage modes
53  E2D_PARENT_ALL                =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
54  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.
55} E2D_PARENT_MODE;
56#define     E2D_DEFAULT_PARENTING_MODE  E2D_PARENT_ALL
57
58//! A Struct defining the Position of an Element in 2D-space
59struct Position2D
60{
61  float       x;                 //!< The x-coordinate.
62  float       y;                 //!< The y-coordinate.
63  float       depth;             //!< The distance from the viewing plane.
64};
65
66//! A class for ...
67class Element2D : virtual public BaseObject {
68
69  public:
70    Element2D();
71    Element2D(Element2D* parent);
72    virtual ~Element2D();
73
74    void init();
75    void loadParams(const TiXmlElement* root);
76
77    /** @param alignment the new Alignment of the 2D-Element */
78    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
79    void setAlignment(const char* alignment);
80    inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
81
82    void setLayer(E2D_LAYER layer);
83    void setLayer(const char* layer);
84    /** @returns the Layer this Element is drawn to */
85    inline E2D_LAYER getLayer() const { return this->layer; };
86
87    /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
88    inline void setVisibility(bool visible) { this->visible = visible; };
89    /** @param active true if the Element should be active, false otherwise (will not be ticked) */
90    inline void setActiveness(bool active) { this->active = active; };
91
92
93    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
94    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
95    void setBindNode(const char* bindNode);
96    inline const PNode* getBindNode() const { return this->bindNode; };
97
98    /** @returns the visibility state */
99    inline bool isVisible() { return this->visible; };
100    /** @returns the active-State */
101    inline bool isActive() { return this->active; };
102
103
104    inline void setSize2D(float x, float y) { this->sizeX = x, this->sizeY = y; };
105    inline void setSizeX2D(float x) { this->sizeX = x; };
106    inline void setSizeY2D(float y) { this->sizeY = y; };
107    inline float getSizeX2D() const { return this->sizeX; };
108    inline float getSizeY2D() const { return this->sizeY; };
109
110    // LIKE PNODE
111  public:
112    void setRelCoor2D (const Vector& relCoord);
113    void setRelCoor2D (float x, float y, float dontCare = 1.0);
114    void setRelCoor2Dpx (int x, int y);
115    void setRelCoorSoft2D (const Vector& relCoordSoft, float bias = 1.0);
116    void setRelCoorSoft2D (float x, float y, float dontCare = 1.0, float bias = 1.0);
117    void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0);
118    /** @returns the relative position */
119    inline const Vector& getRelCoor2D () const { return this->prevRelCoordinate; };
120    /** @returns the Relative Coordinate Destination */
121    inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
122    const Vector& getRelCoor2Dpx() const;
123    void setAbsCoor2D (const Vector& absCoord);
124    void setAbsCoor2D (float x, float y, float depth = 1.0);
125    void setAbsCoor2Dpx (int x, int y);
126    /** @returns the absolute position */
127    inline const Vector& getAbsCoor2D () const { return this->absCoordinate; };
128    const Vector& getAbsCoor2Dpx () const;
129
130    void shiftCoor2D (const Vector& shift);
131    void shiftCoor2Dpx (int x, int y);
132
133    void setRelDir2D (float relDir);
134    void setRelDirSoft2D(float relDirSoft, float bias = 1.0);
135    /** @returns the relative Direction */
136    inline float getRelDir2D () const { return this->prevRelDirection; };
137    /** @returns the Relative Directional Destination */
138    inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
139    void setAbsDir2D (float absDir);
140    /** @returns the absolute Direction */
141    inline float getAbsDir2D () const { return this->absDirection; };
142    void shiftDir2D (float shiftDir);
143
144    /** @returns the Speed of the Node */
145    inline float getSpeed() const { return 0; };
146    /** @returns the Velocity of the Node */
147    inline const Vector& getVelocity() const { return this->velocity; };
148
149
150    void addChild2D (Element2D* child, int parentingMode = E2D_PARENT_NONE);
151    void addChild2D (const char* childName);
152    void removeChild2D (Element2D* child);
153    void remove2D();
154
155    void setParent2D (Element2D* parent);
156    void setParent2D (const char* parentName);
157    /** @returns the parent of this Element2D */
158    inline Element2D* getParent2D () const { return this->parent; };
159    /** @returns the List of Children of this Element2D */
160    inline const tList<Element2D>* getChildren2D() const { return this->children; };
161
162    void setParentSoft2D(Element2D* parentNode, float bias = 1.0);
163    void setParentSoft2D(const char* parentName, float bias = 1.0);
164
165    /** @param parentMode sets the parentingMode of this Node */
166    void setParentMode2D (E2D_PARENT_MODE parentMode) { this->parentMode = parentMode; };
167    void setParentMode2D (const char* parentingMode);
168    /** @returns the Parenting mode of this node */
169    int getParentMode2D() const { return this->parentMode; };
170
171    void update2D (float dt);
172
173    void debug (unsigned int depth = 1, unsigned int level = 0) const;
174    void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,1,1)) const;
175
176    // helper functions //
177    static const char* parentingModeToChar2D(int parentingMode);
178    static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
179
180  private:
181    /** tells the child that the parent's Coordinate has changed */
182    inline void parentCoorChanged () { this->bRelCoorChanged = true; }
183    /** tells the child that the parent's Direction has changed */
184    inline void parentDirChanged () { this->bRelDirChanged = true; }
185    /** @returns the last calculated coordinate */
186    inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
187
188  public:
189    virtual void tick(float dt);
190    virtual void draw() const = 0;
191
192  private:
193    const PNode*            bindNode;           //!< a node over which to display this 2D-element
194    float                   sizeX;              //!< The size of the rendered item in x-direction
195    float                   sizeY;              //!< The size of the rendered Item in y-direction
196
197    E2D_ALIGNMENT           alignment;          //!< How the Element is aligned around its Position
198
199    bool                    visible;            //!< If the given Element2D is visible.
200    bool                    active;             //!< If the given Element2D is active.
201    E2D_LAYER               layer;              //!< What layer this Element2D is on.
202
203    bool                    bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
204    bool                    bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
205
206    Vector                  relCoordinate;      //!< coordinates relative to the parent
207    Vector                  absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
208    float                   relDirection;       //!< direction relative to the parent
209    float                   absDirection;       //!< absolute diretion in the world ( from (0,0,1) )
210
211    Vector                  prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
212    Vector                  lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
213    float                   prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
214
215    Vector                  velocity;           //!< Saves the velocity.
216
217    Vector*                 toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft)
218    float*                  toDirection;        //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft)
219    float                   bias;               //!< how fast to iterate to the given position (default is 1)
220
221    Element2D*              parent;             //!< a pointer to the parent node
222    tList<Element2D>*       children;           //!< list of the children of this Element2D
223
224    unsigned int            parentMode;         //!< the mode of the binding
225};
226
227//! The top joint of all Element2D's every Element2D is somehow connected to this one.
228class NullElement2D : public Element2D {
229
230  public:
231    /** @returns a Pointer to the only object of this Class */
232    inline static NullElement2D* getInstance() { if (!NullElement2D::singletonRef) NullElement2D::singletonRef = new NullElement2D();  return NullElement2D::singletonRef; };
233    inline static bool isInstanciated() { return (NullElement2D::singletonRef != NULL)?true:false; };
234    virtual ~NullElement2D ();
235
236  private:
237    NullElement2D ();
238    virtual void draw() const {};
239
240  private:
241    static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
242
243};
244
245#endif /* _ELEMENT_2D_H */
Note: See TracBrowser for help on using the repository browser.