Commit b63f5280 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Fix PressureIn sensor

PixelBrush is multithreaded, therefore sensors should not store
any internal state. We have KisDistanceInformation exactly for
this purpose.

BUG:426234
parent 32d13608
......@@ -120,11 +120,13 @@ struct KisPaintInformation::Private {
int _currentDabSeqNo,
qreal _lastAngle,
QPointF _lastPosition,
qreal _lastMaxPressure,
boost::optional<qreal> _lockedDrawingAngle)
: totalStrokeLength(_totalDistance),
currentDabSeqNo(_currentDabSeqNo),
lastAngle(_lastAngle),
lastPosition(_lastPosition),
lastMaxPressure(_lastMaxPressure),
lockedDrawingAngle(_lockedDrawingAngle)
{
}
......@@ -133,6 +135,7 @@ struct KisPaintInformation::Private {
int currentDabSeqNo = 0;
qreal lastAngle = 0.0;
QPointF lastPosition;
qreal lastMaxPressure = 0.0;
boost::optional<qreal> lockedDrawingAngle;
};
boost::optional<DirectionHistoryInfo> directionHistoryInfo;
......@@ -144,6 +147,7 @@ struct KisPaintInformation::Private {
di->currentDabSeqNo(),
di->lastDrawingAngle(),
di->lastPosition(),
di->maxPressure(),
di->lockedDrawingAngleOptional());
......@@ -438,6 +442,16 @@ qreal KisPaintInformation::drawingDistance() const
return length;
}
qreal KisPaintInformation::maxPressure() const
{
if (!d->directionHistoryInfo) {
warnKrita << "KisPaintInformation::maxPressure()" << "DirectionHistoryInfo object is not available";
return d->pressure;
}
return qMax(d->directionHistoryInfo->lastMaxPressure, d->pressure);
}
qreal KisPaintInformation::drawingSpeed() const
{
return d->speed;
......
......@@ -190,6 +190,14 @@ public:
*/
qreal drawingDistance() const;
/**
* Maximum pressure that has been known during the stroke
*
* WARNING: this method is available *only* inside paintAt() call,
* that is when the distance information is registered.
*/
qreal maxPressure() const;
/// rotation as given by the tablet event
qreal rotation() const;
......
......@@ -82,6 +82,8 @@ struct Q_DECL_HIDDEN KisDistanceInformation::Private {
int currentDabSeqNo;
int levelOfDetail;
qreal lastMaxPressure = 0.0;
};
struct Q_DECL_HIDDEN KisDistanceInitInfo::Private {
......@@ -383,6 +385,11 @@ int KisDistanceInformation::currentDabSeqNo() const
return m_d->currentDabSeqNo;
}
qreal KisDistanceInformation::maxPressure() const
{
return m_d->lastMaxPressure;
}
bool KisDistanceInformation::isStarted() const
{
return m_d->lastPaintInfoValid;
......@@ -407,6 +414,8 @@ void KisDistanceInformation::registerPaintedDab(const KisPaintInformation &info,
m_d->timing = timing;
m_d->currentDabSeqNo++;
m_d->lastMaxPressure = qMax(info.pressure(), m_d->lastMaxPressure);
}
qreal KisDistanceInformation::getNextPointPosition(const QPointF &start,
......
......@@ -140,6 +140,8 @@ public:
int currentDabSeqNo() const;
qreal maxPressure() const;
/**
* @param spacing The new effective spacing after the dab. (Painting a dab is always supposed to
* cause a spacing update.)
......
......@@ -33,19 +33,9 @@ qreal KisDynamicSensorSpeed::value(const KisPaintInformation& info)
* a big image. If you need smaller speeds, just change the curve.
*/
const qreal maxSpeed = 30.0; // px / ms
const qreal blendExponent = 0.05;
const qreal currentSpeed = qMin(1.0, info.drawingSpeed() / maxSpeed);
qreal currentSpeed = info.drawingSpeed() / maxSpeed;
if (m_speed >= 0.0) {
m_speed = qMin(1.0, (m_speed * (1 - blendExponent) +
currentSpeed * blendExponent));
}
else {
m_speed = currentSpeed;
}
return m_speed;
return currentSpeed;
}
KisDynamicSensorRotation::KisDynamicSensorRotation()
......@@ -60,7 +50,6 @@ KisDynamicSensorPressure::KisDynamicSensorPressure()
KisDynamicSensorPressureIn::KisDynamicSensorPressureIn()
: KisDynamicSensor(PRESSURE_IN)
, lastPressure(0.0)
{
}
......
......@@ -31,11 +31,6 @@ public:
KisDynamicSensorSpeed();
~KisDynamicSensorSpeed() override { }
qreal value(const KisPaintInformation& info) override;
void reset() override {
m_speed = -1.0;
}
private:
double m_speed;
};
class KisDynamicSensorRotation : public KisDynamicSensor
......@@ -64,18 +59,8 @@ public:
KisDynamicSensorPressureIn();
~KisDynamicSensorPressureIn() override { }
qreal value(const KisPaintInformation& info) override {
if(!info.isHoveringMode()) {
if(info.pressure() > lastPressure) {
lastPressure = info.pressure();
}
return lastPressure;
}
lastPressure = 0.0;
return 0.0;
return !info.isHoveringMode() ? info.maxPressure() : 0.0;
}
private:
qreal lastPressure;
};
class KisDynamicSensorXTilt : public KisDynamicSensor
......
Supports Markdown
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