added overlay graphics for virtual buttons for touch devices (Android)
authorHolger Schemel <info@artsoft.org>
Thu, 1 Dec 2016 22:36:28 +0000 (23:36 +0100)
committerHolger Schemel <info@artsoft.org>
Thu, 1 Dec 2016 22:36:28 +0000 (23:36 +0100)
graphics/gfx_classic/Makefile
graphics/gfx_classic/overlay/VirtualButtons.ilbm [new file with mode: 0644]
src/init.c
src/libgame/sdl.c
src/libgame/system.c
src/libgame/system.h
src/tools.c

index 041f3c8..194e6e6 100644 (file)
@@ -20,25 +20,26 @@ RM = rm -f
 # EXT = pcx
 EXT = png
 
-FILES = RocksBusy.$(EXT)       \
-       RocksDC.$(EXT)          \
-       RocksDC2.$(EXT)         \
-       RocksDoor.$(EXT)        \
-       RocksDoor2.$(EXT)       \
-       RocksEMC.$(EXT)         \
-       RocksElements.$(EXT)    \
-       RocksFontBig.$(EXT)     \
-       RocksFontDC.$(EXT)      \
-       RocksFontEM.$(EXT)      \
-       RocksFontMedium.$(EXT)  \
-       RocksFontSmall.$(EXT)   \
-       RocksHeroes.$(EXT)      \
-       RocksMore.$(EXT)        \
-       RocksSP.$(EXT)          \
-       RocksScreen.$(EXT)      \
-       RocksToons.$(EXT)       \
-                               \
-       RocksCE.$(EXT)          # dynamically generated from template
+FILES = RocksBusy.$(EXT)               \
+       RocksDC.$(EXT)                  \
+       RocksDC2.$(EXT)                 \
+       RocksDoor.$(EXT)                \
+       RocksDoor2.$(EXT)               \
+       RocksEMC.$(EXT)                 \
+       RocksElements.$(EXT)            \
+       RocksFontBig.$(EXT)             \
+       RocksFontDC.$(EXT)              \
+       RocksFontEM.$(EXT)              \
+       RocksFontMedium.$(EXT)          \
+       RocksFontSmall.$(EXT)           \
+       RocksHeroes.$(EXT)              \
+       RocksMore.$(EXT)                \
+       RocksSP.$(EXT)                  \
+       RocksScreen.$(EXT)              \
+       RocksToons.$(EXT)               \
+       overlay/VirtualButtons.$(EXT)   \
+                                       \
+       RocksCE.$(EXT)                  # dynamically generated from template
 
 
 # -----------------------------------------------------------------------------
diff --git a/graphics/gfx_classic/overlay/VirtualButtons.ilbm b/graphics/gfx_classic/overlay/VirtualButtons.ilbm
new file mode 100644 (file)
index 0000000..75892ef
Binary files /dev/null and b/graphics/gfx_classic/overlay/VirtualButtons.ilbm differ
index 8595288..5e996f3 100644 (file)
@@ -5926,6 +5926,8 @@ void OpenAll()
   InitVideoDisplay();
   InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
 
+  InitOverlayInfo();
+
   print_timestamp_time("[init video stuff]");
 
   InitElementPropertiesStatic();
index 661bf6f..9ed0e49 100644 (file)
@@ -37,6 +37,9 @@ static boolean limit_screen_updates = FALSE;
 /* functions from SGE library */
 void sge_Line(SDL_Surface *, Sint16, Sint16, Sint16, Sint16, Uint32);
 
+/* functions to draw overlay graphics for touch device input */
+static void DrawTouchInputOverlay();
+
 void SDLLimitScreenUpdates(boolean enable)
 {
   limit_screen_updates = enable;
@@ -201,6 +204,9 @@ static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay)
     SDL_SetRenderTarget(sdl_renderer, NULL);
     SDL_RenderCopy(sdl_renderer, sdl_texture_target, src_rect2, dst_rect2);
   }
+
+  // draw overlay graphics for touch device input, if needed
+  DrawTouchInputOverlay();
 #endif
 
   // global synchronization point of the game to align video frame delay
@@ -910,7 +916,7 @@ void SDLSetScreenSizeAndOffsets(int width, int height)
   video.screen_xoffset = 0;
   video.screen_yoffset = 0;
 
-#if defined(PLATFORM_ANDROID)
+#if defined(USE_COMPLETE_DISPLAY)
   float ratio_video   = (float) width / height;
   float ratio_display = (float) video.display_width / video.display_height;
 
@@ -2678,3 +2684,78 @@ boolean SDLReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
 
   return TRUE;
 }
