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