summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-10-01 11:36:57 (GMT)
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-10-02 15:57:19 (GMT)
commit5a26fa6da1986bdb507391fd8784c51258e81d80 (patch)
treee1c0d4aac597cc0ace85e0619d46648a8ce75038
parent385176ad28b3a79bcd196d2d529c4bf7abd4fcc0 (diff)
downloadQt-5a26fa6da1986bdb507391fd8784c51258e81d80.zip
Qt-5a26fa6da1986bdb507391fd8784c51258e81d80.tar.gz
Qt-5a26fa6da1986bdb507391fd8784c51258e81d80.tar.bz2
Changed implementation of qDrawBorderPixmap() to use qDrawPixmaps().
Reviewed-by: Trond
-rw-r--r--src/gui/painting/qdrawutil.cpp408
-rw-r--r--src/gui/painting/qdrawutil.h63
-rw-r--r--src/gui/painting/qpaintengineex.cpp2
-rw-r--r--src/gui/painting/qpaintengineex_p.h9
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp18
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h2
6 files changed, 262 insertions, 240 deletions
diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp
index 4f17e59..c20d8d8 100644
--- a/src/gui/painting/qdrawutil.cpp
+++ b/src/gui/painting/qdrawutil.cpp
@@ -46,6 +46,8 @@
#include "qpainter.h"
#include "qpalette.h"
#include <private/qpaintengineex_p.h>
+#include <qvarlengtharray.h>
+#include <qmath.h>
QT_BEGIN_NAMESPACE
@@ -1079,91 +1081,7 @@ void qDrawItem(QPainter *p, Qt::GUIStyle gs,
according to the \a margins structure.
*/
-static inline void qVerticalRepeat(QPainter *painter,
- const QRect &target,
- const QPixmap &pixmap,
- const QRect &source,
- void (*drawPixmap)(QPainter*,
- const QRect&,
- const QPixmap&,
- const QRect&))
-{
- const int x = target.x();
- const int width = target.width();
- const int height = source.height();
- const int bottom = target.bottom() - height;
- int y = target.y();
- for (; y < bottom; y += height)
- (*drawPixmap)(painter, QRect(x, y, width, height), pixmap, source);
- const QRect remaining(source.x(), source.y(), source.width(), target.bottom() - y + 1);
- (*drawPixmap)(painter, QRect(x, y, width, remaining.height()), pixmap, remaining);
-}
-
-static inline void qHorizontalRepeat(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source,
- void (*drawPixmap)(QPainter*, const QRect&, const QPixmap&, const QRect&))
-{
- const int y = target.y();
- const int width = source.width();
- const int height = target.height();
- const int right = target.right() - width;
- int x = target.x();
- for (; x < right; x += width)
- (*drawPixmap)(painter, QRect(x, y, width, height), pixmap, source);
- const QRect remaining(source.x(), source.y(), target.right() - x + 1, source.height());
- (*drawPixmap)(painter, QRect(x, y, remaining.width(), height), pixmap, remaining);
-}
-
-static inline void qVerticalRound(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source,
- void (*drawPixmap)(QPainter*, const QRect&, const QPixmap&, const QRect&))
-{
- // qreal based - slow on non-fpu devices
- const qreal x = target.x();
- const qreal width = target.width();
- const qreal verticalFactor = static_cast<qreal>(target.height()) / static_cast<qreal>(source.height());
- const qreal verticalIncrement = static_cast<qreal>(target.height()) / static_cast<int>(verticalFactor + 0.5);
- const qreal bottom = target.bottom();
- for (qreal y = static_cast<qreal>(target.y()); y < bottom; y += verticalIncrement)
- (*drawPixmap)(painter, QRectF(x, y, width, verticalIncrement).toRect(), pixmap, source);
-
-}
-
-static inline void qHorizontalRound(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source,
- void (*drawPixmap)(QPainter*, const QRect&, const QPixmap&, const QRect&))
-{
- // qreal based - slow on non-fpu devices
- const qreal y = target.y();
- const qreal height = target.height();
- const qreal horizontalFactor = static_cast<qreal>(target.width()) / static_cast<qreal>(source.width());
- const qreal horizontalIncrement = static_cast<qreal>(target.width()) / static_cast<int>(horizontalFactor + 0.5);
- const qreal right = target.right();
- for (qreal x = target.x(); x < right; x += horizontalIncrement)
- (*drawPixmap)(painter, QRectF(x, y, horizontalIncrement, height).toRect(), pixmap, source);
-}
-
-static inline void qDrawPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
-{
- painter->drawPixmap(target, pixmap, source);
-}
-
-static inline void qDrawVerticallyRepeatedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
-{
- qVerticalRepeat(painter, target, pixmap, source, qDrawPixmap);
-}
-
-static inline void qDrawHorizontallyRepeatedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
-{
- qHorizontalRepeat(painter, target, pixmap, source, qDrawPixmap);
-}
-
-static inline void qDrawVerticallyRoundedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
-{
- qVerticalRound(painter, target, pixmap, source, qDrawPixmap);
-}
-
-static inline void qDrawHorizontallyRoundedPixmap(QPainter *painter, const QRect &target, const QPixmap &pixmap, const QRect &source)
-{
- qHorizontalRound(painter, target, pixmap, source, qDrawPixmap);
-}
+typedef QVarLengthArray<QDrawPixmaps::Data, 16> QDrawPixmapsDataArray;
/*!
\since 4.6
@@ -1180,180 +1098,227 @@ static inline void qDrawHorizontallyRoundedPixmap(QPainter *painter, const QRect
\sa Qt::TileRule, QTileRules, QMargins
*/
-void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap,
- const QRect &sourceRect, const QMargins &sourceMargins, const QTileRules &rules)
+void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins,
+ const QPixmap &pixmap, const QRect &sourceRect,const QMargins &sourceMargins,
+ const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints)
{
+ QDrawPixmaps::Data d;
+ d.opacity = 1.0;
+ d.rotation = 0.0;
+
+ QDrawPixmapsDataArray opaqueData;
+ QDrawPixmapsDataArray translucentData;
+
// source center
- const int sourceTop = sourceRect.top();
- const int sourceLeft = sourceRect.left();
- const int sourceCenterTop = sourceTop + sourceMargins.top();
- const int sourceCenterLeft = sourceLeft + sourceMargins.left();
+ const int sourceCenterTop = sourceRect.top() + sourceMargins.top();
+ const int sourceCenterLeft = sourceRect.left() + sourceMargins.left();
const int sourceCenterBottom = sourceRect.bottom() - sourceMargins.bottom() + 1;
const int sourceCenterRight = sourceRect.right() - sourceMargins.right() + 1;
- const int sourceCenterWidth = sourceCenterRight - sourceMargins.left();
- const int sourceCenterHeight = sourceCenterBottom - sourceMargins.top();
+ const int sourceCenterWidth = sourceCenterRight - sourceCenterLeft;
+ const int sourceCenterHeight = sourceCenterBottom - sourceCenterTop;
// target center
- const int targetTop = targetRect.top();
- const int targetLeft = targetRect.left();
- const int targetCenterTop = targetTop + targetMargins.top();
- const int targetCenterLeft = targetLeft + targetMargins.left();
+ const int targetCenterTop = targetRect.top() + targetMargins.top();
+ const int targetCenterLeft = targetRect.left() + targetMargins.left();
const int targetCenterBottom = targetRect.bottom() - targetMargins.bottom() + 1;
const int targetCenterRight = targetRect.right() - targetMargins.right() + 1;
const int targetCenterWidth = targetCenterRight - targetCenterLeft;
const int targetCenterHeight = targetCenterBottom - targetCenterTop;
+ QVarLengthArray<qreal, 16> xTarget; // x-coordinates of target rectangles
+ QVarLengthArray<qreal, 16> yTarget; // y-coordinates of target rectangles
+
+ int columns = 3;
+ int rows = 3;
+ if (rules.horizontal != Qt::StretchTile && sourceCenterWidth != 0)
+ columns = qMax(3, 2 + qCeil(targetCenterWidth / qreal(sourceCenterWidth)));
+ if (rules.vertical != Qt::StretchTile && sourceCenterHeight != 0)
+ rows = qMax(3, 2 + qCeil(targetCenterHeight / qreal(sourceCenterHeight)));
+
+ xTarget.resize(columns + 1);
+ yTarget.resize(rows + 1);
+
+ xTarget[0] = targetRect.left();
+ xTarget[1] = targetCenterLeft;
+ xTarget[columns - 1] = targetCenterRight;
+ xTarget[columns] = targetRect.left() + targetRect.width();
+
+ yTarget[0] = targetRect.top();
+ yTarget[1] = targetCenterTop;
+ yTarget[rows - 1] = targetCenterBottom;
+ yTarget[rows] = targetRect.top() + targetRect.height();
+
+ qreal dx;
+ qreal dy;
+
+ switch (rules.horizontal) {
+ case Qt::StretchTile:
+ dx = targetCenterWidth;
+ break;
+ case Qt::RepeatTile:
+ dx = sourceCenterWidth;
+ break;
+ case Qt::RoundTile:
+ dx = targetCenterWidth / qreal(columns - 2);
+ break;
+ }
+
+ for (int i = 2; i < columns - 1; ++i)
+ xTarget[i] = xTarget[i - 1] + dx;
+
+ switch (rules.vertical) {
+ case Qt::StretchTile:
+ dy = targetCenterHeight;
+ break;
+ case Qt::RepeatTile:
+ dy = sourceCenterHeight;
+ break;
+ case Qt::RoundTile:
+ dy = targetCenterHeight / qreal(rows - 2);
+ break;
+ }
+
+ for (int i = 2; i < rows - 1; ++i)
+ yTarget[i] = yTarget[i - 1] + dy;
+
// corners
if (targetMargins.top() > 0 && targetMargins.left() > 0 && sourceMargins.top() > 0 && sourceMargins.left() > 0) { // top left
- const QRect targetTopLeftRect(targetLeft, targetTop, targetMargins.left(), targetMargins.top());
- const QRect sourceTopLeftRect(sourceLeft, sourceTop, sourceMargins.left(), sourceMargins.top());
- qDrawPixmap(painter, targetTopLeftRect, pixmap, sourceTopLeftRect);
+ d.point.setX(0.5 * (xTarget[1] + xTarget[0]));
+ d.point.setY(0.5 * (yTarget[1] + yTarget[0]));
+ d.source = QRectF(sourceRect.left(), sourceRect.top(), sourceMargins.left(), sourceMargins.top());
+ d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width();
+ d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height();
+ if (hints & QDrawBorderPixmap::OpaqueTopLeft)
+ opaqueData.append(d);
+ else
+ translucentData.append(d);
}
if (targetMargins.top() > 0 && targetMargins.right() > 0 && sourceMargins.top() > 0 && sourceMargins.right() > 0) { // top right
- const QRect targetTopRightRect(targetCenterRight, targetTop, targetMargins.right(), targetMargins.top());
- const QRect sourceTopRightRect(sourceCenterRight, sourceTop, sourceMargins.right(), sourceMargins.top());
- qDrawPixmap(painter, targetTopRightRect, pixmap, sourceTopRightRect);
+ d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1]));
+ d.point.setY(0.5 * (yTarget[1] + yTarget[0]));
+ d.source = QRectF(sourceCenterRight, sourceRect.top(), sourceMargins.right(), sourceMargins.top());
+ d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width();
+ d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height();
+ if (hints & QDrawBorderPixmap::OpaqueTopRight)
+ opaqueData.append(d);
+ else
+ translucentData.append(d);
}
if (targetMargins.bottom() > 0 && targetMargins.left() > 0 && sourceMargins.bottom() > 0 && sourceMargins.left() > 0) { // bottom left
- const QRect targetBottomLeftRect(targetLeft, targetCenterBottom, targetMargins.left(), targetMargins.bottom());
- const QRect sourceBottomLeftRect(sourceLeft, sourceCenterBottom, sourceMargins.left(), sourceMargins.bottom());
- qDrawPixmap(painter, targetBottomLeftRect, pixmap, sourceBottomLeftRect);
+ d.point.setX(0.5 * (xTarget[1] + xTarget[0]));
+ d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1]));
+ d.source = QRectF(sourceRect.left(), sourceCenterBottom, sourceMargins.left(), sourceMargins.bottom());
+ d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width();
+ d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height();
+ if (hints & QDrawBorderPixmap::OpaqueBottomLeft)
+ opaqueData.append(d);
+ else
+ translucentData.append(d);
}
if (targetMargins.bottom() > 0 && targetMargins.right() > 0 && sourceMargins.bottom() > 0 && sourceMargins.right() > 0) { // bottom right
- const QRect targetBottomRightRect(targetCenterRight, targetCenterBottom, targetMargins.right(), targetMargins.bottom());
- const QRect sourceBottomRightRect(sourceCenterRight, sourceCenterBottom, sourceMargins.right(), sourceMargins.bottom());
- qDrawPixmap(painter, targetBottomRightRect, pixmap, sourceBottomRightRect);
+ d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1]));
+ d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1]));
+ d.source = QRectF(sourceCenterRight, sourceCenterBottom, sourceMargins.right(), sourceMargins.bottom());
+ d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width();
+ d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height();
+ if (hints & QDrawBorderPixmap::OpaqueBottomRight)
+ opaqueData.append(d);
+ else
+ translucentData.append(d);
}
// horizontal edges
- switch (rules.horizontal) {
- case Qt::StretchTile:
+ if (targetCenterWidth > 0 && sourceCenterWidth > 0) {
if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
- const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top());
- const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top());
- qDrawPixmap(painter, targetTopRect, pixmap, sourceTopRect);
- }
- if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
- const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom());
- const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());
- qDrawPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
- }
- break;
- case Qt::RepeatTile:
- if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
- const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top());
- const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top());
- qDrawHorizontallyRepeatedPixmap(painter, targetTopRect, pixmap, sourceTopRect);
- }
- if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
- const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom());
- const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());
- qDrawHorizontallyRepeatedPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
- }
- break;
- case Qt::RoundTile:
- if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
- const QRect targetTopRect(targetCenterLeft, targetTop, targetCenterWidth, targetMargins.top());
- const QRect sourceTopRect(sourceCenterLeft, sourceTop, sourceCenterWidth, sourceMargins.top());
- qDrawHorizontallyRoundedPixmap(painter, targetTopRect, pixmap, sourceTopRect);
+ QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueTop ? opaqueData : translucentData;
+ d.source = QRectF(sourceCenterLeft, sourceRect.top(), sourceCenterWidth, sourceMargins.top());
+ d.point.setY(0.5 * (yTarget[1] + yTarget[0]));
+ d.scaleX = dx / d.source.width();
+ d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height();
+ for (int i = 1; i < columns - 1; ++i) {
+ d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));
+ data.append(d);
+ }
+ if (rules.horizontal == Qt::RepeatTile)
+ data[data.size() - 1].source.setWidth((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX);
}
if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
- const QRect targetBottomRect(targetCenterLeft, targetCenterBottom, targetCenterWidth, targetMargins.bottom());
- const QRect sourceBottomRect(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());
- qDrawHorizontallyRoundedPixmap(painter, targetBottomRect, pixmap, sourceBottomRect);
+ QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueBottom ? opaqueData : translucentData;
+ d.source = QRectF(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());;
+ d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1]));
+ d.scaleX = dx / d.source.width();
+ d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height();
+ for (int i = 1; i < columns - 1; ++i) {
+ d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));
+ data.append(d);
+ }
+ if (rules.horizontal == Qt::RepeatTile)
+ data[data.size() - 1].source.setWidth((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX);
}
- break;
}
// vertical edges
- switch (rules.vertical) {
- case Qt::StretchTile:
- if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
- const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left(), targetCenterHeight);
- const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
- qDrawPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
- }
- if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
- const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right(), targetCenterHeight);
- const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
- qDrawPixmap(painter, targetRightRect, pixmap, sourceRightRect);
- }
- break;
- case Qt::RepeatTile:
- if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
- const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left(), targetCenterHeight);
- const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
- qDrawVerticallyRepeatedPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
- }
- if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
- const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right(), targetCenterHeight);
- const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
- qDrawVerticallyRepeatedPixmap(painter, targetRightRect, pixmap, sourceRightRect);
- }
- break;
- case Qt::RoundTile:
+ if (targetCenterHeight > 0 && sourceCenterHeight > 0) {
if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
- const QRect targetLeftRect(targetLeft, targetCenterTop, targetMargins.left(), targetCenterHeight);
- const QRect sourceLeftRect(sourceLeft, sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
- qDrawVerticallyRoundedPixmap(painter, targetLeftRect, pixmap, sourceLeftRect);
+ QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueLeft ? opaqueData : translucentData;
+ d.source = QRectF(sourceRect.left(), sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
+ d.point.setX(0.5 * (xTarget[1] + xTarget[0]));
+ d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width();
+ d.scaleY = dy / d.source.height();
+ for (int i = 1; i < rows - 1; ++i) {
+ d.point.setY(0.5 * (yTarget[i + 1] + yTarget[i]));
+ data.append(d);
+ }
+ if (rules.vertical == Qt::RepeatTile)
+ data[data.size() - 1].source.setHeight((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY);
}
if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
- const QRect targetRightRect(targetCenterRight, targetCenterTop, targetMargins.right(), targetCenterHeight);
- const QRect sourceRightRect(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
- qDrawVerticallyRoundedPixmap(painter, targetRightRect, pixmap, sourceRightRect);
+ QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueRight ? opaqueData : translucentData;
+ d.source = QRectF(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
+ d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1]));
+ d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width();
+ d.scaleY = dy / d.source.height();
+ for (int i = 1; i < rows - 1; ++i) {
+ d.point.setY(0.5 * (yTarget[i + 1] + yTarget[i]));
+ data.append(d);
+ }
+ if (rules.vertical == Qt::RepeatTile)
+ data[data.size() - 1].source.setHeight((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY);
}
- break;
}
// center
if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) {
- const QRect targetCenterRect(targetCenterLeft, targetCenterTop, targetCenterWidth, targetCenterHeight);
- const QRect sourceCenterRect(sourceCenterLeft, sourceCenterTop, sourceCenterWidth, sourceCenterHeight);
- switch (rules.horizontal) {
- case Qt::StretchTile:
- switch (rules.vertical) {
- case Qt::StretchTile: // stretch stretch
- qDrawPixmap(painter, targetCenterRect, pixmap, sourceCenterRect);
- break;
- case Qt::RepeatTile: // stretch repeat
- qVerticalRepeat(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
- break;
- case Qt::RoundTile: // stretch round
- qVerticalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
- break;
+ QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueCenter ? opaqueData : translucentData;
+ d.source = QRectF(sourceCenterLeft, sourceCenterTop, sourceCenterWidth, sourceCenterHeight);
+ d.scaleX = dx / d.source.width();
+ d.scaleY = dy / d.source.height();
+
+ qreal repeatWidth = (xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX;
+ qreal repeatHeight = (yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY;
+
+ for (int j = 1; j < rows - 1; ++j) {
+ d.point.setY(0.5 * (yTarget[j + 1] + yTarget[j]));
+ for (int i = 1; i < columns - 1; ++i) {
+ d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));
+ data.append(d);
}
- break;
- case Qt::RepeatTile:
- switch (rules.vertical) {
- case Qt::StretchTile: // repeat stretch
- qHorizontalRepeat(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
- break;
- case Qt::RepeatTile: // repeat repeat
- qVerticalRepeat(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawHorizontallyRepeatedPixmap);
- break;
- case Qt::RoundTile: // repeat round
- qVerticalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawHorizontallyRepeatedPixmap);
- break;
- }
- break;
- case Qt::RoundTile:
- switch (rules.vertical) {
- case Qt::StretchTile: // round stretch
- qHorizontalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawPixmap);
- break;
- case Qt::RepeatTile: // round repeat
- qHorizontalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawVerticallyRepeatedPixmap);
- break;
- case Qt::RoundTile: // round round
- qHorizontalRound(painter, targetCenterRect, pixmap, sourceCenterRect, qDrawVerticallyRoundedPixmap);
- break;
- }
- break;
+ if (rules.horizontal == Qt::RepeatTile)
+ data[data.size() - 1].source.setWidth(repeatWidth);
+ }
+ if (rules.vertical == Qt::RepeatTile) {
+ for (int i = 1; i < columns - 1; ++i)
+ data[data.size() - i].source.setHeight(repeatHeight);
}
}
+
+ if (opaqueData.size())
+ qDrawPixmaps(painter, opaqueData.data(), opaqueData.size(), pixmap, QDrawPixmaps::OpaqueHint);
+ if (translucentData.size())
+ qDrawPixmaps(painter, translucentData.data(), translucentData.size(), pixmap);
}
/*!
- \struct QDrawPixmapsData
+ \class QDrawPixmaps::Data
\since 4.6
\internal
@@ -1369,6 +1334,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
*/
/*!
+ \enum QDrawPixmaps::DrawingHint
+ \internal
+*/
+
+/*!
\internal
\since 4.6
@@ -1377,14 +1347,14 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
dataCount elements specifying the parameters used to draw each pixmap instance.
This can be used for example to implement a particle system.
*/
-void qDrawPixmaps(QPainter *painter, const QDrawPixmapsData *drawingData, int dataCount, const QPixmap &pixmap)
+void qDrawPixmaps(QPainter *painter, const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints)
{
QPaintEngine *engine = painter->paintEngine();
if (!engine)
return;
if (engine->isExtended()) {
- static_cast<QPaintEngineEx *>(engine)->drawPixmaps(drawingData, dataCount, pixmap);
+ static_cast<QPaintEngineEx *>(engine)->drawPixmaps(drawingData, dataCount, pixmap, hints);
} else {
qreal oldOpacity = painter->opacity();
QTransform oldTransform = painter->transform();
diff --git a/src/gui/painting/qdrawutil.h b/src/gui/painting/qdrawutil.h
index 98a36a7..fff1cc1 100644
--- a/src/gui/painting/qdrawutil.h
+++ b/src/gui/painting/qdrawutil.h
@@ -143,13 +143,43 @@ struct QTileRules
Qt::TileRule vertical;
};
+#ifndef Q_QDOC
+// For internal use only.
+namespace QDrawBorderPixmap
+{
+ enum DrawingHint
+ {
+ OpaqueTopLeft = 0x0001,
+ OpaqueTop = 0x0002,
+ OpaqueTopRight = 0x0004,
+ OpaqueLeft = 0x0008,
+ OpaqueCenter = 0x0010,
+ OpaqueRight = 0x0020,
+ OpaqueBottomLeft = 0x0040,
+ OpaqueBottom = 0x0080,
+ OpaqueBottomRight = 0x0100,
+ OpaqueCorners = OpaqueTopLeft | OpaqueTopRight | OpaqueBottomLeft | OpaqueBottomRight,
+ OpaqueEdges = OpaqueTop | OpaqueLeft | OpaqueRight | OpaqueBottom,
+ OpaqueFrame = OpaqueCorners | OpaqueEdges,
+ OpaqueAll = OpaqueCenter | OpaqueFrame
+ };
+
+ Q_DECLARE_FLAGS(DrawingHints, DrawingHint)
+}
+#endif
+
Q_GUI_EXPORT void qDrawBorderPixmap(QPainter *painter,
const QRect &targetRect,
const QMargins &targetMargins,
const QPixmap &pixmap,
const QRect &sourceRect,
const QMargins &sourceMargins,
- const QTileRules &rules = QTileRules());
+ const QTileRules &rules = QTileRules()
+#ifndef Q_QDOC
+ , QDrawBorderPixmap::DrawingHints hints = 0
+#endif
+ );
+
inline void qDrawBorderPixmap(QPainter *painter,
const QRect &target,
const QMargins &margins,
@@ -158,17 +188,30 @@ inline void qDrawBorderPixmap(QPainter *painter,
qDrawBorderPixmap(painter, target, margins, pixmap, pixmap.rect(), margins);
}
-struct QDrawPixmapsData
+// For internal use only.
+namespace QDrawPixmaps
{
- QPointF point;
- QRectF source;
- qreal scaleX;
- qreal scaleY;
- qreal rotation;
- qreal opacity;
-};
+ struct Data
+ {
+ QPointF point;
+ QRectF source;
+ qreal scaleX;
+ qreal scaleY;
+ qreal rotation;
+ qreal opacity;
+ };
+
+ enum DrawingHint
+ {
+ OpaqueHint = 0x01
+ };
+
+ Q_DECLARE_FLAGS(DrawingHints, DrawingHint)
+}
-Q_GUI_EXPORT void qDrawPixmaps(QPainter *painter, const QDrawPixmapsData *drawingData, int dataCount, const QPixmap &pixmap);
+// This function is private and may change without notice. Do not use outside Qt!!!
+Q_GUI_EXPORT void qDrawPixmaps(QPainter *painter, const QDrawPixmaps::Data *drawingData,
+ int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints = 0);
QT_END_NAMESPACE
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
index 2342b9d..d712669 100644
--- a/src/gui/painting/qpaintengineex.cpp
+++ b/src/gui/painting/qpaintengineex.cpp
@@ -932,7 +932,7 @@ void QPaintEngineEx::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, con
fill(path, brush);
}
-void QPaintEngineEx::drawPixmaps(const QDrawPixmapsData *drawingData, int dataCount, const QPixmap &pixmap)
+void QPaintEngineEx::drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints)
{
qreal oldOpacity = state()->opacity;
QTransform oldTransform = state()->matrix;
diff --git a/src/gui/painting/qpaintengineex_p.h b/src/gui/painting/qpaintengineex_p.h
index 42c1ce9..81ed06b 100644
--- a/src/gui/painting/qpaintengineex_p.h
+++ b/src/gui/painting/qpaintengineex_p.h
@@ -70,7 +70,12 @@ QT_MODULE(Gui)
class QPainterState;
class QPaintEngineExPrivate;
struct StrokeHandler;
-struct QDrawPixmapsData;
+
+namespace QDrawPixmaps
+{
+ struct Data;
+ enum DrawingHint;
+}
struct QIntRect {
int x1, y1, x2, y2;
@@ -196,7 +201,7 @@ public:
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
- virtual void drawPixmaps(const QDrawPixmapsData *drawingData, int dataCount, const QPixmap &pixmap);
+ virtual void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QFlags<QDrawPixmaps::DrawingHint> hints);
virtual void updateState(const QPaintEngineState &state);
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index 12a8ed8..992d47d 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -1428,11 +1428,11 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, QFontEngineGly
glDrawArrays(GL_TRIANGLES, 0, 6 * glyphs.size());
}
-void QGL2PaintEngineEx::drawPixmaps(const QDrawPixmapsData *drawingData, int dataCount, const QPixmap &pixmap)
+void QGL2PaintEngineEx::drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints)
{
// Use fallback for extended composition modes.
if (state()->composition_mode > QPainter::CompositionMode_Plus) {
- QPaintEngineEx::drawPixmaps(drawingData, dataCount, pixmap);
+ QPaintEngineEx::drawPixmaps(drawingData, dataCount, pixmap, hints);
return;
}
@@ -1448,11 +1448,15 @@ void QGL2PaintEngineEx::drawPixmaps(const QDrawPixmapsData *drawingData, int dat
bool allOpaque = true;
for (int i = 0; i < dataCount; ++i) {
- qreal s = 0.5 * qSin(drawingData[i].rotation * Q_PI / 180);
- qreal c = 0.5 * qCos(drawingData[i].rotation * Q_PI / 180);
+ qreal s = 0;
+ qreal c = 1;
+ if (drawingData[i].rotation != 0) {
+ s = qFastSin(drawingData[i].rotation * Q_PI / 180);
+ c = qFastCos(drawingData[i].rotation * Q_PI / 180);
+ }
- qreal right = drawingData[i].scaleX * drawingData[i].source.width();
- qreal bottom = drawingData[i].scaleY * drawingData[i].source.height();
+ qreal right = 0.5 * drawingData[i].scaleX * drawingData[i].source.width();
+ qreal bottom = 0.5 * drawingData[i].scaleY * drawingData[i].source.height();
QGLPoint bottomRight(right * c - bottom * s, right * s + bottom * c);
QGLPoint bottomLeft(-right * c - bottom * s, -right * s + bottom * c);
@@ -1496,7 +1500,7 @@ void QGL2PaintEngineEx::drawPixmaps(const QDrawPixmapsData *drawingData, int dat
d->transferMode(ImageArrayDrawingMode);
bool isBitmap = pixmap.isQBitmap();
- bool isOpaque = !isBitmap && !pixmap.hasAlphaChannel() && allOpaque;
+ bool isOpaque = !isBitmap && (!pixmap.hasAlphaChannel() || (hints & QDrawPixmaps::OpaqueHint)) && allOpaque;
d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE,
state()->renderHints & QPainter::SmoothPixmapTransform, texture->id);
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
index 9d40726..4f42082 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
@@ -128,7 +128,7 @@ public:
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
- virtual void drawPixmaps(const QDrawPixmapsData *drawingData, int dataCount, const QPixmap &pixmap);
+ virtual void drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints hints);
Type type() const { return OpenGL2; }