Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QGL2PEXVertexArray Class Reference

#include <qgl2pexvertexarray_p.h>

Public Functions

void addPath (const QVectorPath &path, GLfloat curveInverseScale, bool outline=true)
 
void addQuad (const QRectF &rect)
 
void addRect (const QRectF &rect)
 
void addVertex (const GLfloat x, const GLfloat y)
 
QGLRect boundingRect () const
 
void clear ()
 
QGLPoint * data ()
 
void lineToArray (const GLfloat x, const GLfloat y)
 
 QGL2PEXVertexArray ()
 
int stopCount () const
 
int * stops () const
 
int vertexCount () const
 

Private Functions

void addCentroid (const QVectorPath &path, int subPathIndex)
 
void addClosingLine (int index)
 

Properties

bool boundingRectDirty
 
GLfloat maxX
 
GLfloat maxY
 
GLfloat minX
 
GLfloat minY
 
QDataBuffer< QGLPoint > vertexArray
 
QDataBuffer< int > vertexArrayStops
 

Detailed Description

Definition at line 99 of file qgl2pexvertexarray_p.h.

Constructors and Destructors

◆ QGL2PEXVertexArray()

QGL2PEXVertexArray::QGL2PEXVertexArray ( )
inline

Definition at line 102 of file qgl2pexvertexarray_p.h.

102  :
104  maxX(-2e10), maxY(-2e10), minX(2e10), minY(2e10),
105  boundingRectDirty(true)
106  { }
QDataBuffer< QGLPoint > vertexArray
QDataBuffer< int > vertexArrayStops

Functions

◆ addCentroid()

void QGL2PEXVertexArray::addCentroid ( const QVectorPath &  path,
int  subPathIndex 
)
private

Definition at line 71 of file qgl2pexvertexarray.cpp.

Referenced by addPath().

72 {
73  const QPointF *const points = reinterpret_cast<const QPointF *>(path.points());
74  const QPainterPath::ElementType *const elements = path.elements();
75 
76  QPointF sum = points[subPathIndex];
77  int count = 1;
78 
79  for (int i = subPathIndex + 1; i < path.elementCount() && (!elements || elements[i] != QPainterPath::MoveToElement); ++i) {
80  sum += points[i];
81  ++count;
82  }
83 
84  const QPointF centroid = sum / qreal(count);
85  vertexArray.add(centroid);
86 }
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
double qreal
Definition: qglobal.h:1193
int elementCount() const
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
const QPainterPath::ElementType * elements() const
void add(const Type &t)
Definition: qdatabuffer_p.h:93
const qreal * points() const
static const QTextHtmlElement elements[Html_NumElements]
QDataBuffer< QGLPoint > vertexArray

◆ addClosingLine()

void QGL2PEXVertexArray::addClosingLine ( int  index)
private

Definition at line 64 of file qgl2pexvertexarray.cpp.

Referenced by addPath().

