2 CairoPathElement ioDoc(
3 docCopyright("Daniel Rosengren", 2007)
4 docLicense("BSD revised")
5 docCategory("Graphics")
8 #include "IoCairoPathElement.h"
9 #include "IoCairoPath.h"
14 #define DATA(self) ((IoCairoPathElementData *)IoObject_dataPointer(self))
15 #define PATH_DATA(self) (DATA(self)->pathData)
17 static int IoCairoPathElement_pointCount(IoCairoPathElement
*self
);
20 static IoTag
*IoCairoPathElement_newTag(void *state
)
22 IoTag
*tag
= IoTag_newWithName_("CairoPathElement");
23 IoTag_state_(tag
, state
);
24 IoTag_cloneFunc_(tag
, (IoTagCloneFunc
*)IoCairoPathElement_rawClone
);
25 IoTag_freeFunc_(tag
, (IoTagFreeFunc
*)IoCairoPathElement_free
);
26 IoTag_markFunc_(tag
, (IoTagFreeFunc
*)IoCairoPathElement_mark
);
30 IoCairoPathElement
*IoCairoPathElement_proto(void *state
)
32 IoObject
*self
= IoObject_new(state
);
33 IoObject_tag_(self
, IoCairoPathElement_newTag(state
));
35 IoState_registerProtoWithFunc_(state
, self
, IoCairoPathElement_proto
);
38 IoMethodTable methodTable
[] = {
39 {"kind", IoCairoPathElement_kind
},
40 {"pointAt", IoCairoPathElement_pointAt
},
45 IoObject_addMethodTable_(self
, methodTable
);
51 IoCairoPathElement
*IoCairoPathElement_rawClone(IoCairoPathElement
*proto
)
53 IoObject
*self
= IoObject_rawClonePrimitive(proto
);
57 IoCairoPathElement
*IoCairoPathElement_newWithPath_dataOffset_(void *state
, IoObject
*path
, int offset
)
59 IoCairoPathElement
*self
= IOCLONE(IoState_protoWithInitFunction_(state
, IoCairoPathElement_proto
));
60 cairo_path_t
*rawPath
= ((IoCairoPathData
*)IoObject_dataPointer(path
))->path
;
62 IoObject_setDataPointer_(self
, malloc(sizeof(IoCairoPathElementData
)));
63 DATA(self
)->path
= path
;
64 PATH_DATA(self
) = rawPath
->data
+ offset
;
68 void IoCairoPathElement_free(IoCairoPathElement
*self
)
74 void IoCairoPathElement_mark(IoCairoPathElement
*self
)
77 IoObject_shouldMark(DATA(self
)->path
);
81 /* ------------------------------------------------------------------------------------------------*/
83 IoObject
*IoCairoPathElement_kind(IoCairoPathElement
*self
, IoObject
*locals
, IoMessage
*m
)
85 return IONUMBER(PATH_DATA(self
)->header
.type
);
88 IoObject
*IoCairoPathElement_pointAt(IoCairoPathElement
*self
, IoObject
*locals
, IoMessage
*m
)
90 cairo_path_data_t
*data
= 0;
94 if (!DATA(self
)) return IONIL(self
);
96 i
= IoMessage_locals_intArgAt_(m
, locals
, 0);
97 pointCount
= IoCairoPathElement_pointCount(self
);
98 if (i
< 0 || i
>= pointCount
) return IONIL(self
);
100 data
= PATH_DATA(self
) + i
+ 1;
101 return IoSeq_newWithX_y_(IOSTATE
, data
->point
.x
, data
->point
.y
);
105 /* ------------------------------------------------------------------------------------------------*/
108 static int IoCairoPathElement_pointCount(IoCairoPathElement
*self
)
110 switch (PATH_DATA(self
)->header
.type
)
112 case CAIRO_PATH_MOVE_TO
:
114 case CAIRO_PATH_LINE_TO
:
116 case CAIRO_PATH_CURVE_TO
:
118 case CAIRO_PATH_CLOSE_PATH
: