Commit 123ebf1d authored by Craig Watson's avatar Craig Watson

Improved drawing of end of current stroke

Distance between the last drawn point and the current point is
calculated to be able to discard very short stroke segments (i.e we only
add to the current stroke if the input device has moved more than a
certain distance since the last drawn point).

This commit moves this code from the stroke to the scene, which allows
to calculate distance more accurately: it is now calculated as the
total, absolute distance traveled since the last point, rather than simply the
length of a line between the last point and current one.
parent 5fd617c5
......@@ -561,9 +561,22 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
interpolator = UBInterpolator::Bezier;
}
QList<QPair<QPointF, qreal> > 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<QPair<QPointF, qreal> > 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);
......
......@@ -429,6 +429,7 @@ public slots:
QPointF mPreviousPoint;
qreal mPreviousWidth;
qreal mDistanceFromLastStrokePoint;
QList<UBGraphicsPolygonItem*> mPreviousPolygonItems;
......
......@@ -102,14 +102,6 @@ QList<QPair<QPointF, qreal> > 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<strokePoint>() << mDrawnPoints.last();
}
// The first segment is just a straight line to the first midway point
if (n == 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment