Esempio n. 1
0
void
TerminateOnError(
   const char *fmt,
   ...
)
// This function terminates the game because of an error and
// prints the message string pointed to by fmt both in the
// console and in a messagebox.
{
   va_list argptr;
   char string[256];
   extern VOID PAL_Shutdown(VOID);

   // concatenate all the arguments in one string
   va_start(argptr, fmt);
   vsnprintf(string, sizeof(string), fmt, argptr);
   va_end(argptr);

   fprintf(stderr, "\nFATAL ERROR: %s\n", string);

#if SDL_VERSION_ATLEAST(2, 0, 0)
   {
      extern SDL_Window *gpWindow;
      SDL_ShowSimpleMessageBox(0, "FATAL ERROR", string, gpWindow);
   }
#else

#ifdef _WIN32
   MessageBoxA(0, string, "FATAL ERROR", MB_ICONERROR);
#endif

#ifdef __linux__
   panic("beep; xmessage -center \"FATAL ERROR: %s\"", string);
#endif

#if defined(__SYMBIAN32__)
   UTIL_WriteLog(LOG_DEBUG,"[0x%08x][%s][%s] - %s",(long)TerminateOnError,"TerminateOnError",__FILE__, string);
   SDL_Delay(3000);
#endif

#endif

#ifdef _DEBUG
   assert(!"TerminateOnError()"); // allows jumping to debugger
#endif


PAL_Shutdown();

#if defined (NDS)
   while (1);
#else
   exit(255);
#endif
}
Esempio n. 2
0
int 
PAL_EventFilter(
   void                  *userdata,
   const SDL_Event       *lpEvent
)

/*++
  Purpose:

    SDL event filter function. A filter to process all events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    1 = the event will be added to the internal queue.
    0 = the event will be dropped from the queue.

--*/
{
   switch (lpEvent->type)
   {
   case SDL_VIDEORESIZE:
      //
      // resized the window
      //
      VIDEO_Resize(lpEvent->resize.w, lpEvent->resize.h);
      break;

   case SDL_QUIT:
      //
      // clicked on the close button of the window. Quit immediately.
      //
      PAL_Shutdown();
      exit(0);
   }

   PAL_KeyboardEventFilter(lpEvent);
   PAL_MouseEventFilter(lpEvent);
   PAL_JoystickEventFilter(lpEvent);

   //
   // All events are handled here; don't put anything to the internal queue
   //
   return 0;
}
Esempio n. 3
0
static int SDLCALL
PAL_EventFilter(
    void                  *userdata,
    const SDL_Event       *lpEvent
)
#endif
/*++
  Purpose:

    SDL event filter function. A filter to process all events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    1 = the event will be added to the internal queue.
    0 = the event will be dropped from the queue.

--*/
{
    switch (lpEvent->type)
    {
    case SDL_QUIT:
        //
        // clicked on the close button of the window. Quit immediately.
        //
        PAL_Shutdown();
        exit(0);
    }

    //
    // All events are handled here; don't put anything to the internal queue
    //
    return 0;
}
Esempio n. 4
0
static VOID
PAL_KeyboardEventFilter(
   const SDL_Event       *lpEvent
)
/*++
  Purpose:

    Handle keyboard events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    None.

--*/
{
   switch (lpEvent->type)
   {
   case SDL_KEYDOWN:
      //
      // Pressed a key
      //edit by niuzb press f4 then exit
      if (/*lpEvent->key.keysym.mod & KMOD_ALT*/1)
      {
#if 0
		 if (lpEvent->key.keysym.sym == SDLK_RETURN)
         {
            //
            // Pressed Alt+Enter (toggle fullscreen)...
            //
            VIDEO_ToggleFullscreen();
            return;
         }
         else 
#endif
		if (lpEvent->key.keysym.sym == SDLK_F4)
         {
            //
            // Pressed Alt+F4 (Exit program)...
            //
            PAL_Shutdown();
            exit(0);
         }
      }
	  //__android_log_print(ANDROID_LOG_INFO, "libSDL", "key down %c ,%d", lpEvent->key.keysym.sym,lpEvent->key.keysym.sym);
//printf("sdl kp %d is pressed****\n",lpEvent->key.keysym.sym);
      switch (lpEvent->key.keysym.sym)
      {
#ifdef __SYMBIAN32__
      //
      // Symbian-specific stuff
      //
      case SDLK_0:
         VIDEO_ToggleScaleScreen();
         break;
      case SDLK_1:
         SOUND_AdjustVolume(0);
         break;
      case SDLK_3:
         SOUND_AdjustVolume(1);
         break;
#endif

      case SDLK_UP:
      case SDLK_KP8:
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirNorth;
         g_InputState.dwKeyPress |= kKeyUp;
         break;
	  case SDLK_KP2:
	  	g_InputState.dwKeyPress |= kKeySave;
		break;
	  case SDLK_KP4:
	  	g_InputState.dwKeyPress |= kKeyStore;
		break;
          case SDLK_KP5:{
             // printf("sdl kp 5 is pressed\n****");
              g_InputState.dwKeyPress |= kKeyfullblood;
              break;}
      case SDLK_DOWN:
      
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirSouth;
         g_InputState.dwKeyPress |= kKeyDown;
         break;

      case SDLK_LEFT:
      
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirWest;
         g_InputState.dwKeyPress |= kKeyLeft;
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirEast;
         g_InputState.dwKeyPress |= kKeyRight;
         break;

      case SDLK_ESCAPE:
      case SDLK_INSERT:
      case SDLK_LALT:
      case SDLK_RALT:
      case SDLK_KP0:
         g_InputState.dwKeyPress |= kKeyMenu;
         break;

      case SDLK_RETURN:
      case SDLK_SPACE:
      case SDLK_KP_ENTER:
         g_InputState.dwKeyPress |= kKeySearch;
         break;

      case SDLK_PAGEUP:
      case SDLK_KP9:
         g_InputState.dwKeyPress |= kKeyPgUp;
         break;

      case SDLK_PAGEDOWN:
      case SDLK_KP3:
         g_InputState.dwKeyPress |= kKeyPgDn;
         break;

      case SDLK_7: //7 for mobile device
      case SDLK_r:
         g_InputState.dwKeyPress |= kKeyRepeat;
         break;

      case SDLK_2: //2 for mobile device
      case SDLK_a:
         g_InputState.dwKeyPress |= kKeyAuto;
         break;

      case SDLK_d:
         g_InputState.dwKeyPress |= kKeyDefend;
         break;

	  
      case SDLK_e:
         g_InputState.dwKeyPress |= kKeyUseItem;
         break;

      case SDLK_w:
         g_InputState.dwKeyPress |= kKeyThrowItem;
         break;

      case SDLK_q:
         g_InputState.dwKeyPress |= kKeyFlee;
         break;

      case SDLK_s:
         g_InputState.dwKeyPress |= kKeyStatus;
         break;

      case SDLK_f:
	  case SDLK_5: // 5 for mobile device
         g_InputState.dwKeyPress |= kKeyForce;
         break;

      case SDLK_HASH: //# for mobile device
      case SDLK_p:
         VIDEO_SaveScreenshot();
         break;

      default:
         break;
      }
      break;

   case SDL_KEYUP:
      //
      // Released a key
      //
      switch (lpEvent->key.keysym.sym)
      {
      case SDLK_UP:
      case SDLK_KP8:
         if (g_InputState.dir == kDirNorth)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;

      case SDLK_DOWN:
      
         if (g_InputState.dir == kDirSouth)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;
case SDLK_KP2:
              g_InputState.dwKeyPress &= ~kKeySave;
              break;
          case SDLK_KP4:
              g_InputState.dwKeyPress &= ~kKeyStore;
              break;
          case SDLK_KP5:
              g_InputState.dwKeyPress &= ~kKeyfullblood;
              break;
      case SDLK_LEFT:
     
         if (g_InputState.dir == kDirWest)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
         if (g_InputState.dir == kDirEast)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;

      default:
         break;
      }
      break;
   }
}
Esempio n. 5
0
/**
 * Handle keyboard events.
 * @param[in] lpEvent - pointer to the event.
 * @return None
 */
