示例#1
0
F8RES_API char * get_res_buf(
	const f8_uuid * id,
	int *length,
	const char * key
	)
{
	F8_RESOURCE * res;
	F8_RESITEM * item;

	res = _get_res(id);
	if(!res){
		return __false;
	}
	item = _get_item(res, key);

	if(!item){
		if(length){
			*length = 0;
		}
		return __false;
	}
	if(length){
		*length = item->length;
	}
	return (char*)item->buffer;
}
示例#2
0
/*
	associate a buffer with a guid and a key
	the old buffer will be freeed automatically.
*/
F8RES_API __bool set_res_buf_ex(
	const f8_uuid * id,
	const void * buffer,
	int length,
	const char * key,
	__bool bForce
	)
{
	F8_RESOURCE * res;
	F8_RESITEM * item;

	res = _get_res(id);
	if(!res && bForce){
		create_resource(id);		
		res = _get_res(id);
	}
	if(!res){
		assert(0);
		return __false;
	}
	item = _get_item(res, key);
	if(!item){
		item = _new_item(res, key);
	}

	if(!item){
		return __false;
	}
	
	if(length == -1){
		length = strlen((const char*)buffer) + 1;
	}

	if(item->buffer == buffer){
		item->length = length;
		return __true;
	}

	if(item->buffer){
		__free__(item->buffer);
	}

	if(length){
		item->buffer = __malloc__(length);
		item->length = length;
		if(!item->buffer){
			return __false;
		}
		memcpy(item->buffer, buffer, length);
	}else{
		item->buffer = 0;
		item->length = 0;
	}

	return __true;
}
示例#3
0
static int
_create_event_from_dict (PyObject *dict, SDL_Event *event)
{
    PyObject *val, *tuple;

    if (event->type >= SDL_USEREVENT && event->type < SDL_NUMEVENTS)
    {
        /* We use a special mapping - outline this in the docs! */
        event->user.code = PYGAME_USEREVENT_CODE;
        event->user.data1 = (void*)PYGAME_USEREVENT;
        event->user.data2 = dict;
        Py_INCREF (dict);
        return 1;
    }

    switch (event->type)
    {
    case SDL_ACTIVEEVENT:
        if (!_get_item (dict, "gain", &val))
            return 0;
        event->active.gain = (Uint8) PyInt_AsLong (val);
        if (event->active.gain == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "state", &val))
            return 0;
        event->active.state = (Uint8) PyInt_AsLong (val);
        if (event->active.state == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_KEYDOWN:
    case SDL_KEYUP:
        if (!_get_item (dict, "state", &val))
            return 0;
        event->key.state = (Uint8) PyInt_AsLong (val);
        if (event->key.state == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "scancode", &val))
            return 0;
        event->key.keysym.scancode = (Uint8) PyInt_AsLong (val);
        if (event->key.keysym.scancode == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "key", &val))
            return 0;
        event->key.keysym.sym = PyInt_AsLong (val);
        if (event->key.keysym.sym == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "mod", &val))
            return 0;
        event->key.keysym.mod = PyInt_AsLong (val);
        if (event->key.keysym.mod == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "unicode", &val))
            return 0;
        event->key.keysym.unicode = (Uint16) PyInt_AsLong (val);
        if (event->key.keysym.unicode == (Uint16)-1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_MOUSEMOTION:
        if (!_get_item (dict, "state", &val))
            return 0;
        event->motion.state = (Uint8) PyInt_AsLong (val);
        if (event->motion.state == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "x", &val))
            return 0;
        event->motion.x = (Uint16) PyInt_AsLong (val);
        if (event->motion.x == (Uint16)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "y", &val))
            return 0;
        event->motion.y = (Uint16) PyInt_AsLong (val);
        if (event->motion.y == (Uint16)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "xrel", &val))
            return 0;
        event->motion.xrel = (Sint16) PyInt_AsLong (val);
        if (event->motion.xrel == -1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "yrel", &val))
            return 0;
        event->motion.yrel = (Sint16) PyInt_AsLong (val);
        if (event->motion.yrel == -1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "buttons", &tuple))
            return 0;
        if (!PyTuple_Check (tuple) || PyTuple_Size (tuple) != 3)
        {
            PyErr_SetString (PyExc_ValueError,
                             "buttons value for motion event must be a tuple");
            return 0;
        }
        val = PyTuple_GetItem (tuple, 0);
        if (!val)
            return 0;
        if (val == Py_True)
            event->motion.state |= SDL_BUTTON(1);
        val = PyTuple_GetItem (tuple, 1);
        if (!val)
            return 0;
        if (val == Py_True)
            event->motion.state |= SDL_BUTTON(2);
        val = PyTuple_GetItem (tuple, 2);
        if (!val)
            return 0;
        if (val == Py_True)
            event->motion.state |= SDL_BUTTON(3);
        break;

    case SDL_MOUSEBUTTONDOWN:
    case SDL_MOUSEBUTTONUP:
        if (!_get_item (dict, "button", &val))
            return 0;
        event->button.button = (Uint8) PyInt_AsLong (val);
        if (event->button.button == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "x", &val))
            return 0;
        event->button.x = (Uint16) PyInt_AsLong (val);
        if (event->button.x == (Uint16)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "y", &val))
            return 0;
        event->button.y = (Uint16) PyInt_AsLong (val);
        if (event->button.y == (Uint16)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "state", &val))
            return 0;
        event->button.state = (Uint8) PyInt_AsLong (val);
        if (event->button.state == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_JOYAXISMOTION:
        if (!_get_item (dict, "which", &val))
            return 0;
        event->jaxis.which = (Uint8) PyInt_AsLong (val);
        if (event->jaxis.which == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "axis", &val))
            return 0;
        event->jaxis.axis = (Uint8) PyInt_AsLong (val);
        if (event->jaxis.axis == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "value", &val))
            return 0;
        event->jaxis.value = (Sint16) PyInt_AsLong (val);
        if (event->jaxis.value == -1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_JOYBALLMOTION:
        if (!_get_item (dict, "which", &val))
            return 0;
        event->jball.which = (Uint8) PyInt_AsLong (val);
        if (event->jball.which == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "ball", &val))
            return 0;
        event->jball.ball = (Uint8) PyInt_AsLong (val);
        if (event->jball.ball == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "xrel", &val))
            return 0;
        event->jball.xrel = (Sint16) PyInt_AsLong (val);
        if (event->jball.xrel == -1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "yrel", &val))
            return 0;
        event->jball.yrel = (Sint16) PyInt_AsLong (val);
        if (event->jball.yrel == -1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_JOYHATMOTION:
        if (!_get_item (dict, "which", &val))
            return 0;
        event->jhat.which = (Uint8) PyInt_AsLong (val);
        if (event->jhat.which == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "hat", &val))
            return 0;
        event->jhat.hat = (Uint8) PyInt_AsLong (val);
        if (event->jhat.hat == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "value", &val))
            return 0;
        event->jhat.value = (Uint8) PyInt_AsLong (val);
        if (event->jhat.value == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_JOYBUTTONDOWN:
    case SDL_JOYBUTTONUP:
        if (!_get_item (dict, "which", &val))
            return 0;
        event->jbutton.which = (Uint8) PyInt_AsLong (val);
        if (event->jbutton.which == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "button", &val))
            return 0;
        event->jbutton.button = (Uint8) PyInt_AsLong (val);
        if (event->jbutton.button == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "state", &val))
            return 0;
        event->jbutton.state = (Uint8) PyInt_AsLong (val);
        if (event->jbutton.state == (Uint8)-1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_VIDEORESIZE:
        if (!_get_item (dict, "w", &val))
            return 0;
        event->resize.w = PyInt_AsLong (val);
        if (event->resize.w == -1 && PyErr_Occurred ())
            return 0;
        if (!_get_item (dict, "h", &val))
            return 0;
        event->resize.h = PyInt_AsLong (val);
        if (event->resize.h == -1 && PyErr_Occurred ())
            return 0;
        break;

    case SDL_SYSWMEVENT:
        return 0;
    case SDL_QUIT:
        return 0;
    case SDL_VIDEOEXPOSE:
        return 0;
    }
    return 1;
}