1 /**************************************************************************
4 * Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
7 * Additional mouse supported added by David Megginson, 1999.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 **************************************************************************/
31 #include <simgear/compiler.h>
33 #ifdef SG_MATH_EXCEPTION_CLASH
41 #include <Main/fg_os.hxx>
43 #if defined(FX) && defined(XMESA)
44 # include <GL/xmesa.h>
52 #include <simgear/constants.h>
53 #include <simgear/debug/logstream.hxx>
54 #include <simgear/misc/sg_path.hxx>
56 #include <Include/general.hxx>
57 #include <Aircraft/aircraft.hxx>
58 #include <Aircraft/controls.hxx>
59 #include <Airports/simple.hxx>
60 #include <Cockpit/panel.hxx>
61 #include <FDM/flight.hxx>
62 #include <Main/fg_init.hxx>
63 #include <Main/fg_props.hxx>
64 #include <Main/viewmgr.hxx>
71 /* --------------------------------------------------------------------
73 ---------------------------------------------------------------------*/
75 #if defined(WIN32) || defined(__CYGWIN32__)
76 #define WIN32_CURSOR_TWEAKS
77 // uncomment this for cursor to turn off when menu is disabled
78 // #define WIN32_CURSOR_TWEAKS_OFF
79 #elif (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
80 #define X_CURSOR_TWEAKS
83 static int mouse_active = 0;
85 static int MOUSE_XSIZE = 0;
86 static int MOUSE_YSIZE = 0;
94 /* --------------------------------------------------------------------
95 Support for mouse as control yoke (david@megginson.com)
97 - right button toggles between pointer and yoke
98 - horizontal drag with no buttons moves ailerons
99 - vertical drag with no buttons moves elevators
100 - horizontal drag with left button moves brakes (left=on)
101 - vertical drag with left button moves throttle (up=more)
102 - horizontal drag with middle button moves rudder
103 - vertical drag with middle button moves trim
105 For the *_sensitivity variables, a lower number means more sensitive.
107 TODO: figure out how to keep pointer from leaving window in yoke mode.
108 TODO: add thresholds and null zones
109 TODO: sensitivity should be configurable at user option.
110 TODO: allow differential braking (this will be useful if FlightGear
111 ever supports tail-draggers like the DC-3)
112 ---------------------------------------------------------------------*/
114 MouseMode mouse_mode = MOUSE_POINTER;
116 void guiInitMouse(int width, int height)
119 MOUSE_YSIZE = height;
122 void TurnCursorOn( void )
126 switch (mouse_mode) {
128 fgSetMouseCursor(MOUSE_CURSOR_POINTER);
131 fgSetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
134 fgSetMouseCursor(MOUSE_CURSOR_LEFTRIGHT);
138 #if defined(X_CURSOR_TWEAKS)
139 fgWarpMouse( MOUSE_XSIZE/2, MOUSE_YSIZE/2 );
143 void TurnCursorOff( void )
146 #if defined(WIN32_CURSOR_TWEAKS)
147 fgSetMouseCursor(MOUSE_CURSOR_NONE);
148 #elif defined(X_CURSOR_TWEAKS)
149 fgWarpMouse( MOUSE_XSIZE, MOUSE_YSIZE );
153 void maybeToggleMouse( void )
155 #if defined(WIN32_CURSOR_TWEAKS_OFF)
156 static int first_time = ~0;
157 static int mouse_changed = 0;
161 mouse_changed = ~mouse_changed;
165 if( mouse_mode != MOUSE_POINTER )
167 if( mouse_changed ) {
168 mouse_changed = ~mouse_changed;
174 first_time = ~first_time;
175 #endif // #ifdef WIN32