From 621b6a2c4781c9c3e2f5849f9c184a906e0ce5b6 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 3 Dec 2000 04:36:21 +0100 Subject: [PATCH] rnd-20001203-1-src --- src/cartoons.c | 8 +- src/editor.c | 16 ++-- src/game.c | 22 ++--- src/init.c | 65 ++++++++------- src/libgame/msdos.c | 3 +- src/libgame/sdl.c | 29 ++++--- src/libgame/sdl.h | 22 +++-- src/libgame/system.c | 191 +++++++++++++++++++++++++++++++------------ src/libgame/system.h | 87 +++++++++++++++----- src/libgame/text.c | 63 +++++++++----- src/libgame/text.h | 45 +++++++++- src/libgame/x11.c | 27 +++--- src/libgame/x11.h | 18 +++- src/main.c | 24 +++++- src/main.h | 32 +++++++- src/screens.c | 10 +-- src/tools.c | 86 +++++++++---------- src/tools.h | 4 +- 18 files changed, 514 insertions(+), 238 deletions(-) diff --git a/src/cartoons.c b/src/cartoons.c index b3a639a3..c2c0fea6 100644 --- a/src/cartoons.c +++ b/src/cartoons.c @@ -398,8 +398,8 @@ boolean AnimateToon(int toon_nr, boolean restart) }; struct AnimInfo *anim = &toon[toon_nr]; int anim_bitmap_nr = (toon_nr < 6 ? PIX_TOONS : PIX_HEROES); - Bitmap anim_bitmap = pix_masked[anim_bitmap_nr]; - GC anim_clip_gc = clip_gc[anim_bitmap_nr]; + Bitmap anim_bitmap = pix[anim_bitmap_nr]; + GC anim_clip_gc = pix[anim_bitmap_nr]->stored_clip_gc; if (restart) { @@ -541,7 +541,7 @@ void DrawAnim(Bitmap toon_bitmap, GC toon_clip_gc, /* special method to avoid flickering interference with BackToFront() */ BlitBitmap(backbuffer, pix[PIX_DB_DOOR], dest_x-pad_x, dest_y-pad_y, width+2*pad_x, height+2*pad_y, buf_x, buf_y); - SetClipOrigin(toon_clip_gc, dest_x-src_x, dest_y-src_y); + SetClipOrigin(toon_bitmap, toon_clip_gc, dest_x-src_x, dest_y-src_y); BlitBitmapMasked(toon_bitmap, backbuffer, src_x, src_y, width, height, dest_x, dest_y); BlitBitmap(backbuffer, window, dest_x-pad_x, dest_y-pad_y, @@ -553,7 +553,7 @@ void DrawAnim(Bitmap toon_bitmap, GC toon_clip_gc, /* normal method, causing flickering interference with BackToFront() */ BlitBitmap(backbuffer, pix[PIX_DB_DOOR], dest_x-pad_x, dest_y-pad_y, width+2*pad_x, height+2*pad_y, buf_x, buf_y); - SetClipOrigin(toon_clip_gc, buf_x-src_x+pad_x, buf_y-src_y+pad_y); + SetClipOrigin(toon_bitmap,toon_clip_gc, buf_x-src_x+pad_x,buf_y-src_y+pad_y); BlitBitmapMasked(toon_bitmap, pix[PIX_DB_DOOR], src_x, src_y, width, height, buf_x+pad_x, buf_y+pad_y); BlitBitmap(pix[PIX_DB_DOOR], window, buf_x, buf_y, diff --git a/src/editor.c b/src/editor.c index 2ed164c1..f6bd6181 100644 --- a/src/editor.c +++ b/src/editor.c @@ -2134,13 +2134,13 @@ void DrawLevelEd() DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); /* draw mouse button brush elements */ - DrawMiniGraphicExt(drawto, gc, + DrawMiniGraphicExt(drawto, DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS, el2gfx(new_element1)); - DrawMiniGraphicExt(drawto, gc, + DrawMiniGraphicExt(drawto, DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS, el2gfx(new_element2)); - DrawMiniGraphicExt(drawto, gc, + DrawMiniGraphicExt(drawto, DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS, el2gfx(new_element3)); @@ -2313,21 +2313,21 @@ static void PickDrawingElement(int button, int element) if (button == 1) { new_element1 = element; - DrawMiniGraphicExt(drawto, gc, + DrawMiniGraphicExt(drawto, DX + ED_WIN_MB_LEFT_XPOS, DY + ED_WIN_MB_LEFT_YPOS, el2gfx(new_element1)); } else if (button == 2) { new_element2 = element; - DrawMiniGraphicExt(drawto, gc, + DrawMiniGraphicExt(drawto, DX + ED_WIN_MB_MIDDLE_XPOS, DY + ED_WIN_MB_MIDDLE_YPOS, el2gfx(new_element2)); } else { new_element3 = element; - DrawMiniGraphicExt(drawto, gc, + DrawMiniGraphicExt(drawto, DX + ED_WIN_MB_RIGHT_XPOS, DY + ED_WIN_MB_RIGHT_YPOS, el2gfx(new_element3)); } @@ -3451,11 +3451,11 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) } else { - DrawMiniGraphicExt(drawto, gc, + DrawMiniGraphicExt(drawto, gi->x + sx * MINI_TILEX, gi->y + sy * MINI_TILEY, el2gfx(new_element)); - DrawMiniGraphicExt(window, gc, + DrawMiniGraphicExt(window, gi->x + sx * MINI_TILEX, gi->y + sy * MINI_TILEY, el2gfx(new_element)); diff --git a/src/game.c b/src/game.c index 1f39cd8f..3f95c2b0 100644 --- a/src/game.c +++ b/src/game.c @@ -730,7 +730,7 @@ void InitGame() int2str(level_nr, 2), FS_SMALL, FC_YELLOW); else { - DrawTextExt(drawto, gc, DX + XX_EMERALDS, DY + YY_EMERALDS, + DrawTextExt(drawto, DX + XX_EMERALDS, DY + YY_EMERALDS, int2str(level_nr, 3), FS_SMALL, FC_SPECIAL3); BlitBitmap(drawto, drawto, DX + XX_EMERALDS, DY + YY_EMERALDS + 1, @@ -5402,12 +5402,10 @@ int DigField(struct PlayerInfo *player, RemoveField(x, y); player->key[key_nr] = TRUE; RaiseScoreElement(EL_SCHLUESSEL); - DrawMiniGraphicExt(drawto, gc, - DX_KEYS+key_nr*MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1+key_nr); - DrawMiniGraphicExt(window, gc, - DX_KEYS+key_nr*MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1+key_nr); + DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, + GFX_SCHLUESSEL1 + key_nr); + DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, + GFX_SCHLUESSEL1 + key_nr); PlaySoundLevel(x, y, SND_PONG); break; } @@ -5422,12 +5420,10 @@ int DigField(struct PlayerInfo *player, RemoveField(x, y); player->key[key_nr] = TRUE; RaiseScoreElement(EL_SCHLUESSEL); - DrawMiniGraphicExt(drawto, gc, - DX_KEYS+key_nr*MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1+key_nr); - DrawMiniGraphicExt(window, gc, - DX_KEYS+key_nr*MINI_TILEX, DY_KEYS, - GFX_SCHLUESSEL1+key_nr); + DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, + GFX_SCHLUESSEL1 + key_nr); + DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, + GFX_SCHLUESSEL1 + key_nr); PlaySoundLevel(x, y, SND_PONG); break; } diff --git a/src/init.c b/src/init.c index 3a0c54ed..1c56fc0a 100644 --- a/src/init.c +++ b/src/init.c @@ -321,8 +321,6 @@ void InitDisplay() ICON_TITLE_STRING, x11_icon_filename, x11_iconmask_filename, msdos_pointer_filename); - InitScrollbufferSize(FXSIZE, FYSIZE); /* (only needed for MS-DOS code) */ - InitVideoDisplay(); InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen); @@ -422,12 +420,22 @@ void InitGfx() { -1, 0 } }; + /* initialize playfield properties */ + + InitPlayfieldInfo(SX, SY, SXSIZE, SYSIZE, + REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); + InitDoor1Info(DX, DY, DXSIZE, DYSIZE); + InitDoor2Info(VX, VY, VXSIZE, VYSIZE); + InitScrollbufferInfo(FXSIZE, FYSIZE); + /* create additional image buffers for double-buffering */ pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); LoadGfx(PIX_SMALLFONT, &pic[PIX_SMALLFONT]); + InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); + DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); #if defined(PLATFORM_MSDOS) @@ -440,6 +448,8 @@ void InitGfx() if (i != PIX_SMALLFONT) LoadGfx(i,&pic[i]); + InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]); + /* create additional image buffers for masking of graphics */ #if defined(TARGET_SDL) @@ -486,21 +496,23 @@ void InitGfx() clip_gc_values.graphics_exposures = False; clip_gc_valuemask = GCGraphicsExposures; copy_clipmask_gc = - XCreateGC(display, clipmask[PIX_BACK], clip_gc_valuemask, &clip_gc_values); + XCreateGC(display, pix[PIX_BACK]->clip_mask, + clip_gc_valuemask, &clip_gc_values); clip_gc_values.graphics_exposures = False; clip_gc_valuemask = GCGraphicsExposures; tile_clip_gc = - XCreateGC(display, window, clip_gc_valuemask, &clip_gc_values); + XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values); for(i=0; iclip_mask) { clip_gc_values.graphics_exposures = False; - clip_gc_values.clip_mask = clipmask[i]; + clip_gc_values.clip_mask = pix[i]->clip_mask; clip_gc_valuemask = GCGraphicsExposures | GCClipMask; - clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values); + pix[i]->stored_clip_gc = XCreateGC(display, window->drawable, + clip_gc_valuemask,&clip_gc_values); } } @@ -520,12 +532,13 @@ void InitGfx() Pixmap src_pixmap; getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y); - src_pixmap = clipmask[pixmap_nr]; + src_pixmap = pix[pixmap_nr]->clip_mask; - tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1); + tile_clipmask[tile] = XCreatePixmap(display, window->drawable, + TILEX, TILEY, 1); - XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc, - src_x,src_y, TILEX,TILEY, 0,0); + XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc, + src_x, src_y, TILEX, TILEY, 0, 0); } } @@ -575,6 +588,8 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) rest(100); #endif + pix[pos] = CreateBitmapStruct(); + #if defined(TARGET_SDL) /* load image to temporary surface */ if ((sdl_image_tmp = IMG_Load(filename)) == NULL) @@ -595,8 +610,9 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) #else /* !TARGET_SDL */ - pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename, - &pix[pos], &clipmask[pos]); + pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, + filename, + &pix[pos]->drawable, &pix[pos]->clip_mask); switch(pcx_err) { case PCX_Success: @@ -615,19 +631,21 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) break; } - if (!pix[pos]) + if (!pix[pos]->drawable) Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename); +#if 0 /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always use pix_masked[], although they are the same when not using SDL */ pix_masked[pos] = pix[pos]; +#endif #endif /* !TARGET_SDL */ } #if defined(TARGET_X11) /* check if clip mask was correctly created */ - if (pic->picture_with_mask && !clipmask[pos]) + if (pic->picture_with_mask && !pix[pos]->clip_mask) Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); #endif } @@ -1806,25 +1824,16 @@ void CloseAllAndExit(int exit_value) #endif for(i=0; isurface_masked : src_bitmap->surface), + &src_rect, real_dst_bitmap->surface, &dst_rect); - if (dst_surface == window) - SDL_UpdateRect(backbuffer, dst_x, dst_y, width, height); + if (dst_bitmap == window) + SDL_UpdateRect(backbuffer->surface, dst_x, dst_y, width, height); } -inline void SDLFillRectangle(SDL_Surface *dst_surface, int x, int y, +inline void SDLFillRectangle(Bitmap dst_bitmap, int x, int y, int width, int height, unsigned int color) { - SDL_Surface *surface = (dst_surface == window ? backbuffer : dst_surface); + 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; @@ -155,11 +157,12 @@ inline void SDLFillRectangle(SDL_Surface *dst_surface, int x, int y, rect.w = width; rect.h = height; - SDL_FillRect(surface, &rect, - SDL_MapRGB(surface->format, color_r, color_g, color_b)); + SDL_FillRect(real_dst_bitmap->surface, &rect, + SDL_MapRGB(real_dst_bitmap->surface->format, + color_r, color_g, color_b)); - if (dst_surface == window) - SDL_UpdateRect(backbuffer, x, y, width, height); + if (dst_bitmap == window) + SDL_UpdateRect(backbuffer->surface, x, y, width, height); } inline void SDLDrawSimpleLine(SDL_Surface *surface, int from_x, int from_y, diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 768dc6fa..cc60462b 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -24,6 +24,8 @@ #define SURFACE_FLAGS (SDL_SWSURFACE) +#define SDLCOPYAREA_OPAQUE 0 +#define SDLCOPYAREA_MASKED 1 /* system dependent definitions */ @@ -31,11 +33,20 @@ #define FULLSCREEN_STATUS FULLSCREEN_AVAILABLE +/* structure definitions */ + +struct SDLSurfaceInfo +{ + SDL_Surface *surface; + SDL_Surface *surface_masked; +}; + + /* SDL type definitions */ -typedef SDL_Surface *Bitmap; -typedef SDL_Surface *DrawWindow; -typedef SDL_Surface *DrawBuffer; +typedef struct SDLSurfaceInfo *Bitmap; +typedef struct SDLSurfaceInfo *DrawBuffer; +typedef struct SDLSurfaceInfo *DrawWindow; typedef SDLKey Key; @@ -299,9 +310,8 @@ typedef int Colormap; inline void SDLInitVideoDisplay(void); inline void SDLInitVideoBuffer(DrawBuffer *, DrawWindow *, boolean); inline boolean SDLSetVideoMode(DrawBuffer *, boolean); -inline void SDLCopyArea(SDL_Surface *, SDL_Surface *, - int, int, int, int, int, int); -inline void SDLFillRectangle(SDL_Surface *, int, int, int, int, unsigned int); +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(SDL_Surface *, int, int, int, int, unsigned int); inline boolean SDLOpenAudio(void); diff --git a/src/libgame/system.c b/src/libgame/system.c index 3d26c3ce..fe32a073 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -14,41 +14,36 @@ #include "libgame.h" + /* ========================================================================= */ -/* internal variables */ +/* exported variables */ /* ========================================================================= */ +struct ProgramInfo program; +struct OptionInfo options; +struct VideoSystemInfo video; +struct AudioSystemInfo audio; +struct PlayfieldInfo playfield; + Display *display = NULL; Visual *visual = NULL; int screen = 0; Colormap cmap = None; -DrawWindow window = None; -DrawBuffer backbuffer = None; -GC gc = None; +DrawWindow window = NULL; +DrawBuffer backbuffer = NULL; +DrawBuffer drawto = NULL; -int FrameCounter = 0; +int redraw_mask; +int redraw_tiles; - -/* ========================================================================= */ -/* exported variables */ -/* ========================================================================= */ - -struct ProgramInfo program; -struct VideoSystemInfo video; -struct AudioSystemInfo audio; -struct OptionInfo options; +int FrameCounter = 0; /* ========================================================================= */ /* video functions */ /* ========================================================================= */ -inline static int GetRealDepth(int depth) -{ - return (depth == DEFAULT_DEPTH ? video.default_depth : depth); -} - inline void InitProgramInfo(char *command_name, char *program_title, char *window_title, char *icon_title, char *x11_icon_filename, @@ -64,12 +59,47 @@ inline void InitProgramInfo(char *command_name, char *program_title, program.msdos_pointer_filename = msdos_pointer_filename; } -inline void InitScrollbufferSize(int scrollbuffer_width, +inline void InitPlayfieldInfo(int sx, int sy, int sxsize, int sysize, + int real_sx, int real_sy, + int full_sxsize, int full_sysize) +{ + playfield.sx = sx; + playfield.sy = sy; + playfield.sxsize = sxsize; + playfield.sysize = sysize; + playfield.real_sx = real_sx; + playfield.real_sy = real_sy; + playfield.full_sxsize = full_sxsize; + playfield.full_sysize = full_sysize; +} + +inline void InitDoor1Info(int dx, int dy, int dxsize, int dysize) +{ + playfield.dx = dx; + playfield.dy = dy; + playfield.dxsize = dxsize; + playfield.dysize = dysize; +} + +inline void InitDoor2Info(int vx, int vy, int vxsize, int vysize) +{ + playfield.vx = vx; + playfield.vy = vy; + playfield.vxsize = vxsize; + playfield.vysize = vysize; +} + +inline void InitScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height) { /* currently only used by MSDOS code to alloc VRAM buffer, if available */ - video.scrollbuffer_width = scrollbuffer_width; - video.scrollbuffer_height = scrollbuffer_height; + playfield.scrollbuffer_width = scrollbuffer_width; + playfield.scrollbuffer_height = scrollbuffer_height; +} + +inline static int GetRealDepth(int depth) +{ + return (depth == DEFAULT_DEPTH ? video.default_depth : depth); } inline void InitVideoDisplay(void) @@ -98,8 +128,18 @@ inline void InitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window, #endif } +inline Bitmap CreateBitmapStruct(void) +{ +#ifdef TARGET_SDL + return checked_calloc(sizeof(struct SDLSurfaceInfo)); +#else + return checked_calloc(sizeof(struct X11DrawableInfo)); +#endif +} + inline Bitmap CreateBitmap(int width, int height, int depth) { + Bitmap new_bitmap = CreateBitmapStruct(); int real_depth = GetRealDepth(depth); #ifdef TARGET_SDL @@ -115,32 +155,56 @@ inline Bitmap CreateBitmap(int width, int height, int depth) SDL_FreeSurface(surface_tmp); - return surface_native; + new_bitmap->surface = surface_native; #else Pixmap pixmap; - if (!(pixmap = XCreatePixmap(display, window, width, height, real_depth))) + if (!(pixmap = XCreatePixmap(display, window->drawable, + width, height, real_depth))) Error(ERR_EXIT, "cannot create pixmap"); - return pixmap; + new_bitmap->drawable = pixmap; #endif + + if (window == NULL) + Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first"); + new_bitmap->gc = window->gc; + + return new_bitmap; } inline void FreeBitmap(Bitmap bitmap) { + if (bitmap == NULL) + return; + #ifdef TARGET_SDL - SDL_FreeSurface(bitmap); + if (bitmap->surface) + SDL_FreeSurface(bitmap->surface); + if (bitmap->surface_masked) + SDL_FreeSurface(bitmap->surface_masked); #else - XFreePixmap(display, bitmap); + if (bitmap->drawable) + XFreePixmap(display, bitmap->drawable); + if (bitmap->clip_mask) + XFreePixmap(display, bitmap->clip_mask); + if (bitmap->stored_clip_gc) + XFreeGC(display, bitmap->stored_clip_gc); #endif + + free(bitmap); } -inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height) +inline void CloseWindow(DrawWindow window) { -#ifdef TARGET_SDL - SDLFillRectangle(bitmap, x, y, width, height, 0x000000); -#else - XFillRectangle(display, bitmap, gc, x, y, width, height); +#ifdef TARGET_X11 + if (window->drawable) + { + XUnmapWindow(display, window->drawable); + XDestroyWindow(display, window->drawable); + } + if (window->gc) + XFreeGC(display, window->gc); #endif } @@ -151,31 +215,54 @@ inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap, { #ifdef TARGET_SDL SDLCopyArea(src_bitmap, dst_bitmap, - src_x, src_y, width, height, dst_x, dst_y); + 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 +} + +inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height) +{ +#ifdef TARGET_SDL + SDLFillRectangle(bitmap, x, y, width, height, 0x000000); #else - XCopyArea(display, src_bitmap, dst_bitmap, gc, - src_x, src_y, width, height, dst_x, dst_y); + XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height); #endif } +#if 0 #ifndef TARGET_SDL static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */ #endif +#endif -inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap) +inline void SetClipMask(Bitmap bitmap, GC clip_gc, Pixmap clip_pixmap) { -#ifndef TARGET_SDL - XSetClipMask(display, clip_gc, clip_pixmap); +#ifdef TARGET_X11 + if (clip_gc) + { + bitmap->clip_gc = clip_gc; + XSetClipMask(display, bitmap->clip_gc, clip_pixmap); + } +#if 0 last_clip_gc = clip_gc; #endif +#endif } -inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y) +inline void SetClipOrigin(Bitmap bitmap, GC clip_gc, int clip_x, int clip_y) { -#ifndef TARGET_SDL - XSetClipOrigin(display, clip_gc, clip_x, clip_y); +#ifdef TARGET_X11 + if (clip_gc) + { + bitmap->clip_gc = clip_gc; + XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y); + } +#if 0 last_clip_gc = clip_gc; #endif +#endif } inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap, @@ -185,10 +272,10 @@ inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap, { #ifdef TARGET_SDL SDLCopyArea(src_bitmap, dst_bitmap, - src_x, src_y, width, height, dst_x, dst_y); + src_x, src_y, width, height, dst_x, dst_y, SDLCOPYAREA_MASKED); #else - XCopyArea(display, src_bitmap, dst_bitmap, last_clip_gc, - src_x, src_y, width, height, dst_x, dst_y); + XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable, + src_bitmap->clip_gc, src_x, src_y, width, height, dst_x, dst_y); #endif } @@ -196,11 +283,11 @@ inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y, int to_x, int to_y) { #ifdef TARGET_SDL - SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff); + SDLDrawSimpleLine(bitmap->drawable, from_x, from_y, to_x, to_y, 0xffffff); #else - XSetForeground(display, gc, WhitePixel(display, screen)); - XDrawLine(display, bitmap, gc, from_x, from_y, to_x, to_y); - XSetForeground(display, gc, BlackPixel(display, screen)); + 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 } @@ -246,15 +333,15 @@ inline boolean PointerInWindow(DrawWindow window) #ifdef TARGET_SDL return TRUE; #else - DrawWindow root, child; + Window root, child; int root_x, root_y; unsigned int mask; int win_x, win_y; /* if XQueryPointer() returns False, the pointer is not on the same screen as the specified window */ - return XQueryPointer(display, window, &root, &child, &root_x, &root_y, - &win_x, &win_y, &mask); + return XQueryPointer(display, window->drawable, &root, &child, + &root_x, &root_y, &win_x, &win_y, &mask); #endif } @@ -404,7 +491,7 @@ inline boolean CheckCloseWindowEvent(ClientMessageEvent *event) #if defined(TARGET_SDL) return TRUE; /* the only possible message here is SDL_QUIT */ #elif defined(PLATFORM_UNIX) - if ((event->window == window) && + if ((event->window == window->drawable) && (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) return TRUE; #endif diff --git a/src/libgame/system.h b/src/libgame/system.h index 808f752d..25eb0c66 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -38,6 +38,30 @@ #define FULLSCREEN_AVAILABLE TRUE +/* values for redraw_mask */ +#define REDRAW_ALL (1 << 0) +#define REDRAW_FIELD (1 << 1) +#define REDRAW_TILES (1 << 2) +#define REDRAW_DOOR_1 (1 << 3) +#define REDRAW_VIDEO_1 (1 << 4) +#define REDRAW_VIDEO_2 (1 << 5) +#define REDRAW_VIDEO_3 (1 << 6) +#define REDRAW_MICROLEVEL (1 << 7) +#define REDRAW_FROM_BACKBUFFER (1 << 8) +#define REDRAW_DOOR_2 (REDRAW_VIDEO_1 | \ + REDRAW_VIDEO_2 | \ + REDRAW_VIDEO_3) +#define REDRAW_DOOR_3 (1 << 9) +#define REDRAW_DOORS (REDRAW_DOOR_1 | \ + REDRAW_DOOR_2 | \ + REDRAW_DOOR_3) +#define REDRAW_MAIN (REDRAW_FIELD | \ + REDRAW_TILES | \ + REDRAW_MICROLEVEL) +#define REDRAW_FPS (1 << 10) +#define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2) + + /* type definitions */ typedef int (*EventFilter)(const Event *); @@ -56,11 +80,24 @@ struct ProgramInfo char *msdos_pointer_filename; }; +struct OptionInfo +{ + char *display_name; + char *server_host; + int server_port; + char *ro_base_directory; + char *rw_base_directory; + char *level_directory; + boolean serveronly; + boolean network; + boolean verbose; + boolean debug; +}; + struct VideoSystemInfo { int default_depth; int width, height, depth; - int scrollbuffer_width, scrollbuffer_height; boolean fullscreen_available; boolean fullscreen_enabled; }; @@ -75,18 +112,19 @@ struct AudioSystemInfo int device_fd; }; -struct OptionInfo +struct PlayfieldInfo { - char *display_name; - char *server_host; - int server_port; - char *ro_base_directory; - char *rw_base_directory; - char *level_directory; - boolean serveronly; - boolean network; - boolean verbose; - boolean debug; + int sx, sy; + int sxsize, sysize; + int real_sx, real_sy; + int full_sxsize, full_sysize; + int scrollbuffer_width, scrollbuffer_height; + + int dx, dy; + int dxsize, dysize; + + int vx, vy; + int vxsize, vysize; }; @@ -95,12 +133,10 @@ struct OptionInfo /* ========================================================================= */ extern struct ProgramInfo program; +extern struct OptionInfo options; extern struct VideoSystemInfo video; extern struct AudioSystemInfo audio; -extern struct OptionInfo options; - - -/* declarations of internal variables */ +extern struct PlayfieldInfo playfield; extern Display *display; extern Visual *visual; @@ -109,7 +145,10 @@ extern Colormap cmap; extern DrawWindow window; extern DrawBuffer backbuffer; -extern GC gc; +extern DrawBuffer drawto; + +extern int redraw_mask; +extern int redraw_tiles; extern int FrameCounter; @@ -118,15 +157,21 @@ extern int FrameCounter; inline void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *); -inline void InitScrollbufferSize(int, int); + +inline void InitPlayfieldInfo(int, int, int, int, int, int, int, int); +inline void InitDoor1Info(int, int, int, int); +inline void InitDoor2Info(int, int, int, int); +inline void InitScrollbufferInfo(int, int); + inline void InitVideoDisplay(void); inline void InitVideoBuffer(DrawBuffer *,DrawWindow *, int, int, int, boolean); +inline Bitmap CreateBitmapStruct(void); inline Bitmap CreateBitmap(int, int, int); inline void FreeBitmap(Bitmap); -inline void ClearRectangle(Bitmap, int, int, int, int); inline void BlitBitmap(Bitmap, Bitmap, int, int, int, int, int, int); -inline void SetClipMask(GC, Pixmap); -inline void SetClipOrigin(GC, int, int); +inline void ClearRectangle(Bitmap, int, int, int, int); +inline void SetClipMask(Bitmap, GC, Pixmap); +inline void SetClipOrigin(Bitmap, GC, int, int); inline void BlitBitmapMasked(Bitmap, Bitmap, int, int, int, int, int, int); inline void DrawSimpleWhiteLine(Bitmap, int, int, int, int); inline void FlushDisplay(void); diff --git a/src/libgame/text.c b/src/libgame/text.c index 28f88c56..513166fd 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -15,7 +15,29 @@ #include "libgame.h" +#if 1 #include "main_TMP.h" +#endif + + +/* ========================================================================= */ +/* exported variables */ +/* ========================================================================= */ + +struct FontInfo font; + + +/* ========================================================================= */ +/* font functions */ +/* ========================================================================= */ + +void InitFontInfo(Bitmap bitmap_big, Bitmap bitmap_medium, + Bitmap bitmap_small) +{ + font.bitmap_big = bitmap_big; + font.bitmap_medium = bitmap_medium; + font.bitmap_small = bitmap_small; +} int getFontWidth(int font_size, int font_type) { @@ -39,10 +61,10 @@ int getFontHeight(int font_size, int font_type) void DrawInitText(char *text, int ypos, int color) { - if (window && pix[PIX_SMALLFONT]) + if (window && font.bitmap_small) { - ClearRectangle(window, 0, ypos, WIN_XSIZE, FONT2_YSIZE); - DrawTextExt(window, gc, (WIN_XSIZE - strlen(text) * FONT2_XSIZE)/2, + ClearRectangle(window, 0, ypos, video.width, FONT2_YSIZE); + DrawTextExt(window, (video.width - strlen(text) * FONT2_XSIZE)/2, ypos, text, FS_SMALL, color); FlushDisplay(); } @@ -50,7 +72,7 @@ void DrawInitText(char *text, int ypos, int color) void DrawTextFCentered(int y, int font_type, char *format, ...) { - char buffer[FULL_SXSIZE / FONT5_XSIZE + 10]; + char buffer[MAX_OUTPUT_LINESIZE + 1]; int font_width = getFontWidth(FS_SMALL, font_type); va_list ap; @@ -58,37 +80,37 @@ void DrawTextFCentered(int y, int font_type, char *format, ...) vsprintf(buffer, format, ap); va_end(ap); - DrawText(SX + (SXSIZE - strlen(buffer) * font_width) / 2, SY + y, - buffer, FS_SMALL, font_type); + DrawText(playfield.sx + (playfield.sxsize - strlen(buffer) * font_width) / 2, + playfield.sy + y, buffer, FS_SMALL, font_type); } void DrawTextF(int x, int y, int font_type, char *format, ...) { - char buffer[FULL_SXSIZE / FONT5_XSIZE + 10]; + char buffer[MAX_OUTPUT_LINESIZE + 1]; va_list ap; va_start(ap, format); vsprintf(buffer, format, ap); va_end(ap); - DrawText(SX + x, SY + y, buffer, FS_SMALL, font_type); + DrawText(playfield.sx + x, playfield.sy + y, buffer, FS_SMALL, font_type); } void DrawText(int x, int y, char *text, int font_size, int font_type) { - DrawTextExt(drawto, gc, x, y, text, font_size, font_type); + DrawTextExt(drawto, x, y, text, font_size, font_type); - if (x < DX) + if (x < playfield.dx) redraw_mask |= REDRAW_FIELD; - else if (y < VY) + else if (y < playfield.vy) redraw_mask |= REDRAW_DOOR_1; } -void DrawTextExt(DrawBuffer d, GC gc, int x, int y, +void DrawTextExt(DrawBuffer bitmap, int x, int y, char *text, int font_size, int font_type) { + Bitmap font_bitmap; int font_width, font_height, font_start; - int font_bitmap; boolean print_inverse = FALSE; if (font_size != FS_SMALL && font_size != FS_BIG && font_size != FS_MEDIUM) @@ -99,9 +121,9 @@ void DrawTextExt(DrawBuffer d, GC gc, int x, int y, font_width = getFontWidth(font_size, font_type); font_height = getFontHeight(font_size, font_type); - font_bitmap = (font_size == FS_BIG ? PIX_BIGFONT : - font_size == FS_MEDIUM ? PIX_MEDIUMFONT : - PIX_SMALLFONT); + font_bitmap = (font_size == FS_BIG ? font.bitmap_big : + font_size == FS_MEDIUM ? font.bitmap_medium : + font.bitmap_small); font_start = (font_type * (font_size == FS_BIG ? FONT1_YSIZE : font_size == FS_MEDIUM ? FONT6_YSIZE : FONT2_YSIZE) * @@ -137,17 +159,18 @@ void DrawTextExt(DrawBuffer d, GC gc, int x, int y, if (print_inverse) { - BlitBitmap(pix[font_bitmap], d, + BlitBitmap(font_bitmap, bitmap, FONT_CHARS_PER_LINE * font_width, 3 * font_height + font_start, font_width, font_height, x, y); - SetClipOrigin(clip_gc[font_bitmap], dest_x - src_x, dest_y - src_y); - BlitBitmapMasked(pix_masked[font_bitmap], d, + SetClipOrigin(font_bitmap, font_bitmap->stored_clip_gc, + dest_x - src_x, dest_y - src_y); + BlitBitmapMasked(font_bitmap, bitmap, 0, 0, font_width, font_height, dest_x, dest_y); } else - BlitBitmap(pix[font_bitmap], d, + BlitBitmap(font_bitmap, bitmap, src_x, src_y, font_width, font_height, dest_x, dest_y); } diff --git a/src/libgame/text.h b/src/libgame/text.h index 57fa7e13..4aee0437 100644 --- a/src/libgame/text.h +++ b/src/libgame/text.h @@ -16,12 +16,55 @@ #include "libgame.h" +/* font types */ +#define FS_SMALL 0 +#define FS_BIG 1 +#define FS_MEDIUM 2 + +/* font colors */ +#define FC_RED 0 +#define FC_BLUE 1 +#define FC_GREEN 2 +#define FC_YELLOW 3 +#define FC_SPECIAL1 4 +#define FC_SPECIAL2 5 +#define FC_SPECIAL3 6 + +/* font graphics definitions */ +#define FONT1_XSIZE 32 +#define FONT1_YSIZE 32 +#define FONT2_XSIZE 14 +#define FONT2_YSIZE 14 +#define FONT3_XSIZE 11 +#define FONT3_YSIZE 14 +#define FONT4_XSIZE 16 +#define FONT4_YSIZE 16 +#define FONT5_XSIZE 10 +#define FONT5_YSIZE 14 +#define FONT6_XSIZE 16 +#define FONT6_YSIZE 32 + +#define FONT_CHARS_PER_LINE 16 +#define FONT_LINES_PER_FONT 4 + +/* text output definitions */ +#define MAX_OUTPUT_LINESIZE 256 + +/* font structure definitions */ + +struct FontInfo +{ + Bitmap bitmap_big, bitmap_medium, bitmap_small; +}; + + +void InitFontInfo(Bitmap, Bitmap, Bitmap); int getFontWidth(int, int); int getFontHeight(int, int); void DrawInitText(char *, int, int); void DrawTextF(int, int, int, char *, ...); void DrawTextFCentered(int, int, char *, ...); void DrawText(int, int, char *, int, int); -void DrawTextExt(DrawBuffer, GC, int, int, char *, int, int); +void DrawTextExt(DrawBuffer, int, int, char *, int, int); #endif /* TEXT_H */ diff --git a/src/libgame/x11.c b/src/libgame/x11.c index 4f0a25e4..4ac4f4fd 100644 --- a/src/libgame/x11.c +++ b/src/libgame/x11.c @@ -32,7 +32,7 @@ inline void X11InitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window) { *window = X11InitWindow(); - XMapWindow(display, *window); + XMapWindow(display, (*window)->drawable); FlushDisplay(); /* create additional (off-screen) buffer for double-buffering */ @@ -87,7 +87,7 @@ static void X11InitDisplay() static DrawWindow X11InitWindow() { - Window window; + DrawWindow new_window = CreateBitmapStruct(); unsigned int border_width = 4; XGCValues gc_values; unsigned long gc_valuemask; @@ -127,15 +127,17 @@ static DrawWindow X11InitWindow() win_xpos = (screen_width - width) / 2; win_ypos = (screen_height - height) / 2; - window = XCreateSimpleWindow(display, RootWindow(display, screen), - win_xpos, win_ypos, width, height, border_width, - pen_fg, pen_bg); + new_window->drawable = XCreateSimpleWindow(display, + RootWindow(display, screen), + win_xpos, win_ypos, + width, height, border_width, + pen_fg, pen_bg); #if !defined(PLATFORM_MSDOS) proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE); delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE); if ((proto_atom != None) && (delete_atom != None)) - XChangeProperty(display, window, proto_atom, XA_ATOM, 32, + XChangeProperty(display, new_window->drawable, proto_atom, XA_ATOM, 32, PropModePrepend, (unsigned char *) &delete_atom, 1); #if 0 @@ -143,7 +145,7 @@ static DrawWindow X11InitWindow() options.ro_base_directory, GRAPHICS_DIRECTORY, icon_pic.picture_filename); #endif - XReadBitmapFile(display, window, program.x11_icon_filename, + XReadBitmapFile(display, new_window->drawable, program.x11_icon_filename, &icon_width, &icon_height, &icon_pixmap, &icon_hot_x, &icon_hot_y); if (!icon_pixmap) @@ -154,7 +156,7 @@ static DrawWindow X11InitWindow() options.ro_base_directory, GRAPHICS_DIRECTORY, icon_pic.picturemask_filename); #endif - XReadBitmapFile(display, window, program.x11_iconmask_filename, + XReadBitmapFile(display, new_window->drawable, program.x11_iconmask_filename, &icon_width, &icon_height, &iconmask_pixmap, &icon_hot_x, &icon_hot_y); if (!iconmask_pixmap) @@ -186,7 +188,7 @@ static DrawWindow X11InitWindow() class_hints.res_name = program.command_name; class_hints.res_class = program.program_title; - XSetWMProperties(display, window, &windowName, &iconName, + XSetWMProperties(display, new_window->drawable, &windowName, &iconName, NULL, 0, &size_hints, &wm_hints, &class_hints); @@ -199,7 +201,7 @@ static DrawWindow X11InitWindow() ButtonPressMask | ButtonReleaseMask | PointerMotionMask | PointerMotionHintMask | KeyPressMask | KeyReleaseMask; - XSelectInput(display, window, window_event_mask); + XSelectInput(display, new_window->drawable, window_event_mask); #endif /* create GC for drawing with window depth and background color (black) */ @@ -207,9 +209,10 @@ static DrawWindow X11InitWindow() gc_values.foreground = pen_bg; gc_values.background = pen_bg; gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; - gc = XCreateGC(display, window, gc_valuemask, &gc_values); + new_window->gc = + XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values); - return window; + return new_window; } #endif /* TARGET_X11 */ diff --git a/src/libgame/x11.h b/src/libgame/x11.h index 783deb3e..dc407766 100644 --- a/src/libgame/x11.h +++ b/src/libgame/x11.h @@ -38,11 +38,23 @@ #define FULLSCREEN_STATUS FULLSCREEN_NOT_AVAILABLE +/* structure definitions */ + +struct X11DrawableInfo +{ + Drawable drawable; + Drawable clip_mask; + GC gc; /* GC for normal drawing (inheritated from 'window') */ + GC stored_clip_gc; /* GC for masked drawing (used for whole Pixmap) */ + GC clip_gc; /* can be 'stored_clip_gc' or one-tile-only clip GC */ +}; + + /* X11 type definitions */ -typedef Pixmap Bitmap; -typedef Window DrawWindow; -typedef Drawable DrawBuffer; +typedef struct X11DrawableInfo *Bitmap; +typedef struct X11DrawableInfo *DrawWindow; +typedef struct X11DrawableInfo *DrawBuffer; typedef KeySym Key; diff --git a/src/main.c b/src/main.c index 92e8b38a..5547d822 100644 --- a/src/main.c +++ b/src/main.c @@ -29,12 +29,25 @@ DrawBuffer backbuffer; GC gc; #endif -GC clip_gc[NUM_BITMAPS], tile_clip_gc; +#if 0 +GC clip_gc[NUM_BITMAPS]; +#endif +GC tile_clip_gc; Bitmap pix[NUM_BITMAPS]; -Bitmap pix_masked[NUM_BITMAPS], tile_masked[NUM_TILES]; -Pixmap clipmask[NUM_BITMAPS], tile_clipmask[NUM_TILES]; +#if 0 +Bitmap pix_masked[NUM_BITMAPS]; +#endif +Bitmap tile_masked[NUM_TILES]; +#if 0 +Pixmap clipmask[NUM_BITMAPS]; +#endif +Pixmap tile_clipmask[NUM_TILES]; -DrawBuffer drawto, drawto_field, fieldbuffer; +#if 0 +DrawBuffer drawto; +#endif + +DrawBuffer drawto_field, fieldbuffer; #if 0 Colormap cmap; #endif @@ -70,8 +83,11 @@ boolean fullscreen_enabled = FALSE; boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; int redraw_x1 = 0, redraw_y1 = 0; + +#if 0 int redraw_mask; int redraw_tiles; +#endif short Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; short Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; diff --git a/src/main.h b/src/main.h index f2ce895c..512fe3f6 100644 --- a/src/main.h +++ b/src/main.h @@ -441,12 +441,24 @@ extern DrawBuffer backbuffer; extern GC gc; #endif -extern GC clip_gc[], tile_clip_gc; +#if 0 +extern GC clip_gc[]; +#endif +extern GC tile_clip_gc; extern Bitmap pix[]; -extern Bitmap pix_masked[], tile_masked[]; -extern Pixmap clipmask[], tile_clipmask[]; +#if 0 +extern Bitmap pix_masked[]; +#endif +extern Bitmap tile_masked[]; +#if 0 +extern Pixmap clipmask[]; +#endif +extern Pixmap tile_clipmask[]; -extern DrawBuffer drawto, drawto_field, fieldbuffer; +#if 0 +extern DrawBuffer drawto; +#endif +extern DrawBuffer drawto_field, fieldbuffer; #if 0 extern Colormap cmap; #endif @@ -475,8 +487,11 @@ extern boolean fullscreen_enabled; extern boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; extern int redraw_x1, redraw_y1; + +#if 0 extern int redraw_mask; extern int redraw_tiles; +#endif extern short Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; extern short Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; @@ -582,6 +597,8 @@ extern int num_element_info; #define MICROLEV_XPOS (SX + (SXSIZE - MICROLEV_XSIZE) / 2) #define MICROLEV_YPOS (SX + 12 * TILEY - MICRO_TILEY) #define MICROLABEL_YPOS (MICROLEV_YPOS + MICROLEV_YSIZE + 7) + +#if 0 #define FONT1_XSIZE 32 #define FONT1_YSIZE 32 #define FONT2_XSIZE 14 @@ -594,6 +611,7 @@ extern int num_element_info; #define FONT5_YSIZE 14 #define FONT6_XSIZE 16 #define FONT6_YSIZE 32 +#endif #define GFX_STARTX SX #define GFX_STARTY SY @@ -631,8 +649,10 @@ extern int num_element_info; #define MINI_MORE_PER_LINE 16 #define MICRO_MORE_PER_LINE 16 +#if 0 #define FONT_CHARS_PER_LINE 16 #define FONT_LINES_PER_FONT 4 +#endif /* game elements: ** 0 - 499: real elements, stored in level file @@ -1615,6 +1635,7 @@ extern int num_element_info; #define MV_UP (1 << 2) #define MV_DOWN (1 << 3) +#if 0 /* font types */ #define FS_SMALL 0 #define FS_BIG 1 @@ -1627,6 +1648,7 @@ extern int num_element_info; #define FC_SPECIAL1 4 #define FC_SPECIAL2 5 #define FC_SPECIAL3 6 +#endif /* values for game_status */ #define EXITGAME 0 @@ -1692,6 +1714,7 @@ extern int num_element_info; #define MB_MIDDLEBUTTON 2 #define MB_RIGHTBUTTON 3 +#if 0 /* values for redraw_mask */ #define REDRAW_ALL (1 << 0) #define REDRAW_FIELD (1 << 1) @@ -1714,6 +1737,7 @@ extern int num_element_info; REDRAW_MICROLEVEL) #define REDRAW_FPS (1 << 10) #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2) +#endif /* areas in bitmap PIX_DOOR */ /* meaning in PIX_DB_DOOR: (3 PAGEs) diff --git a/src/screens.c b/src/screens.c index 43027323..35a6729f 100644 --- a/src/screens.c +++ b/src/screens.c @@ -261,9 +261,9 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) level_nr = new_level_nr; - DrawTextExt(drawto, gc, SX + 11 * 32, SY + 3 * 32, + DrawTextExt(drawto, SX + 11 * 32, SY + 3 * 32, int2str(level_nr, 3), FS_BIG, font_color); - DrawTextExt(window, gc, SX + 11 * 32, SY + 3 * 32, + DrawTextExt(window, SX + 11 * 32, SY + 3 * 32, int2str(level_nr, 3), FS_BIG, font_color); LoadLevel(level_nr); @@ -616,7 +616,7 @@ void DrawHelpScreenElAction(int start) } j++; - DrawGraphicExt(drawto, gc, xstart, ystart+(i-start)*ystep, graphic+frame); + DrawGraphicExt(drawto, xstart, ystart+(i-start)*ystep, graphic+frame); i++; } @@ -841,9 +841,9 @@ void HandleTypeName(int newxpos, Key key) setup.player_name[xpos] = ascii; setup.player_name[xpos + 1] = 0; xpos++; - DrawTextExt(drawto, gc, SX + 6*32, SY + ypos*32, + DrawTextExt(drawto, SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW); - DrawTextExt(window, gc, SX + 6*32, SY + ypos*32, + DrawTextExt(window, SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW); DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT); } diff --git a/src/tools.c b/src/tools.c index 61e1bac1..78fd3d6e 100644 --- a/src/tools.c +++ b/src/tools.c @@ -247,7 +247,7 @@ void BackToFront() info1[0] = '\0'; sprintf(text, "%.1f fps%s", global.frames_per_second, info1); - DrawTextExt(window, gc, SX, SY, text, FS_SMALL, FC_YELLOW); + DrawTextExt(window, SX, SY, text, FS_SMALL, FC_YELLOW); } FlushDisplay(); @@ -378,7 +378,7 @@ void DrawInitText(char *text, int ypos, int color) if (window && pix[PIX_SMALLFONT]) { ClearRectangle(window, 0, ypos, WIN_XSIZE, FONT2_YSIZE); - DrawTextExt(window, gc, (WIN_XSIZE - strlen(text) * FONT2_XSIZE)/2, + DrawTextExt(window, (WIN_XSIZE - strlen(text) * FONT2_XSIZE)/2, ypos, text, FS_SMALL, color); FlushDisplay(); } @@ -877,17 +877,17 @@ void DrawGraphic(int x, int y, int graphic) } #endif - DrawGraphicExt(drawto_field, gc, FX + x*TILEX, FY + y*TILEY, graphic); + DrawGraphicExt(drawto_field, FX + x*TILEX, FY + y*TILEY, graphic); MarkTileDirty(x,y); } -void DrawGraphicExt(DrawBuffer d, GC gc, int x, int y, int graphic) +void DrawGraphicExt(DrawBuffer bitmap, int x, int y, int graphic) { int bitmap_nr; int src_x, src_y; getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y); - BlitBitmap(pix[bitmap_nr], d, src_x, src_y, TILEX, TILEY, x, y); + BlitBitmap(pix[bitmap_nr], bitmap, src_x, src_y, TILEX, TILEY, x, y); } void DrawGraphicThruMask(int x, int y, int graphic) @@ -917,13 +917,13 @@ void DrawGraphicThruMaskExt(DrawBuffer d, int dest_x, int dest_y, int graphic) return; getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y); - src_bitmap = pix_masked[bitmap_nr]; - drawing_gc = clip_gc[bitmap_nr]; + src_bitmap = pix[bitmap_nr]; + drawing_gc = pix[bitmap_nr]->stored_clip_gc; if (tile_clipmask[tile] != None) { - SetClipMask(tile_clip_gc, tile_clipmask[tile]); - SetClipOrigin(tile_clip_gc, dest_x, dest_y); + SetClipMask(src_bitmap, tile_clip_gc, tile_clipmask[tile]); + SetClipOrigin(src_bitmap, tile_clip_gc, dest_x, dest_y); BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y); } @@ -935,7 +935,7 @@ void DrawGraphicThruMaskExt(DrawBuffer d, int dest_x, int dest_y, int graphic) #endif #endif - SetClipOrigin(drawing_gc, dest_x-src_x, dest_y-src_y); + SetClipOrigin(src_bitmap, drawing_gc, dest_x-src_x, dest_y-src_y); BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y); } @@ -943,7 +943,7 @@ void DrawGraphicThruMaskExt(DrawBuffer d, int dest_x, int dest_y, int graphic) void DrawMiniGraphic(int x, int y, int graphic) { - DrawMiniGraphicExt(drawto,gc, SX + x*MINI_TILEX, SY + y*MINI_TILEY, graphic); + DrawMiniGraphicExt(drawto, SX + x*MINI_TILEX, SY + y*MINI_TILEY, graphic); MarkTileDirty(x/2, y/2); } @@ -994,7 +994,7 @@ void getMiniGraphicSource(int graphic, Bitmap *bitmap, int *x, int *y) } } -void DrawMiniGraphicExt(DrawBuffer d, GC gc, int x, int y, int graphic) +void DrawMiniGraphicExt(DrawBuffer d, int x, int y, int graphic) { Bitmap bitmap; int src_x, src_y; @@ -1011,6 +1011,7 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int src_x, src_y, dest_x, dest_y; int tile = graphic; int bitmap_nr; + Bitmap src_bitmap; GC drawing_gc; if (graphic < 0) @@ -1084,7 +1085,8 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, } getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y); - drawing_gc = clip_gc[bitmap_nr]; + src_bitmap = pix[bitmap_nr]; + drawing_gc = pix[bitmap_nr]->stored_clip_gc; src_x += cx; src_y += cy; @@ -1105,9 +1107,9 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, { if (tile_clipmask[tile] != None) { - SetClipMask(tile_clip_gc, tile_clipmask[tile]); - SetClipOrigin(tile_clip_gc, dest_x, dest_y); - BlitBitmapMasked(pix_masked[bitmap_nr], drawto_field, + SetClipMask(src_bitmap, tile_clip_gc, tile_clipmask[tile]); + SetClipOrigin(src_bitmap, tile_clip_gc, dest_x, dest_y); + BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, TILEX, TILEY, dest_x, dest_y); } else @@ -1118,8 +1120,8 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, #endif #endif - SetClipOrigin(drawing_gc, dest_x - src_x, dest_y - src_y); - BlitBitmapMasked(pix_masked[bitmap_nr], drawto_field, + SetClipOrigin(src_bitmap, drawing_gc, dest_x - src_x, dest_y - src_y); + BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height, dest_x, dest_y); } } @@ -1875,8 +1877,7 @@ boolean Request(char *text, unsigned int req_state) } sprintf(txt, text); txt[tl] = 0; - DrawTextExt(drawto, gc, - DX + 51 - (tl * 14)/2, DY + 8 + ty * 16, + DrawTextExt(drawto, DX + 51 - (tl * 14)/2, DY + 8 + ty * 16, txt, FS_SMALL, FC_YELLOW); text += tl + (tc == 32 ? 1 : 0); } @@ -2137,6 +2138,9 @@ unsigned int MoveDoor(unsigned int door_state) for(x=start; x<=DXSIZE; x+=stepsize) { + Bitmap bitmap = pix[PIX_DOOR]; + GC gc = bitmap->stored_clip_gc; + WaitUntilDelayReached(&door_delay, door_delay_value); if (door_state & DOOR_ACTION_1) @@ -2150,33 +2154,32 @@ unsigned int MoveDoor(unsigned int door_state) ClearRectangle(drawto, DX, DY + DYSIZE - i/2, DXSIZE,i/2); - SetClipOrigin(clip_gc[PIX_DOOR], DX - i, (DY + j) - DOOR_GFX_PAGEY1); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + SetClipOrigin(bitmap, gc, DX - i, (DY + j) - DOOR_GFX_PAGEY1); + BlitBitmapMasked(bitmap, drawto, DXSIZE, DOOR_GFX_PAGEY1, i, 77, DX + DXSIZE - i, DY + j); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + BlitBitmapMasked(bitmap, drawto, DXSIZE, DOOR_GFX_PAGEY1 + 140, i, 63, DX + DXSIZE - i, DY + 140 + j); - SetClipOrigin(clip_gc[PIX_DOOR], - DX - DXSIZE + i, DY - (DOOR_GFX_PAGEY1 + j)); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + SetClipOrigin(bitmap, gc, DX - DXSIZE + i, DY - (DOOR_GFX_PAGEY1 + j)); + BlitBitmapMasked(bitmap, drawto, DXSIZE - i, DOOR_GFX_PAGEY1 + j, i, 77 - j, DX, DY); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + BlitBitmapMasked(bitmap, drawto, DXSIZE-i, DOOR_GFX_PAGEY1 + 140, i, 63, DX, DY + 140 - j); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + BlitBitmapMasked(bitmap, drawto, DXSIZE - i, DOOR_GFX_PAGEY1 + 77, i, 63, DX, DY + 77 - j); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + BlitBitmapMasked(bitmap, drawto, DXSIZE - i, DOOR_GFX_PAGEY1 + 203, i, 77, DX, DY + 203 - j); - SetClipOrigin(clip_gc[PIX_DOOR], DX - i, (DY + j) - DOOR_GFX_PAGEY1); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + SetClipOrigin(bitmap, gc, DX - i, (DY + j) - DOOR_GFX_PAGEY1); + BlitBitmapMasked(bitmap, drawto, DXSIZE, DOOR_GFX_PAGEY1 + 77, i, 63, DX + DXSIZE - i, DY + 77 + j); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + BlitBitmapMasked(bitmap, drawto, DXSIZE, DOOR_GFX_PAGEY1 + 203, i, 77 - j, DX + DXSIZE - i, DY + 203 + j); @@ -2194,21 +2197,21 @@ unsigned int MoveDoor(unsigned int door_state) ClearRectangle(drawto, VX, VY + VYSIZE-i/2, VXSIZE, i/2); - SetClipOrigin(clip_gc[PIX_DOOR], VX - i, (VY + j) - DOOR_GFX_PAGEY2); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + SetClipOrigin(bitmap, gc, VX - i, (VY + j) - DOOR_GFX_PAGEY2); + BlitBitmapMasked(bitmap, drawto, VXSIZE, DOOR_GFX_PAGEY2, i, VYSIZE / 2, VX + VXSIZE-i, VY+j); - SetClipOrigin(clip_gc[PIX_DOOR], + SetClipOrigin(bitmap, gc, VX - VXSIZE + i, VY - (DOOR_GFX_PAGEY2 + j)); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + BlitBitmapMasked(bitmap, drawto, VXSIZE - i, DOOR_GFX_PAGEY2 + j, i, VYSIZE / 2 - j, VX, VY); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + BlitBitmapMasked(bitmap, drawto, VXSIZE - i, DOOR_GFX_PAGEY2 + VYSIZE / 2, i, VYSIZE / 2, VX, VY + VYSIZE / 2 - j); - SetClipOrigin(clip_gc[PIX_DOOR], VX - i, (VY + j) - DOOR_GFX_PAGEY2); - BlitBitmapMasked(pix_masked[PIX_DOOR], drawto, + SetClipOrigin(bitmap, gc, VX - i, (VY + j) - DOOR_GFX_PAGEY2); + BlitBitmapMasked(bitmap, drawto, VXSIZE, DOOR_GFX_PAGEY2 + VYSIZE / 2, i, VYSIZE / 2 - j, VX + VXSIZE - i, VY + VYSIZE / 2 + j); @@ -2253,12 +2256,13 @@ void UndrawSpecialEditorDoor() } #ifndef TARGET_SDL -int ReadPixel(DrawBuffer d, int x, int y) +int ReadPixel(DrawBuffer bitmap, int x, int y) { XImage *pixel_image; unsigned long pixel_value; - pixel_image = XGetImage(display, d, x, y, 1, 1, AllPlanes, ZPixmap); + pixel_image = XGetImage(display, bitmap->drawable, + x, y, 1, 1, AllPlanes, ZPixmap); pixel_value = XGetPixel(pixel_image, 0, 0); XDestroyImage(pixel_image); diff --git a/src/tools.h b/src/tools.h index 721aa002..bbfa8b01 100644 --- a/src/tools.h +++ b/src/tools.h @@ -81,12 +81,12 @@ void DrawGraphicAnimation(int, int, int, int, int, int); void DrawGraphicAnimationThruMask(int, int, int, int, int, int); void getGraphicSource(int, int *, int *, int *); void DrawGraphic(int, int, int); -void DrawGraphicExt(DrawBuffer, GC, int, int, int); +void DrawGraphicExt(DrawBuffer, int, int, int); void DrawGraphicThruMask(int, int, int); void DrawGraphicThruMaskExt(DrawBuffer, int, int, int); void DrawMiniGraphic(int, int, int); void getMiniGraphicSource(int, Bitmap *, int *, int *); -void DrawMiniGraphicExt(DrawBuffer, GC, int, int, int); +void DrawMiniGraphicExt(DrawBuffer, int, int, int); void DrawGraphicShifted(int, int, int, int, int, int, int); void DrawGraphicShiftedThruMask(int, int, int, int, int, int); void DrawScreenElementExt(int, int, int, int, int, int, int); -- 2.34.1