Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7560) move citymap drawing into citydlg_common
Home

[Freeciv-Dev] (PR#7560) move citymap drawing into citydlg_common

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7560) move citymap drawing into citydlg_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 27 Feb 2004 09:56:29 -0800
Reply-to: rt@xxxxxxxxxxx

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

This patch moves the drawing of the city dialog map into citydlg_common.

Currently this drawing exists in two functions: 
city_dialog_update_map_ovh and city_dialog_update_map_iso.  I merge them 
into a single function city_dialog_redraw_map (update => redraw is to 
avoid naming conflicts).  Because of the merge drawing is done slightly 
differently for orthogonal view: instead of drawing black tiles, we fill 
the canvas with black at the start and then just skip over black tiles. 
  The drawing follows the ordering used by iso-view (for ortho-view it 
doesn't matter); there's just one place in the function where it makes a 
difference whether we're in iso-view or ortho-view.

Callers must be changed to pass a pcity and a pcanvas_store to this 
function.  This removes a fair amount of code (50-100 lines) from each GUI.

These drawing functions call a number of helpers to do the actual 
drawing.  All but one of these is already in mapview_common (thanks to 
recent patches).  The remaining function is put_one_tile_iso.  Currently 
we have a gui_map_put_tile_iso function in the client (a remnant from 
before we tracked the mapview canvas in mapview_common).  I rename this 
function to put_one_tile_iso and add pcanvas_store and a citymode 
parameters.  This function should still be considered temporary: 
eventually I'd like to move it into mapview_common (see PR#3572).

The result is pretty straightforward.  The main benefits are that 250 
lines are removed and iso-view support is added to gui-xaw.  The patch 
is only large because of so much code that is deleted!  However, note 
that these functions are still a little buggy (the red tile frames).  I 
don't know why this is, but after this code is unified I'll spend some 
time tracking it down.

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

Final note: gui-sdl has its own implementation of citydlg drawing: the 
citydlg is drawn using scaled-down sprites so it's smaller than the 
mapview.  This is not currently possible using the common code.  However 
this patch won't break gui-sdl (though it doesn't compile anyway); it 
just doesn't call this function.  Eventually the scaling functionality 
should be merged into the common code or dropped.

jason

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.27
diff -u -r1.27 citydlg_common.c
--- client/citydlg_common.c     2004/02/26 04:05:10     1.27
+++ client/citydlg_common.c     2004/02/27 17:23:07
@@ -20,13 +20,16 @@
 #include "log.h"
 #include "support.h"
 
+#include "mapview_g.h"
+
+#include "citydlg_common.h"
+#include "climap.h"
 #include "clinet.h"
 #include "control.h"
+#include "mapview_common.h"
 #include "options.h"           /* for concise_city_production */
 #include "tilespec.h"          /* for is_isometric */
 
-#include "citydlg_common.h"
-
 /**************************************************************************
   Return the width of the city dialog canvas.
 **************************************************************************/
@@ -113,6 +116,71 @@
          orig_canvas_x, orig_canvas_y, *city_x, *city_y);
 
   return is_valid_city_coords(*city_x, *city_y);
