3 Python wrapper for librfxswf- primitive objects (implementation)
5 Part of the swftools package.
7 Copyright (c) 2003 Matthias Kramm <kramm@quiss.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
25 #include "../rfxswf.h"
27 #include "./pyutils.h"
28 #include "primitives.h"
30 //----------------------------------------------------------------------------
36 PyObject* f_Color(PyObject* self, PyObject* args, PyObject* kwargs)
38 static char *kwlist[] = {"r", "g", "b", "a", NULL};
40 int r=0,g=0,b=0,a=255;
41 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii|i", kwlist, &r,&g,&b,&a))
43 color = PyObject_New(ColorObject, &ColorClass);
48 return (PyObject*)color;
50 static PyObject* color_getattr(PyObject * self, char* a)
52 ColorObject*color = (ColorObject*)self;
54 return Py_BuildValue("r", color->rgba.r);
55 } else if(!strcmp(a, "g")) {
56 return Py_BuildValue("g", color->rgba.g);
57 } else if(!strcmp(a, "b")) {
58 return Py_BuildValue("b", color->rgba.b);
59 } else if(!strcmp(a, "a")) {
60 return Py_BuildValue("a", color->rgba.a);
64 static int color_setattr(PyObject * self, char* attr, PyObject* o)
66 ColorObject*color = (ColorObject*)self;
67 if(!strcmp(attr, "r")) {
68 if (!PyArg_Parse(o, "d", &color->rgba.r)) goto err;
70 } else if(!strcmp(attr, "g")) {
71 if (!PyArg_Parse(o, "d", &color->rgba.g)) goto err;
73 } else if(!strcmp(attr, "b")) {
74 if (!PyArg_Parse(o, "d", &color->rgba.b)) goto err;
76 } else if(!strcmp(attr, "a")) {
77 if (!PyArg_Parse(o, "d", &color->rgba.a)) goto err;
81 mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, attr, o);
84 RGBA color_getRGBA(PyObject*self)
86 ColorObject*color = 0;
87 if (!PyArg_Parse(self, "O!", &ColorClass, &color)) {
89 memset(&dummy, 0, sizeof(dummy));
90 mylog("Error: wrong type for function color_getRGBA");
95 PyTypeObject ColorClass =
97 PyObject_HEAD_INIT(NULL)
100 tp_basicsize: sizeof(ColorObject),
102 tp_dealloc: dummy_dealloc,
104 tp_getattr: color_getattr,
105 tp_setattr: color_setattr,
107 //----------------------------------------------------------------------------
113 PyObject* f_BBox(PyObject* self, PyObject* args, PyObject* kwargs)
115 static char *kwlist[] = {"xmin", "ymin", "xmax", "ymax", NULL};
118 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiii", kwlist,
124 bbox = PyObject_New(BBoxObject, &BBoxClass);
126 return (PyObject*)bbox;
128 static PyObject* bbox_getattr(PyObject * self, char* a)
130 BBoxObject*bbox = (BBoxObject*)self;
131 if(!strcmp(a, "xmin")) {
132 return Py_BuildValue("i", bbox->bbox.xmin);
133 } else if(!strcmp(a, "ymin")) {
134 return Py_BuildValue("i", bbox->bbox.ymin);
135 } else if(!strcmp(a, "xmax")) {
136 return Py_BuildValue("i", bbox->bbox.xmax);
137 } else if(!strcmp(a, "ymax")) {
138 return Py_BuildValue("i", bbox->bbox.ymax);
142 static int bbox_setattr(PyObject * self, char* a, PyObject* o)
144 BBoxObject*bbox= (BBoxObject*)self;
145 if(!strcmp(a, "xmin")) {
146 if (!PyArg_Parse(o, "i", &bbox->bbox.xmin)) goto err;
148 } else if(!strcmp(a, "ymin")) {
149 if (!PyArg_Parse(o, "i", &bbox->bbox.ymin)) goto err;
151 } else if(!strcmp(a, "xmax")) {
152 if (!PyArg_Parse(o, "i", &bbox->bbox.xmax)) goto err;
154 } else if(!strcmp(a, "ymax")) {
155 if (!PyArg_Parse(o, "i", &bbox->bbox.ymax)) goto err;
159 mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, a, o);
162 SRECT bbox_getBBox(PyObject*self)
165 if (!PyArg_Parse(self, "O!", &BBoxClass, &bbox)) {
167 memset(&dummy, 0, sizeof(dummy));
168 mylog("Error: wrong type for function color_getRGBA");
173 PyTypeObject BBoxClass =
175 PyObject_HEAD_INIT(NULL)
178 tp_basicsize: sizeof(BBoxObject),
180 tp_dealloc: dummy_dealloc,
182 tp_getattr: bbox_getattr,
183 tp_setattr: bbox_setattr,
185 SRECT bbox_getBBox(PyObject*self);
186 //----------------------------------------------------------------------------
192 PyObject* f_Matrix(PyObject* self, PyObject* args, PyObject* kwargs)
196 static PyObject* matrix_getattr(PyObject * self, char* a)
200 static int matrix_setattr(PyObject * self, char* a, PyObject* o)
204 MATRIX matrix_getMatrix(PyObject*self)
206 MatrixObject*matrix= 0;
207 if (!PyArg_Parse(self, "O!", &MatrixClass, &matrix)) {
209 memset(&dummy, 0, sizeof(dummy));
210 mylog("Error: wrong type for function color_getRGBA");
213 return matrix->matrix;
215 PyTypeObject MatrixClass =
217 PyObject_HEAD_INIT(NULL)
220 tp_basicsize: sizeof(MatrixObject),
222 tp_dealloc: dummy_dealloc,
224 tp_getattr: matrix_getattr,
225 tp_setattr: matrix_setattr,
231 tp_hash: 0, // dict(x)
235 //----------------------------------------------------------------------------
241 PyObject* f_ColorTransform(PyObject* self, PyObject* args, PyObject* kwargs)
245 static PyObject* colortransform_getattr(PyObject * self, char* a)
249 static int colortransform_setattr(PyObject * self, char* a, PyObject* o)
253 CXFORM colortransform_getCXForm(PyObject*self)
255 CXFormObject*cxform= 0;
256 if (!PyArg_Parse(self, "O!", &CXFormClass, &cxform)) {
258 memset(&dummy, 0, sizeof(dummy));
259 mylog("Error: wrong type for function color_getRGBA");
262 return cxform->cxform;
264 PyTypeObject CXFormClass =
266 PyObject_HEAD_INIT(NULL)
268 tp_name: "ColorTransform",
269 tp_basicsize: sizeof(CXFormObject),
271 tp_dealloc: dummy_dealloc,
273 tp_getattr: colortransform_getattr,
274 tp_setattr: colortransform_setattr,
276 //----------------------------------------------------------------------------
282 PyObject* f_Gradient(PyObject* self, PyObject* args, PyObject* kwargs)
286 static PyObject* gradient_getattr(PyObject * self, char* a)
290 static int gradient_setattr(PyObject * self, char* a, PyObject* o)
294 GRADIENT colortransform_getGradient(PyObject*self)
296 GradientObject*gradient = 0;
297 if (!PyArg_Parse(self, "O!", &gradient, &gradient)) {
299 memset(&dummy, 0, sizeof(dummy));
300 mylog("Error: wrong type for function color_getRGBA");
303 return gradient->gradient;
305 PyTypeObject GradientClass =
307 PyObject_HEAD_INIT(NULL)
310 tp_basicsize: sizeof(GradientObject),
312 tp_dealloc: dummy_dealloc,
314 tp_getattr: gradient_getattr,
315 tp_setattr: gradient_setattr,
317 //----------------------------------------------------------------------------
319 static PyMethodDef primitive_methods[] =
321 {"Color", (PyCFunction)f_Color, METH_KEYWORDS, "Create a new color object."},
322 {"Gradient", (PyCFunction)f_Gradient, METH_KEYWORDS, "Create a new gradient object."},
323 {"ColorTransform", (PyCFunction)f_ColorTransform, METH_KEYWORDS, "Create a new colortransform object."},
324 {"Matrix", (PyCFunction)f_Matrix, METH_KEYWORDS, "Create a new matrix object."},
325 {"BBox", (PyCFunction)f_BBox, METH_KEYWORDS, "Create a new bounding box object."},
326 {NULL, NULL, 0, NULL}
329 PyMethodDef* primitive_getMethods()
331 GradientClass.ob_type = &PyType_Type;
332 CXFormClass.ob_type = &PyType_Type;
333 BBoxClass.ob_type = &PyType_Type;
334 MatrixClass.ob_type = &PyType_Type;
335 return primitive_methods;