65 {
66  QPointF point(vertexArray.at(index));
67  if (point != QPointF(vertexArray.last()))
68  vertexArray.add(point);
69 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
Type & at(int i)
Definition: qdatabuffer_p.h:86
void add(const Type &t)
Definition: qdatabuffer_p.h:93
Type & last()
Definition: qdatabuffer_p.h:88
quint16 index
QDataBuffer< QGLPoint > vertexArray

◆ addPath()

void QGL2PEXVertexArray::addPath ( const QVectorPath &  path,
GLfloat  curveInverseScale,
bool  outline = true 
)

Definition at line 88 of file qgl2pexvertexarray.cpp.

Referenced by QGL2PaintEngineExPrivate::fill().

89 {
90  const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
91  const QPainterPath::ElementType* const elements = path.elements();
92 
93  if (boundingRectDirty) {
94  minX = maxX = points[0].x();
95  minY = maxY = points[0].y();
96  boundingRectDirty = false;
97  }
98 
99  if (!outline && !path.isConvex())
100  addCentroid(path, 0);
101 
102  int lastMoveTo = vertexArray.size();
103  vertexArray.add(points[0]); // The first element is always a moveTo
104 
105  do {
106  if (!elements) {
107 // qDebug("QVectorPath has no elements");
108  // If the path has a null elements pointer, the elements implicitly
109  // start with a moveTo (already added) and continue with lineTos:
110  for (int i=1; i<path.elementCount(); ++i)
111  lineToArray(points[i].x(), points[i].y());
112 
113  break;
114  }
115 // qDebug("QVectorPath has element types");
116 
117  for (int i=1; i<path.elementCount(); ++i) {
118  switch (elements[i]) {
120  if (!outline)
121  addClosingLine(lastMoveTo);
122 // qDebug("element[%d] is a MoveToElement", i);
124  if (!outline) {
125  if (!path.isConvex()) addCentroid(path, i);
126  lastMoveTo = vertexArray.size();
127  }
128  lineToArray(points[i].x(), points[i].y()); // Add the moveTo as a new vertex
129  break;
131 // qDebug("element[%d] is a LineToElement", i);
132  lineToArray(points[i].x(), points[i].y());
133  break;
135  QBezier b = QBezier::fromPoints(*(((const QPointF *) points) + i - 1),
136  points[i],
137  points[i+1],
138  points[i+2]);
139  QRectF bounds = b.bounds();
140  // threshold based on same algorithm as in qtriangulatingstroker.cpp
141  int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * 3.14f / (curveInverseScale * 6));
142  if (threshold < 3) threshold = 3;
143  qreal one_over_threshold_minus_1 = qreal(1) / (threshold - 1);
144  for (int t=0; t<threshold; ++t) {
145  QPointF pt = b.pointAt(t * one_over_threshold_minus_1);
146  lineToArray(pt.x(), pt.y());
147  }
148  i += 2;
149  break; }
150  default:
151  break;
152  }
153  }
154  } while (0);
155 
156  if (!outline)
157  addClosingLine(lastMoveTo);
159 }
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
double qreal
Definition: qglobal.h:1193
int elementCount() const
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPointF pointAt(qreal t) const
Definition: qbezier_p.h:163
const QPainterPath::ElementType * elements() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
void add(const Type &t)
Definition: qdatabuffer_p.h:93
void lineToArray(const GLfloat x, const GLfloat y)
QRectF bounds() const
Definition: qbezier.cpp:223
void addCentroid(const QVectorPath &path, int subPathIndex)
const qreal * points() const
bool isConvex() const
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static const QTextHtmlElement elements[Html_NumElements]
QDataBuffer< QGLPoint > vertexArray
QDataBuffer< int > vertexArrayStops
void addClosingLine(int index)
int size() const
Definition: qdatabuffer_p.h:83

◆ addQuad()

void QGL2PEXVertexArray::addQuad ( const QRectF &  rect)
inline

Definition at line 123 of file qgl2pexvertexarray_p.h.

Referenced by QGL2PaintEngineExPrivate::drawCachedGlyphs().

124  {
125  qreal top = rect.top();
126  qreal left = rect.left();
127  qreal bottom = rect.bottom();
128  qreal right = rect.right();
129 
130  vertexArray << QGLPoint(left, top)
131  << QGLPoint(right, top)
132  << QGLPoint(left, bottom)
133  << QGLPoint(right, bottom);
134 
135  }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QDataBuffer< QGLPoint > vertexArray
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ addRect()

void QGL2PEXVertexArray::addRect ( const QRectF &  rect)
inline

Definition at line 108 of file qgl2pexvertexarray_p.h.

109  {
110  qreal top = rect.top();
111  qreal left = rect.left();
112  qreal bottom = rect.bottom();
113  qreal right = rect.right();
114 
115  vertexArray << QGLPoint(left, top)
116  << QGLPoint(right, top)
117  << QGLPoint(right, bottom)
118  << QGLPoint(right, bottom)
119  << QGLPoint(left, bottom)
120  << QGLPoint(left, top);
121  }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
QDataBuffer< QGLPoint > vertexArray
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ addVertex()

