Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#2383) unification of show_city_descriptions
Home

[Freeciv-Dev] (PR#2383) unification of show_city_descriptions

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2383) unification of show_city_descriptions
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Fri, 22 Nov 2002 17:04:45 -0800
Reply-to: rt@xxxxxxxxxxxxxx

This is where the unification gets fun (but also harder).

This patch moves show_city_descriptions() out of gui-xxx/mapview.c and
into mapview_common.c.  A new GUI function, show_city_desc, is
introduced to do the "work" of drawing the description (most GUIs
already had this function, called show_desc_at_tile).  Some of the logic
is moved out of show_desc_at_tile and into show_city_descriptions, which
is the reason for the rename.  show_city_desc is generally more elegant now.

I've also slipped in a tiny topology fix to show_city_descriptions. 
Kudos to anybody (except Ross) who can spot it.

Finally, since large portions of show_city_desc had to be reindented
anyway, I fixed the formatting of these and introduced some small
improvements to GTK, GTK-2.0, and XAW clients.  These have all been
tested, and should be at least as correct as the old versions.

The only drawback is that there is no MUI support.  The MUI client will
not compile until this is dealt with.  I don't know if I am up to this task.

Some advantages of unifying the code is that it is possible to optimize
the loop in the iso case using isometric coordinates to get rid of the
current 100% extra drawing that is done (or the return value of
get_canvas_xy may be used for this purpose).  It may also be possible to
unify the iso and non-iso cases.

jason

Index: client//mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.17
diff -u -r1.17 mapview_common.c
--- client//mapview_common.c    2002/11/22 18:52:12     1.17
+++ client//mapview_common.c    2002/11/23 00:52:50
@@ -345,6 +345,57 @@
 }
 
 /**************************************************************************
+  Show descriptions for all cities visible on the map canvas.
+**************************************************************************/
+void show_city_descriptions(void)
+{
+  int map_view_x0, map_view_y0, map_win_width, map_win_height;
+  int map_tile_width, map_tile_height;
+  int canvas_x, canvas_y;
+  struct city *pcity;
+
+  if (!draw_city_names && !draw_city_productions)
+    return;
+
+  get_mapview_dimensions(&map_view_x0, &map_view_y0,
+                        &map_win_width, &map_win_height);
+  map_tile_width = (map_win_width - 1) / NORMAL_TILE_WIDTH + 1;
+  map_tile_height = (map_win_height - 1) / NORMAL_TILE_HEIGHT + 1;
+
+  if (is_isometric ) {
+    int w, h;
+
+    for (h = -1; h < map_tile_height * 2; h++) {
+      int x_base = map_view_x0 + h / 2 + (h != -1 ? h % 2 : 0);
+      int y_base = map_view_y0 + h / 2 + (h == -1 ? -1 : 0);
+      for (w = 0; w <= map_tile_width; w++) {
+       int x = x_base + w;
+       int y = y_base - w;
+       if (normalize_map_pos(&x, &y)
+           && (pcity = map_get_city(x, y))) {
+         get_canvas_xy(x, y, &canvas_x, &canvas_y);
+         show_city_desc(pcity, canvas_x, canvas_y);
+       }
+      }
+    }
+  } else { /* is_isometric */
+    int x1, y1;
+    for (x1 = 0; x1 < map_tile_width; x1++) {
+      for (y1 = 0; y1 < map_tile_height; y1++) {
+       int x = map_view_x0 + x1;
+       int y = map_view_y0 + y1;
+
+       if (normalize_map_pos(&x, &y)
+           && (pcity = map_get_city(x, y))) {
+         get_canvas_xy(x, y, &canvas_x, &canvas_y);
+         show_city_desc(pcity, canvas_x, canvas_y);
+       }
+      }
+    }
+  }
+}
+
+/**************************************************************************
   Find the "best" city to associate with the selected tile.
     a.  A city working the tile is the best
     b.  If another player is working the tile, return NULL.
Index: client//mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.11
diff -u -r1.11 mapview_common.h
--- client//mapview_common.h    2002/11/22 18:52:12     1.11
+++ client//mapview_common.h    2002/11/23 00:52:50
@@ -55,6 +55,8 @@
                                int map_view_map_height);
 
 void update_map_canvas_visible(void);
+
+void show_city_descriptions(void);
                                
 struct city *find_city_near_tile(int x, int y);
 
Index: client//gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.134
diff -u -r1.134 mapview.c
--- client//gui-gtk/mapview.c   2002/11/22 18:52:12     1.134
+++ client//gui-gtk/mapview.c   2002/11/23 00:52:51
@@ -1270,99 +1270,52 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void show_desc_at_tile(int x, int y)
+void show_city_desc(struct city *pcity, int canvas_x, int canvas_y)
 {
   static char buffer[512], buffer2[32];
-  struct city *pcity = map_get_city(x, y);
+  int w, w2, ascent;
+  enum color_std color;
 
-  if (pcity) {
-    int canvas_x, canvas_y;
-    int w, w2, ascent;
-    enum color_std color;
-
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-
-    get_city_mapview_name_and_growth(pcity, buffer, sizeof(buffer),
-                                    buffer2, sizeof(buffer2), &color);
-
-    gdk_string_extents(main_fontset, buffer, NULL, NULL, &w, &ascent, NULL);
-    if (buffer2[0] != '\0') {
-      /* HACK: put a character's worth of space between the two strings. */
-      w += gdk_string_width(main_fontset, "M");
-    }
-    w2 = gdk_string_width(prod_fontset, buffer2);
+  canvas_x += NORMAL_TILE_WIDTH / 2;
+  canvas_y += NORMAL_TILE_HEIGHT;
 
