1 // Copyright (C) 2008 Tim Moore 2 // 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. 7 // 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. 12 // 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. 16 17 #ifndef FLIGHTGEAR_WINDOWBUILDER_HXX 18 #define FLIGHTGEAR_WINDOWBUILDER_HXX 1 19 20 #include <osg/ref_ptr> 21 #include <osg/Referenced> 22 #include <osg/GraphicsContext> 23 24 #include <string> 25 26 class SGPropertyNode; 27 28 namespace flightgear 29 { 30 class GraphicsWindow; 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. 35 */ 36 class WindowBuilder : public osg::Referenced 37 { 38 public: 39 /** Initialize the singleton window builder. 40 * @param stencil whether windows should allocate stencil planes 41 */ 42 static void initWindowBuilder(bool stencil); 43 /** Get the singleton window builder 44 */ getWindowBuilder()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. 49 */ 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 55 */ 56 GraphicsWindow* getDefaultWindow(); 57 /** Get the name used to look up the default window. 58 */ getDefaultWindowName()59 const std::string& getDefaultWindowName() { return defaultWindowName; } 60 61 static void setPoseAsStandaloneApp(bool b); 62 protected: 63 WindowBuilder(bool stencil); 64 65 void setFullscreenTraits(const SGPropertyNode* winNode, osg::GraphicsContext::Traits* traits); 66 bool setWindowedTraits(const SGPropertyNode* winNode, osg::GraphicsContext::Traits* traits); 67 68 void setMacPoseAsStandaloneApp(osg::GraphicsContext::Traits* traits); 69 70 void makeDefaultTraits(bool stencil); 71 72 osg::ref_ptr<osg::GraphicsContext::Traits> defaultTraits; 73 int defaultCounter; 74 bool usingQtGraphicsWindow = false; 75 76 static osg::ref_ptr<WindowBuilder> windowBuilder; 77 static const std::string defaultWindowName; 78 static bool poseAsStandaloneApp; 79 }; 80 81 /** Silly function for making the default window and camera 82 * names. This concatenates a string with in integer. 83 */ 84 std::string makeName(const std::string& prefix, int num); 85 86 } 87 #endif 88