From: <ai...@us...> - 2009-12-01 05:46:50
|
Revision: 10653 http://plplot.svn.sourceforge.net/plplot/?rev=10653&view=rev Author: airwin Date: 2009-12-01 05:46:38 +0000 (Tue, 01 Dec 2009) Log Message: ----------- Implement native driver gradients for all qt raster devices and -dev svgqt. Modified Paths: -------------- trunk/bindings/qt_gui/plqt.cpp trunk/drivers/qt.cpp trunk/include/qt.h Modified: trunk/bindings/qt_gui/plqt.cpp =================================================================== --- trunk/bindings/qt_gui/plqt.cpp 2009-12-01 05:20:00 UTC (rev 10652) +++ trunk/bindings/qt_gui/plqt.cpp 2009-12-01 05:46:38 UTC (rev 10653) @@ -372,6 +372,30 @@ m_painterP->setBrush( B ); } +void QtPLDriver::setGradient( int x1, int x2, int y1, int y2, + int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ) +{ + if ( !m_painterP->isActive() || ncol1 < 2 ) return; + + int i; + qreal stop_arg; + QGradient linear_gradient; + QGradientStops stops; + + linear_gradient = QLinearGradient( + QPointF((qreal) ( x1 * downscale ), (qreal) ( m_dHeight - y1 * downscale )), + QPointF((qreal) ( x2 * downscale ), (qreal) ( m_dHeight - y2 * downscale ))); + + for ( i = 0; i < ncol1; i++ ) + { + stop_arg = (qreal) i / (qreal) ( ncol1 - 1 ); + stops << QGradientStop( stop_arg, QColor( r[i], g[i], + b[i], (int) ( alpha[i] * 255 ))); + } + linear_gradient.setStops( stops ); + m_painterP->setBrush( linear_gradient ); +} + void QtPLDriver::setWidth( PLINT w ) { if ( !m_painterP->isActive()) return; Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-12-01 05:20:00 UTC (rev 10652) +++ trunk/drivers/qt.cpp 2009-12-01 05:46:38 UTC (rev 10653) @@ -240,10 +240,11 @@ plParseDrvOpts( qt_options ); /* Stream setup */ - pls->color = 1; - pls->plbuf_write = 0; - pls->dev_fill0 = 1; - pls->dev_fill1 = 0; + pls->color = 1; + pls->plbuf_write = 0; + pls->dev_fill0 = 1; + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -334,6 +335,8 @@ void plD_esc_rasterqt( PLStream * pls, PLINT op, void* ptr ) { short *xa, *ya; + int *r, *g, *b; + qreal *alpha; PLINT i; QtRasterDevice * widget = (QtRasterDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) @@ -367,6 +370,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new int [pls->ncol1]; + g = new int [pls->ncol1]; + b = new int [pls->ncol1]; + alpha = new qreal [pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ @@ -622,10 +657,11 @@ plParseDrvOpts( qt_options ); /* Stream setup */ - pls->color = 1; - pls->plbuf_write = 0; - pls->dev_fill0 = 1; - pls->dev_fill1 = 0; + pls->color = 1; + pls->plbuf_write = 0; + pls->dev_fill0 = 1; + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -733,6 +769,8 @@ void plD_esc_svgqt( PLStream * pls, PLINT op, void* ptr ) { short *xa, *ya; + int *r, *g, *b; + qreal *alpha; PLINT i; QtSVGDevice * widget = (QtSVGDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) @@ -759,6 +797,39 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new int [pls->ncol1]; + g = new int [pls->ncol1]; + b = new int [pls->ncol1]; + alpha = new qreal [pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ Modified: trunk/include/qt.h =================================================================== --- trunk/include/qt.h 2009-12-01 05:20:00 UTC (rev 10652) +++ trunk/include/qt.h 2009-12-01 05:46:38 UTC (rev 10653) @@ -128,6 +128,8 @@ virtual void drawPolygon( short * x, short * y, PLINT npts ); virtual void drawText( PLStream* pls, EscText* txt ); virtual void setColor( int r, int g, int b, double alpha ); + virtual void setGradient( int x1, int x2, int y1, int y2, + int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ); virtual void setBackgroundColor( int r, int g, int b, double alpha ){} virtual void setWidth( PLINT w ); // Set pen to draw solid strokes (called after drawing dashed strokes) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |