]> git.mxchange.org Git - flightgear.git/blob - src/GUI/mouse.cxx
don't initialize iterator twice
[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 #include "gui_local.hxx"
68
69 SG_USING_STD(string);
70 SG_USING_STD(cout);
71
72 /* --------------------------------------------------------------------
73 Mouse stuff
74 ---------------------------------------------------------------------*/
75
76 static int mouse_active = 0;
77
78 static int MOUSE_XSIZE = 0;
79 static int MOUSE_YSIZE = 0;
80
81 /* --------------------------------------------------------------------
82 Support for mouse as control yoke (david@megginson.com)
83
84 - right button toggles between pointer and yoke
85 - horizontal drag with no buttons moves ailerons
86 - vertical drag with no buttons moves elevators
87 - horizontal drag with left button moves brakes (left=on)
88 - vertical drag with left button moves throttle (up=more)
89 - horizontal drag with middle button moves rudder
90 - vertical drag with middle button moves trim
91
92 For the *_sensitivity variables, a lower number means more sensitive.
93
94 TODO: figure out how to keep pointer from leaving window in yoke mode.
95 TODO: add thresholds and null zones
96 TODO: sensitivity should be configurable at user option.
97 TODO: allow differential braking (this will be useful if FlightGear
98       ever supports tail-draggers like the DC-3)
99 ---------------------------------------------------------------------*/
100
101 MouseMode mouse_mode = MOUSE_POINTER;
102
103 void guiInitMouse(int width, int height)
104 {
105         MOUSE_XSIZE = width;
106         MOUSE_YSIZE = height;
107 }
108
109 void TurnCursorOn( void )
110 {
111     mouse_active = ~0;
112 #if defined(WIN32)
113     switch (mouse_mode) {
114         case MOUSE_POINTER:
115             fgSetMouseCursor(MOUSE_CURSOR_POINTER);
116             break;
117         case MOUSE_YOKE:
118             fgSetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
119             break;
120         case MOUSE_VIEW:
121             fgSetMouseCursor(MOUSE_CURSOR_LEFTRIGHT);
122             break;
123     }
124 #endif
125 #if defined(X_CURSOR_TWEAKS)
126     fgWarpMouse( MOUSE_XSIZE/2, MOUSE_YSIZE/2 );
127 #endif
128 }
129
130 void TurnCursorOff( void )
131 {
132     mouse_active = 0;
133 #if defined(WIN32_CURSOR_TWEAKS)
134     fgSetMouseCursor(MOUSE_CURSOR_NONE);
135 #elif defined(X_CURSOR_TWEAKS)
136     fgWarpMouse( MOUSE_XSIZE, MOUSE_YSIZE );
137 #endif
138 }
139
140 void maybeToggleMouse( void )
141 {
142 #if defined(WIN32_CURSOR_TWEAKS_OFF)
143     static int first_time = ~0;
144     static int mouse_changed = 0;
145
146     if ( first_time ) {
147         if(!mouse_active) {
148             mouse_changed = ~mouse_changed;
149             TurnCursorOn();
150         }
151     } else {
152         if( mouse_mode != MOUSE_POINTER )
153             return;
154         if( mouse_changed ) {
155             mouse_changed = ~mouse_changed;
156             if(mouse_active) {
157                 TurnCursorOff();
158             }
159         }
160     }
161     first_time = ~first_time;
162 #endif // #ifdef WIN32
163 }
164