Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_pipebrush_parasite.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2005 Bart Coppens <kde@bartcoppens.be>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
8
9#include <KisPortingUtils.h>
10
12{
13 init();
14 needsMovement = false;
15
16 const QList<QStringView> parasites = source.split(QLatin1Char(' '), Qt::SkipEmptyParts);
17
18 for (int i = 0; i < parasites.count(); i++) {
19 const QList<QStringView> split = parasites.at(i).split(QLatin1Char(':'), Qt::SkipEmptyParts);
20
21 if (split.count() != 2) {
22 warnImage << "Wrong count for this parasite key/value:" << parasites.at(i);
23 continue;
24 }
25 const QStringView &index = split.at(0);
26 if (index == QLatin1String("dim")) {
27 dim = (split.at(1)).toInt();
29 dim = 1;
30 }
31 } else if (index.startsWith(QLatin1String("sel"))) {
32 int selIndex = index.mid(strlen("sel")).toInt();
33
34 if (selIndex >= 0 && selIndex < dim) {
35 selectionMode = split.at(1).toString();
36
37 if (selectionMode == QLatin1String("incremental")) {
39 } else if (selectionMode == QLatin1String("angular")) {
41 needsMovement = true;
42 } else if (selectionMode == QLatin1String("random")) {
44 } else if (selectionMode == QLatin1String("pressure")) {
46 } else if (selectionMode == QLatin1String("xtilt")) {
48 } else if (selectionMode == QLatin1String("ytilt")) {
50 } else if (selectionMode == QLatin1String("velocity")) {
52 } else {
54 }
55 }
56 else {
57 warnImage << "Sel: wrong index: " << selIndex << "(dim = " << dim << ")";
58 }
59 } else if (index.startsWith(QLatin1String("rank"))) {
60 int rankIndex = index.mid(strlen("rank")).toInt();
62 warnImage << "Rankindex out of range: " << rankIndex;
63 continue;
64 }
65 rank[rankIndex] = (split.at(1)).toInt();
66 } else if (index == QLatin1String("ncells")) {
67 ncells = (split.at(1)).toInt();
68 if (ncells < 1) {
69 warnImage << "ncells out of range: " << ncells;
70 ncells = 1;
71 }
72 }
73 }
74
75 for (int i = 0; i < dim; i++) {
76 index[i] = 0;
77 }
78
80}
81
83{
84 for (int i = 0; i < MaxDim; i++) {
85 rank[i] = index[i] = brushesCount[i] = 0;
87 }
88}
89
91{
92 for (int i = 0; i < dim; i++) {
93 // In the 2 listed cases, we'd divide by 0!
94 if (rank[i] == 0 &&
97
98 warnImage << "PIPE brush has a wrong rank for its selection mode!";
100 }
101 }
102}
103
105{
106 // I assume ncells is correct. If it isn't, complain to the parasite header.
107 if (rank[0] != 0) {
108 brushesCount[0] = ncells / rank[0];
109 }
110 else {
111 brushesCount[0] = ncells;
112 }
113
114 for (int i = 1; i < dim; i++) {
115 if (rank[i] == 0) {
116 brushesCount[i] = brushesCount[i - 1];
117 }
118 else {
119 brushesCount[i] = brushesCount[i - 1] / rank[i];
120 }
121 }
122}
123
124bool KisPipeBrushParasite::saveToDevice(QIODevice* dev) const
125{
126 // write out something like
127 // <count> ncells:<count> dim:<dim> rank0:<rank0> sel0:<sel0> <...>
128
129 QTextStream stream(dev);
131
132 // XXX: FIXME things like step, placement and so are not added (nor loaded, as a matter of fact)"
133 stream << ncells << " ncells:" << ncells << " dim:" << dim;
134
135 for (int i = 0; i < dim; i++) {
136 stream << " rank" << i << ":" << rank[i] << " sel" << i << ":";
137 switch (selection[i]) {
139 stream << "constant"; break;
141 stream << "incremental"; break;
143 stream << "angular"; break;
145 stream << "velocity"; break;
147 stream << "random"; break;
149 stream << "pressure"; break;
151 stream << "xtilt"; break;
153 stream << "ytilt"; break;
154 }
155 }
156
157 return true;
158}
159
160bool loadFromDevice(QIODevice */*dev*/)
161{
162 // XXX: implement...
163 return true;
164}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
KisPipeBrushParasite()
Set some default values.
KisParasite::SelectionMode selection[MaxDim]
bool saveToDevice(QIODevice *dev) const
void setBrushesCount()
Initializes the brushesCount helper.
bool needsMovement
If true, the brush won't be painted when there is no motion.
qint32 brushesCount[MaxDim]
The total count of brushes in each dimension (helper)
qint32 index[MaxDim]
The current index in each dimension, so that the selection modes know where to start.
#define warnImage
Definition kis_debug.h:88
bool loadFromDevice(QIODevice *)
void setUtf8OnStream(QTextStream &stream)