Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: introducing Layers

File size: 3.5 KB
Line 
1/*!
2 * @file element_2d.h
3 * @brief Definition of the 2D elements rendered on top through the GraphicsEngine
4*/
5
6#ifndef _ELEMENT_2D_H
7#define _ELEMENT_2D_H
8
9#include "base_object.h"
10
11// FORWARD DECLARATION
12class PNode;
13class TiXmlElement;
14
15//!< An enumerator defining the Depth of a 2D-element.
16typedef enum
17{
18  E2D_BELOW_ALL                 =     1,        //!< Will be rendered below the 3D-scene. @todo make this work.
19  E2D_BOTTOM                    =     2,        //!< Will be rendered on the bottom Layer
20  E2D_MEDIUM                    =     4,        //!< Will be rendered on the medium Layer.
21  E2D_TOP                       =     8,        //!< Will be rendered on top of everything else
22
23  E2D_LAYER_COUNT               =     4         //!< The count of Layers.
24} E2D_LAYER;
25#define E2D_DEFAULT_LAYER       E2D_TOP
26#define E2D_ALL_LAYERS          E2D_TOP | E2D_MEDIUM | E2D_BOTTOM | E2D_BELOW_ALL
27
28typedef enum
29{
30  E2D_ALIGN_NONE                =     0,
31  E2D_ALIGN_LEFT                =     1,
32  E2D_ALIGN_RIGHT               =     2,
33  E2D_ALIGN_CENTER              =     4,
34  E2D_ALIGN_SCREEN_CENTER       =     8
35} E2D_ALIGNMENT;
36
37//! A Struct defining the Position of an Element in 2D-space
38struct Position2D
39{
40  float       x;                 //!< The x-coordinate.
41  float       y;                 //!< The y-coordinate.
42  float       depth;             //!< The distance from the viewing plane.
43};
44
45//! A class for ...
46class Element2D : virtual public BaseObject {
47
48  public:
49    Element2D();
50    virtual ~Element2D();
51
52    void init();
53    void loadParams(const TiXmlElement* root);
54
55    /** @param xCoord the xCoordinate @param yCoord the y-Coordinate. These coordinates are Relative */
56    inline void setPosition2D(int xCoord, int yCoord) { this->relPos2D[0] = xCoord; this->relPos2D[1] = yCoord; };
57    /** this returns the Absolute Position on the screen set by positioning in the tick-phase */
58    inline const Position2D& getPosition2D() { return this->absPos2D; };
59
60    /** @param alignment the new Alignment of the 2D-Element */
61    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
62    void setAlignment(const char* alignment);
63
64    void setLayer(E2D_LAYER layer);
65    void setLayer(const char* layer);
66    /** @returns the Layer this Element is drawn to */
67    inline E2D_LAYER getLayer() { return this->layer; };
68
69    /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
70    inline void setVisibility(bool visible) { this->visible = visible; };
71
72    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
73    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
74    void setBindNode(const char* bindNode);
75
76    /** @returns the visibility state */
77    inline bool isVisible() { return this->visible; };
78
79    virtual void tick(float dt);
80    virtual void draw() const = NULL;
81
82  protected:
83    void positioning();
84
85  protected:
86    const PNode*            bindNode;         //!< a node over which to display this 2D-element
87    int                     relPos2D[2];      //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.)
88    Position2D              absPos2D;         //!< The absolute position of the 2D-Element.
89
90    E2D_ALIGNMENT           alignment;        //!< How the Element is aligned around its Position
91
92  private:
93    bool                    visible;
94    E2D_LAYER               layer;
95};
96
97
98#endif /* _ELEMENT_2D_H */
Note: See TracBrowser for help on using the repository browser.