/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
 * Copyright 2020 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#pragma once

#include <osgEarth/Common>
#include <osgEarth/ImageLayer>
#include <osgEarth/Geometry>
#include <osgEarth/Map>
#include <osgText/Font>

using namespace osgEarth;

namespace osgEarth { namespace Util
{
    /**
     * Image layer displaying TileKey information
     */
    class OSGEARTH_EXPORT DebugImageLayer : public ImageLayer
    {
    public:
        class OSGEARTH_EXPORT Options : public ImageLayer::Options {
        public:
            META_LayerOptions(osgEarth, Options, ImageLayer::Options);
            OE_OPTION(std::string, colorCode, "#000000");
            OE_OPTION(bool, invertY, false);
            OE_OPTION(bool, showTessellation, false);
            virtual Config getConfig() const;
            static Config getMetadata();
        private:
            void fromConfig( const Config& conf );
        };

    public:
        META_Layer(osgEarth, DebugImageLayer, Options, ImageLayer, DebugImage);        

    public: // Layer

        void init() override;
        Status openImplementation() override;
        void addedToMap(const Map* map) override;
        GeoImage createImageImplementation(const TileKey& key, ProgressCallback* progress) const override;

        //! Allow the user to directly set the profile before opening the layer
        void setProfile(const Profile* profile) override;

    protected:

        //! Destructor
        virtual ~DebugImageLayer() { }

        osg::ref_ptr<osgEarth::Geometry> _geom;
        osg::ref_ptr<osgText::Font> _font;
        osg::Vec4f _color;
        osg::ref_ptr<const osg::Image> _tessImage;
    };

} }

OSGEARTH_SPECIALIZE_CONFIG(osgEarth::Util::DebugImageLayer::Options);
