From 4fb9b978fbaa5d187ce5323d101bcf5271a585e2 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 9 Mar 2024 08:09:25 +0100 Subject: [PATCH] Limit StrokeManager use to stroke tools (#1814) * Limit StrokeManager use to stroke tools * Rename StrokeManager to StrokeInterpolator This better distinguishes it from BaseManager-derived classes * Augment PointerEvent with position in canvas coordinates --- core_lib/core_lib.pro | 4 +- core_lib/src/interface/scribblearea.cpp | 32 +++------ core_lib/src/interface/scribblearea.h | 5 +- core_lib/src/tool/basetool.cpp | 47 +------------ core_lib/src/tool/basetool.h | 16 +---- core_lib/src/tool/brushtool.cpp | 14 ++-- core_lib/src/tool/buckettool.cpp | 18 ++--- core_lib/src/tool/cameratool.cpp | 62 ++++++++--------- core_lib/src/tool/cameratool.h | 13 ++-- core_lib/src/tool/erasertool.cpp | 16 +++-- core_lib/src/tool/eyedroppertool.cpp | 29 ++++---- core_lib/src/tool/eyedroppertool.h | 8 +-- core_lib/src/tool/handtool.cpp | 23 +++---- core_lib/src/tool/handtool.h | 4 +- core_lib/src/tool/movetool.cpp | 69 ++++++++++--------- core_lib/src/tool/movetool.h | 12 ++-- core_lib/src/tool/penciltool.cpp | 14 ++-- core_lib/src/tool/pentool.cpp | 14 ++-- core_lib/src/tool/polylinetool.cpp | 8 ++- core_lib/src/tool/polylinetool.h | 2 +- core_lib/src/tool/selecttool.cpp | 34 ++++----- core_lib/src/tool/selecttool.h | 9 +-- core_lib/src/tool/smudgetool.cpp | 7 +- ...rokemanager.cpp => strokeinterpolator.cpp} | 65 +++++++---------- .../{strokemanager.h => strokeinterpolator.h} | 26 ++----- core_lib/src/tool/stroketool.cpp | 43 ++++++++++-- core_lib/src/tool/stroketool.h | 11 +++ core_lib/src/util/pointerevent.cpp | 21 ++---- core_lib/src/util/pointerevent.h | 14 ++-- 29 files changed, 301 insertions(+), 339 deletions(-) rename core_lib/src/tool/{strokemanager.cpp => strokeinterpolator.cpp} (84%) rename core_lib/src/tool/{strokemanager.h => strokeinterpolator.h} (77%) diff --git a/core_lib/core_lib.pro b/core_lib/core_lib.pro index 4b0642ecf3..54e396635c 100644 --- a/core_lib/core_lib.pro +++ b/core_lib/core_lib.pro @@ -84,7 +84,7 @@ HEADERS += \ src/tool/polylinetool.h \ src/tool/selecttool.h \ src/tool/smudgetool.h \ - src/tool/strokemanager.h \ + src/tool/strokeinterpolator.h \ src/tool/stroketool.h \ src/util/blitrect.h \ src/util/cameraeasingtype.h \ @@ -169,7 +169,7 @@ SOURCES += src/graphics/bitmap/bitmapimage.cpp \ src/tool/polylinetool.cpp \ src/tool/selecttool.cpp \ src/tool/smudgetool.cpp \ - src/tool/strokemanager.cpp \ + src/tool/strokeinterpolator.cpp \ src/tool/stroketool.cpp \ src/util/blitrect.cpp \ src/util/cameraeasingtype.cpp \ diff --git a/core_lib/src/interface/scribblearea.cpp b/core_lib/src/interface/scribblearea.cpp index 143983cb08..84a7394aee 100644 --- a/core_lib/src/interface/scribblearea.cpp +++ b/core_lib/src/interface/scribblearea.cpp @@ -21,6 +21,7 @@ GNU General Public License for more details. #include #include #include +#include #include "pointerevent.h" #include "beziercurve.h" @@ -38,7 +39,6 @@ GNU General Public License for more details. #include "colormanager.h" #include "toolmanager.h" -#include "strokemanager.h" #include "layermanager.h" #include "playbackmanager.h" #include "viewmanager.h" @@ -54,8 +54,6 @@ ScribbleArea::ScribbleArea(QWidget* parent) : QWidget(parent), // Qt::WA_StaticContents ensure that the widget contents are rooted to the top-left corner // and don't change when the widget is resized. setAttribute(Qt::WA_StaticContents); - - mStrokeManager.reset(new StrokeManager); } ScribbleArea::~ScribbleArea() @@ -573,7 +571,7 @@ void ScribbleArea::wheelEvent(QWheelEvent* event) void ScribbleArea::tabletEvent(QTabletEvent *e) { - PointerEvent event(e); + PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->posF())); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (event.pointerType() == QPointingDevice::PointerType::Eraser) @@ -591,8 +589,6 @@ void ScribbleArea::tabletEvent(QTabletEvent *e) if (event.eventType() == PointerEvent::Press) { event.accept(); - mStrokeManager->pointerPressEvent(&event); - mStrokeManager->setTabletInUse(true); if (mIsFirstClick) { mIsFirstClick = false; @@ -601,7 +597,8 @@ void ScribbleArea::tabletEvent(QTabletEvent *e) } else { - qreal distance = QLineF(currentTool()->getCurrentPressPoint(), currentTool()->getLastPressPoint()).length(); + qreal distance = QLineF(e->posF(), mTabletPressPos).length(); + mTabletPressPos = e->posF(); if (mDoubleClickMillis <= DOUBLE_CLICK_THRESHOLD && distance < 5.0) { currentTool()->pointerDoubleClickEvent(&event); @@ -618,7 +615,6 @@ void ScribbleArea::tabletEvent(QTabletEvent *e) { if (!(event.buttons() & (Qt::LeftButton | Qt::RightButton)) || mTabletInUse) { - mStrokeManager->pointerMoveEvent(&event); pointerMoveEvent(&event); } } @@ -628,9 +624,7 @@ void ScribbleArea::tabletEvent(QTabletEvent *e) mMouseFilterTimer->start(); if (mTabletInUse) { - mStrokeManager->pointerReleaseEvent(&event); pointerReleaseEvent(&event); - mStrokeManager->setTabletInUse(false); mTabletInUse = false; } } @@ -733,10 +727,7 @@ void ScribbleArea::mousePressEvent(QMouseEvent* e) return; } - PointerEvent event(e); - - mStrokeManager->pointerPressEvent(&event); - + PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos())); pointerPressEvent(&event); mMouseInUse = event.isAccepted(); } @@ -744,30 +735,25 @@ void ScribbleArea::mousePressEvent(QMouseEvent* e) void ScribbleArea::mouseMoveEvent(QMouseEvent* e) { if (mTabletInUse || (mMouseFilterTimer->isActive() && mTabletReleaseMillisAgo < MOUSE_FILTER_THRESHOLD)) { e->ignore(); return; } - PointerEvent event(e); - - mStrokeManager->pointerMoveEvent(&event); + PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos())); pointerMoveEvent(&event); } void ScribbleArea::mouseReleaseEvent(QMouseEvent* e) { if (mTabletInUse || (mMouseFilterTimer->isActive() && mTabletReleaseMillisAgo < MOUSE_FILTER_THRESHOLD)) { e->ignore(); return; } - PointerEvent event(e); - - mStrokeManager->pointerReleaseEvent(&event); + PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos())); pointerReleaseEvent(&event); mMouseInUse = (e->buttons() & Qt::RightButton) || (e->buttons() & Qt::LeftButton); } void ScribbleArea::mouseDoubleClickEvent(QMouseEvent* e) { - if (mStrokeManager->isTabletInUse()) { e->ignore(); return; } - PointerEvent event(e); - mStrokeManager->pointerPressEvent(&event); + if (mTabletInUse) { e->ignore(); return; } + PointerEvent event(e, mEditor->view()->mapScreenToCanvas(e->localPos())); currentTool()->pointerDoubleClickEvent(&event); } diff --git a/core_lib/src/interface/scribblearea.h b/core_lib/src/interface/scribblearea.h index 277f29d7d6..5d396d9102 100644 --- a/core_lib/src/interface/scribblearea.h +++ b/core_lib/src/interface/scribblearea.h @@ -36,7 +36,6 @@ GNU General Public License for more details. #include "canvaspainter.h" #include "overlaypainter.h" #include "preferencemanager.h" -#include "strokemanager.h" #include "selectionpainter.h" #include "camerapainter.h" #include "tiledbuffer.h" @@ -63,7 +62,6 @@ class ScribbleArea : public QWidget bool init(); void setEditor(Editor* e) { mEditor = e; } - StrokeManager* getStrokeManager() const { return mStrokeManager.get(); } Editor* editor() const { return mEditor; } void deleteSelection(); @@ -217,8 +215,6 @@ public slots: BitmapImage* currentBitmapImage(Layer* layer) const; VectorImage* currentVectorImage(Layer* layer) const; - std::unique_ptr mStrokeManager; - Editor* mEditor = nullptr; LayerVisibility mLayerVisibility = LayerVisibility::ALL; @@ -246,6 +242,7 @@ public slots: // Microsoft suggests that a double click action should be no more than 500 ms const int DOUBLE_CLICK_THRESHOLD = 500; QTimer* mDoubleClickTimer = nullptr; + QPointF mTabletPressPos; int mTabletReleaseMillisAgo; const int MOUSE_FILTER_THRESHOLD = 200; diff --git a/core_lib/src/tool/basetool.cpp b/core_lib/src/tool/basetool.cpp index c59bd50772..7ae8cb0626 100644 --- a/core_lib/src/tool/basetool.cpp +++ b/core_lib/src/tool/basetool.cpp @@ -21,7 +21,7 @@ GNU General Public License for more details. #include "editor.h" #include "viewmanager.h" #include "scribblearea.h" -#include "strokemanager.h" +#include "strokeinterpolator.h" #include "pointerevent.h" QString BaseTool::TypeName(ToolType type) @@ -81,7 +81,6 @@ void BaseTool::initialize(Editor* editor) mScribbleArea = editor->getScribbleArea(); Q_ASSERT(mScribbleArea); - mStrokeManager = mEditor->getScribbleArea()->getStrokeManager(); loadSettings(); } @@ -119,49 +118,9 @@ bool BaseTool::isDrawingTool() return true; } -bool BaseTool::isActive() +bool BaseTool::isActive() const { - return strokeManager()->isActive(); -} - -QPointF BaseTool::getCurrentPressPixel() const -{ - return strokeManager()->getCurrentPressPixel(); -} - -QPointF BaseTool::getCurrentPressPoint() const -{ - return mEditor->view()->mapScreenToCanvas(strokeManager()->getCurrentPressPixel()); -} - -QPointF BaseTool::getCurrentPixel() const -{ - return strokeManager()->getCurrentPixel(); -} - -QPointF BaseTool::getCurrentPoint() const -{ - return mEditor->view()->mapScreenToCanvas(getCurrentPixel()); -} - -QPointF BaseTool::getLastPixel() const -{ - return strokeManager()->getLastPixel(); -} - -QPointF BaseTool::getLastPoint() const -{ - return mEditor->view()->mapScreenToCanvas(getLastPixel()); -} - -QPointF BaseTool::getLastPressPixel() const -{ - return strokeManager()->getLastPressPixel(); -} - -QPointF BaseTool::getLastPressPoint() const -{ - return mEditor->view()->mapScreenToCanvas(getLastPressPixel()); + return false; } void BaseTool::setWidth(const qreal width) diff --git a/core_lib/src/tool/basetool.h b/core_lib/src/tool/basetool.h index 1c18ca635a..076f5bd9c1 100644 --- a/core_lib/src/tool/basetool.h +++ b/core_lib/src/tool/basetool.h @@ -33,7 +33,6 @@ class ScribbleArea; class QKeyEvent; class QMouseEvent; class QTabletEvent; -class StrokeManager; class PointerEvent; class Properties @@ -101,7 +100,7 @@ class BaseTool : public QObject * * @return Returns true if the tool is currently active, else returns false. */ - virtual bool isActive(); + virtual bool isActive() const; virtual void setWidth(const qreal width); virtual void setFeather(const qreal feather); @@ -136,15 +135,6 @@ class BaseTool : public QObject Properties properties; - QPointF getCurrentPressPixel() const; - QPointF getCurrentPressPoint() const; - QPointF getCurrentPixel() const; - QPointF getCurrentPoint() const; - QPointF getLastPixel() const; - QPointF getLastPoint() const; - QPointF getLastPressPixel() const; - QPointF getLastPressPoint() const; - bool isPropertyEnabled(ToolPropertyType t) { return mPropertyEnabled[t]; } bool isDrawingTool(); @@ -152,7 +142,6 @@ class BaseTool : public QObject bool isActiveChanged(ToolType, bool); protected: - StrokeManager* strokeManager() const { return mStrokeManager; } Editor* editor() { return mEditor; } QHash mPropertyEnabled; @@ -160,9 +149,6 @@ class BaseTool : public QObject Editor* mEditor = nullptr; ScribbleArea* mScribbleArea = nullptr; QList mActiveConnections; - -private: - StrokeManager* mStrokeManager = nullptr; }; #endif // BASETOOL_H diff --git a/core_lib/src/tool/brushtool.cpp b/core_lib/src/tool/brushtool.cpp index f7127dcc65..655f257f28 100644 --- a/core_lib/src/tool/brushtool.cpp +++ b/core_lib/src/tool/brushtool.cpp @@ -27,7 +27,6 @@ GNU General Public License for more details. #include "vectorimage.h" #include "editor.h" #include "colormanager.h" -#include "strokemanager.h" #include "layermanager.h" #include "viewmanager.h" #include "selectionmanager.h" @@ -141,6 +140,7 @@ QCursor BrushTool::cursor() void BrushTool::pointerPressEvent(PointerEvent *event) { + mInterpolator.pointerPressEvent(event); if (handleQuickSizing(event)) { return; } @@ -155,16 +155,19 @@ void BrushTool::pointerPressEvent(PointerEvent *event) void BrushTool::pointerMoveEvent(PointerEvent* event) { + mInterpolator.pointerMoveEvent(event); if (handleQuickSizing(event)) { return; } if (event->buttons() & Qt::LeftButton && event->inputType() == mCurrentInputType) { - mCurrentPressure = strokeManager()->getPressure(); + mCurrentPressure = mInterpolator.getPressure(); drawStroke(); - if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel()) - strokeManager()->setStabilizerLevel(properties.stabilizerLevel); + if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel()) + { + mInterpolator.setStabilizerLevel(properties.stabilizerLevel); + } } StrokeTool::pointerMoveEvent(event); @@ -172,6 +175,7 @@ void BrushTool::pointerMoveEvent(PointerEvent* event) void BrushTool::pointerReleaseEvent(PointerEvent *event) { + mInterpolator.pointerReleaseEvent(event); if (handleQuickSizing(event)) { return; } @@ -223,7 +227,7 @@ void BrushTool::paintAt(QPointF point) void BrushTool::drawStroke() { StrokeTool::drawStroke(); - QList p = strokeManager()->interpolateStroke(); + QList p = mInterpolator.interpolateStroke(); Layer* layer = mEditor->layers()->currentLayer(); diff --git a/core_lib/src/tool/buckettool.cpp b/core_lib/src/tool/buckettool.cpp index 54e57f5aa3..4e0668b00e 100644 --- a/core_lib/src/tool/buckettool.cpp +++ b/core_lib/src/tool/buckettool.cpp @@ -18,8 +18,6 @@ GNU General Public License for more details. #include #include -#include -#include #include #include "pointerevent.h" @@ -29,7 +27,6 @@ GNU General Public License for more details. #include "layercamera.h" #include "layermanager.h" #include "colormanager.h" -#include "strokemanager.h" #include "viewmanager.h" #include "vectorimage.h" #include "editor.h" @@ -169,6 +166,7 @@ void BucketTool::setFillReferenceMode(int referenceMode) void BucketTool::pointerPressEvent(PointerEvent* event) { + mInterpolator.pointerPressEvent(event); startStroke(event->inputType()); Layer* targetLayer = mEditor->layers()->currentLayer(); @@ -183,14 +181,15 @@ void BucketTool::pointerPressEvent(PointerEvent* event) getCurrentPoint(), properties); - // Because we can change layer to on the fly but we do not act reactively on it - // it's neccesary to invalidate layer cache on press event, otherwise the cache - // will be drawn until a move event has been initiated. + // Because we can change layer to on the fly, but we do not act reactively + // on it, it's necessary to invalidate layer cache on press event. + // Otherwise, the cache will be drawn until a move event has been initiated. mScribbleArea->invalidatePainterCaches(); } void BucketTool::pointerMoveEvent(PointerEvent* event) { + mInterpolator.pointerMoveEvent(event); if (event->buttons() & Qt::LeftButton && event->inputType() == mCurrentInputType) { Layer* layer = mEditor->layers()->currentLayer(); @@ -208,6 +207,7 @@ void BucketTool::pointerMoveEvent(PointerEvent* event) void BucketTool::pointerReleaseEvent(PointerEvent* event) { + mInterpolator.pointerReleaseEvent(event); if (event->inputType() != mCurrentInputType) return; Layer* layer = editor()->layers()->currentLayer(); @@ -275,12 +275,12 @@ void BucketTool::drawStroke() { StrokeTool::drawStroke(); - if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel()) + if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel()) { - strokeManager()->setStabilizerLevel(properties.stabilizerLevel); + mInterpolator.setStabilizerLevel(properties.stabilizerLevel); } - QList p = strokeManager()->interpolateStroke(); + QList p = mInterpolator.interpolateStroke(); Layer* layer = mEditor->layers()->currentLayer(); diff --git a/core_lib/src/tool/cameratool.cpp b/core_lib/src/tool/cameratool.cpp index ab39285397..20097a3fbb 100644 --- a/core_lib/src/tool/cameratool.cpp +++ b/core_lib/src/tool/cameratool.cpp @@ -18,6 +18,7 @@ GNU General Public License for more details. #include "cameratool.h" +#include "object.h" #include "editor.h" #include "pointerevent.h" #include "layermanager.h" @@ -117,7 +118,7 @@ QCursor CameraTool::cursor() QImage moveTypeImage; QPoint offset = QPoint(6, 6); - switch(moveMode()) + switch(mCamMoveMode) { case CameraMoveType::TOPLEFT: case CameraMoveType::BOTTOMRIGHT: @@ -160,36 +161,33 @@ QCursor CameraTool::cursor() return QCursor(cursorPixmap); } -CameraMoveType CameraTool::moveMode() +void CameraTool::updateMoveMode(const QPointF& pos) { if (mScribbleArea->isPointerInUse()) { - // Pointer in use, return previous used mode - return mCamMoveMode; + // Pointer in use, keep previous used mode + return; } Layer* layer = mEditor->layers()->currentLayer(); - CameraMoveType mode = CameraMoveType::NONE; + mCamMoveMode = CameraMoveType::NONE; qreal selectionTolerance = mEditor->select()->selectionTolerance(); - QPointF currentPoint = getCurrentPoint(); Q_ASSERT(layer->type() == Layer::CAMERA); LayerCamera* cam = static_cast(layer); if (layer->keyExists(mEditor->currentFrame())) { - mode = getCameraMoveMode(currentPoint, - selectionTolerance); - mCamMoveMode = mode; + mCamMoveMode = getCameraMoveMode(pos, + selectionTolerance); } else if (properties.cameraShowPath) { int keyPos = cam->firstKeyFramePosition(); while (keyPos <= cam->getMaxKeyFramePosition()) { - mode = getPathMoveMode(cam, - keyPos, - currentPoint, - selectionTolerance); - mCamPathMoveMode = mode; - if (mode != CameraMoveType::NONE) + mCamMoveMode = getPathMoveMode(cam, + keyPos, + pos, + selectionTolerance); + if (mCamMoveMode != CameraMoveType::NONE) { mDragPathFrame = keyPos; break; @@ -202,7 +200,6 @@ CameraMoveType CameraTool::moveMode() keyPos = cam->getNextKeyFramePosition(keyPos); } } - return mode; } void CameraTool::setShowCameraPath(const bool showCameraPath) @@ -245,32 +242,32 @@ void CameraTool::resetTransform(CameraFieldOption option) emit mEditor->frameModified(mEditor->currentFrame()); } -void CameraTool::transformCamera(Qt::KeyboardModifiers keyMod) +void CameraTool::transformCamera(const QPointF& pos, Qt::KeyboardModifiers keyMod) { Q_ASSERT(editor()->layers()->currentLayer()->type() == Layer::CAMERA); LayerCamera* layer = static_cast(editor()->layers()->currentLayer()); qreal angleDeg = 0; if (mCamMoveMode == CameraMoveType::ROTATION) { - angleDeg = getAngleBetween(getCurrentPoint(), mCameraRect.center()) - mStartAngle; + angleDeg = getAngleBetween(pos, mCameraRect.center()) - mStartAngle; if (keyMod == Qt::ShiftModifier) { angleDeg = constrainedRotation(angleDeg, mRotationIncrement); } mCurrentAngle = angleDeg; } - transformView(layer, mCamMoveMode, getCurrentPoint(), mTransformOffset, -angleDeg, mEditor->currentFrame()); + transformView(layer, mCamMoveMode, pos, mTransformOffset, -angleDeg, mEditor->currentFrame()); mEditor->updateFrame(); - mTransformOffset = getCurrentPoint(); + mTransformOffset = pos; } -void CameraTool::transformCameraPath() +void CameraTool::transformCameraPath(const QPointF& pos) { Q_ASSERT(editor()->layers()->currentLayer()->type() == Layer::CAMERA); LayerCamera* layer = static_cast(editor()->layers()->currentLayer()); - layer->updatePathControlPointAtFrame(getCurrentPoint(), mDragPathFrame); + layer->updatePathControlPointAtFrame(pos, mDragPathFrame); mEditor->updateFrame(); } @@ -279,27 +276,29 @@ int CameraTool::constrainedRotation(const qreal rotatedAngle, const int rotation return qRound(rotatedAngle / rotationIncrement) * rotationIncrement; } -void CameraTool::pointerPressEvent(PointerEvent*) +void CameraTool::pointerPressEvent(PointerEvent* event) { + updateMoveMode(event->canvasPos()); updateUIAssists(mEditor->layers()->currentLayer()); - mStartAngle = getAngleBetween(getCurrentPoint(), mCameraRect.center()) - mCurrentAngle; - mTransformOffset = getCurrentPoint(); + mStartAngle = getAngleBetween(event->canvasPos(), mCameraRect.center()) - mCurrentAngle; + mTransformOffset = event->canvasPos(); } void CameraTool::pointerMoveEvent(PointerEvent* event) { Layer* currentLayer = mEditor->layers()->currentLayer(); + updateMoveMode(event->canvasPos()); updateUIAssists(currentLayer); if (mScribbleArea->isPointerInUse()) // the user is also pressing the mouse (dragging) { if (currentLayer->keyExists(mEditor->currentFrame())) { - transformCamera(event->modifiers()); + transformCamera(event->canvasPos(), event->modifiers()); } - else if (mCamPathMoveMode == CameraMoveType::PATH) + else if (mCamMoveMode == CameraMoveType::PATH) { - transformCameraPath(); + transformCameraPath(event->canvasPos()); } } mScribbleArea->updateToolCursor(); @@ -310,14 +309,15 @@ void CameraTool::pointerMoveEvent(PointerEvent* event) void CameraTool::pointerReleaseEvent(PointerEvent* event) { Layer* layer = editor()->layers()->currentLayer(); + updateMoveMode(event->canvasPos()); updateUIAssists(layer); int frame = mEditor->currentFrame(); if (layer->keyExists(frame)) { - transformCamera(event->modifiers()); + transformCamera(event->canvasPos(), event->modifiers()); mEditor->view()->forceUpdateViewTransform(); - } else if (mCamPathMoveMode == CameraMoveType::PATH) { - transformCameraPath(); + } else if (mCamMoveMode == CameraMoveType::PATH) { + transformCameraPath(event->canvasPos()); mEditor->view()->forceUpdateViewTransform(); } emit mEditor->frameModified(frame); diff --git a/core_lib/src/tool/cameratool.h b/core_lib/src/tool/cameratool.h index 51adb8b44d..819fc89893 100644 --- a/core_lib/src/tool/cameratool.h +++ b/core_lib/src/tool/cameratool.h @@ -55,9 +55,9 @@ class CameraTool : public BaseTool void loadSettings() override; - void pointerPressEvent(PointerEvent*) override; - void pointerReleaseEvent(PointerEvent*) override; - void pointerMoveEvent(PointerEvent*) override; + void pointerPressEvent(PointerEvent* event) override; + void pointerReleaseEvent(PointerEvent* event) override; + void pointerMoveEvent(PointerEvent* event) override; void setShowCameraPath(const bool showCameraPath) override; void resetCameraPath() override; @@ -75,9 +75,9 @@ class CameraTool : public BaseTool void paintInterpolations(QPainter& painter, const QTransform& worldTransform, int currentFrame, const LayerCamera* cameraLayer, const Camera* keyframe, bool isPlaying) const; void paintControlPoint(QPainter& painter, const QTransform& worldTransform, const LayerCamera* cameraLayer, const int frameIndex, const QPointF& pathPoint, bool hollowHandle) const; - CameraMoveType moveMode(); - void transformCamera(Qt::KeyboardModifiers keyMod); - void transformCameraPath(); + void updateMoveMode(const QPointF& pos); + void transformCamera(const QPointF& pos, Qt::KeyboardModifiers keyMod); + void transformCameraPath(const QPointF& pos); void updateSettings(const SETTING setting); int constrainedRotation(const qreal rotatedAngle, const int rotationIncrement) const; @@ -91,7 +91,6 @@ class CameraTool : public BaseTool QPointF mTransformOffset; CameraMoveType mCamMoveMode = CameraMoveType::NONE; - CameraMoveType mCamPathMoveMode = CameraMoveType::NONE; int mDragPathFrame = 1; int mRotationIncrement = 0; diff --git a/core_lib/src/tool/erasertool.cpp b/core_lib/src/tool/erasertool.cpp index d87ac2a126..9b54d074d8 100644 --- a/core_lib/src/tool/erasertool.cpp +++ b/core_lib/src/tool/erasertool.cpp @@ -23,7 +23,6 @@ GNU General Public License for more details. #include "editor.h" #include "blitrect.h" #include "scribblearea.h" -#include "strokemanager.h" #include "layermanager.h" #include "viewmanager.h" #include "layervector.h" @@ -151,6 +150,7 @@ QCursor EraserTool::cursor() void EraserTool::pointerPressEvent(PointerEvent *event) { + mInterpolator.pointerPressEvent(event); if (handleQuickSizing(event)) { return; } @@ -164,16 +164,19 @@ void EraserTool::pointerPressEvent(PointerEvent *event) void EraserTool::pointerMoveEvent(PointerEvent* event) { + mInterpolator.pointerMoveEvent(event); if (handleQuickSizing(event)) { return; } if (event->buttons() & Qt::LeftButton && event->inputType() == mCurrentInputType) { - mCurrentPressure = strokeManager()->getPressure(); + mCurrentPressure = mInterpolator.getPressure(); updateStrokes(); - if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel()) - strokeManager()->setStabilizerLevel(properties.stabilizerLevel); + if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel()) + { + mInterpolator.setStabilizerLevel(properties.stabilizerLevel); + } } StrokeTool::pointerMoveEvent(event); @@ -181,6 +184,7 @@ void EraserTool::pointerMoveEvent(PointerEvent* event) void EraserTool::pointerReleaseEvent(PointerEvent *event) { + mInterpolator.pointerReleaseEvent(event); if (handleQuickSizing(event)) { return; } @@ -230,7 +234,7 @@ void EraserTool::paintAt(QPointF point) void EraserTool::drawStroke() { StrokeTool::drawStroke(); - QList p = strokeManager()->interpolateStroke(); + QList p = mInterpolator.interpolateStroke(); Layer* layer = mEditor->layers()->currentLayer(); @@ -275,7 +279,7 @@ void EraserTool::drawStroke() mCurrentWidth = properties.width; if (properties.pressure) { - mCurrentWidth = (mCurrentWidth + (strokeManager()->getPressure() * mCurrentWidth)) * 0.5; + mCurrentWidth = (mCurrentWidth + (mInterpolator.getPressure() * mCurrentWidth)) * 0.5; } qreal brushWidth = mCurrentWidth; diff --git a/core_lib/src/tool/eyedroppertool.cpp b/core_lib/src/tool/eyedroppertool.cpp index d72c3f71a3..69a4a7fdbc 100644 --- a/core_lib/src/tool/eyedroppertool.cpp +++ b/core_lib/src/tool/eyedroppertool.cpp @@ -80,14 +80,14 @@ QCursor EyedropperTool::cursor(const QColor color) void EyedropperTool::pointerPressEvent(PointerEvent*) {} -void EyedropperTool::pointerMoveEvent(PointerEvent*) +void EyedropperTool::pointerMoveEvent(PointerEvent* event) { Layer* layer = mEditor->layers()->currentLayer(); if (layer == nullptr) { return; } if (layer->type() == Layer::BITMAP) { - QColor pickedColor = getBitmapColor(static_cast(layer)); + QColor pickedColor = getBitmapColor(static_cast(layer), event->canvasPos()); if (pickedColor.isValid()) { mScribbleArea->setCursor(cursor(pickedColor)); @@ -99,7 +99,7 @@ void EyedropperTool::pointerMoveEvent(PointerEvent*) } if (layer->type() == Layer::VECTOR) { - int pickedColor = getVectorColor(static_cast(layer)); + int pickedColor = getVectorColor(static_cast(layer), event->canvasPos()); if (pickedColor >= 0) { mScribbleArea->setCursor(cursor(mEditor->object()->getColor(pickedColor).color)); @@ -115,20 +115,21 @@ void EyedropperTool::pointerReleaseEvent(PointerEvent* event) { if (event->button() == Qt::LeftButton) { - updateFrontColor(); + updateFrontColor(event->canvasPos()); // reset cursor mScribbleArea->setCursor(cursor()); } } -void EyedropperTool::updateFrontColor() +void EyedropperTool::updateFrontColor(const QPointF& pos) { Layer* layer = mEditor->layers()->currentLayer(); if (layer == nullptr) { return; } + if (layer->type() == Layer::BITMAP) { - QColor pickedColor = getBitmapColor(static_cast(layer)); + QColor pickedColor = getBitmapColor(static_cast(layer), pos); if (pickedColor.isValid()) { mEditor->color()->setFrontColor(pickedColor); @@ -136,7 +137,7 @@ void EyedropperTool::updateFrontColor() } else if (layer->type() == Layer::VECTOR) { - int pickedColor = getVectorColor(static_cast(layer)); + int pickedColor = getVectorColor(static_cast(layer), pos); if (pickedColor >= 0) { mEditor->color()->setColorNumber(pickedColor); @@ -144,28 +145,28 @@ void EyedropperTool::updateFrontColor() } } -QColor EyedropperTool::getBitmapColor(LayerBitmap* layer) +QColor EyedropperTool::getBitmapColor(LayerBitmap* layer, const QPointF& pos) { BitmapImage* targetImage = layer->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0); - if (targetImage == nullptr || !targetImage->contains(getCurrentPoint())) return QColor(); + if (targetImage == nullptr || !targetImage->contains(pos)) return QColor(); QColor pickedColour; - const QRgb pixelColor = targetImage->constScanLine(qFloor(getCurrentPoint().x()), - qFloor(getCurrentPoint().y())); + const QRgb pixelColor = targetImage->constScanLine(qFloor(pos.x()), + qFloor(pos.y())); pickedColour.setRgba(pixelColor); if (pickedColour.alpha() <= 0) pickedColour = QColor(); return pickedColour; } -int EyedropperTool::getVectorColor(LayerVector* layer) +int EyedropperTool::getVectorColor(LayerVector* layer, const QPointF& pos) { auto vectorImage = static_cast(layer->getLastKeyFrameAtPosition(mEditor->currentFrame())); if (vectorImage == nullptr) return -1; // Check curves const qreal toleranceDistance = 10.0; - const QList closestCurves = vectorImage->getCurvesCloseTo(getCurrentPoint(), toleranceDistance); + const QList closestCurves = vectorImage->getCurvesCloseTo(pos, toleranceDistance); const QList visibleClosestCurves = filter(closestCurves, [vectorImage](int i) { return vectorImage->isCurveVisible(i); }); if (!visibleClosestCurves.isEmpty()) @@ -174,6 +175,6 @@ int EyedropperTool::getVectorColor(LayerVector* layer) } // Check fills - int colorNumber = vectorImage->getColorNumber(getCurrentPoint()); + int colorNumber = vectorImage->getColorNumber(pos); return colorNumber; } diff --git a/core_lib/src/tool/eyedroppertool.h b/core_lib/src/tool/eyedroppertool.h index 1cd47a0771..674cf31cad 100644 --- a/core_lib/src/tool/eyedroppertool.h +++ b/core_lib/src/tool/eyedroppertool.h @@ -35,16 +35,16 @@ class EyedropperTool : public BaseTool void pointerPressEvent( PointerEvent* ) override; void pointerReleaseEvent( PointerEvent* event ) override; - void pointerMoveEvent( PointerEvent* ) override; + void pointerMoveEvent( PointerEvent* event ) override; /** Updates front color for bitmap and color index for vector */ - void updateFrontColor(); + void updateFrontColor(const QPointF& pos); private: /** Retrieves color of the pixel under the cursor for a bitmap layer */ - QColor getBitmapColor(LayerBitmap* layer); + QColor getBitmapColor(LayerBitmap* layer, const QPointF& pos); /** Retrieves the color index of the pixel under the cursor for a vector layer */ - int getVectorColor(LayerVector *layer); + int getVectorColor(LayerVector *layer, const QPointF& pos); }; #endif // EYEDROPPERTOOL_H diff --git a/core_lib/src/tool/handtool.cpp b/core_lib/src/tool/handtool.cpp index d741a2ed12..ef0deb2eab 100644 --- a/core_lib/src/tool/handtool.cpp +++ b/core_lib/src/tool/handtool.cpp @@ -18,14 +18,13 @@ GNU General Public License for more details. #include "handtool.h" #include -#include #include #include #include "layer.h" #include "layercamera.h" #include "editor.h" -#include "strokemanager.h" +#include "strokeinterpolator.h" #include "viewmanager.h" #include "scribblearea.h" @@ -65,10 +64,10 @@ QCursor HandTool::cursor() return mIsHeld ? QCursor(Qt::ClosedHandCursor) : QCursor(Qt::OpenHandCursor); } -void HandTool::pointerPressEvent(PointerEvent*) +void HandTool::pointerPressEvent(PointerEvent* event) { - mLastPixel = getCurrentPixel(); - mStartPoint = mEditor->view()->mapScreenToCanvas(mLastPixel); + mLastPixel = event->viewportPos(); + mStartPoint = event->canvasPos(); mIsHeld = true; mScribbleArea->updateToolCursor(); @@ -81,8 +80,8 @@ void HandTool::pointerMoveEvent(PointerEvent* event) return; } - transformView(event->modifiers(), event->buttons()); - mLastPixel = getCurrentPixel(); + transformView(event->modifiers(), event->viewportPos(), event->buttons()); + mLastPixel = event->viewportPos(); } void HandTool::pointerReleaseEvent(PointerEvent* event) @@ -100,7 +99,7 @@ void HandTool::pointerDoubleClickEvent(PointerEvent* event) } } -void HandTool::transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons buttons) +void HandTool::transformView(Qt::KeyboardModifiers keyMod, const QPointF& pos, Qt::MouseButtons buttons) { bool isTranslate = keyMod == Qt::NoModifier; bool isRotate = keyMod & Qt::AltModifier; @@ -110,15 +109,15 @@ void HandTool::transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons butt if (isTranslate) { - QPointF d = getCurrentPoint() - getLastPoint(); + QPointF d = viewMgr->mapScreenToCanvas(pos) - viewMgr->mapScreenToCanvas(mLastPixel); QPointF offset = viewMgr->translation() + d; viewMgr->translate(offset); } else if (isRotate) { QPoint centralPixel(mScribbleArea->width() / 2, mScribbleArea->height() / 2); - QVector2D startV(getLastPixel() - centralPixel); - QVector2D curV(getCurrentPixel() - centralPixel); + QVector2D startV(mLastPixel - centralPixel); + QVector2D curV(pos - centralPixel); qreal angleOffset = static_cast(std::atan2(curV.y(), curV.x()) - std::atan2(startV.y(), startV.x())); angleOffset = qRadiansToDegrees(angleOffset); @@ -129,7 +128,7 @@ void HandTool::transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons butt } else if (isScale) { - const float delta = (static_cast(getCurrentPixel().y() - mLastPixel.y())) / 100.f; + const float delta = (static_cast(pos.y() - mLastPixel.y())) / 100.f; const qreal scaleValue = viewMgr->scaling() * (1 + (delta * mDeltaFactor)); viewMgr->scaleAtOffset(scaleValue, mStartPoint); } diff --git a/core_lib/src/tool/handtool.h b/core_lib/src/tool/handtool.h index 1f17747b74..56078179ba 100644 --- a/core_lib/src/tool/handtool.h +++ b/core_lib/src/tool/handtool.h @@ -36,11 +36,9 @@ class HandTool : public BaseTool void pointerMoveEvent(PointerEvent *) override; void pointerDoubleClickEvent(PointerEvent *) override; - virtual bool isActive() override { return false; } - private: void updateSettings(const SETTING setting); - void transformView(Qt::KeyboardModifiers keyMod, Qt::MouseButtons buttons); + void transformView(Qt::KeyboardModifiers keyMod, const QPointF& pos, Qt::MouseButtons buttons); QPointF mLastPixel; QPointF mStartPoint; diff --git a/core_lib/src/tool/movetool.cpp b/core_lib/src/tool/movetool.cpp index e93ffe2529..9569131bfe 100644 --- a/core_lib/src/tool/movetool.cpp +++ b/core_lib/src/tool/movetool.cpp @@ -24,8 +24,7 @@ GNU General Public License for more details. #include "pointerevent.h" #include "editor.h" #include "toolmanager.h" -#include "viewmanager.h" -#include "strokemanager.h" +#include "strokeinterpolator.h" #include "selectionmanager.h" #include "overlaymanager.h" #include "scribblearea.h" @@ -69,10 +68,7 @@ QCursor MoveTool::cursor() } else if (mEditor->overlays()->anyOverlayEnabled()) { - LayerCamera* layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex()); - Q_ASSERT(layerCam); - mode = mEditor->overlays()->getMoveModeForPoint(getCurrentPoint(), layerCam->getViewAtFrame(mEditor->currentFrame())); - mPerspMode = mode; + mode = mPerspMode; } return cursor(mode); @@ -106,16 +102,16 @@ void MoveTool::pointerPressEvent(PointerEvent* event) if (mEditor->select()->somethingSelected()) { - beginInteraction(event->modifiers(), currentLayer); + beginInteraction(event->canvasPos(), event->modifiers(), currentLayer); } - if (mEditor->overlays()->anyOverlayEnabled()) + else if (mEditor->overlays()->anyOverlayEnabled()) { - mEditor->overlays()->setMoveMode(mPerspMode); - LayerCamera* layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex()); Q_ASSERT(layerCam); - QPoint mapped = layerCam->getViewAtFrame(mEditor->currentFrame()).map(getCurrentPoint()).toPoint(); + mPerspMode = mEditor->overlays()->getMoveModeForPoint(event->canvasPos(), layerCam->getViewAtFrame(mEditor->currentFrame())); + mEditor->overlays()->setMoveMode(mPerspMode); + QPoint mapped = layerCam->getViewAtFrame(mEditor->currentFrame()).map(event->canvasPos()).toPoint(); mEditor->overlays()->updatePerspective(mapped); } @@ -129,29 +125,35 @@ void MoveTool::pointerMoveEvent(PointerEvent* event) if (mScribbleArea->isPointerInUse()) // the user is also pressing the mouse (dragging) { - transformSelection(event->modifiers()); + transformSelection(event->canvasPos(), event->modifiers()); if (mEditor->overlays()->anyOverlayEnabled()) { LayerCamera* layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex()); Q_ASSERT(layerCam); - mEditor->overlays()->updatePerspective(layerCam->getViewAtFrame(mEditor->currentFrame()).map(getCurrentPoint())); + mEditor->overlays()->updatePerspective(layerCam->getViewAtFrame(mEditor->currentFrame()).map(event->canvasPos())); } if (mEditor->select()->somethingSelected()) { - transformSelection(event->modifiers()); + transformSelection(event->canvasPos(), event->modifiers()); } } else { // the user is moving the mouse without pressing it // update cursor to reflect selection corner interaction - mEditor->select()->setMoveModeForAnchorInRange(getCurrentPoint()); + mEditor->select()->setMoveModeForAnchorInRange(event->canvasPos()); + if (mEditor->overlays()->anyOverlayEnabled()) + { + LayerCamera *layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex()); + Q_ASSERT(layerCam); + mPerspMode = mEditor->overlays()->getMoveModeForPoint(event->canvasPos(), layerCam->getViewAtFrame(mEditor->currentFrame())); + } mScribbleArea->updateToolCursor(); if (currentLayer->type() == Layer::VECTOR) { - storeClosestVectorCurve(currentLayer); + storeClosestVectorCurve(event->canvasPos(), currentLayer); } } mEditor->updateFrame(); @@ -173,7 +175,7 @@ void MoveTool::pointerReleaseEvent(PointerEvent*) mEditor->frameModified(mEditor->currentFrame()); } -void MoveTool::transformSelection(Qt::KeyboardModifiers keyMod) +void MoveTool::transformSelection(const QPointF& pos, Qt::KeyboardModifiers keyMod) { auto selectMan = mEditor->select(); if (selectMan->somethingSelected()) @@ -190,11 +192,11 @@ void MoveTool::transformSelection(Qt::KeyboardModifiers keyMod) qreal newAngle = 0; if (selectMan->getMoveMode() == MoveMode::ROTATION) { QPointF anchorPoint = selectMan->currentTransformAnchor(); - newAngle = selectMan->angleFromPoint(getCurrentPoint(), anchorPoint) - mRotatedAngle; + newAngle = selectMan->angleFromPoint(pos, anchorPoint) - mRotatedAngle; mPreviousAngle = newAngle; } - selectMan->adjustSelection(getCurrentPoint(), mOffset, newAngle, rotationIncrement); + selectMan->adjustSelection(pos, mOffset, newAngle, rotationIncrement); } else // there is nothing selected { @@ -202,7 +204,7 @@ void MoveTool::transformSelection(Qt::KeyboardModifiers keyMod) } } -void MoveTool::beginInteraction(Qt::KeyboardModifiers keyMod, Layer* layer) +void MoveTool::beginInteraction(const QPointF& pos, Qt::KeyboardModifiers keyMod, Layer* layer) { auto selectMan = mEditor->select(); QRectF selectionRect = selectMan->mySelectionRect(); @@ -213,7 +215,7 @@ void MoveTool::beginInteraction(Qt::KeyboardModifiers keyMod, Layer* layer) if (keyMod != Qt::ShiftModifier) { - if (selectMan->isOutsideSelectionArea(getCurrentPoint())) + if (selectMan->isOutsideSelectionArea(pos)) { applyTransformation(); mEditor->deselectAll(); @@ -230,15 +232,15 @@ void MoveTool::beginInteraction(Qt::KeyboardModifiers keyMod, Layer* layer) if (layer->type() == Layer::VECTOR) { - createVectorSelection(keyMod, layer); + createVectorSelection(pos, keyMod, layer); } selectMan->setTransformAnchor(selectMan->getSelectionAnchorPoint()); - selectMan->setDragOrigin(getCurrentPressPoint()); + selectMan->setDragOrigin(pos); mOffset = selectMan->myTranslation(); if(selectMan->getMoveMode() == MoveMode::ROTATION) { - mRotatedAngle = selectMan->angleFromPoint(getCurrentPoint(), selectMan->currentTransformAnchor()) - mPreviousAngle; + mRotatedAngle = selectMan->angleFromPoint(pos, selectMan->currentTransformAnchor()) - mPreviousAngle; } } @@ -247,7 +249,7 @@ void MoveTool::beginInteraction(Qt::KeyboardModifiers keyMod, Layer* layer) * In vector the selection rectangle is based on the bounding box of the curves * We can therefore create a selection just by clicking near/on a curve */ -void MoveTool::createVectorSelection(Qt::KeyboardModifiers keyMod, Layer* layer) +void MoveTool::createVectorSelection(const QPointF& pos, Qt::KeyboardModifiers keyMod, Layer* layer) { assert(layer->type() == Layer::VECTOR); LayerVector* vecLayer = static_cast(layer); @@ -258,9 +260,9 @@ void MoveTool::createVectorSelection(Qt::KeyboardModifiers keyMod, Layer* layer) { setCurveSelected(vectorImage, keyMod); } - else if (vectorImage->getLastAreaNumber(getLastPoint()) > -1) + else if (vectorImage->getLastAreaNumber(pos) > -1) { - setAreaSelected(vectorImage, keyMod); + setAreaSelected(pos, vectorImage, keyMod); } } @@ -278,9 +280,9 @@ void MoveTool::setCurveSelected(VectorImage* vectorImage, Qt::KeyboardModifiers } } -void MoveTool::setAreaSelected(VectorImage* vectorImage, Qt::KeyboardModifiers keyMod) +void MoveTool::setAreaSelected(const QPointF& pos, VectorImage* vectorImage, Qt::KeyboardModifiers keyMod) { - int areaNumber = vectorImage->getLastAreaNumber(getLastPoint()); + int areaNumber = vectorImage->getLastAreaNumber(pos); if (!vectorImage->isAreaSelected(areaNumber)) { if (keyMod != Qt::ShiftModifier) @@ -296,13 +298,13 @@ void MoveTool::setAreaSelected(VectorImage* vectorImage, Qt::KeyboardModifiers k * @brief MoveTool::storeClosestVectorCurve * stores the curves closest to the mouse position in mClosestCurves */ -void MoveTool::storeClosestVectorCurve(Layer* layer) +void MoveTool::storeClosestVectorCurve(const QPointF& pos, Layer* layer) { auto selectMan = mEditor->select(); auto layerVector = static_cast(layer); VectorImage* pVecImg = layerVector->getLastVectorImageAtFrame(mEditor->currentFrame(), 0); if (pVecImg == nullptr) { return; } - selectMan->setCurves(pVecImg->getCurvesCloseTo(getCurrentPoint(), selectMan->selectionTolerance())); + selectMan->setCurves(pVecImg->getCurvesCloseTo(pos, selectMan->selectionTolerance())); } void MoveTool::applyTransformation() @@ -328,6 +330,11 @@ bool MoveTool::leavingThisTool() return true; } +bool MoveTool::isActive() const { + return mScribbleArea->isPointerInUse() && + (mEditor->select()->somethingSelected() || mEditor->overlays()->getMoveMode() != MoveMode::NONE); +} + void MoveTool::resetToDefault() { setShowSelectionInfo(false); diff --git a/core_lib/src/tool/movetool.h b/core_lib/src/tool/movetool.h index 38107d642d..24c39dae22 100644 --- a/core_lib/src/tool/movetool.h +++ b/core_lib/src/tool/movetool.h @@ -41,6 +41,7 @@ class MoveTool : public BaseTool void pointerMoveEvent(PointerEvent*) override; bool leavingThisTool() override; + bool isActive() const override; void resetToDefault() override; void setShowSelectionInfo(const bool b) override; @@ -49,16 +50,17 @@ class MoveTool : public BaseTool void applyTransformation(); void updateSettings(const SETTING setting); - void beginInteraction(Qt::KeyboardModifiers keyMod, Layer* layer); - void createVectorSelection(Qt::KeyboardModifiers keyMod, Layer* layer); - void transformSelection(Qt::KeyboardModifiers keyMod); - void storeClosestVectorCurve(Layer* layer); + void beginInteraction(const QPointF& pos, Qt::KeyboardModifiers keyMod, Layer* layer); + void createVectorSelection(const QPointF& pos, Qt::KeyboardModifiers keyMod, Layer* layer); + void transformSelection(const QPointF& pos, Qt::KeyboardModifiers keyMod); + void storeClosestVectorCurve(const QPointF& pos, Layer* layer); void setCurveSelected(VectorImage* vectorImage, Qt::KeyboardModifiers keyMod); - void setAreaSelected(VectorImage* vectorImage, Qt::KeyboardModifiers keyMod); + void setAreaSelected(const QPointF& pos, VectorImage* vectorImage, Qt::KeyboardModifiers keyMod); Layer* currentPaintableLayer(); + QPointF mCurrentPoint; qreal mRotatedAngle = 0.0; qreal mPreviousAngle = 0.0; int mRotationIncrement = 0; diff --git a/core_lib/src/tool/penciltool.cpp b/core_lib/src/tool/penciltool.cpp index 4fde93f17d..a0f63e9025 100644 --- a/core_lib/src/tool/penciltool.cpp +++ b/core_lib/src/tool/penciltool.cpp @@ -22,7 +22,6 @@ GNU General Public License for more details. #include "layermanager.h" #include "colormanager.h" -#include "strokemanager.h" #include "viewmanager.h" #include "preferencemanager.h" #include "selectionmanager.h" @@ -146,6 +145,7 @@ QCursor PencilTool::cursor() void PencilTool::pointerPressEvent(PointerEvent *event) { + mInterpolator.pointerPressEvent(event); if (handleQuickSizing(event)) { return; } @@ -166,22 +166,26 @@ void PencilTool::pointerPressEvent(PointerEvent *event) void PencilTool::pointerMoveEvent(PointerEvent* event) { + mInterpolator.pointerMoveEvent(event); if (handleQuickSizing(event)) { return; } if (event->buttons() & Qt::LeftButton && event->inputType() == mCurrentInputType) { - mCurrentPressure = strokeManager()->getPressure(); + mCurrentPressure = mInterpolator.getPressure(); drawStroke(); - if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel()) - strokeManager()->setStabilizerLevel(properties.stabilizerLevel); + if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel()) + { + mInterpolator.setStabilizerLevel(properties.stabilizerLevel); + } } StrokeTool::pointerMoveEvent(event); } void PencilTool::pointerReleaseEvent(PointerEvent *event) { + mInterpolator.pointerReleaseEvent(event); if (handleQuickSizing(event)) { return; } @@ -233,7 +237,7 @@ void PencilTool::paintAt(QPointF point) void PencilTool::drawStroke() { StrokeTool::drawStroke(); - QList p = strokeManager()->interpolateStroke(); + QList p = mInterpolator.interpolateStroke(); Layer* layer = mEditor->layers()->currentLayer(); diff --git a/core_lib/src/tool/pentool.cpp b/core_lib/src/tool/pentool.cpp index a2f9858722..65c262f44f 100644 --- a/core_lib/src/tool/pentool.cpp +++ b/core_lib/src/tool/pentool.cpp @@ -22,7 +22,6 @@ GNU General Public License for more details. #include "vectorimage.h" #include "layervector.h" #include "colormanager.h" -#include "strokemanager.h" #include "layermanager.h" #include "viewmanager.h" #include "selectionmanager.h" @@ -120,6 +119,7 @@ QCursor PenTool::cursor() void PenTool::pointerPressEvent(PointerEvent *event) { + mInterpolator.pointerPressEvent(event); if (handleQuickSizing(event)) { return; } @@ -134,16 +134,19 @@ void PenTool::pointerPressEvent(PointerEvent *event) void PenTool::pointerMoveEvent(PointerEvent* event) { + mInterpolator.pointerMoveEvent(event); if (handleQuickSizing(event)) { return; } if (event->buttons() & Qt::LeftButton && event->inputType() == mCurrentInputType) { - mCurrentPressure = strokeManager()->getPressure(); + mCurrentPressure = mInterpolator.getPressure(); drawStroke(); - if (properties.stabilizerLevel != strokeManager()->getStabilizerLevel()) - strokeManager()->setStabilizerLevel(properties.stabilizerLevel); + if (properties.stabilizerLevel != mInterpolator.getStabilizerLevel()) + { + mInterpolator.setStabilizerLevel(properties.stabilizerLevel); + } } StrokeTool::pointerMoveEvent(event); @@ -151,6 +154,7 @@ void PenTool::pointerMoveEvent(PointerEvent* event) void PenTool::pointerReleaseEvent(PointerEvent *event) { + mInterpolator.pointerReleaseEvent(event); if (handleQuickSizing(event)) { return; } @@ -199,7 +203,7 @@ void PenTool::paintAt(QPointF point) void PenTool::drawStroke() { StrokeTool::drawStroke(); - QList p = strokeManager()->interpolateStroke(); + QList p = mInterpolator.interpolateStroke(); Layer* layer = mEditor->layers()->currentLayer(); diff --git a/core_lib/src/tool/polylinetool.cpp b/core_lib/src/tool/polylinetool.cpp index 5a3c664cd4..3779b2a7c3 100644 --- a/core_lib/src/tool/polylinetool.cpp +++ b/core_lib/src/tool/polylinetool.cpp @@ -105,7 +105,7 @@ bool PolylineTool::leavingThisTool() return true; } -bool PolylineTool::isActive() +bool PolylineTool::isActive() const { return !mPoints.isEmpty(); } @@ -123,6 +123,7 @@ void PolylineTool::clearToolData() void PolylineTool::pointerPressEvent(PointerEvent* event) { + mInterpolator.pointerPressEvent(event); if (handleQuickSizing(event)) { return; } @@ -155,6 +156,7 @@ void PolylineTool::pointerPressEvent(PointerEvent* event) void PolylineTool::pointerMoveEvent(PointerEvent* event) { + mInterpolator.pointerMoveEvent(event); if (handleQuickSizing(event)) { return; } @@ -170,6 +172,7 @@ void PolylineTool::pointerMoveEvent(PointerEvent* event) void PolylineTool::pointerReleaseEvent(PointerEvent* event) { + mInterpolator.pointerReleaseEvent(event); if (handleQuickSizing(event)) { return; } @@ -177,8 +180,9 @@ void PolylineTool::pointerReleaseEvent(PointerEvent* event) StrokeTool::pointerReleaseEvent(event); } -void PolylineTool::pointerDoubleClickEvent(PointerEvent*) +void PolylineTool::pointerDoubleClickEvent(PointerEvent* event) { + mInterpolator.pointerPressEvent(event); // include the current point before ending the line. mPoints << getCurrentPoint(); diff --git a/core_lib/src/tool/polylinetool.h b/core_lib/src/tool/polylinetool.h index b1b11683d4..02b63d8634 100644 --- a/core_lib/src/tool/polylinetool.h +++ b/core_lib/src/tool/polylinetool.h @@ -47,7 +47,7 @@ class PolylineTool : public StrokeTool bool leavingThisTool() override; - virtual bool isActive() override; + bool isActive() const override; private: QList mPoints; diff --git a/core_lib/src/tool/selecttool.cpp b/core_lib/src/tool/selecttool.cpp index 1fa4d639a9..02c1653436 100644 --- a/core_lib/src/tool/selecttool.cpp +++ b/core_lib/src/tool/selecttool.cpp @@ -45,7 +45,6 @@ QCursor SelectTool::cursor() // Don't update cursor while we're moving the selection if (mScribbleArea->isPointerInUse()) { return QCursor(mCursorPixmap); } - mEditor->select()->setMoveModeForAnchorInRange(getCurrentPoint()); MoveMode mode = mEditor->select()->getMoveMode(); mCursorPixmap.fill(QColor(255, 255, 255, 0)); @@ -94,7 +93,7 @@ void SelectTool::setShowSelectionInfo(const bool b) settings.setValue("ShowSelectionInfo", b); } -void SelectTool::beginSelection(Layer* currentLayer) +void SelectTool::beginSelection(Layer* currentLayer, const QPointF& pos) { auto selectMan = mEditor->select(); @@ -111,8 +110,8 @@ void SelectTool::beginSelection(Layer* currentLayer) } else { - selectMan->setSelection(QRectF(getCurrentPoint().x(), getCurrentPoint().y(), 1, 1), mEditor->layers()->currentLayer()->type() == Layer::BITMAP); - mAnchorOriginPoint = getLastPoint(); + selectMan->setSelection(QRectF(pos.x(), pos.y(), 1, 1), mEditor->layers()->currentLayer()->type() == Layer::BITMAP); + mAnchorOriginPoint = pos; } mScribbleArea->updateFrame(); @@ -126,14 +125,15 @@ void SelectTool::pointerPressEvent(PointerEvent* event) if (event->button() != Qt::LeftButton) { return; } auto selectMan = mEditor->select(); - selectMan->setMoveModeForAnchorInRange(getCurrentPoint()); + mPressPoint = event->canvasPos(); + selectMan->setMoveModeForAnchorInRange(mPressPoint); mMoveMode = selectMan->getMoveMode(); mStartMoveMode = mMoveMode; - beginSelection(currentLayer); + beginSelection(currentLayer, mPressPoint); } -void SelectTool::pointerMoveEvent(PointerEvent*) +void SelectTool::pointerMoveEvent(PointerEvent* event) { Layer* currentLayer = mEditor->layers()->currentLayer(); if (currentLayer == nullptr) { return; } @@ -142,13 +142,13 @@ void SelectTool::pointerMoveEvent(PointerEvent*) if (!selectMan->somethingSelected()) { return; } - selectMan->setMoveModeForAnchorInRange(getCurrentPoint()); + selectMan->setMoveModeForAnchorInRange(event->canvasPos()); mMoveMode = selectMan->getMoveMode(); mScribbleArea->updateToolCursor(); if (mScribbleArea->isPointerInUse()) { - controlOffsetOrigin(getCurrentPoint(), mAnchorOriginPoint); + controlOffsetOrigin(event->canvasPos(), mAnchorOriginPoint); if (currentLayer->type() == Layer::VECTOR) { @@ -171,11 +171,11 @@ void SelectTool::pointerReleaseEvent(PointerEvent* event) // if there's a small very small distance between current and last point // discard the selection... // TODO: improve by adding a timer to check if the user is deliberately selecting - if (QLineF(mAnchorOriginPoint, getCurrentPoint()).length() < 5.0) + if (QLineF(mAnchorOriginPoint, event->canvasPos()).length() < 5.0) { mEditor->deselectAll(); } - if (maybeDeselect()) + if (maybeDeselect(event->canvasPos())) { mEditor->deselectAll(); } @@ -191,9 +191,9 @@ void SelectTool::pointerReleaseEvent(PointerEvent* event) mScribbleArea->updateFrame(); } -bool SelectTool::maybeDeselect() +bool SelectTool::maybeDeselect(const QPointF& pos) { - return (!isSelectionPointValid() && mEditor->select()->getMoveMode() == MoveMode::NONE); + return (!isSelectionPointValid(pos) && mEditor->select()->getMoveMode() == MoveMode::NONE); } /** @@ -202,11 +202,11 @@ bool SelectTool::maybeDeselect() */ void SelectTool::keepSelection(Layer* currentLayer) { - auto selectMan = mEditor->select(); if (currentLayer->type() == Layer::VECTOR) { VectorImage* vectorImage = static_cast(currentLayer)->getLastVectorImageAtFrame(mEditor->currentFrame(), 0); if (vectorImage == nullptr) { return; } + auto selectMan = mEditor->select(); selectMan->setSelection(vectorImage->getSelectionRect(), false); } } @@ -217,7 +217,7 @@ void SelectTool::controlOffsetOrigin(QPointF currentPoint, QPointF anchorPoint) if (mStartMoveMode != MoveMode::NONE) { QRectF rect = mSelectionRect; - QPointF offset = offsetFromPressPos(); + QPointF offset = offsetFromPressPos(currentPoint); if (mStartMoveMode == MoveMode::TOPLEFT) { rect.adjust(offset.x(), offset.y(), 0, 0); } else if (mStartMoveMode == MoveMode::TOPRIGHT) { @@ -300,7 +300,7 @@ bool SelectTool::keyPressEvent(QKeyEvent* event) return BaseTool::keyPressEvent(event); } -QPointF SelectTool::offsetFromPressPos() +QPointF SelectTool::offsetFromPressPos(const QPointF& pos) { - return getCurrentPoint() - getCurrentPressPoint(); + return pos - mPressPoint; } diff --git a/core_lib/src/tool/selecttool.h b/core_lib/src/tool/selecttool.h index 16e7328468..91a1d106eb 100644 --- a/core_lib/src/tool/selecttool.h +++ b/core_lib/src/tool/selecttool.h @@ -50,17 +50,18 @@ class SelectTool : public BaseTool void manageSelectionOrigin(QPointF currentPoint, QPointF originPoint); void controlOffsetOrigin(QPointF currentPoint, QPointF anchorPoint); - void beginSelection(Layer* currentLayer); + void beginSelection(Layer* currentLayer, const QPointF& pos); void keepSelection(Layer* currentLayer); - QPointF offsetFromPressPos(); + QPointF offsetFromPressPos(const QPointF& pos); - inline bool isSelectionPointValid() { return mAnchorOriginPoint != getLastPoint(); } - bool maybeDeselect(); + inline bool isSelectionPointValid(const QPointF& pos) { return mAnchorOriginPoint != pos; } + bool maybeDeselect(const QPointF& pos); // Store selection origin, so we can calculate // the selection rectangle in mousePressEvent. QPointF mAnchorOriginPoint; + QPointF mPressPoint; MoveMode mMoveMode; MoveMode mStartMoveMode = MoveMode::NONE; QRectF mSelectionRect; diff --git a/core_lib/src/tool/smudgetool.cpp b/core_lib/src/tool/smudgetool.cpp index e3594b9ae1..e951121780 100644 --- a/core_lib/src/tool/smudgetool.cpp +++ b/core_lib/src/tool/smudgetool.cpp @@ -24,7 +24,6 @@ GNU General Public License for more details. #include "scribblearea.h" #include "layermanager.h" -#include "strokemanager.h" #include "viewmanager.h" #include "selectionmanager.h" @@ -139,6 +138,7 @@ bool SmudgeTool::keyReleaseEvent(QKeyEvent *event) void SmudgeTool::pointerPressEvent(PointerEvent* event) { + mInterpolator.pointerPressEvent(event); if (handleQuickSizing(event)) { return; } @@ -196,6 +196,7 @@ void SmudgeTool::pointerPressEvent(PointerEvent* event) void SmudgeTool::pointerMoveEvent(PointerEvent* event) { + mInterpolator.pointerMoveEvent(event); if (handleQuickSizing(event)) { return; } @@ -256,6 +257,7 @@ void SmudgeTool::pointerMoveEvent(PointerEvent* event) void SmudgeTool::pointerReleaseEvent(PointerEvent* event) { + mInterpolator.pointerReleaseEvent(event); if (handleQuickSizing(event)) { return; } @@ -307,7 +309,7 @@ void SmudgeTool::drawStroke() if (sourceImage == nullptr) { return; } // Can happen if the first frame is deleted while drawing BitmapImage targetImage = sourceImage->copy(); StrokeTool::drawStroke(); - QList p = strokeManager()->interpolateStroke(); + QList p = mInterpolator.interpolateStroke(); for (int i = 0; i < p.size(); i++) { @@ -321,7 +323,6 @@ void SmudgeTool::drawStroke() //opacity = currentPressure; // todo: Probably not interesting?! //brushWidth = brushWidth * opacity; - BlitRect rect; QPointF a = mLastBrushPoint; QPointF b = getCurrentPoint(); diff --git a/core_lib/src/tool/strokemanager.cpp b/core_lib/src/tool/strokeinterpolator.cpp similarity index 84% rename from core_lib/src/tool/strokemanager.cpp rename to core_lib/src/tool/strokeinterpolator.cpp index d94ba58b1c..5eef01a382 100644 --- a/core_lib/src/tool/strokemanager.cpp +++ b/core_lib/src/tool/strokeinterpolator.cpp @@ -18,29 +18,23 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include "strokemanager.h" +#include "strokeinterpolator.h" -#include -#include -#include #include #include #include "object.h" #include "pointerevent.h" - -StrokeManager::StrokeManager() +StrokeInterpolator::StrokeInterpolator() { - m_timeshot = 0; - mTabletInUse = false; mTabletPressure = 0; reset(); - connect(&timer, &QTimer::timeout, this, &StrokeManager::interpolatePollAndPaint); + connect(&timer, &QTimer::timeout, this, &StrokeInterpolator::interpolatePollAndPaint); } -void StrokeManager::reset() +void StrokeInterpolator::reset() { mStrokeStarted = false; pressureQueue.clear(); @@ -51,39 +45,39 @@ void StrokeManager::reset() mStabilizerLevel = -1; } -void StrokeManager::setPressure(float pressure) +void StrokeInterpolator::setPressure(float pressure) { mTabletPressure = pressure; } -void StrokeManager::pointerPressEvent(PointerEvent* event) +void StrokeInterpolator::pointerPressEvent(PointerEvent* event) { reset(); if (!(event->button() == Qt::NoButton)) // if the user is pressing the left/right button { - //qDebug() << "press"; - mLastPressPixel = mCurrentPressPixel; - mCurrentPressPixel = event->posF(); + mCurrentPressPixel = event->viewportPos(); } - mLastPixel = mCurrentPixel = event->posF(); + mLastPixel = mCurrentPixel = event->viewportPos(); mStrokeStarted = true; setPressure(event->pressure()); + + mTabletInUse = mTabletInUse || event->isTabletEvent(); } -void StrokeManager::pointerMoveEvent(PointerEvent* event) +void StrokeInterpolator::pointerMoveEvent(PointerEvent* event) { // only applied to drawing tools. if (mStabilizerLevel != -1) { - smoothMousePos(event->posF()); + smoothMousePos(event->viewportPos()); } else { // No smoothing mLastPixel = mCurrentPixel; - mCurrentPixel = event->posF(); + mCurrentPixel = event->viewportPos(); mLastInterpolated = mCurrentPixel; } if(event->isTabletEvent()) @@ -92,7 +86,7 @@ void StrokeManager::pointerMoveEvent(PointerEvent* event) } } -void StrokeManager::pointerReleaseEvent(PointerEvent* event) +void StrokeInterpolator::pointerReleaseEvent(PointerEvent* event) { // flush out stroke if (mStrokeStarted) @@ -101,14 +95,15 @@ void StrokeManager::pointerReleaseEvent(PointerEvent* event) } mStrokeStarted = false; + mTabletInUse = mTabletInUse && !event->isTabletEvent(); } -void StrokeManager::setStabilizerLevel(int level) +void StrokeInterpolator::setStabilizerLevel(int level) { mStabilizerLevel = level; } -void StrokeManager::smoothMousePos(QPointF pos) +void StrokeInterpolator::smoothMousePos(QPointF pos) { // Smooth mouse position before drawing QPointF smoothPos; @@ -144,8 +139,6 @@ void StrokeManager::smoothMousePos(QPointF pos) mLastPixel = mLastInterpolated; } - mousePos = pos; - if (!mStrokeStarted) { return; @@ -158,7 +151,7 @@ void StrokeManager::smoothMousePos(QPointF pos) } -QPointF StrokeManager::interpolateStart(QPointF firstPoint) +QPointF StrokeInterpolator::interpolateStart(QPointF firstPoint) { if (mStabilizerLevel == StabilizationLevel::SIMPLE) { @@ -166,16 +159,10 @@ QPointF StrokeManager::interpolateStart(QPointF firstPoint) strokeQueue.clear(); pressureQueue.clear(); - mSingleshotTime.start(); - previousTime = mSingleshotTime.elapsed(); - mLastPixel = firstPoint; } else if (mStabilizerLevel == StabilizationLevel::STRONG) { - mSingleshotTime.start(); - previousTime = mSingleshotTime.elapsed(); - // Clear queue strokeQueue.clear(); pressureQueue.clear(); @@ -207,7 +194,7 @@ QPointF StrokeManager::interpolateStart(QPointF firstPoint) return firstPoint; } -void StrokeManager::interpolatePoll() +void StrokeInterpolator::interpolatePoll() { // remove oldest stroke strokeQueue.dequeue(); @@ -216,7 +203,7 @@ void StrokeManager::interpolatePoll() strokeQueue.enqueue(mLastInterpolated); } -void StrokeManager::interpolatePollAndPaint() +void StrokeInterpolator::interpolatePollAndPaint() { //qDebug() <<"inpol:" << mStabilizerLevel << "strokes"<< strokeQueue; if (!strokeQueue.isEmpty()) @@ -226,7 +213,7 @@ void StrokeManager::interpolatePollAndPaint() } } -QList StrokeManager::interpolateStroke() +QList StrokeInterpolator::interpolateStroke() { // is nan initially QList result; @@ -251,7 +238,7 @@ QList StrokeManager::interpolateStroke() return result; } -QList StrokeManager::noInpolOp(QList points) +QList StrokeInterpolator::noInpolOp(QList points) { setPressure(getPressure()); @@ -264,9 +251,8 @@ QList StrokeManager::noInpolOp(QList points) return points; } -QList StrokeManager::tangentInpolOp(QList points) +QList StrokeInterpolator::tangentInpolOp(QList points) { - int time = mSingleshotTime.elapsed(); static const qreal smoothness = 1.f; QLineF line(mLastPixel, mCurrentPixel); @@ -314,12 +300,11 @@ QList StrokeManager::tangentInpolOp(QList points) m_previousTangent = newTangent; } - previousTime = time; return points; } // Mean sampling interpolation operation -QList StrokeManager::meanInpolOp(QList points, qreal x, qreal y, qreal pressure) +QList StrokeInterpolator::meanInpolOp(QList points, qreal x, qreal y, qreal pressure) { for (int i = 0; i < strokeQueue.size(); i++) { @@ -345,7 +330,7 @@ QList StrokeManager::meanInpolOp(QList points, qreal x, qreal return points; } -void StrokeManager::interpolateEnd() +void StrokeInterpolator::interpolateEnd() { // Stop timer timer.stop(); diff --git a/core_lib/src/tool/strokemanager.h b/core_lib/src/tool/strokeinterpolator.h similarity index 77% rename from core_lib/src/tool/strokemanager.h rename to core_lib/src/tool/strokeinterpolator.h index 01c91c8cc9..eb8c867528 100644 --- a/core_lib/src/tool/strokemanager.h +++ b/core_lib/src/tool/strokeinterpolator.h @@ -15,24 +15,21 @@ GNU General Public License for more details. */ -#ifndef STROKEMANAGER_H -#define STROKEMANAGER_H +#ifndef STROKEINTERPOLATOR_H +#define STROKEINTERPOLATOR_H -#include #include #include #include #include -#include -#include "object.h" class PointerEvent; -class StrokeManager : public QObject +class StrokeInterpolator : public QObject { public: - StrokeManager(); + StrokeInterpolator(); void pointerPressEvent(PointerEvent* event); void pointerMoveEvent(PointerEvent* event); @@ -42,9 +39,7 @@ class StrokeManager : public QObject float getPressure() { return mTabletPressure; } int getStabilizerLevel() { return mStabilizerLevel; } - bool isTabletInUse() { return mTabletInUse; } - void setTabletInUse(bool inUse) { mTabletInUse = inUse; } - bool isActive() { return mStrokeStarted; } + bool isActive() const { return mStrokeStarted; } QList interpolateStroke(); void interpolatePoll(); @@ -56,11 +51,9 @@ class StrokeManager : public QObject QList noInpolOp(QList points); QList tangentInpolOp(QList points); - QPointF getLastPressPixel() const { return mLastPressPixel; } QPointF getCurrentPixel() const { return mCurrentPixel; } QPointF getLastPixel() const { return mLastPixel; } QPointF getLastMeanPixel() const { return mLastInterpolated; } - QPointF getMousePos() const { return mousePos; } QPointF getCurrentPressPixel() const { return mCurrentPressPixel; } private: @@ -74,24 +67,17 @@ class StrokeManager : public QObject QTimer timer; - QElapsedTimer mSingleshotTime; QPointF mCurrentPressPixel = { 0, 0 }; - QPointF mLastPressPixel2 = { 0, 0 }; - QPointF mLastPressPixel = { 0, 0 }; QPointF mCurrentPixel = { 0, 0 }; QPointF mLastPixel = { 0, 0 }; QPointF mLastInterpolated = { 0, 0 }; - QPointF mousePos = { 0, 0 }; QPointF m_previousTangent; bool mHasTangent = false; - int previousTime = 0; bool mStrokeStarted = false; bool mTabletInUse = false; float mTabletPressure = 1.f; int mStabilizerLevel = 0; - - clock_t m_timeshot; }; -#endif // STROKEMANAGER_H +#endif // STROKEINTERPOLATOR_H diff --git a/core_lib/src/tool/stroketool.cpp b/core_lib/src/tool/stroketool.cpp index 5da6ad0035..e301275aba 100644 --- a/core_lib/src/tool/stroketool.cpp +++ b/core_lib/src/tool/stroketool.cpp @@ -19,7 +19,6 @@ GNU General Public License for more details. #include #include "scribblearea.h" -#include "strokemanager.h" #include "viewmanager.h" #include "preferencemanager.h" #include "editor.h" @@ -91,6 +90,36 @@ void StrokeTool::onViewUpdated() updateCanvasCursor(); } +QPointF StrokeTool::getCurrentPressPixel() const +{ + return mInterpolator.getCurrentPressPixel(); +} + +QPointF StrokeTool::getCurrentPressPoint() const +{ + return mEditor->view()->mapScreenToCanvas(mInterpolator.getCurrentPressPixel()); +} + +QPointF StrokeTool::getCurrentPixel() const +{ + return mInterpolator.getCurrentPixel(); +} + +QPointF StrokeTool::getCurrentPoint() const +{ + return mEditor->view()->mapScreenToCanvas(getCurrentPixel()); +} + +QPointF StrokeTool::getLastPixel() const +{ + return mInterpolator.getLastPixel(); +} + +QPointF StrokeTool::getLastPoint() const +{ + return mEditor->view()->mapScreenToCanvas(getLastPixel()); +} + void StrokeTool::startStroke(PointerEvent::InputType inputType) { if (emptyFrameActionEnabled()) @@ -104,11 +133,11 @@ void StrokeTool::startStroke(PointerEvent::InputType inputType) mStrokePoints.clear(); //Experimental - QPointF startStrokes = strokeManager()->interpolateStart(mLastPixel); + QPointF startStrokes = mInterpolator.interpolateStart(mLastPixel); mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes); mStrokePressures.clear(); - mStrokePressures << strokeManager()->getPressure(); + mStrokePressures << mInterpolator.getPressure(); mCurrentInputType = inputType; @@ -141,8 +170,8 @@ bool StrokeTool::emptyFrameActionEnabled() void StrokeTool::endStroke() { - strokeManager()->interpolateEnd(); - mStrokePressures << strokeManager()->getPressure(); + mInterpolator.interpolateEnd(); + mStrokePressures << mInterpolator.getPressure(); mStrokePoints.clear(); mStrokePressures.clear(); @@ -158,9 +187,9 @@ void StrokeTool::drawStroke() if (pixel != mLastPixel || !mFirstDraw) { // get last pixel before interpolation initializes - QPointF startStrokes = strokeManager()->interpolateStart(getLastPixel()); + QPointF startStrokes = mInterpolator.interpolateStart(getLastPixel()); mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes); - mStrokePressures << strokeManager()->getPressure(); + mStrokePressures << mInterpolator.getPressure(); } else { diff --git a/core_lib/src/tool/stroketool.h b/core_lib/src/tool/stroketool.h index 28bc766c84..0fd441c3ac 100644 --- a/core_lib/src/tool/stroketool.h +++ b/core_lib/src/tool/stroketool.h @@ -21,6 +21,7 @@ GNU General Public License for more details. #include "basetool.h" #include "pointerevent.h" #include "preferencesdef.h" +#include "strokeinterpolator.h" #include "canvascursorpainter.h" @@ -50,6 +51,7 @@ class StrokeTool : public BaseTool static const qreal WIDTH_MAX; void loadSettings() override; + bool isActive() const override { return mInterpolator.isActive(); }; bool keyPressEvent(QKeyEvent* event) override; void pointerPressEvent(PointerEvent* event) override; @@ -66,6 +68,13 @@ public slots: void onViewUpdated(); protected: + QPointF getCurrentPressPixel() const; + QPointF getCurrentPressPoint() const; + QPointF getCurrentPixel() const; + QPointF getCurrentPoint() const; + QPointF getLastPixel() const; + QPointF getLastPoint() const; + // dynamic cursor adjustment virtual bool startAdjusting(Qt::KeyboardModifiers modifiers); virtual void stopAdjusting(); @@ -98,6 +107,8 @@ public slots: QPointF mAdjustPosition; CanvasCursorPainter mCanvasCursorPainter; + + StrokeInterpolator mInterpolator; }; #endif // STROKETOOL_H diff --git a/core_lib/src/util/pointerevent.cpp b/core_lib/src/util/pointerevent.cpp index dc7c0f2029..1baacfbb0c 100644 --- a/core_lib/src/util/pointerevent.cpp +++ b/core_lib/src/util/pointerevent.cpp @@ -1,34 +1,27 @@ #include "pointerevent.h" -PointerEvent::PointerEvent(QMouseEvent* event) +PointerEvent::PointerEvent(QMouseEvent* event, const QPointF& canvasPos) { mMouseEvent = event; + mCanvasPos = canvasPos; } -PointerEvent::PointerEvent(QTabletEvent* event) +PointerEvent::PointerEvent(QTabletEvent* event, const QPointF& canvasPos) { mTabletEvent = event; + mCanvasPos = canvasPos; } PointerEvent::~PointerEvent() { } -QPoint PointerEvent::pos() const +QPointF PointerEvent::canvasPos() const { - if (mMouseEvent) - { - return mMouseEvent->pos(); - } - else if (mTabletEvent) - { - return mTabletEvent->pos(); - } - Q_ASSERT(false); - return QPoint(); + return mCanvasPos; } -QPointF PointerEvent::posF() const +QPointF PointerEvent::viewportPos() const { if (mMouseEvent) { diff --git a/core_lib/src/util/pointerevent.h b/core_lib/src/util/pointerevent.h index aad7ed692b..22a3a5e393 100644 --- a/core_lib/src/util/pointerevent.h +++ b/core_lib/src/util/pointerevent.h @@ -21,19 +21,20 @@ class PointerEvent Unmapped }; - PointerEvent(QMouseEvent* event); - PointerEvent(QTabletEvent* event); + PointerEvent(QMouseEvent* event, const QPointF& canvasPos); + PointerEvent(QTabletEvent* event, const QPointF& canvasPos); ~PointerEvent(); /** - * Returns QPoint of the device */ - QPoint pos() const; + * Returns the QPointF of the device, in canvas coordinates + */ + QPointF canvasPos() const; /** - * Returns the QPointF of the device + * Returns the QPointF of the device, in viewport coordinates * Returns pos() if used on mouse event */ - QPointF posF() const; + QPointF viewportPos() const; /** * Returns a value between 0 and 1 for tablet events, @@ -91,6 +92,7 @@ class PointerEvent private: QTabletEvent* mTabletEvent = nullptr; QMouseEvent* mMouseEvent = nullptr; + QPointF mCanvasPos; }; #endif // POINTEREVENT_H