diff --git a/libs/image/kis_warptransform_worker.h b/libs/image/kis_warptransform_worker.h --- a/libs/image/kis_warptransform_worker.h +++ b/libs/image/kis_warptransform_worker.h @@ -47,6 +47,7 @@ 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 p, QVector q, qreal alpha); static QPointF similitudeTransformMath(QPointF v, QVector p, QVector q, qreal alpha); @@ -75,6 +76,7 @@ private: WarpMathFunction m_warpMathFunction; + WarpCalculation m_warpCalc; QVector m_origPoint; QVector m_transfPoint; qreal m_alpha; diff --git a/plugins/tools/tool_transform2/kis_tool_transform_config_widget.cpp b/plugins/tools/tool_transform2/kis_tool_transform_config_widget.cpp --- a/plugins/tools/tool_transform2/kis_tool_transform_config_widget.cpp +++ b/plugins/tools/tool_transform2/kis_tool_transform_config_widget.cpp @@ -268,11 +268,13 @@ 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 @@ ToolTransformArgs *config = m_transaction->currentConfig(); config->setMode(ToolTransformArgs::WARP); + config->setWarpCalculation(KisWarpTransformWorker::WarpCalculation::GRID); emit sigResetTransform(); } @@ -1194,11 +1197,16 @@ 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(); } diff --git a/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp b/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp --- a/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp +++ b/plugins/tools/tool_transform2/kis_warp_transform_strategy.cpp @@ -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 @@ 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 @@ gc.save(); gc.setTransform(m_d->handlesTransform, true); - // draw connecting lines if (m_d->drawConnectionLines) { gc.setOpacity(0.5); @@ -247,12 +246,15 @@ 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 @@ } } + + // 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(); } diff --git a/plugins/tools/tool_transform2/tool_transform_args.h b/plugins/tools/tool_transform2/tool_transform_args.h --- a/plugins/tools/tool_transform2/tool_transform_args.h +++ b/plugins/tools/tool_transform2/tool_transform_args.h @@ -131,6 +131,13 @@ 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 @@ QVector m_origPoints; QVector m_transfPoints; KisWarpTransformWorker::WarpType m_warpType; + KisWarpTransformWorker::WarpCalculation m_warpCalculation; // DRAW or GRID double m_alpha; //'free transform'-related diff --git a/plugins/tools/tool_transform2/wdg_tool_transform.ui b/plugins/tools/tool_transform2/wdg_tool_transform.ui --- a/plugins/tools/tool_transform2/wdg_tool_transform.ui +++ b/plugins/tools/tool_transform2/wdg_tool_transform.ui @@ -6,7 +6,7 @@ 0 0 - 479 + 489 674 @@ -250,7 +250,7 @@ QFrame::Raised - 3 + 0 @@ -1535,7 +1535,10 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - 0 + 2 + + + 30 3 @@ -2198,7 +2201,7 @@ - +