From 27a283729bf1e7b956c5ceba87215a6d177b4bc7 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 4 Apr 2003 02:14:41 +0200 Subject: [PATCH] rnd-20030404-3-src --- Makefile | 4 ++-- src/conftime.h | 2 +- src/libgame/gadgets.c | 27 +++++++++++++++++------ src/libgame/gadgets.h | 5 +++-- src/libgame/sdl.c | 28 ++++++++++++++++++++++-- src/libgame/sdl.h | 2 ++ src/libgame/system.c | 50 +++++++++++++++++++++---------------------- src/libgame/system.h | 1 + src/libgame/text.c | 16 ++++++++++++++ src/libgame/text.h | 5 +++-- 10 files changed, 100 insertions(+), 40 deletions(-) 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 a94a173e..695cc5da 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-04-04 01:21]" +#define COMPILE_DATE_STRING "[2003-04-04 02:13]" diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 90d7087a..0058bf18 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -172,6 +172,8 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) cursor_string[1] = (cursor_letter != '\0' ? cursor_letter : ' '); cursor_string[2] = '\0'; + SetInverseTextColor(gi->text.inverse_color); + /* draw cursor, if active */ if (pressed) DrawTextExt(drawto, @@ -328,11 +330,13 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->selectbox.x + border, gi->selectbox.y + border + i * font_height, gi->selectbox.width - 2 * border, font_height, - gi->selectbox.reverse_color); + gi->selectbox.inverse_color); text[0] = '~'; strncpy(&text[1], gi->selectbox.values[i], gi->selectbox.size); text[1 + gi->selectbox.size] = '\0'; + + SetInverseTextColor(gi->selectbox.inverse_color); } else { @@ -746,12 +750,23 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) if (gi->type & GD_TYPE_TEXTINPUT) { - int font_width = getFontWidth(gi->text.font_type); - int font_height = getFontHeight(gi->text.font_type); + int font_nr = gi->text.font_type; + int font_bitmap_id = gfx.select_font_function(font_nr); + struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id]; + int font_width = getFontWidth(font_nr); + int font_height = getFontHeight(font_nr); int border_size = gi->border.size; + int src_x, src_y; gi->width = 2 * border_size + (gi->text.size + 1) * font_width; gi->height = 2 * border_size + font_height; + + if (!getFontChar(font_nr, '|', &src_x, &src_y)) + Error(ERR_EXIT, "text input gadget incomplete (cannot get cursor)"); + + src_x += font_width / 2; + src_y += font_height / 2; + gi->text.inverse_color = GetPixel(font->bitmap, src_x, src_y); } if (gi->type & GD_TYPE_SELECTBOX) @@ -759,8 +774,8 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) int font_nr = gi->selectbox.font_type; int font_bitmap_id = gfx.select_font_function(font_nr); struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id]; - int font_width = getFontWidth(gi->selectbox.font_type); - int font_height = getFontHeight(gi->selectbox.font_type); + int font_width = getFontWidth(font_nr); + int font_height = getFontHeight(font_nr); int border_size = gi->border.size; int button_size = gi->border.size_selectbutton; int src_x, src_y; @@ -792,7 +807,7 @@ static void HandleGadgetTags(struct GadgetInfo *gi, int first_tag, va_list ap) src_x += font_width / 2; src_y += font_height / 2; - gi->selectbox.reverse_color = GetPixel(font->bitmap, src_x, src_y); + gi->selectbox.inverse_color = GetPixel(font->bitmap, src_x, src_y); /* always start with closed selectbox */ gi->selectbox.open = FALSE; diff --git a/src/libgame/gadgets.h b/src/libgame/gadgets.h index 4ee06dbb..ab8e9143 100644 --- a/src/libgame/gadgets.h +++ b/src/libgame/gadgets.h @@ -144,8 +144,9 @@ struct GadgetTextInput int number_min; /* minimal allowed numeric value */ int number_max; /* maximal allowed numeric value */ int size; /* maximal size of input text */ - int cursor_position; /* actual cursor position */ int font_type; /* font to use for text input */ + int cursor_position; /* actual cursor position */ + Pixel inverse_color; /* color for highlighting */ }; struct GadgetSelectbox @@ -159,7 +160,7 @@ struct GadgetSelectbox int x, y; /* open selectbox position */ int width, height; /* open selectbox size */ int num_values; /* number of text strings */ - Pixel reverse_color; /* color for highlighting */ + Pixel inverse_color; /* color for highlighting */ /* runtime values */ boolean open; /* opening state of selectbox */ diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 9403b2a7..24064895 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -548,9 +548,9 @@ void sge_PutPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color) } void sge_PutPixelRGB(SDL_Surface *surface, Sint16 x, Sint16 y, - Uint8 R, Uint8 G, Uint8 B) + Uint8 r, Uint8 g, Uint8 b) { - sge_PutPixel(surface, x, y, SDL_MapRGB(surface->format, R, G, B)); + sge_PutPixel(surface, x, y, SDL_MapRGB(surface->format, r, g, b)); } Sint32 sge_CalcYPitch(SDL_Surface *dest, Sint16 y) @@ -865,6 +865,30 @@ void sge_LineRGB(SDL_Surface *Surface, Sint16 x1, Sint16 y1, Sint16 x2, } +/* + ----------------------------------------------------------------------------- + quick (no, it's slow) and dirty hack to "invert" rectangle inside SDL surface + ----------------------------------------------------------------------------- +*/ + +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 (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); + } + } +} + + /* ========================================================================= */ /* The following functions were taken from the SDL_gfx library version 2.0.3 */ /* (Rotozoomer) by Andreas Schiffler */ diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 81eb7c6a..e214879b 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -332,6 +332,8 @@ inline void SDLDrawSimpleLine(Bitmap *, int, int, int, int, Uint32); inline void SDLDrawLine(Bitmap *, int, int, int, int, Uint32); inline Pixel SDLGetPixel(Bitmap *, int, int); +inline void SDLInvertArea(Bitmap *, int, int, int, int, Uint32); + void SDLZoomBitmap(Bitmap *, Bitmap *); Bitmap *SDLLoadImage(char *); diff --git a/src/libgame/system.c b/src/libgame/system.c index 0e0bb333..290b92a4 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -275,7 +275,7 @@ inline static int GetRealDepth(int depth) inline static void sysFillRectangle(Bitmap *bitmap, int x, int y, int width, int height, Pixel color) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDLFillRectangle(bitmap, x, y, width, height, color); #else X11FillRectangle(bitmap, x, y, width, height, color); @@ -286,12 +286,12 @@ 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); +#if defined(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); + X11CopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, + dst_x, dst_y, mask_mode); #endif } @@ -326,7 +326,7 @@ inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, video.fullscreen_available = FULLSCREEN_STATUS; video.fullscreen_enabled = FALSE; -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDLInitVideoBuffer(backbuffer, window, fullscreen); #else X11InitVideoBuffer(backbuffer, window); @@ -335,7 +335,7 @@ inline void InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, inline Bitmap *CreateBitmapStruct(void) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) return checked_calloc(sizeof(struct SDLSurfaceInfo)); #else return checked_calloc(sizeof(struct X11DrawableInfo)); @@ -347,7 +347,7 @@ inline Bitmap *CreateBitmap(int width, int height, int depth) Bitmap *new_bitmap = CreateBitmapStruct(); int real_depth = GetRealDepth(depth); -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDLCreateBitmapContent(new_bitmap, width, height, real_depth); #else X11CreateBitmapContent(new_bitmap, width, height, real_depth); @@ -364,7 +364,7 @@ inline static void FreeBitmapPointers(Bitmap *bitmap) if (bitmap == NULL) return; -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDLFreeBitmapPointers(bitmap); #else X11FreeBitmapPointers(bitmap); @@ -398,7 +398,7 @@ inline void FreeBitmap(Bitmap *bitmap) inline void CloseWindow(DrawWindow *window) { -#ifdef TARGET_X11 +#if defined(TARGET_X11) if (window->drawable) { XUnmapWindow(display, window->drawable); @@ -483,7 +483,7 @@ static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */ inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap) { -#ifdef TARGET_X11 +#if defined(TARGET_X11) if (clip_gc) { bitmap->clip_gc = clip_gc; @@ -497,7 +497,7 @@ inline void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap) inline void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y) { -#ifdef TARGET_X11 +#if defined(TARGET_X11) if (clip_gc) { bitmap->clip_gc = clip_gc; @@ -546,7 +546,7 @@ inline void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap, inline void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y, int to_x, int to_y) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL); #else X11DrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL); @@ -655,7 +655,7 @@ inline void SyncDisplay(void) inline void KeyboardAutoRepeatOn(void) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2, SDL_DEFAULT_REPEAT_INTERVAL / 2); SDL_EnableUNICODE(1); @@ -667,7 +667,7 @@ inline void KeyboardAutoRepeatOn(void) inline void KeyboardAutoRepeatOff(void) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableUNICODE(0); #else @@ -678,7 +678,7 @@ inline void KeyboardAutoRepeatOff(void) inline boolean PointerInWindow(DrawWindow *window) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) return TRUE; #else Window root, child; @@ -695,7 +695,7 @@ inline boolean PointerInWindow(DrawWindow *window) inline boolean SetVideoMode(boolean fullscreen) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) return SDLSetVideoMode(&backbuffer, fullscreen); #else boolean success = TRUE; @@ -716,7 +716,7 @@ inline boolean SetVideoMode(boolean fullscreen) inline boolean ChangeVideoModeIfNeeded(boolean fullscreen) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)|| (!fullscreen && video.fullscreen_enabled)) fullscreen = SetVideoMode(fullscreen); @@ -833,7 +833,7 @@ void CreateBitmapWithSmallBitmaps(Bitmap *src_bitmap) FreeBitmap(tmp_bitmap_2); FreeBitmap(tmp_bitmap_8); -#ifdef TARGET_SDL +#if defined(TARGET_SDL) src_bitmap->surface = tmp_bitmap->surface; tmp_bitmap->surface = NULL; #else @@ -907,7 +907,7 @@ inline void SetAudioMode(boolean enabled) inline void InitEventFilter(EventFilter filter_function) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) /* set event filter to filter out certain events */ SDL_SetEventFilter(filter_function); #endif @@ -915,7 +915,7 @@ inline void InitEventFilter(EventFilter filter_function) inline boolean PendingEvent(void) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) return (SDL_PollEvent(NULL) ? TRUE : FALSE); #else return (XPending(display) ? TRUE : FALSE); @@ -924,7 +924,7 @@ inline boolean PendingEvent(void) inline void NextEvent(Event *event) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) SDLNextEvent(event); #else XNextEvent(display, event); @@ -933,7 +933,7 @@ inline void NextEvent(Event *event) inline Key GetEventKey(KeyEvent *event, boolean with_modifiers) { -#ifdef TARGET_SDL +#if defined(TARGET_SDL) #if 0 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n", (int)event->keysym.unicode, @@ -986,7 +986,7 @@ inline void InitJoysticks() { int i; -#ifdef NO_JOYSTICK +#if defined(NO_JOYSTICK) return; /* joysticks generally deactivated by compile-time directive */ #endif diff --git a/src/libgame/system.h b/src/libgame/system.h index 955be708..af31de3f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -339,6 +339,7 @@ struct GfxInfo int num_fonts; struct FontBitmapInfo *font_bitmap_info; int (*select_font_function)(int); + Pixel inverse_text_color; int anim_random_frame; }; diff --git a/src/libgame/text.c b/src/libgame/text.c index 29f558f4..e21acc03 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -115,12 +115,18 @@ void InitFontInfo(struct FontBitmapInfo *font_bitmap_info, int num_fonts, gfx.num_fonts = num_fonts; gfx.font_bitmap_info = font_bitmap_info; gfx.select_font_function = select_font_function; + gfx.inverse_text_color = WHITE_PIXEL; #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) InitFontClipmasks(); #endif } +void SetInverseTextColor(Pixel inverse_text_color) +{ + gfx.inverse_text_color = inverse_text_color; +} + int getFontWidth(int font_nr) { int font_bitmap_id = gfx.select_font_function(font_nr); @@ -265,6 +271,15 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, { if (print_inverse) /* special mode for text gadgets */ { +#if defined(TARGET_SDL) + /* blit normally (non-masked) */ + BlitBitmap(font->bitmap, dst_bitmap, src_x, src_y, + font->width, font->height, dst_x, dst_y); + + /* invert character */ + SDLInvertArea(dst_bitmap, dst_x, dst_y, font->width, font->height, + gfx.inverse_text_color); +#else /* first step: draw solid colored rectangle (use "cursor" character) */ if (print_inverse_cursor) BlitBitmap(font->bitmap, dst_bitmap, @@ -277,6 +292,7 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, dst_x - src_x, dst_y - src_y); BlitBitmapMasked(font->bitmap, dst_bitmap, 0, 0, font->width, font->height, dst_x, dst_y); +#endif } else if (mask_mode == BLIT_MASKED) { diff --git a/src/libgame/text.h b/src/libgame/text.h index 39e9b2f2..f506b940 100644 --- a/src/libgame/text.h +++ b/src/libgame/text.h @@ -37,8 +37,9 @@ /* font structure definitions */ -void InitFontInfo(struct FontBitmapInfo *, int, - int (*select_font_function)(int)); +void InitFontInfo(struct FontBitmapInfo *, int, int (*function)(int)); +void SetInverseTextColor(Pixel); + int getFontWidth(int); int getFontHeight(int); boolean getFontChar(int, char, int *, int *); -- 2.34.1