static int IntFromObjIndex (PyObject* obj, int _index, int* val) { int result = 0; PyObject* item; item = PySequence_GetItem (obj, _index); if (item) { result = IntFromObj (item, val); Py_DECREF (item); } return result; }
static PyObject* _sdl_joyeventstate (PyObject *self, PyObject *args) { int state; /* TODO: is that necessary? */ /*ASSERT_VIDEO_INIT(NULL);*/ if (!IntFromObj (args, &state)) return NULL; return PyInt_FromLong (SDL_JoystickEventState (state)); }
static PyObject* _context_disable (PyObject *self, PyObject *args) { ALenum val; ASSERT_CONTEXT_IS_CURRENT(self, NULL); if (!IntFromObj (args, (int*) &val)) return NULL; CLEAR_ALERROR_STATE (); alDisable (val); if (SetALErrorException (alGetError (), 0)) return NULL; Py_RETURN_NONE; }
static int _context_setdistancemodel (PyObject* self, PyObject *value, void *closure) { int model; ASSERT_CONTEXT_IS_CURRENT (self, -1); if (!IntFromObj (value, &model)) return -1; CLEAR_ALERROR_STATE (); alDistanceModel ((ALenum)model); if (SetALErrorException (alGetError (), 0)) return -1; return 0; }
static PyObject* _sdl_joyopened (PyObject *self, PyObject *args) { int joy; ASSERT_JOYSTICK_INIT(NULL); if (!IntFromObj (args, &joy)) return NULL; if (joy < 0 || joy >= SDL_NumJoysticks()) { PyErr_SetString (PyExc_ValueError, "invalid joystick index"); return NULL; } return PyBool_FromLong (SDL_JoystickOpened (joy)); }
static PyObject* _sdl_joygetname (PyObject *self, PyObject *args) { int joy; ASSERT_JOYSTICK_INIT(NULL); if (!IntFromObj (args, &joy)) return NULL; if (joy < 0 || joy >= SDL_NumJoysticks()) { PyErr_SetString (PyExc_ValueError, "invalid joystick index"); return NULL; } return Text_FromUTF8 (SDL_JoystickName (joy)); }
static PyObject* _context_isenabled (PyObject *self, PyObject *args) { ALenum val; ALboolean ret; ASSERT_CONTEXT_IS_CURRENT(self, NULL); if (!IntFromObj (args, (int*) &val)) return NULL; CLEAR_ALERROR_STATE (); ret = alIsEnabled (val); if (SetALErrorException (alGetError (), 0)) return NULL; if (ret == AL_TRUE) Py_RETURN_TRUE; Py_RETURN_FALSE; }
static PyObject* _sdl_wmgrabinput (PyObject *self, PyObject *args) { int mode; ASSERT_VIDEO_SURFACE_SET(NULL); if (PyBool_Check (args)) { if (args == Py_True) mode = SDL_WM_GrabInput (SDL_GRAB_ON); else mode = SDL_WM_GrabInput (SDL_GRAB_OFF); } else if (IntFromObj (args, &mode)) mode = SDL_WM_GrabInput (mode); else { PyErr_SetString (PyExc_TypeError, "argument must be bool or int"); return NULL; } return PyInt_FromLong (mode); }
/* Sources methods */ static PyObject* _sources_setprop (PyObject *self, PyObject *args) { long bufnum; ALenum param; PyObject *values; char *type; PropType ptype = INVALID; if (!CONTEXT_IS_CURRENT (((PySources*)self)->context)) { PyErr_SetString (PyExc_PyGameError, "source context is not current"); return NULL; } if (!PyArg_ParseTuple (args, "llO|s:set_prop", &bufnum, ¶m, &values, &type)) return NULL; if (type) { ptype = GetPropTypeFromStr (type); if (ptype == INVALID) { PyErr_SetString (PyExc_RuntimeError, "passing a sequence requires passing a type specifier"); return NULL; } } if (PySequence_Check (values)) { Py_ssize_t size, cnt; if (!type) { PyErr_SetString (PyExc_RuntimeError, "passing a sequence requires passing a type specifier"); return NULL; } if (ptype == INT || ptype == FLOAT) { PyErr_SetString (PyExc_TypeError, "cannot use single value type and sequence together"); return NULL; } size = PySequence_Size (values); switch (ptype) { case INT3: case INTARRAY: { ALint *vals; int tmp; if (ptype == INT3 && size < 3) { PyErr_SetString (PyExc_ValueError, "sequence too small for 'i3'"); return NULL; } vals = PyMem_New (ALint, size); if (!vals) return NULL; for (cnt = 0; cnt < size; cnt++) { if (!IntFromSeqIndex (values, cnt, &tmp)) { PyMem_Free (vals); return NULL; } vals[cnt] = (ALint) tmp; } CLEAR_ALERROR_STATE (); if (ptype == INT3) alSource3i ((ALuint)bufnum, param, vals[0], vals[1], vals[2]); else alSourceiv ((ALuint)bufnum, param, vals); PyMem_Free (vals); /* Error will be set at the end */ break; } case FLOAT3: case FLOATARRAY: { ALfloat *vals; double tmp; if (ptype == FLOAT3 && size < 3) { PyErr_SetString (PyExc_ValueError, "sequence too small for 'f3'"); return NULL; } vals = PyMem_New (ALfloat, size); if (!vals) return NULL; for (cnt = 0; cnt < size; cnt++) { if (!DoubleFromSeqIndex (values, cnt, &tmp)) { PyMem_Free (vals); return NULL; } vals[cnt] = (ALfloat) tmp; } CLEAR_ALERROR_STATE (); if (ptype == FLOAT3) alSource3f ((ALuint)bufnum, param, vals[0], vals[1], vals[2]); else alSourcefv ((ALuint)bufnum, param, vals); PyMem_Free (vals); /* Error will be set at the end */ break; } default: PyErr_SetString (PyExc_TypeError, "unsupported value"); return NULL; } } else { int ival = 0; double fval = 0; if (!type) { if (IntFromObj (values, &ival)) ptype = INT; else PyErr_Clear (); if (DoubleFromObj (values, &fval)) ptype = FLOAT; else { PyErr_Clear (); PyErr_SetString (PyExc_TypeError, "unsupported value"); return NULL; } } switch (ptype) { case INT: if (!IntFromObj (values, &ival)) return NULL; CLEAR_ALERROR_STATE (); alSourcei ((ALuint)bufnum, param, (ALint) ival); break; case FLOAT: if (!DoubleFromObj (values, &fval)) return NULL; CLEAR_ALERROR_STATE (); alSourcef ((ALuint)bufnum, param, (ALfloat) fval); break; default: PyErr_SetString (PyExc_TypeError, "value type mismatch"); return NULL; } } if (SetALErrorException (alGetError (), 0)) return NULL; Py_RETURN_NONE; }