Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7502) move put_city_tile_output into mapview_common
Home

[Freeciv-Dev] (PR#7502) move put_city_tile_output into mapview_common

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7502) move put_city_tile_output into mapview_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Feb 2004 22:12:28 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch moves put_city_tile_output into mapview_common.  Perfectly 
straightforward.

Tested under gui-gtk-2.0.  Also supported & compiled: gtk, xaw, win32 
clients.

jason

? coasts.diff
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.80
diff -u -r1.80 mapview_common.c
--- client/mapview_common.c     2004/02/24 05:20:24     1.80
+++ client/mapview_common.c     2004/02/24 06:05:51
@@ -665,6 +665,40 @@
 }
 
 /****************************************************************************
+  Draw food, shield, and trade output values on the tile.
+
+  The proper way to do this is probably something like what Civ II does
+  (one sprite drawn N times on top of itself), but we just use separate
+  sprites (limiting the number of combinations).
+****************************************************************************/
+void put_city_tile_output(struct city *pcity, int city_x, int city_y,
+                         struct canvas_store *pcanvas_store,
+                         int canvas_x, int canvas_y)
+{
+  int food = city_get_food_tile(city_x, city_y, pcity);
+  int shields = city_get_shields_tile(city_x, city_y, pcity);
+  int trade = city_get_trade_tile(city_x, city_y, pcity);
+
+  food = CLIP(0, food, NUM_TILES_DIGITS - 1);
+  shields = CLIP(0, shields, NUM_TILES_DIGITS - 1);
+  trade = CLIP(0, trade, NUM_TILES_DIGITS - 1);
+
+  /* In iso-view the output sprite is a bit smaller than the tile, so we
+   * have to use an offset. */
+  if (is_isometric) {
+    canvas_x += NORMAL_TILE_WIDTH / 3;
+    canvas_y -= NORMAL_TILE_HEIGHT / 3;
+  }
+
+  gui_put_sprite_full(pcanvas_store, canvas_x, canvas_y,
+                     sprites.city.tile_foodnum[food]);
+  gui_put_sprite_full(pcanvas_store, canvas_x, canvas_y,
+                     sprites.city.tile_shieldnum[shields]);
+  gui_put_sprite_full(pcanvas_store, canvas_x, canvas_y,
+                     sprites.city.tile_tradenum[trade]);
+}
+
+/****************************************************************************
   Draw food, gold, and shield upkeep values on the unit.
 
   The proper way to do this is probably something like what Civ II does
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.45
diff -u -r1.45 mapview_common.h
--- client/mapview_common.h     2004/02/24 05:20:24     1.45
+++ client/mapview_common.h     2004/02/24 06:05:52
@@ -165,6 +165,10 @@
              int unit_width, int unit_height);
 void put_unit_full(struct unit *punit, struct canvas_store *pcanvas_store,
                   int canvas_x, int canvas_y);
+
+void put_city_tile_output(struct city *pcity, int city_x, int city_y,
+                         struct canvas_store *pcanvas_store,
+                         int canvas_x, int canvas_y);
 void put_unit_city_overlays(struct unit *punit,
                            struct canvas_store *pcanvas_store,
                            int canvas_x, int canvas_y);
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.175
diff -u -r1.175 citydlg.c
--- client/gui-gtk/citydlg.c    2004/01/06 08:11:33     1.175
+++ client/gui-gtk/citydlg.c    2004/02/24 06:05:52
@@ -1762,6 +1762,7 @@
 {
   struct city *pcity = pdialog->pcity;
   int city_x, city_y;
+  struct canvas_store store = {pdialog->map_canvas_store};
 
   gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
 
@@ -1791,11 +1792,7 @@
     if (tile_get_known(map_x, map_y)
        && city_to_canvas_pos(&canvas_x, &canvas_y, x, y)
        && pcity->city_map[x][y] == C_TILE_WORKER) {
-      put_city_tile_output(pdialog->map_canvas_store,
-                          canvas_x, canvas_y,
-                          city_get_food_tile(x, y, pcity),
-                          city_get_shields_tile(x, y, pcity),
-                          city_get_trade_tile(x, y, pcity));
+      put_city_tile_output(pcity, x, y, &store, canvas_x, canvas_y);
     }
   }
   city_map_checked_iterate_end;
@@ -1835,12 +1832,9 @@
        put_one_tile(&store, map_x, map_y,
                     x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_WIDTH, TRUE);
        if (pcity->city_map[x][y] == C_TILE_WORKER)
-         put_city_tile_output(pdialog->map_canvas_store,
+         put_city_tile_output(pcity, x, y, &store,
                               x * NORMAL_TILE_WIDTH,
-                              y * NORMAL_TILE_HEIGHT,
-                              city_get_food_tile(x, y, pcity),
-                              city_get_shields_tile(x, y, pcity),
-                              city_get_trade_tile(x, y, pcity));
+                              y * NORMAL_TILE_HEIGHT);
        else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE)
          pixmap_frame_tile_red(pdialog->map_canvas_store,
                                x * NORMAL_TILE_WIDTH,
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.197
diff -u -r1.197 mapview.c
--- client/gui-gtk/mapview.c    2004/02/24 05:20:25     1.197
+++ client/gui-gtk/mapview.c    2004/02/24 06:05:53
@@ -698,29 +698,6 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void put_city_tile_output(GdkDrawable *pm, int canvas_x, int canvas_y, 
-                         int food, int shield, int trade)
-{
-  food = CLIP(0, food, NUM_TILES_DIGITS-1);
-  trade = CLIP(0, trade, NUM_TILES_DIGITS-1);
-  shield = CLIP(0, shield, NUM_TILES_DIGITS-1);
-  
-  if (is_isometric) {
-    canvas_x += NORMAL_TILE_WIDTH/3;
-    canvas_y -= NORMAL_TILE_HEIGHT/3;
-  }
-
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y,
-                         sprites.city.tile_foodnum[food]);
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y,
-                         sprites.city.tile_shieldnum[shield]);
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y,
-                         sprites.city.tile_tradenum[trade]);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 void put_unit_gpixmap(struct unit *punit, GtkPixcomm *p)
 {
   struct canvas_store canvas_store = {NULL, p};
@@ -941,6 +918,7 @@
 {
   int canvas_x, canvas_y;
   static struct city *last_pcity=NULL;
+  struct canvas_store store = {map_canvas->window, NULL};
 
   if (color==-1) {
     if (pcity!=last_pcity)
@@ -989,11 +967,7 @@
 
     /* draw tile output */
     if (worked == C_TILE_WORKER) {
-      put_city_tile_output(map_canvas->window,
-                          canvas_x, canvas_y,
-                          city_get_food_tile(i, j, pcity),
-                          city_get_shields_tile(i, j, pcity),
-                          city_get_trade_tile(i, j, pcity));
+      put_city_tile_output(pcity, i, j, &store, canvas_x, canvas_y);
     }
   } city_map_checked_iterate_end;
 
