Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
vectorimage.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 #ifndef VECTORIMAGE_H
18 #define VECTORIMAGE_H
19 
20 
21 #include <QtXml>
22 #include <QTransform>
23 #include <QDebug>
24 #include <QImage>
25 #include <QStringList>
26 
27 #include "bezierarea.h"
28 #include "beziercurve.h"
29 #include "vertexref.h"
30 #include "keyframe.h"
31 
32 class Object;
33 class QPainter;
34 
35 class VectorImage : public KeyFrame
36 {
37 public:
38  VectorImage();
39  virtual ~VectorImage();
40 
41  void setObject( Object* pObj ) { mObject = pObj; }
42 
43  bool read(QString filePath);
44  Status write(QString filePath, QString format);
45 
46  Status createDomElement(QXmlStreamWriter& doc);
47  void loadDomElement(QDomElement element);
48 
49  void insertCurve(int position, BezierCurve& newCurve, qreal factor, bool interacts);
50  void addCurve(BezierCurve& newCurve, qreal factor, bool interacts = true);
51  void removeCurveAt(int i);
52  void select(QRectF rectangle);
53  void setSelected(int curveNumber, bool YesOrNo);
54  void setSelected(int curveNumber, int vertexNumber, bool YesOrNo);
55  void setSelected(VertexRef vertexRef, bool YesOrNo);
56  void setSelected(QList<int> curveList, bool YesOrNo);
57  void setSelected(QList<VertexRef> vertexList, bool YesOrNo);
58  bool isSelected(int curveNumber);
59  bool isSelected(int curveNumber, int vertexNumber);
60  bool isSelected(VertexRef vertexRef);
61  bool isSelected(QList<int> curveList);
62  bool isSelected(QList<VertexRef> vertexList);
63  void setAreaSelected(int areaNumber, bool YesOrNo);
64  bool isAreaSelected(int areaNumber);
65 
66  int getFirstSelectedCurve();
67  int getFirstSelectedArea();
68  void selectAll();
69  void deselectAll();
70  QRectF getSelectionRect() { return mSelectionRect; }
71  void setSelectionRect(QRectF rectange);
72  void calculateSelectionRect();
73  void deleteSelection();
74  void deleteSelectedPoints();
75  void removeVertex(int i, int m);
76 
77  void paste(VectorImage&);
78 
79  QColor getColour(int i);
80  int getColourNumber(QPointF point);
81  bool usesColour(int index);
82  void removeColour(int index);
83 
84  void paintImage(QPainter& painter, bool simplified, bool showThinCurves, bool antialiasing);
85  void outputImage(QImage* image, QTransform myView, bool simplified, bool showThinCurves, bool antialiasing); // uses paintImage
86 
87  void clear();
88  void clean();
89  void setSelectionTransformation(QTransform transform);
90  void applySelectionTransformation();
91  void applySelectionTransformation(QTransform transform);
92  void applyColourToSelection(int colourNumber);
93  void applyWidthToSelection(qreal width);
94  void applyFeatherToSelection(qreal feather);
95  void applyOpacityToSelection(qreal opacity);
96  void applyInvisibilityToSelection(bool YesOrNo);
97  void applyVariableWidthToSelection(bool YesOrNo);
98  void fillPath(QList<QPointF> contourPath, int colour, float tolerance);
99  void fill(QPointF point, int colour, float tolerance);
100  void addArea(BezierArea bezierArea);
101  int getFirstAreaNumber(QPointF point);
102  int getLastAreaNumber(QPointF point);
103  int getLastAreaNumber(QPointF point, int maxAreaNumber);
104  void removeArea(QPointF point);
105  void updateArea(BezierArea& bezierArea);
106 
107  QList<int> getCurvesCloseTo(QPointF thisPoint, qreal maxDistance);
108  VertexRef getClosestVertexTo(QPointF thisPoint, qreal maxDistance);
109  QList<VertexRef> getCurveVertices(int curveNumber);
110  QList<VertexRef> getVerticesCloseTo(QPointF thisPoint, qreal maxDistance);
111  QList<VertexRef> getVerticesCloseTo(QPointF thisPoint, qreal maxDistance, QList<VertexRef>* listOfPoints);
112  QList<VertexRef> getVerticesCloseTo(VertexRef thisPointRef, qreal maxDistance);
113  QList<VertexRef> getVerticesCloseTo(VertexRef thisPointRef, qreal maxDistance, QList<VertexRef>* listOfPoints);
114  QList<VertexRef> getAndRemoveVerticesCloseTo(QPointF thisPoint, qreal maxDistance, QList<VertexRef>* listOfPoints);
115  QList<VertexRef> getAndRemoveVerticesCloseTo(VertexRef thisPointRef, qreal maxDistance, QList<VertexRef>* listOfPoints);
116  QPointF getVertex(int curveNumber, int vertexNumber);
117  QPointF getVertex(VertexRef vertexRef);
118  QPointF getC1(int curveNumber, int vertexNumber);
119  QPointF getC1(VertexRef vertexRef);
120  QPointF getC2(int curveNumber, int vertexNumber);
121  QPointF getC2(VertexRef vertexRef);
122  QList<VertexRef> getAllVertices();
123  int getCurveSize(int curveNumber);
124 
125  QList<BezierCurve> m_curves;
126  QList<BezierArea> area;
127  QList<int> m_curveDisplayOrders;
128 
129  qreal getDistance(VertexRef r1, VertexRef r2);
130 
131  QSize getSize() {return mSize;}
132 
133 private:
134  void addPoint( int curveNumber, int vertexNumber, qreal t );
135 
136  void checkCurveExtremity(BezierCurve& newCurve, qreal tolerance);
137  void checkCurveIntersections(BezierCurve& newCurve, qreal tolerance);
138 
139  QList<QPointF> getfillContourPoints(QPoint point);
140  void updateImageSize(BezierCurve& updatedCurve);
141 
142 private:
143  Object* mObject = nullptr;
144  QRectF mSelectionRect;
145  QTransform mSelectionTransformation;
146  QSize mSize;
147 };
148 
149 #endif
150 
Definition: object.h:71