changed some platform-related preprocessor definition names
[rocksndiamonds.git] / src / events.c
index e07b8494cef2b9167b45382cb919bf5e69a3189f..4a31bcd6539140624d9e8f0c25f1f7523dc40fc7 100644 (file)
@@ -38,6 +38,7 @@ static boolean cursor_inside_playfield = FALSE;
 static int cursor_mode_last = CURSOR_DEFAULT;
 static unsigned int special_cursor_delay = 0;
 static unsigned int special_cursor_delay_value = 1000;
+static boolean special_cursor_enabled = FALSE;
 
 static boolean stop_processing_events = FALSE;
 
@@ -48,6 +49,11 @@ static void HandleNoEvent(void);
 static void HandleEventActions(void);
 
 
+void SetPlayfieldMouseCursorEnabled(boolean enabled)
+{
+  special_cursor_enabled = enabled;
+}
+
 // event filter to set mouse x/y position (for pointer class global animations)
 // (this is especially required to ensure smooth global animation mouse pointer
 // movement when the screen is updated without handling events; this can happen
@@ -108,7 +114,7 @@ static int FilterEvents(const Event *event)
     {
       SetMouseCursor(CURSOR_DEFAULT);
 
-      DelayReached(&special_cursor_delay, 0);
+      ResetDelayCounter(&special_cursor_delay);
 
       cursor_mode_last = CURSOR_DEFAULT;
     }
@@ -336,15 +342,14 @@ static void HandleMouseCursor(void)
 
     // display normal pointer if mouse pressed
     if (button_status != MB_RELEASED)
-      DelayReached(&special_cursor_delay, 0);
+      ResetDelayCounter(&special_cursor_delay);
 
     if (gfx.cursor_mode != CURSOR_PLAYFIELD &&
        cursor_inside_playfield &&
+       special_cursor_enabled &&
        DelayReached(&special_cursor_delay, special_cursor_delay_value))
     {
-      if (level.game_engine_type != GAME_ENGINE_TYPE_MM ||
-         tile_cursor.enabled)
-       SetMouseCursor(CURSOR_PLAYFIELD);
+      SetMouseCursor(CURSOR_PLAYFIELD);
     }
   }
   else if (gfx.cursor_mode != CURSOR_DEFAULT)
@@ -524,6 +529,10 @@ void HandleButtonEvent(ButtonEvent *event)
   // for any mouse button event, disable playfield tile cursor
   SetTileCursorEnabled(FALSE);
 
+  // for any mouse button event, disable playfield mouse cursor
+  if (cursor_inside_playfield)
+    SetPlayfieldMouseCursorEnabled(FALSE);
+
 #if defined(HAS_SCREEN_KEYBOARD)
   if (video.shifted_up)
     event->y += video.shifted_up_pos;
@@ -576,7 +585,7 @@ void HandleWheelEvent(WheelEvent *event)
               event->y < 0 ? MB_WHEEL_DOWN :
               event->y > 0 ? MB_WHEEL_UP : 0);
 
-#if defined(PLATFORM_WIN32) || defined(PLATFORM_MACOSX)
+#if defined(PLATFORM_WINDOWS) || defined(PLATFORM_MAC)
   // accelerated mouse wheel available on Mac and Windows
   wheel_steps = (event->x ? ABS(event->x) : ABS(event->y));
 #else
@@ -1709,9 +1718,11 @@ void HandleButton(int mx, int my, int button, int button_nr)
   // when playing, only handle gadgets when using "follow finger" controls
   // or when using touch controls in combination with the MM game engine
   // or when using gadgets that do not overlap with virtual buttons
+  // or when touch controls are disabled (e.g., with mouse-only levels)
   handle_gadgets =
     (game_status != GAME_MODE_PLAYING ||
      level.game_engine_type == GAME_ENGINE_TYPE_MM ||
+     strEqual(setup.touch.control_type, TOUCH_CONTROL_OFF) ||
      strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER) ||
      (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS) &&
       !CheckVirtualButtonPressed(mx, my, button)));
@@ -1772,7 +1783,11 @@ void HandleButton(int mx, int my, int button, int button_nr)
       break;
 
     case GAME_MODE_SCORES:
-      HandleHallOfFame(0, 0, 0, 0, button);
+      HandleHallOfFame(mx, my, 0, 0, button);
+      break;
+
+    case GAME_MODE_SCOREINFO:
+      HandleScoreInfo(mx, my, 0, 0, button);
       break;
 
     case GAME_MODE_EDITOR:
@@ -2091,6 +2106,8 @@ void HandleKey(Key key, int key_status)
          {
            key_action      |= key_info[i].action | JOY_BUTTON_SNAP;
            key_snap_action |= key_info[i].action;
+
+           tape.property_bits |= TAPE_PROPERTY_TAS_KEYS;
          }
        }
       }
@@ -2154,6 +2171,10 @@ void HandleKey(Key key, int key_status)
       // for MM style levels, handle in-game keyboard input in HandleJoystick()
       if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
        joy |= key_action;
