X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsystem.c;h=bccb5fddddbc847b0208998eb783968cb86b9dd9;hb=41def9c1d8c6939b8754fdab43579272e49d4da4;hp=d4b7f9a92b7b5147f38f93eca7ad7e028bb6b7f8;hpb=1ceb7ce8723b32b267758bfda3bb7903fff8ea7a;p=rocksndiamonds.git diff --git a/src/libgame/system.c b/src/libgame/system.c index d4b7f9a9..bccb5fdd 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -166,8 +166,10 @@ void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize, gfx.field_save_buffer = field_save_buffer; +#if 0 gfx.background_bitmap = NULL; gfx.background_bitmap_mask = REDRAW_NONE; +#endif SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */ SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */ @@ -193,6 +195,12 @@ void InitGfxWindowInfo(int win_xsize, int win_ysize) { gfx.win_xsize = win_xsize; gfx.win_ysize = win_ysize; + +#if 1 + gfx.background_bitmap_mask = REDRAW_NONE; + + ReCreateBitmap(&gfx.background_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH); +#endif } void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height) @@ -259,9 +267,11 @@ void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) else gfx.background_bitmap_mask &= ~mask; +#if 0 if (gfx.background_bitmap == NULL) gfx.background_bitmap = CreateBitmap(video.width, video.height, DEFAULT_DEPTH); +#endif if (background_bitmap_tile == NULL) /* empty background requested */ return; @@ -367,8 +377,10 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) video.fullscreen_available = FULLSCREEN_STATUS; video.fullscreen_enabled = FALSE; - video.fullscreen_modes = NULL; +#if 0 video.fullscreen_mode_current = NULL; + video.fullscreen_modes = NULL; +#endif #if defined(TARGET_SDL) SDLInitVideoBuffer(&backbuffer, &window, fullscreen); @@ -379,34 +391,6 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) drawto = backbuffer; } -Bitmap *CreateBitmapStruct(void) -{ -#if defined(TARGET_SDL) - return checked_calloc(sizeof(struct SDLSurfaceInfo)); -#else - return checked_calloc(sizeof(struct X11DrawableInfo)); -#endif -} - -Bitmap *CreateBitmap(int width, int height, int depth) -{ - Bitmap *new_bitmap = CreateBitmapStruct(); - int real_width = MAX(1, width); /* prevent zero bitmap width */ - int real_height = MAX(1, height); /* prevent zero bitmap height */ - int real_depth = GetRealDepth(depth); - -#if defined(TARGET_SDL) - SDLCreateBitmapContent(new_bitmap, real_width, real_height, real_depth); -#else - X11CreateBitmapContent(new_bitmap, real_width, real_height, real_depth); -#endif - - new_bitmap->width = real_width; - new_bitmap->height = real_height; - - return new_bitmap; -} - inline static void FreeBitmapPointers(Bitmap *bitmap) { if (bitmap == NULL) @@ -443,16 +427,53 @@ void FreeBitmap(Bitmap *bitmap) free(bitmap); } -void CloseWindow(DrawWindow *window) +Bitmap *CreateBitmapStruct(void) { -#if defined(TARGET_X11) - if (window->drawable) +#if defined(TARGET_SDL) + return checked_calloc(sizeof(struct SDLSurfaceInfo)); +#else + return checked_calloc(sizeof(struct X11DrawableInfo)); +#endif +} + +Bitmap *CreateBitmap(int width, int height, int depth) +{ + Bitmap *new_bitmap = CreateBitmapStruct(); + int real_width = MAX(1, width); /* prevent zero bitmap width */ + int real_height = MAX(1, height); /* prevent zero bitmap height */ + int real_depth = GetRealDepth(depth); + +#if defined(TARGET_SDL) + SDLCreateBitmapContent(new_bitmap, real_width, real_height, real_depth); +#else + X11CreateBitmapContent(new_bitmap, real_width, real_height, real_depth); +#endif + + new_bitmap->width = real_width; + new_bitmap->height = real_height; + + return new_bitmap; +} + +void ReCreateBitmap(Bitmap **bitmap, int width, int height, int depth) +{ + Bitmap *new_bitmap = CreateBitmap(width, height, depth); + + if (*bitmap == NULL) { - XUnmapWindow(display, window->drawable); - XDestroyWindow(display, window->drawable); + *bitmap = new_bitmap; } - if (window->gc) - XFreeGC(display, window->gc); + else + { + TransferBitmapPointers(new_bitmap, *bitmap); + free(new_bitmap); + } +} + +void CloseWindow(DrawWindow *window) +{ +#if defined(TARGET_X11) + X11CloseWindow(window); #endif } @@ -491,6 +512,38 @@ boolean DrawingOnBackground(int x, int y) CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask)); } +static boolean ValidClippedRectangle(Bitmap *bitmap, int *x, int *y, + int *width, int *height) +{ + /* 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) + { + *x = 0; + *width += *x; + } + else if (*x + *width > bitmap->width) + *width = bitmap->width - *x; + + if (*y < 0) + { + *y = 0; + *height += *y; + } + else if (*y + *height > bitmap->height) + *height = bitmap->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) @@ -498,6 +551,29 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, if (DrawingDeactivated(dst_x, dst_y, width, height)) return; +#if 1 + if (!ValidClippedRectangle(src_bitmap, &src_x, &src_y, &width, &height) || + !ValidClippedRectangle(dst_bitmap, &dst_x, &dst_y, &width, &height)) + return; +#else + /* skip if rectangle starts outside bitmap */ + if (src_x >= src_bitmap->width || + src_y >= src_bitmap->height || + dst_x >= dst_bitmap->width || + dst_y >= dst_bitmap->height) + return; + + /* clip if rectangle overlaps bitmap */ + if (src_x + width > src_bitmap->width) + width = src_bitmap->width - src_x; + if (src_y + height > src_bitmap->height) + height = src_bitmap->height - src_y; + if (dst_x + width > dst_bitmap->width) + width = dst_bitmap->width - dst_x; + if (dst_y + height > dst_bitmap->height) + height = dst_bitmap->height - dst_y; +#endif + #if 0 /* !!! 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, @@ -559,6 +635,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 bitmap "backbuffer" -- "bitmap_cross" may be undefined) */ + if (!ValidClippedRectangle(backbuffer, &x, &y, &width, &height)) + return; +#endif + #if defined(TARGET_SDL) SDLFadeRectangle(bitmap_cross, x, y, width, height, fade_mode, fade_delay, post_delay, draw_border_function); @@ -574,6 +656,22 @@ void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height, if (DrawingDeactivated(x, y, width, height)) return; +#if 1 + if (!ValidClippedRectangle(bitmap, &x, &y, &width, &height)) + return; +#else + /* skip if rectangle starts outside bitmap */ + if (x >= bitmap->width || + y >= bitmap->height) + return; + + /* clip if rectangle overlaps bitmap */ + if (x + width > bitmap->width) + width = bitmap->width - x; + if (y + height > bitmap->height) + height = bitmap->height - y; +#endif + sysFillRectangle(bitmap, x, y, width, height, color); }