| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include <Carbon/Carbon.h> |
| 22 |
|
| 23 |
#include "zmisc.h" |
| 24 |
#include "bezctx.h" |
| 25 |
#include "bezctx_quartz.h" |
| 26 |
|
| 27 |
|
| 28 |
typedef struct { |
| 29 |
bezctx base; |
| 30 |
CGMutablePathRef pathref; |
| 31 |
int is_open; |
| 32 |
} bezctx_quartz; |
| 33 |
|
| 34 |
static void |
| 35 |
bezctx_quartz_moveto(bezctx *z, double x, double y, int is_open) { |
| 36 |
bezctx_quartz *bc = (bezctx_quartz *)z; |
| 37 |
if (!bc->is_open) CGPathCloseSubpath(bc->pathref); |
| 38 |
CGPathMoveToPoint(bc->pathref, NULL, x, y); |
| 39 |
bc->is_open = is_open; |
| 40 |
} |
| 41 |
|
| 42 |
static void |
| 43 |
bezctx_quartz_lineto(bezctx *z, double x, double y) { |
| 44 |
bezctx_quartz *bc = (bezctx_quartz *)z; |
| 45 |
CGPathAddLineToPoint(bc->pathref, NULL, x, y); |
| 46 |
} |
| 47 |
|
| 48 |
static void |
| 49 |
bezctx_quartz_quadto(bezctx *z, double x1, double y1, double x2, double y2) |
| 50 |
{ |
| 51 |
bezctx_quartz *bc = (bezctx_quartz *)z; |
| 52 |
CGPathAddQuadCurveToPoint(bc->pathref, NULL, x1, y1, x2, y2); |
| 53 |
} |
| 54 |
|
| 55 |
bezctx * |
| 56 |
new_bezctx_quartz(void) { |
| 57 |
bezctx_quartz *result = znew(bezctx_quartz, 1); |
| 58 |
|
| 59 |
result->base.moveto = bezctx_quartz_moveto; |
| 60 |
result->base.lineto = bezctx_quartz_lineto; |
| 61 |
result->base.quadto = bezctx_quartz_quadto; |
| 62 |
result->base.mark_knot = NULL; |
| 63 |
result->pathref = CGPathCreateMutable(); |
| 64 |
result->is_open = 1; |
| 65 |
return &result->base; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
CGMutablePathRef |
| 70 |
bezctx_to_quartz(bezctx *z) |
| 71 |
{ |
| 72 |
bezctx_quartz *bc = (bezctx_quartz *)z; |
| 73 |
CGMutablePathRef result = bc->pathref; |
| 74 |
|
| 75 |
if (!bc->is_open) CGPathCloseSubpath(result); |
| 76 |
zfree(bc); |
| 77 |
return result; |
| 78 |
} |