static VOID PAL_KeyboardEventFilter(const SDL_Event *lpEvent)
{
    switch (lpEvent->type) {
        case SDL_KEYDOWN:
            //
            // Pressed a key
            //
            if (lpEvent->key.keysym.mod & KMOD_ALT) {
                if (lpEvent->key.keysym.sym == SDLK_RETURN) {
                    //
                    // Pressed Alt+Enter (toggle fullscreen)...
                    //
                    VIDEO_ToggleFullscreen();
                    return;
                } else if (lpEvent->key.keysym.sym == SDLK_F4) {
                    //
                    // Pressed Alt+F4 (Exit program)...
                    //
                    PAL_Shutdown();
                    exit(0);
                }
            }

            switch (lpEvent->key.keysym.sym) {
#ifdef __SYMBIAN32__
                //
                // Symbian-specific stuff
                //
                case SDLK_0:
                   VIDEO_ToggleScaleScreen();
                   break;
                case SDLK_1:
                   SOUND_AdjustVolume(0);
                   break;
                case SDLK_3:
                   SOUND_AdjustVolume(1);
                   break;
#endif

#ifdef __WINPHONE__
                case SDLK_AC_BACK:
                   if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
                   {
                      PAL_Shutdown();
                      exit(0);
                   }
                   g_uiLastBackKeyTime = SDL_GetTicks();
                   VIDEO_UpdateScreen(NULL);
                   break;
#endif

                case SDLK_UP:
                case SDLK_KP8:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirNorth) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirNorth;
                        g_InputState.dwKeyPress |= kKeyUp;
                    }
                    break;

                case SDLK_DOWN:
                case SDLK_KP2:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirSouth) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirSouth;
                        g_InputState.dwKeyPress |= kKeyDown;
                    }
                    break;

                case SDLK_LEFT:
                case SDLK_KP4:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirWest) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirWest;
                        g_InputState.dwKeyPress |= kKeyLeft;
                    }
                    break;

                case SDLK_RIGHT:
                case SDLK_KP6:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirEast) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirEast;
                        g_InputState.dwKeyPress |= kKeyRight;
                    }
                    break;

#if defined(DINGOO)
                case SDLK_SPACE:
                   g_InputState.dwKeyPress = kKeyMenu;
                   break;

                case SDLK_LCTRL:
                   g_InputState.dwKeyPress = kKeySearch;
                   break;
#else
                case SDLK_ESCAPE:
                case SDLK_INSERT:
                case SDLK_LALT:
                case SDLK_RALT:
                case SDLK_KP0:
                    g_InputState.dwKeyPress |= kKeyMenu;
                    break;

                case SDLK_RETURN:
                case SDLK_SPACE:
                case SDLK_KP_ENTER:
                case SDLK_LCTRL:
                    g_InputState.dwKeyPress |= kKeySearch;
                    break;

                case SDLK_PAGEUP:
                case SDLK_KP9:
                    g_InputState.dwKeyPress |= kKeyPgUp;
                    break;

                case SDLK_PAGEDOWN:
                case SDLK_KP3:
                    g_InputState.dwKeyPress |= kKeyPgDn;
                    break;

                case SDLK_7: //7 for mobile device
                case SDLK_r:
                    g_InputState.dwKeyPress |= kKeyRepeat;
                    break;

                case SDLK_2: //2 for mobile device
                case SDLK_a:
                    g_InputState.dwKeyPress |= kKeyAuto;
                    break;

                case SDLK_d:
                    g_InputState.dwKeyPress |= kKeyDefend;
                    break;

                case SDLK_e:
                    g_InputState.dwKeyPress |= kKeyUseItem;
                    break;

                case SDLK_w:
                    g_InputState.dwKeyPress |= kKeyThrowItem;
                    break;

                case SDLK_q:
                    g_InputState.dwKeyPress |= kKeyFlee;
                    break;

                case SDLK_s:
                    g_InputState.dwKeyPress |= kKeyStatus;
                    break;

                case SDLK_f:
                case SDLK_5: // 5 for mobile device
                    g_InputState.dwKeyPress |= kKeyForce;
                    break;

                case SDLK_HASH: //# for mobile device
                case SDLK_p:
                    VIDEO_SaveScreenshot();
                    break;
