Author: cazfi
Date: Sun May  1 00:22:32 2016
New Revision: 32534

URL: http://svn.gna.org/viewcvs/freeciv?rev=32534&view=rev
Log:
Replaced GtkPixcomm based citizen bar with GtkImage based one in gtk3- and 
gtk3x-clients.

See patch #7151

Modified:
    trunk/client/gui-gtk-3.0/citydlg.c
    trunk/client/gui-gtk-3.x/citydlg.c

Modified: trunk/client/gui-gtk-3.0/citydlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/citydlg.c?rev=32534&r1=32533&r2=32534&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/citydlg.c  (original)
+++ trunk/client/gui-gtk-3.0/citydlg.c  Sun May  1 00:22:32 2016
@@ -61,7 +61,6 @@
 #include "graphics.h"
 #include "gui_main.h"
 #include "gui_stuff.h"
-#include "gtkpixcomm.h"
 #include "happiness.h"
 #include "helpdlg.h"
 #include "inputdlg.h"
@@ -136,7 +135,8 @@
   GtkWidget *notebook;
 
   GtkWidget *popup_menu;
-  GtkWidget *citizen_pixmap;
+  GtkWidget *citizen_images;
+  cairo_surface_t *citizen_surface;
 
   struct {
     struct city_map_canvas map_canvas;
@@ -1476,9 +1476,11 @@
 static struct city_dialog *create_city_dialog(struct city *pcity)
 {
   struct city_dialog *pdialog;
-
   GtkWidget *close_command;
   GtkWidget *vbox, *hbox, *cbox, *ebox;
+  int citizen_bar_width;
+  int citizen_bar_height;
+  GdkPixbuf *pb;
 
   if (!city_dialogs_have_been_initialised) {
     initialize_city_dialogs();
@@ -1540,18 +1542,24 @@
   ebox = gtk_event_box_new();
   gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE);
   gtk_container_add(GTK_CONTAINER(cbox), ebox);
-  pdialog->citizen_pixmap =
-      gtk_pixcomm_new(tileset_small_sprite_width(tileset)
-                      * NUM_CITIZENS_SHOWN,
-                      tileset_small_sprite_height(tileset));
-  gtk_widget_add_events(pdialog->citizen_pixmap, GDK_BUTTON_PRESS_MASK);
-  gtk_widget_set_margin_left(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_margin_right(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_margin_top(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_margin_bottom(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_halign(pdialog->citizen_pixmap, GTK_ALIGN_START);
-  gtk_widget_set_valign(pdialog->citizen_pixmap, GTK_ALIGN_CENTER);
-  gtk_container_add(GTK_CONTAINER(ebox), pdialog->citizen_pixmap);
+
+  citizen_bar_width = tileset_small_sprite_width(tileset) * NUM_CITIZENS_SHOWN;
+  citizen_bar_height = tileset_small_sprite_height(tileset);
+
+  pdialog->citizen_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+                                                        citizen_bar_width, 
citizen_bar_height);
+  pb = surface_get_pixbuf(pdialog->citizen_surface, citizen_bar_width, 
citizen_bar_height);
+  pdialog->citizen_images = gtk_image_new_from_pixbuf(pb);
+  g_object_unref(pb);
+
+  gtk_widget_add_events(pdialog->citizen_images, GDK_BUTTON_PRESS_MASK);
+  gtk_widget_set_margin_left(pdialog->citizen_images, 2);
+  gtk_widget_set_margin_right(pdialog->citizen_images, 2);
+  gtk_widget_set_margin_top(pdialog->citizen_images, 2);
+  gtk_widget_set_margin_bottom(pdialog->citizen_images, 2);
+  gtk_widget_set_halign(pdialog->citizen_images, GTK_ALIGN_START);
+  gtk_widget_set_valign(pdialog->citizen_images, GTK_ALIGN_CENTER);
+  gtk_container_add(GTK_CONTAINER(ebox), pdialog->citizen_images);
   g_signal_connect(G_OBJECT(ebox), "button-press-event",
                    G_CALLBACK(citizens_callback), pdialog);
 
@@ -1694,11 +1702,13 @@
 static void city_dialog_update_citizens(struct city_dialog *pdialog)
 {
   enum citizen_category categories[MAX_CITY_SIZE];
-  int i, width, size;
-  int start_margin;
-  int end_margin;
+  int i, width;
+  int citizen_bar_width;
+  int citizen_bar_height;
   struct city *pcity = pdialog->pcity;
   int num_citizens = get_city_citizen_types(pcity, FEELING_FINAL, categories);
+  GdkPixbuf *pb;
+  cairo_t *cr;
 
   /* If there is not enough space we stack the icons. We draw from left to */
   /* right. width is how far we go to the right for each drawn pixmap. The */
@@ -1715,19 +1725,24 @@
   pdialog->cwidth = width;
 
   /* overview page */
-  start_margin = gtk_widget_get_margin_left(pdialog->citizen_pixmap);
-  end_margin = gtk_widget_get_margin_right(pdialog->citizen_pixmap);
-  gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->citizen_pixmap));
-
-  size = (num_citizens - 1) * width + tileset_small_sprite_width(tileset) +
-    2 * (start_margin + end_margin);
-  gtk_widget_set_size_request(GTK_WIDGET(pdialog->citizen_pixmap), size, -1);
+  citizen_bar_width = (num_citizens - 1) * width + 
tileset_small_sprite_width(tileset) + 2;
+  citizen_bar_height = tileset_small_sprite_height(tileset);
+
+  cr = cairo_create(pdialog->citizen_surface);
 
   for (i = 0; i < num_citizens; i++) {
-    gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
-                       get_citizen_sprite(tileset, categories[i], i, pcity),
-                       i * width, 0);
-  }
+    cairo_set_source_surface(cr,
+                             get_citizen_sprite(tileset, categories[i], i, 
pcity)->surface,
+                             i * width, 0);
+    cairo_rectangle(cr, i * width, 0, width, citizen_bar_height);
+    cairo_fill(cr);
+  }
+
+  cairo_destroy(cr);
+
+  pb = surface_get_pixbuf(pdialog->citizen_surface, citizen_bar_width, 
citizen_bar_height);
+  gtk_image_set_from_pixbuf(GTK_IMAGE(pdialog->citizen_images), pb);
+  g_object_unref(pb);
 }
 
 /****************************************************************
@@ -3289,6 +3304,7 @@
   }
 
   cairo_surface_destroy(pdialog->map_canvas_store_unscaled);
+  cairo_surface_destroy(pdialog->citizen_surface);
 
   free(pdialog);
 

Modified: trunk/client/gui-gtk-3.x/citydlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.x/citydlg.c?rev=32534&r1=32533&r2=32534&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.x/citydlg.c  (original)
+++ trunk/client/gui-gtk-3.x/citydlg.c  Sun May  1 00:22:32 2016
@@ -61,7 +61,6 @@
 #include "graphics.h"
 #include "gui_main.h"
 #include "gui_stuff.h"
-#include "gtkpixcomm.h"
 #include "happiness.h"
 #include "helpdlg.h"
 #include "inputdlg.h"
@@ -136,7 +135,8 @@
   GtkWidget *notebook;
 
   GtkWidget *popup_menu;
-  GtkWidget *citizen_pixmap;
+  GtkWidget *citizen_images;
+  cairo_surface_t *citizen_surface;
 
   struct {
     struct city_map_canvas map_canvas;
@@ -1479,6 +1479,8 @@
 
   GtkWidget *close_command;
   GtkWidget *vbox, *hbox, *cbox, *ebox;
+  int citizen_bar_width;
+  int citizen_bar_height;
 
   if (!city_dialogs_have_been_initialised) {
     initialize_city_dialogs();
@@ -1540,18 +1542,22 @@
   ebox = gtk_event_box_new();
   gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE);
   gtk_container_add(GTK_CONTAINER(cbox), ebox);
-  pdialog->citizen_pixmap =
-      gtk_pixcomm_new(tileset_small_sprite_width(tileset)
-                      * NUM_CITIZENS_SHOWN,
-                      tileset_small_sprite_height(tileset));
-  gtk_widget_add_events(pdialog->citizen_pixmap, GDK_BUTTON_PRESS_MASK);
-  gtk_widget_set_margin_start(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_margin_end(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_margin_top(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_margin_bottom(pdialog->citizen_pixmap, 2);
-  gtk_widget_set_halign(pdialog->citizen_pixmap, GTK_ALIGN_START);
-  gtk_widget_set_valign(pdialog->citizen_pixmap, GTK_ALIGN_CENTER);
-  gtk_container_add(GTK_CONTAINER(ebox), pdialog->citizen_pixmap);
+
+  citizen_bar_width = tileset_small_sprite_width(tileset) * NUM_CITIZENS_SHOWN;
+  citizen_bar_height = tileset_small_sprite_height(tileset);
+
+  pdialog->citizen_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+                                                        citizen_bar_width, 
citizen_bar_height);
+  pdialog->citizen_images = 
gtk_image_new_from_surface(pdialog->citizen_surface);
+
+  gtk_widget_add_events(pdialog->citizen_images, GDK_BUTTON_PRESS_MASK);
+  gtk_widget_set_margin_start(pdialog->citizen_images, 2);
+  gtk_widget_set_margin_end(pdialog->citizen_images, 2);
+  gtk_widget_set_margin_top(pdialog->citizen_images, 2);
+  gtk_widget_set_margin_bottom(pdialog->citizen_images, 2);
+  gtk_widget_set_halign(pdialog->citizen_images, GTK_ALIGN_START);
+  gtk_widget_set_valign(pdialog->citizen_images, GTK_ALIGN_CENTER);
+  gtk_container_add(GTK_CONTAINER(ebox), pdialog->citizen_images);
   g_signal_connect(G_OBJECT(ebox), "button-press-event",
                    G_CALLBACK(citizens_callback), pdialog);
 
@@ -1692,11 +1698,11 @@
 static void city_dialog_update_citizens(struct city_dialog *pdialog)
 {
   enum citizen_category categories[MAX_CITY_SIZE];
-  int i, width, size;
-  int start_margin;
-  int end_margin;
+  int i, width;
+  int citizen_bar_height;
   struct city *pcity = pdialog->pcity;
   int num_citizens = get_city_citizen_types(pcity, FEELING_FINAL, categories);
+  cairo_t *cr;
 
   /* If there is not enough space we stack the icons. We draw from left to */
   /* right. width is how far we go to the right for each drawn pixmap. The */
@@ -1713,19 +1719,19 @@
   pdialog->cwidth = width;
 
   /* overview page */
-  start_margin = gtk_widget_get_margin_start(pdialog->citizen_pixmap);
-  end_margin = gtk_widget_get_margin_end(pdialog->citizen_pixmap);
-  gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->citizen_pixmap));
-
-  size = (num_citizens - 1) * width + tileset_small_sprite_width(tileset) +
-    2 * (start_margin + end_margin);
-  gtk_widget_set_size_request(GTK_WIDGET(pdialog->citizen_pixmap), size, -1);
+  citizen_bar_height = tileset_small_sprite_height(tileset);
+
+  cr = cairo_create(pdialog->citizen_surface);
 
   for (i = 0; i < num_citizens; i++) {
-    gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
-                       get_citizen_sprite(tileset, categories[i], i, pcity),
-                       i * width, 0);
-  }
+    cairo_set_source_surface(cr,
+                             get_citizen_sprite(tileset, categories[i], i, 
pcity)->surface,
+                             i * width, 0);
+    cairo_rectangle(cr, i * width, 0, width, citizen_bar_height);
+    cairo_fill(cr);
+  }
+
+  cairo_destroy(cr);
 }
 
 /****************************************************************
@@ -3319,6 +3325,7 @@
   }
 
   cairo_surface_destroy(pdialog->map_canvas_store_unscaled);
+  cairo_surface_destroy(pdialog->citizen_surface);
 
   free(pdialog);
 


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

Reply via email to