improved virtual buttons for touch devices (Android)
authorHolger Schemel <info@artsoft.org>
Mon, 12 Dec 2016 20:50:41 +0000 (21:50 +0100)
committerHolger Schemel <info@artsoft.org>
Mon, 12 Dec 2016 20:50:41 +0000 (21:50 +0100)
graphics/gfx_classic/overlay/VirtualButtons.ilbm
src/events.c
src/libgame/sdl.c

index 75892ef2b234710cec9c9582927c493fb32fa2e8..5a394301be6fe53778213f760ec0f6744cf63295 100644 (file)
Binary files a/graphics/gfx_classic/overlay/VirtualButtons.ilbm and b/graphics/gfx_classic/overlay/VirtualButtons.ilbm differ
index 0aa4185af0696700c32810874520ac6687621881..abf74ba51b1385dbf1eefe283f34da81880042b7 100644 (file)
@@ -617,15 +617,30 @@ void HandleFingerEvent(FingerEvent *event)
   {
     int key_status = (event->type == EVENT_FINGERRELEASE ? KEY_RELEASED :
                      KEY_PRESSED);
   {
     int key_status = (event->type == EVENT_FINGERRELEASE ? KEY_RELEASED :
                      KEY_PRESSED);
-    Key key = (event->x < 1.0 / 3.0 ?
-              (event->y < 1.0 / 2.0 ? setup.input[0].key.snap :
-               setup.input[0].key.drop) :
-              event->x > 2.0 / 3.0 ?
-              (event->y < 1.0 / 3.0 ? setup.input[0].key.up :
-               event->y > 2.0 / 3.0 ? setup.input[0].key.down :
-               event->x < 5.0 / 6.0 ? setup.input[0].key.left :
-               setup.input[0].key.right) :
+    float ypos = 1.0 - 1.0 / 3.0 * video.display_width / video.display_height;
+
+    event_y = (event_y - ypos) / (1 - ypos);
+
+    Key key = (event_x > 0         && event_x < 1.0 / 6.0 &&
+              event_y > 2.0 / 3.0 && event_y < 1 ?
+              setup.input[0].key.snap :
+              event_x > 1.0 / 6.0 && event_x < 1.0 / 3.0 &&
+              event_y > 2.0 / 3.0 && event_y < 1 ?
+              setup.input[0].key.drop :
+              event_x > 7.0 / 9.0 && event_x < 8.0 / 9.0 &&
+              event_y > 0         && event_y < 1.0 / 3.0 ?
+              setup.input[0].key.up :
+              event_x > 6.0 / 9.0 && event_x < 7.0 / 9.0 &&
+              event_y > 1.0 / 3.0 && event_y < 2.0 / 3.0 ?
+              setup.input[0].key.left :
+              event_x > 8.0 / 9.0 && event_x < 1 &&
+              event_y > 1.0 / 3.0 && event_y < 2.0 / 3.0 ?
+              setup.input[0].key.right :
+              event_x > 7.0 / 9.0 && event_x < 8.0 / 9.0 &&
+              event_y > 2.0 / 3.0 && event_y < 1 ?
+              setup.input[0].key.down :
               KSYM_UNDEFINED);
               KSYM_UNDEFINED);
+
     char *key_status_name = (key_status == KEY_RELEASED ? "KEY_RELEASED" :
                             "KEY_PRESSED");
     int i;
     char *key_status_name = (key_status == KEY_RELEASED ? "KEY_RELEASED" :
                             "KEY_PRESSED");
     int i;
index 9ed0e49da6bc6367e88ae84be0c781780abd2fe1..7221c7afeede8e9655e005b63d98bb8c4e1b51e0 100644 (file)
@@ -2753,8 +2753,28 @@ static void DrawTouchInputOverlay()
 
   alpha_last = alpha;
 
 
   alpha_last = alpha;
 
+  float ratio_overlay = (float) width / height;
+  float ratio_screen = (float) video.screen_width / video.screen_height;
+  int width_scaled, height_scaled;
+  int xpos, ypos;
+
+  if (ratio_overlay > ratio_screen)
+  {
+    width_scaled = video.screen_width;
+    height_scaled = video.screen_height * ratio_screen / ratio_overlay;
+    xpos = 0;
+    ypos = video.screen_height - height_scaled;
+  }
+  else
+  {
+    width_scaled = video.screen_width * ratio_overlay / ratio_screen;
+    height_scaled = video.screen_height;
+    xpos = (video.screen_width - width_scaled) / 2;
+    ypos = 0;
+  }
+
   SDL_Rect src_rect = { 0, 0, width, height };
   SDL_Rect src_rect = { 0, 0, width, height };
-  SDL_Rect dst_rect = { 0, 0, video.screen_width, video.screen_height };
+  SDL_Rect dst_rect = { xpos, ypos, width_scaled, height_scaled };
 
   SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect);
 #endif
 
   SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect);
 #endif