Updating built in Io code to use += instead of x = x + y
[io/quag.git] / addons / Cairo / source / IoCairoPath.c
blob98bfb929c21389d0af057d6464ee046ac19a1d34
1 /*#io
2 CairoPath ioDoc(
3 docCopyright("Daniel Rosengren", 2007)
4 docLicense("BSD revised")
5 docCategory("Graphics")
6 */
8 #include "IoCairoPath.h"
9 #include "IoCairoPathElement.h"
10 #include "IoList.h"
11 #include "tools.h"
12 #include <stdlib.h>
14 #define DATA(self) ((IoCairoPathData *)IoObject_dataPointer(self))
15 #define PATH(self) (DATA(self)->path)
18 void *IoMessage_locals_cairoPathArgAt_(IoMessage *self, void *locals, int n)
20 IoObject *arg = IoMessage_locals_valueArgAt_(self, locals, n);
21 if (!ISCAIROPATH(arg))
22 IoMessage_locals_numberArgAt_errorForType_(self, locals, n, "CairoPath");
23 return arg;
27 static IoTag *IoCairoPath_newTag(void *state)
29 IoTag *tag = IoTag_newWithName_("CairoPath");
30 IoTag_state_(tag, state);
31 IoTag_cloneFunc_(tag, (IoTagCloneFunc *)IoCairoPath_rawClone);
32 IoTag_freeFunc_(tag, (IoTagFreeFunc *)IoCairoPath_free);
33 return tag;
36 IoCairoPath *IoCairoPath_proto(void *state)
38 IoObject *self = IoObject_new(state);
39 IoObject_tag_(self, IoCairoPath_newTag(state));
41 IoState_registerProtoWithFunc_(state, self, IoCairoPath_proto);
44 IoMethodTable methodTable[] = {
45 {"foreach", IoCairoPath_foreach},
46 {NULL, NULL},
49 IoObject_addMethodTable_(self, methodTable);
52 return self;
55 IoCairoPath *IoCairoPath_rawClone(IoCairoPath *proto)
57 IoObject *self = IoObject_rawClonePrimitive(proto);
58 if (DATA(proto))
60 DATA(proto)->refCount += 1;
61 IoObject_setDataPointer_(self, DATA(proto));
63 return self;
66 IoCairoPath *IoCairoPath_newWithRawPath_(void *state, cairo_path_t *path)
68 IoCairoPath *self = 0;
70 checkStatus_(state, 0, path->status);
72 self = IOCLONE(IoState_protoWithInitFunction_(state, IoCairoPath_proto));
73 IoObject_setDataPointer_(self, calloc(1, sizeof(IoCairoPathData)));
74 DATA(self)->path = path;
75 DATA(self)->refCount = 1;
76 return self;
79 void IoCairoPath_free(IoCairoPath *self)
81 if (!DATA(self))
82 return;
84 DATA(self)->refCount -= 1;
85 if (DATA(self)->refCount > 0)
86 return;
88 cairo_path_destroy(PATH(self));
89 free(DATA(self));
93 cairo_path_t *IoCairoPath_rawPath(IoCairoPath *self)
95 return PATH(self);
99 /* ------------------------------------------------------------------------------------------------*/
101 IoObject *IoCairoPath_foreach(IoCairoPath *self, IoObject *locals, IoMessage *m)
103 cairo_path_t *path = PATH(self);
104 IoList *elementList = IoList_new(IOSTATE);
105 int i;
107 for (i = 0; i < path->num_data; i += path->data[i].header.length)
108 IoList_rawAppend_(elementList, IoCairoPathElement_newWithPath_dataOffset_(IOSTATE, self, i));
110 return IoList_foreach(elementList, locals, m);