#ifndef _MAIN_WINDOW_H #define _MAIN_WINDOW_H #ifdef APPLE_NATIVE_GLUT #include #include #include #else #include #endif #include "types.h" #include #include #include "Player.h" #include "Cell.h" #include "Field.h" #include "Game.h" #include "KeyboardController.h" enum TextAlign { right = -2, center = -1, left = 0 }; // Functions defines for C callbacks /** * Called when the window is resized. * May not work yet on all platforms. **/ void f_onChangeSize(int w, int h); /** * Called when timer finishes. **/ void f_onTimer(int v=0); /** * Called when we want to redisplay (Idle) **/ void f_onDisplay(); /** * Called when an ASCII key is pressed. **/ void f_onNormalKeyPressed(unsigned char key, int x, int y); /** * Called when a special key is pressed. **/ void f_onSpecialKeyPressed(int key, int x, int y); /** * Transforms an hexadecimal color into its 3 channels, as floats (0.f - 1.f) **/ void hex2fColor(uint color, float &out_red, float &out_green, float &out_blue); /** * Singleton : display window **/ class MainWindow { private : MainWindow(); // constructor is private, MainWindow( MainWindow const & ); // copy constructor is private MainWindow &operator=( MainWindow const & ); // Assignment operator virtual ~MainWindow(); // ... and destructor. public: /** * Retrieves (create if necessary) the single instance of the class. **/ static MainWindow &getInstance(); public: /** * Initializes freeglut (glutinit) **/ void init(int *argcp, char **argv); /** * Defines window size and name, creates it and defines proper projection matrix **/ void create(std::string name, int x, int y, int width, int height); /** * Registers callbacks and start glut's infinite loop. **/ void startLoop(); /** * Sets the Field we want to draw from **/ void setField(Field* pField); /** * Returns the field we draw from. **/ Field* getField(); /** * Sets the game we will periodically update **/ void setGame(Game* pGame); /** * Returns the game we will periodically update **/ Game* getGame(); /** * Dynamically allocate a new KeyboardController, register it and return it. **/ KeyboardController* generateNewKeyboardController(Player *pPlayer, KeyCode leftKey, KeyCode rightKey); public: // Callbacks /** * Is called when window size is changed **/ void onChangeSize(int w, int h); /** * Is called when display is redrawn **/ void onRenderScene(); /** * is called every (X) ms. **/ void onTimer(); /** * Is called when a special key is pressed **/ void onSpecialKeyPressed(int key); /** * is called when an ASCII key is pressed **/ void onNormalKeyPressed(uint8 key); private: void onKeyPressed(KeyCode key); void drawCell(uint Color); void drawString(GLfloat x, GLfloat y, char *text, uint color, TextAlign align); private: static MainWindow s_mainWindow; Field *m_pField; Game *m_pGame; int m_width, m_height; std::vector m_vpKeyboardController; }; #endif