Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12175) refresh_city_mapcanvas
Home

[Freeciv-Dev] (PR#12175) refresh_city_mapcanvas

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12175) refresh_city_mapcanvas
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 8 Feb 2005 11:17:35 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch provides a refresh_city_mapcanvas function.  It can be called 
to refresh a city on the map canvas.  This moves the "ugly" logic about 
what area the city actually covers out of packhand.c and into 
mapview_common.

-jason

? fog
? fog.c
? fog.png
? data/isotrident/grid.png
? data/isotrident/mask-30x30.png
? data/misc/colors.png
? data/trident/foo.png
? data/trident/grid.png
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.179
diff -u -r1.179 mapview_common.c
--- client/mapview_common.c     8 Feb 2005 18:43:51 -0000       1.179
+++ client/mapview_common.c     8 Feb 2005 19:16:30 -0000
@@ -114,6 +114,47 @@
 }
 
 /**************************************************************************
+  Refreshes a single city on the map canvas.
+
+  If full_refresh is given then the citymap area and the city text will
+  also be refreshed.  Otherwise only the base city sprite is refreshed.
+**************************************************************************/
+void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile,
+                           bool full_refresh, bool write_to_screen)
+{
+  if (full_refresh && (draw_map_grid || draw_borders)) {
+    /* We have to make sure we update any workers on the map grid, then
+     * redraw the city descriptions on top of them.  So we calculate the
+     * rectangle covered by the city's map, and update that.  Then we
+     * queue up a city description redraw for later.
+     *
+     * HACK: The +2 below accounts for grid lines that may actually be on a
+     * tile outside of the city radius. */
+    int canvas_x, canvas_y;
+    int width = get_citydlg_canvas_width() + 2;
+    int height = get_citydlg_canvas_height() + 2;
+
+    (void) tile_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
+
+    update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
+                     canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
+                     width, height);
+  } else {
+    int canvas_x, canvas_y;
+
+    if (tile_to_canvas_pos(&canvas_x, &canvas_y, ptile)) {
+      canvas_y += NORMAL_TILE_HEIGHT - UNIT_TILE_HEIGHT;
+      update_map_canvas(canvas_x, canvas_y,
+                       UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT);
+    }
+  }
+  if (write_to_screen) {
+    flush_dirty();
+  }
+  overview_update_tile(ptile);
+}
+
+/**************************************************************************
 Returns the color the grid should have between tile (x1,y1) and
 (x2,y2).
 **************************************************************************/
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.89
diff -u -r1.89 mapview_common.h
--- client/mapview_common.h     8 Feb 2005 18:43:51 -0000       1.89
+++ client/mapview_common.h     8 Feb 2005 19:16:32 -0000
@@ -213,6 +213,8 @@
 void refresh_tile_mapcanvas(struct tile *ptile, bool write_to_screen);
 void refresh_unit_mapcanvas(struct unit *punit, struct tile *ptile,
                            bool write_to_screen);
+void refresh_city_mapcanvas(struct city *pcity, struct tile *ptile,
+                           bool full_refresh, bool write_to_screen);
 
 enum color_std get_grid_color(const struct tile *ptile, enum direction8 dir);
 
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.466
diff -u -r1.466 packhand.c
--- client/packhand.c   8 Feb 2005 18:43:51 -0000       1.466
+++ client/packhand.c   8 Feb 2005 19:16:33 -0000
@@ -584,25 +584,8 @@
     }
   }
 
-  if ((draw_map_grid || draw_borders) && can_client_change_view()) {
-    /* We have to make sure we update any workers on the map grid, then
-     * redraw the city descriptions on top of them.  So we calculate the
-     * rectangle covered by the city's map, and update that.  Then we
-     * queue up a city description redraw for later.
-     *
-     * HACK: The +2 below accounts for grid lines that may actually be on a
-     * tile outside of the city radius. */
-    int canvas_x, canvas_y;
-    int width = get_citydlg_canvas_width() + 2;
-    int height = get_citydlg_canvas_height() + 2;
-
-    (void) tile_to_canvas_pos(&canvas_x, &canvas_y, pcity->tile);
-
-    update_map_canvas(canvas_x - (width - NORMAL_TILE_WIDTH) / 2,
-                     canvas_y - (height - NORMAL_TILE_HEIGHT) / 2,
-                     width, height);
-  } else {
-    refresh_tile_mapcanvas(pcity->tile, FALSE);
+  if (can_client_change_view()) {
+    refresh_city_mapcanvas(pcity, pcity->tile, TRUE, FALSE);
   }
 
   if (city_workers_display==pcity)  {
@@ -1110,7 +1093,7 @@
 
          if (pcity->client.occupied != new_occupied) {
            pcity->client.occupied = new_occupied;
-           refresh_tile_mapcanvas(pcity->tile, FALSE);
+           refresh_city_mapcanvas(pcity, pcity->tile, FALSE, FALSE);
          }
        }
 
@@ -1125,7 +1108,7 @@
          /* Unit moved into a city - obviously it's occupied. */
          if (!pcity->client.occupied) {
            pcity->client.occupied = TRUE;
-           refresh_tile_mapcanvas(pcity->tile, FALSE);
+           refresh_city_mapcanvas(pcity, pcity->tile, FALSE, FALSE);
          }
        }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12175) refresh_city_mapcanvas, Jason Short <=