fixed tile selection cursor position for levels smaller than the playfield
[rocksndiamonds.git] / src / libgame / system.c
index a87ecc837f15206351dd228e89bedcf25512a925..139ee57a562d6c2a046d7397c9df6e4d6c445e0e 100644 (file)
@@ -33,6 +33,7 @@ struct OptionInfo     options;
 struct VideoSystemInfo video;
 struct AudioSystemInfo audio;
 struct GfxInfo         gfx;
+struct TileCursorInfo  tile_cursor;
 struct OverlayInfo     overlay;
 struct ArtworkInfo     artwork;
 struct JoystickInfo    joystick;
@@ -286,6 +287,11 @@ void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int))
   gfx.draw_global_border_function = draw_global_border_function;
 }
 
+void InitGfxDrawTileCursorFunction(void (*draw_tile_cursor_function)(int))
+{
+  gfx.draw_tile_cursor_function = draw_tile_cursor_function;
+}
+
 void InitGfxCustomArtworkInfo()
 {
   gfx.override_level_graphics = FALSE;
@@ -300,6 +306,23 @@ void InitGfxOtherSettings()
   gfx.cursor_mode = CURSOR_DEFAULT;
 }
 
+void InitTileCursorInfo()
+{
+  tile_cursor.enabled = FALSE;
+  tile_cursor.active = FALSE;
+  tile_cursor.moving = FALSE;
+
+  tile_cursor.xpos = 0;
+  tile_cursor.ypos = 0;
+  tile_cursor.x = 0;
+  tile_cursor.y = 0;
+  tile_cursor.target_x = 0;
+  tile_cursor.target_y = 0;
+
+  tile_cursor.sx = 0;
+  tile_cursor.sy = 0;
+}
+
 void InitOverlayInfo()
 {
   overlay.enabled = FALSE;
@@ -311,6 +334,47 @@ void InitOverlayInfo()
 #endif
 }
 
+void SetTileCursorEnabled(boolean enabled)
+{
+  tile_cursor.enabled = enabled;
+}
+
+void SetTileCursorActive(boolean active)
+{
+  tile_cursor.active = active;
+}
+
+void SetTileCursorTargetXY(int x, int y)
+{
+  // delayed placement of tile selection cursor at target position
+  // (tile cursor will be moved to target position step by step)
+
+  tile_cursor.xpos = x;
+  tile_cursor.ypos = y;
+  tile_cursor.target_x = tile_cursor.sx + x * gfx.game_tile_size;
+  tile_cursor.target_y = tile_cursor.sy + y * gfx.game_tile_size;
+
+  tile_cursor.moving = TRUE;
+}
+
+void SetTileCursorXY(int x, int y)
+{
+  // immediate placement of tile selection cursor at target position
+
+  SetTileCursorTargetXY(x, y);
+
+  tile_cursor.x = tile_cursor.target_x;
+  tile_cursor.y = tile_cursor.target_y;
+
+  tile_cursor.moving = FALSE;
+}
+
+void SetTileCursorSXSY(int sx, int sy)
+{
+  tile_cursor.sx = sx;
+  tile_cursor.sy = sy;
+}
+
 void SetOverlayEnabled(boolean enabled)
 {
   overlay.enabled = enabled;
@@ -421,6 +485,11 @@ void LimitScreenUpdates(boolean enable)
   SDLLimitScreenUpdates(enable);
 }
 
+void InitVideoDefaults(void)
+{
+  video.default_depth = 32;
+}
+
 void InitVideoDisplay(void)
 {
   if (program.headless)
@@ -466,7 +535,7 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
 
   SDLInitVideoBuffer(fullscreen);
 
-  video.initialized = TRUE;
+  video.initialized = !program.headless;
 
   drawto = backbuffer;
 }
@@ -600,6 +669,17 @@ inline static boolean CheckDrawingArea(int x, int y, int width, int height,
   return FALSE;
 }
 
+boolean DrawingDeactivatedField()
+{
+  if (program.headless)
+    return TRUE;
+
+  if (gfx.draw_deactivation_mask & REDRAW_FIELD)
+    return TRUE;
+
+  return FALSE;
+}
+
 boolean DrawingDeactivated(int x, int y, int width, int height)
 {
   return CheckDrawingArea(x, y, width, height, gfx.draw_deactivation_mask);
@@ -903,6 +983,9 @@ void DrawLine(Bitmap *bitmap, int from_x, int from_y,
 {
   int x, y;
 
+  if (program.headless)
+    return;
+
   for (x = 0; x < line_width; x++)
   {
     for (y = 0; y < line_width; y++)
@@ -938,6 +1021,9 @@ void DrawLines(Bitmap *bitmap, struct XY *points, int num_points, Pixel pixel)
 
 Pixel GetPixel(Bitmap *bitmap, int x, int y)
 {
+  if (program.headless)
+    return BLACK_PIXEL;
+
   if (x < 0 || x >= bitmap->width ||
       y < 0 || y >= bitmap->height)
     return BLACK_PIXEL;
@@ -948,6 +1034,9 @@ Pixel GetPixel(Bitmap *bitmap, int x, int y)
 Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
                      unsigned int color_g, unsigned int color_b)
 {
+  if (program.headless)
+    return BLACK_PIXEL;
+
   return SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
 }