Ejemplo n.º 1
0
int sandbox_pm_shutdown(void)
{
	sandbox_exit();
	return 0;
}
Ejemplo n.º 2
0
static int handle_event(void * data)
{
	struct event_callback_t * cb = (struct event_callback_t *)(data);
	SDL_GameController * gc = NULL;
	SDL_Event e;
	int x, y, v;
	unsigned int button;

	while(1)
	{
		if(SDL_WaitEvent(&e))
		{
	        switch(e.type)
	        {
	        case SDL_KEYDOWN:
	        	if(cb->key.down)
	        		cb->key.down(cb->key.device, keycode_map(e.key.keysym.sym));
	        	break;

	        case SDL_KEYUP:
	        	if(cb->key.up)
	        		cb->key.up(cb->key.device, keycode_map(e.key.keysym.sym));
	        	break;

	        case SDL_MOUSEBUTTONDOWN:
	        	switch(e.button.button)
	        	{
				case SDL_BUTTON_LEFT:
					button = 0x01;
					break;
				case SDL_BUTTON_MIDDLE:
					button = 0x02;
					break;
				case SDL_BUTTON_RIGHT:
					button = 0x03;
					break;
				case SDL_BUTTON_X1:
					button = 0x04;
					break;
				case SDL_BUTTON_X2:
					button = 0x05;
					break;
				default:
					button = 0x00;
					break;
	        	}
				if(cb->mouse.down && (button != 0x00))
					cb->mouse.down(cb->mouse.device, e.button.x, e.button.y, button);
				break;

	        case SDL_MOUSEMOTION:
	        	if(cb->mouse.move)
	        		cb->mouse.move(cb->mouse.device, e.motion.x, e.motion.y);
	        	break;

	        case SDL_MOUSEBUTTONUP:
	        	switch(e.button.button)
	        	{
				case SDL_BUTTON_LEFT:
					button = 0x01;
					break;
				case SDL_BUTTON_MIDDLE:
					button = 0x02;
					break;
				case SDL_BUTTON_RIGHT:
					button = 0x03;
					break;
				case SDL_BUTTON_X1:
					button = 0x04;
					break;
				case SDL_BUTTON_X2:
					button = 0x05;
					break;
				default:
					button = 0x00;
					break;
	        	}
				if(cb->mouse.up && (button != 0x00))
					cb->mouse.up(cb->mouse.device, e.button.x, e.button.y, button);
				break;

	        case SDL_MOUSEWHEEL:
	        	if(cb->mouse.wheel)
	        		cb->mouse.wheel(cb->mouse.device, e.wheel.x, e.wheel.y);
	        	break;
/*
	        case SDL_FINGERDOWN:
				if(cb->touch.begin)
					cb->touch.begin(cb->touch.device, (int)(e.tfinger.x * sandbox_sdl_fb_get_width()), (int)(e.tfinger.y * sandbox_sdl_fb_get_height()), (unsigned int)e.tfinger.fingerId);
	        	break;

	        case SDL_FINGERMOTION:
				if(cb->touch.move)
					cb->touch.move(cb->touch.device, (int)(e.tfinger.x * sandbox_sdl_fb_get_width()), (int)(e.tfinger.y * sandbox_sdl_fb_get_height()), (unsigned int)e.tfinger.fingerId);
	        	break;

	        case SDL_FINGERUP:
				if(cb->touch.end)
					cb->touch.end(cb->touch.device, (int)(e.tfinger.x * sandbox_sdl_fb_get_width()), (int)(e.tfinger.y * sandbox_sdl_fb_get_height()), (unsigned int)e.tfinger.fingerId);
	        	break;
*/
	        case SDL_CONTROLLERDEVICEADDED:
	        	if(!gc)
	        		gc = SDL_GameControllerOpen(e.cdevice.which);
	            break;

	        case SDL_CONTROLLERDEVICEREMOVED:
	        	if(gc)
	        	{
	        		SDL_GameControllerClose(gc);
	        		gc = NULL;
	        	}
	            break;

	        case SDL_CONTROLLERAXISMOTION:
	        	switch(e.caxis.axis)
	        	{
				case SDL_CONTROLLER_AXIS_LEFTX:
				case SDL_CONTROLLER_AXIS_LEFTY:
					x = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTX);
					y = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTY);
					if(cb->joystick.left_stick)
						cb->joystick.left_stick(cb->joystick.device, x, y);
					break;

				case SDL_CONTROLLER_AXIS_RIGHTX:
				case SDL_CONTROLLER_AXIS_RIGHTY:
					x = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_RIGHTX);
					y = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_RIGHTY);
					if(cb->joystick.right_stick)
						cb->joystick.right_stick(cb->joystick.device, x, y);
					break;

				case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
					v = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
					if(cb->joystick.left_trigger)
						cb->joystick.left_trigger(cb->joystick.device, v);
					break;

				case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
					v = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
					if(cb->joystick.right_trigger)
						cb->joystick.right_trigger(cb->joystick.device, v);
					break;

				default:
					break;
	        	}
	        	break;

	        case SDL_CONTROLLERBUTTONDOWN:
				switch(e.cbutton.button)
				{
				case SDL_CONTROLLER_BUTTON_A:
					button = 0x05;
					break;
				case SDL_CONTROLLER_BUTTON_B:
					button = 0x06;
					break;
				case SDL_CONTROLLER_BUTTON_X:
					button = 0x07;
					break;
				case SDL_CONTROLLER_BUTTON_Y:
					button = 0x08;
					break;
				case SDL_CONTROLLER_BUTTON_BACK:
					button = 0x09;
					break;
				case SDL_CONTROLLER_BUTTON_GUIDE:
					button = 0x0b;
					break;
				case SDL_CONTROLLER_BUTTON_START:
					button = 0x0a;
					break;
				case SDL_CONTROLLER_BUTTON_LEFTSTICK:
					button = 0x0e;
					break;
				case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
					button = 0x0f;
					break;
				case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
					button = 0x0c;
					break;
				case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
					button = 0x0d;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_UP:
					button = 0x01;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
					button = 0x02;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
					button = 0x03;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
					button = 0x04;
					break;
				default:
					button = 0x00;
					break;
				}
				if(cb->joystick.button_down && (button != 0x00))
					cb->joystick.button_down(cb->joystick.device, button);
				break;

	        case SDL_CONTROLLERBUTTONUP:
				switch(e.cbutton.button)
				{
				case SDL_CONTROLLER_BUTTON_A:
					button = 0x05;
					break;
				case SDL_CONTROLLER_BUTTON_B:
					button = 0x06;
					break;
				case SDL_CONTROLLER_BUTTON_X:
					button = 0x07;
					break;
				case SDL_CONTROLLER_BUTTON_Y:
					button = 0x08;
					break;
				case SDL_CONTROLLER_BUTTON_BACK:
					button = 0x09;
					break;
				case SDL_CONTROLLER_BUTTON_GUIDE:
					button = 0x0b;
					break;
				case SDL_CONTROLLER_BUTTON_START:
					button = 0x0a;
					break;
				case SDL_CONTROLLER_BUTTON_LEFTSTICK:
					button = 0x0e;
					break;
				case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
					button = 0x0f;
					break;
				case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
					button = 0x0c;
					break;
				case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
					button = 0x0d;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_UP:
					button = 0x01;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
					button = 0x02;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
					button = 0x03;
					break;
				case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
					button = 0x04;
					break;
				default:
					button = 0x00;
					break;
				}
				if(cb->joystick.button_up && (button != 0x00))
					cb->joystick.button_up(cb->joystick.device, button);
	        	break;

	        case SDL_QUIT:
	        	sandbox_exit();
	        	break;

	        default:
	        	break;
	        }
		}
	}

	return 0;
}