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