2
* Copyright (c) 2010 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_particle_paintop.h"
20
#include "kis_particle_paintop_settings.h"
26
#include <KoCompositeOp.h>
28
#include <kis_image.h>
29
#include <kis_debug.h>
31
#include <kis_global.h>
32
#include <kis_paint_device.h>
33
#include <kis_painter.h>
34
#include <kis_types.h>
35
#include <kis_paintop.h>
36
#include <kis_paint_information.h>
38
#include "kis_particleop_option.h"
40
#include "particle_brush.h"
42
KisParticlePaintOp::KisParticlePaintOp(const KisParticlePaintOpSettings *settings, KisPainter * painter, KisImageWSP image)
43
: KisPaintOp( painter )
44
, m_settings( settings )
48
m_properties.particleCount = settings->getInt(PARTICLE_COUNT);
49
m_properties.iterations = settings->getInt(PARTICLE_ITERATIONS);
50
m_properties.gravity = settings->getDouble(PARTICLE_GRAVITY);
51
m_properties.weight = settings->getDouble(PARTICLE_WEIGHT);
52
m_properties.scale = QPointF(settings->getDouble(PARTICLE_SCALE_X),settings->getDouble(PARTICLE_SCALE_Y));
54
m_particleBrush.setProperties( &m_properties );
55
m_particleBrush.initParticles();
60
KisParticlePaintOp::~KisParticlePaintOp()
64
qreal KisParticlePaintOp::paintAt(const KisPaintInformation& info)
66
return paintLine(info, info).spacing;
70
KisDistanceInformation KisParticlePaintOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, const KisDistanceInformation& savedDist)
73
if (!painter()) return KisDistanceInformation();
76
m_dab = new KisPaintDevice(painter()->device()->colorSpace());
84
m_particleBrush.setInitialPosition(pi1.pos());
88
m_particleBrush.draw(m_dab, painter()->paintColor(), pi2.pos());
89
QRect rc = m_dab->extent();
91
painter()->bitBlt(rc.x(), rc.y(), m_dab, rc.x(), rc.y(), rc.width(), rc.height());
93
QPointF diff = pi2.pos() - pi1.pos();
94
return KisDistanceInformation(0, sqrt( diff.x()*diff.x() + diff.y()*diff.y() ));