diff options
author | Gunnar Sletta <gunnar.sletta@digia.com> | 2013-11-12 12:13:11 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-12 18:20:30 +0100 |
commit | 508ad2e9b3af24f453720e3a3a8b7c561944abf3 (patch) | |
tree | f5b362f9b38f9dd9cc7c53f3ee423943a303cf40 /src/quick | |
parent | 7a092000169a8e9d537f3d341ef48277397f997d (diff) |
Fix boundingbox calculation of rotated items.
Task-number: QTBUG-34328
Change-Id: If0202a67d95500333a0fb6f4ca3eb19ecb027770
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 33 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h | 9 |
2 files changed, 34 insertions, 8 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index 940b8dd02b..3782cab5d3 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -113,6 +113,7 @@ struct QMatrix4x4_Accessor int flagBits; static bool isTranslate(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits <= 0x1; } + static bool isScale(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits <= 0x2; } static bool is2DSafe(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits < 0x8; } }; @@ -533,6 +534,38 @@ int qsg_positionAttribute(QSGGeometry *g) { return -1; } + +void Rect::map(const QMatrix4x4 &matrix) +{ + const float *m = matrix.constData(); + if (QMatrix4x4_Accessor::isScale(matrix)) { + tl.x = tl.x * m[0] + m[12]; + tl.y = tl.y * m[5] + m[13]; + br.x = br.x * m[0] + m[12]; + br.y = br.y * m[5] + m[13]; + if (tl.x > br.x) + qSwap(tl.x, br.x); + if (tl.y > br.y) + qSwap(tl.y, br.y); + } else { + Pt mtl = tl; + Pt mtr = { br.x, tl.y }; + Pt mbl = { tl.x, br.y }; + Pt mbr = br; + + mtl.map(matrix); + mtr.map(matrix); + mbl.map(matrix); + mbr.map(matrix); + + set(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); + (*this) |= mtl; + (*this) |= mtr; + (*this) |= mbl; + (*this) |= mbr; + } +} + void Element::computeBounds() { Q_ASSERT(!boundsComputed); diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 6d95f83d7a..aacf482ead 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -119,14 +119,7 @@ struct Rect { Q_ASSERT(tl.y <= br.y); } - void map(const QMatrix4x4 &m) { - tl.map(m); - br.map(m); - if (br.x < tl.x) - qSwap(br.x, tl.x); - if (br.y < tl.y) - qSwap(br.y, tl.y); - } + void map(const QMatrix4x4 &m); void set(float left, float top, float right, float bottom) { tl.set(left, top); |