Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
strokemanager.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #ifndef STROKEMANAGER_H
19 #define STROKEMANAGER_H
20 
21 #include <QQueue>
22 #include <QPointF>
23 #include <QList>
24 #include <QPoint>
25 #include <time.h>
26 #include <QTabletEvent>
27 #include <QTimer>
28 #include <QTime>
29 #include "object.h"
30 #include "assert.h"
31 
32 class StrokeManager : public QObject
33 {
34 public:
35  StrokeManager();
36 
37  void tabletEvent(QTabletEvent* event);
38  void mousePressEvent(QMouseEvent* event);
39  void mouseMoveEvent(QMouseEvent* event);
40  void mouseReleaseEvent(QMouseEvent* event);
41  void setPressure(float pressure);
42  void setInpolLevel(int level);
43 
44  float getPressure() { return mTabletPressure; }
45  int getInpolLevel() { return mInpolLevel; }
46  bool isTabletInUse() { return mTabletInUse; }
47 
48  QList<QPointF> interpolateStroke();
49  void interpolatePoll();
50  QPointF interpolateStart(QPointF firstPoint);
51  void interpolatePollAndPaint();
52  void interpolateEnd();
53  void smoothMousePos(QPointF pos);
54  QList<QPointF> meanInpolOp( QList<QPointF> points, qreal x, qreal y, qreal pressure );
55  QList<QPointF> noInpolOp(QList<QPointF> points);
56  QList<QPointF> tangentInpolOp(QList<QPointF> points);
57 
58  QPointF getLastPressPixel() const { return mLastPressPixel; }
59  QPointF getCurrentPixel() const { return mCurrentPixel; }
60  QPointF getLastPixel() const { return mLastPixel; }
61  QPointF getLastMeanPixel() const { return mLastInterpolated; }
62  QPointF getMousePos() const { return mousePos; }
63 
64 private:
65 
66  static const int STROKE_QUEUE_LENGTH = 3; // 4 points for cubic bezier
67 
68  void reset();
69 
70  QPointF getEventPosition(QMouseEvent *);
71 
72  float pressure = 1.0f; // last pressure
73  QQueue<QPointF> strokeQueue;
74  QQueue<qreal> pressureQueue;
75 
76  QTimer timer;
77 
78  QTime mSingleshotTime;
79  QPointF mLastPressPixel2 = { 0, 0 };
80  QPointF mLastPressPixel = { 0, 0 };
81  QPointF mCurrentPixel = { 0, 0 };
82  QPointF mLastPixel = { 0, 0 };
83  QPointF mLastInterpolated = { 0, 0 };
84  QPointF mousePos = { 0, 0 };
85 
86  QPointF m_previousTangent;
87  bool hasTangent = false;
88  int previousTime = 0;
89 
90  bool mStrokeStarted = false;
91 
92  bool mTabletInUse = false;
93  float mTabletPressure = 1.f;
94  int mInpolLevel = 0;
95  QPointF mTabletPosition;
96  qreal mMeanPressure;
97 
98  clock_t m_timeshot;
99 
100 };
101 
102 #endif // STROKEMANAGER_H