Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_brushes_pipe.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2012 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_BRUSHES_PIPE_H
8#define __KIS_BRUSHES_PIPE_H
9
12#include <kis_brush.h>
13
14class KisRandomSource;
16
17
18template<class BrushType>
20{
21public:
24
26 m_brushes.clear();
27 Q_FOREACH (QSharedPointer<BrushType> brush, rhs.m_brushes) {
28 KoResourceSP clonedBrush = brush->clone();
29 QSharedPointer<BrushType> actualClonedBrush = clonedBrush.dynamicCast<BrushType>();
30 m_brushes.append(actualClonedBrush );
31 KIS_ASSERT_RECOVER(clonedBrush) {continue;}
32 }
33 }
34
35 virtual ~KisBrushesPipe() {
36 }
37
38 virtual void clear() {
39 m_brushes.clear();
40 }
41
43 return m_brushes.first();
44 }
45
47 return m_brushes.last();
48 }
49
50
52 Q_UNUSED(info);
53 return !m_brushes.isEmpty() ? m_brushes.at(currentBrushIndex()) : 0;
54 }
55
56 qint32 maskWidth(KisDabShape const& shape, double subPixelX, double subPixelY, const KisPaintInformation& info) {
58 return brush ? brush->maskWidth(shape, subPixelX, subPixelY, info) : 0;
59 }
60
61 qint32 maskHeight(KisDabShape const& shape, double subPixelX, double subPixelY, const KisPaintInformation& info) {
63 return brush ? brush->maskHeight(shape, subPixelX, subPixelY, info) : 0;
64 }
65
66 void setAngle(qreal angle) {
67 Q_FOREACH (QSharedPointer<BrushType> brush, m_brushes) {
68 brush->setAngle(angle);
69 }
70 }
71
72 void setScale(qreal scale) {
73 Q_FOREACH (QSharedPointer<BrushType> brush, m_brushes) {
74 brush->setScale(scale);
75 }
76 }
77
78 void setSpacing(double spacing) {
79 Q_FOREACH (QSharedPointer<BrushType> brush, m_brushes) {
80 brush->setSpacing(spacing);
81 }
82 }
83
84 bool isImageType() const {
85 Q_FOREACH (QSharedPointer<BrushType> brush, m_brushes) {
86 if (brush->isImageType()) return true;
87 }
88 return false;
89 }
90
92 Q_FOREACH (QSharedPointer<BrushType> brush, m_brushes) {
93 if (brush->hasColorAndTransparency()) return true;
94 }
95 return false;
96 }
97
98 void setBrushApplication(enumBrushApplication brushApplication) const {
99 Q_FOREACH(QSharedPointer<BrushType> brush, m_brushes) {
100 brush->setBrushApplication(brushApplication);
101 }
102 }
103
104 void setGradient(KoAbstractGradientSP gradient) const {
105 Q_FOREACH(QSharedPointer<BrushType> brush, m_brushes) {
106 brush->setGradient(gradient);
107 }
108 }
109
110 void prepareForSeqNo(const KisPaintInformation& info, int seqNo) {
116 updateBrushIndexes(info.randomSource(), seqNo);
117 chooseNextBrush(info);
118 }
119
121 KisDabShape const& shape,
122 const KisPaintInformation& info,
123 double subPixelX , double subPixelY,
124 qreal softnessFactor, qreal lightnessStrength = DEFAULT_LIGHTNESS_STRENGTH) {
125
127 if (!brush) return;
128
129
130 brush->generateMaskAndApplyMaskOrCreateDab(dst, coloringInformation, shape, info, subPixelX, subPixelY, softnessFactor, lightnessStrength);
131 }
132
134 KisDabShape const& shape,
135 const KisPaintInformation& info,
136 double subPixelX, double subPixelY) {
137
139 if (!brush) return 0;
140
141 KisFixedPaintDeviceSP device = brush->paintDevice(colorSpace, shape, info, subPixelX, subPixelY);
142 return device;
143 }
144
146 Q_FOREACH(QSharedPointer<BrushType> brush, m_brushes) {
147 brush->notifyBrushIsGoingToBeClonedForStroke();
148 }
149 }
150
154
157 (void) chooseNextBrush(info);
158 }
159
165 virtual void notifyStrokeStarted() = 0;
166
167protected:
169 m_brushes.append(brush);
170 }
171
172 int sizeBrush() {
173 return m_brushes.size();
174 }
175
182 virtual int chooseNextBrush(const KisPaintInformation& info) = 0;
183
192 virtual int currentBrushIndex() = 0;
193
202 virtual void updateBrushIndexes(KisRandomSourceSP randomSource, int seqNo) = 0;
203
204protected:
206};
207
208#endif /* __KIS_BRUSHES_PIPE_H */
virtual int currentBrushIndex()=0
QSharedPointer< BrushType > firstBrush() const
QVector< QSharedPointer< BrushType > > m_brushes
void setSpacing(double spacing)
KisBrushesPipe(const KisBrushesPipe &rhs)
QSharedPointer< BrushType > currentBrush(const KisPaintInformation &info)
KisFixedPaintDeviceSP paintDevice(const KoColorSpace *colorSpace, KisDabShape const &shape, const KisPaintInformation &info, double subPixelX, double subPixelY)
virtual void notifyStrokeStarted()=0
QSharedPointer< BrushType > lastBrush() const
virtual void updateBrushIndexes(KisRandomSourceSP randomSource, int seqNo)=0
qint32 maskWidth(KisDabShape const &shape, double subPixelX, double subPixelY, const KisPaintInformation &info)
void notifyBrushIsGoingToBeClonedForStroke()
bool hasColorAndTransparency() const
void setGradient(KoAbstractGradientSP gradient) const
virtual ~KisBrushesPipe()
void addBrush(QSharedPointer< BrushType > brush)
void generateMaskAndApplyMaskOrCreateDab(KisFixedPaintDeviceSP dst, KisBrush::ColoringInformation *coloringInformation, KisDabShape const &shape, const KisPaintInformation &info, double subPixelX, double subPixelY, qreal softnessFactor, qreal lightnessStrength=DEFAULT_LIGHTNESS_STRENGTH)
QVector< QSharedPointer< BrushType > > brushes()
void prepareForSeqNo(const KisPaintInformation &info, int seqNo)
virtual int chooseNextBrush(const KisPaintInformation &info)=0
bool isImageType() const
qint32 maskHeight(KisDabShape const &shape, double subPixelX, double subPixelY, const KisPaintInformation &info)
void setBrushApplication(enumBrushApplication brushApplication) const
void setAngle(qreal angle)
void setScale(qreal scale)
virtual void clear()
void testingSelectNextBrush(const KisPaintInformation &info)
KisRandomSourceSP randomSource() const
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55
static const qreal DEFAULT_LIGHTNESS_STRENGTH
Definition kis_brush.h:46
enumBrushApplication
Definition kis_brush.h:38
KisSharedPtr< KisRandomSource > KisRandomSourceSP
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)