My Project
qvectorpath.h
1 #pragma once
2 #include "Painter.h"
3 #include "ParaRect.h"
4 #include "PaintEngine.h"
5 #include "qpainterpath.h"
6 
7 namespace ParaEngine
8 {
9  class CPaintEngine;
10 
11  struct QRealRect {
12  float x1, y1, x2, y2;
13  };
14 
15  typedef void(*qvectorpath_cache_cleanup)(CPaintEngine *engine, void *data);
16 
18  {
19  public:
20  enum Hint {
21  // Shape hints, in 0x000000ff, access using shape()
22  AreaShapeMask = 0x0001, // shape covers an area
23  NonConvexShapeMask = 0x0002, // shape is not convex
24  CurvedShapeMask = 0x0004, // shape contains curves...
25  LinesShapeMask = 0x0008,
26  RectangleShapeMask = 0x0010,
27  ShapeMask = 0x001f,
28 
29  // Shape hints merged into basic shapes..
30  LinesHint = LinesShapeMask,
31  RectangleHint = AreaShapeMask | RectangleShapeMask,
32  EllipseHint = AreaShapeMask | CurvedShapeMask,
33  ConvexPolygonHint = AreaShapeMask,
34  PolygonHint = AreaShapeMask | NonConvexShapeMask,
35  RoundedRectHint = AreaShapeMask | CurvedShapeMask,
36  ArbitraryShapeHint = AreaShapeMask | NonConvexShapeMask | CurvedShapeMask,
37 
38  // Other hints
39  IsCachedHint = 0x0100, // Set if the cache hint is set
40  ShouldUseCacheHint = 0x0200, // Set if the path should be cached when possible..
41  ControlPointRect = 0x0400, // Set if the control point rect has been calculated...
42 
43  // Shape rendering specifiers...
44  OddEvenFill = 0x1000,
45  WindingFill = 0x2000,
46  ImplicitClose = 0x4000
47  };
48 
49  QVectorPath(const float *points, int count, const QPainterPath::ElementType *elements = 0, uint32 hints = ArbitraryShapeHint);
50  ~QVectorPath();
51 
52  QRectF controlPointRect() const;
53 
54  inline Hint shape() const { return (Hint)(m_hints & ShapeMask); }
55  inline bool isConvex() const { return (m_hints & NonConvexShapeMask) == 0; }
56  inline bool isCurved() const { return (m_hints & CurvedShapeMask)!=0; }
57 
58  inline bool isCacheable() const { return (m_hints & ShouldUseCacheHint) != 0; }
59  inline bool hasImplicitClose() const { return (m_hints & ImplicitClose) != 0; }
60  inline bool hasWindingFill() const { return (m_hints & WindingFill) != 0; }
61 
62  inline void makeCacheable() const { m_hints |= ShouldUseCacheHint; m_cache = 0; }
63  inline uint32 hints() const { return m_hints; }
64 
65  inline const QPainterPath::ElementType *elements() const { return m_elements; }
66  inline const float *points() const { return m_points; }
67  inline bool isEmpty() const { return m_points == 0; }
68 
69  inline int elementCount() const { return m_count; }
70  inline const QPainterPath convertToPainterPath() const;
71 
72  static inline uint32 polygonFlags(CPaintEngine::PolygonDrawMode mode)
73  {
74  switch (mode) {
75  case CPaintEngine::ConvexMode: return ConvexPolygonHint | ImplicitClose;
76  case CPaintEngine::OddEvenMode: return PolygonHint | OddEvenFill | ImplicitClose;
77  case CPaintEngine::WindingMode: return PolygonHint | WindingFill | ImplicitClose;
78  case CPaintEngine::PolylineMode: return PolygonHint;
79  default: return 0;
80  }
81  }
82 
83  struct CacheEntry {
84  CPaintEngine *engine;
85  void *data;
86  qvectorpath_cache_cleanup cleanup;
87  CacheEntry *next;
88  };
89 
90  CacheEntry *addCacheData(CPaintEngine *engine, void *data, qvectorpath_cache_cleanup cleanup) const;
91  inline CacheEntry *lookupCacheData(CPaintEngine *engine) const {
92  PE_ASSERT(m_hints & ShouldUseCacheHint);
93  CacheEntry *e = m_cache;
94  while (e) {
95  if (e->engine == engine)
96  return e;
97  e = e->next;
98  }
99  return 0;
100  }
101 
102  template <typename T> static inline bool isRect(const T *pts, int elementCount) {
103  return (elementCount == 5 // 5-point polygon, check for closed rect
104  && pts[0] == pts[8] && pts[1] == pts[9] // last point == first point
105  && pts[0] == pts[6] && pts[2] == pts[4] // x values equal
106  && pts[1] == pts[3] && pts[5] == pts[7] // y values equal...
107  && pts[0] < pts[4] && pts[1] < pts[5]
108  ) ||
109  (elementCount == 4 // 4-point polygon, check for unclosed rect
110  && pts[0] == pts[6] && pts[2] == pts[4] // x values equal
111  && pts[1] == pts[3] && pts[5] == pts[7] // y values equal...
112  && pts[0] < pts[4] && pts[1] < pts[5]
113  );
114  }
115 
116  inline bool isRect() const
117  {
118  const QPainterPath::ElementType * const types = elements();
119 
120  return (shape() == QVectorPath::RectangleHint)
121  || (isRect(points(), elementCount())
122  && (!types || (types[0] == QPainterPath::MoveToElement
123  && types[1] == QPainterPath::LineToElement
124  && types[2] == QPainterPath::LineToElement
125  && types[3] == QPainterPath::LineToElement)));
126  }
127 
128 
129  private:
130  const QPainterPath::ElementType *m_elements;
131  const float *m_points;
132  const int m_count;
133 
134  mutable uint32 m_hints;
135  mutable QRealRect m_cp_rect;
136 
137  mutable CacheEntry *m_cache;
138  };
139 
140  const QVectorPath &qtVectorPathForPath(const QPainterPath &path);
141 }
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ParaRect.h:517
Definition: qvectorpath.h:11
Definition: qvectorpath.h:83
The CPaintEngine class provides an abstract definition of how CPainter draws to a given device on a g...
Definition: PaintEngine.h:34
Definition: qvectorpath.h:17
Definition: qpainterpath.h:18