Skip to content

Instantly share code, notes, and snippets.

@bitcraft
Last active March 15, 2016 06:22
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bitcraft/1785face7c5684916cde to your computer and use it in GitHub Desktop.
static PyObject*
surf_blit_list (PyObject* self, PyObject* args)
{
SDL_Surface *src, *dest = PySurface_AsSurface (self);
GAME_Rect *src_rect, temp;
PyObject *srcobject, *argrect = NULL;
SDL_Rect dest_rect, sdlsrc_rect;
int result;
int dx, dy;
int sx, sy;
int the_args = 0;
int loop, size;
PyObject *list;
PyObject *inner_list;
PyObject *pos;
if (!PyArg_ParseTuple (args, "O", &list))
return NULL;
if (!PySequence_Check (list))
return RAISE (PyExc_TypeError,
"Argument must be a sequence of rectstyle objects.");
size = PySequence_Length (list); /*warning, size could be -1 on error?*/
if (size < 1) {
if (size < 0) {
/*Error.*/
return NULL;
}
/*Empty list: nothing to be done.*/
Py_RETURN_NONE;
}
for (loop = 0; loop < size; ++loop)
{
inner_list = PySequence_GetItem (list, loop);
src = PySequence_GetItem (inner_list, 0);
pos = PySequence_GetItem (inner_list, 1);
if ((src_rect = GameRect_FromObject (pos, &temp))) {
dx = src_rect->x;
dy = src_rect->y;
}
else if (TwoIntsFromObj (pos, &sx, &sy)) {
dx = sx;
dy = sy;
}
temp.x = temp.y = 0;
temp.w = src->w;
temp.h = src->h;
src_rect = &temp;
dest_rect.x = (short) dx;
dest_rect.y = (short) dy;
dest_rect.w = (unsigned short) src_rect->w;
dest_rect.h = (unsigned short) src_rect->h;
sdlsrc_rect.x = (short) src_rect->x;
sdlsrc_rect.y = (short) src_rect->y;
sdlsrc_rect.w = (unsigned short) src_rect->w;
sdlsrc_rect.h = (unsigned short) src_rect->h;
result = PySurface_Blit (self, src, &dest_rect, &sdlsrc_rect, 0);
}
Py_RETURN_NONE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment