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 PyObject* f_Color(PyObject* self, PyObject* args, PyObject* kwargs)
32 static char *kwlist[] = {"r", "g", "b", "a", NULL};
34 int r=0,g=0,b=0,a=255;
35 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii|i", kwlist, &r,&g,&b,&a))
37 color = PyObject_New(ColorObject, &ColorClass);
42 return (PyObject*)color;
44 static PyObject* color_getattr(PyObject * self, char* a)
46 ColorObject*color = (ColorObject*)self;
48 return Py_BuildValue("r", color->rgba.r);
49 } else if(!strcmp(a, "g")) {
50 return Py_BuildValue("g", color->rgba.g);
51 } else if(!strcmp(a, "b")) {
52 return Py_BuildValue("b", color->rgba.b);
53 } else if(!strcmp(a, "a")) {
54 return Py_BuildValue("a", color->rgba.a);
58 static int color_setattr(PyObject * self, char* attr, PyObject* o)
60 ColorObject*color = (ColorObject*)self;
61 if(!strcmp(attr, "r")) {
62 if (!PyArg_Parse(o, "d", &color->rgba.r)) goto err;
64 } else if(!strcmp(attr, "g")) {
65 if (!PyArg_Parse(o, "d", &color->rgba.g)) goto err;
67 } else if(!strcmp(attr, "b")) {
68 if (!PyArg_Parse(o, "d", &color->rgba.b)) goto err;
70 } else if(!strcmp(attr, "a")) {
71 if (!PyArg_Parse(o, "d", &color->rgba.a)) goto err;
75 mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, attr, o);
78 //----------------------------------------------------------------------------
79 PyObject* f_BBox(PyObject* self, PyObject* args, PyObject* kwargs)
81 static char *kwlist[] = {"xmin", "ymin", "xmax", "ymax", NULL};
84 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiii", kwlist,
90 bbox = PyObject_New(BBoxObject, &BBoxClass);
92 return (PyObject*)bbox;
94 static PyObject* bbox_getattr(PyObject * self, char* a)
96 BBoxObject*bbox = (BBoxObject*)self;
97 if(!strcmp(a, "xmin")) {
98 return Py_BuildValue("i", bbox->bbox.xmin);
99 } else if(!strcmp(a, "ymin")) {
100 return Py_BuildValue("i", bbox->bbox.ymin);
101 } else if(!strcmp(a, "xmax")) {
102 return Py_BuildValue("i", bbox->bbox.xmax);
103 } else if(!strcmp(a, "ymax")) {
104 return Py_BuildValue("i", bbox->bbox.ymax);
108 static int bbox_setattr(PyObject * self, char* a, PyObject* o)
110 BBoxObject*bbox= (BBoxObject*)self;
111 if(!strcmp(a, "xmin")) {
112 if (!PyArg_Parse(o, "i", &bbox->bbox.xmin)) goto err;
114 } else if(!strcmp(a, "ymin")) {
115 if (!PyArg_Parse(o, "i", &bbox->bbox.ymin)) goto err;
117 } else if(!strcmp(a, "xmax")) {
118 if (!PyArg_Parse(o, "i", &bbox->bbox.xmax)) goto err;
120 } else if(!strcmp(a, "ymax")) {
121 if (!PyArg_Parse(o, "i", &bbox->bbox.ymax)) goto err;
125 mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, a, o);
128 //----------------------------------------------------------------------------
129 PyObject* f_Matrix(PyObject* self, PyObject* args, PyObject* kwargs)
133 static PyObject* matrix_getattr(PyObject * self, char* a)
137 static int matrix_setattr(PyObject * self, char* a, PyObject* o)
141 //----------------------------------------------------------------------------
142 PyObject* f_ColorTransform(PyObject* self, PyObject* args, PyObject* kwargs)
146 static PyObject* colortransform_getattr(PyObject * self, char* a)
150 static int colortransform_setattr(PyObject * self, char* a, PyObject* o)
154 //----------------------------------------------------------------------------
155 PyObject* f_Gradient(PyObject* self, PyObject* args, PyObject* kwargs)
159 static PyObject* gradient_getattr(PyObject * self, char* a)
163 static int gradient_setattr(PyObject * self, char* a, PyObject* o)
167 //----------------------------------------------------------------------------
169 PyTypeObject ColorClass =
171 PyObject_HEAD_INIT(NULL)
174 tp_basicsize: sizeof(ColorObject),
176 tp_dealloc: dummy_dealloc,
178 tp_getattr: color_getattr,
179 tp_setattr: color_setattr,
181 PyTypeObject BBoxClass =
183 PyObject_HEAD_INIT(NULL)
186 tp_basicsize: sizeof(BBoxObject),
188 tp_dealloc: dummy_dealloc,
190 tp_getattr: bbox_getattr,
191 tp_setattr: bbox_setattr,
193 PyTypeObject GradientClass =
195 PyObject_HEAD_INIT(NULL)
198 tp_basicsize: sizeof(GradientObject),
200 tp_dealloc: dummy_dealloc,
202 tp_getattr: gradient_getattr,
203 tp_setattr: gradient_setattr,
205 PyTypeObject CXFormClass =
207 PyObject_HEAD_INIT(NULL)
209 tp_name: "ColorTransform",
210 tp_basicsize: sizeof(CXFormObject),
212 tp_dealloc: dummy_dealloc,
214 tp_getattr: colortransform_getattr,
215 tp_setattr: colortransform_setattr,
217 PyTypeObject MatrixClass =
219 PyObject_HEAD_INIT(NULL)
222 tp_basicsize: sizeof(MatrixObject),
224 tp_dealloc: dummy_dealloc,
226 tp_getattr: matrix_getattr,
227 tp_setattr: matrix_setattr,
233 tp_hash: 0, // dict(x)