Index: client/gui-gtk/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.h,v
retrieving revision 1.23
diff -u -r1.23 mapview.h
--- client/gui-gtk/mapview.h    2004/01/30 01:36:14     1.23
+++ client/gui-gtk/mapview.h    2004/02/24 06:05:53
@@ -30,8 +30,6 @@
 gint overview_canvas_expose(GtkWidget *w, GdkEventExpose *ev);
 gint map_canvas_expose(GtkWidget *w, GdkEventExpose *ev);
 
-void put_city_tile_output(GdkDrawable *pm, int canvas_x, int canvas_y, 
-                         int food, int shield, int trade);
 void put_unit_gpixmap(struct unit *punit, GtkPixcomm *p);
 
 void put_unit_gpixmap_city_overlays(struct unit *punit, GtkPixcomm *p);
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.72
diff -u -r1.72 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        2004/02/02 12:35:44     1.72
+++ client/gui-gtk-2.0/citydlg.c        2004/02/24 06:05:54
@@ -1363,6 +1363,7 @@
 {
   struct city *pcity = pdialog->pcity;
   int city_x, city_y;
+  struct canvas_store store = {pdialog->map_canvas_store};
 
   gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
 
@@ -1392,11 +1393,7 @@
     if (tile_get_known(map_x, map_y)
        && city_to_canvas_pos(&canvas_x, &canvas_y, x, y)
        && pcity->city_map[x][y] == C_TILE_WORKER) {
-      put_city_tile_output(pdialog->map_canvas_store,
-                          canvas_x, canvas_y,
-                          city_get_food_tile(x, y, pcity),
-                          city_get_shields_tile(x, y, pcity),
-                          city_get_trade_tile(x, y, pcity));
+      put_city_tile_output(pcity, x, y, &store, canvas_x, canvas_y);
     }
   }
   city_map_checked_iterate_end;