-    gtk_draw_shadowed_string(map_canvas->window, main_fontset,
-                            toplevel->style->black_gc,
-                            toplevel->style->white_gc,
-                            canvas_x + NORMAL_TILE_WIDTH / 2 - (w + w2) / 2,
-                            canvas_y + NORMAL_TILE_HEIGHT + ascent,
-                            buffer);
-    gdk_gc_set_foreground(civ_gc, colors_standard[color]);
-    gtk_draw_shadowed_string(map_canvas->window, prod_fontset,
-                            toplevel->style->black_gc,
-                            civ_gc,
-                            canvas_x + NORMAL_TILE_WIDTH / 2
-                            - (w + w2) / 2 + w,
-                            canvas_y + NORMAL_TILE_HEIGHT + ascent,
-                            buffer2);
-
-    if (draw_city_productions && (pcity->owner==game.player_idx)) {
-      int y_offset;
-
-      if (draw_city_names)
-       y_offset = gdk_string_height(main_fontset, buffer);
-      else
-       y_offset = 0;
-
-      get_city_mapview_production(pcity, buffer, sizeof(buffer));
-
-      gdk_string_extents(prod_fontset, buffer, NULL, NULL, &w, &ascent, NULL);
-      gtk_draw_shadowed_string(map_canvas->window, prod_fontset,
-                              toplevel->style->black_gc,
-                              toplevel->style->white_gc,
-                              canvas_x + NORMAL_TILE_WIDTH / 2 - w / 2,
-                              canvas_y + NORMAL_TILE_HEIGHT +
-                              ascent + 3 + y_offset, buffer);
-    }
-  }
-}
+  get_city_mapview_name_and_growth(pcity, buffer, sizeof(buffer),
+                                  buffer2, sizeof(buffer2), &color);
 
