Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9473) new function put_drawn_sprites
Home

[Freeciv-Dev] (PR#9473) new function put_drawn_sprites

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9473) new function put_drawn_sprites
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 Jul 2004 00:19:36 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9473 >

This patch adds a new function to mapview_common put_drawn_sprites(). 
This is called from put_one_tile_iso (or pixmap_put_tile_iso).  In turn 
it then calls canvas_put_sprite_fogged, which is a new (and necessary) 
canvas function.

This removes some duplication of code across GUIs, and is a step toward 
the unification of the once-formidable put_one_tile_iso.

canvas_put_sprite_fogged gets two parameters (fog_x,fog_y), which are 
currently unused.  However they are needed for the correct 
implementation of this function when using stippling.  The 
implementation in CVS now is buggy.

I added the canvas_put_sprite_full function to the gtk, gtk2, xaw, and 
win32 clients.  It's not implemented for the xaw client which doesn't 
yet support iso-view.  I tested the gtk and gtk2 clients but couldn't 
get the win32 client to configure, so it's untested.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.135
diff -u -r1.135 mapview_common.c
--- client/mapview_common.c     25 Jun 2004 16:38:48 -0000      1.135
+++ client/mapview_common.c     22 Jul 2004 07:06:36 -0000
@@ -1169,6 +1169,41 @@
 }
 
 /**************************************************************************
+  Draw an array of drawn sprites onto the canvas.
+**************************************************************************/
+void put_drawn_sprites(struct canvas *pcanvas,
+                      int canvas_x, int canvas_y,
+                      int count, struct drawn_sprite *pdrawn, bool fog,
+                      int map_x, int map_y, bool citymode)
+{
+  int i;
+
+  for (i = 0; i < count; i++) {
+    int ox = pdrawn[i].offset_x, oy = pdrawn[i].offset_y, dx, dy;
+
+    switch (pdrawn[i].type) {
+    case DRAWN_SPRITE:
+      if (pdrawn[i].style == DRAW_FULL) {
+       dx = UNIT_TILE_WIDTH - NORMAL_TILE_WIDTH;
+       dy = UNIT_TILE_HEIGHT - NORMAL_TILE_HEIGHT;
+      } else {
+       dx = dy = 0;
+      }
+      canvas_put_sprite_fogged(pcanvas,
+                              canvas_x + ox - dx, canvas_y + oy - dy,
+                              pdrawn[i].sprite,
+                              fog && pdrawn[i].foggable,
+                              canvas_x, canvas_y);
+      break;
+    case DRAWN_GRID:
+      /*** Grid (map grid, borders, coastline, etc.) ***/
+      tile_draw_grid(pcanvas, map_x, map_y, canvas_x, canvas_y, citymode);
+      break;
+    }
+  }
+}
+
+/**************************************************************************
   Draw the given map tile at the given canvas position in non-isometric
   view.
 **************************************************************************/
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.70
diff -u -r1.70 mapview_common.h
--- client/mapview_common.h     25 Jun 2004 13:53:25 -0000      1.70
+++ client/mapview_common.h     22 Jul 2004 07:06:36 -0000
@@ -19,6 +19,8 @@
 
 #include "colors_g.h"
 
+#include "tilespec.h"
+
 struct unit;
 
 struct canvas_store;           /* opaque type, real type is gui-dep */
@@ -158,6 +160,10 @@
 
 void put_nuke_mushroom_pixmaps(int map_x, int map_y);
 
+void put_drawn_sprites(struct canvas *pcanvas,
+                      int canvas_x, int canvas_y,
+                      int count, struct drawn_sprite *pdrawn, bool fog,
+                      int map_x, int map_y, bool citymode);
 void put_one_tile(struct canvas *pcanvas, int map_x, int map_y,
                  int canvas_x, int canvas_y, bool citymode);
 void tile_draw_grid(struct canvas *pcanvas, int map_x, int map_y,
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.227
diff -u -r1.227 mapview.c
--- client/gui-gtk/mapview.c    22 Jul 2004 05:42:47 -0000      1.227
+++ client/gui-gtk/mapview.c    22 Jul 2004 07:06:36 -0000
@@ -679,6 +679,19 @@
                    0, 0, sprite->width, sprite->height);
 }
 
+/****************************************************************************
+  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
+  fog.
+****************************************************************************/
+void canvas_put_sprite_fogged(struct canvas *pcanvas,
+                             int canvas_x, int canvas_y,
+                             struct Sprite *psprite,
+                             bool fog, int fog_x, int fog_y)
+{
+  pixmap_put_overlay_tile_draw(pcanvas->pixmap, canvas_x, canvas_y,
+                              psprite, fog);
+}
+
 /**************************************************************************
   Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
 **************************************************************************/
