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

« back to all changes in this revision

Viewing changes to krita/plugins/paintops/spray/spray_brush.h

  • 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
1
/*
2
 
 *  Copyright (c) 2008 Lukas Tvrdy <lukast.dev@gmail.com>
 
2
 *  Copyright (c) 2008-2010 Lukáš Tvrdý <lukast.dev@gmail.com>
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
19
19
#ifndef _SPRAY_BRUSH_H_
20
20
#define _SPRAY_BRUSH_H_
21
21
 
22
 
#include <QVector>
23
 
#include <qrect.h>
24
 
 
25
22
#include <KoColor.h>
26
23
 
27
24
#include "kis_paint_device.h"
28
25
#include "kis_painter.h"
29
26
#include "kis_paint_information.h"
30
27
 
31
 
#include "kis_spray_paintop_settings.h"
 
28
#include "kis_color_option.h"
32
29
 
33
30
#include "random_gauss.h"
34
31
 
 
32
 
 
33
#include <QImage>
 
34
 
 
35
 
35
36
class QRect;
36
37
 
 
38
class KisSprayProperties{
 
39
public:
 
40
    quint16 diameter;
 
41
    quint16 radius;
 
42
    quint16 particleCount;
 
43
    qreal aspect;
 
44
    qreal coverage;
 
45
    qreal amount;
 
46
    qreal spacing;
 
47
    qreal scale;
 
48
    qreal brushRotation;
 
49
    bool jitterMovement;
 
50
    bool useDensity;
 
51
    // particle type size
 
52
    quint8 shape;
 
53
    quint16 width;
 
54
    quint16 height;
 
55
    bool randomSize;
 
56
    bool proportional;
 
57
    // distribution
 
58
    bool gaussian;
 
59
    // rotation
 
60
    bool fixedRotation;
 
61
    bool randomRotation;
 
62
    bool followCursor;
 
63
    quint16 fixedAngle;
 
64
    qreal randomRotationWeight;
 
65
    qreal followCursorWeigth;
 
66
    QImage image;
 
67
};
 
68
 
 
69
 
37
70
class SprayBrush
38
71
{
39
72
 
40
73
public:
41
 
    SprayBrush(const KoColor &inkColor);
42
74
    SprayBrush();
43
75
    ~SprayBrush();
44
 
    SprayBrush(KoColor inkColor);
45
 
    void paint(KisPaintDeviceSP dev, const KisPaintInformation& info, const KoColor &color);
46
 
 
 
76
 
 
77
    void paint(KisPaintDeviceSP dab, KisPaintDeviceSP source,  const KisPaintInformation& info, qreal rotation, qreal scale, const KoColor &color, const KoColor &bgColor);
 
78
    void setProperties(KisSprayProperties * properties, KisColorProperties * colorProperties){
 
79
        m_properties = properties;
 
80
        m_colorProperties = colorProperties;
 
81
    }
 
82
    
 
83
private:
 
84
    KoColor m_inkColor;
 
85
    qreal m_radius;
 
86
    quint32 m_particlesCount; 
 
87
    quint8 m_pixelSize;
 
88
 
 
89
    RandomGauss * m_rand;
 
90
    KisPainter * m_painter;
 
91
    KisPaintDeviceSP m_imageDevice;
 
92
    QImage m_brushQImage;
 
93
    QImage m_transformed;
 
94
 
 
95
    const KisSprayProperties * m_properties;
 
96
    const KisColorProperties * m_colorProperties;
 
97
 
 
98
private:
 
99
    /// rotation in radians according the settings (gauss distribution, uniform distribution or fixed angle)
 
100
    qreal rotationAngle();
47
101
    /// Paints Wu Particle
48
102
    void paintParticle(KisRandomAccessor &writeAccessor, const KoColor &color, qreal rx, qreal ry);
49
103
    void paintCircle(KisPainter * painter, qreal x, qreal y, int radius, int steps);
50
104
    void paintEllipse(KisPainter * painter, qreal x, qreal y, int a, int b, qreal angle, int steps);
51
105
    void paintRectangle(KisPainter * painter, qreal x, qreal y, int width, int height, qreal angle, int steps);
52
106
 
53
 
    void paintMetaballs(KisPaintDeviceSP dev, const KisPaintInformation &info, const KoColor &painterColor);
54
 
    void paintDistanceMap(KisPaintDeviceSP dev, const KisPaintInformation &info, const KoColor &painterColor);
55
 
 
56
107
    void paintOutline(KisPaintDeviceSP dev, const KoColor& painterColor, qreal posX, qreal posY, qreal radius);
57
108
 
58
 
    void setDiameter(int diameter) {
59
 
        m_diameter = diameter;
60
 
        m_radius = diameter * 0.5;
61
 
    }
62
 
 
63
 
    void setCoverity(qreal coverage) {
64
 
        m_coverage = coverage;
65
 
    }
66
 
 
67
 
    void setJitterSize(bool jitterSize) {
68
 
        m_jitterSize = jitterSize;
69
 
    }
70
 
 
71
 
    void setJitterMovement(bool jitterMovement) {
72
 
        m_jitterMovement = jitterMovement;
73
 
    }
74
 
 
75
 
    // set the amount of the jittering brush position
76
 
    void setAmount(qreal amount) {
77
 
        m_amount = amount;
78
 
    }
79
 
 
80
 
    void setScale(qreal scale) {
81
 
        m_scale = scale;
82
 
    }
83
 
 
84
 
    void setObject(int object) {
85
 
        m_object = object;
86
 
    }
87
 
 
88
 
    void setShape(int shape) {
89
 
        m_shape = shape;
90
 
    }
91
 
 
92
 
    void setJitterShapeSize(bool jitterShapeSize) {
93
 
        m_jitterShapeSize = jitterShapeSize;
94
 
    }
95
 
 
96
 
    void setObjectDimension(int width, int height) {
97
 
        m_width = width;
98
 
        m_height = height;
99
 
    }
100
 
 
101
 
    // getters
102
 
    qreal radius() {
103
 
        return m_radius;
104
 
    }
105
 
 
106
 
    qreal objectWidth() {
107
 
        return m_width;
108
 
    }
109
 
 
110
 
    qreal objectHeight() {
111
 
        return m_height;
112
 
    }
113
 
 
114
 
    // setters
115
 
 
116
 
    void setUseDensity(bool useDensity) {
117
 
        m_useDensity = useDensity;
118
 
    }
119
 
 
120
 
    void setParticleCount(int particleCount) {
121
 
        m_particlesCount = particleCount;
122
 
    }
123
 
 
124
 
    void setMaxTreshold(qreal tresh) {
125
 
        m_maxtresh = tresh;
126
 
    }
127
 
 
128
 
    void setMinTreshold(qreal tresh) {
129
 
        m_mintresh = tresh;
130
 
    }
131
 
 
132
 
    void setRendering(bool highQuality) {
133
 
        m_highQuality = highQuality;
134
 
    }
135
 
 
136
 
    void setRadius(qreal radiusX, qreal radiusY) {
137
 
        m_radiusX = qRound(radiusX);
138
 
        m_radiusY = qRound(radiusY);
139
 
    }
140
 
 
141
 
    void setComputeArea(QRect area) {
142
 
        m_computeArea = area;
143
 
    }
144
 
 
145
 
    // set true if the particles should have random opacity
146
 
    void setUseRandomOpacity(bool isRandom) {
147
 
        m_randomOpacity = isRandom;
148
 
    }
149
 
 
150
 
    void setSettingsObject(const KisSprayPaintOpSettings* settings) {
151
 
        m_settings = settings;
152
 
    }
153
 
 
154
 
private:
155
 
    KoColor m_inkColor;
156
 
    int m_counter;
157
 
    qreal m_radius;
158
 
    int m_pixelSize;
159
 
    int m_diameter;
160
 
    qreal m_scale;
161
 
 
162
 
    // jitter
163
 
    bool m_jitterSize;
164
 
    bool m_jitterMovement;
165
 
 
166
 
    qreal m_coverage;
167
 
 
168
 
    // amount of jitter for movement
169
 
    qreal m_amount;
170
 
 
171
 
    int m_object;
172
 
    int m_shape;
173
 
 
174
 
    // object shape
175
 
    int m_width;
176
 
    int m_height;
177
 
    bool m_jitterShapeSize;
178
 
 
179
 
    // particles
180
 
    int m_particlesCount;
181
 
    bool m_useDensity;
182
 
 
183
 
    // metaballs
184
 
    qreal m_maxtresh;
185
 
    qreal m_mintresh;
186
 
 
187
 
    // color options
188
 
    bool m_randomOpacity;
189
 
 
190
 
    int m_radiusX;
191
 
    int m_radiusY;
192
 
 
193
 
    bool m_highQuality;
194
 
 
195
 
    QRect m_computeArea;
196
 
 
197
 
    RandomGauss * m_rand;
198
 
    KisPainter * m_painter;
199
 
private:
200
 
    const KisSprayPaintOpSettings* m_settings;
201
 
 
 
109
    /// mix a with b.b mix with weight and a with 1.0 - weight 
 
110
    inline qreal linearInterpolation(qreal a, qreal b, qreal weight){
 
111
        return (1.0 - weight) * a + weight * b;
 
112
    }
 
113
 
 
114
    // TODO: move this somewhere where I can reuse it 
 
115
    /// convert radians to degrees
 
116
    inline qreal rad2deg(qreal rad){
 
117
        return rad * (180.0/M_PI);
 
118
    }
 
119
 
 
120
    /// convert degrees to radians
 
121
    inline qreal deg2rad(quint16 deg){
 
122
        return deg * (M_PI/180.0);
 
123
    }
202
124
};
203
125
 
204
126
#endif