-/**************************************************************************
-...
-**************************************************************************/
-void show_city_descriptions(void)
-{
-  if (!draw_city_names && !draw_city_productions)
-    return;
+  gdk_string_extents(main_fontset, buffer, NULL, NULL, &w, &ascent, NULL);
+  if (buffer2[0] != '\0') {
+    /* HACK: put a character's worth of space between the two strings. */
+    w += gdk_string_width(main_fontset, "M");
+  }
+  w2 = gdk_string_width(prod_fontset, buffer2);
 
-  if (is_isometric ) {
-    int x, y;
-    int w, h;
-
-    for (h=-1; h<map_canvas_store_theight*2; h++) {
-      int x_base = map_view_x0 + h/2 + (h != -1 ? h%2 : 0);
-      int y_base = map_view_y0 + h/2 + (h == -1 ? -1 : 0);
-      for (w=0; w<=map_canvas_store_twidth; w++) {
-       x = (x_base + w);
-       y = y_base - w;
-       if (normalize_map_pos(&x, &y)) {
-         show_desc_at_tile(x, y);
-       }
-      }
-    }
-  } else { /* is_isometric */
-    int x1, y1;
-    for (x1 = 0; x1 < map_canvas_store_twidth; x1++) {
-      int x = map_view_x0 + x1;
-      for (y1 = 0; y1 < map_canvas_store_theight; y1++) {
-       int y = map_view_y0 + y1;
-
-       if (normalize_map_pos(&x, &y)) {
-         show_desc_at_tile(x, y);
-       }
-      }
+  gtk_draw_shadowed_string(map_canvas->window, main_fontset,
+                          toplevel->style->black_gc,
+                          toplevel->style->white_gc,
+                          canvas_x - (w + w2) / 2,
+                          canvas_y + ascent,
+                          buffer);
+  gdk_gc_set_foreground(civ_gc, colors_standard[color]);
+  gtk_draw_shadowed_string(map_canvas->window, prod_fontset,
+                          toplevel->style->black_gc,
+                          civ_gc,
+                          canvas_x - (w + w2) / 2 + w,
+                          canvas_y + ascent,
+                          buffer2);
+
+  if (draw_city_productions && (pcity->owner==game.player_idx)) {
+    if (draw_city_names) {
+      canvas_y += gdk_string_height(main_fontset, buffer);
     }
+
+    get_city_mapview_production(pcity, buffer, sizeof(buffer));
+
+    gdk_string_extents(prod_fontset, buffer, NULL, NULL, &w, &ascent, NULL);
+    gtk_draw_shadowed_string(map_canvas->window, prod_fontset,
+                            toplevel->style->black_gc,
+                            toplevel->style->white_gc,
+                            canvas_x - w / 2,
+                            canvas_y + ascent + 3, buffer);
   }
 }
 
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.22
diff -u -r1.22 mapview.c
--- client//gui-gtk-2.0/mapview.c       2002/11/22 18:52:13     1.22
+++ client//gui-gtk-2.0/mapview.c       2002/11/23 00:52:52
@@ -1294,138 +1294,90 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void show_desc_at_tile(PangoLayout *layout, int x, int y)
+void show_city_desc(struct city *pcity, int canvas_x, int canvas_y)
 {
   static char buffer[512], buffer2[32];
-  struct city *pcity;
-  if ((pcity = map_get_city(x, y))) {
-    int canvas_x, canvas_y;
-    PangoRectangle rect, rect2;
-    enum color_std color;
-    int extra_width = 0;
-
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-    if (draw_city_names) {
-      get_city_mapview_name_and_growth(pcity, buffer, sizeof(buffer),
-                                      buffer2, sizeof(buffer2), &color);
-
-      pango_layout_set_font_description(layout, main_font);
-      if (buffer2[0] != '\0') {
-       /* HACK: put a character's worth of space between the two strings. */
-       pango_layout_set_text(layout, "M", -1);
-       pango_layout_get_pixel_extents(layout, &rect, NULL);
-       extra_width = rect.width;
-      }
-      pango_layout_set_text(layout, buffer, -1);
-      pango_layout_get_pixel_extents(layout, &rect, NULL);
-      rect.width += extra_width;
+  PangoRectangle rect, rect2;
+  enum color_std color;
+  int extra_width = 0;
+  PangoLayout *layout;
 
-      if (draw_city_growth && pcity->owner == game.player_idx) {
-       /* We need to know the size of the growth text before
-          drawing anything. */
-       pango_layout_set_font_description(layout, city_productions_font);
-       pango_layout_set_text(layout, buffer2, -1);
-       pango_layout_get_pixel_extents(layout, &rect2, NULL);
-
-       /* Now return the layout to its previous state. */
-       pango_layout_set_font_description(layout, main_font);
-       pango_layout_set_text(layout, buffer, -1);
-      } else {
-       rect2.width = 0;
-      }
+  /* FIXME: layout should be statically declared */
+  layout = pango_layout_new(gdk_pango_context_get());
 
-      gtk_draw_shadowed_string(map_canvas->window,
-                          toplevel->style->black_gc,
-                          toplevel->style->white_gc,
-                          canvas_x + NORMAL_TILE_WIDTH / 2
-                              - (rect.width + rect2.width) / 2,
-                          canvas_y + NORMAL_TILE_HEIGHT +
-                          PANGO_ASCENT(rect), layout);
-
-      if (draw_city_growth && pcity->owner == game.player_idx) {
-       pango_layout_set_font_description(layout, city_productions_font);
-       pango_layout_set_text(layout, buffer2, -1);
-       gdk_gc_set_foreground(civ_gc, colors_standard[color]);
-       gtk_draw_shadowed_string(map_canvas->window,
-                       toplevel->style->black_gc,
-                       civ_gc,
-                       canvas_x + NORMAL_TILE_WIDTH / 2
-                                - (rect.width + rect2.width) / 2
-                                + rect.width,
-                       canvas_y + NORMAL_TILE_HEIGHT +
-                       PANGO_ASCENT(rect) + rect.height / 2
-                                - rect2.height / 2, layout);
+  canvas_x += NORMAL_TILE_WIDTH / 2;
+  canvas_y += NORMAL_TILE_HEIGHT;
 
-      }
+  if (draw_city_names) {
+    get_city_mapview_name_and_growth(pcity, buffer, sizeof(buffer),
+                                    buffer2, sizeof(buffer2), &color);
+
+    pango_layout_set_font_description(layout, main_font);
+    if (buffer2[0] != '\0') {
+      /* HACK: put a character's worth of space between the two strings. */
+      pango_layout_set_text(layout, "M", -1);
+      pango_layout_get_pixel_extents(layout, &rect, NULL);
+      extra_width = rect.width;
     }
+    pango_layout_set_text(layout, buffer, -1);
+    pango_layout_get_pixel_extents(layout, &rect, NULL);
+    rect.width += extra_width;
+
+    if (draw_city_growth && pcity->owner == game.player_idx) {
+      /* We need to know the size of the growth text before
+        drawing anything. */
+      pango_layout_set_font_description(layout, city_productions_font);
+      pango_layout_set_text(layout, buffer2, -1);
+      pango_layout_get_pixel_extents(layout, &rect2, NULL);
 
-    if (draw_city_productions && (pcity->owner==game.player_idx)) {
-      int y_offset;
-
-      get_city_mapview_production(pcity, buffer, sizeof(buffer));
+      /* Now return the layout to its previous state. */
+      pango_layout_set_font_description(layout, main_font);
+      pango_layout_set_text(layout, buffer, -1);
+    } else {
+      rect2.width = 0;
+    }
 
-      if (draw_city_names)
-       y_offset = rect.height + 3;
-      else
-       y_offset = 0;
-
-       pango_layout_set_font_description(layout, city_productions_font);
-       pango_layout_set_text(layout, buffer, -1);
-
-       pango_layout_get_pixel_extents(layout, &rect, NULL);
-       gtk_draw_shadowed_string(map_canvas->window,
-                          toplevel->style->black_gc,
-                          toplevel->style->white_gc,
-                          canvas_x + NORMAL_TILE_WIDTH / 2 - rect.width / 2,
-                          canvas_y + NORMAL_TILE_HEIGHT +
-                          PANGO_ASCENT(rect) + y_offset, layout);
+    gtk_draw_shadowed_string(map_canvas->window,
+                            toplevel->style->black_gc,
+                            toplevel->style->white_gc,
+                            canvas_x - (rect.width + rect2.width) / 2,
+                            canvas_y + PANGO_ASCENT(rect), layout);
+
+    if (draw_city_growth && pcity->owner == game.player_idx) {
+      pango_layout_set_font_description(layout, city_productions_font);
+      pango_layout_set_text(layout, buffer2, -1);
+      gdk_gc_set_foreground(civ_gc, colors_standard[color]);
+      gtk_draw_shadowed_string(map_canvas->window,
+                              toplevel->style->black_gc,
+                              civ_gc,
+                              canvas_x - (rect.width + rect2.width) / 2
+                              + rect.width,
+                              canvas_y + PANGO_ASCENT(rect)
+                              + rect.height / 2 - rect2.height / 2,
+                              layout);
     }
-  }
-}
 
-/**************************************************************************
-...
-**************************************************************************/
-void show_city_descriptions(void)
-{
-  PangoLayout *layout;
+    canvas_y += rect.height + 3;
+  }
 
-  if (!draw_city_names && !draw_city_productions)
-    return;
+  if (draw_city_productions && (pcity->owner==game.player_idx)) {
+    get_city_mapview_production(pcity, buffer, sizeof(buffer));
 
-  layout = pango_layout_new(gdk_pango_context_get());
+    pango_layout_set_font_description(layout, city_productions_font);
+    pango_layout_set_text(layout, buffer, -1);
 
-  if (is_isometric ) {
-    int x, y;
-    int w, h;
-
-    for (h=-1; h<map_canvas_store_theight*2; h++) {
-      int x_base = map_view_x0 + h/2 + (h != -1 ? h%2 : 0);
-      int y_base = map_view_y0 + h/2 + (h == -1 ? -1 : 0);
-      for (w=0; w<=map_canvas_store_twidth; w++) {
-       x = (x_base + w);
-       y = y_base - w;
-       if (normalize_map_pos(&x, &y)) {
-         show_desc_at_tile(layout, x, y);
-       }
-      }
-    }
-  } else { /* is_isometric */
-    int x1, y1;
-    for (x1 = 0; x1 < map_canvas_store_twidth; x1++) {
-      int x = map_view_x0 + x1;
-      for (y1 = 0; y1 < map_canvas_store_theight; y1++) {
-       int y = map_view_y0 + y1;
-
-       if (normalize_map_pos(&x, &y)) {
-         show_desc_at_tile(layout, x, y);
-       }
-      }
-    }
+    pango_layout_get_pixel_extents(layout, &rect, NULL);
+    gtk_draw_shadowed_string(map_canvas->window,
+                            toplevel->style->black_gc,
+                            toplevel->style->white_gc,
+                            canvas_x - rect.width / 2,
+                            canvas_y + PANGO_ASCENT(rect), layout);
   }
 
+#if 0
   gdk_gc_set_clip_rectangle(toplevel->style->black_gc, NULL);
   gdk_gc_set_clip_rectangle(toplevel->style->white_gc, NULL);
+#endif
   g_object_unref(layout);
 }
 
Index: client//gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.81
diff -u -r1.81 mapclass.c
--- client//gui-mui/mapclass.c  2002/11/14 09:14:57     1.81
+++ client//gui-mui/mapclass.c  2002/11/23 00:52:54
@@ -433,7 +433,8 @@
 }
 
 /**************************************************************************
-...
+  FIXME: this function is now a part of the GUI interface.  It has
+  been renamed to show_city_desc().  See Map_Priv_showCityDescriptions().
 **************************************************************************/
 static void show_desc_at_tile(Object *o, struct Map_Data *data, int x, int y)
 {
@@ -475,6 +476,11 @@
   }
 }
 
+/**************************************************************************
+  FIXME: this function has gone away; show_desc_at_tile is now used
+  exclusively instead.  But some of the font work here will have to
+  be moved or rethought.
+**************************************************************************/
 static void Map_Priv_ShowCityDescriptions(Object *o, struct Map_Data *data)
 {
   struct TextFont *new_font;
Index: client//gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.47
diff -u -r1.47 mapview.c
--- client//gui-mui/mapview.c   2002/11/19 20:13:39     1.47
+++ client//gui-mui/mapview.c   2002/11/23 00:52:54
@@ -504,7 +504,8 @@
 }
 
 /**************************************************************************
-...
+  FIXME: this function has been moved into mapview_common.  See
+  MUIM_Map_ShowCityDescriptions.
 **************************************************************************/
 void show_city_descriptions(void)
 {
Index: client//gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.17
diff -u -r1.17 mapview.c
--- client//gui-stub/mapview.c  2002/11/19 20:13:39     1.17
+++ client//gui-stub/mapview.c  2002/11/23 00:52:54
@@ -83,9 +83,10 @@
 }
 
 /**************************************************************************
-  Show descriptions for all cities visible on the map canvas.
+  Draw a description for the given city.  (canvas_x, canvas_y) is the
+  canvas position of the city itself.
 **************************************************************************/
-void show_city_descriptions(void)
+void show_city_desc(struct city *pcity, int canvas_x, int canvas_y)
 {
        /* PORTME */
 }
Index: client//gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.36
diff -u -r1.36 mapview.c
--- client//gui-win32/mapview.c 2002/11/19 20:13:39     1.36
+++ client//gui-win32/mapview.c 2002/11/23 00:52:55
@@ -893,102 +893,61 @@
 /**************************************************************************
 
 **************************************************************************/
-static void show_desc_at_tile(HDC hdc,int x, int y)
+void show_city_desc(struct city *pcity, int canvas_x, int canvas_y)
 {
   char buffer[500];
   int y_offset;
-  int canvas_x,canvas_y;
-  struct city *pcity;
-  if ((pcity = map_get_city(x, y))) {
-    get_canvas_xy(x, y, &canvas_x, &canvas_y);
-    y_offset=canvas_y+NORMAL_TILE_HEIGHT;
-    if ((draw_city_names)&&(pcity->name)) {
-      RECT rc;
-      DrawText(hdc,pcity->name,strlen(pcity->name),&rc,DT_CALCRECT);
-      rc.left=canvas_x+NORMAL_TILE_WIDTH/2-10;
-      rc.right=rc.left+20;
-      rc.bottom-=rc.top;
-      rc.top=y_offset;
-      rc.bottom+=rc.top;
-      SetTextColor(hdc,RGB(0,0,0));
-      DrawText(hdc,pcity->name,strlen(pcity->name),&rc,
-              DT_NOCLIP | DT_CENTER);
-      rc.left++;
-      rc.top--;
-      rc.right++;
-      rc.bottom--;
-      SetTextColor(hdc,RGB(255,255,255));
-      DrawText(hdc,pcity->name,strlen(pcity->name),&rc,
-              DT_NOCLIP | DT_CENTER);
-      y_offset=rc.bottom+2;
-    }      
-    if (draw_city_productions && (pcity->owner==game.player_idx)) {
-      RECT rc;
-
-      get_city_mapview_production(pcity, buffer, sizeof(buffer));
-      
-      DrawText(hdc,buffer,strlen(buffer),&rc,DT_CALCRECT);
-      rc.left=canvas_x+NORMAL_TILE_WIDTH/2-10;
-      rc.right=rc.left+20;
-      rc.bottom-=rc.top;
-      rc.top=y_offset;
-      rc.bottom+=rc.top; 
-      SetTextColor(hdc,RGB(0,0,0));
-      DrawText(hdc,buffer,strlen(buffer),&rc,
-              DT_NOCLIP | DT_CENTER);
-      rc.left++;
-      rc.top--;
-      rc.right++;
-      rc.bottom--;
-      SetTextColor(hdc,RGB(255,255,255));
-      DrawText(hdc,buffer,strlen(buffer),&rc,
-              DT_NOCLIP | DT_CENTER);
-    }
-  }
-  
-}
-
-/**************************************************************************
-
-**************************************************************************/
-void show_city_descriptions(void)
-{
   HDC hdc;
 
-  if (!draw_city_names && !draw_city_productions)
-    return;
-
   /* TODO: hdc should be stored statically */
   hdc = GetDC(map_window);
   SetBkMode(hdc,TRANSPARENT);
+
+  y_offset = canvas_y + NORMAL_TILE_HEIGHT;
+  if (draw_city_names && pcity->name) {
+    RECT rc;
+
+    /* FIXME: draw city growth as well, using
+     * get_city_mapview_name_and_growth() */
+
+    DrawText(hdc, pcity->name, strlen(pcity->name), &rc, DT_CALCRECT);
+    rc.left = canvas_x + NORMAL_TILE_WIDTH / 2 - 10;
+    rc.right = rc.left + 20;
+    rc.bottom -= rc.top;
+    rc.top = y_offset;
+    rc.bottom += rc.top;
+    SetTextColor(hdc, RGB(0, 0, 0));
+    DrawText(hdc, pcity->name, strlen(pcity->name), &rc,
+            DT_NOCLIP | DT_CENTER);
+    rc.left++;
+    rc.top--;
+    rc.right++;
+    rc.bottom--;
+    SetTextColor(hdc, RGB(255, 255, 255));
+    DrawText(hdc, pcity->name, strlen(pcity->name), &rc,
+            DT_NOCLIP | DT_CENTER);
+    y_offset = rc.bottom + 2;
+  }
 
-  if (is_isometric ) {
-    int x, y;
-    int w, h;
-    
-    for (h=-1; h<map_view_height*2; h++) {
-      int x_base = map_view_x + h/2 + (h != -1 ? h%2 : 0);
-      int y_base = map_view_y + h/2 + (h == -1 ? -1 : 0);
-      for (w=0; w<=map_view_width; w++) {
-        x = (x_base + w);
-        y = y_base - w;
-        if (normalize_map_pos(&x, &y)) {
-          show_desc_at_tile(hdc, x, y);
-        }
-      }
-    }
-  } else { /* is_isometric */
-    int x1, y1;
-    for (x1 = 0; x1 < map_view_width; x1++) {
-      int x = map_view_x + x1;
-      for (y1 = 0; y1 < map_view_width; y1++) {
-        int y = map_view_y + y1;
-
-        if (normalize_map_pos(&x, &y)) {
-          show_desc_at_tile(hdc, x, y);
-        }
-      }
-    }
+  if (draw_city_productions && pcity->owner == game.player_idx) {
+    RECT rc;
+
+    get_city_mapview_production(pcity, buffer, sizeof(buffer));
+      
+    DrawText(hdc, buffer, strlen(buffer), &rc, DT_CALCRECT);
+    rc.left = canvas_x + NORMAL_TILE_WIDTH / 2 - 10;
+    rc.right = rc.left + 20;
+    rc.bottom -= rc.top;
+    rc.top = y_offset;
+    rc.bottom += rc.top; 
+    SetTextColor(hdc, RGB(0, 0, 0));
+    DrawText(hdc, buffer, strlen(buffer), &rc, DT_NOCLIP | DT_CENTER);
+    rc.left++;
+    rc.top--;
+    rc.right++;
+    rc.bottom--;
+    SetTextColor(hdc, RGB(255, 255, 255));
+    DrawText(hdc, buffer, strlen(buffer), &rc, DT_NOCLIP | DT_CENTER);
   }
 
   ReleaseDC(map_window, hdc);
Index: client//gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.107
diff -u -r1.107 mapview.c
--- client//gui-xaw/mapview.c   2002/11/22 18:52:13     1.107
+++ client//gui-xaw/mapview.c   2002/11/23 00:52:56
@@ -734,65 +734,47 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void show_city_descriptions(void)
+void show_city_desc(struct city *pcity, int canvas_x, int canvas_y)
 {
-  int x, y;
+  char buffer[512], buffer2[512];
+  enum color_std color;
+  int w, w2;
+
+  canvas_x += NORMAL_TILE_WIDTH / 2;
+  canvas_y += NORMAL_TILE_HEIGHT;
+
+  get_city_mapview_name_and_growth(pcity, buffer, sizeof(buffer),
+                                  buffer2, sizeof(buffer2), &color);
+
+  w = XTextWidth(main_font_struct, buffer, strlen(buffer));
+  if (buffer2[0] != '\0') {
+    /* HACK: put a character's worth of space between the two strings. */
+    w += XTextWidth(main_font_struct, "M", 1);
+  }
+  w2 = XTextWidth(main_font_struct, buffer2, strlen(buffer2));
+
+  draw_shadowed_string(main_font_struct, font_gc,
+                      COLOR_STD_WHITE, COLOR_STD_BLACK,
+                      canvas_x - (w + w2) / 2,
+                      canvas_y, buffer);
+
+  draw_shadowed_string(prod_font_struct, prod_font_gc, color,
+                      COLOR_STD_BLACK,
+                      canvas_x - (w + w2) / 2 + w,
+                      canvas_y, buffer2);
+
+  if (draw_city_productions && (pcity->owner == game.player_idx)) {
+    if (draw_city_names) {
+      canvas_y += main_font_struct->ascent + main_font_struct->descent;
+    }
 
-  if (!draw_city_names && !draw_city_productions)
-    return;
+    get_city_mapview_production(pcity, buffer, sizeof(buffer));
+    w = XTextWidth(prod_font_struct, buffer, strlen(buffer));
 
-  for (y = 0; y < map_canvas_store_theight; ++y) {
-    for (x = 0; x < map_canvas_store_twidth; ++x) {
-      int rx = map_view_x0 + x;
-      int ry = map_view_y0 + y;
-      struct city *pcity;
-
-      if (!normalize_map_pos(&rx, &ry))
-        continue;
-
-      if ((pcity = map_get_city(rx, ry))) {
-       char buffer[512], buffer2[512];
-       enum color_std color;
-       int w, w2;
-
-       get_city_mapview_name_and_growth(pcity, buffer, sizeof(buffer),
-                                        buffer2, sizeof(buffer2), &color);
-
-       w = XTextWidth(main_font_struct, buffer, strlen(buffer));
-       if (buffer2[0] != '\0') {
-         /* HACK: put a character's worth of space between the two strings. */
-         w += XTextWidth(main_font_struct, "M", 1);
-       }
-       w2 = XTextWidth(main_font_struct, buffer2, strlen(buffer2));
-
-       draw_shadowed_string(main_font_struct, font_gc,
-                            COLOR_STD_WHITE, COLOR_STD_BLACK,
-                            x * NORMAL_TILE_WIDTH +
-                            NORMAL_TILE_WIDTH / 2 - (w + w2) / 2,
-                            (y + 1) * NORMAL_TILE_HEIGHT, buffer);
-
-       draw_shadowed_string(prod_font_struct, prod_font_gc, color,
-                            COLOR_STD_BLACK,
-                            x * NORMAL_TILE_WIDTH + NORMAL_TILE_WIDTH / 2 -
-                            (w + w2) / 2 + w, (y + 1) * NORMAL_TILE_HEIGHT,
-                            buffer2);
-
-       if (draw_city_productions && (pcity->owner == game.player_idx)) {
-         int yoffset = (draw_city_names ? main_font_struct->ascent +
-                        main_font_struct->descent : 0);
-
-          get_city_mapview_production(pcity, buffer, sizeof(buffer));
-         w = XTextWidth(prod_font_struct, buffer, strlen(buffer));
-
-         draw_shadowed_string(prod_font_struct, prod_font_gc,
-                              COLOR_STD_WHITE, COLOR_STD_BLACK,
-                              x * NORMAL_TILE_WIDTH +
-                              NORMAL_TILE_WIDTH / 2 - w / 2,
-                              (y + 1) * NORMAL_TILE_HEIGHT +
-                              yoffset, buffer);
-       }
-      }
-    }
+    draw_shadowed_string(prod_font_struct, prod_font_gc,
+                        COLOR_STD_WHITE, COLOR_STD_BLACK,
+                        canvas_x - w / 2,
+                        canvas_y, buffer);
   }
 }
 
Index: client//include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.23
diff -u -r1.23 mapview_g.h
--- client//include/mapview_g.h 2002/11/19 20:13:39     1.23
+++ client//include/mapview_g.h 2002/11/23 00:52:56
@@ -39,7 +39,7 @@
 
 void center_tile_mapcanvas(int x, int y);
 
-void show_city_descriptions(void);
+void show_city_desc(struct city *pcity, int canvas_x, int canvas_y);
 
 void update_map_canvas(int x, int y, int width, int height,
                       bool write_to_screen);

[Prev in Thread] Current Thread [Next in Thread]