Commit abce2dcc authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Added recording adapter

Now the recording works again
parent 29f5c407
......@@ -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_recording_adapter.cpp
tool/kis_tool_paint.cc
tool/kis_tool_shape.cc
tool/kis_tool_select_base.cpp
......
/*
* 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_recording_adapter.h"
#include "kis_image.h"
#include "kis_node.h"
#include "kis_paintop_preset.h"
#include "recorder/kis_action_recorder.h"
#include "recorder/kis_recorded_path_paint_action.h"
#include "recorder/kis_node_query_path.h"
KisRecordingAdapter::KisRecordingAdapter()
: m_pathPaintAction(0)
{
}
KisRecordingAdapter::~KisRecordingAdapter()
{
}
void KisRecordingAdapter::startStroke(KisImageWSP image, KisResourcesSnapshotSP resources)
{
Q_ASSERT(!m_pathPaintAction);
Q_ASSERT(!m_image);
m_image = image;
m_pathPaintAction = new KisRecordedPathPaintAction(
KisNodeQueryPath::absolutePath(resources->currentNode()), 0);
resources->setupPaintAction(m_pathPaintAction);
}
void KisRecordingAdapter::endStroke()
{
Q_ASSERT(m_pathPaintAction);
Q_ASSERT(m_image);
m_image->actionRecorder()->addAction(*m_pathPaintAction);
delete m_pathPaintAction;
m_pathPaintAction = 0;
m_image = 0;
}
void KisRecordingAdapter::addPoint(const KisPaintInformation &pi)
{
m_pathPaintAction->addPoint(pi);
}
void KisRecordingAdapter::addLine(const KisPaintInformation &pi1,
const KisPaintInformation &pi2)
{
m_pathPaintAction->addLine(pi1, pi2);
}
void KisRecordingAdapter::addCurve(const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2)
{
m_pathPaintAction->addCurve(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_RECORDING_ADAPTER_H
#define __KIS_RECORDING_ADAPTER_H
#include "kis_types.h"
#include "kis_resources_snapshot.h"
class KisRecordedPathPaintAction;
class KisPaintInformation;
class KisRecordingAdapter
{
public:
KisRecordingAdapter();
~KisRecordingAdapter();
void startStroke(KisImageWSP image, KisResourcesSnapshotSP resources);
void endStroke();
void addPoint(const KisPaintInformation &pi);
void addLine(const KisPaintInformation &pi1,
const KisPaintInformation &pi2);
void addCurve(const KisPaintInformation &pi1,
const QPointF &control1,
const QPointF &control2,
const KisPaintInformation &pi2);
private:
KisImageWSP m_image;
KisRecordedPathPaintAction *m_pathPaintAction;
};
#endif /* __KIS_RECORDING_ADAPTER_H */
......@@ -29,6 +29,7 @@
#include "kis_image.h"
#include "kis_paint_device.h"
#include "kis_paint_layer.h"
#include "recorder/kis_recorded_paint_action.h"
struct KisResourcesSnapshot::Private {
......@@ -114,6 +115,21 @@ void KisResourcesSnapshot::setupPainter(KisPainter* painter)
painter->setMirrorInformation(m_d->axisCenter, m_d->mirrorMaskHorizontal, m_d->mirrorMaskVertical);
}
void KisResourcesSnapshot::setupPaintAction(KisRecordedPaintAction *action)
{
action->setPaintOpPreset(m_d->currentPaintOpPreset);
action->setPaintIncremental(!needsIndirectPainting());
action->setPaintColor(m_d->currentFgColor);
action->setBackgroundColor(m_d->currentBgColor);
action->setGenerator(m_d->currentGenerator);
action->setGradient(m_d->currentGradient);
action->setPattern(m_d->currentPattern);
action->setOpacity(m_d->opacity / qreal(OPACITY_OPAQUE_U8));
action->setCompositeOp(m_d->compositeOp->id());
}
KisPostExecutionUndoAdapter* KisResourcesSnapshot::postExecutionUndoAdapter() const
{
return m_d->undoAdapter;
......
......@@ -29,6 +29,7 @@ class KoResourceManager;
class KoCompositeOp;
class KisPainter;
class KisPostExecutionUndoAdapter;
class KisRecordedPaintAction;
class KRITAUI_EXPORT KisResourcesSnapshot : public KisShared
......@@ -38,6 +39,8 @@ public:
~KisResourcesSnapshot();
void setupPainter(KisPainter *painter);
void KDE_DEPRECATED setupPaintAction(KisRecordedPaintAction *action);
KisPostExecutionUndoAdapter* postExecutionUndoAdapter() const;
void setCurrentNode(KisNodeSP node);
......
......@@ -36,8 +36,6 @@
#include <kis_canvas_resource_provider.h>
// Krita/image
#include <recorder/kis_action_recorder.h>
#include <recorder/kis_recorded_path_paint_action.h>
#include <kis_layer.h>
#include <kis_paint_layer.h>
#include <kis_painter.h>
......@@ -52,7 +50,6 @@
#include <opengl/kis_opengl.h>
#include "canvas/kis_canvas2.h"
#include "kis_cursor.h"
#include <recorder/kis_node_query_path.h>
#include <kis_view2.h>
#include <kis_painting_assistants_manager.h>
#include <kis_3d_object_model.h>
......@@ -60,10 +57,10 @@
#include "kis_painting_information_builder.h"
#include "kis_tool_freehand_helper.h"
#include "kis_recording_adapter.h"
#include "strokes/freehand_stroke.h"
#define ENABLE_RECORDING
static const int HIDE_OUTLINE_TIMEOUT = 800; // ms
KisToolFreehand::KisToolFreehand(KoCanvasBase * canvas, const QCursor & cursor, const QString & transactionText)
......@@ -75,7 +72,6 @@ KisToolFreehand::KisToolFreehand(KoCanvasBase * canvas, const QCursor & cursor,
m_assistant = false;
m_smoothness = 1.0;
m_magnetism = 1.0;
m_pathPaintAction = 0;
setSupportOutline(true);
......@@ -101,12 +97,14 @@ KisToolFreehand::KisToolFreehand(KoCanvasBase * canvas, const QCursor & cursor,
m_infoBuilder = new KisToolPaintingInformationBuilder(this);
m_helper = new KisToolFreehandHelper(m_infoBuilder);
m_recordingAdapter = new KisRecordingAdapter();
m_helper = new KisToolFreehandHelper(m_infoBuilder, m_recordingAdapter);
}
KisToolFreehand::~KisToolFreehand()
{
delete m_helper;
delete m_recordingAdapter;
delete m_infoBuilder;
}
......@@ -134,17 +132,6 @@ void KisToolFreehand::initStroke(KoPointerEvent *event)
image(),
image().data(),
image()->postExecutionUndoAdapter());
#ifdef ENABLE_RECORDING // Temporary, to figure out what is going without being
// distracted by the recording
bool indirectPainting = !currentPaintOpPreset()->settings()->paintIncremental();
m_pathPaintAction = new KisRecordedPathPaintAction(
KisNodeQueryPath::absolutePath(currentNode()),
currentPaintOpPreset()
);
m_pathPaintAction->setPaintIncremental(!indirectPainting);
setupPaintAction(m_pathPaintAction);
#endif
}
void KisToolFreehand::doStroke(KoPointerEvent *event)
......@@ -155,14 +142,6 @@ void KisToolFreehand::doStroke(KoPointerEvent *event)
void KisToolFreehand::endStroke()
{
m_helper->endPaint();
#ifdef ENABLE_RECORDING
if (image() && m_pathPaintAction)
image()->actionRecorder()->addAction(*m_pathPaintAction);
delete m_pathPaintAction;
m_pathPaintAction = 0;
#endif
setCurrentNodeLocked(false);
}
......
......@@ -38,11 +38,10 @@ class KoCanvasBase;
class KisPainter;
class KisRecordedPathPaintAction;
class KisPaintingInformationBuilder;
class KisToolFreehandHelper;
class KisRecordingAdapter;
class KRITAUI_EXPORT KisToolFreehand : public KisToolPaint
......@@ -131,13 +130,12 @@ private:
QRectF m_oldOutlineRect;
bool m_explicitShowOutline;
KisRecordedPathPaintAction* m_pathPaintAction;
KAction* m_increaseBrushSize;
KAction* m_decreaseBrushSize;
KisPaintingInformationBuilder *m_infoBuilder;
KisToolFreehandHelper *m_helper;
KisRecordingAdapter *m_recordingAdapter;
};
......
......@@ -25,6 +25,7 @@
#include "kis_distance_information.h"
#include "kis_painting_information_builder.h"
#include "kis_recording_adapter.h"
#include "kis_image.h"
#include "strokes/freehand_stroke.h"
#include "kis_painter.h"
......@@ -33,6 +34,7 @@
struct KisToolFreehandHelper::Private
{
KisPaintingInformationBuilder *infoBuilder;
KisRecordingAdapter *recordingAdapter;
KisStrokesFacade *strokesFacade;
bool haveTangent;
......@@ -59,11 +61,13 @@ struct KisToolFreehandHelper::Private
};
KisToolFreehandHelper::KisToolFreehandHelper(KisPaintingInformationBuilder *infoBuilder)
KisToolFreehandHelper::KisToolFreehandHelper(KisPaintingInformationBuilder *infoBuilder,
KisRecordingAdapter *recordingAdapter)
: m_d(new Private)
{
m_d->painter = 0;
m_d->infoBuilder = infoBuilder;
m_d->recordingAdapter = recordingAdapter;
m_d->smooth = true;
m_d->smoothness = 1.0;
......@@ -116,6 +120,10 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
bool indirectPainting = m_d->resources->needsIndirectPainting();
if(m_d->recordingAdapter) {
m_d->recordingAdapter->startStroke(image, m_d->resources);
}
KisStrokeStrategy *stroke =
new FreehandStrokeStrategy(indirectPainting,
m_d->resources, m_d->painter);
......@@ -191,6 +199,10 @@ void KisToolFreehandHelper::endPaint()
m_d->painter = 0;
m_d->strokesFacade->endStroke(m_d->strokeId);
if(m_d->recordingAdapter) {
m_d->recordingAdapter->endStroke();
}
}
const KisPaintOp* KisToolFreehandHelper::currentPaintOp() const
......@@ -229,6 +241,10 @@ void KisToolFreehandHelper::paintAt(const KisPaintInformation &pi)
new FreehandStrokeStrategy::Data(m_d->resources->currentNode(),
m_d->painter, pi,
m_d->dragDistance));
if(m_d->recordingAdapter) {
m_d->recordingAdapter->addPoint(pi);
}
}
void KisToolFreehandHelper::paintLine(const KisPaintInformation &pi1,
......@@ -239,6 +255,10 @@ void KisToolFreehandHelper::paintLine(const KisPaintInformation &pi1,
new FreehandStrokeStrategy::Data(m_d->resources->currentNode(),
m_d->painter, pi1, pi2,
m_d->dragDistance));
if(m_d->recordingAdapter) {
m_d->recordingAdapter->addLine(pi1, pi2);
}
}
void KisToolFreehandHelper::paintBezierCurve(const KisPaintInformation &pi1,
......@@ -252,5 +272,9 @@ void KisToolFreehandHelper::paintBezierCurve(const KisPaintInformation &pi1,
m_d->painter,
pi1, control1, control2, pi2,
m_d->dragDistance));
if(m_d->recordingAdapter) {
m_d->recordingAdapter->addCurve(pi1, control1, control2, pi2);
}
}
......@@ -28,6 +28,7 @@
class KoPointerEvent;
class KoResourceManager;
class KisPaintingInformationBuilder;
class KisRecordingAdapter;
class KisStrokesFacade;
class KisPostExecutionUndoAdapter;
class KisPaintOp;
......@@ -38,7 +39,8 @@ class KRITAUI_EXPORT KisToolFreehandHelper : public QObject
Q_OBJECT
public:
KisToolFreehandHelper(KisPaintingInformationBuilder *infoBuilder);
KisToolFreehandHelper(KisPaintingInformationBuilder *infoBuilder,
KisRecordingAdapter *recordingAdapter = 0);
~KisToolFreehandHelper();
void setSmoothness(bool smooth, qreal smoothness);
......
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