X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=e9d10df51f3a8103acb3520b27615e00cb487e1c;hb=4bb90da7a98b741b4576099be6b89d324c8a80de;hp=f479fd9960b804faa6ae41bc42b1a8040b3971c2;hpb=608be3bcd270eb45628a274eddb6dbcc8940accf;p=rocksndiamonds.git diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index f479fd99..e9d10df5 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -26,9 +26,9 @@ /* functions from SGE library */ inline void sge_Line(SDL_Surface *, Sint16, Sint16, Sint16, Sint16, Uint32); -#ifdef PLATFORM_WIN32 +/* #ifdef PLATFORM_WIN32 */ #define FULLSCREEN_BUG -#endif +/* #endif */ /* stuff needed to work around SDL/Windows fullscreen drawing bug */ static int fullscreen_width; @@ -71,7 +71,7 @@ inline void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, fullscreen_yoffset = 0; #ifdef FULLSCREEN_BUG - for (i=0; screen_xy[i][0] != -1; i++) + for (i = 0; screen_xy[i][0] != -1; i++) { if (video.width <= screen_xy[i][0] && video.height <= screen_xy[i][1]) { @@ -340,11 +340,11 @@ inline void SDLDrawLines(SDL_Surface *surface, struct XY *points, int i, x, y; int line_width = 4; - for (i=0; isurface; + SDL_Surface *surface = src_bitmap->surface; #ifdef FULLSCREEN_BUG - if (dst_bitmap == backbuffer || dst_bitmap == window) + if (src_bitmap == backbuffer || src_bitmap == window) { x += video_xoffset; y += video_yoffset; @@ -864,6 +864,19 @@ void sge_LineRGB(SDL_Surface *Surface, Sint16 x1, Sint16 y1, Sint16 x2, sge_Line(Surface, x1, y1, x2, y2, SDL_MapRGB(Surface->format, R, G, B)); } +inline void SDLPutPixel(Bitmap *dst_bitmap, int x, int y, Pixel pixel) +{ +#ifdef FULLSCREEN_BUG + if (dst_bitmap == backbuffer || dst_bitmap == window) + { + x += video_xoffset; + y += video_yoffset; + } +#endif + + sge_PutPixel(dst_bitmap->surface, x, y, pixel); +} + /* ----------------------------------------------------------------------------- @@ -874,16 +887,33 @@ void sge_LineRGB(SDL_Surface *Surface, Sint16 x1, Sint16 y1, Sint16 x2, inline void SDLInvertArea(Bitmap *bitmap, int src_x, int src_y, int width, int height, Uint32 color) { - SDL_Surface *surface = bitmap->surface; int x, y; - for (y=src_y; y < src_y + height; y++) + for (y = src_y; y < src_y + height; y++) { - for (x=src_x; x < src_x + width; x++) + for (x = src_x; x < src_x + width; x++) { Uint32 pixel = SDLGetPixel(bitmap, x, y); - sge_PutPixel(surface, x, y, pixel == BLACK_PIXEL ? color : BLACK_PIXEL); + SDLPutPixel(bitmap, x, y, pixel == BLACK_PIXEL ? color : BLACK_PIXEL); + } + } +} + +inline void SDLCopyInverseMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + int x, y; + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + Uint32 pixel = SDLGetPixel(src_bitmap, src_x + x, src_y + y); + + if (pixel != BLACK_PIXEL) + SDLPutPixel(dst_bitmap, dst_x + x, dst_y + y, BLACK_PIXEL); } } } @@ -1151,7 +1181,7 @@ SDL_Surface *zoomSurface(SDL_Surface *src, int dst_width, int dst_height) else { /* copy palette */ - for (i=0; i < zoom_src->format->palette->ncolors; i++) + for (i = 0; i < zoom_src->format->palette->ncolors; i++) zoom_dst->format->palette->colors[i] = zoom_src->format->palette->colors[i]; zoom_dst->format->palette->ncolors = zoom_src->format->palette->ncolors; @@ -1247,19 +1277,26 @@ static SDL_Cursor *create_cursor(struct MouseCursorInfo *cursor_info) void SDLSetMouseCursor(struct MouseCursorInfo *cursor_info) { static struct MouseCursorInfo *last_cursor_info = NULL; + static struct MouseCursorInfo *last_cursor_info2 = NULL; static SDL_Cursor *cursor_default = NULL; static SDL_Cursor *cursor_current = NULL; + /* if invoked for the first time, store the SDL default cursor */ if (cursor_default == NULL) cursor_default = SDL_GetCursor(); + /* only create new cursor if cursor info (custom only) has changed */ if (cursor_info != NULL && cursor_info != last_cursor_info) { cursor_current = create_cursor(cursor_info); last_cursor_info = cursor_info; } - SDL_SetCursor(cursor_info ? cursor_current : cursor_default); + /* only set new cursor if cursor info (custom or NULL) has changed */ + if (cursor_info != last_cursor_info2) + SDL_SetCursor(cursor_info ? cursor_current : cursor_default); + + last_cursor_info2 = cursor_info; } @@ -1332,14 +1369,14 @@ inline void SDLNextEvent(Event *event) } else if (event->type == EVENT_MOTIONNOTIFY) { - if (((ButtonEvent *)event)->x > video_xoffset) - ((ButtonEvent *)event)->x -= video_xoffset; + if (((MotionEvent *)event)->x > video_xoffset) + ((MotionEvent *)event)->x -= video_xoffset; else - ((ButtonEvent *)event)->x = 0; - if (((ButtonEvent *)event)->y > video_yoffset) - ((ButtonEvent *)event)->y -= video_yoffset; + ((MotionEvent *)event)->x = 0; + if (((MotionEvent *)event)->y > video_yoffset) + ((MotionEvent *)event)->y -= video_yoffset; else - ((ButtonEvent *)event)->y = 0; + ((MotionEvent *)event)->y = 0; } #endif } @@ -1417,7 +1454,7 @@ void SDLInitJoysticks() } } - for (i=0; i