+}
+
+/****************************************************************************
+  Draw the full city map onto the canvas store.  Works for both isometric
+  and orthogonal views.
+****************************************************************************/
+void city_dialog_redraw_map(struct city *pcity,
+                           struct canvas_store *pcanvas_store)
+{
+  int city_x, city_y;
+
+  /* First make it all black. */
+  gui_put_rectangle(pcanvas_store, COLOR_STD_BLACK, 0, 0,
+                   get_citydlg_canvas_width(), get_citydlg_canvas_height());
+
+  /* We have to draw the tiles in a particular order, so its best
+     to avoid using any iterator macro. */
+  for (city_x = 0; city_x < CITY_MAP_SIZE; city_x++) {
+    for (city_y = 0; city_y < CITY_MAP_SIZE; city_y++) {
+      int map_x, map_y, canvas_x, canvas_y;
+
+      if (is_valid_city_coords(city_x, city_y)
+         && city_map_to_map(&map_x, &map_y, pcity, city_x, city_y)
+         && tile_get_known(map_x, map_y)
+         && city_to_canvas_pos(&canvas_x, &canvas_y, city_x, city_y)) {
+       if (is_isometric) {
+         put_one_tile_iso(pcanvas_store, map_x, map_y,
+                          canvas_x, canvas_y,
+                          0, 0, 0,
+                          NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT,
+                          UNIT_TILE_HEIGHT,
+                          D_FULL, TRUE);
+       } else {
+         put_one_tile(pcanvas_store, map_x, map_y,
+                      canvas_x, canvas_y, TRUE);
+       }
+      }
+    }
+  }
+
+  /* We have to put the output afterwards or it will be covered
+   * in iso-view. */
+  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
+    int canvas_x, canvas_y;
+
+    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(pcity, x, y, pcanvas_store, canvas_x, canvas_y);
+    }
+  } city_map_checked_iterate_end;
+
+  /* This sometimes will draw one of the lines on top of a city or
+   * unit pixmap (in iso-view). This should maybe be moved to
+   * put_one_tile to fix this, but maybe it wouldn't be a good idea because
+   * the lines would get obscured. */
+  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
+    int canvas_x, canvas_y;
+
+    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_UNAVAILABLE) {
+      put_red_frame_tile(pcanvas_store, canvas_x, canvas_y);
+    }
+  } city_map_checked_iterate_end;
 }
 
 /**************************************************************************
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.17
diff -u -r1.17 citydlg_common.h
--- client/citydlg_common.h     2003/08/06 07:22:44     1.17
+++ client/citydlg_common.h     2004/02/27 17:23:07
@@ -21,6 +21,7 @@
 #include "shared.h"            /* bool type */
 
 struct city;
+struct canvas_store;
 
 enum citizen_type {
   CITIZEN_ELVIS,
@@ -40,6 +41,8 @@
                        int city_x, int city_y);
 bool canvas_to_city_pos(int *city_x, int *city_y,
                        int canvas_x, int canvas_y);
+void city_dialog_redraw_map(struct city *pcity,
+                           struct canvas_store *pcanvas_store);
 
 void get_city_dialog_production(struct city *pcity,
                                 char *buffer, size_t buffer_len);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.84
diff -u -r1.84 mapview_common.c
--- client/mapview_common.c     2004/02/27 16:30:31     1.84
+++ client/mapview_common.c     2004/02/27 17:23:07
@@ -1108,10 +1108,11 @@
     }
 
     if (normalize_map_pos(&map_x, &map_y)) {
-      gui_map_put_tile_iso(map_x, map_y, canvas_x, canvas_y,
-                          offset_x, offset_y, offset_y_unit,
-                          width, height, height_unit,
-                          draw);
+      put_one_tile_iso(mapview_canvas.store,
+                      map_x, map_y, canvas_x, canvas_y,
+                      offset_x, offset_y, offset_y_unit,
+                      width, height, height_unit,
+                      draw, FALSE);
     } else {
       gui_put_sprite(mapview_canvas.store, canvas_x, canvas_y,
                     sprites.black_tile, offset_x, offset_y, width, height);
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.178
diff -u -r1.178 citydlg.c
--- client/gui-gtk/citydlg.c    2004/02/27 16:30:32     1.178
+++ client/gui-gtk/citydlg.c    2004/02/27 17:23:08
@@ -230,8 +230,6 @@
 static void city_dialog_update_citizens(struct city_dialog *pdialog);
 static void city_dialog_update_information(GtkWidget **info_label,
                                            struct city_dialog *pdialog);
-static void city_dialog_update_map_iso(struct city_dialog *pdialog);
-static void city_dialog_update_map_ovh(struct city_dialog *pdialog);
 static void city_dialog_update_map(struct city_dialog *pdialog);
 static void city_dialog_update_building(struct city_dialog *pdialog);
 static void city_dialog_update_improvement_list(struct city_dialog
@@ -1756,106 +1754,13 @@
 }
 
 /****************************************************************
-Isometric.
-*****************************************************************/
-static void city_dialog_update_map_iso(struct city_dialog *pdialog)
-{
-  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]);
-
-  /* First make it all black. */
-  gdk_draw_rectangle(pdialog->map_canvas_store, fill_bg_gc, TRUE,
-                    0, 0, canvas_width, canvas_height);
-
-  /* We have to draw the tiles in a particular order, so its best
-     to avoid using any iterator macro. */
-  for (city_x = 0; city_x<CITY_MAP_SIZE; city_x++)
-    for (city_y = 0; city_y<CITY_MAP_SIZE; city_y++) {
-      int map_x, map_y, canvas_x, canvas_y;
-
-      if (is_valid_city_coords(city_x, city_y)
-         && city_map_to_map(&map_x, &map_y, pcity, city_x, city_y)
-         && tile_get_known(map_x, map_y)
-         && city_to_canvas_pos(&canvas_x, &canvas_y, city_x, city_y)) {
-       put_one_tile_full(pdialog->map_canvas_store, map_x, map_y,
-                         canvas_x, canvas_y, 1);
-      }
-    }
-
-  /* We have to put the output afterwards or it will be covered. */
-  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
-    int canvas_x, canvas_y;
-
-    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(pcity, x, y, &store, canvas_x, canvas_y);
-    }
-  }
-  city_map_checked_iterate_end;
-
-  /* This sometimes will draw one of the lines on top of a city or
-     unit pixmap. This should maybe be moved to put_one_tile_pixmap()
-     to fix this, but maybe it wouldn't be a good idea because the
-     lines would get obscured. */
-  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
-    int canvas_x, canvas_y;
-
-    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_UNAVAILABLE) {
-      put_red_frame_tile(&store, canvas_x, canvas_y);
-    }
-  }
-  city_map_checked_iterate_end;
-}
-
-/****************************************************************
-Non-isometric
-*****************************************************************/
-static void city_dialog_update_map_ovh(struct city_dialog *pdialog)
-{
-  int x, y;
-  struct city *pcity = pdialog->pcity;
-  struct canvas_store store = {pdialog->map_canvas_store};
-
-  for (y = 0; y < CITY_MAP_SIZE; y++)
-    for (x = 0; x < CITY_MAP_SIZE; x++) {
-      int map_x, map_y;
-
-      if (is_valid_city_coords(x, y)
-         && city_map_to_map(&map_x, &map_y, pcity, x, y)
-         && tile_get_known(map_x, map_y)) {
-       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(pcity, x, y, &store,
-                              x * NORMAL_TILE_WIDTH,
-                              y * NORMAL_TILE_HEIGHT);
-       else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE)
-         put_red_frame_tile(&store,
-                            x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT);
-      } else {
-       pixmap_put_black_tile(pdialog->map_canvas_store,
-                             x * NORMAL_TILE_WIDTH,
-                             y * NORMAL_TILE_HEIGHT);
-      }
-    }
-}
-
-/****************************************************************
 ...
 *****************************************************************/
 static void city_dialog_update_map(struct city_dialog *pdialog)
 {
-  if (is_isometric) {
-    city_dialog_update_map_iso(pdialog);
-  } else {
-    city_dialog_update_map_ovh(pdialog);
-  }
+  struct canvas_store store = {pdialog->map_canvas_store};
+
+  city_dialog_redraw_map(pdialog->pcity, &store);
 
   /* draw to real window */
   draw_map_canvas(pdialog);
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.200
diff -u -r1.200 mapview.c
--- client/gui-gtk/mapview.c    2004/02/27 16:30:32     1.200
+++ client/gui-gtk/mapview.c    2004/02/27 17:23:08
@@ -526,17 +526,18 @@
 }
 
 /**************************************************************************
-  Draw some or all of a tile onto the mapview canvas.
+  Draw some or all of a tile onto the canvas.
 **************************************************************************/