@@ -1436,12 +1433,9 @@
        put_one_tile(&store, map_x, map_y,
                     x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT, TRUE);
        if (pcity->city_map[x][y] == C_TILE_WORKER)
-         put_city_tile_output(pdialog->map_canvas_store,
+         put_city_tile_output(pcity, x, y, &store,
                               x * NORMAL_TILE_WIDTH,
-                              y * NORMAL_TILE_HEIGHT,
-                              city_get_food_tile(x, y, pcity),
-                              city_get_shields_tile(x, y, pcity),
-                              city_get_trade_tile(x, y, pcity));
+                              y * NORMAL_TILE_HEIGHT);
        else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE)
          pixmap_frame_tile_red(pdialog->map_canvas_store,
                                x * NORMAL_TILE_WIDTH,
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.97
diff -u -r1.97 mapview.c
--- client/gui-gtk-2.0/mapview.c        2004/02/24 05:20:25     1.97
+++ client/gui-gtk-2.0/mapview.c        2004/02/24 06:05:54
@@ -760,29 +760,6 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void put_city_tile_output(GdkDrawable *pm, int canvas_x, int canvas_y, 
-                         int food, int shield, int trade)
-{
-  food = CLIP(0, food, NUM_TILES_DIGITS-1);
-  trade = CLIP(0, trade, NUM_TILES_DIGITS-1);
-  shield = CLIP(0, shield, NUM_TILES_DIGITS-1);
-  
-  if (is_isometric) {
-    canvas_x += NORMAL_TILE_WIDTH/3;
-    canvas_y -= NORMAL_TILE_HEIGHT/3;
-  }
-
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y,
-                         sprites.city.tile_foodnum[food]);
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y,
-                         sprites.city.tile_shieldnum[shield]);
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y,
-                         sprites.city.tile_tradenum[trade]);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 void put_unit_gpixmap(struct unit *punit, GtkPixcomm *p)
 {
   struct canvas_store canvas_store = {NULL, p};
@@ -1022,6 +999,7 @@
 {
   int canvas_x, canvas_y;
   static struct city *last_pcity=NULL;
+  struct canvas_store store = {map_canvas->window, NULL};
 
   if (color==-1) {
     if (pcity!=last_pcity)
@@ -1070,11 +1048,7 @@
 
     /* draw tile output */
     if (worked == C_TILE_WORKER) {
-      put_city_tile_output(map_canvas->window,
-                          canvas_x, canvas_y,
-                          city_get_food_tile(i, j, pcity),
-                          city_get_shields_tile(i, j, pcity),
-                          city_get_trade_tile(i, j, pcity));
+      put_city_tile_output(pcity, i, j, &store, canvas_x, canvas_y);
     }
   } city_map_checked_iterate_end;
 
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.13
diff -u -r1.13 mapview.h
--- client/gui-gtk-2.0/mapview.h        2004/01/30 01:16:41     1.13
+++ client/gui-gtk-2.0/mapview.h        2004/02/24 06:05:54
@@ -33,8 +33,6 @@
 gboolean map_canvas_configure(GtkWidget *w, GdkEventConfigure *ev,
                              gpointer data);
 
-void put_city_tile_output(GdkDrawable *pm, int canvas_x, int canvas_y, 
-                         int food, int shield, int trade);
 void put_unit_gpixmap(struct unit *punit, GtkPixcomm *p);
 
 void put_unit_gpixmap_city_overlays(struct unit *punit, GtkPixcomm *p);
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.69
diff -u -r1.69 citydlg.c
--- client/gui-win32/citydlg.c  2004/02/23 08:51:58     1.69
+++ client/gui-win32/citydlg.c  2004/02/24 06:05:56
@@ -500,6 +500,7 @@
 {
   struct city *pcity = pdialog->pcity;
   int city_x,city_y;
+  struct canvas_store store = {hdc, NULL};
   
   /* We have to draw the tiles in a particular order, so its best
      to avoid using any iterator macro. */
@@ -522,11 +523,7 @@
     if (tile_get_known(map_x, map_y)
        && city_to_canvas_pos(&canvas_x, &canvas_y, x, y)
        && pcity->city_map[x][y] == C_TILE_WORKER) {
-      put_city_tile_output(hdc,
-                          canvas_x, canvas_y,
-                          city_get_food_tile(x, y, pcity),
-                          city_get_shields_tile(x, y, pcity), 
-                          city_get_trade_tile(x, y, pcity));
+      put_city_tile_output(pcity, x, y, &store, canvas_x, canvas_y);
     }
   } city_map_checked_iterate_end;
 
@@ -566,11 +563,9 @@
        put_one_tile(&store, map_x, map_y,
                     x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT, TRUE);
         if(pcity->city_map[x][y]==C_TILE_WORKER)
-          put_city_tile_output(citydlgdc, NORMAL_TILE_WIDTH*x,
-                              y*NORMAL_TILE_HEIGHT,
-                               city_get_food_tile(x, y, pcity),
-                               city_get_shields_tile(x, y, pcity),
-                               city_get_trade_tile(x, y, pcity));
+          put_city_tile_output(pcity, x, y, &store,
+                              NORMAL_TILE_WIDTH * x,
+                              NORMAL_TILE_HEIGHT * y);
        else if(pcity->city_map[x][y]==C_TILE_UNAVAILABLE)
          pixmap_frame_tile_red(citydlgdc, x*NORMAL_TILE_WIDTH,
                                y*NORMAL_TILE_HEIGHT);
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.94
diff -u -r1.94 mapview.c
--- client/gui-win32/mapview.c  2004/02/24 05:20:25     1.94
+++ client/gui-win32/mapview.c  2004/02/24 06:05:56
@@ -285,27 +285,6 @@
   }
 }
 
