Author: sveinung Date: Wed Aug 3 10:33:47 2016 New Revision: 33436 URL: http://svn.gna.org/viewcvs/freeciv?rev=33436&view=rev Log: Gtk 3 clients: standardize unit selection icon.
Standardize on the unit selection dialog's unit icon in unit selection items. Use it in the transport dialog and in the action selection dialog's unit target switcher. (The last two both use the unit selects unit dialog) This adds information like nationality, hit points and veteran status to the transport dialog and in the action selection dialog. It therefore becomes easier to tell the units apart. See patch #7531 Modified: trunk/client/gui-gtk-3.0/unitselect.c trunk/client/gui-gtk-3.0/unitselect.h trunk/client/gui-gtk-3.0/unitselunitdlg.c trunk/client/gui-gtk-3.x/unitselect.c trunk/client/gui-gtk-3.x/unitselect.h trunk/client/gui-gtk-3.x/unitselunitdlg.c Modified: trunk/client/gui-gtk-3.0/unitselect.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/unitselect.c?rev=33436&r1=33435&r2=33436&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/unitselect.c (original) +++ trunk/client/gui-gtk-3.0/unitselect.c Wed Aug 3 10:33:47 2016 @@ -761,6 +761,28 @@ -1); } +/************************************************************************** + Get an unit selection list item suitable image of the specified unit. + + Caller is responsible for getting rid of the returned image after use. +**************************************************************************/ +GdkPixbuf *usdlg_get_unit_image(const struct unit *punit) +{ + GdkPixbuf *out; + struct canvas canvas_store = FC_STATIC_CANVAS_INIT; + + canvas_store.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + tileset_full_tile_width(tileset), tileset_full_tile_height(tileset)); + + put_unit(punit, &canvas_store, 1.0, 0, 0); + out = surface_get_pixbuf(canvas_store.surface, + tileset_full_tile_width(tileset), + tileset_full_tile_height(tileset)); + cairo_surface_destroy(canvas_store.surface); + + return out; +} + /***************************************************************************** Append units (recursively). *****************************************************************************/ @@ -789,17 +811,7 @@ gtk_tree_store_append(GTK_TREE_STORE(store), it, parent); /* Unit gfx */ - { - struct canvas canvas_store = FC_STATIC_CANVAS_INIT; - - canvas_store.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - tileset_full_tile_width(tileset), tileset_full_tile_height(tileset)); - - put_unit(punit, &canvas_store, 1.0, 0, 0); - pix = surface_get_pixbuf(canvas_store.surface, tileset_full_tile_width(tileset), - tileset_full_tile_height(tileset)); - cairo_surface_destroy(canvas_store.surface); - } + pix = usdlg_get_unit_image(punit); phome = game_city_by_number(punit->homecity); if (phome) { Modified: trunk/client/gui-gtk-3.0/unitselect.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/unitselect.h?rev=33436&r1=33435&r2=33436&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/unitselect.h (original) +++ trunk/client/gui-gtk-3.0/unitselect.h Wed Aug 3 10:33:47 2016 @@ -21,4 +21,6 @@ void unit_select_dialog_popdown(void); +GdkPixbuf *usdlg_get_unit_image(const struct unit *punit); + #endif /* FC__UNITSELECT_H */ Modified: trunk/client/gui-gtk-3.0/unitselunitdlg.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/unitselunitdlg.c?rev=33436&r1=33435&r2=33436&view=diff ============================================================================== --- trunk/client/gui-gtk-3.0/unitselunitdlg.c (original) +++ trunk/client/gui-gtk-3.0/unitselunitdlg.c Wed Aug 3 10:33:47 2016 @@ -29,10 +29,11 @@ #include "control.h" #include "tilespec.h" -/* client/gui-gtk-3.x */ +/* client/gui-gtk-3.0 */ #include "gui_main.h" #include "gui_stuff.h" #include "sprite.h" +#include "unitselect.h" #include "unitselunitdlg.h" @@ -127,6 +128,8 @@ tcount = 0; unit_list_iterate(potential_tgt_units, ptgt) { + GdkPixbuf *tubuf; + struct unit_type *tgt_type = unit_type_get(ptgt); struct unit_sel_unit_cb_data *cbdata = fc_malloc(sizeof(struct unit_sel_unit_cb_data)); @@ -145,9 +148,10 @@ G_CALLBACK(unit_sel_unit_destroyed), cbdata); gtk_grid_attach(GTK_GRID(box), radio, 0, tcount, 1, 1); - spr = get_unittype_sprite(tileset, tgt_type, direction8_invalid()); - if (spr != NULL) { - icon = gtk_image_new_from_pixbuf(sprite_get_pixbuf(spr)); + tubuf = usdlg_get_unit_image(ptgt); + if (tubuf != NULL) { + icon = gtk_image_new_from_pixbuf(tubuf); + g_object_unref(tubuf); } else { icon = gtk_image_new(); } Modified: trunk/client/gui-gtk-3.x/unitselect.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.x/unitselect.c?rev=33436&r1=33435&r2=33436&view=diff ============================================================================== --- trunk/client/gui-gtk-3.x/unitselect.c (original) +++ trunk/client/gui-gtk-3.x/unitselect.c Wed Aug 3 10:33:47 2016 @@ -761,6 +761,28 @@ -1); } +/************************************************************************** + Get an unit selection list item suitable image of the specified unit. + + Caller is responsible for getting rid of the returned image after use. +**************************************************************************/ +GdkPixbuf *usdlg_get_unit_image(const struct unit *punit) +{ + GdkPixbuf *out; + struct canvas canvas_store = FC_STATIC_CANVAS_INIT; + + canvas_store.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + tileset_full_tile_width(tileset), tileset_full_tile_height(tileset)); + + put_unit(punit, &canvas_store, 1.0, 0, 0); + out = surface_get_pixbuf(canvas_store.surface, + tileset_full_tile_width(tileset), + tileset_full_tile_height(tileset)); + cairo_surface_destroy(canvas_store.surface); + + return out; +} + /***************************************************************************** Append units (recursively). *****************************************************************************/ @@ -789,17 +811,7 @@ gtk_tree_store_append(GTK_TREE_STORE(store), it, parent); /* Unit gfx */ - { - struct canvas canvas_store = FC_STATIC_CANVAS_INIT; - - canvas_store.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - tileset_full_tile_width(tileset), tileset_full_tile_height(tileset)); - - put_unit(punit, &canvas_store, 1.0, 0, 0); - pix = surface_get_pixbuf(canvas_store.surface, tileset_full_tile_width(tileset), - tileset_full_tile_height(tileset)); - cairo_surface_destroy(canvas_store.surface); - } + pix = usdlg_get_unit_image(punit); phome = game_city_by_number(punit->homecity); if (phome) { Modified: trunk/client/gui-gtk-3.x/unitselect.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.x/unitselect.h?rev=33436&r1=33435&r2=33436&view=diff ============================================================================== --- trunk/client/gui-gtk-3.x/unitselect.h (original) +++ trunk/client/gui-gtk-3.x/unitselect.h Wed Aug 3 10:33:47 2016 @@ -21,4 +21,6 @@ void unit_select_dialog_popdown(void); +GdkPixbuf *usdlg_get_unit_image(const struct unit *punit); + #endif /* FC__UNITSELECT_H */ Modified: trunk/client/gui-gtk-3.x/unitselunitdlg.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.x/unitselunitdlg.c?rev=33436&r1=33435&r2=33436&view=diff ============================================================================== --- trunk/client/gui-gtk-3.x/unitselunitdlg.c (original) +++ trunk/client/gui-gtk-3.x/unitselunitdlg.c Wed Aug 3 10:33:47 2016 @@ -33,6 +33,7 @@ #include "gui_main.h" #include "gui_stuff.h" #include "sprite.h" +#include "unitselect.h" #include "unitselunitdlg.h" @@ -127,6 +128,8 @@ tcount = 0; unit_list_iterate(potential_tgt_units, ptgt) { + GdkPixbuf *tubuf; + struct unit_type *tgt_type = unit_type_get(ptgt); struct unit_sel_unit_cb_data *cbdata = fc_malloc(sizeof(struct unit_sel_unit_cb_data)); @@ -145,9 +148,10 @@ G_CALLBACK(unit_sel_unit_destroyed), cbdata); gtk_grid_attach(GTK_GRID(box), radio, 0, tcount, 1, 1); - spr = get_unittype_sprite(tileset, tgt_type, direction8_invalid()); - if (spr != NULL) { - icon = gtk_image_new_from_pixbuf(sprite_get_pixbuf(spr)); + tubuf = usdlg_get_unit_image(ptgt); + if (tubuf != NULL) { + icon = gtk_image_new_from_pixbuf(tubuf); + g_object_unref(tubuf); } else { icon = gtk_image_new(); } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits