Activate lines and polylines

pull/1/head
Timothy Pearson 12 years ago
parent c2a1262df8
commit 2e57d2cf81

@ -384,6 +384,8 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
double x; double x;
double y; double y;
double x2;
double y2;
double width; double width;
double height; double height;
@ -393,13 +395,16 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
// Convert data types // Convert data types
if (p) { if (p) {
// if ((c == PdcDrawPoint) || (c == PdcMoveTo) || (c == PdcLineTo) || (c == PdcSetBrushOrigin)) { if ((c == PdcDrawPoint) || (c == PdcMoveTo) || (c == PdcLineTo) || (c == PdcSetBrushOrigin)) {
// qt4point1 = QPoint(p[0].point->x(), p[0].point->y()); x = p[0].point->x();
// } y = p[0].point->y();
// if (c == PdcDrawLine) { }
// qt4point1 = QPoint(p[0].point->x(), p[0].point->y()); if (c == PdcDrawLine) {
// qt4point2 = QPoint(p[1].point->x(), p[1].point->y()); x = p[0].point->x();
// } y = p[0].point->y();
x2 = p[1].point->x();
y2 = p[1].point->y();
}
// if ((c == PdcDrawPolyline) || (c == PdcDrawPolygon) || (c == PdcDrawLineSegments) || (c == PdcDrawCubicBezier)) { // if ((c == PdcDrawPolyline) || (c == PdcDrawPolygon) || (c == PdcDrawLineSegments) || (c == PdcDrawCubicBezier)) {
// TQPointArray qt3parray = *p[0].ptarr; // TQPointArray qt3parray = *p[0].ptarr;
// qt4polygon.resize(qt3parray.count()); // qt4polygon.resize(qt3parray.count());
@ -420,24 +425,52 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
switch ( c ) { // exec cmd switch ( c ) { // exec cmd
case PdcNOP: case PdcNOP:
break; break;
#if 0
case PdcDrawPoint: case PdcDrawPoint:
m_qt4painter->drawPoint( qt4point1 ); if (m_painter) {
cairo_save(m_painter);
if (m_pen.style() != TQPen::NoPen) {
cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
cairo_line_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
updatePen(FALSE);
cairo_set_line_cap(m_painter, CAIRO_LINE_CAP_ROUND);
cairo_stroke(m_painter);
}
cairo_restore(m_painter);
}
break; break;
case PdcMoveTo: case PdcMoveTo:
curPt = qt4point1; if (m_painter) {
cairo_save(m_painter);
if (m_pen.style() != TQPen::NoPen) {
cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
}
cairo_restore(m_painter);
}
break; break;
case PdcLineTo: case PdcLineTo:
prevPt = curPt; if (m_painter) {
curPt = qt4point1; cairo_save(m_painter);
m_qt4painter->drawLine( prevPt, curPt ); if (m_pen.style() != TQPen::NoPen) {
cairo_line_to(m_painter, x2+CAIRO_PIXEL_OFFSET, y2+CAIRO_PIXEL_OFFSET);
dualStrokePen();
}
cairo_restore(m_painter);
}
break; break;
case PdcDrawLine: case PdcDrawLine:
m_qt4painter->drawLine( qt4point1, qt4point2 ); if (m_painter) {
cairo_save(m_painter);
if (m_pen.style() != TQPen::NoPen) {
cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
cairo_line_to(m_painter, x2+CAIRO_PIXEL_OFFSET, y2+CAIRO_PIXEL_OFFSET);
dualStrokePen();
}
cairo_restore(m_painter);
}
break; break;
#endif
case PdcDrawRect: case PdcDrawRect:
if (m_painter) { if (m_painter) {
cairo_save(m_painter);
if (m_pen.style() != TQPen::NoPen) { if (m_pen.style() != TQPen::NoPen) {
cairo_rectangle(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET, width, height); cairo_rectangle(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET, width, height);
dualStrokePen(); dualStrokePen();
@ -447,6 +480,7 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
cairo_rectangle(m_painter, x+line_width+CAIRO_PIXEL_OFFSET, y+line_width+CAIRO_PIXEL_OFFSET, width-(line_width*2), height-(line_width*2)); cairo_rectangle(m_painter, x+line_width+CAIRO_PIXEL_OFFSET, y+line_width+CAIRO_PIXEL_OFFSET, width-(line_width*2), height-(line_width*2));
dualStrokeBrush(); dualStrokeBrush();
} }
cairo_restore(m_painter);
} }
else { else {
#if defined(QT_CHECK_RANGE) #if defined(QT_CHECK_RANGE)
@ -476,9 +510,35 @@ bool TQt3CairoPaintDevice::cmd( int c, TQPainter *pt, TQPDevCmdParam *p )
lineCount = (count == -1) ? (qt4polygon.size() - index) / 2 : count; lineCount = (count == -1) ? (qt4polygon.size() - index) / 2 : count;
m_qt4painter->drawLines(qt4polygon.constData() + index * 2, lineCount); m_qt4painter->drawLines(qt4polygon.constData() + index * 2, lineCount);
break; break;
#endif
case PdcDrawPolyline: case PdcDrawPolyline:
m_qt4painter->drawPolyline( qt4polygon ); if (m_painter) {
cairo_save(m_painter);
if (p) {
const TQPointArray* pointarray = p[0].ptarr;
if (pointarray) {
int x;
int y;
bool first=true;
for (i=0;i<pointarray->count();i++) {
pointarray->point(i, &x, &y );
if (first) {
cairo_move_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
first = false;
}
else {
cairo_line_to(m_painter, x+CAIRO_PIXEL_OFFSET, y+CAIRO_PIXEL_OFFSET);
}
}
if (m_pen.style() != TQPen::NoPen) {
dualStrokePen();
}
}
}
cairo_restore(m_painter);
}
break; break;
#if 0
case PdcDrawPolygon: case PdcDrawPolygon:
m_qt4painter->drawPolygon( qt4polygon, (p[1].ival == 0)?Qt::OddEvenFill:Qt::WindingFill ); m_qt4painter->drawPolygon( qt4polygon, (p[1].ival == 0)?Qt::OddEvenFill:Qt::WindingFill );
break; break;

@ -11,7 +11,7 @@ main (int argc, char *argv[])
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 120, 120); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 500, 500);
// cr = cairo_create (surface); // cr = cairo_create (surface);
// /* Examples are in 1.0 x 1.0 coordinate space */ // /* Examples are in 1.0 x 1.0 coordinate space */
@ -28,24 +28,50 @@ main (int argc, char *argv[])
TQt3CairoPaintDevice pd(surface); TQt3CairoPaintDevice pd(surface);
TQPainter p(&pd); TQPainter p(&pd);
p.setPen(TQPen(TQt::red, 1));
p.drawRect(5, 5, 50, 50); // Rectangle tests
{
TQBrush brush( TQt::yellow, TQBrush::DiagCrossPattern ); // yellow pattern p.setPen(TQPen(TQt::red, 1));
p.setBrush( brush ); // set the yellow brush p.drawRect(5, 5, 50, 50);
p.setPen( TQt::NoPen ); // do not draw outline TQBrush brush( TQt::yellow, TQBrush::DiagCrossPattern ); // yellow pattern
p.drawRect( 0,0, 25,25 ); // draw filled rectangle p.setBrush( brush ); // set the yellow brush
TQBrush brush2( TQt::green, TQBrush::SolidPattern ); // green pattern p.setPen( TQt::NoPen ); // do not draw outline
p.setBrush( brush2 ); // set the yellow brush p.drawRect( 0,0, 25,25 ); // draw filled rectangle
p.setPen( TQt::NoPen ); // do not draw outline TQBrush brush2( TQt::green, TQBrush::SolidPattern ); // green pattern
p.drawRect( 40,30, 200,100 ); // draw filled rectangle p.setBrush( brush2 ); // set the yellow brush
p.setBrush( TQt::NoBrush ); // do not fill p.setPen( TQt::NoPen ); // do not draw outline
p.setPen( TQt::blue ); // set blue pen, 0 pixel width p.drawRect( 40,30, 200,100 ); // draw filled rectangle
p.drawRect( 10,10, 30,20 ); // draw rectangle outline p.setBrush( TQt::NoBrush ); // do not fill
TQBrush brush3( TQColor(255,128,0), TQBrush::SolidPattern ); // green pattern p.setPen( TQt::blue ); // set blue pen, 0 pixel width
p.setBrush( brush3 ); // set the yellow brush p.drawRect( 10,10, 30,20 ); // draw rectangle outline
p.setPen( TQColor(255,0,255) ); // draw outline TQBrush brush3( TQColor(255,128,0), TQBrush::SolidPattern ); // green pattern
p.drawRect( 50,50, 180,80 ); // draw filled rectangle p.setBrush( brush3 ); // set the yellow brush
p.setPen( TQColor(255,0,255) ); // draw outline
p.drawRect( 50,40, 180,80 ); // draw filled rectangle
}
// Line tests
{
p.setPen( TQt::blue ); // set blue pen, 0 pixel width
p.drawLine(140,140, 160,160);
}
// Point tests
{
p.setPen( TQt::green ); // set green pen, 0 pixel width
p.drawPoint(135,135);
}
// Polyline tests
{
TQPointArray a;
int x1 = 200;
int y1 = 10;
a.setPoints( 11, x1+0, y1+85, x1+75, y1+75, x1+100, y1+10, x1+125, y1+75, x1+200, y1+85, x1+150, y1+125, x1+160, y1+190, x1+100, y1+150, x1+40, y1+190, x1+50, y1+125, x1+0, y1+85 );
p.setPen(TQt::red);
p.drawPolyline(a);
}
p.end(); p.end();

Loading…
Cancel
Save