2
* Copyright (c) 2009 Lukáš Tvrdý <lukast.dev@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "kis_experiment_paintop.h"
20
#include "kis_experiment_paintop_settings.h"
29
#include <KoColorSpace.h>
31
#include <kis_image.h>
32
#include <kis_debug.h>
34
#include <kis_brush.h>
35
#include <kis_global.h>
36
#include <kis_paint_device.h>
37
#include <kis_painter.h>
38
#include <kis_types.h>
39
#include <kis_paintop.h>
40
#include <kis_selection.h>
41
#include <kis_random_accessor.h>
42
#include <KoCompositeOp.h>
44
#include <kis_experimentop_option.h>
46
KisExperimentPaintOp::KisExperimentPaintOp(const KisExperimentPaintOpSettings *settings, KisPainter * painter, KisImageSP image)
47
: KisPaintOp( painter )
48
, m_settings( settings )
54
m_startSize = settings->getDouble(EXPERIMENT_START_SIZE);
55
m_endSize = settings->getDouble(EXPERIMENT_END_SIZE);
58
qreal average = qMax(m_startSize, m_endSize ) - qMin(m_startSize, m_endSize) * 0.5;
59
if ( average * 0.5 > 1)
61
m_ySpacing = m_xSpacing = average * 0.5 * settings->getDouble(EXPERIMENT_SPACING);
64
m_ySpacing = m_xSpacing = 1.0;
66
m_spacing = m_xSpacing;
70
if ( !settings->node() ){
73
m_dev = settings->node()->paintDevice();
77
m_rotationOption.readOptionSetting(settings);
78
m_sizeOption.readOptionSetting(settings);
79
m_opacityOption.readOptionSetting(settings);
82
KisExperimentPaintOp::~KisExperimentPaintOp()
87
qreal KisExperimentPaintOp::paintAt(const KisPaintInformation& info)
89
if (!painter()) return m_spacing;
92
m_dab = new KisPaintDevice(painter()->device()->colorSpace());
100
m_oldData = new KisPaintDevice(painter()->device()->colorSpace());
111
// delete the previous dab in final datasource which will be bitblt
113
erasedRc = rc = m_previousDab;
114
KisRectConstIteratorPixel srcIt = m_dev->createRectConstIterator(rc.left(), rc.top(), rc.width(), rc.height());
116
KisRectIteratorPixel dstIt = m_oldData->createRectIterator(rc.left(), rc.top(), rc.width(), rc.height());
118
KisRectIteratorPixel dstIt = m_dev->createRectIterator(rc.left(), rc.top(), rc.width(), rc.height());
122
qint32 pixelSize = m_dev->pixelSize();
123
for (;!srcIt.isDone(); ++srcIt, ++dstIt) {
124
memcpy(dstIt.rawData(),srcIt.oldRawData(), pixelSize );
127
QString compositeOpId = painter()->compositeOp()->id();
128
painter()->setCompositeOp(COMPOSITE_CLEAR);
129
painter()->bitBlt(rc.topLeft(), m_oldData, rc);
130
painter()->setCompositeOp(compositeOpId);
134
m_painter = new KisPainter(m_dab);
135
m_painter->setFillStyle(KisPainter::FillStyleForegroundColor);
136
m_painter->setPaintColor(painter()->paintColor());
139
m_positions.append(info);
140
int size = m_positions.size();
148
diameter = m_startSize;
149
pad = 0.5 * diameter;
150
pos = m_positions[0].pos();
151
pos -= QPointF(pad,pad);
152
m_painter->paintEllipse(pos.x(), pos.y(), diameter, diameter);
155
for (int i = 0; i < size; i++)
157
part = (i / (qreal)(size-1));
159
diameter = (1.0 - part) * m_startSize + part * m_endSize; if (diameter < 1.0) continue;
161
pad = 0.5 * diameter;
163
pos = m_positions[i].pos();
164
pos -= QPointF(pad,pad);
166
m_painter->paintEllipse(pos.x(), pos.y(), diameter, diameter);
172
// save the size of it so that we can delete it next time
173
rc = m_previousDab = m_dab->extent();
174
painter()->bitBlt(rc.topLeft(), m_dab, rc);
176
m_settings->node()->setDirty(erasedRc);