[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krita/tantsevov/T6224-watercolor] plugins/paintops/watercolor: New planes' and generators' logic
From: Grigory Tantsevov <null () kde ! org>
Date: 2017-08-04 11:21:11
Message-ID: E1ddafH-0002mK-UK () code ! kde ! org
[Download RAW message or body]
Git commit b424f2f42f5450c373685dca1a42634050b08d3b by Grigory Tantsevov.
Committed on 04/08/2017 at 11:20.
Pushed by tantsevov into branch 'tantsevov/T6224-watercolor'.
New planes' and generators' logic
M +1 -1 plugins/paintops/watercolor/CMakeLists.txt
M +68 -8 plugins/paintops/watercolor/kis_base_splats_plane.cpp
M +18 -3 plugins/paintops/watercolor/kis_base_splats_plane.h
A +48 -0 plugins/paintops/watercolor/kis_fixed_splats_plane.cpp [License: \
GPL (v2+)] A +35 -0 plugins/paintops/watercolor/kis_fixed_splats_plane.h \
[License: GPL (v2+)] M +24 -12 \
plugins/paintops/watercolor/kis_splat_generator_strategy.cpp M +6 -6 \
plugins/paintops/watercolor/kis_splat_generator_strategy.h M +44 -38 \
plugins/paintops/watercolor/kis_watercolor_paintop.cpp M +9 -8 \
plugins/paintops/watercolor/kis_watercolor_paintop.h
https://commits.kde.org/krita/b424f2f42f5450c373685dca1a42634050b08d3b
diff --git a/plugins/paintops/watercolor/CMakeLists.txt \
b/plugins/paintops/watercolor/CMakeLists.txt index 892c2b8e589..d17987f5281 100644
--- a/plugins/paintops/watercolor/CMakeLists.txt
+++ b/plugins/paintops/watercolor/CMakeLists.txt
@@ -2,12 +2,12 @@ set(kritawatercolorpaintop_SOURCES
kis_splat.cpp
kis_wetmap.cpp
kis_base_splats_plane.cpp
+ kis_fixed_splats_plane.cpp
watercolor_paintop_plugin.cpp
kis_watercolor_paintop.cpp
kis_watercolor_paintop_settings.cpp
kis_watercolor_paintop_settings_widget.cpp
kis_watercolorop_option.cpp
- kis_watercolor_base_items.cpp
kis_splat_generator_strategy.cpp
)
ki18n_wrap_ui(kritawatercolorpaintop_SOURCES wdgwatercoloroptions.ui )
diff --git a/plugins/paintops/watercolor/kis_base_splats_plane.cpp \
b/plugins/paintops/watercolor/kis_base_splats_plane.cpp index \
808f62c2cb2..2da6e458cff 100644
--- a/plugins/paintops/watercolor/kis_base_splats_plane.cpp
+++ b/plugins/paintops/watercolor/kis_base_splats_plane.cpp
@@ -20,25 +20,85 @@
#include "kis_base_splats_plane.h"
-KisBaseSplatsPlane::KisBaseSplatsPlane(const KoColorSpace *colorSpace)
+KisBaseSplatsPlane::KisBaseSplatsPlane(bool useCaching, KisBaseSplatsPlane \
*lowLvlPlane) + : m_lowLvlPlane(lowLvlPlane),
+ m_isDirty(true),
+ m_useCaching(useCaching)
{
- m_cachedPD = new KisPaintDevice(colorSpace);
+}
+
+KisBaseSplatsPlane::~KisBaseSplatsPlane()
+{
+
}
void KisBaseSplatsPlane::add(KisSplat *splat)
{
- KisPainter *painter = new KisPainter(m_cachedPD);
- splat->doPaint(painter);
+ m_splats << splat;
+ setDirty(splat->boundingRect().toAlignedRect());
}
void KisBaseSplatsPlane::remove(KisSplat *splat)
{
- m_cachedPD->clear(splat->boundingRect().toRect());
+ m_splats.removeOne(splat);
+ setDirty(splat->boundingRect().toAlignedRect());
}
void KisBaseSplatsPlane::paint(KisPainter *gc, QRect rect)
{
- gc->bitBlt(rect.topLeft(),
- m_cachedPD,
- rect);
+ if (m_useCaching) {
+
+ if (m_isDirty) {
+ if (!m_cachedPD) {
+ m_cachedPD = new KisPaintDevice(gc->device()->colorSpace());
+ } else {
+ m_cachedPD->clear();
+ }
+
+ KisPainter *painter = new KisPainter(m_cachedPD);
+ Q_FOREACH (KisSplat *splat, m_splats) {
+ splat->doPaint(painter);
+ }
+ m_isDirty = false;
+ }
+
+
+ gc->bitBlt(rect.topLeft(),
+ m_cachedPD,
+ rect);
+ } else {
+ Q_FOREACH (KisSplat *splat, m_splats) {
+ splat->doPaint(gc);
+ }
+ }
+}
+
+QRect KisBaseSplatsPlane::update(KisWetMap *wetMap)
+{
+ QRect dirtyRect;
+
+ for (auto it = m_splats.begin(); it != m_splats.end();) {
+ KisSplat *splat = *it;
+
+ if (splat->update(wetMap) == KisSplat::Fixed) {
+ m_lowLvlPlane->add(splat);
+ {
+ // move to protected call to parent class
+ it = m_splats.erase(it);
+ setDirty(splat->boundingRect().toAlignedRect());
+
+ }
+ dirtyRect |= splat->boundingRect().toAlignedRect();
+ } else {
+ ++it;
+ }
+ }
+
+ return dirtyRect;
+}
+
+void KisBaseSplatsPlane::setDirty(const QRect &rc)
+{
+ m_dirtyRect |= rc;
+ m_isDirty = true;
}
diff --git a/plugins/paintops/watercolor/kis_base_splats_plane.h \
b/plugins/paintops/watercolor/kis_base_splats_plane.h index 237f602defb..5df7b2c0e01 \
100644
--- a/plugins/paintops/watercolor/kis_base_splats_plane.h
+++ b/plugins/paintops/watercolor/kis_base_splats_plane.h
@@ -41,8 +41,9 @@
class KisBaseSplatsPlane
{
public:
- KisBaseSplatsPlane(const KoColorSpace* colorSpace);
- ~KisBaseSplatsPlane(){}
+ KisBaseSplatsPlane(bool useCaching,
+ KisBaseSplatsPlane *lowLvlPlane = 0);
+ virtual ~KisBaseSplatsPlane();
/**
* @brief add splat to list of splats and paint device
@@ -67,9 +68,23 @@ public:
* @brief update plane
* @param wetMap - base for updating
*/
- QList<KisSplat *> update(KisWetMap *wetMap);
+ virtual QRect update(KisWetMap *wetMap);
+
+
+protected:
+
+ QList<KisSplat*>::iterator remove(QList<KisSplat*>::iterator it);
+ QList<KisSplat*> m_splats;
+ KisBaseSplatsPlane *m_lowLvlPlane;
+
+protected:
+ void setDirty(const QRect &rc);
+
private:
KisPaintDeviceSP m_cachedPD;
+ bool m_isDirty;
+ bool m_useCaching;
+ QRect m_dirtyRect;
};
#endif // KIS_ABSTRACT_SPLATS_PLANE_H
diff --git a/plugins/paintops/watercolor/kis_fixed_splats_plane.cpp \
b/plugins/paintops/watercolor/kis_fixed_splats_plane.cpp new file mode 100644
index 00000000000..676d077ff0d
--- /dev/null
+++ b/plugins/paintops/watercolor/kis_fixed_splats_plane.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 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_fixed_splats_plane.h"
+
+KisFixedSplatsPlane::KisFixedSplatsPlane(KisBaseSplatsPlane *driedPlane)
+ : KisBaseSplatsPlane(true, driedPlane)
+{
+}
+
+QRect KisFixedSplatsPlane::update(KisWetMap *wetMap)
+{
+ QRect dirtyRect;
+
+ for (auto it = m_splats.begin(); it != m_splats.end();) {
+ KisSplat *splat = *it;
+
+ if (splat->update(wetMap) == KisSplat::Dried) {
+ m_lowLvlPlane->add(splat);
+ {
+ // move to protected call to parent class
+ it = m_splats.erase(it);
+ setDirty(splat->boundingRect().toAlignedRect());
+ }
+ dirtyRect |= splat->boundingRect().toAlignedRect();
+ } else {
+ ++it;
+ }
+ }
+
+ return dirtyRect;
+}
+
diff --git a/plugins/paintops/watercolor/kis_fixed_splats_plane.h \
b/plugins/paintops/watercolor/kis_fixed_splats_plane.h new file mode 100644
index 00000000000..7a4f8dee646
--- /dev/null
+++ b/plugins/paintops/watercolor/kis_fixed_splats_plane.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2017 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 KISFIXEDSPLATSPLANE_H
+#define KISFIXEDSPLATSPLANE_H
+
+#include "kis_base_splats_plane.h"
+
+class KisFixedSplatsPlane : public KisBaseSplatsPlane
+{
+public:
+ KisFixedSplatsPlane(KisBaseSplatsPlane *driedPlane);
+
+ QRect update(KisWetMap *wetMap) override;
+
+private:
+ KisBaseSplatsPlane *m_flowingPlane;
+};
+
+#endif // KISFIXEDSPLATSPLANE_H
diff --git a/plugins/paintops/watercolor/kis_splat_generator_strategy.cpp \
b/plugins/paintops/watercolor/kis_splat_generator_strategy.cpp index \
d948e612f0e..2d60100e764 100644
--- a/plugins/paintops/watercolor/kis_splat_generator_strategy.cpp
+++ b/plugins/paintops/watercolor/kis_splat_generator_strategy.cpp
@@ -22,16 +22,20 @@
#include <QVector2D>
-void KisSimpleBrushGenerator::generate(QList<KisSplat *> *flowing, KisWetMap \
*wetMap, QPointF pos, qreal radius, const KoColor &color) +QList<KisSplat *> \
KisSimpleBrushGenerator::generate(KisWetMap *wetMap, QPointF pos, qreal radius, const \
KoColor &color) {
+ QList<KisSplat *> ret;
KisSplat *newSplat = new KisSplat(pos, radius,
color);
wetMap->addWater(pos.toPoint(), radius / 2);
- flowing->push_back(newSplat);
+ ret << newSplat;
+
+ return ret;
}
-void KisWetOnDryGenerator::generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, \
QPointF pos, qreal radius, const KoColor &color) +QList<KisSplat *> \
KisWetOnDryGenerator::generate(KisWetMap *wetMap, QPointF pos, qreal radius, const \
KoColor &color) {
+ QList<KisSplat *> ret;
wetMap->addWater(pos.toPoint(), radius / 2);
/// 1 splat in center, 6 around
@@ -42,7 +46,7 @@ void KisWetOnDryGenerator::generate(QList<KisSplat *> *flowing, \
KisWetMap *wetMa
KisSplat *splat = new KisSplat(pos, radius,
color);
- flowing->push_back(splat);
+ ret << splat;
for (int i = 0; i < 6; i++) {
qreal theta = i * M_PI / 3;
@@ -57,12 +61,14 @@ void KisWetOnDryGenerator::generate(QList<KisSplat *> *flowing, \
KisWetMap *wetMa 1.f,
radialSpeed,
color);
- flowing->push_back(splat);
+ ret << splat;
}
+ return ret;
}
-void KisCrunchyGenerator::generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, \
QPointF pos, qreal radius, const KoColor &color) +QList<KisSplat *> \
KisCrunchyGenerator::generate(KisWetMap *wetMap, QPointF pos, qreal radius, const \
KoColor &color) {
+ QList<KisSplat *> ret;
wetMap->addWater(pos.toPoint(), radius / 2);
KisSplat *splat = new KisSplat(pos,
@@ -70,11 +76,13 @@ void KisCrunchyGenerator::generate(QList<KisSplat *> *flowing, \
KisWetMap *wetMap radius,
15, 5, 0.25f, 2.f,
color);
- flowing->push_back(splat);
+ ret << splat;
+ return ret;
}
-void KisWetOnWetGenerator::generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, \
QPointF pos, qreal radius, const KoColor &color) +QList<KisSplat *> \
KisWetOnWetGenerator::generate(KisWetMap *wetMap, QPointF pos, qreal radius, const \
KoColor &color) {
+ QList<KisSplat *> ret;
wetMap->addWater(pos.toPoint(), radius / 2);
int smallD = radius / 2;
@@ -85,18 +93,20 @@ void KisWetOnWetGenerator::generate(QList<KisSplat *> *flowing, \
KisWetMap *wetMa bigD,
15, 5, 1.f, 2.f,
color);
- flowing->push_back(splat);
+ ret << splat;
splat = new KisSplat(pos,
QPointF(0, 0),
smallD,
15, 5, 1.f, 2.f,
color);
- flowing->push_back(splat);
+ ret << splat;
+ return ret;
}
-void KisBlobbyGenerator::generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, \
QPointF pos, qreal radius, const KoColor &color) +QList<KisSplat *> \
KisBlobbyGenerator::generate(KisWetMap *wetMap, QPointF pos, qreal radius, const \
KoColor &color) {
+ QList<KisSplat *> ret;
wetMap->addWater(pos.toPoint(), radius / 2);
qreal firstD = (qreal) radius / 3;
@@ -126,6 +136,8 @@ void KisBlobbyGenerator::generate(QList<KisSplat *> *flowing, \
KisWetMap *wetMap, size,
15, 5, 1.f, 2.f,
color);
- flowing->push_back(splat);
+ ret << splat;
}
+
+ return ret;
}
diff --git a/plugins/paintops/watercolor/kis_splat_generator_strategy.h \
b/plugins/paintops/watercolor/kis_splat_generator_strategy.h index \
9005dc13bd1..cb73d28446e 100644
--- a/plugins/paintops/watercolor/kis_splat_generator_strategy.h
+++ b/plugins/paintops/watercolor/kis_splat_generator_strategy.h
@@ -30,38 +30,38 @@ class KisSplatGeneratorStrategy
{
public:
virtual ~KisSplatGeneratorStrategy(){}
- virtual void generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, QPointF \
pos, qreal radius, const KoColor &color) = 0; + virtual QList<KisSplat *> \
generate(KisWetMap *wetMap, QPointF pos, qreal radius, const KoColor &color) = 0;
};
class KisSimpleBrushGenerator : public KisSplatGeneratorStrategy
{
public:
- void generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, QPointF pos, qreal \
radius, const KoColor &color) override; + QList<KisSplat *> generate(KisWetMap \
*wetMap, QPointF pos, qreal radius, const KoColor &color) override; };
class KisWetOnDryGenerator : public KisSplatGeneratorStrategy
{
public:
- void generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, QPointF pos, qreal \
radius, const KoColor &color) override; + QList<KisSplat *> generate(KisWetMap \
*wetMap, QPointF pos, qreal radius, const KoColor &color) override; };
class KisCrunchyGenerator : public KisSplatGeneratorStrategy
{
public:
- void generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, QPointF pos, qreal \
radius, const KoColor &color) override; + QList<KisSplat *> generate(KisWetMap \
*wetMap, QPointF pos, qreal radius, const KoColor &color) override; };
class KisWetOnWetGenerator : public KisSplatGeneratorStrategy
{
public:
- void generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, QPointF pos, qreal \
radius, const KoColor &color) override; + QList<KisSplat *> generate(KisWetMap \
*wetMap, QPointF pos, qreal radius, const KoColor &color) override; };
class KisBlobbyGenerator : public KisSplatGeneratorStrategy
{
public:
- void generate(QList<KisSplat *> *flowing, KisWetMap *wetMap, QPointF pos, qreal \
radius, const KoColor &color) override; + QList<KisSplat *> generate(KisWetMap \
*wetMap, QPointF pos, qreal radius, const KoColor &color) override; };
#endif // KIS_SPLAT_GENERATOR_STRATEGY_H
diff --git a/plugins/paintops/watercolor/kis_watercolor_paintop.cpp \
b/plugins/paintops/watercolor/kis_watercolor_paintop.cpp index \
531cd783fce..4e7088a084c 100644
--- a/plugins/paintops/watercolor/kis_watercolor_paintop.cpp
+++ b/plugins/paintops/watercolor/kis_watercolor_paintop.cpp
@@ -29,10 +29,10 @@
#include "kis_splat_generator_strategy.h"
KisWatercolorPaintOp::KisWatercolorPaintOp(const KisPaintOpSettingsSP settings, \
KisPainter *painter, KisNodeSP node, KisImageSP image)
- : KisPaintOp(painter), m_fixedTree(4, 2),
- m_driedPlane(painter->device()->colorSpace()),
- m_fixedPlane(painter->device()->colorSpace()),
- m_flowingPlane(painter->device()->colorSpace())
+ : KisPaintOp(painter),
+ m_driedPlane(true),
+ m_fixedPlane(&m_driedPlane),
+ m_flowingPlane(false, &m_fixedPlane)
{
Q_UNUSED(image);
Q_UNUSED(node);
@@ -50,9 +50,7 @@ KisWatercolorPaintOp::~KisWatercolorPaintOp()
KisSpacingInformation KisWatercolorPaintOp::paintAt(const KisPaintInformation &info)
{
- QRect flowingRect,
- fixedRect,
- driedRect;
+ QRect dirtyRect;
// Painting new stroke
qint16 time = m_timer.elapsed();
@@ -80,51 +78,59 @@ KisSpacingInformation KisWatercolorPaintOp::paintAt(const \
KisPaintInformation &i break;
}
- strategy->generate(&m_flowing,
- m_wetMap,
+ QList<KisSplat *> newSplats =
+ strategy->generate(m_wetMap,
info.pos(),
m_watercolorOption.radius,
painter()->paintColor());
- foreach (KisSplat *splat, m_flowing) {
+
+ foreach (KisSplat *splat, newSplats) {
m_flowingPlane.add(splat);
- flowingRect |= splat->boundingRect().toRect();
+ dirtyRect |= splat->boundingRect().toAlignedRect();
}
// Updating system
for (int i = 0; i < timeGone / 33; i++) {
- foreach (KisSplat *splat, m_flowing) {
- if (splat->update(m_wetMap) == KisSplat::Fixed) {
- m_fixed.push_back(splat);
- m_fixedTree.insert(splat->boundingRect(), splat);
- m_fixedPlane.add(splat);
- fixedRect |= splat->boundingRect().toRect();
-
- m_flowing.removeOne(splat);
- m_flowingPlane.remove(splat);
- flowingRect |= splat->boundingRect().toRect();
- }
- }
- foreach (KisSplat *splat, m_fixed) {
- if (splat->update(m_wetMap) == KisSplat::Dried) {
- m_dried.push_back(splat);
- m_driedPlane.add(splat);
- driedRect |= splat->boundingRect().toRect();
-
- m_fixed.removeOne(splat);
- m_fixedTree.remove(splat);
- m_fixedPlane.remove(splat);
- fixedRect |= splat->boundingRect().toRect();
- }
- }
+// foreach (KisSplat *splat, m_flowing) {
+// // todo: check if tree should be updated when splat is changed
+
+// if (splat->update(m_wetMap) == KisSplat::Fixed) {
+// m_fixed.push_back(splat);
+// m_fixedTree.insert(splat->boundingRect(), splat);
+// m_fixedPlane.add(splat);
+// fixedRect |= splat->boundingRect().toRect();
+
+// m_flowing.removeOne(splat);
+// m_flowingPlane.remove(splat);
+// flowingRect |= splat->boundingRect().toRect();
+// }
+// }
+
+// fixedRect |= m_fixedPlane.update(wetMap);
+
+// /*foreach (KisSplat *splat, m_fixed) {
+// if (splat->update(m_wetMap) == KisSplat::Dried) {
+// m_dried.push_back(splat);
+// m_driedPlane.add(splat);
+// driedRect |= splat->boundingRect().toRect();
+
+// m_fixed.removeOne(splat);
+// m_fixedTree.remove(splat);
+// m_fixedPlane.remove(splat);
+// fixedRect |= splat->boundingRect().toRect();
+// }
+// }*/
+ dirtyRect |= m_fixedPlane.update(m_wetMap) |
+ m_flowingPlane.update(m_wetMap);
m_wetMap->update();
}
m_lastTime = time - time % 33;
source()->clear();
- m_driedPlane.paint(painter(), driedRect);
- m_fixedPlane.paint(painter(), fixedRect);
- m_flowingPlane.paint(painter(), flowingRect);
+ m_driedPlane.paint(painter(), dirtyRect);
+ m_fixedPlane.paint(painter(), dirtyRect);
+ m_flowingPlane.paint(painter(), dirtyRect);
return updateSpacingImpl(info);
}
diff --git a/plugins/paintops/watercolor/kis_watercolor_paintop.h \
b/plugins/paintops/watercolor/kis_watercolor_paintop.h index f395abed90d..a7edda18c14 \
100644
--- a/plugins/paintops/watercolor/kis_watercolor_paintop.h
+++ b/plugins/paintops/watercolor/kis_watercolor_paintop.h
@@ -35,6 +35,7 @@
#include "KoRTree.h"
#include "kis_base_splats_plane.h"
+#include "kis_fixed_splats_plane.h"
class KisPainter;
@@ -59,14 +60,14 @@ private:
KisWetMap *m_wetMap;
- QList<KisSplat *> m_flowing,
- m_fixed,
- m_dried;
- KoRTree<KisSplat *> m_fixedTree;
-
- KisBaseSplatsPlane m_driedPlane,
- m_fixedPlane,
- m_flowingPlane;
+// QList<KisSplat *> m_flowing,
+// m_fixed,
+// m_dried;
+// KoRTree<KisSplat *> m_fixedTree;
+
+ KisBaseSplatsPlane m_driedPlane;
+ KisFixedSplatsPlane m_fixedPlane;
+ KisBaseSplatsPlane m_flowingPlane;
};
#endif // KIS_EXPERIMENT_PAINTOP_H_
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic