From 48d129b87f0b3f64577a0e653c7f48ba9c40cbab Mon Sep 17 00:00:00 2001 From: William Joye Date: Sun, 19 Mar 2017 14:01:09 -0400 Subject: add fill support --- tkmacosx/macosxlib.h | 5 +++-- tkmacosx/macosxlib.mm | 45 ++++++++++++++++++++++++++++++--------------- tkmacosx/tkmacosx.mm | 29 ++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/tkmacosx/macosxlib.h b/tkmacosx/macosxlib.h index 22d71db..69e779b 100644 --- a/tkmacosx/macosxlib.h +++ b/tkmacosx/macosxlib.h @@ -22,11 +22,12 @@ void macosxClip(Vector, Vector); void macosxDrawText(Vector, float, const char*); void macosxDrawLine(Vector, Vector); void macosxDrawLines(Vector*, int); -void macosxDrawRect(Vector, Vector); +void macosxFillPolygon(Vector*, int); void macosxDrawArc(Vector, float, float, float); +void macosxFillArc(Vector, float, float, float); void macosxDrawCurve(Vector, Vector, Vector, Vector); +void macosxFillCurve(Vector, Vector, Vector, Vector); -void macosxFillPolygon(Vector*, int); void macosxBitmapCreate(void*, int, int, const Vector&, const Vector&); diff --git a/tkmacosx/macosxlib.mm b/tkmacosx/macosxlib.mm index 77a7bdb..454d026 100644 --- a/tkmacosx/macosxlib.mm +++ b/tkmacosx/macosxlib.mm @@ -121,12 +121,21 @@ void macosxDrawLines(Vector* v, int n) */ } -void macosxDrawRect(Vector v, Vector s) +void macosxFillPolygon(Vector* v, int n) { /* if (tkmacosx) { - Vector vv1 = v*tkmacosx->getCanvasToPage(); - tkmacosx->drawRect(vv1[0], vv1[1], s[0], s[1]); + float xx[n]; + float yy[n]; + + for(int ii=0; iigetCanvasToPage(); + + xx[ii] = vv[0]; + yy[ii] = vv[1]; + } + + tkmacosx->fillPolygon(xx,yy,n); } */ } @@ -141,6 +150,16 @@ void macosxDrawArc(Vector v, float rad, float ang1, float ang2) */ } +void macosxFillArc(Vector v, float rad, float ang1, float ang2) +{ +/* + if (tkmacosx) { + Vector vv = v*tkmacosx->getCanvasToPage(); + tkmacosx->fillArc(vv[0], vv[1], rad, ang1, ang2); + } +*/ +} + void macosxDrawCurve(Vector v0, Vector t0, Vector t1, Vector v1) { /* @@ -156,24 +175,20 @@ void macosxDrawCurve(Vector v0, Vector t0, Vector t1, Vector v1) */ } -void macosxFillPolygon(Vector* v, int n) +void macosxFillCurve(Vector v0, Vector t0, Vector t1, Vector v1) { /* if (tkmacosx) { - float xx[n]; - float yy[n]; - - for(int ii=0; iigetCanvasToPage(); - - xx[ii] = vv[0]; - yy[ii] = vv[1]; - } + Vector vv0 = v0*tkmacosx->getCanvasToPage(); + Vector tt0 = t0*tkmacosx->getCanvasToPage(); + Vector tt1 = t1*tkmacosx->getCanvasToPage(); + Vector vv1 = v1*tkmacosx->getCanvasToPage(); - tkmacosx->fillPolygon(xx,yy,n); + tkmacosx->fillCurve(vv0[0], vv0[1], tt0[0], tt0[1], + tt1[0], tt1[1], vv1[0], vv1[1]); } */ -} +} void macosxBitmapCreate(void* img, int width, int height, const Vector& v, const Vector& s) diff --git a/tkmacosx/tkmacosx.mm b/tkmacosx/tkmacosx.mm index efebe60..00b8163 100644 --- a/tkmacosx/tkmacosx.mm +++ b/tkmacosx/tkmacosx.mm @@ -753,11 +753,14 @@ void TkMacosx::drawLines(float* x, float* y, int n) CGContextStrokePath(context); } -void TkMacosx::drawRect(float x, float y, float w, float h) +void TkMacosx::fillPolygon(float* x, float* y, int n) { CGContextBeginPath(context); - CGContextAddRect(context, CGRectMake(x,y,w,h)); - CGContextStrokePath(context); + CGContextMoveToPoint(context, x[0], y[0]); + for (int ii=1; ii