24  while (SDL_PollEvent(&e)) {
 
   26      case SDL_EVENT_WINDOW_RESIZED: {
 
   32        SDL_Point window_size;
 
   36        SDL_Point render_size;
 
   38                                         &render_size.y, 
nullptr);
 
   40        const auto x_scale = 
static_cast<float>(window_size.x) /
 
   41                             static_cast<float>(render_size.x);
 
   43        const auto y_scale = 
static_cast<float>(window_size.y) /
 
   44                             static_cast<float>(render_size.y);
 
   46        const auto scale = std::min(x_scale, y_scale);
 
   49                          static_cast<float>(render_size.x) * scale,
 
   50                          static_cast<float>(render_size.y) * scale);
 
   54      case SDL_EVENT_KEY_DOWN: {
 
   56          keyboard.pressed[e.key.scancode] = 
true;
 
   57          keyboard.down[e.key.scancode] = 
true;
 
   58          keyboard.anyPressed = 
true;
 
   59          keyboard.lastPressed = e.key.scancode;
 
   64      case SDL_EVENT_KEY_UP: {
 
   66          keyboard.released[e.key.scancode] = 
true;
 
   67          keyboard.down[e.key.scancode] = 
false;
 
   72      case SDL_EVENT_MOUSE_BUTTON_DOWN: {
 
   73        const auto button = 
static_cast<int>(e.button.button);
 
   74        mouse.pressed[button] = 
true;
 
   75        mouse.down[button] = 
true;
 
   76        mouse.anyPressed = 
true;
 
   77        mouse.lastPressed = button;
 
   81      case SDL_EVENT_MOUSE_BUTTON_UP: {
 
   82        auto button = 
static_cast<int>(e.button.button);
 
   83        mouse.released[button] = 
true;
 
   84        mouse.down[button] = 
false;
 
   88      case SDL_EVENT_MOUSE_MOTION: {
 
   91        mouse.xChange = e.motion.xrel;
 
   92        mouse.yChange = e.motion.yrel;
 
   98      case SDL_EVENT_MOUSE_WHEEL: {
 
  103      case SDL_EVENT_GAMEPAD_AXIS_MOTION: {
 
  108        auto motion = e.gaxis.value / 32768.0f;
 
  109        auto& current = controller[e.gaxis.which];
 
  111        if (motion > current.deadZone) {
 
  112          current.axis[e.gaxis.axis] = motion;
 
  113        } 
else if (motion < -current.deadZone) {
 
  114          current.axis[e.gaxis.axis] = motion;
 
  116          current.axis[e.gaxis.axis] = 0.0f;
 
  122      case SDL_EVENT_GAMEPAD_BUTTON_DOWN: {
 
  127        auto button = 
static_cast<int>(e.gbutton.button);
 
  128        controller[e.gbutton.which].pressed[button] = 
true;
 
  129        controller[e.gbutton.which].down[button] = 
true;
 
  130        controller[e.gbutton.which].anyPressed = 
true;
 
  131        controller[e.gbutton.which].lastPressed = button;
 
  135      case SDL_EVENT_GAMEPAD_BUTTON_UP: {
 
  140        auto button = 
static_cast<int>(e.gbutton.button);
 
  141        controller[e.gbutton.which].released[button] = 
true;
 
  142        controller[e.gbutton.which].down[button] = 
false;
 
  146      case SDL_EVENT_GAMEPAD_ADDED: {
 
  148            !SDL_IsGamepad(e.gdevice.which) ||
 
  149            SDL_OpenGamepad(e.gdevice.which) == 
nullptr) {
 
  154        SDL_OpenGamepad(e.gdevice.which);
 
  159      case SDL_EVENT_GAMEPAD_REMOVED: {
 
  164        auto* controller = SDL_GetGamepadFromID(e.gdevice.which);
 
  167          SDL_CloseGamepad(controller);
 
  173      case SDL_EVENT_QUIT: {
 
 
  185  if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD)) {
 
  195  spec.format = SDL_AUDIO_S16LE;
 
  199  if (!Mix_OpenAudio(0, &spec)) {
 
  204      SDL_CreateWindow(
"", width * scale, height * scale, SDL_WINDOW_RESIZABLE);
 
  211  SDL_SetHint(SDL_HINT_RENDER_VSYNC, 
"1");
 
  217                                   SDL_LOGICAL_PRESENTATION_LETTERBOX);