improved virtual buttons for touch devices (Android)
[rocksndiamonds.git] / src / libgame / system.c
index 0e7169f4d79c4eb4a339f2c22a63dc920684813c..5443e87da6ebd560a3ef446c8f45d4f107b4ed15 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;
@@ -363,6 +379,7 @@ void LimitScreenUpdates(boolean enable)
 void InitVideoDisplay(void)
 {
   SDLInitVideoDisplay();
+  SDLSetDisplaySize();
 }
 
 void CloseVideoDisplay(void)
@@ -378,6 +395,11 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
   video.height = height;
   video.depth = GetRealDepth(depth);
 
+  video.screen_width = width;
+  video.screen_height = height;
+  video.screen_xoffset = 0;
+  video.screen_yoffset = 0;
+
   video.fullscreen_available = FULLSCREEN_STATUS;
   video.fullscreen_enabled = FALSE;
 
@@ -386,6 +408,12 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
   video.frame_delay = 0;
   video.frame_delay_value = GAME_FRAME_DELAY;
 
+  video.shifted_up = FALSE;
+  video.shifted_up_pos = 0;
+  video.shifted_up_pos_last = 0;
+  video.shifted_up_delay = 0;
+  video.shifted_up_delay_value = ONE_SECOND_DELAY / 4;
+
   SDLInitVideoBuffer(fullscreen);
 
   video.initialized = TRUE;
@@ -977,32 +1005,9 @@ void ReloadCustomImage(Bitmap *bitmap, char *basename)
   free(new_bitmap);
 }
 
-static void SetMaskedBitmapSurface(Bitmap *bitmap)
-{
-  if (bitmap == NULL)
-    return;
-
-  SDL_Surface *surface = bitmap->surface;
-
-  if (bitmap->surface_masked)
-    SDL_FreeSurface(bitmap->surface_masked);
-
-  SDL_SetColorKey(surface, SET_TRANSPARENT_PIXEL,
-                 SDL_MapRGB(surface->format, 0x00, 0x00, 0x00));
-
-  if ((bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
-    Error(ERR_EXIT, "SDL_DisplayFormat() failed");
-
-  SDL_SetColorKey(surface, UNSET_TRANSPARENT_PIXEL, 0);
-}
-
 static Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
 {
-  Bitmap *dst_bitmap = SDLZoomBitmap(src_bitmap, zoom_width, zoom_height);
-
-  SetMaskedBitmapSurface(dst_bitmap);
-
-  return dst_bitmap;
+  return SDLZoomBitmap(src_bitmap, zoom_width, zoom_height);
 }
 
 void ReCreateGameTileSizeBitmap(Bitmap **bitmaps)
@@ -1418,16 +1423,6 @@ void SetAudioMode(boolean enabled)
 /* event functions                                                           */
 /* ========================================================================= */
 
-void InitEventFilter(EventFilter filter_function)
-{
-  /* set event filter to filter out certain events */
-#if defined(TARGET_SDL2)
-  SDL_SetEventFilter(filter_function, NULL);
-#else
-  SDL_SetEventFilter(filter_function);
-#endif
-}
-
 boolean PendingEvent(void)
 {
   return (SDL_PollEvent(NULL) ? TRUE : FALSE);
@@ -1534,6 +1529,38 @@ KeyMod GetKeyModStateFromEvents()
   return HandleKeyModState(KSYM_UNDEFINED, 0);
 }
 
+void StartTextInput(int x, int y, int width, int height)
+{
+#if defined(TARGET_SDL2)
+  SDL_StartTextInput();
+
+#if defined(HAS_SCREEN_KEYBOARD)
+  if (y + height > SCREEN_KEYBOARD_POS(video.height))
+  {
+    video.shifted_up_pos = y + height - SCREEN_KEYBOARD_POS(video.height);
+    video.shifted_up_delay = SDL_GetTicks();
+    video.shifted_up = TRUE;
+  }
+#endif
+#endif
+}
+
+void StopTextInput()
+{
+#if defined(TARGET_SDL2)
+  SDL_StopTextInput();
+
+#if defined(HAS_SCREEN_KEYBOARD)
+  if (video.shifted_up)
+  {
+    video.shifted_up_pos = 0;
+    video.shifted_up_delay = SDL_GetTicks();
+    video.shifted_up = FALSE;
+  }
+#endif
+#endif
+}
+
 boolean CheckCloseWindowEvent(ClientMessageEvent *event)
 {
   if (event->type != EVENT_CLIENTMESSAGE)