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>
37 #include <simgear/misc/props.hxx>
38 #include <simgear/misc/props_io.hxx>
39 #include <simgear/misc/exception.hxx>
40 #include <simgear/misc/sg_path.hxx>
44 #include <Include/general.hxx>
45 #include <Main/globals.hxx>
46 #include <Main/fg_props.hxx>
49 #include "gui_local.hxx"
50 #include "apt_dlg.hxx"
51 #include "net_dlg.hxx"
54 // main.cxx hack, should come from an include someplace
55 extern void fgInitVisuals( void );
56 extern void fgReshape( int width, int height );
57 extern void fgRenderFrame( void );
59 extern void initDialog (void);
60 extern void mkDialogInit (void);
61 extern void ConfirmExitDialogInit(void);
65 fntTexFont *guiFntHandle = 0;
67 puMenuBar *mainMenuBar = 0;
68 //static puButton *hideMenuButton = 0;
76 unsigned int Menu_size;
81 SGPath spath( globals->get_fg_root() );
82 spath.append( "menu.xml" );
85 readProperties(spath.c_str(), &main);
86 } catch (const sg_exception &ex) {
87 SG_LOG(SG_GENERAL, SG_ALERT, "Error processing the menu file.");
91 SG_LOG(SG_GENERAL, SG_INFO, "Reading menu entries.");
94 mainMenuBar = new puMenuBar ();
96 SGPropertyNode *menu = main.getChild("menu");
98 vector<SGPropertyNode_ptr>submenu = menu->getChildren("submenu");
100 Menu_size = 1+submenu.size();
101 Menu = (fg_gui_t *)calloc(Menu_size, sizeof(fg_gui_t));
103 for (unsigned int h = 0; h < submenu.size(); h++) {
105 vector<SGPropertyNode_ptr>option = submenu[h]->getChildren("option");
108 // Make sure all entries will fit into allocated memory
110 Menu[h].submenu = (char **)calloc(1+option.size(), sizeof(char *));
111 Menu[h].cb = (puCallback *)calloc(1+option.size(), sizeof(puCallback));
113 for (unsigned int i = 0; i < option.size(); i++) {
115 SGPropertyNode *name = option[i]->getNode("name");
116 SGPropertyNode *call = option[i]->getNode("call");
117 SGPropertyNode *sep = option[i]->getNode("seperator");
119 int pos = option.size()-i-1;
121 Menu[h].submenu[pos] = strdup("----------");
122 } else if (call && strcmp(call->getStringValue(), "")) {
123 cout << name->getStringValue() << endl;
124 string text = fgGetString( name->getStringValue(),
127 = strdup(text.c_str());
129 Menu[h].submenu[pos] = strdup("not specified");
132 Menu[h].cb[pos] = NULL;
133 for (unsigned int j=0; __fg_gui_fn[j].fn; j++)
135 !strcmp(call->getStringValue(), __fg_gui_fn[j].name) )
137 Menu[h].cb[pos] = __fg_gui_fn[j].fn;
142 SGPropertyNode *name = submenu[h]->getNode("name");
143 cout << name->getStringValue() << endl;
144 string text = fgGetString( name->getStringValue(),
147 Menu[h].name = strdup(text.c_str());
148 mainMenuBar->add_submenu(Menu[h].name, Menu[h].submenu, Menu[h].cb);
152 mainMenuBar->close();
156 // FIXME: Has to be called from somewhere
157 // or better yet, turn the menu into a class of its own
158 void destroyMenu(void) {
159 for(unsigned int i=0; i < Menu_size; i++) {
163 // FIXME: don't use strdup/free
164 for(unsigned int j=0; Menu[i].submenu[j] != NULL; j++)
165 free(Menu[i].submenu[j]);
172 /* -------------------------------------------------------------------------
174 _____________________________________________________________________*/
179 char *mesa_win_state;
183 puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
184 puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.4);
188 // Next check home directory
190 char* envp = ::getenv( "FG_FONTS" );
191 if ( envp != NULL ) {
194 fntpath.set( globals->get_fg_root() );
195 fntpath.append( "Fonts" );
198 // Install our fast fonts
199 fntpath.append(fgGetString("/sim/font", "typewriter.txf"));
200 guiFntHandle = new fntTexFont ;
201 guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
202 puFont GuiFont ( guiFntHandle, 15 ) ;
203 puSetDefaultFonts( GuiFont, GuiFont ) ;
204 guiFnt = puGetDefaultLabelFont();
206 if (!fgHasNode("/sim/startup/mouse-pointer")) {
207 // no preference specified for mouse pointer, attempt to autodetect...
208 // Determine if we need to render the cursor, or if the windowing
209 // system will do it. First test if we are rendering with glide.
210 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
211 // Test for the MESA_GLX_FX env variable
212 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
213 // test if we are fullscreen mesa/glide
214 if ( (mesa_win_state[0] == 'f') ||
215 (mesa_win_state[0] == 'F') ) {
220 // mouse_active = ~mouse_active;
221 } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
222 // don't show pointer
224 // force showing pointer
226 // mouse_active = ~mouse_active;
229 // MOUSE_VIEW mode stuff
232 // Set up our Dialog Boxes
233 ConfirmExitDialogInit();
236 #ifdef FG_NETWORK_OLK
245 // Set up menu bar toggle
248 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
249 guiToggleMenu(); // Menu off by default