#include "ImageViewWidget.h"

#include "GridNode.h"
#include "TransformNode.h"

#include "ThemeManager.h"
#include "PaintEvent.h"

ImageViewWidget::ImageViewWidget()
{
    mName = "ImageViewWidget";
}

ImageViewWidget::~ImageViewWidget()
{

}

void ImageViewWidget::doPaint(const PaintEvent* event)
{
    if (!mVisible)
    {
        return;
    }

    if (!mGridNode)
    {
        mGridNode = std::make_unique<GridNode>(Transform(mLocation));
        mGridNode->setName(mName + "_GridNode");
        mGridNode->setNumX(mNumX);
        mGridNode->setNumY(mNumY);

        mGridNode->setWidth(mSize.mWidth);
        mGridNode->setHeight(mSize.mHeight);

        mGridNode->setStrokeColor(event->getThemesManager()->getColor(mBorder));

        mRootNode->addChild(mGridNode.get());
    }

    if (mTransformDirty)
    {
        mGridNode->setWidth(mSize.mWidth);
        mGridNode->setHeight(mSize.mHeight);
    }

    if (mMaterialDirty)
    {
        mGridNode->setFillColor(event->getThemesManager()->getColor(mBorder));
    }
}
