static int TwoIntsFromObj (PyObject* obj, int* val1, int* val2) { if (PyTuple_Check (obj) && PyTuple_Size (obj) == 1) return TwoIntsFromObj (PyTuple_GET_ITEM (obj, 0), val1, val2); if (!PySequence_Check (obj) || PySequence_Length (obj) != 2) return 0; if (!IntFromObjIndex (obj, 0, val1) || !IntFromObjIndex (obj, 1, val2)) return 0; return 1; }
static PyObject* movie_set_display (PyObject* self, PyObject* args) { SMPEG* movie = PyMovie_AsSMPEG (self); PyObject* surfobj, *posobj=NULL; GAME_Rect *rect, temp; int x=0, y=0; if (!PyArg_ParseTuple (args, "O|O", &surfobj, &posobj)) return NULL; if (!SDL_WasInit (SDL_INIT_VIDEO)) return RAISE (PyExc_SDLError, "cannot convert without pygame.display initialized"); Py_XDECREF (((PyMovieObject*) self)->surftarget); ((PyMovieObject*) self)->surftarget = NULL; if (PySurface_Check (surfobj)) { SMPEG_Info info; SDL_Surface* surf; if (posobj == NULL) { Py_BEGIN_ALLOW_THREADS; SMPEG_getinfo (movie, &info); SMPEG_scaleXY (movie, info.width, info.height); Py_END_ALLOW_THREADS; x = y = 0; } else if (TwoIntsFromObj (posobj, &x, &y)) { Py_BEGIN_ALLOW_THREADS; SMPEG_getinfo (movie, &info); SMPEG_scaleXY (movie, info.width, info.height); Py_END_ALLOW_THREADS; } else if ((rect = GameRect_FromObject (posobj, &temp))) { x = rect->x; y = rect->y; Py_BEGIN_ALLOW_THREADS; SMPEG_scaleXY (movie, rect->w, rect->h); Py_END_ALLOW_THREADS; } else return RAISE (PyExc_TypeError, "Invalid position argument"); surf = PySurface_AsSurface (surfobj); Py_BEGIN_ALLOW_THREADS; SMPEG_getinfo (movie, &info); SMPEG_enablevideo (movie, 1); SMPEG_setdisplay (movie, surf, NULL, NULL); SMPEG_move (movie, x, y); Py_END_ALLOW_THREADS; } else { Py_BEGIN_ALLOW_THREADS; SMPEG_enablevideo (movie, 0); Py_END_ALLOW_THREADS; if (surfobj != Py_None) return RAISE (PyExc_TypeError, "destination must be a Surface"); } Py_RETURN_NONE; }