diff options
author | Timothy Pearson <[email protected]> | 2012-09-17 11:49:39 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2012-09-17 11:49:39 -0500 |
commit | b6cb4612ca9c615323c0540a3b05edc24feec642 (patch) | |
tree | 7c14ed41a50285e015d351a8b2029aba9d6e7f4b /tdegtk/tqtcairopainter.cpp | |
parent | 52cddfb3039519e7745e770b5198ff43cb9d195f (diff) | |
download | gtk3-tqt-engine-b6cb4612ca9c615323c0540a3b05edc24feec642.tar.gz gtk3-tqt-engine-b6cb4612ca9c615323c0540a3b05edc24feec642.zip |
Add transformation support
Diffstat (limited to 'tdegtk/tqtcairopainter.cpp')
-rw-r--r-- | tdegtk/tqtcairopainter.cpp | 126 |
1 files changed, 104 insertions, 22 deletions
diff --git a/tdegtk/tqtcairopainter.cpp b/tdegtk/tqtcairopainter.cpp index 05e9a0a..2f16d11 100644 --- a/tdegtk/tqtcairopainter.cpp +++ b/tdegtk/tqtcairopainter.cpp @@ -680,6 +680,23 @@ void TQt3CairoPaintDevice::drawText(TQPainter *p, int x, int y, const TQString & g_object_unref(layout); } +void TQt3CairoPaintDevice::setCairoTransformations() { + cairo_matrix_t combinedMatrix; + cairo_matrix_t tempMatrix; + + cairo_matrix_init_identity(&combinedMatrix); + if (m_worldMatrixEnabled) { + cairo_matrix_multiply(&tempMatrix, &combinedMatrix, &m_worldMatrix); + combinedMatrix = tempMatrix; + } + if (m_viewportMatrixEnabled) { + cairo_matrix_multiply(&tempMatrix, &combinedMatrix, &m_viewportMatrix); + combinedMatrix = tempMatrix; + } + + cairo_set_matrix(m_painter, &combinedMatrix); +} + /*! \class TQt3CairoPaintDevice tdeqt4painter.h \brief The TQt3CairoPaintDevice class is a paint device that translates @@ -927,13 +944,20 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) cairo_restore(m_painter); } break; -#if 0 case PdcDrawText: - // NOTE - // drawText baseline = FALSE for this! - m_qt4painter->drawText( qt4point1, qt4string ); + if (m_painter) { + cairo_save(m_painter); + if (p) { + TQString string = *p[1].str; + drawText(pt, p[0].rect->x()+CAIRO_PIXEL_OFFSET, p[0].rect->y()+CAIRO_PIXEL_OFFSET, string, 0, -1, TQPainter::Auto, TRUE); + } + cairo_restore(m_painter); + } break; +#if 0 case PdcDrawTextFormatted: + // NOTE + // Unlike PdcDrawText and PdcDrawText2, PdcDrawTextFormatted and PdcDrawText2Formatted do NOT use the baseline as the Y position coordinate! m_qt4painter->drawText( qt4rect, qt4formattedtextflags, qt4string ); break; #endif @@ -944,14 +968,27 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) TQString string = *p[1].str; drawText(pt, p[0].rect->x()+CAIRO_PIXEL_OFFSET, p[0].rect->y()+CAIRO_PIXEL_OFFSET, string, 0, -1, TQPainter::Auto, TRUE); } + cairo_restore(m_painter); } break; #if 0 case PdcDrawText2Formatted: m_qt4painter->drawText( qt4rect, qt4formattedtextflags, qt4string ); break; +#endif case PdcDrawPixmap: - m_qt4painter->drawPixmap( qt4rect, qt4pixmap ); + if (m_painter) { + cairo_save(m_painter); + if (p) { + TQImage sourceImage = p[1].pixmap->convertToImage(); + cairo_surface_t* sourceSurface = TQImageToCairoSurface(sourceImage); + cairo_rectangle(m_painter, p[0].rect->x(), p[0].rect->y(), p[0].rect->width(), p[0].rect->height()); + cairo_set_source_surface(m_painter, sourceSurface, p[0].rect->x(), p[0].rect->y()); + cairo_fill(m_painter); + cairo_surface_destroy(sourceSurface); + } + cairo_restore(m_painter); + } break; #if 0 case PdcDrawImage: { @@ -966,7 +1003,6 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) } break; #endif -#endif case PdcBegin: if (!m_painter) { m_bgColor = TQColor(0,0,0); @@ -975,6 +1011,11 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) m_pen = TQPen(); m_brush = TQBrush(); m_brushOrigin = TQPoint(0,0); + m_worldMatrixEnabled = false; + m_viewportMatrixEnabled = false; + cairo_matrix_init_identity(&m_worldMatrix); + cairo_matrix_init_identity(&m_viewportMatrix); + setCairoTransformations(); } break; case PdcEnd: @@ -1098,7 +1139,6 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) } break; #if 0 -#if 0 case PdcSetTabStops: s >> i_16; painter->setTabStops( i_16 ); @@ -1118,32 +1158,74 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p ) delete [] ta; } break; - case PdcSetVXform: - s >> i_8; -#ifndef QT_NO_TRANSFORMATIONS - painter->setViewXForm( i_8 ); #endif + case PdcSetVXform: + if ((p) && (m_painter)) { + m_viewportMatrixEnabled = p[0].ival; + setCairoTransformations(); + } break; case PdcSetWindow: - s >> r; -#ifndef QT_NO_TRANSFORMATIONS - painter->setWindow( r ); -#endif + if ((p) && (m_painter) && (pt)) { + TQRect viewportRect = pt->viewport(); + int wx = p[0].rect->x(); + int wy = p[0].rect->y(); + int ww = p[0].rect->width(); + int wh = p[0].rect->height(); + int vx = viewportRect.x(); + int vy = viewportRect.y(); + int vw = viewportRect.width(); + int vh = viewportRect.height(); + double scaleW = (double)vw/(double)ww; + double scaleH = (double)vh/(double)wh; + cairo_matrix_init(&m_viewportMatrix, scaleW, 0, 0, scaleH, vx - wx*scaleW, vy - wy*scaleH); + setCairoTransformations(); + } break; case PdcSetViewport: - s >> r; -#ifndef QT_NO_TRANSFORMATIONS - painter->setViewport( r ); -#endif + if ((p) && (m_painter) && (pt)) { + TQRect windowRect = pt->window(); + int wx = windowRect.x(); + int wy = windowRect.y(); + int ww = windowRect.width(); + int wh = windowRect.height(); + int vx = p[0].rect->x(); + int vy = p[0].rect->y(); + int vw = p[0].rect->width(); + int vh = p[0].rect->height(); + double scaleW = (double)vw/(double)ww; + double scaleH = (double)vh/(double)wh; + cairo_matrix_init(&m_viewportMatrix, scaleW, 0, 0, scaleH, vx - wx*scaleW, vy - wy*scaleH); + setCairoTransformations(); + } break; -#endif case PdcSetWXform: - m_qt4painter->setWorldMatrixEnabled( p[0].ival ); + if ((p) && (m_painter)) { + m_worldMatrixEnabled = p[0].ival; + setCairoTransformations(); + } break; case PdcSetWMatrix: - m_qt4painter->setWorldMatrix( qt4matrix, p[1].ival ); + if ((p) && (m_painter)) { + const TQWMatrix* tqt3matrix = p[0].matrix; + if (tqt3matrix) { + if (p[1].ival) { + // Combine + cairo_matrix_t new_matrix; + cairo_matrix_t original_matrix = m_worldMatrix; + cairo_matrix_init(&new_matrix, tqt3matrix->m11(), tqt3matrix->m12(), tqt3matrix->m21(), tqt3matrix->m22(), tqt3matrix->dx(), tqt3matrix->dy()); + cairo_matrix_multiply(&m_worldMatrix, &original_matrix, &new_matrix); + } + else { + // Replace + cairo_matrix_init(&m_worldMatrix, tqt3matrix->m11(), tqt3matrix->m12(), tqt3matrix->m21(), tqt3matrix->m22(), tqt3matrix->dx(), tqt3matrix->dy()); + } + setCairoTransformations(); + } + } break; #if 0 +#if 0 #ifndef QT_NO_TRANSFORMATIONS case PdcSaveWMatrix: painter->saveWorldMatrix(); |