sprite support.
[swftools.git] / lib / python / primitives.c
index b1cb0c6..2857a6a 100644 (file)
@@ -41,6 +41,7 @@ PyObject* f_Color(PyObject* self, PyObject* args, PyObject* kwargs)
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii|i", kwlist, &r,&g,&b,&a))
        return NULL;
     color = PyObject_New(ColorObject, &ColorClass);
+    mylog("+%08x(%d) color_new(%d,%d,%d,%d)\n", (int)color, color->ob_refcnt, r,g,b,a);
     color->rgba.r = r;
     color->rgba.g = g;
     color->rgba.b = b;
@@ -92,6 +93,11 @@ RGBA color_getRGBA(PyObject*self)
     }
     return color->rgba;
 }
+void color_dealloc(PyObject* self)
+{
+    mylog("-%08x(%d) color_dealloc\n", (int)self, self->ob_refcnt);
+    PyObject_Del(self);
+}
 PyTypeObject ColorClass = 
 {
     PyObject_HEAD_INIT(NULL)
@@ -99,7 +105,7 @@ PyTypeObject ColorClass =
     tp_name: "Color",
     tp_basicsize: sizeof(ColorObject),
     tp_itemsize: 0,
-    tp_dealloc: dummy_dealloc,
+    tp_dealloc: color_dealloc,
     tp_print: 0,
     tp_getattr: color_getattr,
     tp_setattr: color_setattr,
@@ -114,13 +120,20 @@ PyObject* f_BBox(PyObject* self, PyObject* args, PyObject* kwargs)
 {
     static char *kwlist[] = {"xmin", "ymin", "xmax", "ymax", NULL};
     BBoxObject* bbox;
+    float xmin,ymin,xmax,ymax;
+    if(!kwargs) {
+       if (!PyArg_ParseTuple(args, "ffff", &xmin, &ymin, &xmax, &ymax))
+           return NULL;
+    } else {
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ffff", kwlist, &xmin, &ymin, &xmax, &ymax))
+           return NULL;
+    }
     SRECT box;
-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiii", kwlist, 
-               &box.xmin,
-               &box.ymin,
-               &box.xmax,
-               &box.ymax));
-       return NULL;
+    box.xmin = (int)(xmin*20);
+    box.ymin = (int)(ymin*20);
+    box.xmax = (int)(xmax*20);
+    box.ymax = (int)(ymax*20);
+    mylog("+%08x(%d) bbox_new(%d,%d,%d,%d)\n", (int)self, self?self->ob_refcnt:0, box.xmin, box.ymin, box.xmax,box.ymax);
     bbox = PyObject_New(BBoxObject, &BBoxClass);
     bbox->bbox = box;
     return (PyObject*)bbox;
@@ -129,13 +142,13 @@ static PyObject* bbox_getattr(PyObject * self, char* a)
 {
     BBoxObject*bbox = (BBoxObject*)self;
     if(!strcmp(a, "xmin")) {
-       return Py_BuildValue("i", bbox->bbox.xmin);
+       return Py_BuildValue("f", bbox->bbox.xmin/20.0);
     } else if(!strcmp(a, "ymin")) {
-       return Py_BuildValue("i", bbox->bbox.ymin);
+       return Py_BuildValue("f", bbox->bbox.ymin/20.0);
     } else if(!strcmp(a, "xmax")) {
-       return Py_BuildValue("i", bbox->bbox.xmax);
+       return Py_BuildValue("f", bbox->bbox.xmax/20.0);
     } else if(!strcmp(a, "ymax")) {
-       return Py_BuildValue("i", bbox->bbox.ymax);
+       return Py_BuildValue("f", bbox->bbox.ymax/20.0);
     }
     return NULL;
 }
@@ -143,23 +156,36 @@ static int bbox_setattr(PyObject * self, char* a, PyObject* o)
 {
     BBoxObject*bbox= (BBoxObject*)self;
     if(!strcmp(a, "xmin")) {
-       if (!PyArg_Parse(o, "i", &bbox->bbox.xmin)) goto err;
+       float xmin;
+       if (!PyArg_Parse(o, "i", &xmin)) goto err;
+       bbox->bbox.xmin = (int)(xmin*20);
        return 0;
     } else if(!strcmp(a, "ymin")) {
-       if (!PyArg_Parse(o, "i", &bbox->bbox.ymin)) goto err;
+       float ymin;
+       if (!PyArg_Parse(o, "i", &ymin)) goto err;
+       bbox->bbox.ymin = (int)(ymin*20);
        return 0;
     } else if(!strcmp(a, "xmax")) {
-       if (!PyArg_Parse(o, "i", &bbox->bbox.xmax)) goto err;
+       float xmax;
+       if (!PyArg_Parse(o, "i", &xmax)) goto err;
+       bbox->bbox.xmax = (int)(xmax*20);
        return 0;
     } else if(!strcmp(a, "ymax")) {
-       if (!PyArg_Parse(o, "i", &bbox->bbox.ymax)) goto err;
+       float ymax;
+       if (!PyArg_Parse(o, "i", &ymax)) goto err;
+       bbox->bbox.ymax = (int)(ymax*20);
        return 0;
     } 
 err:
     mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, a, o);
     return 1;
 }
