Krita Source Code Documentation
Loading...
Searching...
No Matches
KisStabilizerDelayedPaintHelper.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Alvin Wong <alvinhochun-at-gmail-com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9constexpr int fixedPaintTimerInterval = 20;
10
12 : elapsedTime(elapsedTime)
13 , paintInfo(paintInfo)
14{
15}
16
21
23 if (running()) {
24 cancel();
25 }
27 m_paintTimer.start();
28 m_elapsedTimer.start();
31 m_paintQueue.enqueue(TimedPaintInfo(m_lastPendingTime, firstPaintInfo));
32}
33
35 int now = m_elapsedTimer.elapsed();
36 int delayedPaintInterval = m_elapsedTimer.elapsed() - m_lastPendingTime;
37 for (int i = 0; i < newPaintInfos.size(); i++) {
38 // TODO: Risk of overflowing?
39 int offsetTime = (delayedPaintInterval * i) / newPaintInfos.size();
40 m_paintQueue.enqueue(TimedPaintInfo(now + offsetTime, newPaintInfos[i]));
41 }
43}
44
46 // This function is also called from KisToolFreehandHelper::paint
48 if (m_paintQueue.isEmpty()) {
49 return;
50 }
51 int now = m_lastPaintTime;
52 // Always keep one in the queue since painting requires two points
53 while (m_paintQueue.size() > 1 && m_paintQueue.head().elapsedTime <= now) {
54 const TimedPaintInfo dequeued = m_paintQueue.dequeue();
55 m_paintLine(dequeued.paintInfo, m_paintQueue.head().paintInfo);
56 }
57}
58
60 m_paintTimer.stop();
61 m_elapsedTimer.invalidate();
62 if (m_paintQueue.isEmpty()) {
63 return;
64 }
65 TimedPaintInfo dequeued = m_paintQueue.dequeue();
66 while (!m_paintQueue.isEmpty()) {
67 const TimedPaintInfo dequeued2 = m_paintQueue.dequeue();
68 m_paintLine(dequeued.paintInfo, dequeued2.paintInfo);
69 dequeued = dequeued2;
70 }
71}
72
77
80 return;
81 }
82 paintSome();
83 // Explicitly update the outline because this is outside the pointer event
85}
constexpr int fixedPaintTimerInterval
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void update(const QVector< KisPaintInformation > &newPaintInfos)
std::function< void(const KisPaintInformation &, const KisPaintInformation &) m_paintLine)
void start(const KisPaintInformation &firstPaintInfo)
TimedPaintInfo(int elapsedTime, KisPaintInformation paintInfo)