]> git.mxchange.org Git - flightgear.git/blob - src/Main/splash.cxx
allow to trigger widgets via accelerator key, which is defined via "keynum"
[flightgear.git] / src / Main / splash.cxx
1 // splash.cxx -- draws the initial splash screen
2 //
3 // Written by Curtis Olson, started July 1998.  (With a little looking
4 // at Freidemann's panel code.) :-)
5 //
6 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef SG_MATH_EXCEPTION_CLASH
30 #  include <math.h>
31 #endif
32
33 #ifdef HAVE_WINDOWS_H
34 #  include <windows.h>
35 #endif
36
37 #include <string.h>
38
39 #include <plib/pu.h>
40 #include <simgear/compiler.h>
41
42 #include SG_GLU_H
43
44 #include <simgear/debug/logstream.hxx>
45 #include <simgear/screen/texture.hxx>
46 #include <simgear/math/sg_random.h>
47 #include <simgear/misc/sg_path.hxx>
48
49 #include <GUI/new_gui.hxx>
50
51 #include "globals.hxx"
52 #include "fg_props.hxx"
53 #include "splash.hxx"
54 #include "fg_os.hxx"
55
56 static const int fontsize = 19;
57 static const char fontname[] = "default.txf";
58 static const char *progress_text = 0;
59
60
61 static SGTexture splash;
62 static fntTexFont font;
63 static fntRenderer info;
64
65
66 // Initialize the splash screen
67 void fgSplashInit ( const char *splash_texture ) {
68     fgRequestRedraw();
69
70     SG_LOG( SG_GENERAL, SG_INFO, "Initializing splash screen" );
71
72
73     SGPath fontpath;
74     char* envp = ::getenv("FG_FONTS");
75     if (envp != NULL) {
76         fontpath.set(envp);
77     } else {
78         fontpath.set(globals->get_fg_root());
79         fontpath.append("Fonts");
80     }
81     SGPath path(fontpath);
82     path.append(fontname);
83
84     if (!font.load((char *)path.c_str())) {
85         SG_LOG( SG_GENERAL, SG_ALERT, "Error loading font " << path.str() );
86         return;
87     }
88
89     info.setFont(&font);
90     info.setPointSize(fontsize);
91
92     if (!fgGetBool("/sim/startup/splash-screen"))
93         return;
94
95     splash.bind();
96
97     SGPath tpath( globals->get_fg_root() );
98     if (splash_texture == NULL || !strcmp(splash_texture, "")) {
99         // load in the texture data
100         int num = (int)(sg_random() * 5.0 + 1.0);
101         char num_str[5];
102         snprintf(num_str, 4, "%d", num);
103
104         tpath.append( "Textures/Splash" );
105         tpath.concat( num_str );
106         tpath.concat( ".rgb" );
107     } else
108         tpath.append( splash_texture );
109
110     splash.read_rgb_texture(tpath.c_str());
111     if (!splash.usable())
112     {
113         // Try compressed
114         SGPath fg_tpath = tpath;
115         fg_tpath.concat( ".gz" );
116
117         splash.read_rgb_texture(fg_tpath.c_str());
118         if ( !splash.usable() )
119         {
120             SG_LOG( SG_GENERAL, SG_ALERT,
121                     "Error in loading splash screen texture " << tpath.str() );
122             exit(-1);
123         }
124     }
125
126     splash.select();
127 }
128
129
130 void fgSplashProgress ( const char *s )
131 {
132     progress_text = s;
133     fgRequestRedraw();
134 }
135
136
137 // Update the splash screen with alpha specified from 0.0 to 1.0
138 void fgSplashUpdate ( float alpha ) {
139     int screen_width = fgGetInt("/sim/startup/xsize", 0);
140     int screen_height = fgGetInt("/sim/startup/ysize", 0);
141
142     if (!screen_width || !screen_height)
143         return;
144
145     int size = screen_width < (screen_height - 5 * fontsize)
146             ? screen_width : screen_height - 5 * fontsize;
147     if (size > 512)
148         size = 512;
149
150     int xmin, ymin, xmax, ymax;
151     xmin = (screen_width - size) / 2;
152     xmax = xmin + size;
153
154     ymin = (screen_height - size) / 2;
155     ymax = ymin + size;
156
157     glMatrixMode(GL_PROJECTION);
158     glPushMatrix();
159     glLoadIdentity();
160     gluOrtho2D(0, screen_width, 0, screen_height);
161     glMatrixMode(GL_MODELVIEW);
162     glPushMatrix();
163     glLoadIdentity();
164
165     glDisable(GL_DEPTH_TEST);
166     glDisable(GL_LIGHTING);
167
168     // draw the background
169     glColor4f( 0.0, 0.0, 0.0, alpha );
170     glBegin(GL_POLYGON);
171     glVertex2f(0.0, 0.0);
172     glVertex2f(screen_width, 0.0);
173     glVertex2f(screen_width, screen_height);
174     glVertex2f(0.0, screen_height);
175     glEnd();
176
177     // now draw the logo
178     if (fgGetBool("/sim/startup/splash-screen", true)) {
179         glEnable(GL_TEXTURE_2D);
180         splash.bind();
181         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
182
183         glColor4f( 1.0, 1.0, 1.0, alpha );
184         glBegin(GL_POLYGON);
185         glTexCoord2f(0.0, 0.0); glVertex2f(xmin, ymin);
186         glTexCoord2f(1.0, 0.0); glVertex2f(xmax, ymin);
187         glTexCoord2f(1.0, 1.0); glVertex2f(xmax, ymax);
188         glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
189         glEnd();
190     }
191
192     if (info.getFont() && progress_text && fgGetBool("/sim/startup/splash-progress", true)) {
193         glEnable(GL_ALPHA_TEST);
194         glEnable(GL_BLEND);
195         glAlphaFunc(GL_GREATER, 0.1f);
196         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
197         glDisable(GL_CULL_FACE);
198
199         float left, right, bot, top;
200
201         info.begin();
202         FGColor c(1.0, 0.9, 0.0);
203         c.merge(fgGetNode("/sim/gui/colors/splash"));
204         glColor4f(c.red(), c.green(), c.blue(), alpha);
205
206         font.getBBox(progress_text, fontsize, 0, &left, &right, &bot, &top);
207         info.start2f((screen_width - right) / 2.0, 10.0 - bot);
208         info.puts(progress_text);
209
210         const char *s = fgGetString("/sim/startup/splash-title", "");
211         font.getBBox(s, fontsize, 0, &left, &right, &bot, &top);
212         info.start2f((screen_width - right) / 2.0, screen_height - top - bot - 10.0);
213         info.puts(s);
214         info.end();
215     }
216
217     glEnable(GL_DEPTH_TEST);
218     glEnable(GL_LIGHTING);
219     glDisable(GL_TEXTURE_2D);
220
221     glMatrixMode(GL_PROJECTION);
222     glPopMatrix();
223     glMatrixMode(GL_MODELVIEW);
224     glPopMatrix();
225 }
226
227