src/gui/painting/qvectorpath_p.h
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    64 
    64 
    65 QT_BEGIN_NAMESPACE
    65 QT_BEGIN_NAMESPACE
    66 
    66 
    67 QT_MODULE(Gui)
    67 QT_MODULE(Gui)
    68 
    68 
       
    69 class QPaintEngineEx;
    69 
    70 
    70 #define QVECTORPATH_NO_CACHE
    71 typedef void (*qvectorpath_cache_cleanup)(QPaintEngineEx *engine, void *data);
    71 
    72 
    72 struct QRealRect {
    73 struct QRealRect {
    73     qreal x1, y1, x2, y2;
    74     qreal x1, y1, x2, y2;
    74 };
    75 };
    75 
    76 
    76 class Q_GUI_EXPORT QVectorPath
    77 class Q_GUI_EXPORT QVectorPath
    77 {
    78 {
    78 public:
    79 public:
    79     enum Hint {
    80     enum Hint {
    80         // Basic shapes...
    81         // Shape hints, in 0x000000ff, access using shape()
    81         LinesHint               = 0x0001, // Just plain lines...
    82         AreaShapeMask           = 0x0001,       // shape covers an area
    82         RectangleHint           = 0x0002,
    83         NonConvexShapeMask      = 0x0002,       // shape is not convex
    83         ConvexPolygonHint       = 0x0003, // Convex polygon...
    84         CurvedShapeMask         = 0x0004,       // shape contains curves...
    84         NonISectPolygonHint     = 0x0004, // concave polygon, but not intersecting..
    85         LinesShapeMask          = 0x0008,
    85         NonCurvedShapeHint      = 0x0005, // Generic polygon, possibly self-intersecting...
    86         RectangleShapeMask      = 0x0010,
    86         CurvedShapeHint         = 0x0006, // Generic vector path..
    87         ShapeMask               = 0x001f,
    87         EllipseHint             = 0x0007,
    88 
    88         ShapeHintMask           = 0x000f,
    89         // Shape hints merged into basic shapes..
       
    90         LinesHint               = LinesShapeMask,
       
    91         RectangleHint           = AreaShapeMask | RectangleShapeMask,
       
    92         EllipseHint             = AreaShapeMask | CurvedShapeMask,
       
    93         ConvexPolygonHint       = AreaShapeMask,
       
    94         PolygonHint             = AreaShapeMask | NonConvexShapeMask,
       
    95         RoundedRectHint         = AreaShapeMask | CurvedShapeMask,
       
    96         ArbitraryShapeHint      = AreaShapeMask | NonConvexShapeMask | CurvedShapeMask,
    89 
    97 
    90         // Other hints
    98         // Other hints
    91         CacheHint               = 0x0100,
    99         IsCachedHint            = 0x0100, // Set if the cache hint is set
    92         ControlPointRect        = 0x0200, // Set if the control point rect has been calculated...
   100         ShouldUseCacheHint      = 0x0200, // Set if the path should be cached when possible..
       
   101         ControlPointRect        = 0x0400, // Set if the control point rect has been calculated...
    93 
   102 
    94         // Shape rendering specifiers...
   103         // Shape rendering specifiers...
    95         OddEvenFill             = 0x1000,
   104         OddEvenFill             = 0x1000,
    96         WindingFill             = 0x2000,
   105         WindingFill             = 0x2000,
    97         ImplicitClose           = 0x4000
   106         ImplicitClose           = 0x4000
    99 
   108 
   100     // ### Falcon: introduca a struct XY for points so lars is not so confused...
   109     // ### Falcon: introduca a struct XY for points so lars is not so confused...
   101     QVectorPath(const qreal *points,
   110     QVectorPath(const qreal *points,
   102                 int count,
   111                 int count,
   103                 const QPainterPath::ElementType *elements = 0,
   112                 const QPainterPath::ElementType *elements = 0,
   104                 uint hints = CurvedShapeHint)
   113                 uint hints = ArbitraryShapeHint)
   105         : m_elements(elements),
   114         : m_elements(elements),
   106           m_points(points),
   115           m_points(points),
   107           m_count(count),
   116           m_count(count),
   108           m_hints(hints)
   117           m_hints(hints)
   109 #ifndef QVECTORPATH_NO_CACHE
       
   110         , m_cache(0)
       
   111 #endif
       
   112     {
   118     {
   113     }
   119     }
   114 
   120 
       
   121     ~QVectorPath();
       
   122 
   115     QRectF controlPointRect() const;
   123     QRectF controlPointRect() const;
   116 
   124 
   117     inline Hint shape() const { return (Hint) (m_hints & ShapeHintMask); }
   125     inline Hint shape() const { return (Hint) (m_hints & ShapeMask); }
       
   126     inline bool isConvex() const { return (m_hints & NonConvexShapeMask) == 0; }
       
   127     inline bool isCurved() const { return m_hints & CurvedShapeMask; }
   118 
   128 
   119     inline bool hasCacheHint() const { return m_hints & CacheHint; }
   129     inline bool isCacheable() const { return m_hints & ShouldUseCacheHint; }
   120     inline bool hasImplicitClose() const { return m_hints & ImplicitClose; }
   130     inline bool hasImplicitClose() const { return m_hints & ImplicitClose; }
   121     inline bool hasWindingFill() const { return m_hints & WindingFill; }
   131     inline bool hasWindingFill() const { return m_hints & WindingFill; }
   122 
   132 
       
   133     inline void makeCacheable() const { m_hints |= ShouldUseCacheHint; m_cache = 0; }
   123     inline uint hints() const { return m_hints; }
   134     inline uint hints() const { return m_hints; }
   124 
   135 
   125     inline const QPainterPath::ElementType *elements() const { return m_elements; }
   136     inline const QPainterPath::ElementType *elements() const { return m_elements; }
   126     inline const qreal *points() const { return m_points; }
   137     inline const qreal *points() const { return m_points; }
   127     inline bool isEmpty() const { return m_points == 0; }
   138     inline bool isEmpty() const { return m_points == 0; }
   129     inline int elementCount() const { return m_count; }
   140     inline int elementCount() const { return m_count; }
   130     inline const QPainterPath convertToPainterPath() const;
   141     inline const QPainterPath convertToPainterPath() const;
   131 
   142 
   132     static inline uint polygonFlags(QPaintEngine::PolygonDrawMode mode);
   143     static inline uint polygonFlags(QPaintEngine::PolygonDrawMode mode);
   133 
   144 
   134 private:
       
   135     Q_DISABLE_COPY(QVectorPath)
       
   136 
       
   137 #ifndef QVECTORPATH_NO_CACHE
       
   138     struct CacheEntry {
   145     struct CacheEntry {
   139         void *engine;
   146         QPaintEngineEx *engine;
   140         int id;
   147         void *data;
   141         void *extra;
   148         qvectorpath_cache_cleanup cleanup;
   142         CacheEntry *next;
   149         CacheEntry *next;
   143     };
   150     };
   144 
   151 
   145     void addCacheData(CacheEntry *d) {
   152     CacheEntry *addCacheData(QPaintEngineEx *engine, void *data, qvectorpath_cache_cleanup cleanup) const;
   146         d->next = m_cache;
   153     inline CacheEntry *lookupCacheData(QPaintEngineEx *engine) const {
   147         m_cache = d;
   154         Q_ASSERT(m_hints & ShouldUseCacheHint);
       
   155         CacheEntry *e = m_cache;
       
   156         while (e) {
       
   157             if (e->engine == engine)
       
   158                 return e;
       
   159             e = e->next;
       
   160         }
       
   161         return 0;
   148     }
   162     }
   149 
   163 
   150     CacheEntry *m_cache;
   164 
   151 #endif
   165 private:
       
   166     Q_DISABLE_COPY(QVectorPath)
   152 
   167 
   153     const QPainterPath::ElementType *m_elements;
   168     const QPainterPath::ElementType *m_elements;
   154     const qreal *m_points;
   169     const qreal *m_points;
   155     const int m_count;
   170     const int m_count;
   156 
   171 
   157     mutable uint m_hints;
   172     mutable uint m_hints;
   158     mutable QRealRect m_cp_rect;
   173     mutable QRealRect m_cp_rect;
       
   174 
       
   175     mutable CacheEntry *m_cache;
   159 };
   176 };
   160 
   177 
   161 Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &path);
   178 Q_GUI_EXPORT const QVectorPath &qtVectorPathForPath(const QPainterPath &path);
   162 
   179 
   163 QT_END_NAMESPACE
   180 QT_END_NAMESPACE