+void FadeExt(int fade_mask, int fade_mode)
+{
+ static int fade_mode_skip = FADE_MODE_NONE;
+ void (*draw_border_function)(void) = NULL;
+#if 0
+ Bitmap *bitmap = (fade_mode != FADE_MODE_FADE_IN ? bitmap_db_cross : NULL);
+#else
+ Bitmap *bitmap = (fade_mode & FADE_TYPE_TRANSFORM ? bitmap_db_cross : NULL);
+#endif
+ int x, y, width, height;
+ int fade_delay, post_delay;
+
+ redraw_mask |= fade_mask;
+
+ if (fade_mode & FADE_TYPE_SKIP)
+ {
+#if 0
+ printf("::: will skip %d ... [%d]\n", fade_mode, fade_mode_skip);
+#endif
+
+ fade_mode_skip = fade_mode;
+
+ return;
+ }
+
+ if (fade_mode_skip & FADE_TYPE_SKIP)
+ {
+#if 0
+ printf("::: skipping %d ... [%d]\n", fade_mode, fade_mode_skip);
+#endif
+
+ /* skip all fade operations until specified fade operation */
+ if (fade_mode & fade_mode_skip)
+ fade_mode_skip = FADE_MODE_NONE;
+
+ return;
+ }
+
+#if 1
+ if (global.autoplay_leveldir)
+ fading.fade_mode = FADE_MODE_NONE;
+#endif
+
+#if 1
+ if (fading.fade_mode == FADE_MODE_NONE)
+ return;
+#endif
+
+ if (fade_mask & REDRAW_FIELD)
+ {
+ x = REAL_SX;
+ y = REAL_SY;
+ width = FULL_SXSIZE;
+ height = FULL_SYSIZE;
+
+ fade_delay = fading.fade_delay;
+ post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0);
+
+ draw_border_function = DrawMaskedBorder_FIELD;
+ }
+ else /* REDRAW_ALL */
+ {
+ x = 0;
+ y = 0;
+ width = WIN_XSIZE;
+ height = WIN_YSIZE;
+
+ fade_delay = fading.fade_delay;
+ post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0);
+ }
+
+#if 1
+ if (!setup.fade_screens || fade_delay == 0)
+#else
+ if (!setup.fade_screens || fade_delay == 0 || fading.anim_mode == ANIM_NONE)
+#endif
+ {
+ if (fade_mode == FADE_MODE_FADE_OUT)
+ ClearRectangle(backbuffer, x, y, width, height);
+
+ BackToFront();
+
+ return;
+ }
+
+ FadeRectangle(bitmap, x, y, width, height, fade_mode, fade_delay, post_delay,
+ draw_border_function);
+
+ redraw_mask &= ~fade_mask;
+}
+
+void FadeIn(int fade_mask)
+{
+#if 1
+ // printf("::: now fading in...\n");
+
+ if (fading.fade_mode & FADE_TYPE_TRANSFORM)
+ FadeExt(fade_mask, fading.fade_mode);
+ else
+ FadeExt(fade_mask, FADE_MODE_FADE_IN);
+#else
+#if 1
+ if (fading.fade_mode == FADE_MODE_CROSSFADE)
+ FadeExt(fade_mask, FADE_MODE_CROSSFADE);
+ else
+ FadeExt(fade_mask, FADE_MODE_FADE_IN);
+#else
+ FadeExt(fade_mask, FADE_MODE_FADE_IN);
+#endif
+#endif
+}
+
+void FadeOut(int fade_mask)
+{
+#if 1
+ // printf("::: fading.fade_mode == %d\n", fading.fade_mode);
+
+ if (fading.fade_mode & FADE_TYPE_TRANSFORM)
+ FadeCrossSaveBackbuffer();
+ else
+ FadeExt(fade_mask, FADE_MODE_FADE_OUT);
+#else
+#if 1
+ if (fading.fade_mode == FADE_MODE_CROSSFADE)
+ FadeCrossSaveBackbuffer();
+ else
+ FadeExt(fade_mask, FADE_MODE_FADE_OUT);
+#else
+ FadeExt(fade_mask, FADE_MODE_FADE_OUT);
+#endif
+#endif
+}
+
+void FadeCross(int fade_mask)
+{
+ FadeExt(fade_mask, FADE_MODE_CROSSFADE);
+}
+
+void FadeCrossSaveBackbuffer()
+{
+ BlitBitmap(backbuffer, bitmap_db_cross, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+}
+
+static void FadeSetLeaveNext(struct TitleFadingInfo fading_leave, boolean set)
+{
+ static struct TitleFadingInfo fading_leave_stored;
+
+ if (set)
+ fading_leave_stored = fading_leave;
+ else
+ fading = fading_leave_stored;
+}
+
+void FadeSetEnterMenu()
+{
+ fading = menu.enter_menu;
+
+ FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */
+}
+
+void FadeSetLeaveMenu()
+{
+ fading = menu.leave_menu;
+
+ FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */
+}
+
+void FadeSetEnterScreen()
+{
+ fading = menu.enter_screen[game_status];
+
+ FadeSetLeaveNext(menu.leave_screen[game_status], TRUE); /* store */
+}
+
+void FadeSetLeaveScreen()
+{
+ FadeSetLeaveNext(menu.leave_screen[game_status], FALSE); /* recall */
+}
+
+void FadeSetFromType(int type)
+{
+ if (type & TYPE_ENTER_SCREEN)
+ FadeSetEnterScreen();
+ else if (type & TYPE_ENTER)
+ FadeSetEnterMenu();
+ else if (type & TYPE_LEAVE)
+ FadeSetLeaveMenu();
+}
+
+void FadeSetDisabled()
+{
+ static struct TitleFadingInfo fading_none = { FADE_MODE_NONE, -1, -1, -1 };
+
+ fading = fading_none;
+}
+
+void FadeSkipNextFadeIn()
+{
+ FadeExt(0, FADE_MODE_SKIP_FADE_IN);
+}
+
+void FadeSkipNextFadeOut()
+{
+ FadeExt(0, FADE_MODE_SKIP_FADE_OUT);
+}
+
+void SetWindowBackgroundImageIfDefined(int graphic)
+{
+ if (graphic_info[graphic].bitmap)
+ SetWindowBackgroundBitmap(graphic_info[graphic].bitmap);
+}
+