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
This commit is contained in:
cohrs
2002-03-24 00:04:41 +00:00
parent 658ee6436a
commit 88f0680567
5 changed files with 49 additions and 48 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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);

View File

@@ -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))

View File

@@ -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) );
}