Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_paint_information.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7#ifndef _KIS_PAINT_INFORMATION_
8#define _KIS_PAINT_INFORMATION_
9
10#include <kis_debug.h>
11#include <QTime>
12
13#include "kis_global.h"
14#include "kritaimage_export.h"
16#include "kis_random_source.h"
20
21
22class QDomDocument;
23class QDomElement;
25
26
50class KRITAIMAGE_EXPORT KisPaintInformation
51{
52public:
68
69public:
70
74 KisPaintInformation(const QPointF & pos,
75 qreal pressure,
76 qreal xTilt,
77 qreal yTilt,
78 qreal rotation,
79 qreal tangentialPressure,
80 qreal perspective,
81 qreal time,
82 qreal speed);
83
84 KisPaintInformation(const QPointF & pos,
85 qreal pressure,
86 qreal xTilt,
87 qreal yTilt,
88 qreal rotation);
89
90 KisPaintInformation(const QPointF & pos = QPointF(),
91 qreal pressure = PRESSURE_DEFAULT);
92
94
95 void operator=(const KisPaintInformation& rhs);
96
98
99 template <class PaintOp>
100 void paintAt(PaintOp &op, KisDistanceInformation *distanceInfo) {
101 KisSpacingInformation spacingInfo;
102 KisTimingInformation timingInfo;
103 {
104 DistanceInformationRegistrar r = registerDistanceInformation(distanceInfo);
105 spacingInfo = op.paintAt(*this);
106 timingInfo = op.updateTimingImpl(*this);
107
108 // Initiate the process of locking the drawing angle. The locked value will
109 // always be present in the internals, but it will be requested but the users
110 // with a special parameter of drawingAngle() only.
111 if (!this->isHoveringMode()) {
112 distanceInfo->lockCurrentDrawingAngle(*this);
113 }
114 }
115
116 distanceInfo->registerPaintedDab(*this, spacingInfo, timingInfo);
117 }
118
119 const QPointF& pos() const;
120 void setPos(const QPointF& p);
121
123 qreal pressure() const;
124
126 void setPressure(qreal p);
127
129 qreal xTilt() const;
130
132 qreal yTilt() const;
133
135 void overrideDrawingAngle(qreal angle);
136
138 qreal drawingAngleSafe(const KisDistanceInformation &distance) const;
139
147 DistanceInformationRegistrar registerDistanceInformation(KisDistanceInformation *distance);
148
155 qreal drawingAngle(bool considerLockedAngle = false) const;
156
163 QPointF drawingDirectionVector() const;
164
171 qreal drawingSpeed() const;
172
179 qreal drawingDistance() const;
180
187 qreal maxPressure() const;
188
190 qreal rotation() const;
191
193 qreal tangentialPressure() const;
194
196 qreal perspective() const;
197
199 qreal currentTime() const;
200 void setCurrentTime(qreal time) const;
201
203 int currentDabSeqNo() const;
204
206 qreal totalStrokeLength() const;
207
208 // random source for generating in-stroke effects
209 KisRandomSourceSP randomSource() const;
210
211 // the stroke should initialize random source of all the used
212 // paint info objects, otherwise it shows a warning
213 void setRandomSource(KisRandomSourceSP value);
214
215 // random source for generating in-stroke effects, generates one(!) value per stroke
216 KisPerStrokeRandomSourceSP perStrokeRandomSource() const;
217
218 // the stroke should initialize per stroke random source of all the used
219 // paint info objects, otherwise it shows a warning
220 void setPerStrokeRandomSource(KisPerStrokeRandomSourceSP value);
221
222 // set level of detail which info object has been generated for
223 void setLevelOfDetail(int levelOfDetail);
224
238 bool isHoveringMode() const;
239
246 static KisPaintInformation createHoveringModeInfo(const QPointF &pos,
247 qreal pressure = PRESSURE_DEFAULT,
248 qreal xTilt = 0.0, qreal yTilt = 0.0,
249 qreal rotation = 0.0,
250 qreal tangentialPressure = 0.0,
251 qreal perspective = 1.0,
252 qreal speed = 0.0,
253 qreal canvasrotation = 0.0,
254 bool canvasMirroredH = false,
255 bool canvasMirroredV = false,
256 qreal tiltDirectionOffset = 0.0);
257
261 qreal canvasRotation() const;
262
266 void setCanvasRotation(qreal rotation);
267
271 bool canvasMirroredH() const;
272
276 void setCanvasMirroredH(bool value);
277
281 bool canvasMirroredV() const;
282
286 void setCanvasMirroredV(bool value);
287
291 qreal tiltDirectionOffset() const;
292
296 void setTiltDirectionOffset(qreal angle);
297
298 void toXML(QDomDocument&, QDomElement&) const;
299
300 static KisPaintInformation fromXML(const QDomElement&);
301
302 // TODO: Refactor the static mix functions to non-static in-place mutation
303 // versions like mixOtherOnlyPosition and mixOtherWithoutTime.
304 // Heap allocation on Windows is awfully slow and will fragment the memory
305 // badly. Since KisPaintInformation allocates on the heap, we should reuse
306 // existing instance whenever possible, especially in loops.
307 // Ref: https://phabricator.kde.org/D6578
308
310 static KisPaintInformation mixOnlyPosition(qreal t, const KisPaintInformation& mixedPi, const KisPaintInformation& basePi);
311 static KisPaintInformation mix(const QPointF& p, qreal t, const KisPaintInformation& p1, const KisPaintInformation& p2);
312 static KisPaintInformation mix(qreal t, const KisPaintInformation& pi1, const KisPaintInformation& pi2);
313 static KisPaintInformation mixWithoutTime(const QPointF &p, qreal t, const KisPaintInformation &p1, const KisPaintInformation &p2);
314 static KisPaintInformation mixWithoutTime(qreal t, const KisPaintInformation &pi1, const KisPaintInformation &pi2);
315 void mixOtherOnlyPosition(qreal t, const KisPaintInformation& other);
316 void mixOtherWithoutTime(qreal t, const KisPaintInformation& other);
317 static qreal tiltDirection(const KisPaintInformation& info, bool normalize = true);
318 static qreal tiltElevation(const KisPaintInformation& info, qreal maxTiltX = 60.0, qreal maxTiltY = 60.0, bool normalize = true);
319
320private:
321 static KisPaintInformation mixImpl(const QPointF &p, qreal t, const KisPaintInformation &p1, const KisPaintInformation &p2, bool posOnly, bool mixTime);
322 void mixOtherImpl(const QPointF &p, qreal t, const KisPaintInformation &other, bool posOnly, bool mixTime);
323
324private:
325 struct Private;
326 Private* const d;
327};
328
329KRITAIMAGE_EXPORT QDebug operator<<(QDebug debug, const KisPaintInformation& info);
330
331
332#endif
float value(const T *src, size_t ch)
const Params2D p
QPointF p2
QPointF p1
qreal distance(const QPointF &p1, const QPointF &p2)
DistanceInformationRegistrar(const DistanceInformationRegistrar &rhs)=delete
void paintAt(PaintOp &op, KisDistanceInformation *distanceInfo)
const double PRESSURE_DEFAULT
Definition kis_global.h:99
KRITAIMAGE_EXPORT QDebug operator<<(QDebug debug, const KisPaintInformation &info)
void lockCurrentDrawingAngle(const KisPaintInformation &info) const
void registerPaintedDab(const KisPaintInformation &info, const KisSpacingInformation &spacing, const KisTimingInformation &timing)