Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#8488) move iso-view grid drawing into mapview_common
Home

[Freeciv-Dev] (PR#8488) move iso-view grid drawing 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#8488) move iso-view grid drawing into mapview_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 11 Apr 2004 13:10:55 -0700
Reply-to: rt@xxxxxxxxxxx

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

This function creates a new function in mapview_common, 
tile_draw_grid_iso.  This draws the map grid, the map borders, and the 
"coastlines".  Each of these is handled by a separate static function in 
mapview_common.c; borders were already done this way.

It is tested under gui-gtk only; gui-gtk-2.0 is identical and so should 
also work.  I suspect borders may fail under gui-win32 since it doesn't 
have a "full" implementation of canvas_put_line (AFAICT currently 
borders are not drawn).  This should be easily fixable.

gui-sdl and gui-mui don't use this function (but should).  gui-xaw has 
no iso-view, of course.

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.98
diff -u -r1.98 mapview_common.c
--- client/mapview_common.c     29 Mar 2004 19:17:06 -0000      1.98
+++ client/mapview_common.c     11 Apr 2004 20:03:31 -0000
@@ -999,14 +999,43 @@
   }
 }
 
+/****************************************************************************
+   Draw the map grid around the given map tile at the given canvas position
+   in isometric view.
+****************************************************************************/
+static void tile_draw_map_grid_iso(struct canvas *pcanvas,
+                                  int map_x, int map_y,
+                                  int canvas_x, int canvas_y,
+                                  enum draw_type draw)
+{
+  if (!draw_map_grid
+      || map_get_tile(map_x, map_y)->client.hilite != HILITE_NONE) {
+    return;
+  }
+
+  /* we draw the 2 lines on top of the tile; the buttom lines will be
+   * drawn by the tiles underneath. */
+  if (draw & D_M_R) {
+    canvas_put_line(pcanvas, get_grid_color(map_x, map_y, map_x, map_y - 1),
+                   LINE_NORMAL, canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y,
+                   NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 2);
+  }
+
+  if (draw & D_M_L) {
+    canvas_put_line(pcanvas, get_grid_color(map_x, map_y, map_x - 1, map_y),
+                   LINE_NORMAL, canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2,
+                   NORMAL_TILE_WIDTH / 2, -NORMAL_TILE_HEIGHT / 2);
+  }
+}
+
 /**************************************************************************
    Draw the borders of the given map tile at the given canvas position
    in isometric view.
 **************************************************************************/
-void tile_draw_borders_iso(struct canvas *pcanvas,
-                          int map_x, int map_y,
-                          int canvas_x, int canvas_y,
-                          enum draw_type draw)
+static void tile_draw_borders_iso(struct canvas *pcanvas,
+                                 int map_x, int map_y,
+                                 int canvas_x, int canvas_y,
+                                 enum draw_type draw)
 {
   struct player *this_owner = map_get_owner(map_x, map_y), *adjc_owner;
   int x1, y1;
@@ -1046,6 +1075,53 @@
                      NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 2);
     }
   }
