1 // Copyright (C) 2008 Tim Moore
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #ifndef FLIGHTGEAR_WINDOWBUILDER_HXX
18 #define FLIGHTGEAR_WINDOWBUILDER_HXX 1
20 #include <osg/ref_ptr>
21 #include <osg/Referenced>
22 #include <osg/GraphicsContext>
31 /** Singleton Builder class for creating a GraphicsWindow from property
32 * nodes. This involves initializing an osg::GraphicsContext::Traits
33 * structure from the property node values and creating an
34 * osgViewer::GraphicsWindow.
36 class WindowBuilder : public osg::Referenced
39 /** Initialize the singleton window builder.
40 * @param stencil whether windows should allocate stencil planes
42 static void initWindowBuilder(bool stencil);
43 /** Get the singleton window builder
45 static WindowBuilder* getWindowBuilder() { return windowBuilder.get(); }
46 /** Create a window from its property node description.
47 * @param winNode The window's root property node
48 * @return a graphics window.
50 GraphicsWindow* buildWindow(const SGPropertyNode* winNode);
51 /** Get a window whose properties come from FlightGear's
52 * command line arguments and their defaults. The window is opened
53 * if it has not been already.
54 * @return the default graphics window
56 GraphicsWindow* getDefaultWindow();
58 WindowBuilder(bool stencil);
59 static osg::GraphicsContext::Traits* makeDefaultTraits(bool stencil);
60 osg::ref_ptr<osg::GraphicsContext::Traits> defaultTraits;
62 static osg::ref_ptr<WindowBuilder> windowBuilder;
63 osg::ref_ptr<GraphicsWindow> defaultWindow;
66 /** Silly function for making the default window and camera
67 * names. This concatenates a string with in integer.
69 std::string makeName(const std::string& prefix, int num);