Author: sveinung
Date: Wed Aug  3 10:34:49 2016
New Revision: 33437

URL: http://svn.gna.org/viewcvs/freeciv?rev=33437&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:
    branches/S2_6/client/gui-gtk-3.0/unitselect.c
    branches/S2_6/client/gui-gtk-3.0/unitselect.h
    branches/S2_6/client/gui-gtk-3.0/unitselunitdlg.c

Modified: branches/S2_6/client/gui-gtk-3.0/unitselect.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/unitselect.c?rev=33437&r1=33436&r2=33437&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/unitselect.c       (original)
+++ branches/S2_6/client/gui-gtk-3.0/unitselect.c       Wed Aug  3 10:34:49 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: branches/S2_6/client/gui-gtk-3.0/unitselect.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/unitselect.h?rev=33437&r1=33436&r2=33437&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/unitselect.h       (original)
+++ branches/S2_6/client/gui-gtk-3.0/unitselect.h       Wed Aug  3 10:34:49 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: branches/S2_6/client/gui-gtk-3.0/unitselunitdlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/unitselunitdlg.c?rev=33437&r1=33436&r2=33437&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/unitselunitdlg.c   (original)
+++ branches/S2_6/client/gui-gtk-3.0/unitselunitdlg.c   Wed Aug  3 10:34:49 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"
 
@@ -128,6 +129,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));
@@ -146,10 +149,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(), TRUE);
-    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

Reply via email to