author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Mon, 19 Apr 2010 10:15:19 +0300 | |
branch | RCL_3 |
changeset 9 | b5b118452c7d |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtOpenGL module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qgl2pexvertexarray_p.h" |
|
43 |
||
44 |
#include <private/qbezier_p.h> |
|
45 |
||
46 |
QT_BEGIN_NAMESPACE |
|
47 |
||
48 |
void QGL2PEXVertexArray::clear() |
|
49 |
{ |
|
50 |
vertexArray.reset(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
vertexArrayStops.reset(); |
0 | 52 |
boundingRectDirty = true; |
53 |
} |
|
54 |
||
55 |
||
56 |
QGLRect QGL2PEXVertexArray::boundingRect() const |
|
57 |
{ |
|
58 |
if (boundingRectDirty) |
|
59 |
return QGLRect(0.0, 0.0, 0.0, 0.0); |
|
60 |
else |
|
61 |
return QGLRect(minX, minY, maxX, maxY); |
|
62 |
} |
|
63 |
||
64 |
void QGL2PEXVertexArray::addRect(const QRectF &rect) |
|
65 |
{ |
|
66 |
vertexArray << rect.topLeft() << rect.topRight() << rect.bottomRight() |
|
67 |
<< rect.bottomRight() << rect.bottomLeft() << rect.topLeft(); |
|
68 |
} |
|
69 |
||
70 |
void QGL2PEXVertexArray::addClosingLine(int index) |
|
71 |
{ |
|
72 |
if (QPointF(vertexArray.at(index)) != QPointF(vertexArray.last())) |
|
73 |
vertexArray.add(vertexArray.at(index)); |
|
74 |
} |
|
75 |
||
76 |
void QGL2PEXVertexArray::addCentroid(const QVectorPath &path, int subPathIndex) |
|
77 |
{ |
|
78 |
const QPointF *const points = reinterpret_cast<const QPointF *>(path.points()); |
|
79 |
const QPainterPath::ElementType *const elements = path.elements(); |
|
80 |
||
81 |
QPointF sum = points[subPathIndex]; |
|
82 |
int count = 1; |
|
83 |
||
84 |
for (int i = subPathIndex + 1; i < path.elementCount() && (!elements || elements[i] != QPainterPath::MoveToElement); ++i) { |
|
85 |
sum += points[i]; |
|
86 |
++count; |
|
87 |
} |
|
88 |
||
89 |
const QPointF centroid = sum / qreal(count); |
|
90 |
vertexArray.add(centroid); |
|
91 |
} |
|
92 |
||
93 |
void QGL2PEXVertexArray::addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline) |
|
94 |
{ |
|
95 |
const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); |
|
96 |
const QPainterPath::ElementType* const elements = path.elements(); |
|
97 |
||
98 |
if (boundingRectDirty) { |
|
99 |
minX = maxX = points[0].x(); |
|
100 |
minY = maxY = points[0].y(); |
|
101 |
boundingRectDirty = false; |
|
102 |
} |
|
103 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
if (!outline && !path.isConvex()) |
0 | 105 |
addCentroid(path, 0); |
106 |
||
107 |
int lastMoveTo = vertexArray.size(); |
|
108 |
vertexArray.add(points[0]); // The first element is always a moveTo |
|
109 |
||
110 |
do { |
|
111 |
if (!elements) { |
|
112 |
// qDebug("QVectorPath has no elements"); |
|
113 |
// If the path has a null elements pointer, the elements implicitly |
|
114 |
// start with a moveTo (already added) and continue with lineTos: |
|
115 |
for (int i=1; i<path.elementCount(); ++i) |
|
116 |
lineToArray(points[i].x(), points[i].y()); |
|
117 |
||
118 |
break; |
|
119 |
} |
|
120 |
// qDebug("QVectorPath has element types"); |
|
121 |
||
122 |
for (int i=1; i<path.elementCount(); ++i) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
switch (elements[i]) { |
0 | 124 |
case QPainterPath::MoveToElement: |
125 |
if (!outline) |
|
126 |
addClosingLine(lastMoveTo); |
|
127 |
// qDebug("element[%d] is a MoveToElement", i); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
vertexArrayStops.add(vertexArray.size()); |
0 | 129 |
if (!outline) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
if (!path.isConvex()) addCentroid(path, i); |
0 | 131 |
lastMoveTo = vertexArray.size(); |
132 |
} |
|
133 |
lineToArray(points[i].x(), points[i].y()); // Add the moveTo as a new vertex |
|
134 |
break; |
|
135 |
case QPainterPath::LineToElement: |
|
136 |
// qDebug("element[%d] is a LineToElement", i); |
|
137 |
lineToArray(points[i].x(), points[i].y()); |
|
138 |
break; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
case QPainterPath::CurveToElement: { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
QBezier b = QBezier::fromPoints(*(((const QPointF *) points) + i - 1), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
points[i], |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
points[i+1], |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
points[i+2]); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
QRectF bounds = b.bounds(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
// threshold based on same algorithm as in qtriangulatingstroker.cpp |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * 3.14f / (curveInverseScale * 6)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
if (threshold < 3) threshold = 3; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
qreal one_over_threshold_minus_1 = 1.f / (threshold - 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
for (int t=0; t<threshold; ++t) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
QPointF pt = b.pointAt(t * one_over_threshold_minus_1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
lineToArray(pt.x(), pt.y()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
i += 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
break; } |
0 | 155 |
default: |
156 |
break; |
|
157 |
} |
|
158 |
} |
|
159 |
} while (0); |
|
160 |
||
161 |
if (!outline) |
|
162 |
addClosingLine(lastMoveTo); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
vertexArrayStops.add(vertexArray.size()); |
0 | 164 |
} |
165 |
||
166 |
void QGL2PEXVertexArray::lineToArray(const GLfloat x, const GLfloat y) |
|
167 |
{ |
|
168 |
vertexArray.add(QGLPoint(x, y)); |
|
169 |
||
170 |
if (x > maxX) |
|
171 |
maxX = x; |
|
172 |
else if (x < minX) |
|
173 |
minX = x; |
|
174 |
if (y > maxY) |
|
175 |
maxY = y; |
|
176 |
else if (y < minY) |
|
177 |
minY = y; |
|
178 |
} |
|
179 |
||
180 |
QT_END_NAMESPACE |