#include "CanvasDrawingArea.h"

#include "MouseEvent.h"

#include "GeometryNode.h"
#include "TransformNode.h"
#include "CircleNode.h"

#include <iostream>

CanvasDrawingArea::~CanvasDrawingArea()
{

}

void CanvasDrawingArea::addShapeAt(unsigned x, unsigned y)
{
    if (mActiveDrawingCommand == CanvasDrawCommand::CIRCLE)
    {
        auto circle = std::make_unique<CircleNode>(DiscretePoint(x, y), 5);
        circle->setFillColor(Color(255, 0, 0));
        circle->setName("CanvasDrawingArea_CircleNode");

        mRootNode->addChild(circle.get());

        mSceneNodes.push_back(std::move(circle));
        mContentDirty = true;
    }
}

bool CanvasDrawingArea::isDirty() const
{
    return Widget::isDirty() || mContentDirty;
}

void CanvasDrawingArea::doPaint(const PaintEvent* event)
{
    mContentDirty = false;
}

void CanvasDrawingArea::onMyMouseEvent(const MouseEvent* event)
{
    if(event->GetAction() == MouseEvent::Action::Pressed)
    {

    }
    else if(event->GetAction() == MouseEvent::Action::Released)
    {
        auto client_loc = event->GetClientLocation();
        auto screen_loc = event->GetScreenLocation();

        addShapeAt(client_loc.GetX(), client_loc.GetY());
    }
}
