2010-06-06 00:58:11 +02:00
|
|
|
#ifndef OVERLAYBASE
|
|
|
|
#define OVERLAYBASE
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2010-04-14 22:01:45 +02:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
#include <SDL/SDL.h>
|
2010-06-06 00:58:11 +02:00
|
|
|
#include <map>
|
|
|
|
#include <list>
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
namespace Engine {
|
|
|
|
|
2010-06-06 00:58:11 +02:00
|
|
|
class ModelBase;
|
|
|
|
|
|
|
|
/** \brief Base class for user-interfaces
|
2010-06-06 01:22:01 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2010-06-06 00:58:11 +02:00
|
|
|
*/
|
2010-04-05 23:38:59 +02:00
|
|
|
class OverlayBase {
|
|
|
|
public:
|
|
|
|
OverlayBase () {};
|
|
|
|
virtual ~OverlayBase() {};
|
|
|
|
|
2010-06-06 01:22:01 +02:00
|
|
|
/** \brief This function gets called by the OverlayManager class */
|
2010-06-06 00:58:11 +02:00
|
|
|
virtual void Init() {};
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
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; };
|
|
|
|
|
2010-06-06 01:22:01 +02:00
|
|
|
/** \brief Draws the content of the Overlay */
|
2010-04-05 23:38:59 +02:00
|
|
|
virtual void Draw () = 0;
|
|
|
|
};
|
|
|
|
|
2010-04-14 22:01:45 +02:00
|
|
|
typedef boost::shared_ptr<OverlayBase> OverlayBasePtr;
|
|
|
|
|
2010-06-06 00:58:11 +02:00
|
|
|
/** \brief Takes care of all OverlayBase classes and proxies input and drawing with regard to the current game state of ModelBase
|
|
|
|
*
|
2010-06-06 01:22:01 +02:00
|
|
|
* \note You need to set the ModelBase pointer manually by calling OverlayManager::SetModel()!
|
2010-06-06 00:58:11 +02:00
|
|
|
*/
|
|
|
|
class OverlayManager {
|
|
|
|
public:
|
|
|
|
/** \brief Calls OverlayBase::Init() for all registered Overlays */
|
|
|
|
void InitOverlays();
|
|
|
|
|
2010-06-06 01:22:01 +02:00
|
|
|
/** \brief Draws the Overlays associated with the current game state */
|
2010-06-06 00:58:11 +02:00
|
|
|
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<unsigned int, std::list<OverlayBasePtr> > mOverlays;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2010-04-05 23:38:59 +02:00
|
|
|
|
2010-06-06 00:58:11 +02:00
|
|
|
#endif /* OVERLAYBASE */
|