/*! -------------------------------------------------------------------- \file Input.h \brief Class to encapsulate keyboard and mouse input \author 15-493 Instructors \date 2002-09-04 $Updated: qsb $ $Date: 2002/11/18 08:23:01 $ -------------------------------------------------------------------- */ #ifndef __INPUT_H__ #define __INPUT_H__ //! convenience definition for the Input singleton #define theInput Input::getInstance() //--------------------------------------------------------------------- // Input // //! Class to encapsulate keyboard and mouse input // //--------------------------------------------------------------------- class Input { public: //! returns a handle to the singleton instance of Input (use "theInput") static Input& getInstance() { if (!s_pInput) s_pInput = new Input(); return *s_pInput; } //! cleans up the singleton when it is no longer needed static void Destroy(); // static wrappers used for callbacks static void MouseMotionCallback(int x, int y) { theInput.MouseMotion(x, y); }; static void MousePassiveMotionCallback(int x, int y) { theInput.MousePassiveMotion(x, y); }; static void MouseButtonCallback(int button, int state, int x, int y) { theInput.MouseButton(button, state, x, y); }; static void KeyDownCallback(unsigned char key, int x, int y) { theInput.Keyboard(key, x, y); }; static void KeyUpCallback(unsigned char key, int x, int y) { theInput.KeyboardUp(key, x, y); }; static void KeySpecialDownCallback(int key, int x, int y) { theInput.KeyboardSpecial(key, x, y); }; static void KeySpecialUpCallback(int key, int x, int y) { theInput.KeyboardSpecialUp(key, x, y); }; //! enum's to keep track of what special keys are being pressed // (glut doesn't do this for us) enum {KEY_UP=0, // add additional keys here KEY_DOWN, KEY_LEFT, KEY_RIGHT, // don't change the last element! NUM_SPEC_KEYS}; //! checks if a certain char key is being pressed bool IsKeyPressed(unsigned char key) { return m_bKeyPressed[(int) key]; }; //! checks if a certain special key is being pressed bool IsSpecialPressed(int key) { return m_bSpecialPressed[key]; }; bool IsButtonPressed(int button) { return m_bButtonPressed[button]; } int GetMouseX() { return _dx; } int GetMouseY() { return _dy; } void UpdateState() {} // _dx = 0; _dy = 0; } enum MouseButtons { LEFT_BUTTON=0, MIDDLE_BUTTON, RIGHT_BUTTON, NUM_BUTTONS }; //////////////////////////////////////////////////////////////// protected: Input(); void MouseMotion(int x, int y); void MousePassiveMotion(int x, int y); void MouseButton(int button, int state, int x, int y); void Keyboard(unsigned char key, int x, int y); void KeyboardUp(unsigned char key, int x, int y); void KeyboardSpecial(int key, int x, int y); void KeyboardSpecialUp(int key, int x, int y); //! store location of mouse int m_iMousePos[2]; //! remember if mouse is being clicked bool m_bButtonPressed[NUM_BUTTONS]; //! array to store which char keys are being pressed static const int MAX_KEYS = 256; bool m_bKeyPressed[MAX_KEYS]; //! array to store which special keys are being pressed bool m_bSpecialPressed[NUM_SPEC_KEYS]; //! singleton instance static Input *s_pInput; // keep track of mouse movement int _dx; int _dy; }; #endif // ndef __INPUT_H__