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.
preferencesAboutTextFull
Craig Watson 7 years ago
parent 5fd617c539
commit 123ebf1d95
  1. 21
      src/domain/UBGraphicsScene.cpp
  2. 1
      src/domain/UBGraphicsScene.h
  3. 8
      src/domain/UBGraphicsStroke.cpp

@ -561,9 +561,22 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
interpolator = UBInterpolator::Bezier; interpolator = UBInterpolator::Bezier;
} }
QList<QPair<QPointF, qreal> > newPoints = mCurrentStroke->addPoint(scenePos, width, interpolator);
if (newPoints.length() > 1) { // Don't draw segments smaller than a certain length. This can help with performance
drawCurve(newPoints); // (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) { if (interpolator == UBInterpolator::Bezier) {
@ -577,7 +590,7 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
mTempPolygon = NULL; mTempPolygon = NULL;
} }
QPointF lastDrawnPoint = newPoints.last().first; QPointF lastDrawnPoint = mCurrentStroke->points().last().first;
mTempPolygon = lineToPolygonItem(QLineF(lastDrawnPoint, scenePos), mPreviousWidth, width); mTempPolygon = lineToPolygonItem(QLineF(lastDrawnPoint, scenePos), mPreviousWidth, width);
addItem(mTempPolygon); addItem(mTempPolygon);

@ -429,6 +429,7 @@ public slots:
QPointF mPreviousPoint; QPointF mPreviousPoint;
qreal mPreviousWidth; qreal mPreviousWidth;
qreal mDistanceFromLastStrokePoint;
QList<UBGraphicsPolygonItem*> mPreviousPolygonItems; 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; // 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. // 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 // The first segment is just a straight line to the first midway point
if (n == 1) { if (n == 1) {

Loading…
Cancel
Save