diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 9b6a1958..4327a495 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -561,9 +561,22 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres interpolator = UBInterpolator::Bezier; } - QList > newPoints = mCurrentStroke->addPoint(scenePos, width, interpolator); - if (newPoints.length() > 1) { - drawCurve(newPoints); + + // Don't draw segments smaller than a certain length. This can help with performance + // (less polygons to draw) but mostly with making the curve look smooth. + + qreal antiScaleRatio = 1./(UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); + qreal MIN_DISTANCE = 10*antiScaleRatio; // arbitrary. Move to settings if relevant. + qreal distance = QLineF(mPreviousPoint, scenePos).length(); + + mDistanceFromLastStrokePoint += distance; + + if (mDistanceFromLastStrokePoint > MIN_DISTANCE) { + QList > newPoints = mCurrentStroke->addPoint(scenePos, width, interpolator); + if (newPoints.length() > 1) + drawCurve(newPoints); + + mDistanceFromLastStrokePoint = 0; } if (interpolator == UBInterpolator::Bezier) { @@ -577,7 +590,7 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres mTempPolygon = NULL; } - QPointF lastDrawnPoint = newPoints.last().first; + QPointF lastDrawnPoint = mCurrentStroke->points().last().first; mTempPolygon = lineToPolygonItem(QLineF(lastDrawnPoint, scenePos), mPreviousWidth, width); addItem(mTempPolygon); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 18a8c05a..84d01514 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -429,6 +429,7 @@ public slots: QPointF mPreviousPoint; qreal mPreviousWidth; + qreal mDistanceFromLastStrokePoint; QList mPreviousPolygonItems; diff --git a/src/domain/UBGraphicsStroke.cpp b/src/domain/UBGraphicsStroke.cpp index 8218624d..4456b26d 100644 --- a/src/domain/UBGraphicsStroke.cpp +++ b/src/domain/UBGraphicsStroke.cpp @@ -102,14 +102,6 @@ QList > UBGraphicsStroke::addPoint(const QPointF& point, q // The curve we are interpolating is not between two drawn points; // it is between the midway points of the second-to-last and last point, and last and current point. - // Don't draw segments smaller than a certain length. This can help with performance - // (less polygons to draw) but mostly with keeping the curve smooth. - qreal MIN_DISTANCE = 3*mAntiScaleRatio; - qreal distance = QLineF(mReceivedPoints.last().first, newPoint.first).length(); - - if (distance < MIN_DISTANCE) { - return QList() << mDrawnPoints.last(); - } // The first segment is just a straight line to the first midway point if (n == 1) {