#ifndef OVERLAYBASE #define OVERLAYBASE #include #include #include #include namespace Engine { class ModelBase; /** \brief Base class for user-interfaces * * An Overlay is something that is displayed above the game graphics e.g. * such as a health indicator for the player or the user interface such as * the menu or the console. The member function OverlayBase::Draw() is used * for drawing and also receives input such as key press events and mouse * button events. * * The function OverlayBase::Init() is called by the OverlayManager class and * allows the OverlayBase to load its ressources. */ class OverlayBase { public: OverlayBase () {}; virtual ~OverlayBase() {}; /** \brief This function gets called by the OverlayManager class */ virtual void Init() {}; virtual bool OnKeyDown (const SDL_keysym &keysym) { return false; }; virtual bool OnKeyUp (const SDL_keysym &keysym) { return false; }; virtual bool OnMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos) { return false; }; virtual bool OnMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos) { return false; }; /** \brief Draws the content of the Overlay */ virtual void Draw () = 0; }; typedef boost::shared_ptr OverlayBasePtr; /** \brief Takes care of all OverlayBase classes and proxies input and drawing with regard to the current game state of ModelBase * * \note You need to set the ModelBase pointer manually by calling OverlayManager::SetModel()! */ class OverlayManager { public: /** \brief Calls OverlayBase::Init() for all registered Overlays */ void InitOverlays(); /** \brief Draws the Overlays associated with the current game state */ void Draw(); void Register (OverlayBasePtr overlay, unsigned int game_state); /* Input forwarding for the overlays */ bool SendKeyDown (const SDL_keysym &keysym); bool SendKeyUp (const SDL_keysym &keysym); bool SendMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos); bool SendMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos); private: /** \brief Keeps the list of OverlayBase for each game state */ std::map > mOverlays; }; }; #endif /* OVERLAYBASE */