Commit 5b37a729 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Added KisToolMultihandHelper

parent b8ed4adb
......@@ -126,6 +126,7 @@ set(kritaui_LIB_SRCS
tool/kis_tool_freehand.cc
tool/kis_painting_information_builder.cpp
tool/kis_tool_freehand_helper.cpp
tool/kis_tool_multihand_helper.cpp
tool/kis_recording_adapter.cpp
tool/kis_tool_paint.cc
tool/kis_tool_shape.cc
......
......@@ -47,7 +47,7 @@ struct KisToolFreehandHelper::Private
QTime strokeTime;
QTimer strokeTimeoutTimer;
KisPainter *painter;
QVector<KisPainter*> painters;
KisResourcesSnapshotSP resources;
KisStrokeId strokeId;
......@@ -65,7 +65,6 @@ KisToolFreehandHelper::KisToolFreehandHelper(KisPaintingInformationBuilder *info
KisRecordingAdapter *recordingAdapter)
: m_d(new Private)
{
m_d->painter = 0;
m_d->infoBuilder = infoBuilder;
m_d->recordingAdapter = recordingAdapter;
......@@ -109,7 +108,7 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
m_d->strokeTime.start();
m_d->painter = new KisPainter();
createPainters(m_d->painters);
m_d->resources = new KisResourcesSnapshot(image,
undoAdapter,
resourceManager);
......@@ -126,7 +125,7 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
KisStrokeStrategy *stroke =
new FreehandStrokeStrategy(indirectPainting,
m_d->resources, m_d->painter);
m_d->resources, m_d->painters);
m_d->strokeId = m_d->strokesFacade->startStroke(stroke);
......@@ -158,16 +157,17 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event)
qreal scaleFactor = (m_d->previousPaintInformation.currentTime() - m_d->olderPaintInformation.currentTime());
QPointF control1 = m_d->olderPaintInformation.pos() + m_d->previousTangent * scaleFactor;
QPointF control2 = m_d->previousPaintInformation.pos() - newTangent * scaleFactor;
paintBezierCurve(m_d->olderPaintInformation,
control1,
control2,
m_d->previousPaintInformation);
paintBezierCurve(m_d->painters,
m_d->olderPaintInformation,
control1,
control2,
m_d->previousPaintInformation);
m_d->previousTangent = newTangent;
}
m_d->olderPaintInformation = m_d->previousPaintInformation;
m_d->strokeTimeoutTimer.start(100);
} else {
paintLine(m_d->previousPaintInformation, info);
paintLine(m_d->painters, m_d->previousPaintInformation, info);
}
m_d->previousPaintInformation = info;
......@@ -180,7 +180,7 @@ void KisToolFreehandHelper::paint(KoPointerEvent *event)
void KisToolFreehandHelper::endPaint()
{
if (!m_d->hasPaintAtLeastOnce) {
paintAt(m_d->previousPaintInformation);
paintAt(m_d->painters, m_d->previousPaintInformation);
} else if (m_d->smooth) {
finishStroke();
}
......@@ -196,7 +196,7 @@ void KisToolFreehandHelper::endPaint()
* Please note that we are not in MT here, so no mutex
* is needed
*/
m_d->painter = 0;
m_d->painters.clear();
m_d->strokesFacade->endStroke(m_d->strokeId);
......@@ -207,7 +207,7 @@ void KisToolFreehandHelper::endPaint()
const KisPaintOp* KisToolFreehandHelper::currentPaintOp() const
{
return m_d->painter ? m_d->painter->paintOp() : 0;
return !m_d->painters.isEmpty() ? m_d->painters.first()->paintOp() : 0;
}
......@@ -220,7 +220,8 @@ void KisToolFreehandHelper::finishStroke()
qreal scaleFactor = (m_d->previousPaintInformation.currentTime() - m_d->olderPaintInformation.currentTime());
QPointF control1 = m_d->olderPaintInformation.pos() + m_d->previousTangent * scaleFactor;
QPointF control2 = m_d->previousPaintInformation.pos() - newTangent;
paintBezierCurve(m_d->olderPaintInformation,
paintBezierCurve(m_d->painters,
m_d->olderPaintInformation,
control1,
control2,
m_d->previousPaintInformation);
......@@ -229,17 +230,18 @@ void KisToolFreehandHelper::finishStroke()
void KisToolFreehandHelper::doAirbrushing()
{
if(m_d->painter) {
paintAt(m_d->previousPaintInformation);
if(!m_d->painters.isEmpty()) {
paintAt(m_d->painters, m_d->previousPaintInformation);
}
}
void KisToolFreehandHelper::paintAt(const KisPaintInformation &pi)
void KisToolFreehandHelper::paintAt(KisPainter *painter,
const KisPaintInformation &pi)
{
m_d->hasPaintAtLeastOnce = true;
m_d->strokesFacade->addJob(m_d->strokeId,
new FreehandStrokeStrategy::Data(m_d->resources->currentNode(),
m_d->painter, pi,
painter, pi,
m_d->dragDistance));
if(m_d->recordingAdapter) {
......@@ -247,13 +249,14 @@ void KisToolFreehandHelper::paintAt(const KisPaintInformation &pi)
}
}
void KisToolFreehandHelper::paintLine(const KisPaintInformation &pi1,
void KisToolFreehandHelper::paintLine(KisPainter *painter,
const KisPaintInformation &pi1,
const KisPaintInformation &pi2)
{
m_d->hasPaintAtLeastOnce = true;
m_d->strokesFacade->addJob(m_d->strokeId,
new FreehandStrokeStrategy::Data(m_d->resources->currentNode(),
m_d->painter, pi1, pi2,
painter, pi1, pi2,
m_d->dragDistance));
if(m_d->recordingAdapter) {
......@@ -261,7 +264,8 @@ void KisToolFreehandHelper::paintLine(const KisPaintInformation &pi1,
}
}
void KisToolFreehandHelper::paintBezierCurve(const KisPaintInformation &pi1,
void KisToolFreehandHelper::paintBezierCurve(KisPainter *painter,
const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2)
......@@ -269,7 +273,7 @@ void KisToolFreehandHelper::paintBezierCurve(const KisPaintInformation &pi1,
m_d->hasPaintAtLeastOnce = true;
m_d->strokesFacade->addJob(m_d->strokeId,
new FreehandStrokeStrategy::Data(m_d->resources->currentNode(),
m_d->painter,
painter,
pi1, control1, control2, pi2,
m_d->dragDistance));
......@@ -278,3 +282,30 @@ void KisToolFreehandHelper::paintBezierCurve(const KisPaintInformation &pi1,
}
}
void KisToolFreehandHelper::createPainters(QVector<KisPainter*> &painters)
{
painters << new KisPainter();
}
void KisToolFreehandHelper::paintAt(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi)
{
paintAt(painters.first(), pi);
}
void KisToolFreehandHelper::paintLine(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const KisPaintInformation &pi2)
{
paintLine(painters.first(), pi1, pi2);
}
void KisToolFreehandHelper::paintBezierCurve(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2)
{
paintBezierCurve(painters.first(), pi1, control1, control2, pi2);
}
......@@ -32,6 +32,7 @@ class KisRecordingAdapter;
class KisStrokesFacade;
class KisPostExecutionUndoAdapter;
class KisPaintOp;
class KisPainter;
class KRITAUI_EXPORT KisToolFreehandHelper : public QObject
......@@ -56,13 +57,31 @@ public:
const KisPaintOp* currentPaintOp() const;
private:
void paintAt(const KisPaintInformation &pi);
protected:
virtual void createPainters(QVector<KisPainter*> &painters);
virtual void paintAt(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi);
virtual void paintLine(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const KisPaintInformation &pi2);
virtual void paintBezierCurve(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2);
protected:
void paintAt(KisPainter *painter, const KisPaintInformation &pi);
void paintLine(const KisPaintInformation &pi1,
void paintLine(KisPainter *painter,
const KisPaintInformation &pi1,
const KisPaintInformation &pi2);
void paintBezierCurve(const KisPaintInformation &pi1,
void paintBezierCurve(KisPainter *painter,
const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2);
......
/*
* Copyright (c) 2011 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_tool_multihand_helper.h"
#include <QTransform>
#include "kis_painter.h"
struct KisToolMultihandHelper::Private
{
QVector<QTransform> transformations;
};
KisToolMultihandHelper::KisToolMultihandHelper(KisPaintingInformationBuilder *infoBuilder,
KisRecordingAdapter *recordingAdapter)
: KisToolFreehandHelper(infoBuilder, recordingAdapter),
m_d(new Private)
{
}
void KisToolMultihandHelper::setupTransformations(const QVector<QTransform> &transformations)
{
m_d->transformations = transformations;
}
void KisToolMultihandHelper::createPainters(QVector<KisPainter*> &painters)
{
for (int i = 0; i < m_d->transformations.size(); i++) {
painters << new KisPainter();
}
}
void KisToolMultihandHelper::paintAt(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi)
{
Q_ASSERT(painters.size() == m_d->transformations.size());
for (int i = 0; i < m_d->transformations.size(); i++) {
const QTransform &transform = m_d->transformations[i];
KisPaintInformation __pi = pi;
__pi.setPos(transform.map(__pi.pos()));
paintAt(painters[i], __pi);
}
}
void KisToolMultihandHelper::paintLine(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const KisPaintInformation &pi2)
{
Q_ASSERT(painters.size() == m_d->transformations.size());
for (int i = 0; i < m_d->transformations.size(); i++) {
const QTransform &transform = m_d->transformations[i];
KisPaintInformation __pi1 = pi1;
KisPaintInformation __pi2 = pi2;
__pi1.setPos(transform.map(__pi1.pos()));
__pi2.setPos(transform.map(__pi2.pos()));
paintLine(painters[i], __pi1, __pi2);
}
}
void KisToolMultihandHelper::paintBezierCurve(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2)
{
Q_ASSERT(painters.size() == m_d->transformations.size());
for (int i = 0; i < m_d->transformations.size(); i++) {
const QTransform &transform = m_d->transformations[i];
KisPaintInformation __pi1 = pi1;
KisPaintInformation __pi2 = pi2;
__pi1.setPos(transform.map(__pi1.pos()));
__pi2.setPos(transform.map(__pi2.pos()));
QPointF __control1 = transform.map(control1);
QPointF __control2 = transform.map(control2);
paintBezierCurve(painters[i], __pi1, __control1, __control2, __pi2);
}
}
/*
* Copyright (c) 2011 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __KIS_TOOL_MULTIHAND_HELPER_H
#define __KIS_TOOL_MULTIHAND_HELPER_H
#include "kis_tool_freehand_helper.h"
class KRITAUI_EXPORT KisToolMultihandHelper : public KisToolFreehandHelper
{
Q_OBJECT
public:
KisToolMultihandHelper(KisPaintingInformationBuilder *infoBuilder,
KisRecordingAdapter *recordingAdapter = 0);
void setupTransformations(const QVector<QTransform> &transformations);
protected:
void createPainters(QVector<KisPainter*> &painters);
void paintAt(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi);
void paintLine(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const KisPaintInformation &pi2);
void paintBezierCurve(const QVector<KisPainter*> &painters,
const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2);
using KisToolFreehandHelper::paintAt;
using KisToolFreehandHelper::paintLine;
using KisToolFreehandHelper::paintBezierCurve;
private:
struct Private;
Private * const m_d;
};
#endif /* __KIS_TOOL_MULTIHAND_HELPER_H */
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