示例#1
0
static uint8_t sdl_pad_get_hat(sdl_joypad_t *pad, unsigned hat)
{
#ifdef HAVE_SDL2
   if (pad->controller)
      return sdl_pad_get_button(pad, hat);
#endif
   return SDL_JoystickGetHat(pad->joypad, hat);
}
示例#2
0
static bool sdl_joypad_button(unsigned port, uint16_t joykey)
{
   sdl_joypad_t *pad = NULL;
   if (joykey == NO_BTN)
      return false;

   pad = (sdl_joypad_t*)&sdl_pads[port];
   if (!pad->joypad)
      return false;

   /* Check hat. */
   if (GET_HAT_DIR(joykey))
   {
      uint8_t  dir;
      uint16_t hat = GET_HAT(joykey);
      if (hat >= pad->num_hats)
         return false;

      dir = sdl_pad_get_hat(pad, hat);

      switch (GET_HAT_DIR(joykey))
      {
         case HAT_UP_MASK:
            return dir & SDL_HAT_UP;
         case HAT_DOWN_MASK:
            return dir & SDL_HAT_DOWN;
         case HAT_LEFT_MASK:
            return dir & SDL_HAT_LEFT;
         case HAT_RIGHT_MASK:
            return dir & SDL_HAT_RIGHT;
         default:
            break;
      }
      return false;
   }

   /* Check the button */
   if (joykey < pad->num_buttons && sdl_pad_get_button(pad, joykey))
      return true;

   return false;
}