-/* --------------------------------------------------------------------
-Mouse stuff
----------------------------------------------------------------------*/
-
-static int _mX = 0;
-static int _mY = 0;
-static int last_buttons = 0 ;
-static int mouse_active = 0;
-static int menu_on = 0;
-
-/* --------------------------------------------------------------------
-Support for mouse as control yoke (david@megginson.com)
-
-- right button toggles between pointer and yoke
-- horizontal drag with no buttons moves ailerons
-- vertical drag with no buttons moves elevators
-- horizontal drag with left button moves brakes (left=on)
-- vertical drag with left button moves throttle (up=more)
-- horizontal drag with middle button moves rudder
-- vertical drag with middle button moves trim
-
-For the *_sensitivity variables, a lower number means more sensitive.
-
-TODO: figure out how to keep pointer from leaving window in yoke mode.
-TODO: add thresholds and null zones
-TODO: sensitivity should be configurable at user option.
-TODO: allow differential braking (this will be useful if FlightGear
- ever supports tail-draggers like the DC-3)
----------------------------------------------------------------------*/
-
-static int mouse_yoke = 0;
-static float aileron_sensitivity = 500.0;
-static float elevator_sensitivity = 500.0;
-static float brake_sensitivity = 250.0;
-static float throttle_sensitivity = 250.0;
-static float rudder_sensitivity = 500.0;
-static float trim_sensitivity = 1000.0;
-
-void guiMotionFunc ( int x, int y )
-{
- if (mouse_yoke) {
- if (last_buttons & (1 << GLUT_LEFT_BUTTON)) {
- float brake_offset = (_mX - x) / brake_sensitivity;
- float throttle_offset = (_mY - y) / throttle_sensitivity;
- controls.move_brake(FGControls::ALL_WHEELS, brake_offset);
- controls.move_throttle(FGControls::ALL_ENGINES, throttle_offset);
- } else if (last_buttons & (1 << GLUT_MIDDLE_BUTTON)) {
- float rudder_offset = (x - _mX) / rudder_sensitivity;
- float trim_offset = (_mY - y) / trim_sensitivity;
- controls.move_rudder(rudder_offset);
- controls.move_elevator_trim(trim_offset);
- } else {
- float aileron_offset = (x - _mX) / aileron_sensitivity;
- float elevator_offset = (_mY - y) / elevator_sensitivity;
- controls.move_aileron(aileron_offset);
- controls.move_elevator(elevator_offset);
- }
- } else {
- puMouse ( x, y ) ;
- glutPostRedisplay () ;
- }
- _mX = x;
- _mY = y;
-
-}
-
-void guiMouseFunc(int button, int updown, int x, int y)
-{
- // Toggle mouse as pointer or yoke
- if (updown == GLUT_DOWN && (button & GLUT_RIGHT_BUTTON)) {
- FG_LOG( FG_INPUT, FG_INFO, "Toggling mouse as yoke" );
- mouse_yoke = !mouse_yoke;
- if (mouse_yoke) {
- FG_LOG( FG_INPUT, FG_INFO, "Mouse in yoke mode" );
- glutSetCursor(GLUT_CURSOR_NONE);
- } else {
- glutSetCursor(GLUT_CURSOR_INHERIT);
- FG_LOG( FG_INPUT, FG_INFO, "Mouse in pointer mode" );
- }
- }
- _mX = x;
- _mY = y;
- if ( updown == PU_DOWN ) {
- last_buttons |= ( 1 << button ) ;
- } else {
- last_buttons &= ~( 1 << button ) ;
- }
- if (!mouse_yoke) {
- puMouse (button, updown, x,y);
- glutPostRedisplay ();
- }
-}
-
-int guiGetMouseButton(void)
-{
- return last_buttons;
-}
-
-void guiGetMouse(int *x, int *y)
-{
- *x = _mX;
- *y = _mY;
-};
-
-static inline void TurnCursorOn( void )
-{
- mouse_active = ~0;
-#if defined ( WIN32 ) || defined(__CYGWIN32__)
- glutSetCursor(GLUT_CURSOR_INHERIT);
-#endif
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
- glutWarpPointer( glutGet(GLUT_SCREEN_WIDTH)/2, glutGet(GLUT_SCREEN_HEIGHT)/2);
-#endif
-}
-
-static inline void TurnCursorOff( void )
-{
- mouse_active = 0;
-#if defined ( WIN32 ) || defined(__CYGWIN32__)
- glutSetCursor(GLUT_CURSOR_NONE);
-#else // I guess this is what we want to do ??
-#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
- glutWarpPointer( glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT));
-#endif
-#endif
-}
-
-void maybeToggleMouse( void )
-{
-#ifdef WIN32
- static int first_time = ~0;
- static int mouse_changed = 0;
-
- if ( first_time ) {
- if(!mouse_active) {
- mouse_changed = ~mouse_changed;
- TurnCursorOn();
- }
- } else {
- if( mouse_changed ) {
- mouse_changed = ~mouse_changed;
- if(mouse_active) {
- TurnCursorOff();
- }
- }
- }
- first_time = ~first_time;
-#endif // #ifdef WIN32
-}