X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsystem.c;h=4b7a3cad7a238069e30d6f60bf345ce23e59e41e;hb=87382cdd307aa01757ed5c8a863ebb7dcb812e8e;hp=8a5942da4af6ca6984b540c1ef99f4c8e1686ebf;hpb=59ee473b86e7cbc1d9b09a3c22b0bbd3a410f16f;p=rocksndiamonds.git diff --git a/src/libgame/system.c b/src/libgame/system.c index 8a5942da..4b7a3cad 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -211,6 +211,15 @@ void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height) gfx.scrollbuffer_height = scrollbuffer_height; } +void InitGfxClipRegion(boolean enabled, int x, int y, int width, int height) +{ + gfx.clipping_enabled = enabled; + gfx.clip_x = x; + gfx.clip_y = y; + gfx.clip_width = width; + gfx.clip_height = height; +} + void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void)) { gfx.draw_busy_anim_function = draw_busy_anim_function; @@ -512,14 +521,115 @@ boolean DrawingOnBackground(int x, int y) 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) +{ +#if 1 + 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; + +#else + + /* skip if rectangle completely outside bitmap */ + + if (*x + *width <= 0 || + *y + *height <= 0 || + *x >= bitmap->width || + *y >= bitmap->height) + return FALSE; + + /* clip if rectangle overlaps bitmap */ + + if (*x < 0) + { + *width += *x; + *x = 0; + } + else if (*x + *width > bitmap->width) + { + *width = bitmap->width - *x; + } + + if (*y < 0) + { + *height += *y; + *y = 0; + } + else if (*y + *height > bitmap->height) + { + *height = bitmap->height - *y; + } + + return TRUE; +#endif +} + 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 (DrawingDeactivated(dst_x, dst_y, width, height)) return; #if 1 + 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; + +#else /* skip if rectangle starts outside bitmap */ if (src_x >= src_bitmap->width || src_y >= src_bitmap->height || @@ -599,6 +709,12 @@ void FadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, int fade_mode, int fade_delay, int post_delay, void (*draw_border_function)(void)) { +#if 1 + /* (use destination bitmap "backbuffer" -- "bitmap_cross" may be undefined) */ + if (!InClippedRectangle(backbuffer, &x, &y, &width, &height, TRUE)) + return; +#endif + #if defined(TARGET_SDL) SDLFadeRectangle(bitmap_cross, x, y, width, height, fade_mode, fade_delay, post_delay, draw_border_function); @@ -615,6 +731,9 @@ void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height, return; #if 1 + if (!InClippedRectangle(bitmap, &x, &y, &width, &height, TRUE)) + return; +#else /* skip if rectangle starts outside bitmap */ if (x >= bitmap->width || y >= bitmap->height)