X11 wide tilemap support - Gnome patch
- update Gnome code to support a 40 tile wide XPM file
This commit is contained in:
+21
-11
@@ -3,6 +3,7 @@
|
|||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
#include "gnglyph.h"
|
#include "gnglyph.h"
|
||||||
|
#include "tile2x11.h"
|
||||||
|
|
||||||
static GHackGlyphs ghack_glyphs;
|
static GHackGlyphs ghack_glyphs;
|
||||||
static GdkImlibImage** ghack_tiles = NULL;
|
static GdkImlibImage** ghack_tiles = NULL;
|
||||||
@@ -28,8 +29,9 @@ static GdkImlibImage** ghack_tiles = NULL;
|
|||||||
* NOTES:
|
* NOTES:
|
||||||
* The glyphs (tiles) must be in the image in a certain way: the
|
* The glyphs (tiles) must be in the image in a certain way: the
|
||||||
* glyphs must be stacked such that the resultant image is
|
* glyphs must be stacked such that the resultant image is
|
||||||
* TILE_X wide, and TILE_Y * (number of glyphs) high. In this
|
* TILE_X * TILES_PER_ROW wide, and
|
||||||
* sense, TILE_X == TILE_Y, and can be any reasonable integer--
|
* 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
|
* say, 16 <= TILE_X <= 64. Because the glyph number is tightly
|
||||||
* coupled to the Nethack object it represents, the order of the
|
* 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
|
* 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,
|
gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width,
|
||||||
ghack_glyphs.im->rgb_height);
|
ghack_glyphs.im->rgb_height);
|
||||||
|
|
||||||
ghack_glyphs.count = ghack_glyphs.im->rgb_height / ghack_glyphs.im->rgb_width;
|
if (ghack_glyphs.im->rgb_width % TILES_PER_ROW) {
|
||||||
ghack_glyphs.width = ghack_glyphs.im->rgb_width;
|
g_error("%s is not a multiple of %d (number of tiles/row) pixels wide",
|
||||||
ghack_glyphs.height = ghack_glyphs.im->rgb_height / ghack_glyphs.count;
|
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
|
* Further, assume that the tiles are SQUARE
|
||||||
*/
|
*/
|
||||||
ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count );
|
ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count );
|
||||||
@@ -186,8 +195,8 @@ ghack_image_from_glyph( int glyph, gboolean force )
|
|||||||
(force==TRUE)? "TRUE" : "FALSE");
|
(force==TRUE)? "TRUE" : "FALSE");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ghack_tiles[tile] || force)
|
if (!ghack_tiles[tile] || force) {
|
||||||
{
|
int src_x, src_y;
|
||||||
#if 0
|
#if 0
|
||||||
fprintf( stderr, "crop_and_clone: glyph=%d, tile=%d, ptr=%p, x=%d, y=%d, w=%d, h=%d\n", glyph, tile,
|
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,
|
(void*)&(ghack_tiles[tile]), 0,
|
||||||
@@ -197,8 +206,10 @@ ghack_image_from_glyph( int glyph, gboolean force )
|
|||||||
#endif
|
#endif
|
||||||
if (ghack_glyphs.im->pixmap == NULL)
|
if (ghack_glyphs.im->pixmap == NULL)
|
||||||
g_warning( "Aiiee! ghack_glyphs.im->pixmap==NULL!!!!\n");
|
g_warning( "Aiiee! ghack_glyphs.im->pixmap==NULL!!!!\n");
|
||||||
ghack_tiles[tile] = gdk_imlib_crop_and_clone_image(ghack_glyphs.im, 0,
|
src_x = (tile % TILES_PER_ROW) * ghack_glyphs.width;
|
||||||
tile * 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.height,
|
||||||
ghack_glyphs.width);
|
ghack_glyphs.width);
|
||||||
}
|
}
|
||||||
@@ -216,4 +227,3 @@ ghack_image_from_glyph( int glyph, gboolean force )
|
|||||||
|
|
||||||
return ghack_tiles[tile];
|
return ghack_tiles[tile];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user