]> git.mxchange.org Git - flightgear.git/blob - GUI/gui.cxx
Fixed some problems with timing of output strings.
[flightgear.git] / 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 #include <stdlib.h>
27 #include <string.h>
28
29 #include <Include/general.hxx>
30 #include <Main/options.hxx>
31
32 #include "gui.h"
33
34
35 puMenuBar    *mainMenuBar;
36 puButton     *hideMenuButton;
37 puDialogBox  *dialogBox;
38 puText       *dialogBoxMessage;
39 puOneShot    *dialogBoxOkButton;
40 puText       *timerText;
41
42 /* --------------------------------------------------------------------
43        Mouse stuff 
44   ---------------------------------------------------------------------*/
45
46 void guiMotionFunc ( int x, int y )
47 {
48   puMouse ( x, y ) ;
49   glutPostRedisplay () ;
50 }
51
52
53 void guiMouseFunc(int button, int updown, int x, int y)
54 {
55     puMouse (button, updown, x,y);
56     glutPostRedisplay ();
57 }
58
59 /* -----------------------------------------------------------------------
60   the Gui callback functions 
61   ____________________________________________________________________*/
62
63 void hideMenuCb (puObject *cb)
64 {
65   if (cb -> getValue () )
66     {
67       mainMenuBar -> reveal();
68       printf("Showing Menu");
69       hideMenuButton -> setLegend ("Hide Menu");
70     }
71   else
72     {
73       mainMenuBar -> hide  ();
74       printf("Hiding Menu");
75       hideMenuButton -> setLegend ("Show Menu");
76     }
77 }
78
79  void goAwayCb (puObject *)
80 {
81   delete dialogBox;
82   dialogBox = NULL;
83 }
84
85 void mkDialog (char *txt)
86 {
87   dialogBox = new puDialogBox (150, 50);
88   {
89     new puFrame (0,0,400, 100);
90     dialogBoxMessage =   new puText         (10, 70);
91     dialogBoxMessage ->  setLabel           (txt);
92     dialogBoxOkButton =  new puOneShot      (180, 10, 240, 50);
93     dialogBoxOkButton -> setLegend          ("OK");
94     dialogBoxOkButton -> makeReturnDefault  (TRUE );
95     dialogBoxOkButton -> setCallback        (goAwayCb);
96   }
97   dialogBox -> close();
98   dialogBox -> reveal();
99 }
100
101 void notCb (puObject *)
102 {
103   mkDialog ("This function isn't implemented yet");
104 }
105
106 /* -----------------------------------------------------------------------
107    The menu stuff 
108    ---------------------------------------------------------------------*/
109 char *fileSubmenu        [] = { "Exit", "Close", "---------", "Print", "---------", "Save", "New", NULL };
110 char *editSubmenu        [] = { "Edit text", NULL };
111 char *viewSubmenu        [] = { "Cockpit View > ", "View >","------------", "View options...", NULL };
112 char *aircraftSubmenu    [] = { "Autopilot ...", "Engine ...", "Navigation", "Communication", NULL};
113 char *environmentSubmenu [] = { "Time & Date...", "Terrain ...", "Weather", NULL};
114 char *optionsSubmenu     [] = { "Preferences", "Realism & Reliablity...", NULL};
115 char *helpSubmenu        [] = { "About...", "Help", NULL };
116
117 puCallback fileSubmenuCb        [] = { notCb, notCb, NULL, notCb, NULL, notCb, notCb, NULL};
118 puCallback editSubmenuCb        [] = { notCb, NULL };
119 puCallback viewSubmenuCb        [] = { notCb, notCb, NULL, notCb, NULL };
120 puCallback aircraftSubmenuCb    [] = { notCb, notCb, notCb,notCb, NULL };
121 puCallback environmentSubmenuCb [] = { notCb, notCb, notCb, NULL };
122 puCallback optionsSubmenuCb     [] = { notCb, notCb, NULL};
123 puCallback helpSubmenuCb        [] = { notCb, notCb, NULL };
124
125  
126
127 /* -------------------------------------------------------------------------
128    init the gui
129    _____________________________________________________________________*/
130
131
132
133 void guiInit()
134 {
135     char *mesa_win_state;
136
137     // Initialize PUI
138     puInit();
139
140     if ( current_options.get_mouse_pointer() == 0 ) {
141         // no preference specified for mouse pointer, attempt to autodetect...
142         // Determine if we need to render the cursor, or if the windowing
143         // system will do it.  First test if we are rendering with glide.
144         if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
145             // Test for the MESA_GLX_FX env variable
146             if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
147                 // test if we are fullscreen mesa/glide
148                 if ( (mesa_win_state[0] == 'f') || 
149                      (mesa_win_state[0] == 'F') ) {
150                     puShowCursor ();
151                 }
152             }
153         }
154     } else if ( current_options.get_mouse_pointer() == 1 ) {
155         // don't show pointer
156     } else if ( current_options.get_mouse_pointer() == 2 ) {
157         // force showing pointer
158         puShowCursor();
159     }
160
161     // puSetDefaultStyle         ( PUSTYLE_SMALL_BEVELLED );
162     puSetDefaultStyle         ( PUSTYLE_DEFAULT );
163     puSetDefaultColourScheme  (0.2, 0.4, 0.8, 0.5);
164       
165     /* OK the rest is largerly put in here to mimick Steve Baker's
166        "complex" example It should change in future versions */
167       
168     // timerText = new puText (300, 10);
169     // timerText -> setColour (PUCOL_LABEL, 1.0, 1.0, 1.0);
170
171     /* Make a button to hide the menu bar */
172     hideMenuButton = new puButton       (10,10, 150, 50);
173     hideMenuButton -> setValue          (TRUE);
174     hideMenuButton -> setLegend         ("Hide Menu");
175     hideMenuButton -> setCallback       (hideMenuCb);
176     hideMenuButton -> makeReturnDefault (TRUE);
177     hideMenuButton -> hide();
178
179     // Make the menu bar
180     mainMenuBar = new puMenuBar ();
181     mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
182     mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
183     mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
184     mainMenuBar -> add_submenu ("Aircraft", aircraftSubmenu, aircraftSubmenuCb);
185     mainMenuBar -> add_submenu ("Environment", environmentSubmenu, 
186                                 environmentSubmenuCb);
187     mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
188     mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
189     mainMenuBar-> close ();
190 }