+ if (draw_mask & REDRAW_ALL)
+ return TRUE;
+
+ if ((draw_mask & REDRAW_FIELD) && IN_GFX_FIELD_FULL(x, y))
+ return TRUE;
+
+ if ((draw_mask & REDRAW_DOOR_1) && IN_GFX_DOOR_1(x, y))
+ return TRUE;
+
+ if ((draw_mask & REDRAW_DOOR_2) && IN_GFX_DOOR_2(x, y))
+ return TRUE;
+
+ if ((draw_mask & REDRAW_DOOR_3) && IN_GFX_DOOR_3(x, y))
+ return TRUE;
+
+ 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);
+}
+
+boolean DrawingOnBackground(int x, int y)
+{
+ return (CheckDrawingArea(x, y, 1, 1, gfx.background_bitmap_mask) &&
+ CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
+}
+
+static boolean InClippedRectangle(Bitmap *bitmap, int *x, int *y,
+ int *width, int *height, boolean is_dest)
+{
+ int clip_x, clip_y, clip_width, clip_height;
+
+ if (gfx.clipping_enabled && is_dest) /* only clip destination bitmap */
+ {
+ clip_x = MIN(MAX(0, gfx.clip_x), bitmap->width);
+ clip_y = MIN(MAX(0, gfx.clip_y), bitmap->height);
+ clip_width = MIN(MAX(0, gfx.clip_width), bitmap->width - clip_x);
+ clip_height = MIN(MAX(0, gfx.clip_height), bitmap->height - clip_y);
+ }
+ else
+ {
+ clip_x = 0;
+ clip_y = 0;
+ clip_width = bitmap->width;
+ clip_height = bitmap->height;
+ }
+
+ /* skip if rectangle completely outside bitmap */
+
+ if (*x + *width <= clip_x ||
+ *y + *height <= clip_y ||
+ *x >= clip_x + clip_width ||
+ *y >= clip_y + clip_height)
+ return FALSE;
+
+ /* clip if rectangle overlaps bitmap */
+
+ if (*x < clip_x)
+ {
+ *width -= clip_x - *x;
+ *x = clip_x;
+ }
+ else if (*x + *width > clip_x + clip_width)
+ {
+ *width = clip_x + clip_width - *x;
+ }
+
+ if (*y < clip_y)
+ {
+ *height -= clip_y - *y;
+ *y = clip_y;
+ }
+ else if (*y + *height > clip_y + clip_height)
+ {
+ *height = clip_y + clip_height - *y;
+ }
+
+ return TRUE;
+}
+
+void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
+ int src_x, int src_y, int width, int height,
+ int dst_x, int dst_y)
+{
+ int dst_x_unclipped = dst_x;
+ int dst_y_unclipped = dst_y;
+
+ if (program.headless)
+ return;
+
+ if (src_bitmap == NULL || dst_bitmap == NULL)
+ return;
+
+ if (DrawingDeactivated(dst_x, dst_y, width, height))
+ return;
+
+ if (!InClippedRectangle(src_bitmap, &src_x, &src_y, &width, &height, FALSE) ||
+ !InClippedRectangle(dst_bitmap, &dst_x, &dst_y, &width, &height, TRUE))
+ return;
+
+ /* source x/y might need adjustment if destination x/y was clipped top/left */
+ src_x += dst_x - dst_x_unclipped;
+ src_y += dst_y - dst_y_unclipped;
+
+#if defined(TARGET_SDL2)
+ /* !!! 2013-12-11: An "old friend" is back. Same bug in SDL2 2.0.1 !!! */
+ /* !!! 2009-03-30: Fixed by using self-compiled, patched SDL.dll !!! */
+ /* (This bug still exists in the actual (as of 2009-06-15) version 1.2.13,
+ but is already fixed in SVN and should therefore finally be fixed with
+ the next official SDL release, which is probably version 1.2.14.) */
+ /* !!! 2009-03-24: It seems that this problem still exists in 1.2.12 !!! */
+
+ if (src_bitmap == dst_bitmap)
+ {
+ /* needed when blitting directly to same bitmap -- should not be needed with
+ recent SDL libraries, but apparently does not work in 1.2.11 directly */
+
+ static Bitmap *tmp_bitmap = NULL;
+ static int tmp_bitmap_xsize = 0;
+ static int tmp_bitmap_ysize = 0;
+
+ /* start with largest static bitmaps for initial bitmap size ... */
+ if (tmp_bitmap_xsize == 0 && tmp_bitmap_ysize == 0)
+ {
+ tmp_bitmap_xsize = MAX(gfx.win_xsize, gfx.scrollbuffer_width);
+ tmp_bitmap_ysize = MAX(gfx.win_ysize, gfx.scrollbuffer_height);
+ }
+
+ /* ... and allow for later re-adjustments due to custom artwork bitmaps */
+ if (src_bitmap->width > tmp_bitmap_xsize ||
+ src_bitmap->height > tmp_bitmap_ysize)
+ {
+ tmp_bitmap_xsize = MAX(tmp_bitmap_xsize, src_bitmap->width);
+ tmp_bitmap_ysize = MAX(tmp_bitmap_ysize, src_bitmap->height);
+
+ FreeBitmap(tmp_bitmap);
+
+ tmp_bitmap = NULL;
+ }
+
+ if (tmp_bitmap == NULL)
+ tmp_bitmap = CreateBitmap(tmp_bitmap_xsize, tmp_bitmap_ysize,
+ DEFAULT_DEPTH);
+
+ sysCopyArea(src_bitmap, tmp_bitmap,
+ src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE);
+ sysCopyArea(tmp_bitmap, dst_bitmap,
+ dst_x, dst_y, width, height, dst_x, dst_y, BLIT_OPAQUE);
+
+ return;
+ }
+#endif
+
+ sysCopyArea(src_bitmap, dst_bitmap,
+ src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE);
+}
+
+void BlitBitmapTiled(Bitmap *src_bitmap, Bitmap *dst_bitmap,
+ int src_x, int src_y, int src_width, int src_height,
+ int dst_x, int dst_y, int dst_width, int dst_height)
+{
+ int src_xsize = (src_width == 0 ? src_bitmap->width : src_width);
+ int src_ysize = (src_height == 0 ? src_bitmap->height : src_height);
+ int dst_xsize = dst_width;
+ int dst_ysize = dst_height;
+ int src_xsteps = (dst_xsize + src_xsize - 1) / src_xsize;
+ int src_ysteps = (dst_ysize + src_ysize - 1) / src_ysize;
+ int x, y;
+
+ for (y = 0; y < src_ysteps; y++)
+ {
+ for (x = 0; x < src_xsteps; x++)
+ {
+ int draw_x = dst_x + x * src_xsize;
+ int draw_y = dst_y + y * src_ysize;
+ int draw_xsize = MIN(src_xsize, dst_xsize - x * src_xsize);
+ int draw_ysize = MIN(src_ysize, dst_ysize - y * src_ysize);
+
+ BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, draw_xsize, draw_ysize,
+ draw_x, draw_y);
+ }
+ }
+}
+
+void FadeRectangle(int x, int y, int width, int height,
+ int fade_mode, int fade_delay, int post_delay,
+ void (*draw_border_function)(void))
+{
+ /* (use destination bitmap "backbuffer" -- "bitmap_cross" may be undefined) */
+ if (!InClippedRectangle(backbuffer, &x, &y, &width, &height, TRUE))
+ return;
+
+ SDLFadeRectangle(x, y, width, height,
+ fade_mode, fade_delay, post_delay, draw_border_function);
+}
+
+void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height,
+ Pixel color)
+{
+ if (DrawingDeactivated(x, y, width, height))
+ return;
+
+ if (!InClippedRectangle(bitmap, &x, &y, &width, &height, TRUE))
+ return;
+
+ sysFillRectangle(bitmap, x, y, width, height, color);
+}
+
+void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height)
+{
+ FillRectangle(bitmap, x, y, width, height, BLACK_PIXEL);
+}
+
+void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y,
+ int width, int height)
+{
+ if (DrawingOnBackground(x, y))
+ BlitBitmap(gfx.background_bitmap, bitmap, x, y, width, height, x, y);
+ else
+ ClearRectangle(bitmap, x, y, width, height);
+}
+
+void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap,
+ int src_x, int src_y, int width, int height,
+ int dst_x, int dst_y)
+{
+ if (DrawingDeactivated(dst_x, dst_y, width, height))
+ return;
+
+ sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
+ dst_x, dst_y, BLIT_MASKED);
+}
+
+void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
+ int src_x, int src_y, int width, int height,
+ int dst_x, int dst_y)
+{
+ if (DrawingOnBackground(dst_x, dst_y))
+ {
+ /* draw background */
+ BlitBitmap(gfx.background_bitmap, dst_bitmap, dst_x, dst_y, width, height,
+ dst_x, dst_y);
+
+ /* draw foreground */
+ BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height,
+ dst_x, dst_y);
+ }
+ else
+ BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, width, height,
+ dst_x, dst_y);
+}
+
+void BlitTexture(Bitmap *bitmap,
+ int src_x, int src_y, int width, int height,
+ int dst_x, int dst_y)
+{
+ if (bitmap == NULL)
+ return;
+
+ SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y,
+ BLIT_OPAQUE);
+}
+
+void BlitTextureMasked(Bitmap *bitmap,
+ int src_x, int src_y, int width, int height,
+ int dst_x, int dst_y)
+{
+ if (bitmap == NULL)
+ return;
+
+ SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y,
+ BLIT_MASKED);
+}
+
+void BlitToScreen(Bitmap *bitmap,
+ int src_x, int src_y, int width, int height,
+ int dst_x, int dst_y)
+{
+ if (bitmap == NULL)
+ return;
+
+ if (video.screen_rendering_mode == SPECIAL_RENDERING_BITMAP)
+ BlitBitmap(bitmap, gfx.final_screen_bitmap, src_x, src_y,
+ width, height, dst_x, dst_y);
+ else
+ BlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y);
+}
+
+void BlitToScreenMasked(Bitmap *bitmap,
+ int src_x, int src_y, int width, int height,
+ int dst_x, int dst_y)
+{
+ if (bitmap == NULL)
+ return;
+
+ if (video.screen_rendering_mode == SPECIAL_RENDERING_BITMAP)
+ BlitBitmapMasked(bitmap, gfx.final_screen_bitmap, src_x, src_y,
+ width, height, dst_x, dst_y);
+ else
+ BlitTextureMasked(bitmap, src_x, src_y, width, height, dst_x, dst_y);
+}
+
+void DrawSimpleBlackLine(Bitmap *bitmap, int from_x, int from_y,
+ int to_x, int to_y)
+{
+ SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, BLACK_PIXEL);
+}
+
+void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y,
+ int to_x, int to_y)
+{
+ SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL);
+}
+
+void DrawLine(Bitmap *bitmap, int from_x, int from_y,
+ int to_x, int to_y, Pixel pixel, int line_width)
+{
+ int x, y;
+
+ for (x = 0; x < line_width; x++)
+ {
+ for (y = 0; y < line_width; y++)
+ {
+ int dx = x - line_width / 2;
+ int dy = y - line_width / 2;
+
+ if ((x == 0 && y == 0) ||
+ (x == 0 && y == line_width - 1) ||
+ (x == line_width - 1 && y == 0) ||
+ (x == line_width - 1 && y == line_width - 1))
+ continue;
+
+ SDLDrawLine(bitmap,
+ from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel);
+ }
+ }
+}
+
+void DrawLines(Bitmap *bitmap, struct XY *points, int num_points, Pixel pixel)
+{
+ int line_width = 4;
+ int i;
+
+ for (i = 0; i < num_points - 1; i++)
+ DrawLine(bitmap, points[i].x, points[i].y,
+ points[i + 1].x, points[i + 1].y, pixel, line_width);
+
+ /*
+ SDLDrawLines(bitmap->surface, points, num_points, pixel);
+ */
+}
+
+Pixel GetPixel(Bitmap *bitmap, int x, int y)
+{
+ if (x < 0 || x >= bitmap->width ||
+ y < 0 || y >= bitmap->height)
+ return BLACK_PIXEL;
+
+ return SDLGetPixel(bitmap, x, y);
+}
+
+Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r,
+ unsigned int color_g, unsigned int color_b)
+{
+ return SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b);
+}
+
+Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color)
+{
+ unsigned int color_r = (color >> 16) & 0xff;
+ unsigned int color_g = (color >> 8) & 0xff;
+ unsigned int color_b = (color >> 0) & 0xff;
+
+ return GetPixelFromRGB(bitmap, color_r, color_g, color_b);
+}
+
+void KeyboardAutoRepeatOn(void)
+{
+#if defined(TARGET_SDL2)
+ keyrepeat_status = TRUE;
+#else
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2,
+ SDL_DEFAULT_REPEAT_INTERVAL / 2);
+ SDL_EnableUNICODE(1);
+#endif
+}
+
+void KeyboardAutoRepeatOff(void)
+{
+#if defined(TARGET_SDL2)
+ keyrepeat_status = FALSE;