~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to .pc/kubuntu_01_arm_needs_qreal.diff/krita/plugins/paintops/defaultpaintops/eraser/kis_eraseop.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3
 
 *  Copyright (c) 2004-2008 Boudewijn Rempt <boud@valdyas.org>
4
 
 *  Copyright (c) 2004 Clarence Dang <dang@kde.org>
5
 
 *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
6
 
 *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
7
 
 *
8
 
 *  This program is free software; you can redistribute it and/or modify
9
 
 *  it under the terms of the GNU General Public License as published by
10
 
 *  the Free Software Foundation; either version 2 of the License, or
11
 
 *  (at your option) any later version.
12
 
 *
13
 
 *  This program is distributed in the hope that it will be useful,
14
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 *  GNU General Public License for more details.
17
 
 *
18
 
 *  You should have received a copy of the GNU General Public License
19
 
 *  along with this program; if not, write to the Free Software
20
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
 
 */
22
 
 
23
 
#include "kis_eraseop.h"
24
 
 
25
 
#include <QRect>
26
 
 
27
 
#include <kis_image.h>
28
 
#include <kis_debug.h>
29
 
 
30
 
#include <KoColorTransformation.h>
31
 
#include <KoColor.h>
32
 
#include <KoCompositeOp.h>
33
 
 
34
 
#include <kis_brush.h>
35
 
#include <kis_global.h>
36
 
#include <kis_paint_device.h>
37
 
#include <kis_painter.h>
38
 
#include <kis_brush_based_paintop_settings.h>
39
 
 
40
 
KisEraseOp::KisEraseOp(const KisBrushBasedPaintOpSettings *settings, KisPainter *painter, KisImageWSP image)
41
 
        : KisBrushBasedPaintOp(settings, painter)
42
 
{
43
 
    Q_UNUSED(image);
44
 
    Q_ASSERT(settings);
45
 
    Q_ASSERT(painter);
46
 
    m_sizeOption.readOptionSetting(settings);
47
 
    m_opacityOption.readOptionSetting(settings);
48
 
    m_sizeOption.sensor()->reset();
49
 
    m_opacityOption.sensor()->reset();
50
 
}
51
 
 
52
 
KisEraseOp::~KisEraseOp()
53
 
{
54
 
}
55
 
 
56
 
double KisEraseOp::paintAt(const KisPaintInformation& info)
57
 
{
58
 
// Erasing is traditionally in paint applications one of two things:
59
 
// either it is painting in the 'background' color, or it is replacing
60
 
// all pixels with transparent (black?) pixels.
61
 
//
62
 
// That's what this paint op does for now; however, anyone who has
63
 
// ever worked with paper and soft pencils knows that a sharp piece of
64
 
// eraser rubber is a pretty useful too for making sharp to fuzzy lines
65
 
// in the graphite layer, or equally useful: for smudging skin tones.
66
 
//
67
 
// A smudge tool for Krita is in the making, but when working with
68
 
// a tablet, the eraser tip should be at least as functional as a rubber eraser.
69
 
// That means that only after repeated or forceful application should all the
70
 
// 'paint' or 'graphite' be removed from the surface -- a kind of pressure
71
 
// sensitive, incremental smudge.
72
 
//
73
 
// And there should be an option to not have the eraser work on certain
74
 
// kinds of material. Layers are just a hack for this; putting your ink work
75
 
// in one layer and your pencil in another is not the same as really working
76
 
// with the combination.
77
 
 
78
 
    if (!painter()->device()) return 1.0;
79
 
 
80
 
    KisBrushSP brush = m_brush;
81
 
    if (!m_brush)
82
 
        return 1.0;
83
 
    
84
 
    if (! brush->canPaintFor(info))
85
 
        return 1.0;
86
 
 
87
 
    double scale = KisPaintOp::scaleForPressure(m_sizeOption.apply(info));
88
 
    if ((scale * brush->width()) <= 0.01 || (scale * brush->height()) <= 0.01) return spacing(scale);
89
 
 
90
 
    KisPaintDeviceSP device = painter()->device();
91
 
    QPointF hotSpot = brush->hotSpot(scale, scale);
92
 
    QPointF pt = info.pos() - hotSpot;
93
 
 
94
 
    qint32 x;
95
 
    double xFraction;
96
 
    qint32 y;
97
 
    double yFraction;
98
 
 
99
 
    splitCoordinate(pt.x(), &x, &xFraction);
100
 
    splitCoordinate(pt.y(), &y, &yFraction);
101
 
 
102
 
    KisFixedPaintDeviceSP dab = cachedDab(device->colorSpace());
103
 
 
104
 
    quint8 origOpacity = m_opacityOption.apply(painter(), info);
105
 
 
106
 
    QRect dabRect = QRect(0, 0, brush->maskWidth(scale, 0.0), brush->maskHeight(scale, 0.0));
107
 
    QRect dstRect = QRect(x, y, dabRect.width(), dabRect.height());
108
 
 
109
 
 
110
 
    if (painter()->bounds().isValid()) {
111
 
        dstRect &= painter()->bounds();
112
 
    }
113
 
 
114
 
    if (dstRect.isNull() || dstRect.isEmpty() || !dstRect.isValid()) return 1.0;
115
 
 
116
 
    qint32 sx = dstRect.x() - x;
117
 
    qint32 sy = dstRect.y() - y;
118
 
    qint32 sw = dstRect.width();
119
 
    qint32 sh = dstRect.height();
120
 
 
121
 
    if (brush->brushType() == IMAGE || brush->brushType() == PIPE_IMAGE) {
122
 
        dab = brush->paintDevice(device->colorSpace(), scale, 0.0, info, xFraction, yFraction);
123
 
    } else {
124
 
        dab = cachedDab();
125
 
        KoColor color = painter()->paintColor();
126
 
        color.convertTo(dab->colorSpace());
127
 
        brush->mask(dab, color, scale, scale, 0.0, info, xFraction, yFraction);
128
 
    }
129
 
 
130
 
    const KoCompositeOp* op = painter()->compositeOp();
131
 
    painter()->setCompositeOp(COMPOSITE_ERASE);
132
 
    painter()->bltFixed(dstRect.x(), dstRect.y(), dab, sx, sy, sw, sh);
133
 
    painter()->setCompositeOp(op);
134
 
 
135
 
    painter()->setOpacity(origOpacity);
136
 
 
137
 
    return spacing(scale);
138
 
}