+
+static void DrawTouchInputOverlay()
+{
+#if defined(USE_TOUCH_INPUT_OVERLAY)
+  static SDL_Texture *texture = NULL;
+  static boolean initialized = FALSE;
+  static boolean deactivated = TRUE;
+  static int width = 0, height = 0;
+  static int alpha_max = SDL_ALPHA_OPAQUE / 2;
+  static int alpha_step = 5;
+  static int alpha_last = 0;
+  static int alpha = 0;
+
+  if (!overlay.active && deactivated)
+    return;
+
+  if (overlay.active)
+  {
+    if (alpha < alpha_max)
+      alpha = MIN(alpha + alpha_step, alpha_max);
+
+    deactivated = FALSE;
+  }
+  else
+  {
+    alpha = MAX(0, alpha - alpha_step);
+
+    if (alpha == 0)
+      deactivated = TRUE;
+  }
+
+  if (!initialized)
+  {
+    char *basename = "overlay/VirtualButtons.png";
+    char *filename = getCustomImageFilename(basename);
+
+    if (filename == NULL)
+      Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
+
+    SDL_Surface *surface;
+
+    if ((surface = IMG_Load(filename)) == NULL)
+      Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError());
+
+    width  = surface->w;
+    height = surface->h;
+
+    /* set black pixel to transparent if no alpha channel / transparent color */
+    if (!SDLHasAlpha(surface) &&
+       !SDLHasColorKey(surface))
+      SDL_SetColorKey(surface, SET_TRANSPARENT_PIXEL,
+                     SDL_MapRGB(surface->format, 0x00, 0x00, 0x00));
+
+    if ((texture = SDLCreateTextureFromSurface(surface)) == NULL)
+      Error(ERR_EXIT, "SDLCreateTextureFromSurface() failed");
+
+    SDL_FreeSurface(surface);
+
+    SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
+    SDL_SetTextureAlphaMod(texture, alpha_max);
+
+    initialized = TRUE;
+  }
+
+  if (alpha != alpha_last)
+    SDL_SetTextureAlphaMod(texture, alpha);
+
+  alpha_last = alpha;
+
+  SDL_Rect src_rect = { 0, 0, width, height };
+  SDL_Rect dst_rect = { 0, 0, video.screen_width, video.screen_height };
+
+  SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect);
+#endif
+}
index 98ccd70..5443e87 100644 (file)
@@ -33,6 +33,7 @@ struct OptionInfo     options;
 struct VideoSystemInfo video;
 struct AudioSystemInfo audio;
 struct GfxInfo         gfx;
+struct OverlayInfo     overlay;
 struct ArtworkInfo     artwork;
 struct JoystickInfo    joystick;
 struct SetupInfo       setup;
@@ -270,6 +271,21 @@ void InitGfxOtherSettings()
   gfx.cursor_mode = CURSOR_DEFAULT;
 }
 
+void InitOverlayInfo()
+{
+  overlay.active = FALSE;
+}
+
+void SetOverlayActive(boolean active)
+{
+  overlay.active = active;
+}
+
+boolean GetOverlayActive()
+{
+  return overlay.active;
+}
+
 void SetDrawDeactivationMask(int draw_deactivation_mask)
 {
   gfx.draw_deactivation_mask = draw_deactivation_mask;
index 3b51f91..b6cea7b 100644 (file)
 #define TOUCH_DROP_DISTANCE_DEFAULT    5
 
 
-/* values for screen keyboard on mobile devices */
+/* values for special settings for mobile devices */
 #if defined(PLATFORM_ANDROID)
+#define USE_TOUCH_INPUT_OVERLAY
+#define USE_COMPLETE_DISPLAY
 #define HAS_SCREEN_KEYBOARD
 #define SCREEN_KEYBOARD_POS(h)         ((h) / 2)
 #endif
@@ -910,6 +912,11 @@ struct GfxInfo
   int cursor_mode;
 };
 
+struct OverlayInfo
+{
+  boolean active;
+};
+
 struct JoystickInfo
 {
   int status;
@@ -1373,6 +1380,7 @@ extern struct OptionInfo  options;
 extern struct VideoSystemInfo  video;
 extern struct AudioSystemInfo  audio;
 extern struct GfxInfo          gfx;
+extern struct OverlayInfo      overlay;
 extern struct AnimInfo         anim;
 extern struct ArtworkInfo      artwork;
 extern struct JoystickInfo     joystick;
@@ -1427,6 +1435,9 @@ void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(int, int));
 void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int));
 void InitGfxCustomArtworkInfo();
 void InitGfxOtherSettings();
+void InitOverlayInfo();
+void SetOverlayActive(boolean);
+boolean GetOverlayActive();
 void SetDrawDeactivationMask(int);
 void SetDrawBackgroundMask(int);
 void SetWindowBackgroundBitmap(Bitmap *);
index 133a826..794174c 100644 (file)
@@ -926,6 +926,10 @@ void FadeIn(int fade_mask)
   FADE_SXSIZE = FULL_SXSIZE;
   FADE_SYSIZE = FULL_SYSIZE;
 
+  if (game_status == GAME_MODE_PLAYING &&
+      strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
+    SetOverlayActive(TRUE);
+
   SetScreenStates_AfterFadingIn();
 
   // force update of global animation status in case of rapid screen changes
@@ -941,6 +945,8 @@ void FadeOut(int fade_mask)
 
   SetScreenStates_BeforeFadingOut();
 
+  SetOverlayActive(FALSE);
+
 #if 0
   DrawMaskedBorder(REDRAW_ALL);
 #endif
@@ -4211,10 +4217,19 @@ static boolean RequestEnvelope(char *text, unsigned int req_state)
 
 boolean Request(char *text, unsigned int req_state)
 {
+  boolean overlay_active = GetOverlayActive();
+  boolean result;
+
+  SetOverlayActive(FALSE);
+
   if (global.use_envelope_request)
-    return RequestEnvelope(text, req_state);
+    result = RequestEnvelope(text, req_state);
   else
-    return RequestDoor(text, req_state);
+    result = RequestDoor(text, req_state);
+
+  SetOverlayActive(overlay_active);
+
+  return result;
 }
 
 static int compareDoorPartOrderInfo(const void *object1, const void *object2)