From 88f0680567262631ccb27f31029bc7d1b02660be Mon Sep 17 00:00:00 2001 From: cohrs Date: Sun, 24 Mar 2002 00:04:41 +0000 Subject: [PATCH] restore support for non-square XPM-based tiles (X11 & Gnome) - change the way the tile sizes are calculated, based on the image size, so non-square tiles can once again be supported. - fix Gnome port so it can actually display non-square tiles, several height/width uses were backwards - update Install.X11 to note the number of tiles per row in the XPM image --- doc/fixes34.1 | 3 ++- win/X11/Install.X11 | 7 ++++-- win/X11/winmap.c | 19 +++++++-------- win/gnome/gnglyph.c | 57 +++++++++++++++++++++++---------------------- win/gnome/gnmap.c | 11 ++++----- 5 files changed, 49 insertions(+), 48 deletions(-) diff --git a/doc/fixes34.1 b/doc/fixes34.1 index 3414b3453..72dd1c821 100644 --- a/doc/fixes34.1 +++ b/doc/fixes34.1 @@ -18,6 +18,7 @@ wall symbol not replaced when digging while blind and levitating Platform- and/or Interface-Specific Fixes ----------------------------------------- - win32gui: make error() work; it was essentially non-operative in 3.4.0 win32tty: honour the use_inverse option and default to ATR_BOLD if disabled +X11: restore support for non-square tiles when USE_XPM is defined +Gnome: add support for non-square tiles diff --git a/win/X11/Install.X11 b/win/X11/Install.X11 index 7a0ffcd8b..daac06b87 100644 --- a/win/X11/Install.X11 +++ b/win/X11/Install.X11 @@ -50,8 +50,11 @@ When using tiles, you have the option of defining USE_XPM in config.h. This causes NetHack to use the XPM file format for the "x11tiles" file rather than a custom format. Since the XPM format can be processed by existing tools such as PBMPlus and XV, you can modify the tiles to suit -your environment. For example, you may magnify them for display on -high-resolution screens using the following command: +your environment. However, you need to make sure the number of tiles +in each row of the image remains the same (currently 40), as the code +depends on this to calculate the size of each tile. For example, you may +magnify them for display on high-resolution screens using the following +command: xpmtoppm x11tiles | pnmscale -xscale 1 -yscale 1.6875 | pnmdepth 255 | ppmquant 100 | ppmtoxpm >x11tiles_big.xpm To use XPM, you must have the free XPM libraries installed in your system. diff --git a/win/X11/winmap.c b/win/X11/winmap.c index dda4685be..bef860bd3 100644 --- a/win/X11/winmap.c +++ b/win/X11/winmap.c @@ -306,7 +306,8 @@ init_tiles(wp) } /* assume a fixed number of tiles per row */ - if (tile_image->width % TILES_PER_ROW != 0) { + if (tile_image->width % TILES_PER_ROW != 0 || + tile_image->width <= TILES_PER_ROW) { Sprintf(buf, "%s is not a multiple of %d (number of tiles/row) pixels wide", appResources.tile_file, TILES_PER_ROW); @@ -317,20 +318,16 @@ init_tiles(wp) goto tiledone; } - /* infer tile dimensions from image size, assume square tiles */ + /* infer tile dimensions from image size and TILES_PER_ROW */ image_width = tile_image->width; image_height = tile_image->height; - tile_width = image_width / TILES_PER_ROW; - tile_height = tile_width; - tile_count = (image_width * image_height) / (tile_width * tile_height); - if (tile_count < total_tiles_used) { - Sprintf(buf, "%s incomplete, expecting %d tiles, found %d", - appResources.tile_file, total_tiles_used, tile_count); - X11_raw_print(buf); - result = FALSE; - goto tiledone; + tile_count = total_tiles_used; + if ((tile_count % TILES_PER_ROW) != 0) { + tile_count += TILES_PER_ROW - (tile_count % TILES_PER_ROW); } + tile_width = image_width / TILES_PER_ROW; + tile_height = image_height / (tile_count / TILES_PER_ROW); #else /* any less than 16 colours makes tiles useless */ ddepth = DefaultDepthOfScreen(screen); diff --git a/win/gnome/gnglyph.c b/win/gnome/gnglyph.c index 702617a3a..bb08abc42 100644 --- a/win/gnome/gnglyph.c +++ b/win/gnome/gnglyph.c @@ -5,6 +5,9 @@ #include "gnglyph.h" #include "tile2x11.h" +/* from tile.c */ +extern int total_tiles_used; + static GHackGlyphs ghack_glyphs; static GdkImlibImage** ghack_tiles = NULL; @@ -45,38 +48,36 @@ static GdkImlibImage** ghack_tiles = NULL; */ int -ghack_init_glyphs( const char *xpmFile) +ghack_init_glyphs(const char *xpmFile) { - ghack_glyphs.im = gdk_imlib_load_image((char *) xpmFile); - if ( ! ghack_glyphs.im ) - { - g_error("Couldn't load required xpmFile!"); - return -1; + ghack_glyphs.im = gdk_imlib_load_image((char *) xpmFile); + if ( ! ghack_glyphs.im ) { + g_error("Couldn't load required xpmFile!"); + return -1; } - gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width, - ghack_glyphs.im->rgb_height); + gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width, + ghack_glyphs.im->rgb_height); - if (ghack_glyphs.im->rgb_width % TILES_PER_ROW) { - g_error("%s is not a multiple of %d (number of tiles/row) pixels wide", - xpmFile, TILES_PER_ROW); - return -1; - } - ghack_glyphs.width = ghack_glyphs.im->rgb_width / TILES_PER_ROW; - ghack_glyphs.height = ghack_glyphs.width; - ghack_glyphs.count = - (ghack_glyphs.im->rgb_height * ghack_glyphs.im->rgb_width) / - (ghack_glyphs.width * ghack_glyphs.height); + if ((ghack_glyphs.im->rgb_width % TILES_PER_ROW) != 0 || + ghack_glyphs.im->rgb_width <= TILES_PER_ROW) { + g_error("%s is not a multiple of %d (number of tiles/row) pixels wide", + xpmFile, TILES_PER_ROW); + return -1; + } + ghack_glyphs.count = total_tiles_used; + if ((ghack_glyphs.count % TILES_PER_ROW) != 0) { + ghack_glyphs.count += + TILES_PER_ROW - (ghack_glyphs.count % TILES_PER_ROW); + } + ghack_glyphs.width = ghack_glyphs.im->rgb_width / TILES_PER_ROW; + ghack_glyphs.height = + ghack_glyphs.im->rgb_height / (ghack_glyphs.count / TILES_PER_ROW); - /* Assume the tiles are organized in rows of TILES_PER_ROW - * Further, assume that the tiles are SQUARE - */ - ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count ); - if (ghack_tiles == NULL) - return -1; - else - return 0; + /* Assume the tiles are organized in rows of TILES_PER_ROW */ + ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count ); + return (ghack_tiles == NULL) ? -1 : 0; } void @@ -210,8 +211,8 @@ ghack_image_from_glyph( int glyph, gboolean force ) src_y = (tile / TILES_PER_ROW) * ghack_glyphs.height; ghack_tiles[tile] = gdk_imlib_crop_and_clone_image(ghack_glyphs.im, src_x, src_y, - ghack_glyphs.height, - ghack_glyphs.width); + ghack_glyphs.width, + ghack_glyphs.height); } if (ghack_tiles[tile] && (!ghack_tiles[tile]->pixmap || force)) diff --git a/win/gnome/gnmap.c b/win/gnome/gnmap.c index 3d0882e8c..b1d70514d 100644 --- a/win/gnome/gnmap.c +++ b/win/gnome/gnmap.c @@ -221,8 +221,8 @@ ghack_init_map_window ( ) gnome_canvas_image_get_type (), "x", (double) x, "y", (double) y, - "width", (double) ghack_glyph_height(), - "height", (double) ghack_glyph_width(), + "width", (double) ghack_glyph_width(), + "height", (double) ghack_glyph_height(), "anchor", GTK_ANCHOR_NORTH_WEST, NULL) ); } @@ -234,8 +234,7 @@ ghack_init_map_window ( ) g_warning("Bummer! Failed to load the pet_mark image!"); } else { - gdk_imlib_render(petmark, petmark->rgb_width, - petmark->rgb_height); + gdk_imlib_render(petmark, petmark->rgb_width, petmark->rgb_height); /* ghack_map.overlay is an array of canvas images used to * overlay tile images... @@ -573,8 +572,8 @@ ghack_reinit_map_window ( ) gnome_canvas_image_get_type (), "x", (double) x, "y", (double) y, - "width", (double) ghack_glyph_height(), - "height", (double) ghack_glyph_width(), + "width", (double) ghack_glyph_width(), + "height", (double) ghack_glyph_height(), "anchor", GTK_ANCHOR_NORTH_WEST, NULL) ); }