#endif

                default:
                    break;
            }
            break;

        case SDL_KEYUP:
            //
            // Released a key
            //
            switch (lpEvent->key.keysym.sym) {
                case SDLK_UP:
                case SDLK_KP8:
                    if (g_InputState.dir == kDirNorth) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                case SDLK_DOWN:
                case SDLK_KP2:
                    if (g_InputState.dir == kDirSouth) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                case SDLK_LEFT:
                case SDLK_KP4:
                    if (g_InputState.dir == kDirWest) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                case SDLK_RIGHT:
                case SDLK_KP6:
                    if (g_InputState.dir == kDirEast) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                default:
                    break;
            }
            break;
    }
}
Esempio n. 6
0
static BOOL
PAL_SystemMenu(
   VOID
)
/*++
  Purpose:

    Show the system menu.

  Parameters:

    None.

  Return value:

    TRUE if user made some operations in the menu, FALSE if user cancelled.

--*/
{
   LPBOX               lpMenuBox;
   WORD                wReturnValue;
   int                 iSlot, i, iSavedTimes;
   FILE               *fp;
   const SDL_Rect      rect = {40, 60, 100, 135};

   //
   // Create menu items
   //
#ifdef PAL_CLASSIC
   MENUITEM        rgSystemMenuItem[5] =
   {
      // value  label                      enabled   pos
      { 1,      SYSMENU_LABEL_SAVE,        TRUE,     PAL_XY(53, 72) },
      { 2,      SYSMENU_LABEL_LOAD,        TRUE,     PAL_XY(53, 72 + 18) },
      { 3,      SYSMENU_LABEL_MUSIC,       TRUE,     PAL_XY(53, 72 + 36) },
      { 4,      SYSMENU_LABEL_SOUND,       TRUE,     PAL_XY(53, 72 + 54) },
      { 5,      SYSMENU_LABEL_QUIT,        TRUE,     PAL_XY(53, 72 + 72) },
   };
#else
   MENUITEM        rgSystemMenuItem[6] =
   {
      // value  label                      enabled   pos
      { 1,      SYSMENU_LABEL_SAVE,        TRUE,     PAL_XY(53, 72) },
      { 2,      SYSMENU_LABEL_LOAD,        TRUE,     PAL_XY(53, 72 + 18) },
      { 3,      SYSMENU_LABEL_MUSIC,       TRUE,     PAL_XY(53, 72 + 36) },
      { 4,      SYSMENU_LABEL_SOUND,       TRUE,     PAL_XY(53, 72 + 54) },
      { 5,      SYSMENU_LABEL_BATTLEMODE,  TRUE,     PAL_XY(53, 72 + 72) },
      { 6,      SYSMENU_LABEL_QUIT,        TRUE,     PAL_XY(53, 72 + 90) },
   };
#endif

   //
   // Create the menu box.
   //
#ifdef PAL_CLASSIC
   lpMenuBox = PAL_CreateBox(PAL_XY(40, 60), 4, 3, 0, TRUE);
#else
   lpMenuBox = PAL_CreateBox(PAL_XY(40, 60), 5, 3, 0, TRUE);
#endif
   VIDEO_UpdateScreen(&rect);

   //
   // Perform the menu.
   //
#ifdef PAL_CLASSIC
   wReturnValue = PAL_ReadMenu(PAL_SystemMenu_OnItemChange, rgSystemMenuItem, 5,
      gpGlobals->iCurSystemMenuItem, MENUITEM_COLOR);
#else
   wReturnValue = PAL_ReadMenu(PAL_SystemMenu_OnItemChange, rgSystemMenuItem, 6,
      gpGlobals->iCurSystemMenuItem, MENUITEM_COLOR);
#endif

   if (wReturnValue == MENUITEM_VALUE_CANCELLED)
   {
      //
      // User cancelled the menu
      //
      PAL_DeleteBox(lpMenuBox);
      VIDEO_UpdateScreen(&rect);
      return FALSE;
   }

   switch (wReturnValue)
   {
   case 1:
      //
      // Save game
      //
      iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);

      if (iSlot != MENUITEM_VALUE_CANCELLED)
      {
         gpGlobals->bCurrentSaveSlot = (BYTE)iSlot;

         iSavedTimes = 0;
         for (i = 1; i <= 5; i++)
         {
            fp = fopen(va("%s%d%s", PAL_SAVE_PREFIX, i, ".rpg"), "rb");
            if (fp != NULL)
            {
               WORD wSavedTimes;
               fread(&wSavedTimes, sizeof(WORD), 1, fp);
               fclose(fp);
               wSavedTimes = SWAP16(wSavedTimes);
               if ((int)wSavedTimes > iSavedTimes)
               {
                  iSavedTimes = wSavedTimes;
               }
            }
         }
         PAL_SaveGame(va("%s%d%s", PAL_SAVE_PREFIX, iSlot, ".rpg"), iSavedTimes + 1);
      }
      break;

   case 2:
      //
      // Load game
      //
      iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);
      if (iSlot != MENUITEM_VALUE_CANCELLED)
      {
         PAL_PlayMUS(0, FALSE, 1);
         PAL_FadeOut(1);
         PAL_InitGameData(iSlot);
      }
      break;

   case 3:
      //
      // Music
      //
      g_fNoMusic = !PAL_SwitchMenu(!g_fNoMusic);
#ifdef PAL_HAS_NATIVEMIDI
      if (g_fUseMidi)
      {
         if (g_fNoMusic)
         {
            PAL_PlayMUS(0, FALSE, 0);
         }
         else
         {
            PAL_PlayMUS(gpGlobals->wNumMusic, TRUE, 0);
         }
      }
#endif
      break;

   case 4:
      //
      // Sound
      //
      g_fNoSound = !PAL_SwitchMenu(!g_fNoSound);
      break;

#ifndef PAL_CLASSIC
   case 5:
      //
      // Battle Mode
      //
      PAL_BattleSpeedMenu();
      break;

   case 6:
#else
   case 5:
#endif
      //
      // Quit
      //
      if (PAL_ConfirmMenu())
      {
         PAL_PlayMUS(0, FALSE, 2);
         PAL_FadeOut(2);
         PAL_Shutdown();
         exit(0);
      }
      break;
   }

   PAL_DeleteBox(lpMenuBox);
   return TRUE;
}
Esempio n. 7
0
VOID
PAL_StartFrame(
VOID
)
/*++
  Purpose:

  Starts a video frame. Called once per video frame.

  Parameters:

  None.

  Return value:

  None.

  --*/
{
	//
	// Run the game logic of one frame
	//
	PAL_GameUpdate(TRUE);
	if (gpGlobals->fEnteringScene)
	{
		return;
	}

	//
	// Update the positions and gestures of party members
	//
	PAL_UpdateParty();

	//
	// Update the scene
	//
	PAL_MakeScene();
	VIDEO_UpdateScreen(NULL);

	if (g_InputState.dwKeyPress & kKeyMenu)
	{
		//
		// Show the in-game menu
		//
		PAL_InGameMenu();
	}
	else if (g_InputState.dwKeyPress & kKeyUseItem)
	{
		//
		// Show the use item menu
		//
		PAL_GameUseItem();
	}
	else if (g_InputState.dwKeyPress & kKeyThrowItem)
	{
		//
		// Show the equipment menu
		//
		PAL_GameEquipItem();
	}
	else if (g_InputState.dwKeyPress & kKeyForce)
	{
		//
		// Show the magic menu
		//
		PAL_InGameMagicMenu();
	}
	else if (g_InputState.dwKeyPress & kKeyStatus)
	{
		//
		// Show the player status
		//
		PAL_PlayerStatus();
	}
	else if (g_InputState.dwKeyPress & kKeySearch)
	{
		//
		// Process search events
		//
		PAL_Search();
	}
	else if (g_InputState.dwKeyPress & kKeyFlee)
	{
		//
		// Quit Game
		//
		if (PAL_ConfirmMenu())
		{
			PAL_PlayMUS(0, FALSE, 2);
			PAL_FadeOut(2);
			PAL_Shutdown();
			exit(0);
		}
	}

	if (--gpGlobals->wChasespeedChangeCycles == 0)
	{
		gpGlobals->wChaseRange = 1;
	}
}
Esempio n. 8
0
/**
 * Handle joystick events.
 *
 * @param[in] lpEvent - pointer to the event.
 * @return None
 */