-
-/**************************************************************************
-
-**************************************************************************/
-void put_city_tile_output(HDC hdc, int canvas_x, int canvas_y,
-                         int food, int shield, int trade)
-{
-  food = CLIP(0, food, NUM_TILES_DIGITS-1);
-  trade = CLIP(0, trade, NUM_TILES_DIGITS-1);
-  shield = CLIP(0, shield, NUM_TILES_DIGITS-1);  
-  if (is_isometric) {
-    canvas_x += NORMAL_TILE_WIDTH/3;
-    canvas_y -= NORMAL_TILE_HEIGHT/3;
-  }
-
-  draw_sprite(sprites.city.tile_foodnum[food],hdc,canvas_x,canvas_y);
-  draw_sprite(sprites.city.tile_shieldnum[shield],hdc,canvas_x,canvas_y);
-  draw_sprite(sprites.city.tile_tradenum[trade],hdc,canvas_x,canvas_y); 
-
-}
-
 /**************************************************************************
 
 **************************************************************************/
Index: client/gui-win32/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.h,v
retrieving revision 1.12
diff -u -r1.12 mapview.h
--- client/gui-win32/mapview.h  2004/02/21 22:15:03     1.12
+++ client/gui-win32/mapview.h  2004/02/24 06:05:56
@@ -15,8 +15,6 @@
 
 #include "mapview_g.h"
 
