Commit 4b1718db authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

[FEATURE] Add an option to smooth the pressure in Weighted Smoothing mode

This feature makes the shape of the line be more stable, but still there
is one drawback:

When the option is active you almost cannot control the shape of the
beginning of the line, it is always very thin.

CCMAIL:kimageshop@kde.org
parent 71e90ca4
......@@ -51,17 +51,20 @@ void KisToolBrush::slotSetSmoothingType(int index)
m_smoothingOptions.smoothingType = KisSmoothingOptions::NO_SMOOTHING;
m_sliderSmoothnessDistance->setEnabled(false);
m_sliderTailAggressiveness->setEnabled(false);
m_chkSmoothPressure->setEnabled(false);
break;
case 1:
m_smoothingOptions.smoothingType = KisSmoothingOptions::SIMPLE_SMOOTHING;
m_sliderSmoothnessDistance->setEnabled(false);
m_sliderTailAggressiveness->setEnabled(false);
m_chkSmoothPressure->setEnabled(false);
break;
case 2:
default:
m_smoothingOptions.smoothingType = KisSmoothingOptions::WEIGHTED_SMOOTHING;
m_sliderSmoothnessDistance->setEnabled(true);
m_sliderTailAggressiveness->setEnabled(true);
m_chkSmoothPressure->setEnabled(true);
}
}
......@@ -74,6 +77,12 @@ void KisToolBrush::slotSetTailAgressiveness(qreal argh_rhhrr)
{
m_smoothingOptions.tailAggressiveness = argh_rhhrr;
}
void KisToolBrush::setSmoothPressure(bool value)
{
m_smoothingOptions.smoothPressure = value;
}
void KisToolBrush::slotSetMagnetism(int magnetism)
{
m_magnetism = expf(magnetism / (double)MAXIMUM_MAGNETISM) / expf(1.0);
......@@ -105,6 +114,11 @@ QWidget * KisToolBrush::createOptionWidget()
m_sliderTailAggressiveness->setValue(m_smoothingOptions.tailAggressiveness);
addOptionWidgetOption(m_sliderTailAggressiveness, new QLabel(i18n("Tail Aggressiveness:")));
m_chkSmoothPressure = new QCheckBox("", optionWidget);
m_chkSmoothPressure->setChecked(m_smoothingOptions.smoothPressure);
connect(m_chkSmoothPressure, SIGNAL(toggled(bool)), this, SLOT(setSmoothPressure(bool)));
addOptionWidgetOption(m_chkSmoothPressure, new QLabel(i18n("Smooth Pressure")));
slotSetSmoothingType(1);
// Drawing assistant configuration
......
......@@ -49,6 +49,7 @@ private slots:
void slotSetMagnetism(int magnetism);
void slotSetSmoothingType(int index);
void slotSetTailAgressiveness(qreal argh_rhhrr);
void setSmoothPressure(bool value);
private:
QGridLayout *m_optionLayout;
......@@ -58,6 +59,7 @@ private:
KisSliderSpinBox *m_sliderMagnetism;
KisDoubleSliderSpinBox *m_sliderSmoothnessDistance;
KisDoubleSliderSpinBox *m_sliderTailAggressiveness;
QCheckBox *m_chkSmoothPressure;
};
......
......@@ -21,5 +21,6 @@ KisSmoothingOptions::KisSmoothingOptions()
: smoothingType(WEIGHTED_SMOOTHING)
, smoothnessDistance(50.0)
, tailAggressiveness(0.15)
, smoothPressure(false)
{
}
......@@ -34,6 +34,7 @@ struct KisSmoothingOptions
SmoothingType smoothingType;
qreal smoothnessDistance;
qreal tailAggressiveness;
bool smoothPressure;
};
#endif // KIS_SMOOTHING_OPTIONS_H
......@@ -261,6 +261,7 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event)
qreal gaussianWeight2 = sigma * sigma;
qreal velocitySum = 0.0;
qreal scaleSum = 0.0;
qreal pressure = 0.0;
qreal baseRate = 0.0;
Q_ASSERT(m_d->history.size() == m_d->velocityHistory.size());
......@@ -309,16 +310,27 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event)
scaleSum += rate;
x += rate * nextInfo.pos().x();
y += rate * nextInfo.pos().y();
if (m_d->smoothingOptions.smoothPressure) {
pressure += rate * nextInfo.pressure();
}
}
if (scaleSum != 0.0) {
x /= scaleSum;
y /= scaleSum;
if (m_d->smoothingOptions.smoothPressure) {
pressure /= scaleSum;
}
}
if ((x != 0.0 && y != 0.0) || (x == info.pos().x() && y == info.pos().y())) {
info.setMovement(toKisVector2D(info.pos() - QPointF(x, y)));
info.setPos(QPointF(x, y));
if (m_d->smoothingOptions.smoothPressure) {
info.setPressure(pressure);
}
m_d->history.last() = info;
}
}
......
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