X11 wide tilemap support - Gnome patch

- update Gnome code to support a 40 tile wide XPM file
This commit is contained in:
cohrs
2002-03-17 20:04:56 +00:00
parent b6189efe2a
commit 0ffb78e6a4

View File

@@ -3,6 +3,7 @@
/* NetHack may be freely redistributed. See license for details. */
#include "gnglyph.h"
#include "tile2x11.h"
static GHackGlyphs ghack_glyphs;
static GdkImlibImage** ghack_tiles = NULL;
@@ -28,8 +29,9 @@ static GdkImlibImage** ghack_tiles = NULL;
* NOTES:
* The glyphs (tiles) must be in the image in a certain way: the
* glyphs must be stacked such that the resultant image is
* TILE_X wide, and TILE_Y * (number of glyphs) high. In this
* sense, TILE_X == TILE_Y, and can be any reasonable integer--
* TILE_X * TILES_PER_ROW wide, and
* TILE_Y * (number of glyphs) / TILES_PER_ROW high (rounded up).
* In this sense, TILE_X == TILE_Y, and can be any reasonable integer
* say, 16 <= TILE_X <= 64. Because the glyph number is tightly
* coupled to the Nethack object it represents, the order of the
* glyphs in the image is imporant: Glyph 1 is at the top of the
@@ -55,12 +57,19 @@ ghack_init_glyphs( const char *xpmFile)
gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width,
ghack_glyphs.im->rgb_height);
ghack_glyphs.count = ghack_glyphs.im->rgb_height / ghack_glyphs.im->rgb_width;
ghack_glyphs.width = ghack_glyphs.im->rgb_width;
ghack_glyphs.height = ghack_glyphs.im->rgb_height / ghack_glyphs.count;
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);
/* Assume the tiles are stacked vertically.
/* 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 );
@@ -186,8 +195,8 @@ ghack_image_from_glyph( int glyph, gboolean force )
(force==TRUE)? "TRUE" : "FALSE");
}
if (!ghack_tiles[tile] || force)
{
if (!ghack_tiles[tile] || force) {
int src_x, src_y;
#if 0
fprintf( stderr, "crop_and_clone: glyph=%d, tile=%d, ptr=%p, x=%d, y=%d, w=%d, h=%d\n", glyph, tile,
(void*)&(ghack_tiles[tile]), 0,
@@ -197,8 +206,10 @@ ghack_image_from_glyph( int glyph, gboolean force )
#endif
if (ghack_glyphs.im->pixmap == NULL)
g_warning( "Aiiee! ghack_glyphs.im->pixmap==NULL!!!!\n");
ghack_tiles[tile] = gdk_imlib_crop_and_clone_image(ghack_glyphs.im, 0,
tile * ghack_glyphs.width,
src_x = (tile % TILES_PER_ROW) * ghack_glyphs.width;
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);
}
@@ -216,4 +227,3 @@ ghack_image_from_glyph( int glyph, gboolean force )
return ghack_tiles[tile];
}