#ifndef _MOUSE_H_ #define _MOUSE_H_ #include #include #include enum MouseBtn { MOUSE_BTN_LEFT, MOUSE_BTN_MIDDLE, MOUSE_BTN_RIGHT, MOUSE_BTN_COUNT }; class WgdMouse { public: static void init(); // static void update(); //Call this every frame to update mouse info static void updateDimensions(); //These 2D functions return values in the range 0 to 1 inclusive static wgd::vector2d getPos() { return _pos; } static wgd::vector2d getDelta() { return _delta; } static int getWheel() { return mouse->deltaZ(); } //As getPos, but with range -1 to 1 inclusive static wgd::vector2d getAim() { return _aim; } //Get where the mouse is pointing at on the 'ground' plane static wgd::vector3d getPos3D(bool snap); static bool isOnScreen(); //Buttons static bool buttonPressed (MouseBtn btn) { return !lastButtons[btn] && buttons[btn]; } static bool buttonReleased (MouseBtn btn) { return lastButtons[btn] && !buttons[btn]; } static bool buttonDown (MouseBtn btn) { return buttons[btn]; } static bool buttonUp (MouseBtn btn) { return !buttons[btn]; } static bool click (MouseBtn btn) { return buttonReleased(btn) && !mouseMovedSinceClick[btn]; } static bool drag (MouseBtn btn) { return _delta.length() > 0.0f && buttons[btn]; } protected: static wgd::Mouse* mouse; //Cached wgd::Mouse pointer static doste::dvm::OID scene; //Cached doste::OID pointer static float _top, _left; //Scene widget offset static float _width, _height; //Scene widget dimensions static wgd::vector2d _pos; //Mouse co-ordinates on scene widget (range 0 to 1) static wgd::vector2d _aim; //Mouse co-ordinates on scene widget (range -1 to 1) static wgd::vector2d _delta; //Mouse movement between this frame and the last static wgd::vector2d _lastPos; //Mouse co-ords on last frame, for delta calculation static bool buttons[MOUSE_BTN_COUNT]; static bool lastButtons[MOUSE_BTN_COUNT]; static bool mouseMovedSinceClick[MOUSE_BTN_COUNT]; }; #endif //_MOUSE_H_