-void gui_map_put_tile_iso(int map_x, int map_y,
-                         int canvas_x, int canvas_y,
-                         int offset_x, int offset_y, int offset_y_unit,
-                         int width, int height, int height_unit,
-                         enum draw_type draw)
+void put_one_tile_iso(struct canvas_store *pcanvas_store,
+                     int map_x, int map_y,
+                     int canvas_x, int canvas_y,
+                     int offset_x, int offset_y, int offset_y_unit,
+                     int width, int height, int height_unit,
+                     enum draw_type draw, bool citymode)
 {
-  pixmap_put_tile_iso(map_canvas_store,
+  pixmap_put_tile_iso(pcanvas_store->pixmap,
                      map_x, map_y, canvas_x, canvas_y,
-                     FALSE,
+                     citymode,
                      offset_x, offset_y, offset_y_unit,
                      width, height, height_unit, draw);
 }
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.75
diff -u -r1.75 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        2004/02/27 16:30:32     1.75
+++ client/gui-gtk-2.0/citydlg.c        2004/02/27 17:23:08
@@ -198,8 +198,6 @@
 static void city_dialog_update_citizens(struct city_dialog *pdialog);
 static void city_dialog_update_information(GtkWidget **info_label,
                                            struct city_dialog *pdialog);
-static void city_dialog_update_map_iso(struct city_dialog *pdialog);
-static void city_dialog_update_map_ovh(struct city_dialog *pdialog);
 static void city_dialog_update_map(struct city_dialog *pdialog);
 static void city_dialog_update_building(struct city_dialog *pdialog);
 static void city_dialog_update_improvement_list(struct city_dialog
@@ -1357,106 +1355,13 @@
 }
 
 /****************************************************************
-Isometric.
-*****************************************************************/
-static void city_dialog_update_map_iso(struct city_dialog *pdialog)
-{
-  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]);
-
-  /* First make it all black. */
-  gdk_draw_rectangle(pdialog->map_canvas_store, fill_bg_gc, TRUE,
-                    0, 0, canvas_width, canvas_height);
-
-  /* We have to draw the tiles in a particular order, so its best
-     to avoid using any iterator macro. */
-  for (city_x = 0; city_x<CITY_MAP_SIZE; city_x++)
-    for (city_y = 0; city_y<CITY_MAP_SIZE; city_y++) {
-      int map_x, map_y, canvas_x, canvas_y;
-
-      if (is_valid_city_coords(city_x, city_y)
-         && city_map_to_map(&map_x, &map_y, pcity, city_x, city_y)
-         && tile_get_known(map_x, map_y)
-         && city_to_canvas_pos(&canvas_x, &canvas_y, city_x, city_y)) {
-       put_one_tile_full(pdialog->map_canvas_store, map_x, map_y,
-                         canvas_x, canvas_y, 1);
-      }
-    }
-
-  /* We have to put the output afterwards or it will be covered. */
-  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
-    int canvas_x, canvas_y;
-
-    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(pcity, x, y, &store, canvas_x, canvas_y);
-    }
-  }
-  city_map_checked_iterate_end;
-
-  /* This sometimes will draw one of the lines on top of a city or
-     unit pixmap. This should maybe be moved to put_one_tile_pixmap()
-     to fix this, but maybe it wouldn't be a good idea because the
-     lines would get obscured. */
-  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
-    int canvas_x, canvas_y;
-
-    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_UNAVAILABLE) {
-      put_red_frame_tile(&store, canvas_x, canvas_y);
-    }
-  }
-  city_map_checked_iterate_end;
-}
-
-/****************************************************************
-Non-isometric
-*****************************************************************/
-static void city_dialog_update_map_ovh(struct city_dialog *pdialog)
-{
-  int x, y;
-  struct city *pcity = pdialog->pcity;
-  struct canvas_store store = {pdialog->map_canvas_store};
-
-  for (y = 0; y < CITY_MAP_SIZE; y++)
-    for (x = 0; x < CITY_MAP_SIZE; x++) {
-      int map_x, map_y;
-
-      if (is_valid_city_coords(x, y)
-         && city_map_to_map(&map_x, &map_y, pcity, x, y)
-         && tile_get_known(map_x, map_y)) {
-       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(pcity, x, y, &store,
-                              x * NORMAL_TILE_WIDTH,
-                              y * NORMAL_TILE_HEIGHT);
-       else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE)
-         put_red_frame_tile(&store,
-                            x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT);
-      } else {
-       pixmap_put_black_tile(pdialog->map_canvas_store,
-                             x * NORMAL_TILE_WIDTH,
-                             y * NORMAL_TILE_HEIGHT);
-      }
-    }
-}
-
-/****************************************************************
 ...
 *****************************************************************/
 static void city_dialog_update_map(struct city_dialog *pdialog)
 {
-  if (is_isometric) {
-    city_dialog_update_map_iso(pdialog);
-  } else {
-    city_dialog_update_map_ovh(pdialog);
-  }
+  struct canvas_store store = {pdialog->map_canvas_store};
+
+  city_dialog_redraw_map(pdialog->pcity, &store);
 
   /* draw to real window */
   draw_map_canvas(pdialog);
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.100
diff -u -r1.100 mapview.c
--- client/gui-gtk-2.0/mapview.c        2004/02/27 16:30:32     1.100
+++ client/gui-gtk-2.0/mapview.c        2004/02/27 17:23:09
@@ -592,17 +592,18 @@
 }
 
 /**************************************************************************
-  Draw some or all of a tile onto the mapview canvas.
+  Draw some or all of a tile onto the canvas.
 **************************************************************************/