static VOID PAL_JoystickEventFilter(const SDL_Event *lpEvent)
{
#ifdef PAL_HAS_JOYSTICKS
    switch (lpEvent->type) {
#if defined (GEKKO)
        case SDL_JOYHATMOTION:
           switch (lpEvent->jhat.value)
           {
           case SDL_HAT_LEFT:
             g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
             g_InputState.dir = kDirWest;
             g_InputState.dwKeyPress = kKeyLeft;
             break;

           case SDL_HAT_RIGHT:
             g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
             g_InputState.dir = kDirEast;
             g_InputState.dwKeyPress = kKeyRight;
             break;

           case SDL_HAT_UP:
             g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
             g_InputState.dir = kDirNorth;
             g_InputState.dwKeyPress = kKeyUp;
             break;

           case SDL_HAT_DOWN:
             g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
             g_InputState.dir = kDirSouth;
             g_InputState.dwKeyPress = kKeyDown;
             break;
           }
           break;
#else
        case SDL_JOYAXISMOTION:
            //
            // Moved an axis on joystick
            //
            switch (lpEvent->jaxis.axis) {
                case 0:
                    //
                    // X axis
                    //
#if defined(GPH)
                    if (lpEvent->jaxis.value > MAX_DEADZONE) {
                       g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                       g_InputState.dir = kDirEast;
                       g_InputState.dwKeyPress = kKeyRight;
                    } else if (lpEvent->jaxis.value < MIN_DEADZONE) {
                       g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                       g_InputState.dir = kDirWest;
                       g_InputState.dwKeyPress = kKeyLeft;
                    } else {
                       g_InputState.dir = kDirUnknown;
                    }
#else
                    if (lpEvent->jaxis.value > 20000) {
                        if (g_InputState.dir != kDirEast) {
                            g_InputState.dwKeyPress |= kKeyRight;
                        }
                        g_InputState.prevdir = g_InputState.dir;
                        g_InputState.dir = kDirEast;
                    } else if (lpEvent->jaxis.value < -20000) {
                        if (g_InputState.dir != kDirWest) {
                            g_InputState.dwKeyPress |= kKeyLeft;
                        }
                        g_InputState.prevdir = g_InputState.dir;
                        g_InputState.dir = kDirWest;
                    } else {
                        if (g_InputState.prevdir != kDirEast &&
                                g_InputState.prevdir != kDirWest) {
                            g_InputState.dir = g_InputState.prevdir;
                        }
                        g_InputState.prevdir = kDirUnknown;
                    }
#endif
                    break;

                case 1:
                    //
                    // Y axis
                    //
#if defined(GPH)
                    if (lpEvent->jaxis.value > MAX_DEADZONE) {
                       g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                       g_InputState.dir = kDirSouth;
                       g_InputState.dwKeyPress = kKeyDown;
                    } else if (lpEvent->jaxis.value < MIN_DEADZONE) {
                       g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                       g_InputState.dir = kDirNorth;
                       g_InputState.dwKeyPress = kKeyUp;
                    } else {
                       g_InputState.dir = kDirUnknown;
                    }
#else
                    if (lpEvent->jaxis.value > 20000) {
                        if (g_InputState.dir != kDirSouth) {
                            g_InputState.dwKeyPress |= kKeyDown;
                        }
                        g_InputState.prevdir = g_InputState.dir;
                        g_InputState.dir = kDirSouth;
                    } else if (lpEvent->jaxis.value < -20000) {
                        if (g_InputState.dir != kDirNorth) {
                            g_InputState.dwKeyPress |= kKeyUp;
                        }
                        g_InputState.prevdir = g_InputState.dir;
                        g_InputState.dir = kDirNorth;
                    } else {
                        if (g_InputState.prevdir != kDirNorth &&
                                g_InputState.prevdir != kDirSouth) {
                            g_InputState.dir = g_InputState.prevdir;
                        }
                        g_InputState.prevdir = kDirUnknown;
                    }
#endif
                    break;
            }
            break;
#endif

        case SDL_JOYBUTTONDOWN:
            //
            // Pressed the joystick button
            //
#if defined(GPH)
            switch (lpEvent->jbutton.button)
            {
#if defined(GP2XWIZ)
            case 14:
#elif defined(CAANOO)
            case 3:
#endif
               g_InputState.dwKeyPress = kKeyMenu;
               break;

#if defined(GP2XWIZ)
            case 13:
#elif defined(CAANOO)
            case 2:
#endif
               g_InputState.dwKeyPress = kKeySearch;
               break;
#else
#if defined(GEKKO)
            switch (lpEvent->jbutton.button)
            {
            case 2:
               g_InputState.dwKeyPress |= kKeyMenu;
               break;

            case 3:
               g_InputState.dwKeyPress |= kKeySearch;
               break;
#else
            switch (lpEvent->jbutton.button & 1) {
                case 0:
                    g_InputState.dwKeyPress |= kKeyMenu;
                    break;

                case 1:
                    g_InputState.dwKeyPress |= kKeySearch;
                    break;
#endif
#endif
            }
            break;
    }
#endif
}

#ifdef PAL_HAS_TOUCH

#define  TOUCH_NONE     0
#define    TOUCH_UP      1
#define    TOUCH_DOWN      2
#define    TOUCH_LEFT      3
#define    TOUCH_RIGHT   4
#define    TOUCH_BUTTON1   5
#define    TOUCH_BUTTON2   6
#define  TOUCH_BUTTON3  7
#define  TOUCH_BUTTON4  8

static int
PAL_GetTouchArea(
   float X,
   float Y
)
{
   if (Y < 0.5)
   {
      //
      // Upper area
      //
      return TOUCH_NONE;
   }
   else if (X < 1.0 / 3)
   {
      if (Y - 0.5 < (1.0 / 6 - fabs(X - 1.0 / 3 / 2)) * (0.5 / (1.0 / 3)))
      {
         return TOUCH_UP;
      }
      else if (Y - 0.75 > fabs(X - 1.0 / 3 / 2) * (0.5 / (1.0 / 3)))
      {
         return TOUCH_DOWN;
      }
      else if (X < 1.0 / 3 / 2 && fabs(Y - 0.75) < 0.25 - X * (0.5 / (1.0 / 3)))
      {
         return TOUCH_LEFT;
      }
      else
      {
         return TOUCH_RIGHT;
      }
   }
   else if (X > 1.0 - 1.0 / 3)
   {
      if (X < 1.0 - (1.0 / 3 / 2))
      {
         if (Y < 0.75)
         {
            return TOUCH_BUTTON1;
         }
         else
         {
            return TOUCH_BUTTON3;
         }
      }
      else
      {
         if (Y < 0.75)
         {
            return TOUCH_BUTTON2;
         }
         else
         {
            return TOUCH_BUTTON4;
         }
      }
   }

   return TOUCH_NONE;
}

static VOID
PAL_SetTouchAction(
  int area
)
{
   switch (area)
   {
   case TOUCH_UP:
      g_InputState.dir = kDirNorth;
      g_InputState.dwKeyPress |= kKeyUp;
      break;

   case TOUCH_DOWN:
      g_InputState.dir = kDirSouth;
      g_InputState.dwKeyPress |= kKeyDown;
      break;

   case TOUCH_LEFT:
      g_InputState.dir = kDirWest;
      g_InputState.dwKeyPress |= kKeyLeft;
      break;

   case TOUCH_RIGHT:
      g_InputState.dir = kDirEast;
      g_InputState.dwKeyPress |= kKeyRight;
      break;

   case TOUCH_BUTTON1:
      if (gpGlobals->fInBattle)
      {
         g_InputState.dwKeyPress |= kKeyRepeat;
      }
      else
      {
         g_InputState.dwKeyPress |= kKeyForce;
      }
      break;

   case TOUCH_BUTTON2:
      g_InputState.dwKeyPress |= kKeyMenu;
      break;

   case TOUCH_BUTTON3:
      g_InputState.dwKeyPress |= kKeyUseItem;
      break;

   case TOUCH_BUTTON4:
      g_InputState.dwKeyPress |= kKeySearch;
      break;
   }
}

static VOID
PAL_UnsetTouchAction(
  int area
)
{
   switch (area)
   {
   case TOUCH_UP:
   case TOUCH_DOWN:
   case TOUCH_LEFT:
   case TOUCH_RIGHT:
      g_InputState.dir = kDirUnknown;
      break;
   }
}
#endif

/**
 * Handle touch events.
 *
 * @param[in] lpEvent - pointer to the event.
 * @return None
 */
static VOID PAL_TouchEventFilter(const SDL_Event *lpEvent)
{
#ifdef PAL_HAS_TOUCH
    static SDL_TouchID finger1 = -1, finger2 = -1;
    static int prev_touch1 = TOUCH_NONE;
    static int prev_touch2 = TOUCH_NONE;

    switch (lpEvent->type)
    {
    case SDL_FINGERDOWN:
      if (finger1 == -1)
      {
         int area = PAL_GetTouchArea(lpEvent->tfinger.x, lpEvent->tfinger.y);

         finger1 = lpEvent->tfinger.fingerId;
         prev_touch1 = area;
         PAL_SetTouchAction(area);
      }
      else if (finger2 == -1)
      {
         int area = PAL_GetTouchArea(lpEvent->tfinger.x, lpEvent->tfinger.y);

         finger2 = lpEvent->tfinger.fingerId;
         prev_touch2 = area;
         PAL_SetTouchAction(area);
      }
      break;

    case SDL_FINGERUP:
      if (lpEvent->tfinger.fingerId == finger1)
      {
         PAL_UnsetTouchAction(prev_touch1);
         finger1 = -1;
         prev_touch1 = TOUCH_NONE;
      }
      else if (lpEvent->tfinger.fingerId == finger2)
      {
         PAL_UnsetTouchAction(prev_touch2);
         finger2 = -1;
         prev_touch2 = TOUCH_NONE;
      }
      break;

    case SDL_FINGERMOTION:
       if (lpEvent->tfinger.fingerId == finger1)
       {
          int area = PAL_GetTouchArea(lpEvent->tfinger.x, lpEvent->tfinger.y);
          if (prev_touch1 != area && area != TOUCH_NONE)
          {
             PAL_UnsetTouchAction(prev_touch1);
             prev_touch1 = area;
             PAL_SetTouchAction(area);
          }
       }
       else if (lpEvent->tfinger.fingerId == finger2)
       {
          int area = PAL_GetTouchArea(lpEvent->tfinger.x, lpEvent->tfinger.y);
          if (prev_touch2 != area && area != TOUCH_NONE)
          {
             PAL_UnsetTouchAction(prev_touch2);
             prev_touch2 = area;
             PAL_SetTouchAction(area);
          }
       }
       break;
    }
#endif
}

/**
 * SDL event filter function. A filter to process all events.
 *
 * @param[in] lpEvent - pointer to the event.
 * @retval 1 = the event will be added to the internal queue.
 * @retval 0 = the event will be dropped from the queue.
 */
static int SDLCALL PAL_EventFilter(const SDL_Event *lpEvent)
{
    switch (lpEvent->type) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
        case SDL_WINDOWEVENT:
            if (lpEvent->window.event == SDL_WINDOWEVENT_RESIZED) {
                //
                // resized the window
                //
                VIDEO_Resize(lpEvent->window.data1, lpEvent->window.data2);
            }
            break;

#ifdef __IOS__
        case SDL_APP_WILLENTERBACKGROUND:
           g_bRenderPaused = TRUE;
           break;

        case SDL_APP_DIDENTERFOREGROUND:
           g_bRenderPaused = FALSE;
           VIDEO_UpdateScreen(NULL);
           break;
#endif

#else

        case SDL_VIDEORESIZE:
           //
           // resized the window
           //
           VIDEO_Resize(lpEvent->resize.w, lpEvent->resize.h);
           break;
#endif

        case SDL_QUIT:
            //
            // clicked on the close button of the window. Quit immediately.
            //
            PAL_Shutdown();
            exit(0);
    }

    PAL_KeyboardEventFilter(lpEvent);
    PAL_MouseEventFilter(lpEvent);
    PAL_JoystickEventFilter(lpEvent);
    PAL_TouchEventFilter(lpEvent);

    //
    // All events are handled here; don't put anything to the internal queue
    //
    return 0;
}

/**
 * Clear the record of pressed keys.

 */
VOID PAL_ClearKeyState(VOID)
{
    g_InputState.dwKeyPress = 0;
}

/**
 * Initialize the input subsystem.
 */
VOID PAL_InitInput(VOID)
{
    memset((void *) &g_InputState, 0, sizeof(g_InputState));
    g_InputState.dir = kDirUnknown;
    g_InputState.prevdir = kDirUnknown;

    //
    // Check for joystick
    //
#ifdef PAL_HAS_JOYSTICKS
    if (SDL_NumJoysticks() > 0 && g_fUseJoystick) {
        g_pJoy = SDL_JoystickOpen(0);

        //
        // HACKHACK: applesmc and Android Accelerometer shouldn't be considered as real joysticks
        //
        if (strcmp(SDL_JoystickName(g_pJoy), "applesmc") == 0 || strcmp(SDL_JoystickName(g_pJoy), "Android Accelerometer") == 0) {
            SDL_JoystickClose(g_pJoy);

            if (SDL_NumJoysticks() > 1) {
                g_pJoy = SDL_JoystickOpen(1);
            } else {
                g_pJoy = NULL;
            }
        }

        if (g_pJoy != NULL) {
            SDL_JoystickEventState(SDL_ENABLE);
        }
    }
#endif

#ifdef PAL_ALLOW_KEYREPEAT
    SDL_EnableKeyRepeat(0, 0);
#endif
}

/**
 * Shutdown the input subsystem.
 */
VOID PAL_ShutdownInput(VOID)
{
#ifdef PAL_HAS_JOYSTICKS
#if SDL_VERSION_ATLEAST(2, 0, 0)
    if (g_pJoy != NULL) {
        SDL_JoystickClose(g_pJoy);
        g_pJoy = NULL;
    }
#else
    if (SDL_JoystickOpened(0))
    {
       assert(g_pJoy != NULL);
       SDL_JoystickClose(g_pJoy);
       g_pJoy = NULL;
    }
#endif
#endif
}


/**
 * Process all events.
 */
VOID PAL_ProcessEvent(VOID)
{
#ifdef PAL_HAS_NATIVEMIDI
    MIDI_CheckLoop();
#endif
    while (PAL_PollEvent(NULL));
}

/**
 * Poll and process one event.
 *
 * @param[out] event - Events polled from SDL.
 * @return value of PAL_PollEvent
 */
int PAL_PollEvent(SDL_Event *event)
{
    SDL_Event evt;

    int ret = SDL_PollEvent(&evt);
    if (ret != 0) {
        PAL_EventFilter(&evt);
    }

    if (event != NULL) {
        *event = evt;
    }

    return ret;
}
Esempio n. 9
0
static VOID PAL_KeyboardEventFilter(const SDL_Event *lpEvent)
/*++
 Purpose:

 Handle keyboard events.

 Parameters:

 [IN]  lpEvent - pointer to the event.

 Return value:

 None.

 --*/
	{

	switch (lpEvent->type)
		{
		case SDL_KEYDOWN:
			//
			// Pressed a key
			//
			if (lpEvent->key.keysym.mod & KMOD_ALT)
				{
				if (lpEvent->key.keysym.sym == SDLK_RETURN)
					{
					//
					// Pressed Alt+Enter (toggle fullscreen)...
					//
					VIDEO_ToggleFullscreen();
					return;
					}
				else if (lpEvent->key.keysym.sym == SDLK_F4)
					{
					//
					// Pressed Alt+F4 (Exit program)...
					//
					PAL_Shutdown();
					exit(0);
					}
				}

			switch (lpEvent->key.keysym.sym)
				{

				case SDLK_0:
					VIDEO_ToggleFullscreen();
					break;
				case SDLK_1:
					ChangeVolume(0);
					break;
				case SDLK_3:
					ChangeVolume(1);
					break;
				case SDLK_UP:
				case SDLK_KP8:
					g_InputState.prevdir = g_InputState.dir;
					g_InputState.dir = kDirNorth;
					g_InputState.dwKeyPress |= kKeyUp;
					break;

				case SDLK_DOWN:
				case SDLK_KP2:
					g_InputState.prevdir = g_InputState.dir;
					g_InputState.dir = kDirSouth;
					g_InputState.dwKeyPress |= kKeyDown;
					break;

				case SDLK_LEFT:
				case SDLK_KP4:
					g_InputState.prevdir = g_InputState.dir;
					g_InputState.dir = kDirWest;
					g_InputState.dwKeyPress |= kKeyLeft;
					break;

				case SDLK_RIGHT:
				case SDLK_KP6:
					g_InputState.prevdir = g_InputState.dir;
					g_InputState.dir = kDirEast;
					g_InputState.dwKeyPress |= kKeyRight;
					break;

				case SDLK_ESCAPE:
				case SDLK_INSERT:
				case SDLK_LALT:
				case SDLK_RALT:
				case SDLK_KP0:
					g_InputState.dwKeyPress |= kKeyMenu;
					break;

				case SDLK_RETURN:
				case SDLK_SPACE:
				case SDLK_KP_ENTER:
					g_InputState.dwKeyPress |= kKeySearch;
					break;

				case SDLK_PAGEUP:
				case SDLK_KP9:
					g_InputState.dwKeyPress |= kKeyPgUp;
					break;

				case SDLK_PAGEDOWN:
				case SDLK_KP3:
					g_InputState.dwKeyPress |= kKeyPgDn;
					break;

				case SDLK_7:
				case SDLK_r:
					g_InputState.dwKeyPress |= kKeyRepeat;
					break;

				case SDLK_2:
				case SDLK_a:
					g_InputState.dwKeyPress |= kKeyAuto;
					break;

				case SDLK_d:
					g_InputState.dwKeyPress |= kKeyDefend;
					break;

				case SDLK_e:
					g_InputState.dwKeyPress |= kKeyUseItem;
					break;

				case SDLK_w:
					g_InputState.dwKeyPress |= kKeyThrowItem;
					break;

				case SDLK_q:
					g_InputState.dwKeyPress |= kKeyFlee;
					break;

				case SDLK_s:
					g_InputState.dwKeyPress |= kKeyStatus;
					break;

				case SDLK_f:
					g_InputState.dwKeyPress |= kKeyForce;
					break;

				case SDLK_p:
				case SDLK_HASH:
					VIDEO_SaveScreenshot();
					break;
				}
			break;

		case SDL_KEYUP:
			//
			// Released a key
			//
			switch (lpEvent->key.keysym.sym)
				{
				case SDLK_UP:
				case SDLK_KP8:
					if (g_InputState.dir == kDirNorth)
						{
						g_InputState.dir = g_InputState.prevdir;
						}
					g_InputState.prevdir = kDirUnknown;
					break;

				case SDLK_DOWN:
				case SDLK_KP2:
					if (g_InputState.dir == kDirSouth)
						{
						g_InputState.dir = g_InputState.prevdir;
						}
					g_InputState.prevdir = kDirUnknown;
					break;

				case SDLK_LEFT:
				case SDLK_KP4:
					if (g_InputState.dir == kDirWest)
						{
						g_InputState.dir = g_InputState.prevdir;
						}
					g_InputState.prevdir = kDirUnknown;
					break;

				case SDLK_RIGHT:
				case SDLK_KP6:
					if (g_InputState.dir == kDirEast)
						{
						g_InputState.dir = g_InputState.prevdir;
						}
					g_InputState.prevdir = kDirUnknown;
					break;
				}
			break;
		}
	}
Esempio n. 10
0
static VOID
PAL_JoystickEventFilter(
   const SDL_Event       *lpEvent
)
/*++
  Purpose:

    Handle joystick events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    None.

--*/
{
#ifdef PAL_HAS_JOYSTICKS
   switch (lpEvent->type)
   {
#if defined (GEKKO)
   case SDL_JOYHATMOTION:
      switch (lpEvent->jhat.value)
      {
      case SDL_HAT_LEFT:
        g_InputState.dir = kDirWest;
        g_InputState.dwKeyPress = kKeyLeft;
        break;

      case SDL_HAT_RIGHT:
        g_InputState.dir = kDirEast;
        g_InputState.dwKeyPress = kKeyRight;
        break;

      case SDL_HAT_UP:
        g_InputState.dir = kDirNorth;
        g_InputState.dwKeyPress = kKeyUp;
        break;

	  case SDL_HAT_DOWN:
        g_InputState.dir = kDirSouth;
        g_InputState.dwKeyPress = kKeyDown;
        break;
      }
      break;
#else
   case SDL_JOYAXISMOTION:
      //
      // Moved an axis on joystick
      //
      switch (lpEvent->jaxis.axis)
      {
      case 0:
         //
         // X axis
         //
#if defined(GPH)
		if (lpEvent->jaxis.value > MAX_DEADZONE) {
			g_InputState.dir = kDirEast;
			g_InputState.dwKeyPress = kKeyRight;
		} else if (lpEvent->jaxis.value < MIN_DEADZONE) {
			g_InputState.dir = kDirWest;
			g_InputState.dwKeyPress = kKeyLeft;
		} else {
			g_InputState.dir = kDirUnknown;
		}
#else
         if (lpEvent->jaxis.value > 20000)
         {
            if (g_InputState.dir != kDirEast)
            {
               g_InputState.dwKeyPress |= kKeyRight;
            }
            g_InputState.dir = kDirEast;
         }
         else if (lpEvent->jaxis.value < -20000)
         {
            if (g_InputState.dir != kDirWest)
            {
               g_InputState.dwKeyPress |= kKeyLeft;
            }
            g_InputState.dir = kDirWest;
         }
         else
         {
            g_InputState.dir = kDirUnknown;
         }
#endif
         break;

      case 1:
         //
         // Y axis
         //
#if defined(GPH)
		if (lpEvent->jaxis.value > MAX_DEADZONE) {
			g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
			g_InputState.dir = kDirSouth;
			g_InputState.dwKeyPress = kKeyDown;
		} else if (lpEvent->jaxis.value < MIN_DEADZONE) {
			g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
			g_InputState.dir = kDirNorth;
			g_InputState.dwKeyPress = kKeyUp;
		} else {
			g_InputState.dir = kDirUnknown;
		}
#else
         if (lpEvent->jaxis.value > 20000)
         {
            if (g_InputState.dir != kDirSouth)
            {
               g_InputState.dwKeyPress |= kKeyDown;
            }
            g_InputState.dir = kDirSouth;
         }
         else if (lpEvent->jaxis.value < -20000)
         {
            if (g_InputState.dir != kDirNorth)
            {
               g_InputState.dwKeyPress |= kKeyUp;
            }
            g_InputState.dir = kDirNorth;
         }
         else
         {
            g_InputState.dir = kDirUnknown;
         }
#endif
         break;
      }
      break;
#endif

   case SDL_JOYBUTTONDOWN:
      //
      // Pressed the joystick button
      //
#if defined(GPH)
      switch (lpEvent->jbutton.button)
      {
#if defined(GP2XWIZ)
		case 14:
#elif defined(CAANOO)
		case 3:
#endif
			g_InputState.dwKeyPress = kKeyMenu;
			break;

#if defined(GP2XWIZ)
		case 13:
#elif defined(CAANOO)
		case 2:
#endif
			g_InputState.dwKeyPress = kKeySearch;
			break;
#else
#if defined(GEKKO)
      switch (lpEvent->jbutton.button)
      {
		case 2:
         g_InputState.dwKeyPress |= kKeyMenu;
         break;

		case 3:
         g_InputState.dwKeyPress |= kKeySearch;
         break;
#else
      switch (lpEvent->jbutton.button & 1)
      {
      case 0:
         g_InputState.dwKeyPress |= kKeyMenu;
         break;

      case 1:
         g_InputState.dwKeyPress |= kKeySearch;
         break;
#endif
#endif
      }
      break;
   }
#endif
}

#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
static int SDLCALL
PAL_EventFilter(
   const SDL_Event       *lpEvent
)
#else
int PAL_EventFilter(
   void                  *userdata,
   const SDL_Event       *lpEvent
)
#endif
/*++
  Purpose:

    SDL event filter function. A filter to process all events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    1 = the event will be added to the internal queue.
    0 = the event will be dropped from the queue.

--*/
{
   switch (lpEvent->type)
   {
   case SDL_VIDEORESIZE:
      break;

   case SDL_QUIT:
      //
      // clicked on the close button of the window. Quit immediately.
      //
      PAL_Shutdown();
      exit(0);
	  break;
   case SDL_WINDOWEVENT:
	   return 0;
	   break;
   }

   PAL_KeyboardEventFilter(lpEvent);
   PAL_MouseEventFilter(lpEvent);
   PAL_JoystickEventFilter(lpEvent);

   //
   // All events are handled here; don't put anything to the internal queue
   //
   return 0;
}

VOID
PAL_ClearKeyState(
   VOID
)
/*++
  Purpose:

    Clear the record of pressed keys.

  Parameters:

    None.

  Return value:

    None.

--*/
{
#if 0
    if (g_InputState.touchEventType != TOUCH_NONE) {
        printf("clear touch: %d\n", g_InputState.touchEventType);
        
        if (g_InputState.touchEventType == TOUCH_UP) {
            int x = 0;
            int y = 0;
            y = x + 1;
        }
    }
#endif
    
   g_InputState.dwKeyPress = 0;
    g_InputState.touchEventType = TOUCH_NONE;   
}

VOID
PAL_InitInput(
   VOID
)
/*++
  Purpose:

    Initialize the input subsystem.

  Parameters:

    None.

  Return value:

    None.

--*/
{
   memset(&g_InputState, 0, sizeof(g_InputState));
   g_InputState.dir = kDirUnknown;
#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION <= 2
   SDL_SetEventFilter(PAL_EventFilter);
#else
   SDL_SetEventFilter(PAL_EventFilter, NULL);
#endif

   //
   // Check for joystick
   //
#ifdef PAL_HAS_JOYSTICKS
   if (SDL_NumJoysticks() > 0 && g_fUseJoystick)
   {
      g_pJoy = SDL_JoystickOpen(0);
      if (g_pJoy != NULL)
      {
         SDL_JoystickEventState(SDL_ENABLE);
      }
   }
#endif
}

VOID
PAL_ShutdownInput(
   VOID
)
/*++
  Purpose:

    Shutdown the input subsystem.

  Parameters:

    None.

  Return value:

    None.

--*/
{
#ifdef PAL_HAS_JOYSTICKS
   if (SDL_JoystickOpened(0))
   {
      assert(g_pJoy != NULL);
      SDL_JoystickClose(g_pJoy);
      g_pJoy = NULL;
   }
#endif
}

VOID
PAL_ProcessEvent(
   VOID
)
/*++
  Purpose:

    Process all events.

  Parameters:

    None.

  Return value:

    None.

--*/
{
#ifdef PAL_HAS_NATIVEMIDI
   MIDI_CheckLoop();
#endif
   while (SDL_PollEvent(NULL));
}

BOOL PAL_IsTouch(int x, int y, int w, int h)
{
	if (g_InputState.touchEventType == TOUCH_NONE) {
		return FALSE;
	}

	if (g_InputState.touchX >= x && g_InputState.touchX <= x + w
		&& g_InputState.touchY >= y && g_InputState.touchY <= y + h) {
			return TRUE;
	}

	return FALSE;
}

BOOL PAL_IsTouchDown(int x, int y, int w, int h)
{
	if (g_InputState.touchEventType != TOUCH_DOWN) {
		return FALSE;
	}

	if (g_InputState.touchX >= x && g_InputState.touchX <= x + w
		&& g_InputState.touchY >= y && g_InputState.touchY <= y + h) {
			return TRUE;
	}

	return FALSE;
}

BOOL PAL_IsTouchUp(int x, int y, int w, int h)
{
	if (g_InputState.touchEventType != TOUCH_UP) {
		return FALSE;
	}

	if (g_InputState.touchX >= x && g_InputState.touchX <= x + w
		&& g_InputState.touchY >= y && g_InputState.touchY <= y + h) {
			return TRUE;
	}

	return FALSE;
}
Esempio n. 11
0
static VOID
PAL_KeyboardEventFilter(
   const SDL_Event       *lpEvent
)
/*++
  Purpose:

    Handle keyboard events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    None.

--*/
{
   switch (lpEvent->type)
   {
   case SDL_KEYDOWN:
      //
      // Pressed a key
      //
      if (lpEvent->key.keysym.mod & KMOD_ALT)
      {
         if (lpEvent->key.keysym.sym == SDLK_F4)
         {
            //
            // Pressed Alt+F4 (Exit program)...
            //
            PAL_Shutdown();
            exit(0);
         }
      }

      switch (lpEvent->key.keysym.sym)
      {
#ifdef __SYMBIAN32__
      //
      // Symbian-specific stuff
      //
      case SDLK_0:
         VIDEO_ToggleScaleScreen();
         break;
      case SDLK_1:
         SOUND_AdjustVolume(0);
         break;
      case SDLK_3:
         SOUND_AdjustVolume(1);
         break;
#endif

      case SDLK_UP:
	  case SDLK_KP8:
         g_InputState.dir = kDirNorth;
		 g_InputState.dwKeyPress |=kKeyUp;
         g_InputState.dirKeyPress |= kKeyUp;
         break;

      case SDLK_DOWN:
      case SDLK_KP2:
         g_InputState.dir = kDirSouth;
		 g_InputState.dwKeyPress |= kKeyDown;
         g_InputState.dirKeyPress |= kKeyDown;
         break;

      case SDLK_LEFT:
      case SDLK_KP4:
         g_InputState.dir = kDirWest;
		 g_InputState.dwKeyPress |= kKeyLeft;
         g_InputState.dirKeyPress |= kKeyLeft;
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
         g_InputState.dir = kDirEast;
		 g_InputState.dwKeyPress |= kKeyRight;
         g_InputState.dirKeyPress |= kKeyRight;
         break;

#if defined(DINGOO)
      case SDLK_SPACE:
		 g_InputState.dwKeyPress = kKeyMenu;
         break;

      case SDLK_LCTRL:
		 g_InputState.dwKeyPress = kKeySearch;
         break;
#else
      case SDLK_ESCAPE:
      case SDLK_INSERT:
      case SDLK_LALT:
      case SDLK_RALT:
      case SDLK_KP0:
         g_InputState.dwKeyPress |= kKeyMenu;
         break;

      case SDLK_RETURN:
      case SDLK_SPACE:
      case SDLK_KP_ENTER:
      case SDLK_LCTRL:
         g_InputState.dwKeyPress |= kKeySearch;
         break;

      case SDLK_PAGEUP:
      case SDLK_KP9:
         g_InputState.dwKeyPress |= kKeyPgUp;
         break;

      case SDLK_PAGEDOWN:
      case SDLK_KP3:
         g_InputState.dwKeyPress |= kKeyPgDn;
         break;

      case SDLK_7: //7 for mobile device
      case SDLK_r:
         g_InputState.dwKeyPress |= kKeyRepeat;
         break;

      case SDLK_2: //2 for mobile device
      case SDLK_a:
         g_InputState.dwKeyPress |= kKeyAuto;
         break;

      case SDLK_d:
         g_InputState.dwKeyPress |= kKeyDefend;
         break;

      case SDLK_e:
         g_InputState.dwKeyPress |= kKeyUseItem;
         break;

      case SDLK_w:
         g_InputState.dwKeyPress |= kKeyThrowItem;
         break;

      case SDLK_q:
         g_InputState.dwKeyPress |= kKeyFlee;
         break;

      case SDLK_s:
         g_InputState.dwKeyPress |= kKeyStatus;
         break;

      case SDLK_f:
      case SDLK_5: // 5 for mobile device
         g_InputState.dwKeyPress |= kKeyForce;
         break;

      case SDLK_HASH: //# for mobile device
      case SDLK_p:
         VIDEO_SaveScreenshot();
         break;
#endif

      default:
         break;
      }
      break;

   case SDL_KEYUP:
      //
      // Released a key
      //
      switch (lpEvent->key.keysym.sym)
      {
      case SDLK_UP:
      case SDLK_KP8:
		  if ((g_InputState.dirKeyPress & kKeyUp) != 0) {
			  g_InputState.dirKeyPress ^= kKeyUp;
		  }
		  
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      case SDLK_DOWN:
      case SDLK_KP2:
		  if ((g_InputState.dirKeyPress & kKeyDown) != 0) {
			  g_InputState.dirKeyPress ^= kKeyDown;
		  }
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      case SDLK_LEFT:
      case SDLK_KP4:
		  if ((g_InputState.dirKeyPress & kKeyLeft) != 0) {
			  g_InputState.dirKeyPress ^= kKeyLeft;
		  }
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
		  if ((g_InputState.dirKeyPress & kKeyRight) != 0) {
			  g_InputState.dirKeyPress ^= kKeyRight;
		  }
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      default:
         break;
      }
      break;
   }
}
Esempio n. 12
0
static int SDLCALL
PAL_EventFilter(
   const SDL_Event       *lpEvent
)

/*++
  Purpose:

    SDL event filter function. A filter to process all events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    1 = the event will be added to the internal queue.
    0 = the event will be dropped from the queue.

--*/
{
   switch (lpEvent->type)
   {
#if SDL_VERSION_ATLEAST(2,0,0)
   case SDL_WINDOWEVENT:
      if (lpEvent->window.event == SDL_WINDOWEVENT_RESIZED)
      {
         //
         // resized the window
         //
         VIDEO_Resize(lpEvent->window.data1, lpEvent->window.data2);
      }
      break;

   case SDL_APP_WILLENTERBACKGROUND:
      g_bRenderPaused = TRUE;
      break;

   case SDL_APP_DIDENTERFOREGROUND:
      g_bRenderPaused = FALSE;
      VIDEO_UpdateScreen(NULL);
      break;
#else
   case SDL_VIDEORESIZE:
      //
      // resized the window
      //
      VIDEO_Resize(lpEvent->resize.w, lpEvent->resize.h);
      break;
#endif

   case SDL_QUIT:
      //
      // clicked on the close button of the window. Quit immediately.
      //
      PAL_Shutdown(0);
   }

   PAL_KeyboardEventFilter(lpEvent);
   PAL_MouseEventFilter(lpEvent);
   PAL_JoystickEventFilter(lpEvent);
   PAL_TouchEventFilter(lpEvent);

   //
   // All events are handled here; don't put anything to the internal queue
   //
   return 0;
}
Esempio n. 13
0
static VOID
PAL_KeyboardEventFilter(
   const SDL_Event       *lpEvent
)
/*++
  Purpose:

    Handle keyboard events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    None.

--*/
{
   if (lpEvent->type == SDL_KEYDOWN)
   {
      //
      // Pressed a key
      //
      if (lpEvent->key.keysym.mod & KMOD_ALT)
      {
         if (lpEvent->key.keysym.sym == SDLK_RETURN)
         {
            //
            // Pressed Alt+Enter (toggle fullscreen)...
            //
            VIDEO_ToggleFullscreen();
            return;
         }
         else if (lpEvent->key.keysym.sym == SDLK_F4)
         {
            //
            // Pressed Alt+F4 (Exit program)...
            //
            PAL_Shutdown(0);
         }
      }
      else if (lpEvent->key.keysym.sym == SDLK_p)
      {
         VIDEO_SaveScreenshot();
      }
#if PAL_HAS_GLSL
      else if (lpEvent->key.keysym.sym == SDLK_z)
      {
         Filter_StepParamSlot(1);
      }
      else if (lpEvent->key.keysym.sym == SDLK_x)
      {
         Filter_StepParamSlot(-1);
      }
      else if (lpEvent->key.keysym.sym == SDLK_COMMA)
      {
         Filter_StepCurrentParam(1);
      }
      else if (lpEvent->key.keysym.sym == SDLK_PERIOD)
      {
         Filter_StepCurrentParam(-1);
      }
#endif
   }
}