+}
+
+/****************************************************************************
+   Draw the coastline of the given map tile at the given canvas position
+   in isometric view.
+****************************************************************************/
+static void tile_draw_coastline_iso(struct canvas *pcanvas,
+                                   int map_x, int map_y,
+                                   int canvas_x, int canvas_y,
+                                   enum draw_type draw)
+{
+  enum tile_terrain_type t1 = map_get_terrain(map_x, map_y), t2;
+  int adjc_x, adjc_y;
+
+  if (!draw_coastline || draw_terrain || t1 == T_UNKNOWN) {
+    return;
+  }
+
+  if ((draw & D_M_R) && MAPSTEP(adjc_x, adjc_y, map_x, map_y, DIR8_NORTH)) {
+    t2 = map_get_terrain(adjc_x, adjc_y);
+    if (t2 != T_UNKNOWN        && (is_ocean(t1) ^ is_ocean(t2))) {
+      canvas_put_line(pcanvas, COLOR_STD_OCEAN, LINE_NORMAL,
+                     canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y,
+                     NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 2);
+    }
+  }
+
+  if ((draw & D_M_L) && MAPSTEP(adjc_x, adjc_y, map_x, map_y, DIR8_WEST)) {
+    t2 = map_get_terrain(adjc_x, adjc_y);
+    if (t2 != T_UNKNOWN        && (is_ocean(t1) ^ is_ocean(t2))) {
+      canvas_put_line(pcanvas, COLOR_STD_OCEAN, LINE_NORMAL,
+                     canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2,
+                     NORMAL_TILE_WIDTH / 2, -NORMAL_TILE_HEIGHT / 2);
+    }
+  }
+}
+
+/****************************************************************************
+   Draw the grid lines of the given map tile at the given canvas position
+   in isometric view.  (This include the map grid, borders, and coastline).
+****************************************************************************/
+void tile_draw_grid_iso(struct canvas *pcanvas, int map_x, int map_y,
+                       int canvas_x, int canvas_y, enum draw_type draw)
+{
+  tile_draw_map_grid_iso(pcanvas, map_x, map_y, canvas_x, canvas_y, draw);
+  tile_draw_borders_iso(pcanvas, map_x, map_y, canvas_x, canvas_y, draw);
+  tile_draw_coastline_iso(pcanvas, map_x, map_y, canvas_x, canvas_y, draw);
 }
 
 /**************************************************************************
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.53
diff -u -r1.53 mapview_common.h
--- client/mapview_common.h     29 Mar 2004 19:17:06 -0000      1.53
+++ client/mapview_common.h     11 Apr 2004 20:03:31 -0000
@@ -179,10 +179,8 @@
 
 void put_one_tile(struct canvas *pcanvas, int map_x, int map_y,
                  int canvas_x, int canvas_y, bool citymode);
-void tile_draw_borders_iso(struct canvas *pcanvas,
-                          int map_x, int map_y,
-                          int canvas_x, int canvas_y,
-                          enum draw_type draw);
+void tile_draw_grid_iso(struct canvas *pcanvas, int map_x, int map_y,
+                       int canvas_x, int canvas_y, enum draw_type draw);
 
 void update_map_canvas(int x, int y, int width, int height,
                       bool write_to_screen);
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.211
diff -u -r1.211 mapview.c
--- client/gui-gtk/mapview.c    30 Mar 2004 02:01:27 -0000      1.211
+++ client/gui-gtk/mapview.c    11 Apr 2004 20:03:31 -0000
@@ -712,7 +712,7 @@
 
   switch (ltype) {
   case LINE_NORMAL:
-    gc = civ_gc;
+    gc = thin_line_gc;
     break;
   case LINE_BORDER:
     gc = border_line_gc;
@@ -1091,56 +1091,8 @@
     }
   }
 
-  /*** Map grid ***/
-  if (draw_map_grid && !tile_hilited) {
-    /* we draw the 2 lines on top of the tile; the buttom lines will be
-       drawn by the tiles underneath. */
-    if (draw & D_M_R) {
-      gdk_gc_set_foreground(thin_line_gc,
-                           colors_standard[get_grid_color
-                                           (x, y, x, y - 1)]);
-      gdk_draw_line(pm, thin_line_gc,
-                   canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y,
-                   canvas_x + NORMAL_TILE_WIDTH,
-                   canvas_y + NORMAL_TILE_HEIGHT / 2);
-    }
-
-    if (draw & D_M_L) {
-      gdk_gc_set_foreground(thin_line_gc,
-                           colors_standard[get_grid_color
-                                           (x, y, x - 1, y)]);
-      gdk_draw_line(pm, thin_line_gc,
-                   canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2,
-                   canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y);
-    }
-  }
-
-  /* National borders */
-  tile_draw_borders_iso(&canvas_store, x, y, canvas_x, canvas_y, draw);
-
-  if (draw_coastline && !draw_terrain) {
-    enum tile_terrain_type t1 = map_get_terrain(x, y), t2;
-    int x1, y1;
-    gdk_gc_set_foreground(thin_line_gc, colors_standard[COLOR_STD_OCEAN]);
-    x1 = x; y1 = y-1;
-    if (normalize_map_pos(&x1, &y1)) {
-      t2 = map_get_terrain(x1, y1);
-      if (draw & D_M_R && (is_ocean(t1) ^ is_ocean(t2))) {
-       gdk_draw_line(pm, thin_line_gc,
-                     canvas_x+NORMAL_TILE_WIDTH/2, canvas_y,
-                     canvas_x+NORMAL_TILE_WIDTH, 
canvas_y+NORMAL_TILE_HEIGHT/2);
-      }
-    }
-    x1 = x-1; y1 = y;
-    if (normalize_map_pos(&x1, &y1)) {
-      t2 = map_get_terrain(x1, y1);
-      if (draw & D_M_L && (is_ocean(t1) ^ is_ocean(t2))) {
-       gdk_draw_line(pm, thin_line_gc,
-                     canvas_x, canvas_y + NORMAL_TILE_HEIGHT/2,
-                     canvas_x+NORMAL_TILE_WIDTH/2, canvas_y);
-      }
-    }
-  }
+  /*** Grid (map grid, borders, coastline, etc.) ***/
+  tile_draw_grid_iso(&canvas_store, x, y, canvas_x, canvas_y, draw);
 
   /*** City and various terrain improvements ***/
   if (pcity && draw_cities) {
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.115
diff -u -r1.115 mapview.c
--- client/gui-gtk-2.0/mapview.c        4 Apr 2004 14:22:12 -0000       1.115
+++ client/gui-gtk-2.0/mapview.c        11 Apr 2004 20:03:32 -0000
@@ -813,7 +813,7 @@
 
   switch (ltype) {
   case LINE_NORMAL:
-    gc = civ_gc;
+    gc = thin_line_gc;
     break;
   case LINE_BORDER:
     gc = border_line_gc;
@@ -1203,56 +1203,8 @@
     }
   }
 
