// Copyright (C) 2008  Tim Moore
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#ifndef FLIGHTGEAR_WINDOWBUILDER_HXX
#define FLIGHTGEAR_WINDOWBUILDER_HXX 1

#include <osg/ref_ptr>
#include <osg/Referenced>
#include <osg/GraphicsContext>

#include <string>

class SGPropertyNode;

namespace flightgear
{

const char DEFAULT_WINDOW_NAME[] = "FlightGear";

class GraphicsWindow;
/** Singleton Builder class for creating a GraphicsWindow from property
 * nodes. This involves initializing an osg::GraphicsContext::Traits
 * structure from the property node values and creating an
 * osgViewer::GraphicsWindow.
 */
class WindowBuilder : public osg::Referenced
{
public:
    /** Initialize the singleton window builder.
     * @param stencil whether windows should allocate stencil planes
     */
    static void initWindowBuilder();
    /** Get the singleton window builder
     */
    static WindowBuilder* getWindowBuilder() { return windowBuilder.get(); }
    /** Create a window from its property node description.
     * @param winNode The window's root property node
     * @return a graphics window.
     */
    GraphicsWindow* buildWindow(const SGPropertyNode* winNode);

    static void setPoseAsStandaloneApp(bool b);
protected:
    WindowBuilder();

    void setFullscreenTraits(const SGPropertyNode* winNode, osg::GraphicsContext::Traits* traits);
    bool setWindowedTraits(const SGPropertyNode* winNode, osg::GraphicsContext::Traits* traits);
    
    void setMacPoseAsStandaloneApp(osg::GraphicsContext::Traits* traits) const;
    
    void makeDefaultTraits();
    
    osg::ref_ptr<osg::GraphicsContext::Traits> defaultTraits;
    bool usingQtGraphicsWindow = false;
    
    static osg::ref_ptr<WindowBuilder> windowBuilder;
    static bool poseAsStandaloneApp;
};

}
#endif
