fysxasteroids/engine/OverlayBase.h

61 lines
1.6 KiB
C
Raw Normal View History

2010-06-06 00:58:11 +02:00
#ifndef OVERLAYBASE
#define OVERLAYBASE
2010-04-05 23:38:59 +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-04-05 23:38:59 +02:00
class OverlayBase {
public:
OverlayBase () {};
virtual ~OverlayBase() {};
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; };
virtual void Draw () = 0;
void _strange_function_for_vtable () {};
};
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
*
* \node 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();
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 */