Commit 90b30c1a authored by Halla Rempt's avatar Halla Rempt
Browse files

Fix a bug when enabling mirroring and trying the scratchpad

When enabling horizontal and vertical mirroring, painting on the scratchpad
was broken. This was because the scratchpad creates a KisResourceSnapshot
with a 0 image pointer. The snapshot then created a default KisDefaultBounds
object with a 0 image pointer.

That means the KisToolFreehandHelper was told to use an infinite rect
for calculating the mirroring, and iterating over infinity takes a bit of
time.

Fixed by passing the scratchpad's defaultBounds object to the freehand
tool helper, which passes it to the resources snapshot.
parent 681b2ab8
......@@ -38,7 +38,7 @@ struct KisResourcesSnapshot::Private {
}
KisImageWSP image;
KisDefaultBoundsSP bounds;
KisDefaultBoundsBaseSP bounds;
KisPostExecutionUndoAdapter *undoAdapter;
KoColor currentFgColor;
KoColor currentBgColor;
......@@ -61,11 +61,14 @@ struct KisResourcesSnapshot::Private {
KisPainter::FillStyle fillStyle;
};
KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager)
KisResourcesSnapshot::KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager, KisDefaultBoundsBaseSP bounds)
: m_d(new Private())
{
m_d->image = image;
m_d->bounds = new KisDefaultBounds(image);
if (!bounds) {
bounds = new KisDefaultBounds(m_d->image);
}
m_d->bounds = bounds;
m_d->undoAdapter = undoAdapter;
m_d->currentFgColor = resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value<KoColor>();
m_d->currentBgColor = resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value<KoColor>();
......
......@@ -24,7 +24,7 @@
#include "kis_types.h"
#include "krita_export.h"
#include "kis_painter.h"
#include "kis_default_bounds.h"
class KoCanvasResourceManager;
class KoCompositeOp;
......@@ -33,11 +33,10 @@ class KisPostExecutionUndoAdapter;
class KisRecordedPaintAction;
class KisPattern;
class KRITAUI_EXPORT KisResourcesSnapshot : public KisShared
{
public:
KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager);
KisResourcesSnapshot(KisImageWSP image, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager, KisDefaultBoundsBaseSP bounds = 0);
~KisResourcesSnapshot();
void setupPainter(KisPainter *painter);
......
......@@ -93,7 +93,8 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
KisImageWSP image,
KisStrokesFacade *strokesFacade,
KisPostExecutionUndoAdapter *undoAdapter,
KisNodeSP overrideNode)
KisNodeSP overrideNode,
KisDefaultBoundsBaseSP bounds)
{
Q_UNUSED(overrideNode);
......@@ -109,7 +110,8 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
createPainters(m_d->painterInfos);
m_d->resources = new KisResourcesSnapshot(image,
undoAdapter,
resourceManager);
resourceManager,
bounds);
if(overrideNode) {
m_d->resources->setCurrentNode(overrideNode);
......
......@@ -25,7 +25,7 @@
#include "krita_export.h"
#include "kis_paint_information.h"
#include "strokes/freehand_stroke.h"
#include "kis_default_bounds.h"
class KoPointerEvent;
class KoCanvasResourceManager;
......@@ -58,7 +58,8 @@ public:
KisImageWSP image,
KisStrokesFacade *strokesFacade,
KisPostExecutionUndoAdapter *undoAdapter,
KisNodeSP overrideNode = 0);
KisNodeSP overrideNode = 0,
KisDefaultBoundsBaseSP bounds = 0);
void paint(KoPointerEvent *event);
void endPaint();
......
......@@ -197,11 +197,13 @@ void KisScratchPad::beginStroke(KoPointerEvent *event)
{
KoCanvasResourceManager *resourceManager = m_resourceProvider->resourceManager();
m_helper->initPaint(event, resourceManager,
m_helper->initPaint(event,
resourceManager,
0,
m_updateScheduler,
m_undoAdapter,
m_paintLayer);
m_paintLayer,
m_paintLayer->paintDevice()->defaultBounds());
}
void KisScratchPad::doStroke(KoPointerEvent *event)
......@@ -344,7 +346,6 @@ void KisScratchPad::setupScratchPad(KisCanvasResourceProvider* resourceProvider,
m_paintLayer = new KisPaintLayer(0, "ScratchPad", OPACITY_OPAQUE_U8, paintDevice);
m_paintLayer->setGraphListener(m_nodeListener);
m_paintLayer->paintDevice()->setDefaultBounds(new KisScratchPadDefaultBounds(this));
paintDevice->setDefaultBounds(new KisScratchPadDefaultBounds(this));
fillDefault();
}
......
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