@@ -883,21 +896,6 @@
 }
 
 /**************************************************************************
-  Put a drawn sprite (with given offset) onto the pixmap.
-**************************************************************************/
-static void pixmap_put_drawn_sprite(GdkDrawable *pixmap,
-                                   int canvas_x, int canvas_y,
-                                   struct drawn_sprite *pdsprite,
-                                   bool fog)
-{
-  int ox = pdsprite->offset_x, oy = pdsprite->offset_y;
-
-  pixmap_put_overlay_tile_draw(pixmap, canvas_x + ox, canvas_y + oy,
-                              pdsprite->sprite,
-                              fog);
-}
-
-/**************************************************************************
 Only used for isometric view.
 **************************************************************************/
 static void pixmap_put_black_tile_iso(GdkDrawable *pm,
@@ -926,7 +924,7 @@
                                int citymode)
 {
   struct drawn_sprite tile_sprs[80];
-  int count, i;
+  int count;
   bool solid_bg, fog;
   enum color_std bg_color;
   struct canvas canvas_store = {pm};
@@ -970,29 +968,8 @@
     }
   }
 
-  /*** Draw terrain and specials ***/
-  for (i = 0; i < count; i++) {
-    switch (tile_sprs[i].type) {
-    case DRAWN_SPRITE:
-      switch (tile_sprs[i].style) {
-      case DRAW_NORMAL:
-       pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &tile_sprs[i],
-                               fog && tile_sprs[i].foggable);
-       break;
-      case DRAW_FULL:
-       pixmap_put_drawn_sprite(pm, canvas_x,
-                               canvas_y - NORMAL_TILE_HEIGHT / 2,
-                               &tile_sprs[i],
-                               fog && tile_sprs[i].foggable);
-       break;
-      }
-      break;
-    case DRAWN_GRID:
-      /*** Grid (map grid, borders, coastline, etc.) ***/
-      tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y, citymode);
-      break;
-    }
-  }
+  put_drawn_sprites(&canvas_store, canvas_x, canvas_y,
+                   count, tile_sprs, fog, x, y, citymode);
 }
 
 /**************************************************************************
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.133
diff -u -r1.133 mapview.c
--- client/gui-gtk-2.0/mapview.c        22 Jul 2004 05:42:47 -0000      1.133
+++ client/gui-gtk-2.0/mapview.c        22 Jul 2004 07:06:36 -0000
@@ -720,6 +720,19 @@
                    0, 0, sprite->width, sprite->height);
 }
 
+/****************************************************************************
+  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
+  fog.
+****************************************************************************/
+void canvas_put_sprite_fogged(struct canvas *pcanvas,
+                             int canvas_x, int canvas_y,
+                             struct Sprite *psprite,
+                             bool fog, int fog_x, int fog_y)
+{
+  pixmap_put_overlay_tile_draw(pcanvas->v.pixmap, canvas_x, canvas_y,
+                              psprite, fog);
+}
+
 /**************************************************************************
   Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
 **************************************************************************/
@@ -947,21 +960,6 @@
 }
 
 /**************************************************************************
-  Put a drawn sprite (with given offset) onto the pixmap.
-**************************************************************************/
-static void pixmap_put_drawn_sprite(GdkDrawable *pixmap,
-                                   int canvas_x, int canvas_y,
-                                   struct drawn_sprite *pdsprite,
-                                   bool fog)
-{
-  int ox = pdsprite->offset_x, oy = pdsprite->offset_y;
-
-  pixmap_put_overlay_tile_draw(pixmap, canvas_x + ox, canvas_y + oy,
-                              pdsprite->sprite,
-                              fog);
-}
-
-/**************************************************************************
 Only used for isometric view.
 **************************************************************************/
 static void pixmap_put_black_tile_iso(GdkDrawable *pm,
@@ -990,7 +988,7 @@
                                int citymode)
 {
   struct drawn_sprite tile_sprs[80];
-  int count, i;
+  int count;
   bool solid_bg, fog;
   enum color_std bg_color;
   struct canvas canvas_store = {.type = CANVAS_PIXMAP, .v.pixmap = pm};
@@ -1035,28 +1033,8 @@
   }
 
   /*** Draw terrain and specials ***/
-  for (i = 0; i < count; i++) {
-    switch (tile_sprs[i].type) {
-    case DRAWN_SPRITE:
-      switch (tile_sprs[i].style) {
-      case DRAW_NORMAL:
-       pixmap_put_drawn_sprite(pm, canvas_x, canvas_y, &tile_sprs[i],
-                               fog && tile_sprs[i].foggable);
-       break;
-      case DRAW_FULL:
-       pixmap_put_drawn_sprite(pm, canvas_x,
-                               canvas_y - NORMAL_TILE_HEIGHT / 2,
-                               &tile_sprs[i],
-                               fog && tile_sprs[i].foggable);
-       break;
-      }
-      break;
-    case DRAWN_GRID:
-      /*** Grid (map grid, borders, coastline, etc.) ***/
-      tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y, citymode);
-      break;
-    }
-  }
+  put_drawn_sprites(&canvas_store, canvas_x, canvas_y,
+                   count, tile_sprs, fog, x, y, citymode);
 }
 
 /**************************************************************************
Index: client/gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.45
diff -u -r1.45 mapview.c
--- client/gui-stub/mapview.c   23 Jun 2004 14:50:43 -0000      1.45
+++ client/gui-stub/mapview.c   22 Jul 2004 07:06:36 -0000
@@ -178,6 +178,18 @@
 }
 
 /****************************************************************************
+  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
+  fog.
+****************************************************************************/
+void canvas_put_sprite_fogged(struct canvas *pcanvas,
+                             int canvas_x, int canvas_y,
+                             struct Sprite *psprite,
+                             bool fog, int fog_x, int fog_y)
+{
+  /* PORTME */
+}
+
+/****************************************************************************
   Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
 ****************************************************************************/
 void canvas_put_rectangle(struct canvas *pcanvas,
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.128
diff -u -r1.128 mapview.c
--- client/gui-win32/mapview.c  22 Jul 2004 05:42:47 -0000      1.128
+++ client/gui-win32/mapview.c  22 Jul 2004 07:06:37 -0000
@@ -810,6 +810,19 @@
                    0, 0, sprite->width, sprite->height);
 }
 
