Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2716) get_citizen_pixmap is bad (gtk2)
Home

[Freeciv-Dev] (PR#2716) get_citizen_pixmap is bad (gtk2)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2716) get_citizen_pixmap is bad (gtk2)
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Fri, 3 Jan 2003 23:30:56 -0800
Reply-to: rt@xxxxxxxxxxxxxx

This patch removes the use of get_citizen_pixmap for gui-gtk-2.0.

jason


Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.37
diff -u -r1.37 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       2003/01/01 21:16:44     1.37
+++ client/gui-gtk-2.0/gui_main.c       2003/01/04 07:27:52
@@ -644,6 +644,7 @@
   GtkWidget *frame, *table, *paned, *menubar, *sw, *text;
   GtkStyle *style;
   int i;
+  struct Sprite *sprite;
 
   /* the window is divided into two panes. "top" and "message window" */ 
   paned = gtk_vpaned_new();
@@ -732,8 +733,8 @@
     g_signal_connect(ebox, "button_press_event",
                      G_CALLBACK(taxrates_callback), GINT_TO_POINTER(i));
 
-    econ_label[i] = gtk_image_new_from_pixmap(get_citizen_pixmap(c, i, NULL),
-                                             NULL);
+    sprite = get_citizen_sprite(c, i, NULL);
+    econ_label[i] = gtk_image_new_from_pixmap(sprite->pixmap, sprite->mask);
     gtk_container_add(GTK_CONTAINER(ebox), econ_label[i]);
   }
 
@@ -741,9 +742,8 @@
   bulb_label = gtk_image_new_from_pixmap(sprites.bulb[0]->pixmap, NULL);
   sun_label = gtk_image_new_from_pixmap(sprites.warming[0]->pixmap, NULL);
   flake_label = gtk_image_new_from_pixmap(sprites.cooling[0]->pixmap, NULL);
-  government_label
-    = gtk_image_new_from_pixmap(get_citizen_pixmap(CITIZEN_UNHAPPY, 0, NULL),
-                               NULL);
+  sprite = get_citizen_sprite(CITIZEN_UNHAPPY, 0, NULL);
+  government_label = gtk_image_new_from_pixmap(sprite->pixmap, sprite->mask);
 
   for (i = 0; i < 4; i++) {
     GtkWidget *w;
Index: client/gui-gtk-2.0/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/happiness.c,v
retrieving revision 1.6
diff -u -r1.6 happiness.c
--- client/gui-gtk-2.0/happiness.c      2002/12/15 22:43:47     1.6
+++ client/gui-gtk-2.0/happiness.c      2003/01/04 07:27:52
@@ -158,10 +158,9 @@
   get_city_citizen_types(pcity, index, citizens);
 
   for (i = 0; i < num_citizens; i++) {
-    gdk_draw_pixmap(happiness_pixmap, civ_gc,
-                   get_citizen_pixmap(citizens[i], i, pcity),
-                   0, 0, i * offset, 0, SMALL_TILE_WIDTH,
-                   SMALL_TILE_HEIGHT);
+    pixmap_put_sprite_full(happiness_pixmap,
+                          i * offset, 0,
+                          get_citizen_sprite(citizens[i], i, pcity));
   }
 
   return happiness_pixmap;
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.34
diff -u -r1.34 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/01/01 11:51:33     1.34
+++ client/gui-gtk-2.0/mapview.c        2003/01/04 07:27:53
@@ -354,20 +354,24 @@
                      game.player_ptr->government);
 
   d=0;
-  for(;d<(game.player_ptr->economic.luxury)/10;d++)
+  for (; d < game.player_ptr->economic.luxury /10; d++) {
+    struct Sprite *sprite = get_citizen_sprite(CITIZEN_ELVIS, d, NULL);
     gtk_image_set_from_pixmap(GTK_IMAGE(econ_label[d]),
-                             get_citizen_pixmap(CITIZEN_ELVIS, d, NULL),
-                             NULL);
+                             sprite->pixmap, sprite->mask);
+  }
  
-  
for(;d<(game.player_ptr->economic.science+game.player_ptr->economic.luxury)/10;d++)
+  for (; d < (game.player_ptr->economic.science
+            + game.player_ptr->economic.luxury) / 10; d++) {
+    struct Sprite *sprite = get_citizen_sprite(CITIZEN_SCIENTIST, d, NULL);
     gtk_image_set_from_pixmap(GTK_IMAGE(econ_label[d]),
-                             get_citizen_pixmap(CITIZEN_SCIENTIST, d, NULL),
-                             NULL);
+                             sprite->pixmap, sprite->mask);
+  }
  
