1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| /* handle an event sent by the GUI */
static void event_loop(VideoState *cur_stream)
{
int action;
SDL_GameController *ControllerHandles[2];
int MaxJoysticks = SDL_NumJoysticks();
int ControllerIndex = 0;
for(int JoystickIndex=0; JoystickIndex < MaxJoysticks; ++JoystickIndex)
{
if (!SDL_IsGameController(JoystickIndex))
{
continue;
}
if (ControllerIndex >= 2)
{
break;
}
ControllerHandles[ControllerIndex] = SDL_GameControllerOpen(JoystickIndex);
ControllerIndex++;
}
SDL_Event event;
double incr, pos, frac;
for (;;) {
double x;
refresh_loop_wait_event(cur_stream, &event);
SDL_GameControllerUpdate();
action = 0;
/**
* Pour le controller
*/
for (int ControllerIndex = 0;
ControllerIndex < 1;
++ControllerIndex)
{
if(ControllerHandles[ControllerIndex] != 0 && SDL_GameControllerGetAttached(ControllerHandles[ControllerIndex]))
{
// NOTE: We have a controller with index ControllerIndex.
Uint8 Up = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_UP);
Uint8 Down = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_DOWN);
Uint8 Start = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_START);
Uint8 Back = SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_BACK);
// Pause - Play
if(Start == 1){
toggle_pause(cur_stream);
}
// Quit player
if(Back == 1){
do_exit(cur_stream);
}
}
else
{
// TODO: This controller is not plugged in.
printf("No controller plugged! \n");
}
}
...
}
} |
Partager