]> git.mxchange.org Git - flightgear.git/blob - src/GUI/gui.cxx
FGFontCache::initializeFonts() now portable across platform through the use of plib
[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 #ifdef HAVE_WINDOWS_H
34 #  include <windows.h>
35 #endif
36
37 #include <string>
38
39 #include <simgear/structure/exception.hxx>
40 #include <simgear/misc/sg_path.hxx>
41 #include <simgear/props/props.hxx>
42 #include <simgear/props/props_io.hxx>
43
44 #include <plib/pu.h>
45
46 #include <Include/general.hxx>
47 #include <Main/main.hxx>
48 #include <Main/globals.hxx>
49 #include <Main/fg_props.hxx>
50 #include <Main/WindowSystemAdapter.hxx>
51 #include <GUI/new_gui.hxx>
52
53 #include "gui.h"
54 #include "gui_local.hxx"
55 #include "layout.hxx"
56
57 using namespace osg;
58 using namespace flightgear;
59
60 puFont guiFnt = 0;
61
62
63 /* -------------------------------------------------------------------------
64 init the gui
65 _____________________________________________________________________*/
66
67 namespace
68 {
69 class GUIInitOperation : public GraphicsContextOperation
70 {
71 public:
72     GUIInitOperation() : GraphicsContextOperation(std::string("GUI init"))
73     {
74     }
75     void run(GraphicsContext* gc)
76     {
77         WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
78         wsa->puInitialize();
79         puSetDefaultStyle         ( PUSTYLE_SMALL_SHADED ); //PUSTYLE_DEFAULT
80         puSetDefaultColourScheme  (0.8, 0.8, 0.9, 1);
81
82         FGFontCache *fc = globals->get_fontcache();
83         fc->initializeFonts();
84         puFont *GuiFont
85             = fc->get(globals->get_locale()->getStringValue("font",
86                                                             "typewriter.txf"),
87                       15);
88         puSetDefaultFonts(*GuiFont, *GuiFont);
89         guiFnt = puGetDefaultLabelFont();
90
91         LayoutWidget::setDefaultFont(GuiFont, 15);
92   
93         if (!fgHasNode("/sim/startup/mouse-pointer")) {
94             // no preference specified for mouse pointer, attempt to autodetect...
95             // Determine if we need to render the cursor, or if the windowing
96             // system will do it.  First test if we are rendering with
97             // glide.
98             // XXX Not bloody likely in 2008...
99             if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
100                 // Test for the MESA_GLX_FX env variable
101                 char *mesa_win_state = getenv( "MESA_GLX_FX" );
102                 if (mesa_win_state  != NULL) {
103                     // test if we are fullscreen mesa/glide
104                     if ( (mesa_win_state[0] == 'f') ||
105                          (mesa_win_state[0] == 'F') ) {
106                         puShowCursor ();
107                     }
108                 }
109             }
110         } else if ( !fgGetBool("/sim/startup/mouse-pointer") ) {
111             // don't show pointer
112         } else {
113             // force showing pointer
114             puShowCursor();
115         }
116     }
117 };
118
119 ref_ptr<GUIInitOperation> initOp;
120 }
121
122 void guiStartInit()
123 {
124     initOp = new GUIInitOperation;
125     WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
126     GraphicsContext* gc = wsa->getGUIGraphicsContext();
127     gc->add(initOp.get());
128 }
129
130 bool guiFinishInit()
131 {
132     if (!initOp.valid())
133         return false;
134     if (!initOp->isFinished())
135         return false;
136     initMouseQuat();
137     initOp = 0;
138     return true;
139 }
140