#include "GeometryNode.h"

#include "SceneInfo.h"
#include "SceneModel.h"

GeometryNode::GeometryNode(const Transform& transform)
    :   MaterialNode(transform),
        mStrokeThickness(1.0),
        mType(Type::Path)
{

}

GeometryNode::~GeometryNode()
{

}

SceneItem* GeometryNode::getSceneItem(std::size_t idx) const
{
    if (idx == 0)
    {
        return mBackgroundItem.get();
    }
    else
    {
        return nullptr;
    }
}

std::size_t GeometryNode::getNumSceneItems() const
{
    return 1;
}


double GeometryNode::getStrokeThickness() const
{
    return mStrokeThickness;
}

void GeometryNode::setStrokeThickness(double thickness)
{
    if (mStrokeThickness != thickness)
    {
        mGeometryIsDirty = true;
        mStrokeThickness = thickness;
    }
}

void GeometryNode::updateMaterial()
{
    if (!mBackgroundItem)
    {
        return;
    }

    mBackgroundItem->updateSolidMaterial(*mMaterial);
}

void GeometryNode::update(SceneInfo* sceneInfo)
{
    if (!mBackgroundItem || mGeometryIsDirty)
    {
        createOrUpdateGeometry(sceneInfo);
        mGeometryIsDirty = false;
    }

    if (mMaterialIsDirty)
    {
        updateMaterial();
        mMaterialIsDirty = false;
    }
}