-SRECT bbox_getBBox(PyObject*self)
+void bbox_dealloc(PyObject* self)
+{
+    mylog("-%08x(%d) bbox_dealloc\n", (int)self, self->ob_refcnt);
+    PyObject_Del(self);
+}
+SRECT bbox_getSRECT(PyObject*self)
 {
     BBoxObject*bbox= 0;
     if (!PyArg_Parse(self, "O!", &BBoxClass, &bbox)) {
@@ -177,7 +203,7 @@ PyTypeObject BBoxClass =
     tp_name: "BBox",
     tp_basicsize: sizeof(BBoxObject),
     tp_itemsize: 0,
-    tp_dealloc: dummy_dealloc,
+    tp_dealloc: bbox_dealloc,
     tp_print: 0,
     tp_getattr: bbox_getattr,
     tp_setattr: bbox_setattr,
@@ -224,6 +250,11 @@ MATRIX matrix_getMatrix(PyObject*self)
     MatrixObject*matrix = (MatrixObject*)self;
     return matrix->matrix;
 }
+void matrix_dealloc(PyObject* self)
+{
+    mylog("-%08x(%d) matrix_dealloc", self, self->ob_refcnt);
+    PyObject_Del(self);
+}
 PyTypeObject MatrixClass = 
 {
     PyObject_HEAD_INIT(NULL)
@@ -231,7 +262,7 @@ PyTypeObject MatrixClass =
     tp_name: "Matrix",
     tp_basicsize: sizeof(MatrixObject),
     tp_itemsize: 0,
-    tp_dealloc: dummy_dealloc,
+    tp_dealloc: matrix_dealloc,
     tp_print: 0,
     tp_getattr: matrix_getattr,
     tp_setattr: matrix_setattr,
@@ -273,6 +304,11 @@ CXFORM colortransform_getCXForm(PyObject*self)
     }
     return cxform->cxform;
 }
+void colortransform_dealloc(PyObject* self)
+{
+    mylog("-%08x(%d) colortransform_dealloc", self, self->ob_refcnt);
+    PyObject_Del(self);
+}
 PyTypeObject CXFormClass = 
 {
     PyObject_HEAD_INIT(NULL)
@@ -280,7 +316,7 @@ PyTypeObject CXFormClass =
     tp_name: "ColorTransform",
     tp_basicsize: sizeof(CXFormObject),
     tp_itemsize: 0,
-    tp_dealloc: dummy_dealloc,
+    tp_dealloc: colortransform_dealloc,
     tp_print: 0,
     tp_getattr: colortransform_getattr,
     tp_setattr: colortransform_setattr,
@@ -303,7 +339,7 @@ static int gradient_setattr(PyObject * self, char* a, PyObject* o)
 {
     return 0;
 }
-GRADIENT colortransform_getGradient(PyObject*self)
+GRADIENT gradient_getGradient(PyObject*self)
 {
     GradientObject*gradient = 0;
     if (!PyArg_Parse(self, "O!", &gradient, &gradient)) {
@@ -314,6 +350,11 @@ GRADIENT colortransform_getGradient(PyObject*self)
     }
     return gradient->gradient;
 }
+void gradient_dealloc(PyObject* self)
+{
+    mylog("-%08x(%d) gradient_dealloc", self, self->ob_refcnt);
+    PyObject_Del(self);
+}
 PyTypeObject GradientClass = 
 {
     PyObject_HEAD_INIT(NULL)
@@ -321,7 +362,7 @@ PyTypeObject GradientClass =
     tp_name: "Gradient",
     tp_basicsize: sizeof(GradientObject),
     tp_itemsize: 0,
-    tp_dealloc: dummy_dealloc,
+    tp_dealloc: gradient_dealloc,
     tp_print: 0,
     tp_getattr: gradient_getattr,
     tp_setattr: gradient_setattr,