fixed graphics bug
[swftools.git] / lib / python / action.c
1 /* action.c
2
3    Python wrapper for librfxswf- actionscript stuff
4
5    Part of the swftools package.
6
7    Copyright (c) 2003 Matthias Kramm <kramm@quiss.org>
8  
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.
13
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.
18
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 */
22
23 #include <Python.h>
24 #undef HAVE_STAT
25 #include "../rfxswf.h"
26 #include "../log.h"
27 #include "./pyutils.h"
28 #include "action.h"
29
30 PyObject* f_Action(PyObject* self, PyObject* args, PyObject* kwargs)
31 {
32     static char *kwlist[] = {"r", "g", "b", "a", NULL};
33     ActionObject* action;
34     int r=0,g=0,b=0,a=255;
35     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii|i", kwlist, &r,&g,&b,&a))
36         return NULL;
37     action = PyObject_New(ActionObject, &ActionClass);
38     action->rgba.r = r;
39     action->rgba.g = g;
40     action->rgba.b = b;
41     action->rgba.a = a;
42     return (PyObject*)action;
43 }
44 static PyObject* action_getattr(PyObject * self, char* a)
45 {
46     ActionObject*action = (ActionObject*)self;
47     if(!strcmp(a, "r")) {
48         return Py_BuildValue("r", action->rgba.r);
49     } else if(!strcmp(a, "g")) {
50         return Py_BuildValue("g", action->rgba.g);
51     } else if(!strcmp(a, "b")) {
52         return Py_BuildValue("b", action->rgba.b);
53     } else if(!strcmp(a, "a")) {
54         return Py_BuildValue("a", action->rgba.a);
55     }
56     return NULL;
57 }
58 static int action_setattr(PyObject * self, char* attr, PyObject* o)
59 {
60     ActionObject*action = (ActionObject*)self;
61     if(!strcmp(attr, "r")) {
62         if (!PyArg_Parse(o, "d", &action->rgba.r)) goto err;
63         return 0;
64     } else if(!strcmp(attr, "g")) {
65         if (!PyArg_Parse(o, "d", &action->rgba.g)) goto err;
66         return 0;
67     } else if(!strcmp(attr, "b")) {
68         if (!PyArg_Parse(o, "d", &action->rgba.b)) goto err;
69         return 0;
70     } else if(!strcmp(attr, "a")) {
71         if (!PyArg_Parse(o, "d", &action->rgba.a)) goto err;
72         return 0;
73     } 
74 err:
75     mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, attr, o);
76     return 1;
77 }
78
79 PyTypeObject ActionClass = 
80 {
81     PyObject_HEAD_INIT(NULL)
82     0,
83     tp_name: "Action",
84     tp_basicsize: sizeof(ActionObject),
85     tp_itemsize: 0,
86     tp_dealloc: dummy_dealloc,
87     tp_print: 0,
88     tp_getattr: action_getattr,
89     tp_setattr: action_setattr,
90 };