+/****************************************************************************
+  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
+  fog.
+****************************************************************************/
+void canvas_put_sprite_fogged(struct canvas *pcanvas,
+                             int canvas_x, int canvas_y,
+                             struct Sprite *psprite,
+                             bool fog, int fog_x, int fog_y)
+{
+  pixmap_put_overlay_tile_draw(pcanvas->hdc, canvas_x, canvas_y,
+                              psprite, fog);
+}
+
 /**************************************************************************
   Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
 **************************************************************************/
@@ -878,23 +891,6 @@
 
 }
 
-
-/**************************************************************************
-  Put a drawn sprite (with given offset) onto the pixmap.
-**************************************************************************/
-static void pixmap_put_drawn_sprite(HDC hdc,
-                                    int canvas_x, int canvas_y,
-                                    struct drawn_sprite *pdsprite,
-                                    bool fog)
-{
-  int ox = pdsprite->offset_x, oy = pdsprite->offset_y;
-  
-  
-  pixmap_put_overlay_tile_draw(hdc, canvas_x + ox, canvas_y + oy,
-                               pdsprite->sprite, fog);
-  
-}
-
 /**************************************************************************
 Only used for isometric view.
 **************************************************************************/
@@ -904,7 +900,7 @@
 {
   struct drawn_sprite tile_sprs[80];
   struct canvas canvas_store={hdc,NULL};
-  int count, i;
+  int count;
   bool fog, solid_bg, is_real;
   enum color_std bg_color;
 
@@ -940,26 +936,8 @@
   }
 
   /*** Draw terrain and specials ***/
-  for (i = 0; i < count; i++) {
-    switch (tile_sprs[i].type) {
-    case DRAWN_SPRITE:
-      switch (tile_sprs[i].style) {
-      case DRAW_NORMAL:
-       pixmap_put_drawn_sprite(hdc, canvas_x, canvas_y, &tile_sprs[i],
-                               fog && tile_sprs[i].foggable);
-       break;
-      case DRAW_FULL:
-       pixmap_put_drawn_sprite(hdc,
-                               canvas_x, canvas_y - NORMAL_TILE_HEIGHT / 2,
-                               &tile_sprs[i],
-                               fog && tile_sprs[i].foggable);
-       break;
-      }
-    case DRAWN_GRID:
-      /*** Grid (map grid, borders, coastline, etc.) ***/
-      tile_draw_grid(&canvas_store, x, y, canvas_x, canvas_y, citymode);
-    }
-  }
+  put_drawn_sprites(&canvas_store, canvas_x, canvas_y,
+                   count, tile_sprs, fog, x, y, citymode);
 }
 
 /**************************************************************************
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.177
diff -u -r1.177 mapview.c
--- client/gui-xaw/mapview.c    10 Jul 2004 18:48:19 -0000      1.177
+++ client/gui-xaw/mapview.c    22 Jul 2004 07:06:37 -0000
@@ -436,6 +436,18 @@
                    sprite, 0, 0, sprite->width, sprite->height);
 }
 
+/****************************************************************************
+  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
+  fog.
+****************************************************************************/
+void canvas_put_sprite_fogged(struct canvas *pcanvas,
+                             int canvas_x, int canvas_y,
+                             struct Sprite *psprite,
+                             bool fog, int fog_x, int fog_y)
+{
+  /* PORTME */
+}
+
 /**************************************************************************
   Draw a filled-in colored rectangle onto the mapview or citydialog canvas.
 **************************************************************************/
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.54
diff -u -r1.54 mapview_g.h
--- client/include/mapview_g.h  23 Jun 2004 14:50:44 -0000      1.54
+++ client/include/mapview_g.h  22 Jul 2004 07:06:37 -0000
@@ -46,6 +46,10 @@
 void canvas_put_sprite_full(struct canvas *pcanvas, 
                            int canvas_x, int canvas_y,
                            struct Sprite *sprite);
+void canvas_put_sprite_fogged(struct canvas *pcanvas,
+                             int canvas_x, int canvas_y,
+                             struct Sprite *psprite,
+                             bool fog, int fog_x, int fog_y);
 void canvas_put_rectangle(struct canvas *pcanvas,
                          enum color_std color,
                          int canvas_x, int canvas_y, int width, int height);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9473) new function put_drawn_sprites, Jason Short <=