[Freeciv-Dev] Re: (PR#4576) remove sprite padding for flags
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Jason Short wrote:
> [jdorje - Wed Jul 16 04:44:21 2003]:
>
>
>>The attached patch removes the necessity for sprite padding for flags
>>in
>>iso-view tilesets. It basically follows the idea put forth in
>>PR#2960,
>>but only implements it for flags.
>
>
> Updated patch attached. This one has support only in put_unit(), so it
> will break any clients that don't use that function (win32, gtk2, sdl,
> mui). It's also substantially simpler than the previous (gtk-only) one.
Naturally we have to make the adjustment for flags drawn behind cities
as well. This makes the patch ugly again...
jason
? rc
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.49
diff -u -r1.49 mapview_common.c
--- client/mapview_common.c 2003/07/18 01:12:09 1.49
+++ client/mapview_common.c 2003/07/18 20:54:54
@@ -410,7 +410,7 @@
int unit_offset_x, int unit_offset_y,
int unit_width, int unit_height)
{
- struct Sprite *sprites[40];
+ struct drawn_sprite sprites[40];
int solid_bg, i;
int count = fill_unit_sprite_array(sprites, punit, &solid_bg);
@@ -420,12 +420,14 @@
}
for (i = 0; i < count; i++) {
- if (sprites[i]) {
+ if (sprites[i].sprite) {
+ int ox = sprites[i].offset_x, oy = sprites[i].offset_y;
+
/* units are never fogged */
- gui_put_sprite(pcanvas_store,
- canvas_x, canvas_y, sprites[i],
- unit_offset_x, unit_offset_y,
- unit_width, unit_height);
+ gui_put_sprite(pcanvas_store, canvas_x + ox, canvas_y + oy,
+ sprites[i].sprite,
+ unit_offset_x - ox, unit_offset_y - oy,
+ unit_width - ox, unit_height - oy);
}
}
}
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.122
diff -u -r1.122 tilespec.c
--- client/tilespec.c 2003/07/18 20:29:47 1.122
+++ client/tilespec.c 2003/07/18 20:54:55
@@ -80,6 +80,7 @@
static bool is_mountainous = FALSE;
static int roadstyle;
+static int flag_offset_x, flag_offset_y;
struct specfile;
@@ -627,6 +628,10 @@
"tilespec.is_mountainous");
roadstyle = secfile_lookup_int_default(file, is_isometric ? 0 : 1,
"tilespec.roadstyle");
+ flag_offset_x = secfile_lookup_int_default(file, 0,
+ "tilespec.flag_offset_x");
+ flag_offset_y = secfile_lookup_int_default(file, 0,
+ "tilespec.flag_offset_y");
c = secfile_lookup_str_default(file, "10x20", "tilespec.city_names_font");
city_names_font = mystrdup(c);
@@ -1248,50 +1253,60 @@
return sprites.city.tile[style][city_styles[style].tiles_num+1];
}
+#define ADD_SPRITE(s, x_offset, y_offset) \
+ (sprs->sprite = s, \
+ sprs->offset_x = x_offset, \
+ sprs->offset_y = y_offset, \
+ sprs++)
+
+#define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, 0, 0)
+
/**********************************************************************
Fill in the sprite array for the city
***********************************************************************/
-static int fill_city_sprite_array(struct Sprite **sprs, struct city *pcity,
+static int fill_city_sprite_array(struct drawn_sprite *sprs,
+ struct city *pcity,
int *solid_bg)
{
- struct Sprite **save_sprs=sprs;
+ struct drawn_sprite *save_sprs = sprs;
*solid_bg = 0;
if (!no_backdrop) {
- if(!solid_color_behind_units) {
- *sprs++ = get_city_nation_flag_sprite(pcity);
+ if (is_isometric || !solid_color_behind_units) {
+ ADD_SPRITE(get_city_nation_flag_sprite(pcity),
+ flag_offset_x, flag_offset_y);
} else {
*solid_bg = 1;
}
}
if (pcity->occupied) {
- *sprs++ = get_city_occupied_sprite(pcity);
+ ADD_SPRITE_SIMPLE(get_city_occupied_sprite(pcity));
}
- *sprs++ = get_city_sprite(pcity);
+ ADD_SPRITE_SIMPLE(get_city_sprite(pcity));
if (city_got_citywalls(pcity))
- *sprs++ = get_city_wall_sprite(pcity);
+ ADD_SPRITE_SIMPLE(get_city_wall_sprite(pcity));
if(map_has_special(pcity->x, pcity->y, S_POLLUTION))
- *sprs++ = sprites.tx.pollution;
+ ADD_SPRITE_SIMPLE(sprites.tx.pollution);
if(map_has_special(pcity->x, pcity->y, S_FALLOUT))
- *sprs++ = sprites.tx.fallout;
+ ADD_SPRITE_SIMPLE(sprites.tx.fallout);
if(city_unhappy(pcity))
- *sprs++ = sprites.city.disorder;
+ ADD_SPRITE_SIMPLE(sprites.city.disorder);
if(tile_get_known(pcity->x, pcity->y) == TILE_KNOWN_FOGGED &&
draw_fog_of_war)
- *sprs++ = sprites.tx.fog;
+ ADD_SPRITE_SIMPLE(sprites.tx.fog);
/* Put the size sprites last, so that they are not obscured
* (and because they can be hard to read if fogged).
*/
if (pcity->size>=10)
- *sprs++ = sprites.city.size_tens[pcity->size/10];
+ ADD_SPRITE_SIMPLE(sprites.city.size_tens[pcity->size/10]);
- *sprs++ = sprites.city.size[pcity->size%10];
+ ADD_SPRITE_SIMPLE(sprites.city.size[pcity->size%10]);
return sprs - save_sprs;
}
@@ -1300,22 +1315,23 @@
Fill in the sprite array for the city
(small because things have to be done later in isometric view.)
***********************************************************************/
-int fill_city_sprite_array_iso(struct Sprite **sprs, struct city *pcity)
+int fill_city_sprite_array_iso(struct drawn_sprite *sprs, struct city *pcity)
{
- struct Sprite **save_sprs=sprs;
+ struct drawn_sprite *save_sprs = sprs;
if (!no_backdrop) {
- *sprs++ = get_city_nation_flag_sprite(pcity);
+ ADD_SPRITE(get_city_nation_flag_sprite(pcity),
+ flag_offset_x, flag_offset_y);;
}
if (pcity->occupied) {
- *sprs++ = get_city_occupied_sprite(pcity);
+ ADD_SPRITE_SIMPLE(get_city_occupied_sprite(pcity));
}
- *sprs++ = get_city_sprite(pcity);
+ ADD_SPRITE_SIMPLE(get_city_sprite(pcity));
if (city_unhappy(pcity))
- *sprs++ = sprites.city.disorder;
+ ADD_SPRITE_SIMPLE(sprites.city.disorder);
return sprs - save_sprs;
}
@@ -1373,28 +1389,30 @@
/**********************************************************************
Fill in the sprite array for the unit
***********************************************************************/
-int fill_unit_sprite_array(struct Sprite **sprs, struct unit *punit,
- int *solid_bg)
+int fill_unit_sprite_array(struct drawn_sprite *sprs,
+ struct unit *punit, int *solid_bg)
{
- struct Sprite **save_sprs=sprs;
+ struct drawn_sprite *save_sprs = sprs;
int ihp;
*solid_bg = 0;
if (is_isometric) {
if (!no_backdrop) {
- *sprs++ = get_unit_nation_flag_sprite(punit);
+ ADD_SPRITE(get_unit_nation_flag_sprite(punit),
+ flag_offset_x, flag_offset_y);
}
} else {
if (!no_backdrop) {
if (!solid_color_behind_units) {
- *sprs++ = get_unit_nation_flag_sprite(punit);
+ ADD_SPRITE(get_unit_nation_flag_sprite(punit),
+ flag_offset_x, flag_offset_y);
} else {
*solid_bg = 1;
}
}
}
- *sprs++ = unit_type(punit)->sprite;
+ ADD_SPRITE_SIMPLE(unit_type(punit)->sprite);
if(punit->activity!=ACTIVITY_IDLE) {
struct Sprite *s = NULL;
@@ -1446,28 +1464,28 @@
break;
}
- *sprs++ = s;
+ ADD_SPRITE_SIMPLE(s);
}
if (punit->ai.control && punit->activity != ACTIVITY_EXPLORE) {
if (is_military_unit(punit)) {
- *sprs++ = sprites.unit.auto_attack;
+ ADD_SPRITE_SIMPLE(sprites.unit.auto_attack);
} else {
- *sprs++ = sprites.unit.auto_settler;
+ ADD_SPRITE_SIMPLE(sprites.unit.auto_settler);
}
}
if (punit->connecting) {
- *sprs++ = sprites.unit.connect;
+ ADD_SPRITE_SIMPLE(sprites.unit.connect);
}
if (punit->activity == ACTIVITY_PATROL) {
- *sprs++ = sprites.unit.patrol;
+ ADD_SPRITE_SIMPLE(sprites.unit.patrol);
}
ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / unit_type(punit)->hp;
ihp = CLIP(0, ihp, NUM_TILES_HP_BAR-1);
- *sprs++ = sprites.unit.hp_bar[ihp];
+ ADD_SPRITE_SIMPLE(sprites.unit.hp_bar[ihp]);
return sprs - save_sprs;
}
@@ -2036,7 +2054,14 @@
if (solid_color_behind_units) {
punit = get_drawable_unit(abs_x0, abs_y0, citymode);
if (punit && (draw_units || (draw_focus_unit && pfocus == punit))) {
- sprs += fill_unit_sprite_array(sprs, punit, solid_bg);
+ struct drawn_sprite my_sprs[40];
+ int count = fill_unit_sprite_array(my_sprs, punit, solid_bg), i;
+
+ for (i = 0; i < count; i++) {
+ /* HACK: transform drawn_sprite into sprite. */
+ assert(my_sprs[i].offset_x == 0 && my_sprs[i].offset_y == 0);
+ *sprs++ = my_sprs[i].sprite;
+ }
*pplayer = unit_owner(punit);
if (unit_list_size(&ptile->units) > 1)
*sprs++ = sprites.unit.stack;
@@ -2044,7 +2069,14 @@
}
if (pcity && draw_cities) {
- sprs+=fill_city_sprite_array(sprs, pcity, solid_bg);
+ struct drawn_sprite my_sprs[40];
+ int count = fill_city_sprite_array(my_sprs, pcity, solid_bg), i;
+
+ for (i = 0; i < count; i++) {
+ /* HACK: transform drawn_sprite into sprite. */
+ assert(my_sprs[i].offset_x == 0 && my_sprs[i].offset_y == 0);
+ *sprs++ = my_sprs[i].sprite;
+ }
*pplayer = city_owner(pcity);
return sprs - save_sprs;
}
@@ -2167,8 +2199,14 @@
if (pcity && draw_cities) {
int dummy;
+ struct drawn_sprite my_sprs[40];
+ int count = fill_city_sprite_array(my_sprs, pcity, &dummy), i;
- sprs += fill_city_sprite_array(sprs, pcity, &dummy);
+ for (i = 0; i < count; i++) {
+ /* HACK: transform drawn_sprite into sprite. */
+ assert(my_sprs[i].offset_x == 0 && my_sprs[i].offset_y == 0);
+ *sprs++ = my_sprs[i].sprite;
+ }
}
punit = find_visible_unit(ptile);
@@ -2177,10 +2215,17 @@
if ((!focus_unit_hidden || pfocus != punit) &&
(draw_units || (draw_focus_unit && !focus_unit_hidden
&& punit == pfocus))) {
- int dummy;
+ int dummy, count, i;
+ struct drawn_sprite my_sprs[40];
no_backdrop = (pcity != NULL);
- sprs += fill_unit_sprite_array(sprs, punit, &dummy);
+ count = fill_unit_sprite_array(my_sprs, punit, &dummy);
+
+ for (i = 0; i < count; i++) {
+ /* HACK: transform drawn_sprite into sprite. */
+ assert(my_sprs[i].offset_x == 0 && my_sprs[i].offset_y == 0);
+ *sprs++ = my_sprs[i].sprite;
+ }
no_backdrop = FALSE;
if (unit_list_size(&ptile->units) > 1) {
*sprs++ = sprites.unit.stack;
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.45
diff -u -r1.45 tilespec.h
--- client/tilespec.h 2003/07/17 04:43:03 1.45
+++ client/tilespec.h 2003/07/18 20:54:55
@@ -28,6 +28,11 @@
struct unit;
struct player;
+struct drawn_sprite {
+ struct Sprite *sprite;
+ int offset_x, offset_y; /* offset from tile origin */
+};
+
const char **get_tileset_list(void);
void tilespec_read_toplevel(const char *tileset_name);
@@ -55,8 +60,10 @@
int *solid_bg);
int fill_tile_sprite_array(struct Sprite **sprs, int abs_x0, int abs_y0,
bool citymode, int *solid_bg, struct player
**pplayer);
-int fill_unit_sprite_array(struct Sprite **sprs, struct unit *punit, int
*solid_bg);
-int fill_city_sprite_array_iso(struct Sprite **sprs, struct city *pcity);
+int fill_unit_sprite_array(struct drawn_sprite *sprs,
+ struct unit *punit, int *solid_bg);
+int fill_city_sprite_array_iso(struct drawn_sprite *sprs,
+ struct city *pcity);
enum color_std player_color(struct player *pplayer);
enum color_std overview_tile_color(int x, int y);
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.173
diff -u -r1.173 mapview.c
--- client/gui-gtk/mapview.c 2003/07/18 01:12:09 1.173
+++ client/gui-gtk/mapview.c 2003/07/18 20:54:55
@@ -1342,15 +1342,18 @@
int width, int height_unit,
int fog)
{
- struct Sprite *sprites[80];
+ struct drawn_sprite sprites[80];
int count = fill_city_sprite_array_iso(sprites, pcity);
int i;
for (i=0; i<count; i++) {
- if (sprites[i]) {
- pixmap_put_overlay_tile_draw(pm, canvas_x, canvas_y, sprites[i],
- offset_x, offset_y_unit,
- width, height_unit,
+ if (sprites[i].sprite) {
+ int ox = sprites[i].offset_x, oy = sprites[i].offset_y;
+
+ pixmap_put_overlay_tile_draw(pm, canvas_x + ox, canvas_y + oy,
+ sprites[i].sprite,
+ offset_x - ox, offset_y_unit - oy,
+ width - ox, height_unit - oy,
fog);
}
}
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.8
diff -u -r1.8 isotrident.tilespec
--- data/isotrident.tilespec 2003/02/02 00:15:53 1.8
+++ data/isotrident.tilespec 2003/07/18 20:54:55
@@ -24,6 +24,10 @@
; Use roadstyle 0 (old iso style)
roadstyle = 0
+; offset the flags by this amount when drawing units
+flag_offset_x = 17
+flag_offset_y = 11
+
; Font to use to draw city names:
city_names_font = "9x15bold"
@@ -45,7 +49,7 @@
"isotrident/tiles.spec",
"isotrident/small.spec",
"isotrident/units.spec",
- "isotrident/flags.spec",
+ "trident/flags.spec",
"misc/buildings.spec",
"misc/space.spec",
; "misc/techs.spec",
[Freeciv-Dev] (PR#4576) remove sprite padding for flags, Jason Short, 2003/07/18
|
|