Commit 46eb9ae7 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix live preview for the multithreaded brush

Now there is a background stroke running for that
parent c3a1ef80
......@@ -50,7 +50,7 @@ struct KisResourcesSnapshot::Private {
KisDefaultBoundsBaseSP bounds;
KoColor currentFgColor;
KoColor currentBgColor;
KoPattern *currentPattern;
KoPattern *currentPattern = 0;
KoAbstractGradient *currentGradient;
KisPaintOpPresetSP currentPaintOpPreset;
KisNodeSP currentNode;
......@@ -58,19 +58,19 @@ struct KisResourcesSnapshot::Private {
KisFilterConfigurationSP currentGenerator;
QPointF axesCenter;
bool mirrorMaskHorizontal;
bool mirrorMaskVertical;
bool mirrorMaskHorizontal = false;
bool mirrorMaskVertical = false;
quint8 opacity;
QString compositeOpId;
quint8 opacity = OPACITY_OPAQUE_U8;
QString compositeOpId = COMPOSITE_OVER;
const KoCompositeOp *compositeOp;
KisPainter::StrokeStyle strokeStyle;
KisPainter::FillStyle fillStyle;
KisPainter::StrokeStyle strokeStyle = KisPainter::StrokeStyleBrush;
KisPainter::FillStyle fillStyle = KisPainter::FillStyleForegroundColor;
bool globalAlphaLock;
qreal effectiveZoom;
bool presetAllowsLod;
bool globalAlphaLock = false;
qreal effectiveZoom = 1.0;
bool presetAllowsLod = false;
KisSelectionSP selectionOverride;
};
......
......@@ -21,6 +21,7 @@
#include <QDebug>
#include <QGraphicsPixmapItem>
#include "kis_paintop_settings.h"
#include <strokes/freehand_stroke.h>
KisPresetLivePreviewView::KisPresetLivePreviewView(QWidget *parent): QGraphicsView(parent)
{
......@@ -29,7 +30,6 @@ KisPresetLivePreviewView::KisPresetLivePreviewView(QWidget *parent): QGraphicsVi
KisPresetLivePreviewView::~KisPresetLivePreviewView()
{
delete m_brushPreviewPainter;
delete m_noPreviewText;
delete m_brushPreviewScene;
}
......@@ -58,7 +58,6 @@ void KisPresetLivePreviewView::setup()
m_layer = new KisPaintLayer(m_image, "livePreviewStrokeSample", OPACITY_OPAQUE_U8, m_colorSpace);
m_brushPreviewPainter = new KisPainter(m_layer->paintDevice());
// set scene for the view
m_brushPreviewScene = new QGraphicsScene();
......@@ -150,15 +149,14 @@ void KisPresetLivePreviewView::paintBackground()
}
m_brushPreviewPainter->fill(m_layer->image()->width()*sectionPercent*i,
0,
m_layer->image()->width()*(sectionPercent*i +sectionPercent),
m_layer->image()->height(),
fillColor);
const QRect fillRect(m_layer->image()->width()*sectionPercent*i,
0,
m_layer->image()->width()*(sectionPercent*i +sectionPercent),
m_layer->image()->height());
m_layer->paintDevice()->fill(fillRect, fillColor);
}
m_brushPreviewPainter->setPaintColor(KoColor(Qt::white, m_colorSpace));
m_paintColor = KoColor(Qt::white, m_colorSpace);
}
else if (m_currentPreset->paintOp().id() == "roundmarker" ||
......@@ -190,12 +188,8 @@ void KisPresetLivePreviewView::paintBackground()
else {
// fill with gray first to clear out what existed from previous preview
m_brushPreviewPainter->fill(0,0,
m_layer->image()->width(),
m_layer->image()->height(),
KoColor(palette().color(QPalette::Background) , m_colorSpace));
m_brushPreviewPainter->setPaintColor(KoColor(palette().color(QPalette::Text), m_colorSpace));
m_layer->paintDevice()->fill(m_image->bounds(), KoColor(palette().color(QPalette::Background) , m_colorSpace));
m_paintColor = KoColor(palette().color(QPalette::Text), m_colorSpace);
}
}
......@@ -208,7 +202,26 @@ void KisPresetLivePreviewView::setupAndPaintStroke()
qreal previewSize = qBound(1.0, m_currentPreset->settings()->paintOpSize(), 150.0 ); // constrain live preview brush size
KisPaintOpPresetSP proxy_preset = m_currentPreset->clone();
proxy_preset->settings()->setPaintOpSize(previewSize);
m_brushPreviewPainter->setPaintOpPreset(proxy_preset, m_layer, m_image);
KisResourcesSnapshotSP resources =
new KisResourcesSnapshot(m_image,
m_layer);
resources->setBrush(proxy_preset);
resources->setFGColorOverride(m_paintColor);
FreehandStrokeStrategy::PainterInfo *painterInfo = new FreehandStrokeStrategy::PainterInfo();
KisStrokeStrategy *stroke =
new FreehandStrokeStrategy(resources->needsIndirectPainting(),
resources->indirectPaintingCompositeOp(),
resources, painterInfo, kundo2_noi18n("temp_stroke"));
KisStrokeId strokeId = m_image->startStroke(stroke);
//m_brushPreviewPainter->setPaintOpPreset(proxy_preset, m_layer, m_image);
// slope-intercept is good for mapping two values.
......@@ -251,13 +264,14 @@ void KisPresetLivePreviewView::setupAndPaintStroke()
m_canvasCenterPoint.y() + (this->height()*0.2) ));
m_brushPreviewPainter->paintBezierCurve(pointOne,
QPointF(m_canvasCenterPoint.x() + this->width(),
m_canvasCenterPoint.y() - (this->height()*0.2) ),
QPointF(m_canvasCenterPoint.x() - this->width(),
m_canvasCenterPoint.y() + (this->height()*0.2) ),
pointTwo, &m_currentDistance);
m_image->addJob(strokeId,
new FreehandStrokeStrategy::Data(0,
pointOne,
QPointF(m_canvasCenterPoint.x() + this->width(),
m_canvasCenterPoint.y() - (this->height()*0.2) ),
QPointF(m_canvasCenterPoint.x() - this->width(),
m_canvasCenterPoint.y() + (this->height()*0.2) ),
pointTwo));
} else {
......@@ -271,14 +285,19 @@ void KisPresetLivePreviewView::setupAndPaintStroke()
m_curvePointPI2.setPressure(1.0);
m_brushPreviewPainter->paintBezierCurve(m_curvePointPI1,
QPointF(m_canvasCenterPoint.x(),
m_canvasCenterPoint.y()-this->height()),
QPointF(m_canvasCenterPoint.x(),
m_canvasCenterPoint.y()+this->height()),
m_curvePointPI2, &m_currentDistance);
m_image->addJob(strokeId,
new FreehandStrokeStrategy::Data(0,
m_curvePointPI1,
QPointF(m_canvasCenterPoint.x(),
m_canvasCenterPoint.y()-this->height()),
QPointF(m_canvasCenterPoint.x(),
m_canvasCenterPoint.y()+this->height()),
m_curvePointPI2));
}
m_image->addJob(strokeId, new FreehandStrokeStrategy::UpdateData(true));
m_image->endStroke(strokeId);
m_image->waitForDone();
// even though the brush is cloned, the proxy_preset still has some connection to the original preset which will mess brush sizing
......
......@@ -33,6 +33,7 @@
#include "kis_painting_information_builder.h"
#include <kis_image.h>
#include <kis_types.h>
#include <KoColor.h>
/**
* Widget for displaying a live brush preview of your
......@@ -91,8 +92,8 @@ private:
/// internally sets the color space for brush preview
const KoColorSpace *m_colorSpace;
/// painter that actually paints the stroke
KisPainter *m_brushPreviewPainter;
/// the color which is used for rendering the stroke
KoColor m_paintColor;
/// the scene that can add items like text and the brush stroke image
QGraphicsScene *m_brushPreviewScene;
......
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