-  /*** Map grid ***/
-  if (draw_map_grid && !tile_hilited) {
-    /* we draw the 2 lines on top of the tile; the buttom lines will be
-       drawn by the tiles underneath. */
-    if (draw & D_M_R) {
-      gdk_gc_set_foreground(thin_line_gc,
-                           colors_standard[get_grid_color
-                                           (x, y, x, y - 1)]);
-      gdk_draw_line(pm, thin_line_gc,
-                   canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y,
-                   canvas_x + NORMAL_TILE_WIDTH,
-                   canvas_y + NORMAL_TILE_HEIGHT / 2);
-    }
-
-    if (draw & D_M_L) {
-      gdk_gc_set_foreground(thin_line_gc,
-                           colors_standard[get_grid_color
-                                           (x, y, x - 1, y)]);
-      gdk_draw_line(pm, thin_line_gc,
-                   canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2,
-                   canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y);
-    }
-  }
-
-  /* National borders */
-  tile_draw_borders_iso(&canvas_store, x, y, canvas_x, canvas_y, draw);
-
-  if (draw_coastline && !draw_terrain) {
-    enum tile_terrain_type t1 = map_get_terrain(x, y), t2;
-    int x1, y1;
-    gdk_gc_set_foreground(thin_line_gc, colors_standard[COLOR_STD_OCEAN]);
-    x1 = x; y1 = y-1;
-    if (normalize_map_pos(&x1, &y1)) {
-      t2 = map_get_terrain(x1, y1);
-      if (draw & D_M_R && (is_ocean(t1) ^ is_ocean(t2))) {
-       gdk_draw_line(pm, thin_line_gc,
-                     canvas_x+NORMAL_TILE_WIDTH/2, canvas_y,
-                     canvas_x+NORMAL_TILE_WIDTH, 
canvas_y+NORMAL_TILE_HEIGHT/2);
-      }
-    }
-    x1 = x-1; y1 = y;
-    if (normalize_map_pos(&x1, &y1)) {
-      t2 = map_get_terrain(x1, y1);
-      if (draw & D_M_L && (is_ocean(t1) ^ is_ocean(t2))) {
-       gdk_draw_line(pm, thin_line_gc,
-                     canvas_x, canvas_y + NORMAL_TILE_HEIGHT/2,
-                     canvas_x+NORMAL_TILE_WIDTH/2, canvas_y);
-      }
-    }
-  }
+  /*** Grid (map grid, borders, coastline, etc.) ***/
+  tile_draw_grid_iso(&canvas_store, x, y, canvas_x, canvas_y, draw);
 
   /*** City and various terrain improvements ***/
   if (pcity && draw_cities) {
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.107
diff -u -r1.107 mapview.c
--- client/gui-win32/mapview.c  25 Mar 2004 23:29:08 -0000      1.107
+++ client/gui-win32/mapview.c  11 Apr 2004 20:03:32 -0000
@@ -1000,25 +1000,10 @@
     else
       freelog(LOG_ERROR, "sprite is NULL");
   }
-  /*** Map grid ***/
-  if (draw_map_grid) {
-    HPEN old;
-    /* we draw the 2 lines on top of the tile; the buttom lines will be
-       drawn by the tiles underneath. */
-    old=SelectObject(hdc,pen_std[COLOR_STD_BLACK]);
-    if (draw & D_M_R)
-      {
-       MoveToEx(hdc,canvas_x+NORMAL_TILE_WIDTH/2,canvas_y,NULL);
-       LineTo(hdc,canvas_x+NORMAL_TILE_WIDTH,
-              canvas_y+NORMAL_TILE_HEIGHT/2);
-      }
-    if (draw & D_M_L)
-      {
-       MoveToEx(hdc,canvas_x,canvas_y+NORMAL_TILE_HEIGHT/2,NULL);
-       LineTo(hdc,canvas_x+NORMAL_TILE_WIDTH/2,canvas_y);
-      }
-    SelectObject(hdc,old);
-  }
+
+  /*** Grid (map grid, borders, coastline, etc.) ***/
+  tile_draw_grid_iso(&canvas_store, x, y, canvas_x, canvas_y, draw);
+
   if (draw_coastline && !draw_terrain) {
     enum tile_terrain_type t1 = map_get_terrain(x, y), t2;
     int x1, y1;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8488) move iso-view grid drawing into mapview_common, Jason Short <=