added toggling virtual buttons using 'menu' button on Android
[rocksndiamonds.git] / src / events.c
index 0c5b2bc1354f5ad40477daa9ed5ccde37b3ff689..f3330a7ee318ece3e7578f01551a509161c4396f 100644 (file)
@@ -1452,9 +1452,15 @@ void HandleKeyEvent(KeyEvent *event)
     // always map the "back" button to the "escape" key on Android devices
     key = KSYM_Escape;
   }
+  else if (key == KSYM_Menu)
+  {
+    // the "menu" button can be used to toggle displaying virtual buttons
+    if (key_status == KEY_PRESSED)
+      SetOverlayEnabled(!GetOverlayEnabled());
+  }
   else
   {
-    // for any key event other than "back" button, disable overlay buttons
+    // for any other "real" key event, disable virtual buttons
     SetOverlayEnabled(FALSE);
   }
 #endif
@@ -1778,11 +1784,14 @@ static void HandleKeysSpecial(Key key)
   }
 }
 
-void HandleKeysDebug(Key key)
+boolean HandleKeysDebug(Key key, int key_status)
 {
 #ifdef DEBUG
   int i;
 
+  if (key_status != KEY_PRESSED)
+    return FALSE;
+
   if (game_status == GAME_MODE_PLAYING || !setup.debug.frame_delay_game_only)
   {
     boolean mod_key_pressed = ((GetKeyModState() & KMOD_Valid) != KMOD_None);
@@ -1809,7 +1818,7 @@ void HandleKeysDebug(Key key)
        else
          Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)");
 
-       break;
+       return TRUE;
       }
     }
   }
@@ -1822,13 +1831,19 @@ void HandleKeysDebug(Key key)
 
       Error(ERR_DEBUG, "debug mode %s",
            (options.debug ? "enabled" : "disabled"));
+
+      return TRUE;
     }
     else if (key == KSYM_v)
     {
       Error(ERR_DEBUG, "currently using game engine version %d",
            game.engine_version);
+
+      return TRUE;
     }
   }
+
+  return FALSE;
 #endif
 }
 
@@ -1856,6 +1871,9 @@ void HandleKey(Key key, int key_status)
   int joy = 0;
   int i;
 
+  if (HandleKeysDebug(key, key_status))
+    return;            // do not handle already processed keys again
+
   // map special keys (media keys / remote control buttons) to default keys
   if (key == KSYM_PlayPause)
     key = KSYM_space;
@@ -2198,8 +2216,6 @@ void HandleKey(Key key, int key_status)
        return;
       }
   }
-
-  HandleKeysDebug(key);
 }
 
 void HandleNoEvent(void)