]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui.cxx
issue #127: make screen shots work with OSG multi-threading
[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/fg_props.hxx>
45 #include <Main/WindowSystemAdapter.hxx>
46 #include <GUI/new_gui.hxx>
47
48 #include "gui.h"
49 #include "layout.hxx"
50
51 #include <osg/GraphicsContext>
52
53 using namespace flightgear;
54
55 puFont guiFnt = 0;
56
57
58 /* -------------------------------------------------------------------------
59 init the gui
60 _____________________________________________________________________*/
61
62 namespace
63 {
64 class GUIInitOperation : public GraphicsContextOperation
65 {
66 public:
67     GUIInitOperation() : GraphicsContextOperation(std::string("GUI init"))
68     {
69     }
70     void run(osg::GraphicsContext* gc)
71     {
72         WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
73         wsa->puInitialize();
74         puSetDefaultStyle         ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT
75         puSetDefaultColourScheme  (0.8, 0.8, 0.9, 1);
76
77         FGFontCache *fc = globals->get_fontcache();
78         fc->initializeFonts();
79         puFont *GuiFont
80             = fc->get(globals->get_locale()->getStringValue("font",
81                                                             "typewriter.txf"),
82                       15);
83         puSetDefaultFonts(*GuiFont, *GuiFont);
84         guiFnt = puGetDefaultLabelFont();
85
86         LayoutWidget::setDefaultFont(GuiFont, 15);
87   
88         if (!fgHasNode("/sim/startup/mouse-pointer")) {
89             // no preference specified for mouse pointer
90         } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
91             // don't show pointer
92         } else {
93             // force showing pointer
94             puShowCursor();
95         }
96     }
97 };
98
99 osg::ref_ptr<GUIInitOperation> initOp;
100 }
101
102 void guiStartInit(osg::GraphicsContext* gc)
103 {
104     if (gc) {
105         initOp = new GUIInitOperation;
106         gc->add(initOp.get());
107     }
108 }
109
110 bool guiFinishInit()
111 {
112     if (!initOp.valid())
113         return true;
114     if (!initOp->isFinished())
115         return false;
116     initOp = 0;
117     return true;
118 }
119