Qt 4.8
qtriangulatingstroker_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTRIANGULATINGSTROKER_P_H
43 #define QTRIANGULATINGSTROKER_P_H
44 
45 #include <private/qdatabuffer_p.h>
46 #include <qvarlengtharray.h>
47 #include <private/qvectorpath_p.h>
48 #include <private/qbezier_p.h>
49 #include <private/qnumeric_p.h>
50 #include <private/qmath_p.h>
51 
53 
55 {
56 public:
58  void process(const QVectorPath &path, const QPen &pen, const QRectF &clip);
59 
60  inline int vertexCount() const { return m_vertices.size(); }
61  inline const float *vertices() const { return m_vertices.data(); }
62 
63  inline void setInvScale(qreal invScale) { m_inv_scale = invScale; }
64 
65 private:
66  inline void emitLineSegment(float x, float y, float nx, float ny);
67  void moveTo(const qreal *pts);
68  inline void lineTo(const qreal *pts);
69  void cubicTo(const qreal *pts);
70  void join(const qreal *pts);
71  inline void normalVector(float x1, float y1, float x2, float y2, float *nx, float *ny);
72  void endCap(const qreal *pts);
73  void arcPoints(float cx, float cy, float fromX, float fromY, float toX, float toY, QVarLengthArray<float> &points);
74  void endCapOrJoinClosed(const qreal *start, const qreal *cur, bool implicitClose, bool endsAtStart);
75 
76 
78 
79  float m_cx, m_cy; // current points
80  float m_nvx, m_nvy; // normal vector...
81  float m_width;
83 
84  int m_roundness; // Number of line segments in a round join
85  qreal m_sin_theta; // sin(m_roundness / 360);
86  qreal m_cos_theta; // cos(m_roundness / 360);
90 
93 };
94 
96 {
97 public:
99 
100  void process(const QVectorPath &path, const QPen &pen, const QRectF &clip);
101 
103  m_points.add(x);
104  m_points.add(y);
105  m_types.add(type);
106  }
107 
108  inline int elementCount() const { return m_types.size(); }
109  inline qreal *points() const { return m_points.data(); }
110  inline QPainterPath::ElementType *elementTypes() const { return m_types.data(); }
111 
112  inline void setInvScale(qreal invScale) { m_inv_scale = invScale; }
113 
114 private:
119 };
120 
121 inline void QTriangulatingStroker::normalVector(float x1, float y1, float x2, float y2,
122  float *nx, float *ny)
123 {
124  float dx = x2 - x1;
125  float dy = y2 - y1;
126 
127  float pw;
128 
129  if (dx == 0)
130  pw = m_width / qAbs(dy);
131  else if (dy == 0)
132  pw = m_width / qAbs(dx);
133  else
134  pw = m_width / sqrt(dx*dx + dy*dy);
135 
136  *nx = -dy * pw;
137  *ny = dx * pw;
138 }
139 
140 inline void QTriangulatingStroker::emitLineSegment(float x, float y, float vx, float vy)
141 {
142  m_vertices.add(x + vx);
143  m_vertices.add(y + vy);
144  m_vertices.add(x - vx);
145  m_vertices.add(y - vy);
146 }
147 
149 {
150  emitLineSegment(pts[0], pts[1], m_nvx, m_nvy);
151  m_cx = pts[0];
152  m_cy = pts[1];
153 }
154 
156 
157 #endif
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
int type
Definition: qmetatype.cpp:239
void addElement(QPainterPath::ElementType type, qreal x, qreal y)
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Type * data() const
Definition: qdatabuffer_p.h:84
void cubicTo(const qreal *pts)
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void emitLineSegment(float x, float y, float nx, float ny)
PenCapStyle
Definition: qnamespace.h:1147
QDataBuffer< QPainterPath::ElementType > m_types
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void normalVector(float x1, float y1, float x2, float y2, float *nx, float *ny)
void endCapOrJoinClosed(const qreal *start, const qreal *cur, bool implicitClose, bool endsAtStart)
QDataBuffer< qreal > m_points
void add(const Type &t)
Definition: qdatabuffer_p.h:93
void setInvScale(qreal invScale)
PenJoinStyle
Definition: qnamespace.h:1154
void process(const QVectorPath &path, const QPen &pen, const QRectF &clip)
QDataBuffer< float > m_vertices
QPainterPath::ElementType * elementTypes() const
void join(const qreal *pts)
void lineTo(const qreal *pts)
const float * vertices() const
void moveTo(const qreal *pts)
void arcPoints(float cx, float cy, float fromX, float fromY, float toX, float toY, QVarLengthArray< float > &points)
void endCap(const qreal *pts)
void setInvScale(qreal invScale)
int size() const
Definition: qdatabuffer_p.h:83