i've got xamarin.ios coregraphics code draws red triangles @ ends of several white lines of various angles.
i want have red triangles filled in instead of being rendered outlines when use graphic context command fillpath() instead of strokepath() red triangles don't appear.
here's drawarrowhead code (called line drawing code after each individual line drawn).
private void drawarrowhead(pointf[] line, int size) { // create arrowhead , lines individual arrowhead points pointf[] arrowhead = new pointf[] { new pointf(0.0f - size, 0.0f), new pointf(0.0f, 0.0f - size), new pointf(0.0f + size, 0.0f) }; pointf[] line1 = new pointf[] {new pointf(arrowhead[0].x, arrowhead[0].y), new pointf(arrowhead[1].x, arrowhead[1].y)}; pointf[] line2 = new pointf[] {new pointf(arrowhead[1].x, arrowhead[1].y), new pointf(arrowhead[2].x, arrowhead[2].y)}; pointf[] line3 = new pointf[] {new pointf(arrowhead[2].x, arrowhead[2].y), new pointf(arrowhead[0].x, arrowhead[0].y)}; // begin drawing arrowhead gctx.savestate(); uicolor.red.setstroke(); gctx.setfillcolor(uicolor.red.cgcolor); gctx.beginpath(); double angleinradians = math.atan2 (line[0].y - line[1].y, line[0].x -line[1].x); gctx.translatectm(line[1].x, line[1].y); gctx.rotatectm((float)(angleinradians - math.pi / 2)); path.addlines(line1); path.addlines(line2); path.addlines(line3); path.closesubpath(); gctx.addpath(path); gctx.strokepath(); gctx.restorestate(); }
when replace gctx.strokepath() gctx.fillpath() white lines no arrowheads.
when replace gctx.strokepath() gctx.drawpath(cgpathdrawingmode.fillstroke) red triangles they're not filled in.
i'm sure it's simple i'm missing. in advance.
update - 03.22.13
turns out @poupou's answer correct but, compounded of other coding "misinterpretations," didn't solve problem right away. however, since pointed me in right direction towards solution i'm accepting answer.
i first learned how use coregraphics via mike bluestein's excellent drawing coregraphics in monotouch post. however, little knowledge dangerous thing , when began applying these concepts own work, inadvertently mixed graphics context , path methods when shouldn't have.
after lot of googling, reading, , reviewing other peoples coregraphics source code (props nina vyedin , bryan costanich of xamarin drawing sample), came drawarrowhead method works.
private void drawarrowhead(pointf[] line, int size) { gctx.savestate(); uicolor.red.setstroke(); uicolor.red.setfill(); double angleinradians = math.atan2 (line[0].y - line[1].y, line[0].x -line[1].x); gctx.beginpath(); gctx.translatectm(line[1].x, line[1].y); gctx.rotatectm((float)(angleinradians - math.pi / 2)); pointf[] arrowhead = new pointf[] { new pointf (0.0f - arrowheadsize, 0.0f), new pointf (0.0f, 0.0f - arrowheadsize), new pointf (0.0f + arrowheadsize, 0.0f) }; gctx.moveto(arrowhead[0].x, arrowhead[0].y); gctx.addlinetopoint(arrowhead[1].x, arrowhead[1].y); gctx.addlinetopoint(arrowhead[2].x, arrowhead[2].y); gctx.closepath(); gctx.drawpath(cgpathdrawingmode.fillstroke); gctx.restorestate(); }
here's final result.
note: had move drawarrowhead code out of it's method , uiview's draw method avoid invalid context errors when drawing second, third, fourth, , fifth line/arrowhead combinations (you can read type of error here).
calling path.closesubpath();
on cgpath
not identical calling gctx.closepath();
on cgcontext
(where stroke/fill done). did try later ?
Comments
Post a Comment