Commit 28799f72 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Fixed the irritating outline blinking in hovering mode

Now KisPaintInformation can tell the sensors whether it was created
for hovering mode or for a usual painting mode. The sersors can decide
how to behave basing on this info. For example, Fuzzy sensor will return
unit value in non-painting mode.

BUG:329213
parent 575461dc
......@@ -30,7 +30,7 @@ struct KisPaintInformation::Private {
Private() : currentDistanceInfo(0) {}
~Private() {
Q_ASSERT(!currentDistanceInfo);
KIS_ASSERT_RECOVER_NOOP(!currentDistanceInfo);
}
Private(const Private &rhs) {
copy(rhs);
......@@ -49,6 +49,7 @@ struct KisPaintInformation::Private {
tangentialPressure = rhs.tangentialPressure;
perspective = rhs.perspective;
time = rhs.time;
isHoveringMode = rhs.isHoveringMode;
currentDistanceInfo = rhs.currentDistanceInfo;
if (rhs.drawingAngleOverride) {
......@@ -65,6 +66,7 @@ struct KisPaintInformation::Private {
qreal tangentialPressure;
qreal perspective;
int time;
bool isHoveringMode;
QScopedPointer<qreal> drawingAngleOverride;
KisDistanceInformation *currentDistanceInfo;
......@@ -108,6 +110,7 @@ KisPaintInformation::KisPaintInformation(const QPointF & pos_,
d->tangentialPressure = tangentialPressure_;
d->perspective = perspective_;
d->time = time;
d->isHoveringMode = false;
}
KisPaintInformation::KisPaintInformation(const KisPaintInformation& rhs) : d(new Private(*rhs.d))
......@@ -124,9 +127,23 @@ KisPaintInformation::~KisPaintInformation()
delete d;
}
bool KisPaintInformation::isHoveringMode() const
{
return d->isHoveringMode;
}
KisPaintInformation KisPaintInformation::createHoveringModeInfo(const QPointF &pos)
{
KisPaintInformation info(pos);
info.d->isHoveringMode = true;
return info;
}
void KisPaintInformation::toXML(QDomDocument&, QDomElement& e) const
{
// hovering mode infos are not supposed to be saved
KIS_ASSERT_RECOVER_NOOP(!d->isHoveringMode);
e.setAttribute("pointX", QString::number(pos().x(), 'g', 15));
e.setAttribute("pointY", QString::number(pos().y(), 'g', 15));
e.setAttribute("pressure", QString::number(pressure(), 'g', 15));
......@@ -302,7 +319,12 @@ KisPaintInformation KisPaintInformation::mix(const QPointF& p, qreal t, const Ki
qreal tangentialPressure = (1 - t) * pi1.tangentialPressure() + t * pi2.tangentialPressure();
qreal perspective = (1 - t) * pi1.perspective() + t * pi2.perspective();
int time = (1 - t) * pi1.currentTime() + t * pi2.currentTime();
return KisPaintInformation(p, pressure, xTilt, yTilt, rotation, tangentialPressure, perspective, time);
KisPaintInformation result(p, pressure, xTilt, yTilt, rotation, tangentialPressure, perspective, time);
KIS_ASSERT_RECOVER_NOOP(pi1.isHoveringMode() == pi2.isHoveringMode());
result.d->isHoveringMode = pi1.isHoveringMode();
return result;
}
qreal KisPaintInformation::ascension(const KisPaintInformation& info, bool normalize)
......
......@@ -150,6 +150,29 @@ public:
/// Number of ms since the beginning of the stroke
int currentTime() const;
/**
* The paint information may be generated not only during real
* stroke when the actual painting is happening, but also when the
* cursor is hovering the canvas. In this mode some of the sensors
* work a bit differently. The most outstanding example is Fuzzy
* sensor, which returns unit value in this mode, otherwise it is
* too irritating for a user.
*
* This value is true only for paint information objects created with
* createHoveringModeInfo() constructor.
*
* \see createHoveringModeInfo()
*/
bool isHoveringMode() const;
/**
* Create a fake info object with isHoveringMode() property set to
* true.
*
* \see isHoveringMode()
*/
static KisPaintInformation createHoveringModeInfo(const QPointF &pos);
void toXML(QDomDocument&, QDomElement&) const;
static KisPaintInformation fromXML(const QDomElement&);
......
......@@ -31,8 +31,8 @@ class KisDynamicSensorFuzzy : public KisDynamicSensor
public:
KisDynamicSensorFuzzy();
virtual ~KisDynamicSensorFuzzy() { }
virtual qreal value(const KisPaintInformation&) {
return rand() / (qreal)RAND_MAX;
virtual qreal value(const KisPaintInformation &info) {
return !info.isHoveringMode() ? rand() / (qreal)RAND_MAX : 1.0;
}
};
......
......@@ -140,7 +140,7 @@ QPainterPath KisToolFreehandHelper::paintOpOutline(const QPointF &savedCursorPos
KisPaintOpSettings::OutlineMode mode) const
{
const KisPaintOpSettings *settings = globalSettings;
KisPaintInformation info(savedCursorPos);
KisPaintInformation info = KisPaintInformation::createHoveringModeInfo(savedCursorPos);
KisDistanceInformation distanceInfo(m_d->lastOutlinePos.pushThroughHistory(savedCursorPos), 0);
if (!m_d->painterInfos.isEmpty()) {
......
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