Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • tool
strokeinterpolator.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#ifndef STROKEINTERPOLATOR_H
19#define STROKEINTERPOLATOR_H
20
21#include <QQueue>
22#include <QPointF>
23#include <QList>
24#include <QTimer>
25
26
27class PointerEvent;
28
29class StrokeInterpolator : public QObject
30{
31public:
32 StrokeInterpolator();
33
34 void pointerPressEvent(PointerEvent* event);
35 void pointerMoveEvent(PointerEvent* event);
36 void pointerReleaseEvent(PointerEvent* event);
37 void setPressure(float pressure);
38 void setStabilizerLevel(int level);
39
40 float getPressure() { return mTabletPressure; }
41 int getStabilizerLevel() { return mStabilizerLevel; }
42 bool isActive() const { return mStrokeStarted; }
43
44 QList<QPointF> interpolateStroke();
45 void interpolatePoll();
46 QPointF interpolateStart(QPointF firstPoint);
47 void interpolatePollAndPaint();
48 void interpolateEnd();
49 void smoothMousePos(QPointF pos);
50 QList<QPointF> meanInpolOp(QList<QPointF> points, qreal x, qreal y, qreal pressure);
51 QList<QPointF> noInpolOp(QList<QPointF> points);
52 QList<QPointF> tangentInpolOp(QList<QPointF> points);
53
54 QPointF getCurrentPixel() const { return mCurrentPixel; }
55 QPointF getLastPixel() const { return mLastPixel; }
56 QPointF getLastMeanPixel() const { return mLastInterpolated; }
57 QPointF getCurrentPressPixel() const { return mCurrentPressPixel; }
58
59private:
60 static const int STROKE_QUEUE_LENGTH = 3; // 4 points for cubic bezier
61
62 void reset();
63
64 float pressure = 1.0f; // last pressure
65 QQueue<QPointF> strokeQueue;
66 QQueue<qreal> pressureQueue;
67
68 QTimer timer;
69
70 QPointF mCurrentPressPixel = { 0, 0 };
71 QPointF mCurrentPixel = { 0, 0 };
72 QPointF mLastPixel = { 0, 0 };
73 QPointF mLastInterpolated = { 0, 0 };
74
75 QPointF m_previousTangent;
76 bool mHasTangent = false;
77 bool mStrokeStarted = false;
78 bool mTabletInUse = false;
79 float mTabletPressure = 1.f;
80 int mStabilizerLevel = 0;
81};
82
83#endif // STROKEINTERPOLATOR_H
PointerEvent
Definition: pointerevent.h:8
StrokeInterpolator
Definition: strokeinterpolator.h:30
QList
QObject
QObject::event
virtual bool event(QEvent *e)
QPointF
QQueue
QTimer
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39