]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui.cxx
Make sure that all elapsed time gets passed to update when a subsystem
[flightgear.git] / src / GUI / gui.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., 675 Mass Ave, Cambridge, MA 02139, 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 HAVE_WINDOWS_H
34 #  include <windows.h>
35 #endif
36
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>
41
42 #include <plib/pu.h>
43
44 #include <Include/general.hxx>
45 #include <Main/globals.hxx>
46 #include <Main/fg_props.hxx>
47
48 #include "gui.h"
49 #include "gui_local.hxx"
50 #include "net_dlg.hxx"
51 #include "preset_dlg.hxx"
52
53
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 );
58
59 extern void initDialog (void);
60 extern void mkDialogInit (void);
61 extern void ConfirmExitDialogInit(void);
62
63
64 puFont guiFnt = 0;
65 fntTexFont *guiFntHandle = 0;
66 #if defined(FG_OLD_MENUBAR)
67 int gui_menu_on = 0;
68 puMenuBar    *mainMenuBar = 0;
69 //static puButton     *hideMenuButton = 0;
70
71
72 struct fg_gui_t {
73         char *name;
74         char **submenu;
75         puCallback *cb;
76 } *Menu;
77 unsigned int Menu_size;
78
79 void initMenu()
80 {
81      SGPropertyNode main;
82
83      try {
84          fgLoadProps("menu.xml", &main);
85      } catch (const sg_exception &ex) {
86          SG_LOG(SG_GENERAL, SG_ALERT, "Error processing the menu file.");
87          return;
88      }
89
90      SG_LOG(SG_GENERAL, SG_INFO, "Reading menu entries.");
91
92      // Make the menu bar
93      mainMenuBar = new puMenuBar ();
94
95      SGPropertyNode *menu = main.getChild("menu");
96      SGPropertyNode *locale = globals->get_locale();
97
98      vector<SGPropertyNode_ptr>submenu = menu->getChildren("submenu");
99
100      Menu_size = 1+submenu.size();
101      Menu = (fg_gui_t *)calloc(Menu_size, sizeof(fg_gui_t));
102
103      for (unsigned int h = 0; h < submenu.size(); h++) {
104
105          vector<SGPropertyNode_ptr>option = submenu[h]->getChildren("option");
106
107          //
108          // Make sure all entries will fit into allocated memory
109          //
110          Menu[h].submenu = (char **)calloc(1+option.size(), sizeof(char *));
111          Menu[h].cb = (puCallback *)calloc(1+option.size(), sizeof(puCallback));
112
113          for (unsigned int i = 0; i < option.size(); i++) {
114
115              SGPropertyNode *name = option[i]->getNode("name");
116              SGPropertyNode *call = option[i]->getNode("call");
117              SGPropertyNode *sep = option[i]->getNode("seperator");
118
119              int pos = option.size()-i-1;
120              if (sep) {
121                 Menu[h].submenu[pos] = strdup("----------");
122              } else if (call && strcmp(call->getStringValue(), "")) {
123                  string text = locale->getStringValue( name->getStringValue(),
124                                                        "strings/null" );
125                  Menu[h].submenu[pos]
126                      = strdup(text.c_str());
127              } else {
128                  Menu[h].submenu[pos] = strdup("not specified");
129              }
130
131              Menu[h].cb[pos] = NULL;
132              for (unsigned int j=0; __fg_gui_fn[j].fn; j++)
133                  if (call &&
134                      !strcmp(call->getStringValue(), __fg_gui_fn[j].name) )
135                  {
136                      Menu[h].cb[pos] = __fg_gui_fn[j].fn;
137                      break;
138                  }
139          }
140
141          SGPropertyNode *name = submenu[h]->getNode("name");
142          string text = locale->getStringValue( name->getStringValue(),
143                                                "strings/null" );
144
145          Menu[h].name = strdup(text.c_str());
146          mainMenuBar->add_submenu(Menu[h].name, Menu[h].submenu, Menu[h].cb);
147
148     }
149
150     mainMenuBar->close();
151 }
152
153
154 // FIXME: Has to be called from somewhere
155 //        or better yet, turn the menu into a class of its own
156 void destroyMenu(void) {
157     for(unsigned int i=0; i < Menu_size; i++) {
158
159         free(Menu[i].name);
160
161                                 // FIXME: don't use strdup/free
162         for(unsigned int j=0; Menu[i].submenu[j] != NULL; j++)
163            free(Menu[i].submenu[j]);
164     }
165 }
166 #endif
167
168
169
170 /* -------------------------------------------------------------------------
171 init the gui
172 _____________________________________________________________________*/
173
174
175 void guiInit()
176 {
177     char *mesa_win_state;
178
179     // Initialize PUI
180     puInit();
181     puSetDefaultStyle         ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
182     puSetDefaultColourScheme  (0.8, 0.8, 0.9, 0.8);
183
184     initDialog();
185
186     // Next check home directory
187     SGPath fntpath;
188     char* envp = ::getenv( "FG_FONTS" );
189     if ( envp != NULL ) {
190         fntpath.set( envp );
191     } else {
192         fntpath.set( globals->get_fg_root() );
193         fntpath.append( "Fonts" );
194     }
195
196     // Install our fast fonts
197     SGPropertyNode *locale = globals->get_locale();
198     fntpath.append(locale->getStringValue("font", "typewriter.txf"));
199     guiFntHandle = new fntTexFont ;
200     guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
201     puFont GuiFont ( guiFntHandle, 15 ) ;
202     puSetDefaultFonts( GuiFont, GuiFont ) ;
203     guiFnt = puGetDefaultLabelFont();
204   
205     if (!fgHasNode("/sim/startup/mouse-pointer")) {
206         // no preference specified for mouse pointer, attempt to autodetect...
207         // Determine if we need to render the cursor, or if the windowing
208         // system will do it.  First test if we are rendering with glide.
209         if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
210             // Test for the MESA_GLX_FX env variable
211             if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
212                 // test if we are fullscreen mesa/glide
213                 if ( (mesa_win_state[0] == 'f') ||
214                      (mesa_win_state[0] == 'F') ) {
215                     puShowCursor ();
216                 }
217             }
218         }
219 //        mouse_active = ~mouse_active;
220     } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
221         // don't show pointer
222     } else {
223         // force showing pointer
224         puShowCursor();
225 //        mouse_active = ~mouse_active;
226     }
227         
228     // MOUSE_VIEW mode stuff
229         initMouseQuat();
230
231     // Set up our Dialog Boxes
232     ConfirmExitDialogInit();
233     fgPresetInit();
234         
235 #ifdef FG_NETWORK_OLK
236     NewNetIdInit();
237     NewNetFGDInit();
238 #endif
239
240     mkDialogInit();
241
242 #if defined(FG_OLD_MENUBAR)
243     initMenu();
244     
245     // Set up menu bar toggle
246     gui_menu_on = ~0;
247
248     if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
249         guiToggleMenu(); // Menu off by default
250     }
251 #endif
252 }