-void put_city_tile_output(HDC hdc, int x, int y,
-                          int food, int shield, int trade);    
 void pixmap_frame_tile_red(HDC hdc, int x, int y);
 void put_one_tile_full(HDC hdc, int x, int y,
                       int canvas_x, int canvas_y, int citymode);
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.108
diff -u -r1.108 citydlg.c
--- client/gui-xaw/citydlg.c    2004/01/06 08:11:34     1.108
+++ client/gui-xaw/citydlg.c    2004/02/24 06:05:56
@@ -1547,11 +1547,7 @@
          && city_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
        put_one_tile(&store, map_x, map_y, canvas_x, canvas_y, TRUE);
        if (pcity->city_map[x][y] == C_TILE_WORKER)
-         put_city_tile_output(XtWindow(pdialog->map_canvas),
-                              canvas_x, canvas_y,
-                              city_get_food_tile(x, y, pcity),
-                              city_get_shields_tile(x, y, pcity),
-                              city_get_trade_tile(x, y, pcity));
+         put_city_tile_output(pcity, x, y, &store, canvas_x, canvas_y);
        else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE)
          pixmap_frame_tile_red(XtWindow(pdialog->map_canvas),
                                canvas_x, canvas_y);
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.160
diff -u -r1.160 mapview.c
--- client/gui-xaw/mapview.c    2004/02/24 05:20:25     1.160
+++ client/gui-xaw/mapview.c    2004/02/24 06:05:56
@@ -761,21 +761,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-void put_city_tile_output(Pixmap pm, int canvas_x, int canvas_y, 
-                         int food, int shield, int trade)
-{
-  food = CLIP(0, food, NUM_TILES_DIGITS-1);
-  trade = CLIP(0, trade, NUM_TILES_DIGITS-1);
-  shield = CLIP(0, shield, NUM_TILES_DIGITS-1);
-  
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y, 
sprites.city.tile_foodnum[food]);
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y, 
sprites.city.tile_shieldnum[shield]);
-  pixmap_put_overlay_tile(pm, canvas_x, canvas_y, 
sprites.city.tile_tradenum[trade]);
-}
-
-/**************************************************************************
   FIXME: 
   For now only two food, one shield and two masks can be drawn per unit,
   the proper way to do this is probably something like what Civ II does.
@@ -857,6 +842,7 @@
 {
   int canvas_x, canvas_y;
   static struct city *last_pcity = NULL;
+  struct canvas_store store = {XtWindow(map_canvas)};
 
   if (color == -1) {
     if (pcity != last_pcity)
@@ -886,11 +872,7 @@
                     NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
     }
     if (worked == C_TILE_WORKER) {
-      put_city_tile_output(XtWindow(map_canvas),
-                          canvas_x, canvas_y,
-                          city_get_food_tile(i, j, pcity),
-                          city_get_shields_tile(i, j, pcity),
-                          city_get_trade_tile(i, j, pcity));
+      put_city_tile_output(pcity, i, j, &store, canvas_x, canvas_y);
     }
   } city_map_checked_iterate_end;
 
Index: client/gui-xaw/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.h,v
retrieving revision 1.20
diff -u -r1.20 mapview.h
--- client/gui-xaw/mapview.h    2004/02/18 02:20:52     1.20
+++ client/gui-xaw/mapview.h    2004/02/24 06:05:56
@@ -30,9 +30,6 @@
 
 void put_unit_pixmap_city_overlays(struct unit *punit, Pixmap pm);
 
-void put_city_tile_output(Pixmap pm, int canvas_x, int canvas_y, 
-                         int food, int shield, int trade);
-
 void overview_canvas_expose(Widget w, XEvent *event, Region exposed, 
                            void *client_data);
 void map_canvas_expose(Widget w, XEvent *event, Region exposed, 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7502) move put_city_tile_output into mapview_common, Jason Short <=