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., 675 Mass Ave, Cambridge, MA 02139, USA.
24 **************************************************************************/
31 #include <simgear/compiler.h>
33 #ifdef SG_MATH_EXCEPTION_CLASH
44 #if defined(FX) && defined(XMESA)
45 # include <GL/xmesa.h>
54 #include <simgear/constants.h>
55 #include <simgear/debug/logstream.hxx>
56 #include <simgear/misc/sg_path.hxx>
57 #include <simgear/screen/screen-dump.hxx>
59 #include <Include/general.hxx>
60 #include <Aircraft/aircraft.hxx>
61 #include <Airports/simple.hxx>
62 #include <Autopilot/auto_gui.hxx>
63 #include <Autopilot/newauto.hxx>
64 #include <Cockpit/panel.hxx>
65 #include <Controls/controls.hxx>
66 #include <FDM/flight.hxx>
67 #include <Main/fg_init.hxx>
68 #include <Main/fg_io.hxx>
69 #include <Main/globals.hxx>
70 #include <Main/fg_props.hxx>
71 #include <Main/viewmgr.hxx>
74 #include <NetworkOLK/network.h>
77 #if defined( WIN32 ) && !defined( __CYGWIN__ ) && !defined(__MINGW32__)
78 # include <simgear/screen/win32-printer.h>
79 # include <simgear/screen/GlBitmaps.h>
83 #include "gui_local.hxx"
84 #include "apt_dlg.hxx"
85 #include "net_dlg.hxx"
86 #include "sgVec3Slider.hxx"
87 #include "prop_picker.hxx"
91 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
95 // main.cxx hack, should come from an include someplace
96 extern void fgInitVisuals( void );
97 extern void fgReshape( int width, int height );
98 extern void fgRenderFrame( void );
100 extern void initDialog (void);
101 extern void mkDialogInit (void);
102 extern void ConfirmExitDialogInit(void);
106 fntTexFont *guiFntHandle = 0;
108 puMenuBar *mainMenuBar = 0;
109 //static puButton *hideMenuButton = 0;
112 extern void fgLatLonFormatToggle( puObject *);
114 // from gui_funcs.cxx
115 extern void saveFlight(puObject *);
116 extern void loadFlight(puObject *);
117 extern void reInit(puObject *);
118 extern void dumpSnapShot(puObject *);
120 extern void dumpHiResSnapShot(puObject *);
122 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
123 extern void printScreen(puObject *);
125 extern void MayBeGoodBye(puObject *);
126 extern void guiTogglePanel(puObject *);
127 extern void PilotOffsetAdjust(puObject *);
128 extern void fgHUDalphaAdjust(puObject *);
129 extern void prop_pickerView(puObject *);
130 extern void NewAirport(puObject *);
131 #ifdef FG_NETWORK_OLK
132 extern void net_display_toggle(puObject *);
133 extern void NewCallSign(puObject *);
134 extern void net_fgd_scan(puObject *);
135 extern void net_register(puObject *);
136 extern void net_unregister(puObject *);
138 extern void NewAltitude(puObject *);
139 extern void AddWayPoint(puObject *);
140 extern void PopWayPoint(puObject *);
141 extern void ClearRoute(puObject *);
142 extern void fgAPAdjust(puObject *);
143 extern void fgLatLonFormatToggle(puObject *);
144 extern void helpCb(puObject *);
146 static const struct {
148 void (*fn)(puObject *);
152 {"saveFlight", saveFlight},
153 {"loadFlight", loadFlight},
156 {"dumpHiResSnapShot", dumpHiResSnapShot},
158 {"dumpSnapShot", dumpSnapShot},
159 #if defined( WIN32 ) && !defined( __CYGWIN__) && !defined(__MINGW32__)
160 {"printScreen", printScreen},
162 {"MayBeGoodBye", MayBeGoodBye},
165 {"guiTogglePanel", guiTogglePanel},
166 {"PilotOffsetAdjust", PilotOffsetAdjust},
167 {"fgHUDalphaAdjust", fgHUDalphaAdjust},
168 {"prop_pickerView", prop_pickerView},
171 {"NewAirport", NewAirport},
174 #ifdef FG_NETWORK_OLK
175 {"net_display_toggle", net_display_toggle},
176 {"NewCallSign", NewCallSign},
177 {"net_fgd_scan", net_fgd_scan},
178 {"net_register", net_register},
179 {"net_unregister", net_unregister},
183 {"NewAltitude", NewAltitude},
184 {"AddWayPoint", AddWayPoint},
185 {"PopWayPoint", PopWayPoint},
186 {"ClearRoute", ClearRoute},
187 {"fgAPAdjust", fgAPAdjust},
188 {"fgLatLonFormatToggle", fgLatLonFormatToggle},
193 // Structure termination
204 unsigned int Menu_size;
209 SGPath spath( globals->get_fg_root() );
210 spath.append( "menu.xml" );
213 readProperties(spath.c_str(), &main);
214 } catch (const sg_exception &ex) {
215 SG_LOG(SG_GENERAL, SG_ALERT, "Error processing the menu file.");
219 SG_LOG(SG_GENERAL, SG_INFO, "Reading menu entries.");
222 mainMenuBar = new puMenuBar ();
224 SGPropertyNode *menu = main.getChild("menu");
226 vector<SGPropertyNode_ptr>submenu = menu->getChildren("submenu");
228 Menu_size = 1+submenu.size();
229 Menu = (fg_gui_t *)calloc(Menu_size, sizeof(fg_gui_t));
231 for (unsigned int h = 0; h < submenu.size(); h++) {
233 vector<SGPropertyNode_ptr>option = submenu[h]->getChildren("option");
236 // Make sure all entries will fit into allocated memory
238 Menu[h].submenu = (char **)calloc(1+option.size(), sizeof(char *));
239 Menu[h].cb = (puCallback *)calloc(1+option.size(), sizeof(puCallback));
241 for (unsigned int i = 0; i < option.size(); i++) {
243 SGPropertyNode *name = option[i]->getNode("name");
244 SGPropertyNode *call = option[i]->getNode("call");
245 SGPropertyNode *sep = option[i]->getNode("seperator");
248 Menu[h].submenu[i] = strdup("----------");
250 else if (call && strcmp(call->getStringValue(), ""))
251 Menu[h].submenu[i] = strdup(name->getStringValue());
254 Menu[h].submenu[i] = strdup("not specified");
256 Menu[h].cb[i] = NULL;
257 for (unsigned int j=0; __fg_gui_fn[j].fn; j++)
259 !strcmp(call->getStringValue(), __fg_gui_fn[j].name) )
261 Menu[h].cb[i] = __fg_gui_fn[j].fn;
266 SGPropertyNode *name = submenu[h]->getNode("name");
268 Menu[h].name = strdup(name->getStringValue());
269 mainMenuBar->add_submenu(Menu[h].name, Menu[h].submenu, Menu[h].cb);
273 mainMenuBar->close();
277 // FIXME: Has to be called from somewhere
278 // or better yet, turn the menu into a class of its own
279 void destroyMenu(void) {
280 for(unsigned int i=0; i < Menu_size; i++) {
284 // FIXME: don't use strdup/free
285 for(unsigned int j=0; Menu[i].submenu[j] != NULL; j++)
286 free(Menu[i].submenu[j]);
293 /* -------------------------------------------------------------------------
295 _____________________________________________________________________*/
300 char *mesa_win_state;
304 puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
305 puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.4);
309 // Next check home directory
311 char* envp = ::getenv( "FG_FONTS" );
312 if ( envp != NULL ) {
315 fntpath.set( globals->get_fg_root() );
316 fntpath.append( "Fonts" );
319 // Install our fast fonts
320 fntpath.append( "typewriter.txf" );
321 guiFntHandle = new fntTexFont ;
322 guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
323 puFont GuiFont ( guiFntHandle, 15 ) ;
324 puSetDefaultFonts( GuiFont, GuiFont ) ;
325 guiFnt = puGetDefaultLabelFont();
327 if (!fgHasNode("/sim/startup/mouse-pointer")) {
328 // no preference specified for mouse pointer, attempt to autodetect...
329 // Determine if we need to render the cursor, or if the windowing
330 // system will do it. First test if we are rendering with glide.
331 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
332 // Test for the MESA_GLX_FX env variable
333 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
334 // test if we are fullscreen mesa/glide
335 if ( (mesa_win_state[0] == 'f') ||
336 (mesa_win_state[0] == 'F') ) {
341 // mouse_active = ~mouse_active;
342 } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
343 // don't show pointer
345 // force showing pointer
347 // mouse_active = ~mouse_active;
350 // MOUSE_VIEW mode stuff
353 // Set up our Dialog Boxes
354 ConfirmExitDialogInit();
357 #ifdef FG_NETWORK_OLK
366 // Set up menu bar toggle
369 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
370 guiToggleMenu(); // Menu off by default