]> git.mxchange.org Git - flightgear.git/blob - src/GUI/mouse.cxx
remove depreciated gui_local.[ch]xx:
[flightgear.git] / src / GUI / mouse.cxx
1 /**************************************************************************
2  * gui.cxx
3  *
4  * Written 1998 by Durk Talsma, started Juni, 1998.  For the flight gear
5  * project.
6  *
7  * Additional mouse supported added by David Megginson, 1999.
8  *
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.
13  *
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.
18  *
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.
22  *
23  * $Id$
24  **************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include <simgear/compiler.h>
32
33 #ifdef SG_MATH_EXCEPTION_CLASH
34 #  include <math.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <Main/fg_os.hxx>
42
43 #if defined(FX) && defined(XMESA)
44 #  include <GL/xmesa.h>
45 #endif
46
47 #include STL_STRING
48
49 #include <stdlib.h>
50 #include <string.h>
51
52 #include <simgear/constants.h>
53 #include <simgear/debug/logstream.hxx>
54 #include <simgear/misc/sg_path.hxx>
55
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>
65
66 #include "gui.h"
67
68 SG_USING_STD(string);
69 SG_USING_STD(cout);
70
71 /* --------------------------------------------------------------------
72 Mouse stuff
73 ---------------------------------------------------------------------*/
74
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
81 #endif
82
83 static int mouse_active = 0;
84
85 static int MOUSE_XSIZE = 0;
86 static int MOUSE_YSIZE = 0;
87
88 typedef enum {
89         MOUSE_POINTER,
90         MOUSE_YOKE,
91         MOUSE_VIEW
92 } MouseMode;
93
94 /* --------------------------------------------------------------------
95 Support for mouse as control yoke (david@megginson.com)
96
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
104
105 For the *_sensitivity variables, a lower number means more sensitive.
106
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 ---------------------------------------------------------------------*/
113
114 MouseMode mouse_mode = MOUSE_POINTER;
115
116 void guiInitMouse(int width, int height)
117 {
118         MOUSE_XSIZE = width;
119         MOUSE_YSIZE = height;
120 }
121
122 void TurnCursorOn( void )
123 {
124     mouse_active = ~0;
125 #if defined(WIN32)
126     switch (mouse_mode) {
127         case MOUSE_POINTER:
128             fgSetMouseCursor(MOUSE_CURSOR_POINTER);
129             break;
130         case MOUSE_YOKE:
131             fgSetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
132             break;
133         case MOUSE_VIEW:
134             fgSetMouseCursor(MOUSE_CURSOR_LEFTRIGHT);
135             break;
136     }
137 #endif
138 #if defined(X_CURSOR_TWEAKS)
139     fgWarpMouse( MOUSE_XSIZE/2, MOUSE_YSIZE/2 );
140 #endif
141 }
142
143 void TurnCursorOff( void )
144 {
145     mouse_active = 0;
146 #if defined(WIN32_CURSOR_TWEAKS)
147     fgSetMouseCursor(MOUSE_CURSOR_NONE);
148 #elif defined(X_CURSOR_TWEAKS)
149     fgWarpMouse( MOUSE_XSIZE, MOUSE_YSIZE );
150 #endif
151 }
152
153 void maybeToggleMouse( void )
154 {
155 #if defined(WIN32_CURSOR_TWEAKS_OFF)
156     static int first_time = ~0;
157     static int mouse_changed = 0;
158
159     if ( first_time ) {
160         if(!mouse_active) {
161             mouse_changed = ~mouse_changed;
162             TurnCursorOn();
163         }
164     } else {
165         if( mouse_mode != MOUSE_POINTER )
166             return;
167         if( mouse_changed ) {
168             mouse_changed = ~mouse_changed;
169             if(mouse_active) {
170                 TurnCursorOff();
171             }
172         }
173     }
174     first_time = ~first_time;
175 #endif // #ifdef WIN32
176 }
177