<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40371 >

Finally figured out a much better way to make the editor
related pixbufs. :]


----------------------------------------------------------------------
特殊学級の学生の中で一番いい頭。
diff --git a/client/gui-gtk-2.0/editgui.c b/client/gui-gtk-2.0/editgui.c
index ccf309e..87419a8 100644
--- a/client/gui-gtk-2.0/editgui.c
+++ b/client/gui-gtk-2.0/editgui.c
@@ -37,6 +37,7 @@
 #include "chatline_common.h"
 #include "civclient.h"
 #include "editor.h"
+#include "mapview_common.h"
 #include "tilespec.h"
 
 #include "canvas.h"
@@ -592,44 +593,28 @@ static void editbar_refresh(struct editbar *eb)
 static GdkPixbuf *create_military_base_pixbuf(const struct base_type *pbase)
 {
   struct drawn_sprite sprs[80];
-  struct sprite *sprite;
-  int count, w, h, i, ox, oy, sw, sh;
-  GdkPixbuf *src_pixbuf, *dest_pixbuf;
+  int count, w, h, canvas_x, canvas_y;
+  GdkPixbuf *pixbuf;
+  struct canvas canvas;
 
   w = tileset_tile_width(tileset);
   h = tileset_tile_height(tileset);
 
-  dest_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
-  if (dest_pixbuf == NULL) {
+  pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
+  if (pixbuf == NULL) {
     return NULL;
   }
+  gdk_pixbuf_fill(pixbuf, 0x00000000);
 
-  gdk_pixbuf_fill(dest_pixbuf, 0x00000000);
+  canvas.type = CANVAS_PIXBUF;
+  canvas.v.pixbuf = pixbuf;
+  canvas_x = 0;
+  canvas_y = 0;
 
   count = fill_basic_base_sprite_array(tileset, sprs, pbase);
+  put_drawn_sprites(&canvas, canvas_x, canvas_y, count, sprs, FALSE);
 
-  for (i = 0; i < count; i++) {
-    sprite = sprs[i].sprite;
-    if (sprite == NULL) {
-      continue;
-    }
-  
-    src_pixbuf = sprite_get_pixbuf(sprite);
-    if (src_pixbuf == NULL) {
-      continue;
-    }
-
-    ox = sprs[i].offset_x;
-    oy = sprs[i].offset_y;
-
-    sw = MIN(w, MAX(0, sprite->width - ox));
-    sh = MIN(h, MAX(0, sprite->height - oy));
-
-    gdk_pixbuf_composite(src_pixbuf, dest_pixbuf, 0.0, 0.0, sw, sh,
-                         ox, oy, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
-  }
-
-  return dest_pixbuf;
+  return pixbuf;
 }
 
 /****************************************************************************
@@ -644,60 +629,31 @@ static GdkPixbuf *create_military_base_pixbuf(const struct base_type *pbase)
 static GdkPixbuf *create_terrain_pixbuf(struct terrain *pterrain)
 {
   struct drawn_sprite sprs[80];
-  struct sprite *sprite;
-  int count, w, h, i, ox, oy, layer, sw, sh;
-  GdkPixbuf *src_pixbuf, *dest_pixbuf;
-
-  freelog(LOG_DEBUG, "create_terrain_pixbuf %s",
-          terrain_name_translation(pterrain));
+  int count, w, h, canvas_x, canvas_y, i;
+  GdkPixbuf *pixbuf;
+  struct canvas canvas;
 
   w = tileset_tile_width(tileset);
   h = tileset_tile_height(tileset);
 
-  freelog(LOG_DEBUG, "  w=%d h=%d", w, h);
-
-  dest_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
-  if (dest_pixbuf == NULL) {
+  pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);
+  if (pixbuf == NULL) {
     return NULL;
   }
+  gdk_pixbuf_fill(pixbuf, 0x00000000);
 
-  gdk_pixbuf_fill(dest_pixbuf, 0x00000000);
+  canvas.type = CANVAS_PIXBUF;
+  canvas.v.pixbuf = pixbuf;
+  canvas_x = 0;
+  canvas_y = 0;
 
-  for (layer = 0; layer < 3; layer++) {
+  for (i = 0; i < 3; i++) {
     count = fill_basic_terrain_layer_sprite_array(tileset, sprs,
-                                                  layer, pterrain);
-    freelog(LOG_DEBUG, "  layer %d count=%d", layer, count);
-
-    for (i = 0; i < count; i++) {
-      freelog(LOG_DEBUG, "    sprs[%d]: sprite=%p", i, sprs[i].sprite);
-
-      sprite = sprs[i].sprite;
-      if (sprite == NULL) {
-        continue;
-      }
-    
-      src_pixbuf = sprite_get_pixbuf(sprite);
-      if (src_pixbuf == NULL) {
-        continue;
-      }
-
-      freelog(LOG_DEBUG, "      foggable=%d ox=%d oy=%d sw=%d sh=%d mask=%p",
-             sprs[i].foggable, sprs[i].offset_x, sprs[i].offset_y,
-             sprite->width, sprite->height, sprite->mask);
-
-      ox = sprs[i].offset_x;
-      oy = sprs[i].offset_y;
-
-      sw = sprite->width;
-      sh = sprite->height;
-
-      gdk_pixbuf_composite(src_pixbuf, dest_pixbuf, ox, oy, sw, sh,
-                           ox, oy, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
-    }
+                                                  i, pterrain);
+    put_drawn_sprites(&canvas, canvas_x, canvas_y, count, sprs, FALSE);
   }
 
-    
-  return dest_pixbuf;
+  return pixbuf;
 }
 
 /****************************************************************************
diff --git a/client/mapview_common.c b/client/mapview_common.c
index a146a2b..52857f3 100644
--- a/client/mapview_common.c
+++ b/client/mapview_common.c
@@ -849,10 +849,10 @@ bool tile_visible_and_not_on_border_mapcanvas(struct tile *ptile)
 /**************************************************************************
   Draw an array of drawn sprites onto the canvas.
 **************************************************************************/
-static void put_drawn_sprites(struct canvas *pcanvas,
-			      int canvas_x, int canvas_y,
-			      int count, struct drawn_sprite *pdrawn,
-			      bool fog)
+void put_drawn_sprites(struct canvas *pcanvas,
+                       int canvas_x, int canvas_y,
+                       int count, struct drawn_sprite *pdrawn,
+                       bool fog)
 {
   int i;
 
diff --git a/client/mapview_common.h b/client/mapview_common.h
index 6d64a2e..6299a97 100644
--- a/client/mapview_common.h
+++ b/client/mapview_common.h
@@ -265,6 +265,11 @@ void put_one_element(struct canvas *pcanvas, enum mapview_layer layer,
 		     int canvas_x, int canvas_y,
 		     const struct city *citymode);
 
+void put_drawn_sprites(struct canvas *pcanvas,
+                       int canvas_x, int canvas_y,
+                       int count, struct drawn_sprite *pdrawn,
+                       bool fog);
+
 void update_map_canvas(int canvas_x, int canvas_y, int width, int height);
 void update_map_canvas_visible(void);
 void update_city_description(struct city *pcity);
diff --git a/client/tilespec.c b/client/tilespec.c
index b2fbd15..8f9b24e 100644
--- a/client/tilespec.c
+++ b/client/tilespec.c
@@ -5057,6 +5057,9 @@ void tileset_init(struct tileset *t)
   Fill the sprite array with sprites that together make a representative
   image of the given terrain type. Suitable for use as an icon and in list
   views.
+
+  NB: The 'layer' argument is NOT a LAYER_* value, but rather one of 0, 1, 2.
+  Using other values for 'layer' here will result in undefined behaviour. ;)
 ****************************************************************************/
 int fill_basic_terrain_layer_sprite_array(struct tileset *t,
                                           struct drawn_sprite *sprs,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to