+ if (!initialized)
+ {
+ xsn.area_xsize = gfx.win_xsize;
+ xsn.area_ysize = gfx.win_ysize;
+
+ for (i = 0; i < num_xsn_data; i++)
+ {
+ int size = xsn_data[i].size;
+ byte *bits = xsn_data[i].bits;
+ Bitmap *bitmap = CreateBitmap(size, size, DEFAULT_DEPTH);
+
+ FillRectangle(bitmap, 0, 0, size, size, BLACK_PIXEL);
+
+ for (y = 0; y < size; y++)
+ for (x = 0; x < size; x++)
+ if ((bits[y] >> x) & 0x01)
+ SDLPutPixel(bitmap, x, y, WHITE_PIXEL);
+
+ SDL_Surface *surface = bitmap->surface;
+
+ if ((bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
+ Fail("SDLGetNativeSurface() failed");
+
+ SDL_Surface *surface_masked = bitmap->surface_masked;
+
+ 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);
+
+ xsn_data[i].bitmap = bitmap;
+ }
+
+ srand((unsigned int)time(NULL));
+
+ 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;
+
+ DelayReached(&start_delay, 0);
+
+ reinitialize = TRUE;
+ }
+
+ if (reinitialize)
+ {
+ xsn.num_items = 0;
+ xsn.max_items = percent * XSN_MAX_ITEMS / 100;
+ xsn.max_height = percent * XSN_MAX_HEIGHT / 100;
+
+ xsn.max_dx = XSN_MAX_DX;
+ xsn.max_dy = XSN_MAX_DY;
+
+ xsn.change_delay = XSN_CHANGE_DELAY;
+ 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);
+ }
+
+ if (xsn.area_xsize != gfx.win_xsize ||
+ xsn.area_ysize != gfx.win_ysize ||
+ reinitialize)
+ {
+ xsn.area_xsize = gfx.win_xsize;
+ xsn.area_ysize = gfx.win_ysize;
+
+ if (xsn.bitmap != NULL)
+ FreeBitmap(xsn.bitmap);
+
+ xsn.bitmap = CreateBitmap(xsn.area_xsize, xsn.max_height * 2,
+ DEFAULT_DEPTH);
+
+ FillRectangle(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
+ BLACK_PIXEL);
+
+ SDL_Surface *surface = xsn.bitmap->surface;
+
+ if ((xsn.bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
+ Fail("SDLGetNativeSurface() failed");
+
+ SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
+
+ SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
+ SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
+
+ SDLSetAlpha(surface, TRUE, xsn.alpha);
+ SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
+
+ SDLCreateBitmapTextures(xsn.bitmap);
+
+ for (i = 0; i < num_xsn_data; i++)
+ {
+ SDLFreeBitmapTextures(xsn_data[i].bitmap);
+ SDLCreateBitmapTextures(xsn_data[i].bitmap);
+ }
+
+ if (xsn.height != NULL)
+ checked_free(xsn.height);
+
+ xsn.height = checked_calloc(xsn.area_xsize * sizeof(int));
+
+ for (i = 0; i < xsn.area_xsize; i++)
+ xsn.height[i] = xsn.area_ysize - 1;
+ }
+
+ if (!started)
+ {
+ if (!DelayReached(&start_delay, start_delay_value))
+ return;
+
+ 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);
+
+ started = TRUE;
+ }
+
+ if (xsn.num_items < xsn.max_items)
+ {
+ if (DelayReached(&growth_delay, growth_delay_value))
+ {
+ 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))
+ {
+ for (i = 0; i < xsn.num_items; i++)
+ xsn_update_item(i);
+ }
+
+ if (DelayReached(&change_delay, change_delay_value))
+ {
+ xsn_update_change();
+
+ 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,
+ 0, xsn.area_ysize - xsn.max_height);
+
+ for (i = 0; i < xsn.num_items; i++)
+ {
+ int dst_x = xsn.items[i].x;
+ int dst_y = xsn.items[i].y;
+ int type = xsn.items[i].type;
+ int size = xsn_data[type].size;
+ Bitmap *bitmap = xsn_data[type].bitmap;
+
+ BlitToScreenMasked(bitmap, 0, 0, size, size, dst_x, dst_y);
+ }
+}
+
+void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
+{
+ if (program.headless)
+ return;
+
+ Bitmap *fade_bitmap;
+ Bitmap *src_bitmap;
+ int src_x, src_y;
+ int dst_x, dst_y;
+ int graphic = IMG_GLOBAL_TILE_CURSOR;
+ int frame = 0;
+ int tilesize = TILESIZE_VAR;
+ int width = tilesize;
+ int height = tilesize;
+
+ DrawTileCursor_Xsn(draw_target);
+
+ if (!tile_cursor.enabled ||
+ !tile_cursor.active ||
+ !tile_cursor_active)
+ return;
+
+ if (tile_cursor.moving)
+ {
+ int step = TILESIZE_VAR / 4;
+ int dx = tile_cursor.target_x - tile_cursor.x;
+ int dy = tile_cursor.target_y - tile_cursor.y;
+
+ if (ABS(dx) < step)
+ tile_cursor.x = tile_cursor.target_x;
+ else
+ tile_cursor.x += SIGN(dx) * step;
+
+ if (ABS(dy) < step)
+ tile_cursor.y = tile_cursor.target_y;
+ else
+ tile_cursor.y += SIGN(dy) * step;
+
+ if (tile_cursor.x == tile_cursor.target_x &&
+ tile_cursor.y == tile_cursor.target_y)
+ tile_cursor.moving = FALSE;
+ }
+
+ dst_x = tile_cursor.x;
+ dst_y = tile_cursor.y;
+
+ frame = getGraphicAnimationFrame(graphic, -1);
+
+ getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
+
+ fade_bitmap =
+ (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
+ draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
+
+ if (draw_target == DRAW_TO_SCREEN)
+ BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
+ else
+ BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
+ dst_x, dst_y);
+}
+
+#if 0
+static int REQ_in_range(int x, int y)
+{
+ if (y > DY + 249 && y < DY + 278)
+ {
+ if (x > DX + 1 && x < DX + 48)
+ return 1;
+ else if (x > DX + 51 && x < DX + 98)
+ return 2;
+ }
+
+ return 0;
+}