-void gui_map_put_tile_iso(int map_x, int map_y,
-                         int canvas_x, int canvas_y,
-                         int offset_x, int offset_y, int offset_y_unit,
-                         int width, int height, int height_unit,
-                         enum draw_type draw)
+void put_one_tile_iso(struct canvas_store *pcanvas_store,
+                     int map_x, int map_y,
+                     int canvas_x, int canvas_y,
+                     int offset_x, int offset_y, int offset_y_unit,
+                     int width, int height, int height_unit,
+                     enum draw_type draw, bool citymode)
 {
-  pixmap_put_tile_iso(map_canvas_store,
+  pixmap_put_tile_iso(pcanvas_store->pixmap,
                      map_x, map_y, canvas_x, canvas_y,
-                     FALSE,
+                     citymode,
                      offset_x, offset_y, offset_y_unit,
                      width, height, height_unit, draw);
 }
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.72
diff -u -r1.72 citydlg.c
--- client/gui-win32/citydlg.c  2004/02/27 16:30:32     1.72
+++ client/gui-win32/citydlg.c  2004/02/27 17:23:09
@@ -493,106 +493,21 @@
  
 }
 
-/****************************************************************
-Isometric.
-*****************************************************************/
-static void city_dialog_update_map_iso(HDC hdc,struct city_dialog *pdialog)
-{
-  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. */
-  for (city_x = 0; city_x<CITY_MAP_SIZE; city_x++)
-    for (city_y = 0; city_y<CITY_MAP_SIZE; city_y++) {
-      int map_x, map_y, canvas_x, canvas_y;
-
-      if (is_valid_city_coords(city_x, city_y)
-          && city_map_to_map(&map_x, &map_y, pcity, city_x, city_y)
-         && tile_get_known(map_x, map_y)
-          && city_to_canvas_pos(&canvas_x, &canvas_y, city_x, city_y)) {
-       put_one_tile_full(hdc, map_x, map_y, canvas_x, canvas_y, 1);
-      }
-    }
-  
-  /* We have to put the output afterwards or it will be covered. */
-  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
-    int canvas_x, canvas_y;
-
-    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(pcity, x, y, &store, canvas_x, canvas_y);
-    }
-  } city_map_checked_iterate_end;
-
-  /* This sometimes will draw one of the lines on top of a city or
-     unit pixmap. This should maybe be moved to put_one_tile_pixmap()
-     to fix this, but maybe it wouldn't be a good idea because the
-     lines would get obscured. */
-  city_map_checked_iterate(pcity->x, pcity->y, x, y, map_x, map_y) {
-    int canvas_x, canvas_y;
-
-    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_UNAVAILABLE) {
-      put_red_frame_tile(&store, canvas_x, canvas_y);
-    }
-  } city_map_checked_iterate_end;
-
-}
-
-/****************************************************************
-Overhead
-*****************************************************************/
-static void city_dialog_update_map_ovh(HDC hdc,struct city_dialog *pdialog)
-{
-  int y,x;
-  struct city *pcity;
-  struct canvas_store store = {citydlgdc, NULL};
-
-  pcity=pdialog->pcity;
-  for(y=0; y<CITY_MAP_SIZE; y++)
-    for(x=0; x<CITY_MAP_SIZE; x++) {
-      int map_x, map_y;
-
-      if (is_valid_city_coords(x, y)
-         && city_map_to_map(&map_x, &map_y, pcity, x, y)
-         && tile_get_known(map_x, map_y)) {
-       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(pcity, x, y, &store,
-                              NORMAL_TILE_WIDTH * x,
-                              NORMAL_TILE_HEIGHT * y);
-       else if(pcity->city_map[x][y]==C_TILE_UNAVAILABLE)
-         put_red_frame_tile(&store,
-                            x * NORMAL_TILE_WIDTH, y * NORMAL_TILE_HEIGHT);
-      }
-      else {
-       BitBlt(citydlgdc,x*NORMAL_TILE_WIDTH,
-              y*NORMAL_TILE_HEIGHT,
-              NORMAL_TILE_WIDTH,
-              NORMAL_TILE_HEIGHT,
-              NULL,0,0,BLACKNESS);
-      }
-    }
-  
-}
 /**************************************************************************
                                                                           ...
 **************************************************************************/
 void city_dialog_update_map(HDC hdc,struct city_dialog *pdialog)
 {
   HBITMAP oldbit;
+  struct canvas_store store;
+
   oldbit=SelectObject(citydlgdc,pdialog->map_bmp);
   BitBlt(citydlgdc,0,0,pdialog->map_w,pdialog->map_h,
         NULL,0,0,BLACKNESS);
-  if (is_isometric)
-    city_dialog_update_map_iso(citydlgdc,pdialog);
-  else
-    city_dialog_update_map_ovh(citydlgdc,pdialog);
+
+  store.hdc = citydlgdc;
+  store.bitmap = NULL;
+  city_dialog_redraw_map(pdialog->pcity, &store);
                            
   BitBlt(hdc,pdialog->map.x,pdialog->map.y,city_map_width,
         city_map_height,
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.97
diff -u -r1.97 mapview.c
--- client/gui-win32/mapview.c  2004/02/27 16:30:32     1.97
+++ client/gui-win32/mapview.c  2004/02/27 17:23:09
@@ -1080,28 +1080,20 @@
 }
 
 /**************************************************************************
-  Draw some or all of a tile onto the mapview canvas.
+  Draw some or all of a tile onto the canvas.
 **************************************************************************/
-void gui_map_put_tile_iso(int map_x, int map_y,
-                         int canvas_x, int canvas_y,
-                         int offset_x, int offset_y, int offset_y_unit,
-                         int width, int height, int height_unit,
-                         enum draw_type draw)
+void put_one_tile_iso(struct canvas_store *pcanvas_store,
+                     int map_x, int map_y,
+                     int canvas_x, int canvas_y,
+                     int offset_x, int offset_y, int offset_y_unit,
+                     int width, int height, int height_unit,
+                     enum draw_type draw, bool citymode)
 {
-  HDC hdc;
-  HBITMAP old;
-
-  /* FIXME: we don't want to have to recreate the hdc each time! */
-  hdc = CreateCompatibleDC(NULL);
-  old = SelectObject(hdc, mapstorebitmap);
-
-  pixmap_put_tile_iso(hdc, map_x, map_y, canvas_x, canvas_y, 0,
+  pixmap_put_tile_iso(pcanvas_store->hdc, map_x, map_y,
+                     canvas_x, canvas_y, 0,
                      offset_x, offset_y, offset_y_unit,
                      width, height, height_unit,
                      draw);
-
-  SelectObject(hdc, old);
-  DeleteDC(hdc);
 }
 
 /**************************************************************************
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.111
diff -u -r1.111 citydlg.c
--- client/gui-xaw/citydlg.c    2004/02/27 16:30:33     1.111
+++ client/gui-xaw/citydlg.c    2004/02/27 17:23:10
@@ -157,7 +157,6 @@
 static void city_dialog_update_supported_units(struct city_dialog *pdialog, 
int id);
 static void city_dialog_update_present_units(struct city_dialog *pdialog, int 
id);
 static void city_dialog_update_citizens(struct city_dialog *pdialog);
-static void city_dialog_update_map(struct city_dialog *pdialog);
 static void city_dialog_update_production(struct city_dialog *pdialog);
 static void city_dialog_update_output(struct city_dialog *pdialog);
 static void city_dialog_update_building(struct city_dialog *pdialog);
@@ -355,12 +354,14 @@
   struct city_dialog *pdialog;
   
   if((pdialog=get_city_dialog(pcity))) {
+    struct canvas_store store = {XtWindow(pdialog->map_canvas)};
+
     city_dialog_update_improvement_list(pdialog);
     city_dialog_update_title(pdialog);
     city_dialog_update_supported_units(pdialog, 0);
     city_dialog_update_present_units(pdialog, 0);
     city_dialog_update_citizens(pdialog);
-    city_dialog_update_map(pdialog);
+    city_dialog_redraw_map(pdialog->pcity, &store);
     city_dialog_update_production(pdialog);
     city_dialog_update_output(pdialog);
     city_dialog_update_building(pdialog);
@@ -462,10 +463,10 @@
 static void city_map_canvas_expose(Widget w, XEvent *event, Region exposed, 
                                   void *client_data)
 {
-  struct city_dialog *pdialog;
+  struct city_dialog *pdialog = client_data;
+  struct canvas_store store = {XtWindow(pdialog->map_canvas)};
   
-  pdialog=(struct city_dialog *)client_data;
-  city_dialog_update_map(pdialog);
+  city_dialog_redraw_map(pdialog->pcity, &store);
 }
 
 
@@ -1521,38 +1522,6 @@
 
   get_contents_of_output(pdialog, buf, sizeof(buf));
   xaw_set_label(pdialog->output_label, buf);
-}
-
-
-/****************************************************************
-...
-*****************************************************************/
-void city_dialog_update_map(struct city_dialog *pdialog)
-{
-  int x, y;
-  struct city *pcity=pdialog->pcity;
-  struct canvas_store store = {XtWindow(pdialog->map_canvas)};
-  
-  XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
-  XFillRectangle(display, XtWindow(pdialog->map_canvas), fill_bg_gc,
-                0, 0, 4 * NORMAL_TILE_WIDTH, 4 * NORMAL_TILE_HEIGHT);
-
-  for(y=0; y<CITY_MAP_SIZE; y++) {
-    for(x=0; x<CITY_MAP_SIZE; x++) {
-      int map_x, map_y, canvas_x, canvas_y;
-
-      if (is_valid_city_coords(x, y)
-         && city_map_to_map(&map_x, &map_y, pcity, x, y)
-         && tile_get_known(map_x, map_y)
-         && 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(pcity, x, y, &store, canvas_x, canvas_y);
-       else if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE)
-         put_red_frame_tile(&store, 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.163
diff -u -r1.163 mapview.c
--- client/gui-xaw/mapview.c    2004/02/27 16:30:33     1.163
+++ client/gui-xaw/mapview.c    2004/02/27 17:23:10
@@ -473,13 +473,14 @@
 }
 
 /**************************************************************************
-  Draw some or all of a tile onto the mapview canvas.
+  Draw some or all of a tile onto the canvas.
 **************************************************************************/
-void gui_map_put_tile_iso(int map_x, int map_y,
-                         int canvas_x, int canvas_y,
-                         int offset_x, int offset_y, int offset_y_unit,
-                         int width, int height, int height_unit,
-                         enum draw_type draw)
+void put_one_tile_iso(struct canvas_store *pcanvas_store,
+                     int map_x, int map_y,
+                     int canvas_x, int canvas_y,
+                     int offset_x, int offset_y, int offset_y_unit,
+                     int width, int height, int height_unit,
+                     enum draw_type draw, bool citymode)
 {
   /* PORTME */
   assert(0);
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.45
diff -u -r1.45 mapview_g.h
--- client/include/mapview_g.h  2004/02/26 13:38:45     1.45
+++ client/include/mapview_g.h  2004/02/27 17:23:10
@@ -36,11 +36,12 @@
 void show_city_desc(struct city *pcity, int canvas_x, int canvas_y);
 void prepare_show_city_descriptions(void);
 
-void gui_map_put_tile_iso(int map_x, int map_y,
-                         int canvas_x, int canvas_y,
-                         int offset_x, int offset_y, int offset_y_unit,
-                         int width, int height, int height_unit,
-                         enum draw_type draw);
+void put_one_tile_iso(struct canvas_store *pcanvas_store,
+                     int map_x, int map_y,
+                     int canvas_x, int canvas_y,
+                     int offset_x, int offset_y, int offset_y_unit,
+                     int width, int height, int height_unit,
+                     enum draw_type draw, bool citymode);
 void gui_put_sprite(struct canvas_store *pcanvas_store,
                    int canvas_x, int canvas_y,
                    struct Sprite *sprite,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7560) move citymap drawing into citydlg_common, Jason Short <=