stuff-from-scratch/apps/notes_tk/canvas/CanvasDrawingArea.cpp
2023-01-17 08:34:48 +00:00

52 lines
1.2 KiB
C++

#include "CanvasDrawingArea.h"
#include "MouseEvent.h"
#include "GeometryNode.h"
#include "TransformNode.h"
#include "CircleNode.h"
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());
}
}