void QGL2PEXVertexArray::addVertex ( const GLfloat  x,
const GLfloat  y 
)
inline

Definition at line 137 of file qgl2pexvertexarray_p.h.

138  {
139  vertexArray.add(QGLPoint(x, y));
140  }
void add(const Type &t)
Definition: qdatabuffer_p.h:93
QDataBuffer< QGLPoint > vertexArray

◆ boundingRect()

QGLRect QGL2PEXVertexArray::boundingRect ( ) const

◆ clear()

void QGL2PEXVertexArray::clear ( )

Definition at line 48 of file qgl2pexvertexarray.cpp.

Referenced by QGL2PaintEngineExPrivate::drawCachedGlyphs(), and QGL2PaintEngineExPrivate::fill().

49 {
52  boundingRectDirty = true;
53 }
QDataBuffer< QGLPoint > vertexArray
QDataBuffer< int > vertexArrayStops
void reset()
Definition: qdatabuffer_p.h:79

◆ data()

QGLPoint* QGL2PEXVertexArray::data ( )
inline

◆ lineToArray()

void QGL2PEXVertexArray::lineToArray ( const GLfloat  x,
const GLfloat  y 
)

Definition at line 161 of file qgl2pexvertexarray.cpp.

Referenced by addPath().

162 {
163  vertexArray.add(QGLPoint(x, y));
164 
165  if (x > maxX)
166  maxX = x;
167  else if (x < minX)
168  minX = x;
169  if (y > maxY)
170  maxY = y;
171  else if (y < minY)
172  minY = y;
173 }
void add(const Type &t)
Definition: qdatabuffer_p.h:93
QDataBuffer< QGLPoint > vertexArray

◆ stopCount()

int QGL2PEXVertexArray::stopCount ( ) const
inline

◆ stops()

int* QGL2PEXVertexArray::stops ( ) const
inline

◆ vertexCount()

int QGL2PEXVertexArray::vertexCount ( ) const
inline

Definition at line 150 of file qgl2pexvertexarray_p.h.

Referenced by QGL2PaintEngineExPrivate::drawCachedGlyphs(), and QGL2PaintEngineExPrivate::fill().

150 { return vertexArray.size(); }
QDataBuffer< QGLPoint > vertexArray
int size() const
Definition: qdatabuffer_p.h:83

Properties

◆ boundingRectDirty

bool QGL2PEXVertexArray::boundingRectDirty
private

Definition at line 162 of file qgl2pexvertexarray_p.h.

Referenced by addPath(), boundingRect(), and clear().

◆ maxX

GLfloat QGL2PEXVertexArray::maxX
private

Definition at line 158 of file qgl2pexvertexarray_p.h.

Referenced by addPath(), boundingRect(), and lineToArray().

◆ maxY

GLfloat QGL2PEXVertexArray::maxY
private

Definition at line 159 of file qgl2pexvertexarray_p.h.

Referenced by addPath(), boundingRect(), and lineToArray().

◆ minX

GLfloat QGL2PEXVertexArray::minX
private

Definition at line 160 of file qgl2pexvertexarray_p.h.

Referenced by addPath(), boundingRect(), and lineToArray().

◆ minY

GLfloat QGL2PEXVertexArray::minY
private

Definition at line 161 of file qgl2pexvertexarray_p.h.

Referenced by addPath(), boundingRect(), and lineToArray().

◆ vertexArray

QDataBuffer<QGLPoint> QGL2PEXVertexArray::vertexArray
private

Definition at line 155 of file qgl2pexvertexarray_p.h.

Referenced by addCentroid(), addClosingLine(), addPath(), clear(), and lineToArray().

◆ vertexArrayStops

QDataBuffer<int> QGL2PEXVertexArray::vertexArrayStops
private

Definition at line 156 of file qgl2pexvertexarray_p.h.

Referenced by addPath(), and clear().


The documentation for this class was generated from the following files: