My Project
qpainterpath.h
1 #pragma once
2 
3 #include "qmatrix.h"
4 #include "ParaRect.h"
5 #include "ParaLine.h"
6 #include <list>
7 
8 namespace ParaEngine
9 {
10 
11  class QFont;
12  class QPainterPathData;
13  class QPen;
14  class QPolygonF;
15  class QRegion;
16  class QVectorPath;
17 
19  {
20  public:
21  enum ElementType {
22  MoveToElement,
23  LineToElement,
24  CurveToElement,
25  CurveToDataElement
26  };
27 
28  class Element {
29  public:
30  float x;
31  float y;
32  ElementType type;
33 
34  bool isMoveTo() const { return type == MoveToElement; }
35  bool isLineTo() const { return type == LineToElement; }
36  bool isCurveTo() const { return type == CurveToElement; }
37 
38  operator QPointF () const { return QPointF(x, y); }
39 
40  bool operator==(const Element &e) const {
41  return Math::FuzzyCompare(x, e.x)
42  && Math::FuzzyCompare(y, e.y) && type == e.type;
43  }
44  inline bool operator!=(const Element &e) const { return !operator==(e); }
45  };
46 
47  QPainterPath();
48  explicit QPainterPath(const QPointF &startPoint);
50  QPainterPath &operator=(const QPainterPath &other);
51  ~QPainterPath();
52  void swap(QPainterPath &other);
53 
54  void closeSubpath();
55 
56  void moveTo(const QPointF &p);
57  inline void moveTo(float x, float y);
58 
59  void lineTo(const QPointF &p);
60  inline void lineTo(float x, float y);
61 
62  void arcMoveTo(const QRectF &rect, float angle);
63  inline void arcMoveTo(float x, float y, float w, float h, float angle);
64 
65  void arcTo(const QRectF &rect, float startAngle, float arcLength);
66  inline void arcTo(float x, float y, float w, float h, float startAngle, float arcLength);
67 
68  void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt);
69  inline void cubicTo(float ctrlPt1x, float ctrlPt1y, float ctrlPt2x, float ctrlPt2y,
70  float endPtx, float endPty);
71  void quadTo(const QPointF &ctrlPt, const QPointF &endPt);
72  inline void quadTo(float ctrlPtx, float ctrlPty, float endPtx, float endPty);
73 
74  QPointF currentPosition() const;
75 
76  void addRect(const QRectF &rect);
77  inline void addRect(float x, float y, float w, float h);
78  void addEllipse(const QRectF &rect);
79  inline void addEllipse(float x, float y, float w, float h);
80  inline void addEllipse(const QPointF &center, float rx, float ry);
81  void addPolygon(const QPolygonF &polygon);
82  void addText(const QPointF &point, const QFont &f, const std::string &text);
83  inline void addText(float x, float y, const QFont &f, const std::string &text);
84  void addPath(const QPainterPath &path);
85  void addRegion(const QRegion &region);
86 
87  void addRoundedRect(const QRectF &rect, float xRadius, float yRadius,
88  SizeMode mode = AbsoluteSize);
89  inline void addRoundedRect(float x, float y, float w, float h,
90  float xRadius, float yRadius,
91  SizeMode mode = AbsoluteSize);
92 
93  void addRoundRect(const QRectF &rect, int xRnd, int yRnd);
94  inline void addRoundRect(float x, float y, float w, float h,
95  int xRnd, int yRnd);
96  inline void addRoundRect(const QRectF &rect, int roundness);
97  inline void addRoundRect(float x, float y, float w, float h,
98  int roundness);
99 
100  void connectPath(const QPainterPath &path);
101 
102  bool contains(const QPointF &pt) const;
103  bool contains(const QRectF &rect) const;
104  bool intersects(const QRectF &rect) const;
105 
106  void translate(float dx, float dy);
107  inline void translate(const QPointF &offset);
108 
109  QPainterPath translated(float dx, float dy) const;
110  inline QPainterPath translated(const QPointF &offset) const;
111 
112  QRectF boundingRect() const;
113  QRectF controlPointRect() const;
114 
115  FillRule fillRule() const;
116  void setFillRule(FillRule fillRule);
117 
118  bool isEmpty() const;
119 
120  QPainterPath toReversed() const;
121  std::list<QPolygonF> toSubpathPolygons(const QMatrix &matrix = QMatrix()) const;
122  std::list<QPolygonF> toFillPolygons(const QMatrix &matrix = QMatrix()) const;
123  QPolygonF toFillPolygon(const QMatrix &matrix = QMatrix()) const;
124  std::list<QPolygonF> toSubpathPolygons(const QTransform &matrix) const;
125  std::list<QPolygonF> toFillPolygons(const QTransform &matrix) const;
126  QPolygonF toFillPolygon(const QTransform &matrix) const;
127 
128  int elementCount() const;
129  QPainterPath::Element elementAt(int i) const;
130  void setElementPositionAt(int i, float x, float y);
131 
132  float length() const;
133  float percentAtLength(float t) const;
134  QPointF pointAtPercent(float t) const;
135  float angleAtPercent(float t) const;
136  float slopeAtPercent(float t) const;
137 
138  bool intersects(const QPainterPath &p) const;
139  bool contains(const QPainterPath &p) const;
140  QPainterPath united(const QPainterPath &r) const;
141  QPainterPath intersected(const QPainterPath &r) const;
142  QPainterPath subtracted(const QPainterPath &r) const;
143  QPainterPath subtractedInverted(const QPainterPath &r) const;
144 
145  QPainterPath simplified() const;
146 
147  bool operator==(const QPainterPath &other) const;
148  bool operator!=(const QPainterPath &other) const;
149 
150  QPainterPath operator&(const QPainterPath &other) const;
151  QPainterPath operator|(const QPainterPath &other) const;
152  QPainterPath operator+(const QPainterPath &other) const;
153  QPainterPath operator-(const QPainterPath &other) const;
154  QPainterPath &operator&=(const QPainterPath &other);
155  QPainterPath &operator|=(const QPainterPath &other);
156  QPainterPath &operator+=(const QPainterPath &other);
157  QPainterPath &operator-=(const QPainterPath &other);
158 
159  const QVectorPath & vectorPath() const;
160  private:
161  void setDirty(bool);
162  void computeBoundingRect() const;
163  void computeControlPointRect() const;
164 
165  friend class QMatrix;
166  friend class QTransform;
167  };
168 
170  {
171  public:
173  explicit QPainterPathStroker(const QPen &pen);
175 
176  void setWidth(float width);
177  float width() const;
178 
179  QPainterPath createStroke(const QPainterPath &path) const;
180  };
181 
182  inline void QPainterPath::moveTo(float x, float y)
183  {
184  moveTo(QPointF(x, y));
185  }
186 
187  inline void QPainterPath::lineTo(float x, float y)
188  {
189  lineTo(QPointF(x, y));
190  }
191 
192  inline void QPainterPath::arcTo(float x, float y, float w, float h, float startAngle, float arcLength)
193  {
194  arcTo(QRectF(x, y, w, h), startAngle, arcLength);
195  }
196 
197  inline void QPainterPath::arcMoveTo(float x, float y, float w, float h, float angle)
198  {
199  arcMoveTo(QRectF(x, y, w, h), angle);
200  }
201 
202  inline void QPainterPath::cubicTo(float ctrlPt1x, float ctrlPt1y, float ctrlPt2x, float ctrlPt2y,
203  float endPtx, float endPty)
204  {
205  cubicTo(QPointF(ctrlPt1x, ctrlPt1y), QPointF(ctrlPt2x, ctrlPt2y),
206  QPointF(endPtx, endPty));
207  }
208 
209  inline void QPainterPath::quadTo(float ctrlPtx, float ctrlPty, float endPtx, float endPty)
210  {
211  quadTo(QPointF(ctrlPtx, ctrlPty), QPointF(endPtx, endPty));
212  }
213 
214  inline void QPainterPath::addEllipse(float x, float y, float w, float h)
215  {
216  addEllipse(QRectF(x, y, w, h));
217  }
218 
219  inline void QPainterPath::addEllipse(const QPointF &center, float rx, float ry)
220  {
221  addEllipse(QRectF(center.x() - rx, center.y() - ry, 2 * rx, 2 * ry));
222  }
223 
224  inline void QPainterPath::addRect(float x, float y, float w, float h)
225  {
226  addRect(QRectF(x, y, w, h));
227  }
228 
229  inline void QPainterPath::addRoundedRect(float x, float y, float w, float h,
230  float xRadius, float yRadius,
231  SizeMode mode)
232  {
233  addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode);
234  }
235 
236  inline void QPainterPath::addRoundRect(float x, float y, float w, float h,
237  int xRnd, int yRnd)
238  {
239  addRoundRect(QRectF(x, y, w, h), xRnd, yRnd);
240  }
241 
242  inline void QPainterPath::addRoundRect(const QRectF &rect,
243  int roundness)
244  {
245  int xRnd = roundness;
246  int yRnd = roundness;
247  if (rect.width() > rect.height())
248  xRnd = int(roundness * rect.height() / rect.width());
249  else
250  yRnd = int(roundness * rect.width() / rect.height());
251  addRoundRect(rect, xRnd, yRnd);
252  }
253 
254  inline void QPainterPath::addRoundRect(float x, float y, float w, float h,
255  int roundness)
256  {
257  addRoundRect(QRectF(x, y, w, h), roundness);
258  }
259 
260  inline void QPainterPath::addText(float x, float y, const QFont &f, const std::string &text)
261  {
262  addText(QPointF(x, y), f, text);
263  }
264 
265  inline void QPainterPath::translate(const QPointF &offset)
266  {
267  translate(offset.x(), offset.y());
268  }
269 
270  inline QPainterPath QPainterPath::translated(const QPointF &offset) const
271  {
272  return translated(offset.x(), offset.y());
273  }
274 }
The QPen class defines how a CPainter should draw lines and outlines of shapes.
Definition: qpen.h:13
Definition: ParaPoint.h:203
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ParaRect.h:517
Definition: qfont.h:8
Definition: other.hpp:41
Definition: qpainterpath.h:28
Definition: qtransform.h:14
Definition: qpainterpath.h:169
Definition: qvectorpath.h:17
Definition: qpolygon.h:87
Definition: ParaRegion.h:7
Definition: qmatrix.h:12
Definition: qpainterpath.h:18