Author: cazfi
Date: Tue Oct 25 06:47:49 2016
New Revision: 34241

URL: http://svn.gna.org/viewcvs/freeciv?rev=34241&view=rev
Log:
Turned GtkPixcomms in happiness dialog to GtkImage

See patch #7102

Modified:
    branches/S2_6/client/gui-gtk-3.22/happiness.c

Modified: branches/S2_6/client/gui-gtk-3.22/happiness.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.22/happiness.c?rev=34241&r1=34240&r2=34241&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.22/happiness.c       (original)
+++ branches/S2_6/client/gui-gtk-3.22/happiness.c       Tue Oct 25 06:47:49 2016
@@ -42,8 +42,8 @@
 /* semi-arbitrary number that controls the width of the happiness widget */
 #define HAPPINESS_PIX_WIDTH 30
 
-#define        PIXCOMM_WIDTH   (HAPPINESS_PIX_WIDTH * 
tileset_small_sprite_width(tileset))
-#define        PIXCOMM_HEIGHT  (tileset_small_sprite_height(tileset))
+#define        FEELING_WIDTH   (HAPPINESS_PIX_WIDTH * 
tileset_small_sprite_width(tileset))
+#define        FEELING_HEIGHT  (tileset_small_sprite_height(tileset))
 
 #define NUM_HAPPINESS_MODIFIERS 6
 
@@ -53,7 +53,8 @@
   struct city *pcity;
   GtkWidget *shell;
   GtkWidget *cityname_label;
-  GtkWidget *hpixmaps[NUM_HAPPINESS_MODIFIERS];
+  cairo_surface_t *feeling_surfaces[NUM_HAPPINESS_MODIFIERS];
+  GtkWidget *feeling_images[NUM_HAPPINESS_MODIFIERS];
   GtkWidget *happiness_ebox[NUM_HAPPINESS_MODIFIERS];
   GtkWidget *happiness_label[NUM_HAPPINESS_MODIFIERS];
   GtkWidget *close;
@@ -228,6 +229,8 @@
   gtk_container_add(GTK_CONTAINER(pdialog->cityname_label), table);
 
   for (i = 0; i < NUM_HAPPINESS_MODIFIERS; i++) {
+    GdkPixbuf *pb;
+
     /* set spacing between lines of citizens*/
 
     /* happiness labels */
@@ -248,10 +251,14 @@
                      G_CALLBACK(show_happiness_popup), GUINT_TO_POINTER(i));
     pdialog->happiness_ebox[i] = ebox;
 
-    pdialog->hpixmaps[i] = gtk_pixcomm_new(PIXCOMM_WIDTH, PIXCOMM_HEIGHT);
-    gtk_container_add(GTK_CONTAINER(ebox), pdialog->hpixmaps[i]);
-    gtk_widget_set_halign(pdialog->hpixmaps[i], GTK_ALIGN_START);
-    gtk_widget_set_valign(pdialog->hpixmaps[i], GTK_ALIGN_START);
+    pdialog->feeling_surfaces[i] = 
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+                                                              FEELING_WIDTH, 
FEELING_HEIGHT);
+    pb = surface_get_pixbuf(pdialog->feeling_surfaces[i], FEELING_WIDTH, 
FEELING_HEIGHT);
+    pdialog->feeling_images[i] = gtk_image_new_from_pixbuf(pb);
+    g_object_unref(pb);
+    gtk_container_add(GTK_CONTAINER(ebox), pdialog->feeling_images[i]);
+    gtk_widget_set_halign(pdialog->feeling_images[i], GTK_ALIGN_START);
+    gtk_widget_set_valign(pdialog->feeling_images[i], GTK_ALIGN_START);
 
     gtk_grid_attach(GTK_GRID(table), ebox, 1, i, 1, 1);
   }
@@ -275,22 +282,28 @@
 }
 
 /**************************************************************************
-  Refresh citizens pixcomm
-**************************************************************************/
-static void refresh_pixcomm(GtkPixcomm *dst, struct city *pcity,
-                            enum citizen_feeling index)
+  Refresh citizens surface
+**************************************************************************/
+static void refresh_feeling_surface(cairo_surface_t *dst, struct city *pcity,
+                                    enum citizen_feeling index)
 {
   enum citizen_category categories[MAX_CITY_SIZE];
   int i;
   int num_citizens = get_city_citizen_types(pcity, index, categories);
-  int offset = MIN(tileset_small_sprite_width(tileset), PIXCOMM_WIDTH / 
num_citizens);
-
-  gtk_pixcomm_clear(dst);
+  int offset = MIN(tileset_small_sprite_width(tileset), FEELING_WIDTH / 
num_citizens);
+  cairo_t *cr;
+
+  cr = cairo_create(dst);
 
   for (i = 0; i < num_citizens; i++) {
-    gtk_pixcomm_copyto(dst, get_citizen_sprite(tileset, categories[i], i, 
pcity),
-                       i * offset, 0);
-  }
+    cairo_set_source_surface(cr,
+                             get_citizen_sprite(tileset, categories[i], i, 
pcity)->surface,
+                             i * offset, 0);
+    cairo_rectangle(cr, i * offset, 0, offset, FEELING_HEIGHT);
+    cairo_fill(cr);
+  }
+
+  cairo_destroy(cr);
 }
 
 /**************************************************************************
@@ -302,7 +315,13 @@
   struct happiness_dialog *pdialog = get_happiness_dialog(pcity);
 
   for (i = 0; i < FEELING_LAST; i++) {
-    refresh_pixcomm(GTK_PIXCOMM(pdialog->hpixmaps[i]), pdialog->pcity, i);
+    GdkPixbuf *pb;
+
+    refresh_feeling_surface(pdialog->feeling_surfaces[i], pdialog->pcity, i);
+
+    pb = surface_get_pixbuf(pdialog->feeling_surfaces[i], FEELING_WIDTH, 
FEELING_HEIGHT);
+    gtk_image_set_from_pixbuf(GTK_IMAGE(pdialog->feeling_images[i]), pb);
+    g_object_unref(pb);
   }
 }
 
@@ -312,6 +331,8 @@
 void close_happiness_dialog(struct city *pcity)
 {
   struct happiness_dialog *pdialog = get_happiness_dialog(pcity);
+  int i;
+
   if (pdialog == NULL) {
     /* City which is being investigated doesn't contain happiness tab */
     return;
@@ -322,6 +343,11 @@
   dialog_list_remove(dialog_list, pdialog);
 
   gtk_widget_destroy(pdialog->shell);
+
+  for (i = 0; i < NUM_HAPPINESS_MODIFIERS; i++) {
+    cairo_surface_destroy(pdialog->feeling_surfaces[i]);
+  }
+
   free(pdialog);
 }
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to