/*! * @file element_2d.h * @brief Definition of the 2D elements rendered on top through the GraphicsEngine */ #ifndef _ELEMENT_2D_H #define _ELEMENT_2D_H #include "base_object.h" // FORWARD DECLARATION class PNode; class TiXmlElement; //!< An enumerator defining the Depth of a 2D-element. typedef enum { E2D_BELOW_ALL = 1, //!< Will be rendered below the 3D-scene. @todo make this work. E2D_BOTTOM = 2, //!< Will be rendered on the bottom Layer E2D_MEDIUM = 4, //!< Will be rendered on the medium Layer. E2D_TOP = 8, //!< Will be rendered on top of everything else E2D_LAYER_COUNT = 4 //!< The count of Layers. } E2D_LAYER; #define E2D_DEFAULT_LAYER E2D_TOP #define E2D_ALL_LAYERS E2D_TOP | E2D_MEDIUM | E2D_BOTTOM | E2D_BELOW_ALL typedef enum { E2D_ALIGN_NONE = 0, E2D_ALIGN_LEFT = 1, E2D_ALIGN_RIGHT = 2, E2D_ALIGN_CENTER = 4, E2D_ALIGN_SCREEN_CENTER = 8 } E2D_ALIGNMENT; //! A Struct defining the Position of an Element in 2D-space struct Position2D { float x; //!< The x-coordinate. float y; //!< The y-coordinate. float depth; //!< The distance from the viewing plane. }; //! A class for ... class Element2D : virtual public BaseObject { public: Element2D(); virtual ~Element2D(); void init(); void loadParams(const TiXmlElement* root); /** @param xCoord the xCoordinate @param yCoord the y-Coordinate. These coordinates are Relative */ inline void setPosition2D(int xCoord, int yCoord) { this->relPos2D[0] = xCoord; this->relPos2D[1] = yCoord; }; /** this returns the Absolute Position on the screen set by positioning in the tick-phase */ inline const Position2D& getPosition2D() { return this->absPos2D; }; /** @param alignment the new Alignment of the 2D-Element */ inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; void setAlignment(const char* alignment); void setLayer(E2D_LAYER layer); void setLayer(const char* layer); /** @returns the Layer this Element is drawn to */ inline E2D_LAYER getLayer() { return this->layer; }; /** @param visible true if the Element should be visible false otherwise (will not be rendered) */ inline void setVisibility(bool visible) { this->visible = visible; }; /** @param active true if the Element should be active, false otherwise (will not be ticked) */ inline void setActiveness(bool active) { this->active = active; }; /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; }; void setBindNode(const char* bindNode); /** @returns the visibility state */ inline bool isVisible() { return this->visible; }; /** @returns the active-State */ inline bool isActive() { return this->active; }; virtual void tick(float dt); virtual void draw() const = NULL; protected: void positioning(); protected: const PNode* bindNode; //!< a node over which to display this 2D-element int relPos2D[2]; //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.) Position2D absPos2D; //!< The absolute position of the 2D-Element. E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position private: bool visible; //!< If the given Element2D is visible. bool active; //!< If the given Element2D is active. E2D_LAYER layer; //!< What layer this Element2D is on. }; #endif /* _ELEMENT_2D_H */