/* -*-c+
+-*- */
/* osgEarth
 * Copyright 2025 Pelican Mapping
 * MIT License
 */

#ifndef OSGEARTHSYMBOLOGY_ICON_SYMBOL_H
#define OSGEARTHSYMBOLOGY_ICON_SYMBOL_H 1

#include <osgEarth/Common>
#include <osgEarth/InstanceSymbol>

namespace osgEarth
{
    class Style;
    namespace Util {
        class InstanceResource;
    }

    /**
     * Represents a 2D icon for instancing
     */
    class OSGEARTH_EXPORT IconSymbol : public InstanceSymbol
    {
    public:
        // note: these are similar to the values in osgText::Text::AlignmentType
        enum Alignment {
            ALIGN_LEFT_TOP,
            ALIGN_LEFT_CENTER,
            ALIGN_LEFT_BOTTOM,

            ALIGN_CENTER_TOP,
            ALIGN_CENTER_CENTER,
            ALIGN_CENTER_BOTTOM,

            ALIGN_RIGHT_TOP,
            ALIGN_RIGHT_CENTER,
            ALIGN_RIGHT_BOTTOM,
        };

    public:
        META_Object(osgEarth, IconSymbol);

        IconSymbol(const IconSymbol& rhs,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        IconSymbol( const Config& conf =Config() );

        /** dtor */
        virtual ~IconSymbol() { }

        /** Alignment of the marker relative to center pixels */
        OE_OPTION(Alignment, alignment, ALIGN_CENTER_BOTTOM);

        /** Heading. Semantically this differs from an model's heading */
        OE_OPTION(Expression<double>, heading, 0.0);

        /** Decluttering */
        OE_OPTION(bool, declutter, true);

        /** Whether to enable occlusion culling on the icon, if applicable */
        OE_OPTION(bool, occlusionCull, false);

        /** The camera altitude at which to start occlusion culling the icon */
        OE_OPTION(double, occlusionCullAltitude, 200000.0);
        
    public: // non-serialized properties (for programmatic use only)

        /** Explicit image to use for 2D icon placemet */
        void setImage( osg::Image* image ) { _image = image; }
        osg::Image* getImage( unsigned maxSize =INT_MAX ) const;

    public:
        virtual Config getConfig() const;
        virtual void mergeConfig( const Config& conf );
        static void parseSLD(const Config& c, class Style& style);

    public: // InstanceSymbol
        virtual InstanceResource* createResource() const;

    protected:
        mutable osg::ref_ptr<osg::Image> _image;
    };

} // namespace osgEarth

#endif
