2022-12-05 10:59:45 +00:00
|
|
|
#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)
|
|
|
|
{
|
2023-01-20 08:07:09 +00:00
|
|
|
auto circle = std::make_unique<CircleNode>(Transform(DiscretePoint(x, y)), 5);
|
2022-12-05 10:59:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-23 11:55:58 +00:00
|
|
|
void CanvasDrawingArea::doPaint(const PaintEvent*)
|
2022-12-05 10:59:45 +00:00
|
|
|
{
|
|
|
|
mContentDirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasDrawingArea::onMyMouseEvent(const MouseEvent* event)
|
|
|
|
{
|
2023-01-17 08:34:48 +00:00
|
|
|
if(event->getAction() == MouseEvent::Action::Pressed)
|
2022-12-05 10:59:45 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2023-01-17 08:34:48 +00:00
|
|
|
else if(event->getAction() == MouseEvent::Action::Released)
|
2022-12-05 10:59:45 +00:00
|
|
|
{
|
2023-01-17 08:34:48 +00:00
|
|
|
auto client_loc = event->getClientLocation();
|
|
|
|
auto screen_loc = event->getScreenLocation();
|
2022-12-05 10:59:45 +00:00
|
|
|
|
2023-01-13 15:03:07 +00:00
|
|
|
addShapeAt(client_loc.getX(), client_loc.getY());
|
2022-12-05 10:59:45 +00:00
|
|
|
}
|
|
|
|
}
|