~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/plugins/paintops/particle/kis_particle_paintop.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "kis_particle_paintop.h"
 
20
#include "kis_particle_paintop_settings.h"
 
21
 
 
22
#include <cmath>
 
23
 
 
24
#include "kis_vec.h"
 
25
 
 
26
#include <KoCompositeOp.h>
 
27
 
 
28
#include <kis_image.h>
 
29
#include <kis_debug.h>
 
30
 
 
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>
 
37
 
 
38
#include "kis_particleop_option.h"
 
39
 
 
40
#include "particle_brush.h"
 
41
 
 
42
KisParticlePaintOp::KisParticlePaintOp(const KisParticlePaintOpSettings *settings, KisPainter * painter, KisImageWSP image)
 
43
    : KisPaintOp( painter )
 
44
    , m_settings( settings )
 
45
{
 
46
    Q_UNUSED(image);
 
47
    
 
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));
 
53
 
 
54
    m_particleBrush.setProperties( &m_properties );
 
55
    m_particleBrush.initParticles();
 
56
 
 
57
    m_first = true;
 
58
}
 
59
 
 
60
KisParticlePaintOp::~KisParticlePaintOp()
 
61
{
 
62
}
 
63
 
 
64
qreal KisParticlePaintOp::paintAt(const KisPaintInformation& info)
 
65
{
 
66
    return paintLine(info, info).spacing;
 
67
}
 
68
 
 
69
 
 
70
KisDistanceInformation KisParticlePaintOp::paintLine(const KisPaintInformation& pi1, const KisPaintInformation& pi2, const KisDistanceInformation& savedDist)
 
71
{
 
72
    Q_UNUSED(savedDist);
 
73
    if (!painter()) return KisDistanceInformation();
 
74
 
 
75
    if (!m_dab) {
 
76
        m_dab = new KisPaintDevice(painter()->device()->colorSpace());
 
77
    }
 
78
    else {
 
79
        m_dab->clear();
 
80
    }
 
81
    
 
82
 
 
83
    if (m_first){
 
84
        m_particleBrush.setInitialPosition(pi1.pos());
 
85
        m_first = false;
 
86
    }
 
87
 
 
88
    m_particleBrush.draw(m_dab, painter()->paintColor(), pi2.pos());
 
89
    QRect rc = m_dab->extent();
 
90
    
 
91
    painter()->bitBlt(rc.x(), rc.y(), m_dab, rc.x(), rc.y(), rc.width(), rc.height());
 
92
 
 
93
    QPointF diff = pi2.pos() - pi1.pos();
 
94
    return KisDistanceInformation(0, sqrt( diff.x()*diff.x() + diff.y()*diff.y() ));
 
95
}