Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPaintOpUtils::PositionHistory Class Reference

#include <kis_paintop_utils.h>

Public Member Functions

QPointF pushThroughHistory (const QPointF &pt, qreal zoom)
 
void reset (const QPointF &pt)
 

Private Attributes

QPointF m_first
 
QPointF m_second
 

Detailed Description

A special class containing the previous position of the cursor for the sake of painting the outline of the paint op. The main purpose of this class is to ensure that the saved point does not equal to the current one, which would cause a outline flicker. To achieve this the class stores two previously requested points instead of the last one.

Definition at line 113 of file kis_paintop_utils.h.

Member Function Documentation

◆ pushThroughHistory()

QPointF KisPaintOpUtils::PositionHistory::pushThroughHistory ( const QPointF & pt,
qreal zoom )
inline
Returns
the previously used point, which is guaranteed not to be equal to pt and updates the history if needed

We use per-axis distance to avoid artifacts when using devices that send events in a staircase way.

Ideally, we should make the transition from m_first to m_second smooth, but simple blending via 'coeff' doesn't work for some reason.

Definition at line 120 of file kis_paintop_utils.h.

120 {
121 QPointF result;
122 const qreal pointSwapThreshold = 7.0 / zoom;
123
128 const qreal distance = qMin(qAbs(pt.x() - m_second.x()), qAbs(pt.y() - m_second.y()));
129 const qreal coeff = qMin(1.0, distance / pointSwapThreshold);
130
131 if (coeff > 1.0 - std::numeric_limits<qreal>::epsilon()) {
132 result = m_second;
134 m_second = pt;
135 } else {
140 result = m_first;
141 }
142
143 return result;
144 }
qreal distance(const QPointF &p1, const QPointF &p2)
QAction * zoom(const QObject *recvr, const char *slot, QObject *parent)

References distance().

◆ reset()

void KisPaintOpUtils::PositionHistory::reset ( const QPointF & pt)
inline

Definition at line 146 of file kis_paintop_utils.h.

147 {
148 m_first = pt;
149 m_second = pt;
150 }

Member Data Documentation

◆ m_first

QPointF KisPaintOpUtils::PositionHistory::m_first
private

Definition at line 153 of file kis_paintop_utils.h.

◆ m_second

QPointF KisPaintOpUtils::PositionHistory::m_second
private

Definition at line 154 of file kis_paintop_utils.h.


The documentation for this class was generated from the following file: