diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2017-03-19 18:01:09 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2017-03-19 18:01:09 (GMT) |
commit | 48d129b87f0b3f64577a0e653c7f48ba9c40cbab (patch) | |
tree | ef8681089f8f6fe5696865d137adcfd4d03f362c | |
parent | 9530d25ec037286cc829f0de68d0ef0dc706ffde (diff) | |
download | blt-48d129b87f0b3f64577a0e653c7f48ba9c40cbab.zip blt-48d129b87f0b3f64577a0e653c7f48ba9c40cbab.tar.gz blt-48d129b87f0b3f64577a0e653c7f48ba9c40cbab.tar.bz2 |
add fill support
-rw-r--r-- | tkmacosx/macosxlib.h | 5 | ||||
-rw-r--r-- | tkmacosx/macosxlib.mm | 45 | ||||
-rw-r--r-- | 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; ii<n; ii++) { + Vector vv = v[ii]*tkmacosx->getCanvasToPage(); + + 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; ii<n; ii++) { - Vector vv = v[ii]*tkmacosx->getCanvasToPage(); - - 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<n; ii++) + CGContextAddLineToPoint(context, x[ii], y[ii]); + CGContextAddLineToPoint(context, x[0], y[0]); + CGContextEOFillPath(context); } void TkMacosx::drawArc(float x, float y, float rad, float ang1, float ang2) @@ -767,6 +770,13 @@ void TkMacosx::drawArc(float x, float y, float rad, float ang1, float ang2) CGContextStrokePath(context); } +void TkMacosx::fillArc(float x, float y, float rad, float ang1, float ang2) +{ + CGContextBeginPath(context); + CGContextAddArc(context, x, y, rad, ang1, ang2, 0); + CGContextEOFillPath(context); +} + void TkMacosx::drawCurve(float x0, float y0, float u0, float v0, float u1, float v1, @@ -778,14 +788,15 @@ void TkMacosx::drawCurve(float x0, float y0, CGContextStrokePath(context); } -void TkMacosx::fillPolygon(float* x, float* y, int n) +void TkMacosx::fillCurve(float x0, float y0, + float u0, float v0, + float u1, float v1, + float x1, float y1) { CGContextBeginPath(context); - CGContextMoveToPoint(context, x[0], y[0]); - for (int ii=1; ii<n; ii++) - CGContextAddLineToPoint(context, x[ii], y[ii]); - CGContextAddLineToPoint(context, x[0], y[0]); - CGContextEOFillPath(context); + CGContextMoveToPoint(context, x0, y0); + CGContextAddCurveToPoint(context, u0, v0, u1, v1, x1, y1); + CGContextEOPath(context); } void TkMacosx::bitmapCreate(void* data, int width, int height, |