/*************************************************************************** ... ***************************************************************************/ void create_overlay_unit(struct canvas *pcanvas, struct unit_type *punittype) { int x1, x2, y1, y2; int width, height; struct sprite *sprite = get_unittype_sprite(tileset, punittype); sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2); if (pcanvas->type == CANVAS_PIXBUF) { width = gdk_pixbuf_get_width(pcanvas->v.pixbuf); height = gdk_pixbuf_get_height(pcanvas->v.pixbuf); gdk_pixbuf_fill(pcanvas->v.pixbuf, 0x00000000); } else { if (pcanvas->type == CANVAS_PIXCOMM) { gtk_pixcomm_clear(pcanvas->v.pixcomm); } /* Guess */ width = tileset_full_tile_width(tileset); height = tileset_full_tile_height(tileset); } /* Finally, put a picture of the unit in the tile */ canvas_put_sprite(pcanvas, 0, 0, sprite, (x2 + x1 - width) / 2, (y1 + y2 - height) / 2, tileset_full_tile_width(tileset) - (x2 + x1 - width) / 2, tileset_full_tile_height(tileset) - (y1 + y2 - height) / 2); }
/**************************************************************************** Crops all blankspace from a sprite (insofar as is possible as a rectangle) ****************************************************************************/ struct sprite *crop_blankspace(struct sprite *s) { int x1, y1, x2, y2; sprite_get_bounding_box(s, &x1, &y1, &x2, &y2); return crop_sprite(s, x1, y1, x2 - x1 + 1, y2 - y1 + 1, NULL, -1, -1); }
/**************************************************************** Setup max unit sprite size. *****************************************************************/ static void update_max_unit_size(void) { max_unit_height = 0; max_unit_width = 0; unit_type_iterate(i) { int x1, x2, y1, y2; struct sprite *sprite = get_unittype_sprite(tileset, i, direction8_invalid(), TRUE); sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2); max_unit_width = MAX(max_unit_width, x2 - x1); max_unit_height = MAX(max_unit_height, y2 - y1); } unit_type_iterate_end; }