Commit a8ca9897 authored by Scott Petrovic's avatar Scott Petrovic

Simplify display of Warp transformation grid

parent ae246349
......@@ -47,6 +47,7 @@ class KRITAIMAGE_EXPORT KisWarpTransformWorker : public QObject
public:
typedef enum WarpType_ {AFFINE_TRANSFORM = 0, SIMILITUDE_TRANSFORM, RIGID_TRANSFORM, N_MODES} WarpType;
typedef enum WarpCalculation_ {GRID = 0, DRAW} WarpCalculation;
static QPointF affineTransformMath(QPointF v, QVector<QPointF> p, QVector<QPointF> q, qreal alpha);
static QPointF similitudeTransformMath(QPointF v, QVector<QPointF> p, QVector<QPointF> q, qreal alpha);
......@@ -75,6 +76,7 @@ private:
private:
WarpMathFunction m_warpMathFunction;
WarpCalculation m_warpCalc;
QVector<QPointF> m_origPoint;
QVector<QPointF> m_transfPoint;
qreal m_alpha;
......
......@@ -268,11 +268,13 @@ KisToolTransformConfigWidget::KisToolTransformConfigWidget(TransformTransactionP
connect(cmbWarpType, SIGNAL(currentIndexChanged(int)), this, SLOT(notifyEditingFinished()));
connect(m_rotationCenterButtons, SIGNAL(buttonPressed(int)), this, SLOT(notifyEditingFinished()));
connect(aspectButton, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(notifyEditingFinished()));
connect(defaultRadioButton, SIGNAL(clicked(bool)), this, SLOT(notifyEditingFinished()));
connect(customRadioButton, SIGNAL(clicked(bool)), this, SLOT(notifyEditingFinished()));
connect(lockUnlockPointsButton, SIGNAL(clicked()), this, SLOT(notifyEditingFinished()));
connect(resetPointsButton, SIGNAL(clicked()), this, SLOT(notifyEditingFinished()));
connect(defaultRadioButton, SIGNAL(clicked(bool)), this, SLOT(notifyEditingFinished()));
connect(customRadioButton, SIGNAL(clicked(bool)), this, SLOT(notifyEditingFinished()));
// Liquify
//
// liquify brush options do not affect the image directly and are not
......@@ -786,6 +788,7 @@ void KisToolTransformConfigWidget::slotSetWarpModeButtonClicked(bool value)
ToolTransformArgs *config = m_transaction->currentConfig();
config->setMode(ToolTransformArgs::WARP);
config->setWarpCalculation(KisWarpTransformWorker::WarpCalculation::GRID);
emit sigResetTransform();
}
......@@ -1194,11 +1197,16 @@ void KisToolTransformConfigWidget::activateCustomWarpPoints(bool enabled)
if (!enabled) {
config->setEditingTransformPoints(false);
setDefaultWarpPoints(densityBox->value());
config->setWarpCalculation(KisWarpTransformWorker::WarpCalculation::GRID);
} else {
config->setEditingTransformPoints(true);
config->setWarpCalculation(KisWarpTransformWorker::WarpCalculation::DRAW);
setDefaultWarpPoints(0);
}
updateLockPointsButtonCaption();
}
......
......@@ -30,7 +30,7 @@
#include "kis_cursor.h"
#include "kis_transform_utils.h"
#include "kis_algebra_2d.h"
#include "KisHandlePainterHelper.h"
struct KisWarpTransformStrategy::Private
{
......@@ -43,8 +43,8 @@ struct KisWarpTransformStrategy::Private
currentArgs(_currentArgs),
transaction(_transaction),
lastNumPoints(0),
drawConnectionLines(true),
drawOrigPoints(true),
drawConnectionLines(false), // useful while developing
drawOrigPoints(false),
drawTransfPoints(true),
closeOnStartPointClick(false),
clipOriginalPointsPosition(true),
......@@ -237,7 +237,6 @@ void KisWarpTransformStrategy::paint(QPainter &gc)
gc.save();
gc.setTransform(m_d->handlesTransform, true);
// draw connecting lines
if (m_d->drawConnectionLines) {
gc.setOpacity(0.5);
......@@ -247,12 +246,15 @@ void KisWarpTransformStrategy::paint(QPainter &gc)
m_d->currentArgs.isEditingTransformPoints());
}
QPen mainPen(Qt::black);
QPen outlinePen(Qt::white);
// draw handles
{
const int numPoints = m_d->currentArgs.origPoints().size();
QPen mainPen(Qt::black);
QPen outlinePen(Qt::white);
qreal handlesExtraScale = KisTransformUtils::scaleFromAffineMatrix(m_d->handlesTransform);
......@@ -313,6 +315,42 @@ void KisWarpTransformStrategy::paint(QPainter &gc)
}
}
// draw grid lines only if we are using the GRID mode.
if (m_d->currentArgs.warpCalculation() == KisWarpTransformWorker::WarpCalculation::GRID) {
// see how many rows we have. we are only going to do lines up to 6 divisions/
// it is almost impossible to use with 6 even.
const int numPoints = m_d->currentArgs.origPoints().size();
// grid is always square, so get the square root to find # of rows
int rowsInWarp = sqrt(m_d->currentArgs.origPoints().size());
KisHandlePainterHelper handlePainter(&gc);
handlePainter.setHandleStyle(KisHandleStyle::primarySelection());
// draw horizontal lines
for (int i = 0; i < numPoints; i++) {
if (i != 0 && i % rowsInWarp == rowsInWarp -1) {
// skip line if it is the last in the row
} else {
handlePainter.drawConnectionLine(m_d->currentArgs.transfPoints()[i], m_d->currentArgs.transfPoints()[i+1] );
}
}
// draw vertical lines
for (int i = 0; i < numPoints; i++) {
if ( (numPoints - i - 1) < rowsInWarp ) {
// last row doesn't need to draw vertical lines
} else {
handlePainter.drawConnectionLine(m_d->currentArgs.transfPoints()[i], m_d->currentArgs.transfPoints()[i+rowsInWarp] );
}
}
} // end if statement
gc.restore();
}
......
......@@ -131,6 +131,13 @@ public:
inline void setWarpType(KisWarpTransformWorker::WarpType warpType) {
m_warpType = warpType;
}
inline void setWarpCalculation(KisWarpTransformWorker::WarpCalculation warpCalc) {
m_warpCalculation = warpCalc;
}
inline KisWarpTransformWorker::WarpCalculation warpCalculation() {
return m_warpCalculation;
}
inline void setAlpha(double alpha) {
m_alpha = alpha;
}
......@@ -284,6 +291,7 @@ private:
QVector<QPointF> m_origPoints;
QVector<QPointF> m_transfPoints;
KisWarpTransformWorker::WarpType m_warpType;
KisWarpTransformWorker::WarpCalculation m_warpCalculation; // DRAW or GRID
double m_alpha;
//'free transform'-related
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>479</width>
<width>489</width>
<height>674</height>
</rect>
</property>
......@@ -250,7 +250,7 @@
<enum>QFrame::Raised</enum>
</property>
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<widget class="QWidget" name="freeTransformWidget">
<layout class="QVBoxLayout" name="verticalLayout">
......@@ -1535,7 +1535,10 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>0</number>
<number>2</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="value">
<number>3</number>
......@@ -2198,7 +2201,7 @@
<connections/>
<buttongroups>
<buttongroup name="freeTransformRadioGroup"/>
<buttongroup name="buttonGroup"/>
<buttongroup name="cageTransformButtonGroup"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>
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