src/gui/painting/qpaintengineex.cpp
changeset 30 5dc02b23752f
parent 22 79de32ba3296
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   147  *
   147  *
   148  */
   148  */
   149 
   149 
   150 
   150 
   151 struct StrokeHandler {
   151 struct StrokeHandler {
       
   152     StrokeHandler(int reserve) : pts(reserve), types(reserve) {}
   152     QDataBuffer<qreal> pts;
   153     QDataBuffer<qreal> pts;
   153     QDataBuffer<QPainterPath::ElementType> types;
   154     QDataBuffer<QPainterPath::ElementType> types;
   154 };
   155 };
   155 
   156 
   156 
   157 
   392 
   393 
   393     if (path.isEmpty())
   394     if (path.isEmpty())
   394         return;
   395         return;
   395 
   396 
   396     if (!d->strokeHandler) {
   397     if (!d->strokeHandler) {
   397         d->strokeHandler = new StrokeHandler;
   398         d->strokeHandler = new StrokeHandler(path.elementCount()+4);
   398         d->stroker.setMoveToHook(qpaintengineex_moveTo);
   399         d->stroker.setMoveToHook(qpaintengineex_moveTo);
   399         d->stroker.setLineToHook(qpaintengineex_lineTo);
   400         d->stroker.setLineToHook(qpaintengineex_lineTo);
   400         d->stroker.setCubicToHook(qpaintengineex_cubicTo);
   401         d->stroker.setCubicToHook(qpaintengineex_cubicTo);
   401     }
   402     }
   402 
   403 
   458     if (!pen.isCosmetic()) {
   459     if (!pen.isCosmetic()) {
   459         // We include cosmetic pens in this case to avoid having to
   460         // We include cosmetic pens in this case to avoid having to
   460         // change the current transform. Normal transformed,
   461         // change the current transform. Normal transformed,
   461         // non-cosmetic pens will be transformed as part of fill
   462         // non-cosmetic pens will be transformed as part of fill
   462         // later, so they are also covered here..
   463         // later, so they are also covered here..
       
   464         d->activeStroker->setCurveThresholdFromTransform(state()->matrix);
   463         d->activeStroker->begin(d->strokeHandler);
   465         d->activeStroker->begin(d->strokeHandler);
   464         if (types) {
   466         if (types) {
   465             while (points < lastPoint) {
   467             while (points < lastPoint) {
   466                 switch (*types) {
   468                 switch (*types) {
   467                 case QPainterPath::MoveToElement:
   469                 case QPainterPath::MoveToElement:
   515         // For cosmetic pens we need a bit of trickery... We to process xform the input points
   517         // For cosmetic pens we need a bit of trickery... We to process xform the input points
   516         if (state()->matrix.type() >= QTransform::TxProject) {
   518         if (state()->matrix.type() >= QTransform::TxProject) {
   517             QPainterPath painterPath = state()->matrix.map(path.convertToPainterPath());
   519             QPainterPath painterPath = state()->matrix.map(path.convertToPainterPath());
   518             d->activeStroker->strokePath(painterPath, d->strokeHandler, QTransform());
   520             d->activeStroker->strokePath(painterPath, d->strokeHandler, QTransform());
   519         } else {
   521         } else {
       
   522             d->activeStroker->setCurveThresholdFromTransform(state()->matrix);
   520             d->activeStroker->begin(d->strokeHandler);
   523             d->activeStroker->begin(d->strokeHandler);
   521             if (types) {
   524             if (types) {
   522                 while (points < lastPoint) {
   525                 while (points < lastPoint) {
   523                     switch (*types) {
   526                     switch (*types) {
   524                     case QPainterPath::MoveToElement: {
   527                     case QPainterPath::MoveToElement: {
   605 
   608 
   606 void QPaintEngineEx::clip(const QRect &r, Qt::ClipOperation op)
   609 void QPaintEngineEx::clip(const QRect &r, Qt::ClipOperation op)
   607 {
   610 {
   608     qreal right = r.x() + r.width();
   611     qreal right = r.x() + r.width();
   609     qreal bottom = r.y() + r.height();
   612     qreal bottom = r.y() + r.height();
   610     qreal pts[] = { r.x(), r.y(),
   613     qreal pts[] = { qreal(r.x()), qreal(r.y()),
   611                     right, r.y(),
   614                     right, qreal(r.y()),
   612                     right, bottom,
   615                     right, bottom,
   613                     r.x(), bottom,
   616                     qreal(r.x()), bottom,
   614                     r.x(), r.y() };
   617                     qreal(r.x()), qreal(r.y()) };
   615     QVectorPath vp(pts, 5, 0, QVectorPath::RectangleHint);
   618     QVectorPath vp(pts, 5, 0, QVectorPath::RectangleHint);
   616     clip(vp, op);
   619     clip(vp, op);
   617 }
   620 }
   618 
   621 
   619 void QPaintEngineEx::clip(const QRegion &region, Qt::ClipOperation op)
   622 void QPaintEngineEx::clip(const QRegion &region, Qt::ClipOperation op)
   709     for (int i=0; i<rectCount; ++i) {
   712     for (int i=0; i<rectCount; ++i) {
   710         const QRect &r = rects[i];
   713         const QRect &r = rects[i];
   711         // ### Is there a one off here?
   714         // ### Is there a one off here?
   712         qreal right = r.x() + r.width();
   715         qreal right = r.x() + r.width();
   713         qreal bottom = r.y() + r.height();
   716         qreal bottom = r.y() + r.height();
   714         qreal pts[] = { r.x(), r.y(),
   717         qreal pts[] = { qreal(r.x()), qreal(r.y()),
   715                         right, r.y(),
   718                         right, qreal(r.y()),
   716                         right, bottom,
   719                         right, bottom,
   717                         r.x(), bottom,
   720                         qreal(r.x()), bottom,
   718                         r.x(), r.y() };
   721                         qreal(r.x()), qreal(r.y()) };
   719         QVectorPath vp(pts, 5, 0, QVectorPath::RectangleHint);
   722         QVectorPath vp(pts, 5, 0, QVectorPath::RectangleHint);
   720         draw(vp);
   723         draw(vp);
   721     }
   724     }
   722 }
   725 }
   723 
   726 
   891             qreal pts[64];
   894             qreal pts[64];
   892             int oset = -1;
   895             int oset = -1;
   893             for (int i=0; i<count; ++i) {
   896             for (int i=0; i<count; ++i) {
   894                 pts[++oset] = points[i].x();
   897                 pts[++oset] = points[i].x();
   895                 pts[++oset] = points[i].y();
   898                 pts[++oset] = points[i].y();
   896                 pts[++oset] = points[i].x() + 1/63;
   899                 pts[++oset] = points[i].x() + 1/63.;
   897                 pts[++oset] = points[i].y();
   900                 pts[++oset] = points[i].y();
   898             }
   901             }
   899             QVectorPath path(pts, count * 2, qpaintengineex_line_types_16, QVectorPath::LinesHint);
   902             QVectorPath path(pts, count * 2, qpaintengineex_line_types_16, QVectorPath::LinesHint);
   900             stroke(path, pen);
   903             stroke(path, pen);
   901             pointCount -= 16;
   904             pointCount -= 16;
   902             points += 16;
   905             points += 16;
   903         }
   906         }
   904     } else {
   907     } else {
   905         for (int i=0; i<pointCount; ++i) {
   908         for (int i=0; i<pointCount; ++i) {
   906             qreal pts[] = { points[i].x(), points[i].y(), points[i].x() +1/63., points[i].y() };
   909             qreal pts[] = { qreal(points[i].x()), qreal(points[i].y()),
       
   910                             qreal(points[i].x() +1/63.), qreal(points[i].y()) };
   907             QVectorPath path(pts, 2, 0);
   911             QVectorPath path(pts, 2, 0);
   908             stroke(path, pen);
   912             stroke(path, pen);
   909         }
   913         }
   910     }
   914     }
   911 }
   915 }
   968 
   972 
   969     QVectorPath path(pts, 4, 0, QVectorPath::RectangleHint);
   973     QVectorPath path(pts, 4, 0, QVectorPath::RectangleHint);
   970     fill(path, brush);
   974     fill(path, brush);
   971 }
   975 }
   972 
   976 
   973 void QPaintEngineEx::drawPixmaps(const QDrawPixmaps::Data *drawingData, int dataCount, const QPixmap &pixmap, QDrawPixmaps::DrawingHints /*hints*/)
   977 void QPaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount,
   974 {
   978                                          const QPixmap &pixmap, QPainter::PixmapFragmentHints /*hints*/)
       
   979 {
       
   980     if (pixmap.isNull())
       
   981         return;
       
   982 
   975     qreal oldOpacity = state()->opacity;
   983     qreal oldOpacity = state()->opacity;
   976     QTransform oldTransform = state()->matrix;
   984     QTransform oldTransform = state()->matrix;
   977 
   985 
   978     for (int i = 0; i < dataCount; ++i) {
   986     for (int i = 0; i < fragmentCount; ++i) {
   979         QTransform transform = oldTransform;
   987         QTransform transform = oldTransform;
   980         transform.translate(drawingData[i].point.x(), drawingData[i].point.y());
   988         transform.translate(fragments[i].x, fragments[i].y);
   981         transform.rotate(drawingData[i].rotation);
   989         transform.rotate(fragments[i].rotation);
   982         state()->opacity = oldOpacity * drawingData[i].opacity;
   990         state()->opacity = oldOpacity * fragments[i].opacity;
   983         state()->matrix = transform;
   991         state()->matrix = transform;
   984         opacityChanged();
   992         opacityChanged();
   985         transformChanged();
   993         transformChanged();
   986 
   994 
   987         qreal w = drawingData[i].scaleX * drawingData[i].source.width();
   995         qreal w = fragments[i].scaleX * fragments[i].width;
   988         qreal h = drawingData[i].scaleY * drawingData[i].source.height();
   996         qreal h = fragments[i].scaleY * fragments[i].height;
   989         drawPixmap(QRectF(-0.5 * w, -0.5 * h, w, h), pixmap, drawingData[i].source);
   997         QRectF sourceRect(fragments[i].sourceLeft, fragments[i].sourceTop,
       
   998                           fragments[i].width, fragments[i].height);
       
   999         drawPixmap(QRectF(-0.5 * w, -0.5 * h, w, h), pixmap, sourceRect);
   990     }
  1000     }
   991 
  1001 
   992     state()->opacity = oldOpacity;
  1002     state()->opacity = oldOpacity;
   993     state()->matrix = oldTransform;
  1003     state()->matrix = oldTransform;
   994     opacityChanged();
  1004     opacityChanged();