-   for(;d<10;d++)
+  for (; d < 10; d++) {
+    struct Sprite *sprite = get_citizen_sprite(CITIZEN_TAXMAN, d, NULL);
     gtk_image_set_from_pixmap(GTK_IMAGE(econ_label[d]),
-                             get_citizen_pixmap(CITIZEN_TAXMAN, d, NULL),
-                             NULL);
+                             sprite->pixmap, sprite->mask);
+  }
  
   update_timeout_label();
 }
@@ -447,15 +451,6 @@
 /**************************************************************************
 ...
 **************************************************************************/
-GdkPixmap *get_citizen_pixmap(enum citizen_type type, int cnum,
-                             struct city *pcity)
-{
-  return get_citizen_sprite(type, cnum, pcity)->pixmap;
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 void set_indicator_icons(int bulb, int sol, int flake, int gov)
 {
   struct Sprite *gov_sprite;
@@ -1384,6 +1379,40 @@
 }
 
 /**************************************************************************
+  Place part of a (possibly masked) sprite on a pixmap.
+**************************************************************************/
+static void pixmap_put_sprite(GdkDrawable *pixmap,
+                             int pixmap_x, int pixmap_y,
+                             struct Sprite *ssprite,
+                             int offset_x, int offset_y,
+                             int width, int height)
+{
+  if (ssprite->mask) {
+    gdk_gc_set_clip_origin(civ_gc, pixmap_x, pixmap_y);
+    gdk_gc_set_clip_mask(civ_gc, ssprite->mask);
+  }
+
+  gdk_draw_pixmap(pixmap, civ_gc, ssprite->pixmap,
+                 offset_x, offset_y,
+                 pixmap_x + offset_x, pixmap_y + offset_y,
+                 MIN(width, MAX(0, ssprite->width - offset_x)),
+                 MIN(height, MAX(0, ssprite->height - offset_y)));
+
+  gdk_gc_set_clip_mask(civ_gc, NULL);
+}
+
+/**************************************************************************
+  Place a (possibly masked) sprite on a pixmap.
+**************************************************************************/
+void pixmap_put_sprite_full(GdkDrawable *pixmap,
+                           int pixmap_x, int pixmap_y,
+                           struct Sprite *ssprite)
+{
+  pixmap_put_sprite(pixmap, pixmap_x, pixmap_y, ssprite,
+                   0, 0, ssprite->width, ssprite->height);
+}
+
+/**************************************************************************
 Only used for isometric view.
 **************************************************************************/
 static void pixmap_put_overlay_tile_draw(GdkDrawable *pixmap,
@@ -1395,16 +1424,9 @@
 {
   if (!ssprite || !width || !height)
     return;
-
-  gdk_gc_set_clip_origin(civ_gc, canvas_x, canvas_y);
-  gdk_gc_set_clip_mask(civ_gc, ssprite->mask);
 
-  gdk_draw_pixmap(pixmap, civ_gc, ssprite->pixmap,
-                 offset_x, offset_y,
-                 canvas_x+offset_x, canvas_y+offset_y,
-                 MIN(width, MAX(0, ssprite->width-offset_x)),
-                 MIN(height, MAX(0, ssprite->height-offset_y)));
-  gdk_gc_set_clip_mask(civ_gc, NULL);
+  pixmap_put_sprite(pixmap, canvas_x, canvas_y, ssprite,
+                   offset_x, offset_y, width, height);
 
   /* I imagine this could be done more efficiently. Some pixels We first
      draw from the sprite, and then draw black afterwards. It would be much
Index: client/gui-gtk-2.0/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.h,v
retrieving revision 1.6
diff -u -r1.6 mapview.h
--- client/gui-gtk-2.0/mapview.h        2002/12/13 19:15:12     1.6
+++ client/gui-gtk-2.0/mapview.h        2003/01/04 07:27:53
@@ -27,8 +27,6 @@
 struct city;
 
 GdkPixmap *get_thumb_pixmap(int onoff);
-GdkPixmap *get_citizen_pixmap(enum citizen_type type, int cnum,
-                             struct city *pcity);
 
 gboolean overview_canvas_expose(GtkWidget *w, GdkEventExpose *ev, gpointer 
data);
 gboolean map_canvas_expose(GtkWidget *w, GdkEventExpose *ev, gpointer data);
@@ -48,6 +46,10 @@
                     int canvas_x, int canvas_y, int citymode);
 void pixmap_put_black_tile(GdkDrawable *pm,
                           int canvas_x, int canvas_y);
+
+void pixmap_put_sprite_full(GdkDrawable *pixmap,
+                           int pixmap_x, int pixmap_y,
+                           struct Sprite *ssprite);
 
 void scrollbar_jump_callback(GtkAdjustment *adj, gpointer hscrollbar);
 void update_map_canvas_scrollbars_size(void);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2716) get_citizen_pixmap is bad (gtk2), Jason Short via RT <=