[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] subclassing rect
Hello Pete,
Thursday, July 4, 2002, 10:52:42 AM, you wrote:
> i'd be glad to see what you got working. this is good a place as any for
> pygame development. if it starts to get too technical we'll probably just
> drop into private mail eventually.
Ok here's the part of the code I've modified. Basically, I used the
float.c file from the Python 2.2.1 sourcecode as reference.
It seems you have to handle the instanciation of subclasses as a
special case.
It's not the best method as it makes a temp Rect object before copying
its content into the new subclass object. But that way I didn't have
to do extensive changes to your code (and besides if the Python
developers are too lazy to do otherwise, why should I ;)
#if PYTHON_API_VERSION >= 1011 /*this is the python-2.2 constructor*/
staticforward PyObject *
rect_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
static PyObject* rect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
GAME_Rect *argrect, temp;
if (type != &PyRect_Type)
return rect_subtype_new(type, args, kwds); /* Wimp out */
if(!(argrect = GameRect_FromObject(args, &temp)))
return RAISE(PyExc_TypeError, "Argument must be rect style object");
return PyRect_New4(argrect->x, argrect->y, argrect->w, argrect->h);
}
static PyObject *
rect_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *tmp, *new;
assert(PyType_IsSubtype(type, &PyRect_Type));
tmp = rect_new(&PyRect_Type, args, kwds);
if (tmp == NULL)
return NULL;
//assert(PyFloat_CheckExact(tmp));
new = type->tp_alloc(type, 0);
if (new == NULL)
return NULL;
((PyRectObject *)new)->r = ((PyRectObject *)tmp)->r;
Py_DECREF(tmp);
return new;
}
#endif
--
Marc Schefer - codexus@codexus.com
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org