From: Holger Schemel Date: Thu, 3 Apr 2003 21:56:25 +0000 (+0200) Subject: rnd-20030403-3-src X-Git-Tag: 3.0.0^2~116 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=e4bf86b0ac3fd50612eee1439beba2fbaaa7cd09;p=rocksndiamonds.git rnd-20030403-3-src --- diff --git a/Makefile b/Makefile index a5b3d976..ea7b1525 100644 --- a/Makefile +++ b/Makefile @@ -49,8 +49,8 @@ CROSS_PATH_WIN32=/usr/local/cross-tools/i386-mingw32msvc SRC_DIR = src MAKE_CMD = $(MAKE) -C $(SRC_DIR) -DEFAULT_TARGET = x11 -# DEFAULT_TARGET = sdl +# DEFAULT_TARGET = x11 +DEFAULT_TARGET = sdl all: @$(MAKE_CMD) TARGET=$(DEFAULT_TARGET) diff --git a/src/conftime.h b/src/conftime.h index 8f9e2ea2..d0a15b16 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-04-03 21:08]" +#define COMPILE_DATE_STRING "[2003-04-03 23:55]" diff --git a/src/game.c b/src/game.c index b6a7697e..d60f158a 100644 --- a/src/game.c +++ b/src/game.c @@ -919,7 +919,7 @@ void InitGame() else { DrawTextExt(drawto, DX + XX_EMERALDS, DY + YY_EMERALDS, - int2str(level_nr, 3), FONT_LEVEL_NUMBER, FONT_OPAQUE); + int2str(level_nr, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE); BlitBitmap(drawto, drawto, DX + XX_EMERALDS, DY + YY_EMERALDS + 1, getFontWidth(FONT_LEVEL_NUMBER) * 3, diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 45744a8c..90d7087a 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -165,7 +165,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) /* gadget text value */ DrawTextExt(drawto, gi->x + border, gi->y + border, text, - font_type, FONT_MASKED); + font_type, BLIT_MASKED); cursor_letter = gi->text.value[gi->text.cursor_position]; cursor_string[0] = '~'; @@ -177,7 +177,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) DrawTextExt(drawto, gi->x + border + gi->text.cursor_position * font_width, gi->y + border, cursor_string, - font_type, FONT_MASKED); + font_type, BLIT_MASKED); } break; @@ -222,7 +222,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) /* gadget text value */ DrawTextExt(drawto, gi->x + border, gi->y + border, text, - font_type, FONT_MASKED); + font_type, BLIT_MASKED); if (pressed) { @@ -324,7 +324,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) { if (i == gi->selectbox.current_index) { - DrawRectangle(drawto, + FillRectangle(drawto, gi->selectbox.x + border, gi->selectbox.y + border + i * font_height, gi->selectbox.width - 2 * border, font_height, @@ -343,7 +343,7 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) DrawTextExt(drawto, gi->selectbox.x + border, gi->selectbox.y + border + i * font_height, text, - font_type, FONT_MASKED); + font_type, BLIT_MASKED); } redraw_selectbox = TRUE; @@ -790,6 +790,8 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) if (!getFontChar(font_nr, '|', &src_x, &src_y)) Error(ERR_EXIT, "selectbox gadget incomplete (cannot get cursor)"); + src_x += font_width / 2; + src_y += font_height / 2; gi->selectbox.reverse_color = GetPixel(font->bitmap, src_x, src_y); /* always start with closed selectbox */ @@ -1211,6 +1213,24 @@ void HandleGadgets(int mx, int my, int button) if (last_x != gi->event.x || last_y != gi->event.y) changed_position = TRUE; } + else if (gi->type & GD_TYPE_SELECTBOX) + { + int old_index = gi->selectbox.current_index; + + /* if mouse moving inside activated selectbox, select value */ + if (my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height) + gi->selectbox.current_index = + (my - gi->selectbox.y - gi->border.size) / + getFontWidth(gi->selectbox.font_type); + + if (gi->selectbox.current_index < 0) + gi->selectbox.current_index = 0; + else if (gi->selectbox.current_index > gi->selectbox.num_values - 1) + gi->selectbox.current_index = gi->selectbox.num_values - 1; + + if (gi->selectbox.current_index != old_index) + DrawGadget(gi, DG_PRESSED, DG_DIRECT); + } } /* handle gadget popup info text */ diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 85dbab94..635816c7 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -175,7 +175,7 @@ inline boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) inline void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, int src_x, int src_y, int width, int height, - int dst_x, int dst_y, int copy_mode) + int dst_x, int dst_y, int mask_mode) { Bitmap *real_dst_bitmap = (dst_bitmap == window ? backbuffer : dst_bitmap); SDL_Rect src_rect, dst_rect; @@ -207,7 +207,7 @@ inline void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, dst_rect.h = height; if (src_bitmap != backbuffer || dst_bitmap != window) - SDL_BlitSurface((copy_mode == SDLCOPYAREA_MASKED ? + SDL_BlitSurface((mask_mode == BLIT_MASKED ? src_bitmap->surface_masked : src_bitmap->surface), &src_rect, real_dst_bitmap->surface, &dst_rect); @@ -216,13 +216,15 @@ inline void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, } inline void SDLFillRectangle(Bitmap *dst_bitmap, int x, int y, - int width, int height, unsigned int color) + int width, int height, Uint32 color) { Bitmap *real_dst_bitmap = (dst_bitmap == window ? backbuffer : dst_bitmap); SDL_Rect rect; - unsigned int color_r = (color >> 16) && 0xff; - unsigned int color_g = (color >> 8) && 0xff; - unsigned int color_b = (color >> 0) && 0xff; +#if 0 + unsigned int color_r = (color >> 16) & 0xff; + unsigned int color_g = (color >> 8) & 0xff; + unsigned int color_b = (color >> 0) & 0xff; +#endif #ifdef FULLSCREEN_BUG if (dst_bitmap == backbuffer || dst_bitmap == window) @@ -237,22 +239,28 @@ inline void SDLFillRectangle(Bitmap *dst_bitmap, int x, int y, rect.w = width; rect.h = height; +#if 1 + SDL_FillRect(real_dst_bitmap->surface, &rect, color); +#else SDL_FillRect(real_dst_bitmap->surface, &rect, SDL_MapRGB(real_dst_bitmap->surface->format, color_r, color_g, color_b)); +#endif if (dst_bitmap == window) SDL_UpdateRect(backbuffer->surface, x, y, width, height); } inline void SDLDrawSimpleLine(Bitmap *dst_bitmap, int from_x, int from_y, - int to_x, int to_y, unsigned int color) + int to_x, int to_y, Uint32 color) { SDL_Surface *surface = dst_bitmap->surface; SDL_Rect rect; +#if 0 unsigned int color_r = (color >> 16) & 0xff; unsigned int color_g = (color >> 8) & 0xff; unsigned int color_b = (color >> 0) & 0xff; +#endif if (from_x > to_x) swap_numbers(&from_x, &to_x); @@ -273,8 +281,12 @@ inline void SDLDrawSimpleLine(Bitmap *dst_bitmap, int from_x, int from_y, } #endif +#if 1 + SDL_FillRect(surface, &rect, color); +#else SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, color_r, color_g, color_b)); +#endif } inline void SDLDrawLine(Bitmap *dst_bitmap, int from_x, int from_y, diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 4b4f34d3..528b763a 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -23,9 +23,6 @@ #define SURFACE_FLAGS (SDL_SWSURFACE) -#define SDLCOPYAREA_OPAQUE 0 -#define SDLCOPYAREA_MASKED 1 - /* system dependent definitions */ #define TARGET_STRING "SDL" @@ -79,6 +76,9 @@ struct XY #define None 0L +#define BlackPixel(d, s) 0x000000 +#define WhitePixel(d, s) 0xffffff + #define EVENT_BUTTONPRESS SDL_MOUSEBUTTONDOWN #define EVENT_BUTTONRELEASE SDL_MOUSEBUTTONUP #define EVENT_MOTIONNOTIFY SDL_MOUSEMOTION @@ -325,8 +325,8 @@ inline void SDLInitVideoDisplay(void); inline void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean); inline boolean SDLSetVideoMode(DrawBuffer **, boolean); inline void SDLCopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int); -inline void SDLFillRectangle(Bitmap *, int, int, int, int, unsigned int); -inline void SDLDrawSimpleLine(Bitmap *, int, int, int, int, unsigned int); +inline void SDLFillRectangle(Bitmap *, int, int, int, int, Uint32); +inline void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32); inline void SDLDrawLine(Bitmap *, int, int, int, int, Uint32); inline Pixel SDLGetPixel(Bitmap *, int, int); diff --git a/src/libgame/system.c b/src/libgame/system.c index 7d25d4cd..680ff2d5 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -272,6 +272,29 @@ inline static int GetRealDepth(int depth) return (depth == DEFAULT_DEPTH ? video.default_depth : depth); } +inline static void sysFillRectangle(Bitmap *bitmap, int x, int y, + int width, int height, Pixel color) +{ +#ifdef TARGET_SDL + SDLFillRectangle(bitmap, x, y, width, height, color); +#else + X11FillRectangle(bitmap, x, y, width, height, color); +#endif +} + +inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y, int mask_mode) +{ +#ifdef TARGET_SDL + SDLCopyArea(src_bitmap, dst_bitmap, + src_x, src_y, width, height, dst_x, dst_y, mask_mode); +#else + X11CopyArea(src_bitmap, dst_bitmap, + src_x, src_y, width, height, dst_x, dst_y, mask_mode); +#endif +} + inline void InitVideoDisplay(void) { #if defined(TARGET_SDL) @@ -466,59 +489,29 @@ inline boolean DrawingOnBackground(int x, int y) } inline void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, - int src_x, int src_y, - int width, int height, + 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; -#ifdef TARGET_SDL - SDLCopyArea(src_bitmap, dst_bitmap, - src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_OPAQUE); -#else - XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable, - dst_bitmap->gc, src_x, src_y, width, height, dst_x, dst_y); -#endif + sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, + dst_x, dst_y, BLIT_OPAQUE); } -inline void DrawRectangle(Bitmap *bitmap, int x, int y, int width, int height, +inline void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height, Pixel color) { if (DrawingDeactivated(x, y, width, height)) return; -#ifdef TARGET_SDL - SDLFillRectangle(bitmap, x, y, width, height, color); -#else - XSetForeground(display, bitmap->gc, color); - XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height); - XSetForeground(display, bitmap->gc, BlackPixel(display, screen)); -#endif + sysFillRectangle(bitmap, x, y, width, height, color); } -#if 1 -inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height) -{ -#ifdef TARGET_SDL - DrawRectangle(bitmap, x, y, width, height, 0x000000); -#else - DrawRectangle(bitmap, x, y, width, height, 0x000000); -#endif -} -#else inline void ClearRectangle(Bitmap *bitmap, int x, int y, int width, int height) { - if (DrawingDeactivated(x, y, width, height)) - return; - -#ifdef TARGET_SDL - SDLFillRectangle(bitmap, x, y, width, height, 0x000000); -#else - XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height); -#endif + FillRectangle(bitmap, x, y, width, height, BlackPixel(display, screen)); } -#endif inline void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y, int width, int height) @@ -571,13 +564,8 @@ inline void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap, if (DrawingDeactivated(dst_x, dst_y, width, height)) return; -#ifdef TARGET_SDL - SDLCopyArea(src_bitmap, dst_bitmap, - src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_MASKED); -#else - XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable, - src_bitmap->clip_gc, src_x, src_y, width, height, dst_x, dst_y); -#endif + sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, + dst_x, dst_y, BLIT_MASKED); } inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap, @@ -610,7 +598,6 @@ inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y, #else XSetForeground(display, bitmap->gc, WhitePixel(display, screen)); XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y); - XSetForeground(display, bitmap->gc, BlackPixel(display, screen)); #endif } @@ -663,9 +650,6 @@ inline void DrawLines(Bitmap *bitmap, struct XY *points, int num_points, XSetForeground(display, bitmap->line_gc[1], pixel); XDrawLines(display, bitmap->drawable, bitmap->line_gc[1], (XPoint *)points, num_points, CoordModeOrigin); - /* - XSetForeground(display, gc, BlackPixel(display, screen)); - */ #endif } @@ -676,40 +660,20 @@ inline Pixel GetPixel(Bitmap *bitmap, int x, int y) #elif defined(TARGET_ALLEGRO) return AllegroGetPixel(bitmap->drawable, x, y); #else - unsigned long pixel_value; - XImage *pixel_image; - - pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1, - AllPlanes, ZPixmap); - pixel_value = XGetPixel(pixel_image, 0, 0); - - XDestroyImage(pixel_image); - - return pixel_value; + return X11GetPixel(bitmap, x, y); #endif } inline Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r, unsigned int color_g, unsigned int color_b) { - Pixel pixel; - #if defined(TARGET_SDL) - pixel = SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b); + return SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b); #elif defined(TARGET_ALLEGRO) - pixel = AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8); -#elif defined(TARGET_X11_NATIVE) - XColor xcolor; - - xcolor.flags = DoRed | DoGreen | DoBlue; - xcolor.red = (color_r << 8); - xcolor.green = (color_g << 8); - xcolor.blue = (color_b << 8); - XAllocColor(display, cmap, &xcolor); - pixel = xcolor.pixel; + return AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8); +#else + return X11GetPixelFromRGB(color_r, color_g, color_b); #endif - - return pixel; } inline Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color) diff --git a/src/libgame/system.h b/src/libgame/system.h index c5afeada..955be708 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -40,6 +40,9 @@ #define DEFAULT_DEPTH 0 +#define BLIT_OPAQUE 0 +#define BLIT_MASKED 1 + #define FULLSCREEN_NOT_AVAILABLE FALSE #define FULLSCREEN_AVAILABLE TRUE @@ -654,7 +657,7 @@ inline Bitmap *CreateBitmapStruct(void); inline Bitmap *CreateBitmap(int, int, int); inline void FreeBitmap(Bitmap *); inline void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int); -inline void DrawRectangle(Bitmap *, int, int, int, int, Pixel); +inline void FillRectangle(Bitmap *, int, int, int, int, Pixel); inline void ClearRectangle(Bitmap *, int, int, int, int); inline void ClearRectangleOnBackground(Bitmap *, int, int, int, int); inline void SetClipMask(Bitmap *, GC, Pixmap); diff --git a/src/libgame/text.c b/src/libgame/text.c index 61800916..29f558f4 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -168,7 +168,7 @@ void DrawInitText(char *text, int ypos, int font_nr) ClearRectangle(window, 0, ypos, video.width, getFontHeight(font_nr)); DrawTextExt(window, (video.width - text_width) / 2, ypos, text, font_nr, - FONT_OPAQUE); + BLIT_OPAQUE); FlushDisplay(); } } @@ -206,10 +206,10 @@ void DrawTextF(int x, int y, int font_nr, char *format, ...) void DrawText(int x, int y, char *text, int font_nr) { - int mask_mode = FONT_OPAQUE; + int mask_mode = BLIT_OPAQUE; if (DrawingOnBackground(x, y)) - mask_mode = FONT_MASKED; + mask_mode = BLIT_MASKED; DrawTextExt(drawto, x, y, text, font_nr, mask_mode); @@ -261,22 +261,8 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, else if (c == '\\') /* bad luck ... */ c = '/'; -#if 1 if (getFontChar(font_nr, c, &src_x, &src_y)) { -#else - if ((c >= 32 && c <= 95) || c == '°' || c == '´' || c == '|') - { - int src_x= font->src_x + ((c - 32) % FONT_CHARS_PER_LINE) * font->width; - int src_y= font->src_y + ((c - 32) / FONT_CHARS_PER_LINE) * font->height; - - if (c == '°' || c == '´' || c == '|') /* map '°' and 'TM' signs */ - { - src_x = font->src_x + FONT_CHARS_PER_LINE * font->width; - src_y = font->src_y + (c == '°' ? 1 : c == '´' ? 2 : 3) * font->height; - } -#endif - if (print_inverse) /* special mode for text gadgets */ { /* first step: draw solid colored rectangle (use "cursor" character) */ @@ -292,7 +278,7 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, BlitBitmapMasked(font->bitmap, dst_bitmap, 0, 0, font->width, font->height, dst_x, dst_y); } - else if (mask_mode == FONT_MASKED) + else if (mask_mode == BLIT_MASKED) { /* clear font character background */ ClearRectangleOnBackground(dst_bitmap, dst_x, dst_y, diff --git a/src/libgame/text.h b/src/libgame/text.h index c1915d47..39e9b2f2 100644 --- a/src/libgame/text.h +++ b/src/libgame/text.h @@ -32,9 +32,6 @@ #define FONT_CHARS_PER_LINE 16 #define FONT_LINES_PER_FONT 4 -#define FONT_OPAQUE 0 -#define FONT_MASKED 1 - /* text output definitions */ #define MAX_OUTPUT_LINESIZE 1024 diff --git a/src/libgame/x11.c b/src/libgame/x11.c index 6f14c37f..f93b2cdb 100644 --- a/src/libgame/x11.c +++ b/src/libgame/x11.c @@ -327,4 +327,51 @@ Bitmap *X11LoadImage(char *filename) return new_bitmap; } +inline void X11CopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y, int mask_mode) +{ + XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable, + (mask_mode == BLIT_MASKED ? src_bitmap->clip_gc : dst_bitmap->gc), + src_x, src_y, width, height, dst_x, dst_y); +} + +inline void X11FillRectangle(Bitmap *bitmap, int x, int y, + int width, int height, Pixel color) +{ + XSetForeground(display, bitmap->gc, color); + XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height); +} + +inline Pixel X11GetPixel(Bitmap *bitmap, int x, int y) +{ + unsigned long pixel_value; + XImage *pixel_image; + + pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1, + AllPlanes, ZPixmap); + pixel_value = XGetPixel(pixel_image, 0, 0); + + XDestroyImage(pixel_image); + + return pixel_value; +} + +inline Pixel X11GetPixelFromRGB(unsigned int color_r, unsigned int color_g, + unsigned int color_b) +{ + XColor xcolor; + Pixel pixel; + + xcolor.flags = DoRed | DoGreen | DoBlue; + xcolor.red = (color_r << 8); + xcolor.green = (color_g << 8); + xcolor.blue = (color_b << 8); + + XAllocColor(display, cmap, &xcolor); + pixel = xcolor.pixel; + + return pixel; +} + #endif /* TARGET_X11 */ diff --git a/src/libgame/x11.h b/src/libgame/x11.h index 3db9bae3..b0a50365 100644 --- a/src/libgame/x11.h +++ b/src/libgame/x11.h @@ -306,7 +306,11 @@ inline void X11InitVideoDisplay(void); inline void X11InitVideoBuffer(DrawBuffer **, DrawWindow **); void X11ZoomBitmap(Bitmap *, Bitmap *); - Bitmap *X11LoadImage(char *); +inline void X11CopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int); +inline void X11FillRectangle(Bitmap *, int, int, int, int, Pixel); +inline Pixel X11GetPixel(Bitmap *, int, int); +inline Pixel X11GetPixelFromRGB(unsigned int, unsigned int, unsigned int); + #endif /* X11_H */ diff --git a/src/tools.c b/src/tools.c index 412363a6..f0db2696 100644 --- a/src/tools.c +++ b/src/tools.c @@ -278,7 +278,7 @@ void BackToFront() info1[0] = '\0'; sprintf(text, "%.1f fps%s", global.frames_per_second, info1); - DrawTextExt(window, SX, SY, text, FONT_TEXT_2, FONT_OPAQUE); + DrawTextExt(window, SX, SY, text, FONT_TEXT_2, BLIT_OPAQUE); } FlushDisplay();