]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui.cxx
FlightRecorder: smarter log warning.
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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 #include <string>
34
35 #include <simgear/structure/exception.hxx>
36 #include <simgear/misc/sg_path.hxx>
37 #include <simgear/props/props.hxx>
38 #include <simgear/props/props_io.hxx>
39
40 #include <plib/pu.h>
41
42 #include <Main/main.hxx>
43 #include <Main/globals.hxx>
44 #include <Main/locale.hxx>
45 #include <Main/fg_props.hxx>
46 #include <Viewer/WindowSystemAdapter.hxx>
47 #include <Viewer/CameraGroup.hxx>
48 #include <GUI/new_gui.hxx>
49 #include <GUI/FGFontCache.hxx>
50
51 #include "gui.h"
52 #include "layout.hxx"
53
54 #include <osg/GraphicsContext>
55
56 using namespace flightgear;
57
58 puFont guiFnt = 0;
59
60
61 /* -------------------------------------------------------------------------
62 init the gui
63 _____________________________________________________________________*/
64
65 namespace
66 {
67 class GUIInitOperation : public GraphicsContextOperation
68 {
69 public:
70     GUIInitOperation() : GraphicsContextOperation(std::string("GUI init"))
71     {
72     }
73     void run(osg::GraphicsContext* gc)
74     {
75         WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
76         wsa->puInitialize();
77         puSetDefaultStyle         ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT
78         puSetDefaultColourScheme  (0.8, 0.8, 0.9, 1);
79
80         FGFontCache *fc = globals->get_fontcache();
81         fc->initializeFonts();
82         puFont *GuiFont
83             = fc->get(globals->get_locale()->getDefaultFont("typewriter.txf"),
84                       15);
85         puSetDefaultFonts(*GuiFont, *GuiFont);
86         guiFnt = puGetDefaultLabelFont();
87
88         LayoutWidget::setDefaultFont(GuiFont, 15);
89   
90         if (!fgHasNode("/sim/startup/mouse-pointer")) {
91             // no preference specified for mouse pointer
92         } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
93             // don't show pointer
94         } else {
95             // force showing pointer
96             puShowCursor();
97         }
98     }
99 };
100
101 // Operation for querying OpenGL parameters. This must be done in a
102 // valid OpenGL context, potentially in another thread.
103
104 struct GeneralInitOperation : public GraphicsContextOperation
105 {
106     GeneralInitOperation()
107         : GraphicsContextOperation(std::string("General init"))
108     {
109     }
110     void run(osg::GraphicsContext* gc)
111     {
112         SGPropertyNode* simRendering = fgGetNode("/sim/rendering");
113
114         simRendering->setStringValue("gl-vendor", (char*) glGetString(GL_VENDOR));
115         SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VENDOR));
116
117         simRendering->setStringValue("gl-renderer", (char*) glGetString(GL_RENDERER));
118         SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_RENDERER));
119
120         simRendering->setStringValue("gl-version", (char*) glGetString(GL_VERSION));
121         SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_VERSION));
122
123         simRendering->setStringValue("gl-shading-language-version", (char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
124         SG_LOG( SG_GENERAL, SG_INFO, glGetString(GL_SHADING_LANGUAGE_VERSION));
125
126         GLint tmp;
127         glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
128         simRendering->setIntValue("max-texture-size", tmp);
129
130         glGetIntegerv( GL_DEPTH_BITS, &tmp );
131         simRendering->setIntValue("depth-buffer-bits", tmp);
132     }
133 };
134
135 osg::ref_ptr<GUIInitOperation> initOp;
136
137 }
138
139 /** Initializes GUI.
140  * Returns true when done, false when still busy (call again). */
141 bool guiInit()
142 {
143     static osg::ref_ptr<GeneralInitOperation> genOp;
144
145     if (!genOp.valid())
146     {
147         // Pick some window on which to do queries.
148         // XXX Perhaps all this graphics initialization code should be
149         // moved to renderer.cxx?
150         genOp = new GeneralInitOperation;
151         osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
152         WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
153         osg::GraphicsContext* gc = 0;
154         if (guiCamera)
155             gc = guiCamera->getGraphicsContext();
156         if (gc) {
157             gc->add(genOp.get());
158             initOp = new GUIInitOperation;
159             gc->add(initOp.get());
160         } else {
161             wsa->windows[0]->gc->add(genOp.get());
162         }
163         return false; // not ready yet
164     }
165     else
166     {
167         if (!genOp->isFinished())
168             return false;
169         if (!initOp.valid())
170             return true;
171         if (!initOp->isFinished())
172             return false;
173         genOp = 0;
174         initOp = 0;
175         // we're done
176         return true;
177     }
178 }