/** * Process an X11 event. */ static int ProcessEvent (vout_display_t *vd, xcb_window_t window, xcb_generic_event_t *ev) { switch (ev->response_type & 0x7f) { case XCB_BUTTON_PRESS: HandleButtonPress (vd, (xcb_button_press_event_t *)ev); break; case XCB_BUTTON_RELEASE: HandleButtonRelease (vd, (xcb_button_release_event_t *)ev); break; case XCB_MOTION_NOTIFY: HandleMotionNotify (vd, (xcb_motion_notify_event_t *)ev); break; case XCB_CONFIGURE_NOTIFY: { xcb_configure_notify_event_t *cn = (xcb_configure_notify_event_t *)ev; assert (cn->window != window); HandleParentStructure (vd, cn); break; } /* FIXME I am not sure it is the right one */ case XCB_DESTROY_NOTIFY: vout_display_SendEventClose (vd); break; case XCB_MAPPING_NOTIFY: break; default: msg_Dbg (vd, "unhandled event %"PRIu8, ev->response_type); } free (ev); return VLC_SUCCESS; }
inline void SDLHandleUserInput(SDL_Event *Event, game_code *GameCode, game_memory *GameMemory, keyboard_input *KeyboardInput, gamepad_input *GamePadInput) { int KeyCode = Event->key.keysym.sym; uint8 GamePadButton = Event->cbutton.button; const uint8 *KeyState = SDL_GetKeyboardState(NULL); switch(Event->type) { case SDL_KEYDOWN: if(KeyCode == SDLK_ESCAPE) { HandleButtonPress(&KeyboardInput->Escape); GlobalRunning = false; } if(KeyCode == SDLK_a) { HandleButtonPress(&KeyboardInput->A); UnloadGameCode(GameCode); *GameCode = LoadGameCode(); GameMemory->IsInitialized = false; } if(KeyState[SDL_SCANCODE_LALT] && KeyState[SDL_SCANCODE_RETURN] ) { if(!Fullscreen){ SDL_SetWindowFullscreen(SDL_GetWindowFromID(Event->window.windowID), SDL_WINDOW_FULLSCREEN); SDL_SetRelativeMouseMode((SDL_bool)SDL_ENABLE); Fullscreen = true; } else { SDL_SetWindowFullscreen(SDL_GetWindowFromID(Event->window.windowID), 0); SDL_SetRelativeMouseMode((SDL_bool)SDL_DISABLE); Fullscreen = false; } } if(KeyCode == SDLK_b) { HandleButtonPress(&KeyboardInput->B); } if(KeyCode == SDLK_f) { HandleButtonPress(&KeyboardInput->F); } if(KeyCode == SDLK_UP) { HandleButtonPress(&KeyboardInput->Up); } if(KeyCode == SDLK_DOWN) { HandleButtonPress(&KeyboardInput->Down); } if(KeyCode == SDLK_LEFT) { HandleButtonPress(&KeyboardInput->Left); } if(KeyCode == SDLK_RIGHT) { HandleButtonPress(&KeyboardInput->Right); } break; case SDL_KEYUP: if(KeyCode == SDLK_ESCAPE) { HandleButtonRelease(&KeyboardInput->Escape); } if(KeyCode == SDLK_b) { HandleButtonRelease(&KeyboardInput->B); } if(KeyCode == SDLK_f) { HandleButtonRelease(&KeyboardInput->F); } if(KeyCode == SDLK_a) { HandleButtonRelease(&KeyboardInput->A); } if(KeyCode == SDLK_UP) { HandleButtonRelease(&KeyboardInput->Up); } if(KeyCode == SDLK_DOWN) { HandleButtonRelease(&KeyboardInput->Down); } if(KeyCode == SDLK_LEFT) { HandleButtonRelease(&KeyboardInput->Left); } if(KeyCode == SDLK_RIGHT) { HandleButtonRelease(&KeyboardInput->Right); } break; case SDL_CONTROLLERBUTTONDOWN: if(GamePadButton == SDL_CONTROLLER_BUTTON_A) { HandleButtonPress(&GamePadInput->AButton); } if(GamePadButton == SDL_CONTROLLER_BUTTON_B) { HandleButtonPress(&GamePadInput->BButton); } if(GamePadButton == SDL_CONTROLLER_BUTTON_X) { HandleButtonPress(&GamePadInput->XButton); } if(GamePadButton == SDL_CONTROLLER_BUTTON_Y) { HandleButtonPress(&GamePadInput->YButton); } break; case SDL_CONTROLLERBUTTONUP: if(GamePadButton == SDL_CONTROLLER_BUTTON_A) { HandleButtonRelease(&GamePadInput->AButton); } if(GamePadButton == SDL_CONTROLLER_BUTTON_B) { HandleButtonRelease(&GamePadInput->BButton); GlobalRunning = false; } if(GamePadButton == SDL_CONTROLLER_BUTTON_X) { HandleButtonRelease(&GamePadInput->XButton); } if(GamePadButton == SDL_CONTROLLER_BUTTON_Y) { HandleButtonRelease(&GamePadInput->YButton); } break; } // NOTE(Redab): Get values from gamepad joysticks and normalize. real32 LSX = (real32)SDL_GameControllerGetAxis(GamePadHandle, SDL_CONTROLLER_AXIS_LEFTX); if(LSX < 0) { GamePadInput->LeftStick.X = LSX / 32768.0f; } else { GamePadInput->LeftStick.X = LSX / 32767.0f; } real32 LSY = (real32)SDL_GameControllerGetAxis(GamePadHandle, SDL_CONTROLLER_AXIS_LEFTY); if(LSY < 0) { GamePadInput->LeftStick.Y = LSY / 32768.0f; } else { GamePadInput->LeftStick.Y = LSY / 32767.0f; } real32 RSX = (real32)SDL_GameControllerGetAxis(GamePadHandle, SDL_CONTROLLER_AXIS_RIGHTX); if(RSX < 0) { GamePadInput->RightStick.X = RSX / 32768.0f; } else { GamePadInput->RightStick.X = RSX / 32767.0f; } real32 RSY = (real32)SDL_GameControllerGetAxis(GamePadHandle, SDL_CONTROLLER_AXIS_RIGHTY); if(RSY < 0) { GamePadInput->RightStick.Y = RSY / 32768.0f; } else { GamePadInput->RightStick.Y = RSY / 32767.0f; } }