]> git.mxchange.org Git - flightgear.git/blob - Simulator/GUI/gui.cxx
Initial revision.
[flightgear.git] / Simulator / 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  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * $Id$
22  **************************************************************************/
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef HAVE_WINDOWS_H
30 #  include <windows.h>                     
31 #endif
32
33 #include <Include/compiler.h>
34
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37
38 #if defined(FX) && defined(XMESA)
39 #  include <GL/xmesa.h>
40 #endif
41
42 #include STL_STRING
43
44 #include <stdlib.h>
45 #include <string.h>
46
47 #include <Include/general.hxx>
48 #include <Main/options.hxx>
49
50 #include "gui.h"
51
52 FG_USING_STD(string);
53
54
55 puMenuBar    *mainMenuBar;
56 puButton     *hideMenuButton;
57 puDialogBox  *dialogBox;
58 puText       *dialogBoxMessage;
59 puOneShot    *dialogBoxOkButton;
60 puText       *timerText;
61
62 /* --------------------------------------------------------------------
63        Mouse stuff 
64   ---------------------------------------------------------------------*/
65
66 void guiMotionFunc ( int x, int y )
67 {
68   puMouse ( x, y ) ;
69   glutPostRedisplay () ;
70 }
71
72
73 void guiMouseFunc(int button, int updown, int x, int y)
74 {
75     puMouse (button, updown, x,y);
76     glutPostRedisplay ();
77 }
78
79 /* -----------------------------------------------------------------------
80   the Gui callback functions 
81   ____________________________________________________________________*/
82
83 void hideMenuCb (puObject *cb)
84 {
85   if (cb -> getValue () )
86     {
87       mainMenuBar -> reveal();
88       printf("Showing Menu");
89       hideMenuButton -> setLegend ("Hide Menu");
90     }
91   else
92     {
93       mainMenuBar -> hide  ();
94       printf("Hiding Menu");
95       hideMenuButton -> setLegend ("Show Menu");
96     }
97 }
98
99  void goAwayCb (puObject *)
100 {
101   delete dialogBox;
102   dialogBox = NULL;
103 }
104
105 void mkDialog (char *txt)
106 {
107   dialogBox = new puDialogBox (150, 50);
108   {
109     new puFrame (0,0,400, 100);
110     dialogBoxMessage =   new puText         (10, 70);
111     dialogBoxMessage ->  setLabel           (txt);
112     dialogBoxOkButton =  new puOneShot      (180, 10, 240, 50);
113     dialogBoxOkButton -> setLegend          ("OK");
114     dialogBoxOkButton -> makeReturnDefault  (TRUE );
115     dialogBoxOkButton -> setCallback        (goAwayCb);
116   }
117   dialogBox -> close();
118   dialogBox -> reveal();
119 }
120
121 void notCb (puObject *)
122 {
123   mkDialog ("This function isn't implemented yet");
124 }
125
126 void helpCb (puObject *)
127 {
128 #if defined(FX) && !defined(WIN32)
129 #  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
130     if ( global_fullscreen ) {
131         global_fullscreen = false;
132         XMesaSetFXmode( XMESA_FX_WINDOW );
133     }
134 #  endif
135 #endif
136
137 #if !defined(WIN32)
138     string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
139     string command;
140
141     if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
142         command = "netscape -remote \"openURL(" + url + ")\" &";
143     } else {
144         command = "netscape " + url + " &";
145     }
146
147     system( command.c_str() );
148     string text = "Help started in netscape window.";
149 #else
150     string text = "Help not yet implimented for Win32.";
151 #endif
152
153     mkDialog ( (char*)text.c_str() );
154 }
155
156 /* -----------------------------------------------------------------------
157    The menu stuff 
158    ---------------------------------------------------------------------*/
159 char *fileSubmenu        [] = { "Exit", "Close", "---------", "Print", "---------", "Save", "New", NULL };
160 char *editSubmenu        [] = { "Edit text", NULL };
161 char *viewSubmenu        [] = { "Cockpit View > ", "View >","------------", "View options...", NULL };
162 char *aircraftSubmenu    [] = { "Autopilot ...", "Engine ...", "Navigation", "Communication", NULL};
163 char *environmentSubmenu [] = { "Time & Date...", "Terrain ...", "Weather", NULL};
164 char *optionsSubmenu     [] = { "Preferences", "Realism & Reliablity...", NULL};
165 char *helpSubmenu        [] = { "About...", "Help", NULL };
166
167 puCallback fileSubmenuCb        [] = { notCb, notCb, NULL, notCb, NULL, notCb, notCb, NULL};
168 puCallback editSubmenuCb        [] = { notCb, NULL };
169 puCallback viewSubmenuCb        [] = { notCb, notCb, NULL, notCb, NULL };
170 puCallback aircraftSubmenuCb    [] = { notCb, notCb, notCb,notCb, NULL };
171 puCallback environmentSubmenuCb [] = { notCb, notCb, notCb, NULL };
172 puCallback optionsSubmenuCb     [] = { notCb, notCb, NULL};
173 puCallback helpSubmenuCb        [] = { notCb, helpCb, NULL };
174
175  
176
177 /* -------------------------------------------------------------------------
178    init the gui
179    _____________________________________________________________________*/
180
181
182
183 void guiInit()
184 {
185     char *mesa_win_state;
186
187     // Initialize PUI
188     puInit();
189
190     if ( current_options.get_mouse_pointer() == 0 ) {
191         // no preference specified for mouse pointer, attempt to autodetect...
192         // Determine if we need to render the cursor, or if the windowing
193         // system will do it.  First test if we are rendering with glide.
194         if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
195             // Test for the MESA_GLX_FX env variable
196             if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
197                 // test if we are fullscreen mesa/glide
198                 if ( (mesa_win_state[0] == 'f') || 
199                      (mesa_win_state[0] == 'F') ) {
200                     puShowCursor ();
201                 }
202             }
203         }
204     } else if ( current_options.get_mouse_pointer() == 1 ) {
205         // don't show pointer
206     } else if ( current_options.get_mouse_pointer() == 2 ) {
207         // force showing pointer
208         puShowCursor();
209     }
210
211     // puSetDefaultStyle         ( PUSTYLE_SMALL_BEVELLED );
212     puSetDefaultStyle         ( PUSTYLE_DEFAULT );
213     // puSetDefaultColourScheme  (0.2, 0.4, 0.8, 0.5);
214     puSetDefaultColourScheme  (0.8, 0.8, 0.8, 0.5);
215       
216     /* OK the rest is largerly put in here to mimick Steve Baker's
217        "complex" example It should change in future versions */
218       
219     // timerText = new puText (300, 10);
220     // timerText -> setColour (PUCOL_LABEL, 1.0, 1.0, 1.0);
221
222     /* Make a button to hide the menu bar */
223     hideMenuButton = new puButton       (10,10, 150, 50);
224     hideMenuButton -> setValue          (TRUE);
225     hideMenuButton -> setLegend         ("Hide Menu");
226     hideMenuButton -> setCallback       (hideMenuCb);
227     hideMenuButton -> makeReturnDefault (TRUE);
228     hideMenuButton -> hide();
229
230     // Make the menu bar
231     mainMenuBar = new puMenuBar ();
232     mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
233     mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
234     mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
235     mainMenuBar -> add_submenu ("Aircraft", aircraftSubmenu, aircraftSubmenuCb);
236     mainMenuBar -> add_submenu ("Environment", environmentSubmenu, 
237                                 environmentSubmenuCb);
238     mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
239     mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
240     mainMenuBar-> close ();
241 }