summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@nokia.com>2010-11-19 15:25:31 +0100
committerYoann Lopes <yoann.lopes@nokia.com>2010-11-19 15:25:31 +0100
commit6734621437ebcc17224693338f1c7afb497f9935 (patch)
tree99d6717f358e1bcdcc4bd3f9cbd2bd858c4c0bfc
parente5424a11f0682b2092407ed004f104d5cfb43998 (diff)
Fixes Rectangle rendering when radius is bigger than half of the size.
-rw-r--r--src/adaptationlayers/default/default_rectanglenode.cpp15
-rw-r--r--src/canvas/qxclipnode.cpp12
2 files changed, 16 insertions, 11 deletions
diff --git a/src/adaptationlayers/default/default_rectanglenode.cpp b/src/adaptationlayers/default/default_rectanglenode.cpp
index 744a798..70b9647 100644
--- a/src/adaptationlayers/default/default_rectanglenode.cpp
+++ b/src/adaptationlayers/default/default_rectanglenode.cpp
@@ -289,16 +289,19 @@ void DefaultRectangleNode::updateGeometry()
if (m_radius > 0) {
// Rounded corners.
+
+ // Radius should never exceeds half of the width or half of the height
+ qreal radius = qMin(qMin(m_rect.width() / 2, m_rect.height() / 2), m_radius);
QRectF innerRect = m_rect;
- innerRect.adjust(m_radius, m_radius, -m_radius, -m_radius);
+ innerRect.adjust(radius, radius, -radius, -radius);
if (m_pen_width & 1) {
// Pen width is odd, so add the offset as documented.
innerRect.moveLeft(innerRect.left() + qreal(0.5));
innerRect.moveTop(innerRect.top() + qreal(0.5));
}
- qreal innerRadius = m_radius - m_pen_width * qreal(0.5);
- qreal outerRadius = m_radius + m_pen_width * qreal(0.5);
+ qreal innerRadius = radius - m_pen_width * qreal(0.5);
+ qreal outerRadius = radius + m_pen_width * qreal(0.5);
int segments = qMin(30, qCeil(outerRadius)); // Number of segments per corner.
@@ -332,7 +335,7 @@ void DefaultRectangleNode::updateGeometry()
QList<ushort> borderIndices;
int nextGradientStop = 0;
- qreal gradientPos = (m_radius - innerRadius) / (innerRect.height() + 2 * m_radius);
+ qreal gradientPos = (radius - innerRadius) / (innerRect.height() + 2 * radius);
while (nextGradientStop < stops.size() && stops.at(nextGradientStop).first <= gradientPos)
++nextGradientStop;
@@ -353,10 +356,10 @@ void DefaultRectangleNode::updateGeometry()
qreal lX = innerRect.left() - outerRadius * s; // current outer left x-coordinate.
qreal rX = innerRect.right() + outerRadius * s; // current outer right x-coordinate.
- gradientPos = ((part ? innerRect.height() : 0) + m_radius - innerRadius * c) / (innerRect.height() + 2 * m_radius);
+ gradientPos = ((part ? innerRect.height() : 0) + radius - innerRadius * c) / (innerRect.height() + 2 * radius);
while (nextGradientStop < stops.size() && stops.at(nextGradientStop).first <= gradientPos) {
// Insert vertices at gradient stops.
- qreal gy = (innerRect.top() - m_radius) + stops.at(nextGradientStop).first * (innerRect.height() + 2 * m_radius);
+ qreal gy = (innerRect.top() - radius) + stops.at(nextGradientStop).first * (innerRect.height() + 2 * radius);
Q_ASSERT(fillVertexCount >= 2);
qreal t = (gy - py) / (y - py);
qreal glx = plx * (1 - t) + t * lx;
diff --git a/src/canvas/qxclipnode.cpp b/src/canvas/qxclipnode.cpp
index 446f154..4e3df53 100644
--- a/src/canvas/qxclipnode.cpp
+++ b/src/canvas/qxclipnode.cpp
@@ -88,10 +88,12 @@ void QxClipNode::updateGeometry()
Geometry *g = geometry();
int vertexCount = 0;
+ // Radius should never exceeds half of the width or half of the height
+ qreal radius = qMin(qMin(m_rect.width() / 2, m_rect.height() / 2), m_radius);
QRectF rect = m_rect;
- rect.adjust(m_radius, m_radius, -m_radius, -m_radius);
+ rect.adjust(radius, radius, -radius, -radius);
- int segments = qMin(30, qCeil(m_radius)); // Number of segments per corner.
+ int segments = qMin(30, qCeil(radius)); // Number of segments per corner.
// Overestimate the number of vertices and indices, reduce afterwards when the actual numbers are known.
g->setVertexCount((segments + 1) * 4);
@@ -105,9 +107,9 @@ void QxClipNode::updateGeometry()
qreal angle = qreal(0.5 * M_PI) * (part + i / qreal(segments));
qreal s = qFastSin(angle);
qreal c = qFastCos(angle);
- qreal y = (part ? rect.bottom() : rect.top()) - m_radius * c; // current inner y-coordinate.
- qreal lx = rect.left() - m_radius * s; // current inner left x-coordinate.
- qreal rx = rect.right() + m_radius * s; // current inner right x-coordinate.
+ qreal y = (part ? rect.bottom() : rect.top()) - radius * c; // current inner y-coordinate.
+ qreal lx = rect.left() - radius * s; // current inner left x-coordinate.
+ qreal rx = rect.right() + radius * s; // current inner right x-coordinate.
vertices[vertexCount++].position = QVector2D(rx, y);
vertices[vertexCount++].position = QVector2D(lx, y);