added dirty workaround to open program window on specified display
[rocksndiamonds.git] / src / game_mm / mm_tools.c
index 28fe9bfe5ed5b9af5c7fba99434a535547110973..044c83a3484aa056c22a3f8b80e688749f96ea80 100644 (file)
@@ -648,6 +648,7 @@ void DrawMiniLevel_MM(int size_x, int size_y, int scroll_x, int scroll_y)
 #define XSN_CHANGE_DELAY       30
 #define XSN_CHANGE_FACTOR      3
 #define XSN_ALPHA_DEFAULT      XSN_ALPHA_VALUE(95)
+#define XSN_ALPHA_VISIBLE      XSN_ALPHA_VALUE(50)
 #define XSN_DEBUG_STEPS                5
 
 static byte xsn_bits_0[] = { 0x05, 0x02, 0x05 };
@@ -707,6 +708,8 @@ struct Xsn
   struct XsnItem items[XSN_MAX_ITEMS];
 
   Bitmap *bitmap;
+
+  int alpha;
 };
 
 static struct Xsn xsn = { 0 };
@@ -847,7 +850,7 @@ static void xsn_update_item(int nr)
       BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, xsn.max_height,
                       xsize, xsn.max_height, xpos1, 0);
 
-      SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
+      SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
 
       for (i = xpos1; i < xpos2; i++)
        xsn.height[i] = MIN(xsn.height[i] + shrink, xsn.area_ysize - 1);
@@ -896,16 +899,11 @@ static void DrawTileCursor_Xsn(int draw_target)
   static boolean started = FALSE;
   static boolean active = FALSE;
   static boolean debug = FALSE;
-  static unsigned int check_delay = 0;
-  static unsigned int start_delay = 0;
-  static unsigned int growth_delay = 0;
-  static unsigned int update_delay = 0;
-  static unsigned int change_delay = 0;
-  static unsigned int check_delay_value = XSN_CHECK_DELAY * 1000;
-  static unsigned int start_delay_value = 0;
-  static unsigned int growth_delay_value = 0;
-  static unsigned int update_delay_value = 0;
-  static unsigned int change_delay_value = 0;
+  static DelayCounter check_delay = { XSN_CHECK_DELAY * 1000 };
+  static DelayCounter start_delay = { 0 };
+  static DelayCounter growth_delay = { 0 };
+  static DelayCounter update_delay = { 0 };
+  static DelayCounter change_delay = { 0 };
   static int percent = 0;
   static int debug_value = 0;
   boolean reinitialize = FALSE;
@@ -915,7 +913,7 @@ static void DrawTileCursor_Xsn(int draw_target)
   if (draw_target != DRAW_TO_SCREEN)
     return;
 
-  if (DelayReached(&check_delay, check_delay_value))
+  if (DelayReached(&check_delay))
   {
     percent = (debug ? debug_value * 100 / XSN_DEBUG_STEPS : xsn_percent());
 
@@ -943,7 +941,7 @@ static void DrawTileCursor_Xsn(int draw_target)
     debug = TRUE;
     active = FALSE;
 
-    DelayReached(&check_delay, 0);
+    ResetDelayCounter(&check_delay);
 
     setup.debug.xsn_mode = (debug_value > 0);
     tile_cursor.xsn_debug = FALSE;
@@ -952,18 +950,6 @@ static void DrawTileCursor_Xsn(int draw_target)
   if (!active)
     return;
 
-  if (!active_last)
-  {
-    boolean no_delay = (debug || setup.debug.xsn_mode == TRUE);
-
-    start_delay_value = (no_delay ? 0 : XSN_RND(XSN_START_DELAY * 2) * 1000);
-    started = FALSE;
-
-    DelayReached(&start_delay, 0);
-
-    reinitialize = TRUE;
-  }
-
   if (!initialized)
   {
     xsn.area_xsize = gfx.win_xsize;
@@ -1003,6 +989,17 @@ static void DrawTileCursor_Xsn(int draw_target)
     initialized = TRUE;
   }
 
+  if (!active_last)
+  {
+    start_delay.value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
+                        (XSN_START_DELAY + XSN_RND(XSN_START_DELAY)) * 1000);
+    started = FALSE;
+
+    ResetDelayCounter(&start_delay);
+
+    reinitialize = TRUE;
+  }
+
   if (reinitialize)
   {
     xsn.num_items  = 0;
@@ -1016,6 +1013,8 @@ static void DrawTileCursor_Xsn(int draw_target)
     xsn.change_type  = 0;
     xsn.change_dir   = 0;
 
+    xsn.alpha = XSN_ALPHA_DEFAULT;
+
     for (i = 0; i < xsn.max_items; i++)
       xsn_init_item(i);
   }
@@ -1046,8 +1045,8 @@ static void DrawTileCursor_Xsn(int draw_target)
     SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
                    SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
 
-    SDLSetAlpha(surface, TRUE, XSN_ALPHA_DEFAULT);
-    SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
+    SDLSetAlpha(surface, TRUE, xsn.alpha);
+    SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
 
     SDLCreateBitmapTextures(xsn.bitmap);
 
@@ -1068,40 +1067,54 @@ static void DrawTileCursor_Xsn(int draw_target)
 
   if (!started)
   {
-    if (!DelayReached(&start_delay, start_delay_value))
+    if (!DelayReached(&start_delay))
       return;
 
-    update_delay_value = XSN_UPDATE_DELAY;
-    growth_delay_value = XSN_GROWTH_DELAY * 1000;
-    change_delay_value = XSN_CHANGE_DELAY * 1000;
+    update_delay.value = XSN_UPDATE_DELAY;
+    growth_delay.value = XSN_GROWTH_DELAY * 1000;
+    change_delay.value = XSN_CHANGE_DELAY * 1000;
 
-    DelayReached(&growth_delay, 0);
-    DelayReached(&update_delay, 0);
-    DelayReached(&change_delay, 0);
+    ResetDelayCounter(&growth_delay);
+    ResetDelayCounter(&update_delay);
+    ResetDelayCounter(&change_delay);
 
     started = TRUE;
   }
 
   if (xsn.num_items < xsn.max_items)
   {
-    if (DelayReached(&growth_delay, growth_delay_value))
+    if (DelayReached(&growth_delay))
     {
       xsn.num_items += XSN_RND(XSN_GROWTH_RATE * 2);
       xsn.num_items = MIN(xsn.num_items, xsn.max_items);
     }
   }
 
-  if (DelayReached(&update_delay, update_delay_value))
+  if (DelayReached(&update_delay))
   {
     for (i = 0; i < xsn.num_items; i++)
       xsn_update_item(i);
   }
 
-  if (DelayReached(&change_delay, change_delay_value))
+  if (DelayReached(&change_delay))
   {
     xsn_update_change();
 
-    change_delay_value = xsn.change_delay * 1000;
+    change_delay.value = xsn.change_delay * 1000;
+  }
+
+  int xsn_alpha_dx = (gfx.mouse_y > xsn.area_ysize - xsn.max_height ?
+                     (xsn.alpha > XSN_ALPHA_VISIBLE ? -1 : 0) :
+                     (xsn.alpha < XSN_ALPHA_DEFAULT ? +1 : 0));
+
+  if (xsn_alpha_dx != 0)
+  {
+    xsn.alpha += xsn_alpha_dx;
+
+    SDLSetAlpha(xsn.bitmap->surface_masked, TRUE, xsn.alpha);
+
+    SDLFreeBitmapTextures(xsn.bitmap);
+    SDLCreateBitmapTextures(xsn.bitmap);
   }
 
   BlitToScreenMasked(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,