[4838] | 1 | /*! |
---|
[4839] | 2 | * @file element_2d.h |
---|
[4838] | 3 | * @brief Definition of the 2D elements rendered on top through the GraphicsEngine |
---|
[3245] | 4 | */ |
---|
[1853] | 5 | |
---|
[4838] | 6 | #ifndef _ELEMENT_2D_H |
---|
| 7 | #define _ELEMENT_2D_H |
---|
[1853] | 8 | |
---|
[3543] | 9 | #include "base_object.h" |
---|
[1853] | 10 | |
---|
[4838] | 11 | // FORWARD DECLARATION |
---|
[4843] | 12 | class PNode; |
---|
[4858] | 13 | class TiXmlElement; |
---|
[3543] | 14 | |
---|
[4839] | 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 |
---|
[4848] | 21 | E2D_BELOW_ALL, //!< Will be rendered below the 3D-scene. @todo make this work. |
---|
| 22 | |
---|
| 23 | E2D_LAYER_COUNT //!< The count of Layers. |
---|
[4840] | 24 | } E2DLayer; |
---|
[4839] | 25 | |
---|
[4843] | 26 | |
---|
| 27 | typedef enum |
---|
| 28 | { |
---|
[4856] | 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 |
---|
[4848] | 34 | } E2D_ALIGNMENT; |
---|
[4843] | 35 | |
---|
[4847] | 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 | |
---|
[3955] | 44 | //! A class for ... |
---|
[4849] | 45 | class Element2D : virtual public BaseObject { |
---|
[1853] | 46 | |
---|
[4850] | 47 | public: |
---|
| 48 | Element2D(); |
---|
| 49 | virtual ~Element2D(); |
---|
[1853] | 50 | |
---|
[4858] | 51 | void init(); |
---|
| 52 | void loadParams(const TiXmlElement* root); |
---|
| 53 | |
---|
[4856] | 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; }; |
---|
[4858] | 60 | void setAlignment(const char* alignment); |
---|
[4856] | 61 | /** @param layer the Layer this is drawn on */ |
---|
| 62 | inline void setLayer(E2DLayer layer) { this->layer = layer; }; |
---|
[4858] | 63 | void setLayer(const char* layer); |
---|
[4850] | 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 */ |
---|
[4856] | 67 | inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; }; |
---|
[4858] | 68 | void setBindNode(const char* bindNode); |
---|
[4840] | 69 | |
---|
[4850] | 70 | /** @returns the visibility state */ |
---|
| 71 | inline bool isVisible() { return this->visible; }; |
---|
[4840] | 72 | |
---|
[4850] | 73 | virtual void tick(float dt); |
---|
| 74 | virtual void draw() const = NULL; |
---|
[4840] | 75 | |
---|
[4858] | 76 | protected: |
---|
| 77 | void positioning(); |
---|
[4847] | 78 | |
---|
[4850] | 79 | protected: |
---|
| 80 | const PNode* bindNode; //!< a node over which to display this 2D-element |
---|
[4856] | 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 | |
---|
[4850] | 86 | private: |
---|
| 87 | bool visible; |
---|
| 88 | E2DLayer layer; |
---|
[1853] | 89 | }; |
---|
| 90 | |
---|
[4839] | 91 | |
---|
[4838] | 92 | #endif /* _ELEMENT_2D_H */ |
---|