#include "DrawingContext.h"

#include "AbstractPainter.h"
#include "PainterFactory.h"

#include "Grid.h"
#include "TriMesh.h"

#include "DrawingSurface.h"
#include "Scene.h"

DrawingContext::DrawingContext(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode)
    : mDrawingMode(requestedDrawingMode),
      mFontsManager(fontsManager),
      mSurface(surface)
{
    mPainter = PainterFactory::Create(this, mDrawingMode);

    surface->getScene()->setSupportsGeometryPrimitives(mPainter->supportsGeometryPrimitives());
    surface->getScene()->setFontsManager(fontsManager);
}

std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface, FontsManager* fontsManager, DrawingMode requestedDrawingMode)
{
    return std::make_unique<DrawingContext>(surface, fontsManager, requestedDrawingMode);
}

DrawingSurface* DrawingContext::getSurface() const
{
    return mSurface;
}

FontsManager* DrawingContext::getFontsManager() const
{
    return mFontsManager;
}

void DrawingContext::paint()
{
    if (mDrawingMode == DrawingMode::GRAPH)
    {
        mSurface->getScene()->update();
    }
    mPainter->paint();
}

AbstractPainter* DrawingContext::getPainter() const
{
    return mPainter.get();
}
