summaryrefslogtreecommitdiff
path: root/src/gui/painting/qdrawutil.cpp
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-09-29 17:08:41 +0200
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-10-02 17:57:17 +0200
commit385176ad28b3a79bcd196d2d529c4bf7abd4fcc0 (patch)
treee50e39712472bc672308dac1770261587b3f98b6 /src/gui/painting/qdrawutil.cpp
parent4f7d94ca73556f3a40631ad07f565995f6f85176 (diff)
downloadqt4-tools-385176ad28b3a79bcd196d2d529c4bf7abd4fcc0.tar.gz
Added support for drawing a pixmap multiple times in one call.
This is internal API. It's possible to specify a horizontal and vertical scale, rotation, opacity and source rectangle for each pixmap item. Useful for particle effects. Reviewed-by: Trond
Diffstat (limited to 'src/gui/painting/qdrawutil.cpp')
-rw-r--r--src/gui/painting/qdrawutil.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp
index ac3796aa5d..4f17e5929a 100644
--- a/src/gui/painting/qdrawutil.cpp
+++ b/src/gui/painting/qdrawutil.cpp
@@ -45,6 +45,7 @@
#include "qapplication.h"
#include "qpainter.h"
#include "qpalette.h"
+#include <private/qpaintengineex_p.h>
QT_BEGIN_NAMESPACE
@@ -1351,4 +1352,58 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
}
}
+/*!
+ \struct QDrawPixmapsData
+ \since 4.6
+ \internal
+
+ This structure is used with the qDrawPixmaps() function.
+
+ QPointF point: Specifies the center of the target rectangle.
+ QRectF source: Specifies the source rectangle in the pixmap passed into the qDrawPixmaps() call.
+ qreal scaleX: Specifies the horizontal scale of the target rectangle.
+ qreal scaleY: Specifies the vertical scale of the target rectangle.
+ qreal rotation: Specifies the rotation of the target rectangle in degrees.
+ The target rectangle is rotated after scaling.
+ qreal opacity: Specifies the opacity of the rectangle.
+*/
+
+/*!
+ \internal
+ \since 4.6
+
+ This function is used to draw \a pixmap, or a sub-rectangle of \a pixmap, at multiple positions
+ with different scale, rotation and opacity on \a painter. \a drawingData is an array of \a
+ 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)
+{
+ QPaintEngine *engine = painter->paintEngine();
+ if (!engine)
+ return;
+
+ if (engine->isExtended()) {
+ static_cast<QPaintEngineEx *>(engine)->drawPixmaps(drawingData, dataCount, pixmap);
+ } else {
+ qreal oldOpacity = painter->opacity();
+ QTransform oldTransform = painter->transform();
+
+ for (int i = 0; i < dataCount; ++i) {
+ QTransform transform = oldTransform;
+ transform.translate(drawingData[i].point.x(), drawingData[i].point.y());
+ transform.rotate(drawingData[i].rotation);
+ painter->setOpacity(oldOpacity * drawingData[i].opacity);
+ painter->setTransform(transform);
+
+ qreal w = drawingData[i].scaleX * drawingData[i].source.width();
+ qreal h = drawingData[i].scaleY * drawingData[i].source.height();
+ painter->drawPixmap(QRectF(-0.5 * w, -0.5 * h, w, h), pixmap, drawingData[i].source);
+ }
+
+ painter->setOpacity(oldOpacity);
+ painter->setTransform(oldTransform);
+ }
+}
+
QT_END_NAMESPACE