+
+      // for any keyboard event, enable playfield mouse cursor
+      if (key_action && key_status == KEY_PRESSED)
+       SetPlayfieldMouseCursorEnabled(TRUE);
     }
   }
   else
@@ -2269,6 +2290,10 @@ void HandleKey(Key key, int key_status)
       TapeQuickSave();
     else if (key == setup.shortcut.load_game)
       TapeQuickLoad();
+    else if (key == setup.shortcut.restart_game)
+      TapeRestartGame();
+    else if (key == setup.shortcut.pause_before_end)
+      TapeReplayAndPauseBeforeEnd();
     else if (key == setup.shortcut.toggle_pause)
       TapeTogglePause(TAPE_TOGGLE_MANUAL | TAPE_TOGGLE_PLAY_PAUSE);
 
@@ -2276,6 +2301,11 @@ void HandleKey(Key key, int key_status)
     HandleSoundButtonKeys(key);
   }
 
+  if (game_status == GAME_MODE_SCOREINFO)
+  {
+    HandleScreenGadgetKeys(key);
+  }
+
   if (game_status == GAME_MODE_PLAYING && !network_playing)
   {
     int centered_player_nr_next = -999;
@@ -2305,6 +2335,14 @@ void HandleKey(Key key, int key_status)
   if (HandleGadgetsKeyInput(key))
     return;            // do not handle already processed keys again
 
+  // special case: on "space" key, either continue playing or go to main menu
+  if (game_status == GAME_MODE_SCORES && key == KSYM_space)
+  {
+    HandleHallOfFame(0, 0, 0, 0, MB_MENU_CONTINUE);
+
+    return;
+  }
+
   switch (game_status)
   {
     case GAME_MODE_PSEUDO_TYPENAME:
@@ -2320,6 +2358,7 @@ void HandleKey(Key key, int key_status)
     case GAME_MODE_SETUP:
     case GAME_MODE_INFO:
     case GAME_MODE_SCORES:
+    case GAME_MODE_SCOREINFO:
 
       if (anyTextGadgetActiveOrJustFinished && key != KSYM_Escape)
        break;
@@ -2344,6 +2383,8 @@ void HandleKey(Key key, int key_status)
            HandleInfoScreen(0, 0, 0, 0, MB_MENU_CHOICE);
          else if (game_status == GAME_MODE_SCORES)
            HandleHallOfFame(0, 0, 0, 0, MB_MENU_CHOICE);
+         else if (game_status == GAME_MODE_SCOREINFO)
+           HandleScoreInfo(0, 0, 0, 0, MB_MENU_CHOICE);
          break;
 
        case KSYM_Escape:
@@ -2364,6 +2405,8 @@ void HandleKey(Key key, int key_status)
            HandleInfoScreen(0, 0, 0, 0, MB_MENU_LEAVE);
          else if (game_status == GAME_MODE_SCORES)
            HandleHallOfFame(0, 0, 0, 0, MB_MENU_LEAVE);
+         else if (game_status == GAME_MODE_SCOREINFO)
+           HandleScoreInfo(0, 0, 0, 0, MB_MENU_LEAVE);
          break;
 
         case KSYM_Page_Up:
@@ -2379,6 +2422,8 @@ void HandleKey(Key key, int key_status)
            HandleInfoScreen(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
          else if (game_status == GAME_MODE_SCORES)
            HandleHallOfFame(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
+         else if (game_status == GAME_MODE_SCOREINFO)
+           HandleScoreInfo(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
          break;
 
         case KSYM_Page_Down:
@@ -2394,6 +2439,8 @@ void HandleKey(Key key, int key_status)
            HandleInfoScreen(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
          else if (game_status == GAME_MODE_SCORES)
            HandleHallOfFame(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
+         else if (game_status == GAME_MODE_SCOREINFO)
+           HandleScoreInfo(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
          break;
 
        default:
@@ -2411,7 +2458,7 @@ void HandleKey(Key key, int key_status)
       switch (key)
       {
         case KSYM_Escape:
-         RequestQuitGame(setup.ask_on_escape);
+         RequestQuitGame(TRUE);
          break;
 
        default:
@@ -2597,6 +2644,10 @@ void HandleJoystick(void)
       SetTileCursorEnabled(TRUE);
   }
 
+  // for any joystick event, enable playfield mouse cursor
+  if (dx || dy || button)
+    SetPlayfieldMouseCursorEnabled(TRUE);
+
   if (joytest && !button && !DelayReached(&joytest_delay, joytest_delay_value))
   {
     // delay joystick/keyboard actions if axes/keys continually pressed
@@ -2621,6 +2672,7 @@ void HandleJoystick(void)
     case GAME_MODE_SETUP:
     case GAME_MODE_INFO:
     case GAME_MODE_SCORES:
+    case GAME_MODE_SCOREINFO:
     {
       if (anyTextGadgetActive())
        break;
@@ -2641,6 +2693,8 @@ void HandleJoystick(void)
        HandleInfoScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
       else if (game_status == GAME_MODE_SCORES)
        HandleHallOfFame(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
+      else if (game_status == GAME_MODE_SCOREINFO)
+       HandleScoreInfo(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
 
       break;
     }