Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_resources_snapshot.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <KoColor.h>
16#include <resources/KoPattern.h>
19#include "kis_image.h"
20#include "kis_paint_device.h"
21#include "kis_paint_layer.h"
22#include "kis_selection.h"
23#include "kis_selection_mask.h"
24#include "kis_algebra_2d.h"
26
65
67 : m_d(new Private())
68{
69 m_d->image = image;
70 if (!bounds) {
72 }
73 m_d->bounds = bounds;
80 if(m_d->currentGradient) {
82 ->cloneAndBakeVariableColors(m_d->globalCanvasResourcesInterface);
83 }
84 }
86
93 if (presetOverride) {
97 presetOverride->cloneWithResourcesSnapshot(
100 nullptr);
101 } else {
103 if (p) {
105
106 KIS_SAFE_ASSERT_RECOVER(!cacheInterface || p->sanityCheckResourceCacheIsValid(cacheInterface)) {
107 cacheInterface.clear();
108 }
109
111 p->cloneWithResourcesSnapshot(KisGlobalResourcesInterface::instance(),
113 cacheInterface);
114 }
115 }
116
117#ifdef HAVE_THREADED_TEXT_RENDERING_WORKAROUND
118 KisPaintOpRegistry::instance()->preinitializePaintOpIfNeeded(m_d->currentPaintOpPreset);
119#endif /* HAVE_THREADED_TEXT_RENDERING_WORKAROUND */
120
121 m_d->currentExposure = resourceManager->resource(KoCanvasResource::HdrExposure).toDouble();
122
123
125 if (m_d->currentGenerator) {
126 m_d->currentGenerator = m_d->currentGenerator->cloneWithResourcesSnapshot();
127 }
128
129 QPointF relativeAxesCenter(0.5, 0.5);
130 if (m_d->image) {
131 relativeAxesCenter = m_d->image->mirrorAxesCenter();
132 }
134
137
138 m_d->opacity = resourceManager->resource(KoCanvasResource::Opacity).toDouble();
139
142
144
153
154 // Erasing and alpha lock don't mix. If both are enabled, erasing takes priority.
155 m_d->globalAlphaLock = !resourceManager->resource(KoCanvasResource::EraserMode).toBool()
156 && resourceManager->resource(KoCanvasResource::GlobalAlphaLock).toBool();
157 m_d->effectiveZoom = resourceManager->resource(KoCanvasResource::EffectiveZoom).toDouble();
158
160}
161
163 : m_d(new Private())
164{
165 m_d->image = image;
166 if (!bounds) {
168 }
169 m_d->bounds = bounds;
170
171#ifdef HAVE_THREADED_TEXT_RENDERING_WORKAROUND
172 KisPaintOpRegistry::instance()->preinitializePaintOpIfNeeded(m_d->currentPaintOpPreset);
173#endif /* HAVE_THREADED_TEXT_RENDERING_WORKAROUND */
174
175 QPointF relativeAxesCenter(0.5, 0.5);
176 if (m_d->image) {
177 relativeAxesCenter = m_d->image->mirrorAxesCenter();
178 }
181
183
192}
193
194
199
201{
202 painter->setPaintColor(currentFgColor());
205 painter->setPattern(m_d->currentPattern);
207
208 QBitArray lockflags = channelLockFlags();
209 if (lockflags.size() > 0) {
210 painter->setChannelFlags(lockflags);
211 }
212
213 painter->setOpacityF(m_d->opacity);
216
217 painter->setStrokeStyle(m_d->strokeStyle);
218 painter->setFillStyle(m_d->fillStyle);
220
221
227}
228
230{
233
234 painter->setPaintColor(KoColor(Qt::white, painter->device()->colorSpace()));
235 painter->setBackgroundColor(KoColor(Qt::black, painter->device()->colorSpace()));
236
237 painter->setOpacityToUnit();
238 painter->setChannelFlags(QBitArray());
239
240 // masked brush always paints in indirect mode
242
244
245 painter->setStrokeStyle(m_d->strokeStyle);
246
251 painter->setPaintOpPreset(m_d->currentPaintOpPreset->createMaskingPreset(),
253}
254
259
264
266{
267 m_d->strokeStyle = strokeStyle;
268}
269
271{
272 m_d->fillStyle = fillStyle;
273}
274
276{
277 m_d->fillTransform = transform;
278}
279
284
289
291{
292 return m_d->image;
293}
294
296{
297 return !m_d->currentPaintOpPreset->settings()->paintIncremental();
298}
299
301{
302 return m_d->currentPaintOpPreset ?
303 m_d->currentPaintOpPreset->settings()->indirectPaintingCompositeOp()
305}
306
311
313{
319 return m_d->selectionOverride;
320 }
321
322 KisSelectionSP selection = m_d->image ? m_d->image->globalSelection() : 0;
323
324 KisLayerSP layer;
326 if((layer = qobject_cast<KisLayer*>(m_d->currentNode.data()))) {
327 selection = layer->selection();
328 } else if ((mask = dynamic_cast<KisSelectionMask*>(m_d->currentNode.data())) &&
329 mask->selection() == selection) {
330
331 selection = 0;
332 }
333
334 return selection;
335}
336
338{
339 return ( m_d->currentPaintOpPreset
340 && m_d->currentPaintOpPreset->settings()
341 && m_d->currentPaintOpPreset->settings()->isAirbrushing());
342}
343
345{
346 return ( m_d->currentPaintOpPreset
347 && m_d->currentPaintOpPreset->settings()
348 && m_d->currentPaintOpPreset->settings()->airbrushInterval());
349}
350
352{
353 return ( m_d->currentPaintOpPreset
354 && m_d->currentPaintOpPreset->settings()
355 && m_d->currentPaintOpPreset->settings()->useSpacingUpdates());
356}
357
359{
361}
362
363void KisResourcesSnapshot::setCompositeOpId(const QString &compositeOpId)
364{
366}
367
368void KisResourcesSnapshot::setMirroring(bool horizontal, bool vertical)
369{
370 m_d->mirrorMaskHorizontal = horizontal;
371 m_d->mirrorMaskVertical = vertical;
372}
373
375{
376 return m_d->opacity;
377}
378
380{
381 return m_d->compositeOpId;
382}
383
388
390{
391 if (m_d->isUsingOtherColor) {
392 // temporarily swap colors if requested by user
393 return m_d->currentBgColor;
394 } else {
395 return m_d->currentFgColor;
396 }
397}
398
400{
401 if (m_d->isUsingOtherColor) {
402 // temporarily swap colors if requested by user
403 return m_d->currentFgColor;
404 } else {
405 return m_d->currentBgColor;
406 }
407}
408
413
415{
416 return m_d->fillTransform;
417}
418
423
428
433
435{
436 QBitArray channelFlags;
437 KisPaintLayer *paintLayer;
438 if ((paintLayer = dynamic_cast<KisPaintLayer*>(m_d->currentNode.data()))) {
439
440 channelFlags = paintLayer->channelLockFlags();
441 if (m_d->globalAlphaLock) {
442 if (channelFlags.isEmpty()) {
443 channelFlags = paintLayer->colorSpace()->channelFlags(true, true);
444 }
445
446 channelFlags &= paintLayer->colorSpace()->channelFlags(true, false);
447 }
448 }
449 return channelFlags;
450}
451
453{
454 return m_d->effectiveZoom;
455}
456
461
463{
464 return m_d->currentPaintOpPreset && m_d->currentPaintOpPreset->settings()->needsAsynchronousUpdates();
465}
466
468{
469 m_d->currentFgColor = color;
470}
471
473{
474 m_d->currentBgColor = color;
475}
476
478{
479 m_d->selectionOverride = selection;
480 m_d->hasOverrideSelection = true; // needed if selection passed is null to ignore selection
481}
482
484{
486 brush->cloneWithResourcesSnapshot(
489 nullptr);
490
491#ifdef HAVE_THREADED_TEXT_RENDERING_WORKAROUND
492 KisPaintOpRegistry::instance()->preinitializePaintOpIfNeeded(m_d->currentPaintOpPreset);
493#endif /* HAVE_THREADED_TEXT_RENDERING_WORKAROUND */
494}
const Params2D p
const qreal OPACITY_OPAQUE_F
const QString COMPOSITE_OVER
const QString COMPOSITE_ALPHA_DARKEN
virtual QRect imageBorderRect() const
static KisResourcesInterfaceSP instance()
QPointF mirrorAxesCenter() const
KisPostExecutionUndoAdapter * postExecutionUndoAdapter() const override
KisSelectionSP globalSelection() const
Definition kis_image.cc:721
const KoColorSpace * colorSpace() const
static KisPaintOpRegistry * instance()
void setPaintOpPreset(KisPaintOpPresetSP preset, KisNodeSP node, KisImageSP image)
FillStyle
This enum contains the styles with which we can fill things like polygons and ellipses.
@ FillStyleForegroundColor
void setPatternTransform(QTransform transform)
Set the transform on the pattern.
void setStrokeStyle(StrokeStyle strokeStyle)
Set the current brush stroke style.
void setMirrorInformation(const QPointF &axesCenter, bool mirrorHorizontally, bool mirrorVertically)
StrokeStyle
The style of the brush stroke around polygons and so.
void setBackgroundColor(const KoColor &color)
void setOpacityF(qreal opacity)
void setGenerator(KisFilterConfigurationSP generator)
Set the current generator (a generator can be used to fill an area.
void setGradient(const KoAbstractGradientSP gradient)
void setFillStyle(FillStyle fillStyle)
Set the current style with which to fill.
void setOpacityToUnit()
void setPattern(const KoPatternSP pattern)
Set the current pattern.
KisPaintDeviceSP device
void setPaintColor(const KoColor &color)
void setChannelFlags(QBitArray channelFlags)
void setCompositeOpId(const KoCompositeOp *op)
void setupPainter(KisPainter *painter)
void setFGColorOverride(const KoColor &color)
void setFillStyle(KisPainter::FillStyle fillStyle)
void setCurrentNode(KisNodeSP node)
KisPaintOpPresetSP currentPaintOpPreset() const
void setBGColorOverride(const KoColor &color)
void setupMaskingBrushPainter(KisPainter *painter)
KisNodeList selectedNodes() const
KoPatternSP currentPattern() const
KoAbstractGradientSP currentGradient() const
void setBrush(const KisPaintOpPresetSP &brush)
QString indirectPaintingCompositeOp() const
KisFilterConfigurationSP currentGenerator() const
void setMirroring(bool horizontal, bool vertical)
void setSelectionOverride(KisSelectionSP selection)
void setStrokeStyle(KisPainter::StrokeStyle strokeStyle)
KisPostExecutionUndoAdapter * postExecutionUndoAdapter() const
void setCompositeOpId(const QString &compositeOpId)
Override the composite op for the snapshot.
KisResourcesSnapshot(KisImageSP image, KisNodeSP currentNode, KoCanvasResourceProvider *resourceManager, KisDefaultBoundsBaseSP bounds=0, KisNodeList selectedNodes=KisNodeList(), KisPaintOpPresetSP presetOverride=0)
KisSelectionSP activeSelection() const
void setFillTransform(QTransform transform)
KoCanvasResourcesInterfaceSP canvasResourcesInterface() const
QBitArray channelFlags(bool color=true, bool alpha=false) const
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define bounds(x, a, b)
QPointF relativeToAbsolute(const QPointF &pt, const QRectF &rc)
@ CurrentPaintOpPresetCache
the cache associated with the currently active preset (this cache may be different per canvas if the ...
@ EffectiveZoom
-Used only by painting tools for non-displaying purposes
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.
const KoColorSpace * colorSpace() const override
returns the image's colorSpace or null, if there is no image
Definition kis_layer.cc:225
virtual KisSelectionSP selection() const
Definition kis_layer.cc:509
KisSelectionSP selection
Definition kis_mask.cc:44
const QBitArray & channelLockFlags() const
KoCanvasResourcesInterfaceSP globalCanvasResourcesInterface
KisFilterConfigurationSP currentGenerator