/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library 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 
 * OpenSceneGraph Public License for more details.
*/

// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: Frame 59 2008-05-15 20:55:31Z cubicool $

#ifndef OSGWIDGET_FRAME
#define OSGWIDGET_FRAME

#include <osgWidget/Table>

namespace osgWidget {

class OSGWIDGET_EXPORT Frame: public Table
{
    public:
    
        enum CORNER
        {
            CORNER_LOWER_LEFT,
            CORNER_LOWER_RIGHT,
            CORNER_UPPER_LEFT,
            CORNER_UPPER_RIGHT
        };

        enum BORDER 
        {
            BORDER_LEFT,
            BORDER_RIGHT,
            BORDER_TOP,
            BORDER_BOTTOM
        };

        static std::string cornerToString (CORNER);
        static std::string borderToString (BORDER);

        class OSGWIDGET_EXPORT Corner: public Widget
        {
        public:
            META_Object   (osgWidget, Corner);

            Corner (CORNER = CORNER_LOWER_LEFT, point_type = 0.0f, point_type = 0.0f);
            Corner (const Corner&, const osg::CopyOp&);

            bool mouseDrag(double, double, WindowManager*);

            CORNER getCorner() const {
                return _corner;
            }

            void setCorner(CORNER corner) {
                _corner = corner;
            }

            void setCornerAndName(CORNER corner) {
                _corner = corner;
                _name   = cornerToString(corner);
            }
            
        protected:
            CORNER _corner;
        };

        class OSGWIDGET_EXPORT Border: public Widget
        {
        public:
            META_Object   (osgWidget, Border);

            Border (BORDER = BORDER_LEFT, point_type = 0.0f, point_type = 0.0f);
            Border (const Border&, const osg::CopyOp&);

            bool mouseDrag(double, double, WindowManager*);

            BORDER getBorder() const {
                return _border;
            }

            void setBorder(BORDER border) {
                _border = border;
            }

            void setBorderAndName(BORDER border) {
                _border = border;
                _name   = borderToString(border);
            }
            
        protected:
        
            BORDER _border;

        };

        META_Object   (osgWidget, Frame);

        Frame (const std::string& = "");
        Frame (const Frame&, const osg::CopyOp&);

        virtual void managed(WindowManager*);

        static Frame* createSimpleFrame(
            const std::string&,
            point_type,
            point_type,
            point_type,
            point_type,
            Frame* = 0
        );

        static Frame* createSimpleFrameWithSingleTexture(
            const std::string&,
            const std::string&,
            point_type,
            point_type,
            point_type,
            point_type,
            point_type,
            point_type,
            Frame* = 0
        );

        void createSimpleFrame(point_type cw, point_type ch, point_type w, point_type h)
        {
            createSimpleFrame(_name, cw, ch, w, h, this);
        }

        void createSimpleFrameWithSingleTexture(
            const std::string& tex,
            point_type tw,
            point_type th,
            point_type cw,
            point_type ch,
            point_type w,
            point_type h
        )
        {
            createSimpleFrameWithSingleTexture(_name, tex, tw, th, cw, ch, w, h, this);
        }

        bool setWindow(Window*);

        EmbeddedWindow* getEmbeddedWindow() { return dynamic_cast<EmbeddedWindow*>(getByRowCol(1, 1)); }

        const EmbeddedWindow* getEmbeddedWindow() const { return dynamic_cast<const EmbeddedWindow*>(getByRowCol(1, 1)); }

        Corner* getCorner(CORNER c) { return dynamic_cast<Corner*>(_getCorner(c)); }

        const Corner* getCorner(CORNER c) const { return dynamic_cast<const Corner*>(_getCorner(c)); }

        Border* getBorder(BORDER b) { return dynamic_cast<Border*>(_getBorder(b)); }

        const Border* getBorder(BORDER b) const { return dynamic_cast<const Border*>(_getBorder(b)); }

    protected:
    
        Widget* _getCorner (CORNER) const;
        Widget* _getBorder (BORDER) const;

};

}

#endif
