Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12694) new client files for overview code
Home

[Freeciv-Dev] (PR#12694) new client files for overview code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12694) new client files for overview code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Mar 2005 12:50:48 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch splits off some of the massive mapview_common code into a new 
file overview_common.  Joining it there are a stray function and 
variable from tilespec.

In theory a lot of the overview stuff can be encapsulated better. 
However I haven't done this, so the only advantage at this point is 
separation of unrelated code into a separate file (mapview and overview 
are only marginally related).  And maybe it will speed (re)compilation a 
tiny bit.

This patch is just copy-and-paste except:

* Of course the new files needed headers and footers.
* I added the .h file as an #include to some other files.
* Some files were made static or made unstatic as needed.
* I cleaned up overview_tile_color a little.
* I moved the initialization of mapview.can_do_cached_drawing out of 
set_overview_dimensions and into init_mapview_decorations.  Both are 
equally a hack (they're called at the same time).

Only the GTK client is updated.  Others may need some new #includes.

-jason

Index: client/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/Makefile.am,v
retrieving revision 1.62
diff -u -r1.62 Makefile.am
--- client/Makefile.am  19 Mar 2005 23:04:35 -0000      1.62
+++ client/Makefile.am  29 Mar 2005 20:39:54 -0000
@@ -170,6 +170,8 @@
        mapview_common.h \
        messagewin_common.c \
        messagewin_common.h \
+       overview_common.c       \
+       overview_common.h       \
        packhand.c      \
        packhand.h      \
        packhand_gen.h  \
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.165
diff -u -r1.165 control.c
--- client/control.c    27 Mar 2005 09:22:43 -0000      1.165
+++ client/control.c    29 Mar 2005 20:39:54 -0000
@@ -38,6 +38,7 @@
 #include "mapview_g.h"
 #include "menu_g.h"
 #include "options.h"
+#include "overview_common.h"
 #include "tilespec.h"
 
 #include "control.h"
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.52
diff -u -r1.52 mapctrl_common.c
--- client/mapctrl_common.c     28 Mar 2005 16:48:40 -0000      1.52
+++ client/mapctrl_common.c     29 Mar 2005 20:39:55 -0000
@@ -36,6 +36,7 @@
 #include "mapctrl_g.h"
 #include "mapview_g.h"
 #include "options.h"
+#include "overview_common.h"
 #include "tilespec.h"
 
 #include "mapctrl_common.h"
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.222
diff -u -r1.222 mapview_common.c
--- client/mapview_common.c     28 Mar 2005 16:59:14 -0000      1.222
+++ client/mapview_common.c     29 Mar 2005 20:39:55 -0000
@@ -34,26 +34,15 @@
 #include "control.h"
 #include "goto.h"
 #include "mapview_common.h"
+#include "overview_common.h"
 #include "tilespec.h"
 
 struct mapview_decoration *map_deco;
 struct view mapview;
-struct overview overview;
 bool can_slide = TRUE;
 
-/*
- * Set to TRUE if the backing store is more recent than the version
- * drawn into overview.window.
- */
-static bool overview_dirty = FALSE;
-
 static void base_canvas_to_map_pos(int *map_x, int *map_y,
                                   int canvas_x, int canvas_y);
-static void center_tile_overviewcanvas(struct tile *ptile);
-static void get_mapview_corners(int x[4], int y[4]);
-static void redraw_overview(void);
-static void dirty_overview(void);
-static void flush_dirty_overview(void);
 
 enum update_type {
   /* Masks */
@@ -1967,152 +1956,10 @@
 }
 
 /**************************************************************************
-  Copies the overview image from the backing store to the window and
-  draws the viewrect on top of it.
-**************************************************************************/
-static void redraw_overview(void)
-{
-  struct canvas *dest = get_overview_window();
-
-  if (!dest || !overview.store) {
-    return;
-  }
-
-  {
-    struct canvas *src = overview.store;
-    int x = overview.map_x0 * OVERVIEW_TILE_SIZE;
-    int y = overview.map_y0 * OVERVIEW_TILE_SIZE;
-    int ix = overview.width - x;
-    int iy = overview.height - y;
-
-    canvas_copy(dest, src, 0, 0, ix, iy, x, y);
-    canvas_copy(dest, src, 0, y, ix, 0, x, iy);
-    canvas_copy(dest, src, x, 0, 0, iy, ix, y);
-    canvas_copy(dest, src, x, y, 0, 0, ix, iy);
-  }
-
-  {
-    int i;
-    int x[4], y[4];
-
-    get_mapview_corners(x, y);
-
-    for (i = 0; i < 4; i++) {
-      int src_x = x[i];
-      int src_y = y[i];
-      int dest_x = x[(i + 1) % 4];
-      int dest_y = y[(i + 1) % 4];
-
-      canvas_put_line(dest, COLOR_STD_WHITE, LINE_NORMAL, src_x, src_y,
-                     dest_x - src_x, dest_y - src_y);
-    }
-  }
-
-  overview_dirty = FALSE;
-}
-
-/****************************************************************************
-  Mark the overview as "dirty" so that it will be redrawn soon.
-****************************************************************************/
-static void dirty_overview(void)
-{
-  overview_dirty = TRUE;
-}
-
-/****************************************************************************
-  Redraw the overview if it is "dirty".
-****************************************************************************/
-static void flush_dirty_overview(void)
-{
-  if (overview_dirty) {
-    redraw_overview();
-  }
-}
-
-/**************************************************************************
-  Center the overview around the mapview.
-**************************************************************************/
-static void center_tile_overviewcanvas(struct tile *ptile)
-{
-  /* The overview coordinates are equivalent to (scaled) natural
-   * coordinates. */
-  do_in_natural_pos(ntl_x, ntl_y, ptile->x, ptile->y) {
-    /* NOTE: this embeds the map wrapping in the overview code.  This is
-     * basically necessary for the overview to be efficiently
-     * updated. */
-    if (topo_has_flag(TF_WRAPX)) {
-      overview.map_x0 = FC_WRAP(ntl_x - NATURAL_WIDTH / 2, NATURAL_WIDTH);
-    } else {
-      overview.map_x0 = 0;
-    }
-    if (topo_has_flag(TF_WRAPY)) {
-      overview.map_y0 = FC_WRAP(ntl_y - NATURAL_HEIGHT / 2, NATURAL_HEIGHT);
-    } else {
-      overview.map_y0 = 0;
-    }
-    redraw_overview();
-  } do_in_natural_pos_end;
-}
-
-/**************************************************************************
-  Finds the overview (canvas) coordinates for a given map position.
-**************************************************************************/
-void map_to_overview_pos(int *overview_x, int *overview_y,
-                        int map_x, int map_y)
-{
-  /* The map position may not be normal, for instance when the mapview
-   * origin is not a normal position.
-   *
-   * NOTE: this embeds the map wrapping in the overview code. */
-  do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
-    int ovr_x = ntl_x - overview.map_x0, ovr_y = ntl_y - overview.map_y0;
-
-    if (topo_has_flag(TF_WRAPX)) {
-      ovr_x = FC_WRAP(ovr_x, NATURAL_WIDTH);
-    } else {
-      if (MAP_IS_ISOMETRIC) {
-       /* HACK: For iso-maps that don't wrap in the X direction we clip
-        * a half-tile off of the left and right of the overview.  This
-        * means some tiles only are halfway shown.  However it means we
-        * don't show any unreal tiles, which we'd otherwise be doing.  The
-        * rest of the code can't handle unreal tiles in the overview. */
-       ovr_x--;
-      }
-    }
-    if (topo_has_flag(TF_WRAPY)) {
-      ovr_y = FC_WRAP(ovr_y, NATURAL_HEIGHT);
-    }
-    *overview_x = OVERVIEW_TILE_SIZE * ovr_x;
-    *overview_y = OVERVIEW_TILE_SIZE * ovr_y;
-  } do_in_natural_pos_end;
-}
-
-/**************************************************************************
-  Finds the map coordinates for a given overview (canvas) position.
-**************************************************************************/
-void overview_to_map_pos(int *map_x, int *map_y,
-                        int overview_x, int overview_y)
-{
-  int ntl_x = overview_x / OVERVIEW_TILE_SIZE + overview.map_x0;
-  int ntl_y = overview_y / OVERVIEW_TILE_SIZE + overview.map_y0;
-
-  if (MAP_IS_ISOMETRIC && !topo_has_flag(TF_WRAPX)) {
-    /* Clip half tile left and right.  See comment in map_to_overview_pos. */
-    ntl_x++;
-  }
-
-  NATURAL_TO_MAP_POS(map_x, map_y, ntl_x, ntl_y);
-  if (!normalize_map_pos(map_x, map_y)) {
-    /* All positions on the overview should be valid. */
-    assert(FALSE);
-  }
-}
-
-/**************************************************************************
   Find the corners of the mapview, in overview coordinates.  Used to draw
   the "mapview window" rectangle onto the overview.
 **************************************************************************/
-static void get_mapview_corners(int x[4], int y[4])
+void get_mapview_corners(int x[4], int y[4])
 {
   int map_x0, map_y0;
 
@@ -2174,54 +2021,6 @@
 }
 
 /**************************************************************************
-  Redraw the entire backing store for the overview minimap.
-**************************************************************************/
-void refresh_overview_canvas(void)
-{
-  whole_map_iterate(ptile) {
-    overview_update_tile(ptile);
-  } whole_map_iterate_end;
-  redraw_overview();
-}
-
-/**************************************************************************
-  Redraw the given map position in the overview canvas.
-**************************************************************************/
-void overview_update_tile(struct tile *ptile)
-{
-  /* Base overview positions are just like natural positions, but scaled to
-   * the overview tile dimensions. */
-  do_in_natural_pos(ntl_x, ntl_y, ptile->x, ptile->y) {
-    int overview_y = ntl_y * OVERVIEW_TILE_SIZE;
-    int overview_x = ntl_x * OVERVIEW_TILE_SIZE;
-
-    if (MAP_IS_ISOMETRIC) {
-      if (topo_has_flag(TF_WRAPX)) {
-       if (overview_x > overview.width - OVERVIEW_TILE_WIDTH) {
-         /* This tile is shown half on the left and half on the right
-          * side of the overview.  So we have to draw it in two parts. */
-         canvas_put_rectangle(overview.store, 
-                              overview_tile_color(ptile),
-                              overview_x - overview.width, overview_y,
-                              OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT); 
-       }     
-      } else {
-       /* Clip half tile left and right.
-        * See comment in map_to_overview_pos. */
-       overview_x -= OVERVIEW_TILE_SIZE;
-      }
-    } 
-    
-    canvas_put_rectangle(overview.store,
-                        overview_tile_color(ptile),
-                        overview_x, overview_y,
-                        OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
-
-    dirty_overview();
-  } do_in_natural_pos_end;
-}
-
-/**************************************************************************
   Returns TRUE if cached drawing is possible.  If the mapview is too large
   we have to turn it off.
 **************************************************************************/
@@ -2296,46 +2095,14 @@
 }
 
 /**************************************************************************
-  Called if the map size is know or changes.
-**************************************************************************/
-void set_overview_dimensions(int width, int height)
-{
-  int shift = 0; /* used to calculate shift in iso view */
-
-  /* Set the scale of the overview map.  This attempts to limit the overview
-   * to 120 pixels wide or high. */
-  if (MAP_IS_ISOMETRIC) {
-    OVERVIEW_TILE_SIZE = MIN(MAX(120 / width, 1), 120 / height + 1);
-
-    /* Clip half tile left and right.  See comment in map_to_overview_pos. */
-    shift = (!topo_has_flag(TF_WRAPX) ? -OVERVIEW_TILE_SIZE : 0);
-  } else {
-    OVERVIEW_TILE_SIZE = MIN(120 / width + 1, 120 / height + 1);
-  }
-
-  overview.height = OVERVIEW_TILE_HEIGHT * height;
-  overview.width = OVERVIEW_TILE_WIDTH * width + shift; 
-
-  if (overview.store) {
-    canvas_free(overview.store);
-  }
-  overview.store = canvas_create(overview.width, overview.height);
-  canvas_put_rectangle(overview.store, COLOR_STD_BLACK,
-                      0, 0, overview.width, overview.height);
-  update_map_canvas_scrollbars_size();
-
-  mapview.can_do_cached_drawing = can_do_cached_drawing();
-
-  /* Call gui specific function. */
-  map_size_changed();
-}
-
-/**************************************************************************
   Called when we receive map dimensions.  It initialized the mapview
   decorations.
 **************************************************************************/
 void init_mapview_decorations(void)
 {
+  /* HACK: this must be called on a map_info packet. */
+  mapview.can_do_cached_drawing = can_do_cached_drawing();
+
   map_deco = fc_realloc(map_deco, MAP_INDEX_SIZE * sizeof(*map_deco));
   whole_map_iterate(ptile) {
     map_deco[ptile->index].hilite = HILITE_NONE;
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.109
diff -u -r1.109 mapview_common.h
--- client/mapview_common.h     28 Mar 2005 16:48:40 -0000      1.109
+++ client/mapview_common.h     29 Mar 2005 20:39:55 -0000
@@ -43,17 +43,8 @@
   struct canvas *store, *tmp_store;
 };
 
-/* Holds all information about the overview aka minimap. */
-struct overview {
-  /* The following fields are controlled by mapview_common.c. */
-  int map_x0, map_y0;
-  int width, height;           /* Size in pixels. */
-  struct canvas *store;
-};
-
 extern struct mapview_decoration *map_deco;
 extern struct view mapview;
-extern struct overview overview;
 
 /* HACK: Callers can set this to FALSE to disable sliding.  It should be
  * reenabled afterwards. */
@@ -234,6 +225,8 @@
 struct tile *canvas_pos_to_tile(int canvas_x, int canvas_y);
 struct tile *canvas_pos_to_nearest_tile(int canvas_x, int canvas_y);
 
+void get_mapview_corners(int x[4], int y[4]);
+
 void get_mapview_scroll_window(int *xmin, int *ymin,
                               int *xmax, int *ymax,
                               int *xsize, int *ysize);
@@ -300,15 +293,6 @@
                                      size_t growth_buffer_len,
                                      enum color_std *grwoth_color);
 
-void map_to_overview_pos(int *overview_x, int *overview_y,
-                        int map_x, int map_y);
-void overview_to_map_pos(int *map_x, int *map_y,
-                        int overview_x, int overview_y);
-
-void refresh_overview_canvas(void);
-void overview_update_tile(struct tile *ptile);
-void set_overview_dimensions(int width, int height);
-
 void init_mapview_decorations(void);
 bool map_canvas_resized(int width, int height);
 void init_mapcanvas_and_overview(void);
Index: client/overview_common.c
===================================================================
RCS file: client/overview_common.c
diff -N client/overview_common.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ client/overview_common.c    29 Mar 2005 20:39:55 -0000
@@ -0,0 +1,294 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "climap.h"
+#include "control.h"
+#include "options.h"
+#include "overview_common.h"
+
+#include "mapview_g.h"
+
+int OVERVIEW_TILE_SIZE = 2;
+struct overview overview;
+
+/*
+ * Set to TRUE if the backing store is more recent than the version
+ * drawn into overview.window.
+ */
+static bool overview_dirty = FALSE;
+
+/****************************************************************************
+  Return color for overview map tile.
+****************************************************************************/
+static enum color_std overview_tile_color(struct tile *ptile)
+{
+  struct unit *punit;
+  struct city *pcity;
+
+  if (tile_get_known(ptile) == TILE_UNKNOWN) {
+    return COLOR_STD_BLACK;
+  } else if ((pcity = map_get_city(ptile))) {
+    if (pcity->owner == game.player_idx) {
+      return COLOR_STD_WHITE;
+    } else {
+      return COLOR_STD_CYAN;
+    }
+  } else if ((punit = find_visible_unit(ptile))) {
+    if (punit->owner == game.player_idx) {
+      return COLOR_STD_YELLOW;
+    } else {
+      return COLOR_STD_RED;
+    }
+  } else if (is_ocean(ptile->terrain)) {
+    if (tile_get_known(ptile) == TILE_KNOWN_FOGGED && draw_fog_of_war) {
+      return COLOR_STD_RACE4;
+    } else {
+      return COLOR_STD_OCEAN;
+    }
+  } else {
+    if (tile_get_known(ptile) == TILE_KNOWN_FOGGED && draw_fog_of_war) {
+      return COLOR_STD_BACKGROUND;
+    } else {
+      return COLOR_STD_GROUND;
+    }
+  }
+}
+
+/**************************************************************************
+  Copies the overview image from the backing store to the window and
+  draws the viewrect on top of it.
+**************************************************************************/
+static void redraw_overview(void)
+{
+  struct canvas *dest = get_overview_window();
+
+  if (!dest || !overview.store) {
+    return;
+  }
+
+  {
+    struct canvas *src = overview.store;
+    int x = overview.map_x0 * OVERVIEW_TILE_SIZE;
+    int y = overview.map_y0 * OVERVIEW_TILE_SIZE;
+    int ix = overview.width - x;
+    int iy = overview.height - y;
+
+    canvas_copy(dest, src, 0, 0, ix, iy, x, y);
+    canvas_copy(dest, src, 0, y, ix, 0, x, iy);
+    canvas_copy(dest, src, x, 0, 0, iy, ix, y);
+    canvas_copy(dest, src, x, y, 0, 0, ix, iy);
+  }
+
+  {
+    int i;
+    int x[4], y[4];
+
+    get_mapview_corners(x, y);
+
+    for (i = 0; i < 4; i++) {
+      int src_x = x[i];
+      int src_y = y[i];
+      int dest_x = x[(i + 1) % 4];
+      int dest_y = y[(i + 1) % 4];
+
+      canvas_put_line(dest, COLOR_STD_WHITE, LINE_NORMAL, src_x, src_y,
+                     dest_x - src_x, dest_y - src_y);
+    }
+  }
+
+  overview_dirty = FALSE;
+}
+
+/****************************************************************************
+  Mark the overview as "dirty" so that it will be redrawn soon.
+****************************************************************************/
+static void dirty_overview(void)
+{
+  overview_dirty = TRUE;
+}
+
+/****************************************************************************
+  Redraw the overview if it is "dirty".
+****************************************************************************/
+void flush_dirty_overview(void)
+{
+  /* Currently this function is called from mapview_common.  However it
+   * should be made static eventually. */
+  if (overview_dirty) {
+    redraw_overview();
+  }
+}
+
+/**************************************************************************
+  Center the overview around the mapview.
+**************************************************************************/
+void center_tile_overviewcanvas(struct tile *ptile)
+{
+  /* The overview coordinates are equivalent to (scaled) natural
+   * coordinates. */
+  do_in_natural_pos(ntl_x, ntl_y, ptile->x, ptile->y) {
+    /* NOTE: this embeds the map wrapping in the overview code.  This is
+     * basically necessary for the overview to be efficiently
+     * updated. */
+    if (topo_has_flag(TF_WRAPX)) {
+      overview.map_x0 = FC_WRAP(ntl_x - NATURAL_WIDTH / 2, NATURAL_WIDTH);
+    } else {
+      overview.map_x0 = 0;
+    }
+    if (topo_has_flag(TF_WRAPY)) {
+      overview.map_y0 = FC_WRAP(ntl_y - NATURAL_HEIGHT / 2, NATURAL_HEIGHT);
+    } else {
+      overview.map_y0 = 0;
+    }
+    redraw_overview();
+  } do_in_natural_pos_end;
+}
+
+/**************************************************************************
+  Finds the overview (canvas) coordinates for a given map position.
+**************************************************************************/
+void map_to_overview_pos(int *overview_x, int *overview_y,
+                        int map_x, int map_y)
+{
+  /* The map position may not be normal, for instance when the mapview
+   * origin is not a normal position.
+   *
+   * NOTE: this embeds the map wrapping in the overview code. */
+  do_in_natural_pos(ntl_x, ntl_y, map_x, map_y) {
+    int ovr_x = ntl_x - overview.map_x0, ovr_y = ntl_y - overview.map_y0;
+
+    if (topo_has_flag(TF_WRAPX)) {
+      ovr_x = FC_WRAP(ovr_x, NATURAL_WIDTH);
+    } else {
+      if (MAP_IS_ISOMETRIC) {
+       /* HACK: For iso-maps that don't wrap in the X direction we clip
+        * a half-tile off of the left and right of the overview.  This
+        * means some tiles only are halfway shown.  However it means we
+        * don't show any unreal tiles, which we'd otherwise be doing.  The
+        * rest of the code can't handle unreal tiles in the overview. */
+       ovr_x--;
+      }
+    }
+    if (topo_has_flag(TF_WRAPY)) {
+      ovr_y = FC_WRAP(ovr_y, NATURAL_HEIGHT);
+    }
+    *overview_x = OVERVIEW_TILE_SIZE * ovr_x;
+    *overview_y = OVERVIEW_TILE_SIZE * ovr_y;
+  } do_in_natural_pos_end;
+}
+
+/**************************************************************************
+  Finds the map coordinates for a given overview (canvas) position.
+**************************************************************************/
+void overview_to_map_pos(int *map_x, int *map_y,
+                        int overview_x, int overview_y)
+{
+  int ntl_x = overview_x / OVERVIEW_TILE_SIZE + overview.map_x0;
+  int ntl_y = overview_y / OVERVIEW_TILE_SIZE + overview.map_y0;
+
+  if (MAP_IS_ISOMETRIC && !topo_has_flag(TF_WRAPX)) {
+    /* Clip half tile left and right.  See comment in map_to_overview_pos. */
+    ntl_x++;
+  }
+
+  NATURAL_TO_MAP_POS(map_x, map_y, ntl_x, ntl_y);
+  if (!normalize_map_pos(map_x, map_y)) {
+    /* All positions on the overview should be valid. */
+    assert(FALSE);
+  }
+}
+
+/**************************************************************************
+  Redraw the entire backing store for the overview minimap.
+**************************************************************************/
+void refresh_overview_canvas(void)
+{
+  whole_map_iterate(ptile) {
+    overview_update_tile(ptile);
+  } whole_map_iterate_end;
+  redraw_overview();
+}
+
+/**************************************************************************
+  Redraw the given map position in the overview canvas.
+**************************************************************************/
+void overview_update_tile(struct tile *ptile)
+{
+  /* Base overview positions are just like natural positions, but scaled to
+   * the overview tile dimensions. */
+  do_in_natural_pos(ntl_x, ntl_y, ptile->x, ptile->y) {
+    int overview_y = ntl_y * OVERVIEW_TILE_SIZE;
+    int overview_x = ntl_x * OVERVIEW_TILE_SIZE;
+
+    if (MAP_IS_ISOMETRIC) {
+      if (topo_has_flag(TF_WRAPX)) {
+       if (overview_x > overview.width - OVERVIEW_TILE_WIDTH) {
+         /* This tile is shown half on the left and half on the right
+          * side of the overview.  So we have to draw it in two parts. */
+         canvas_put_rectangle(overview.store, 
+                              overview_tile_color(ptile),
+                              overview_x - overview.width, overview_y,
+                              OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT); 
+       }     
+      } else {
+       /* Clip half tile left and right.
+        * See comment in map_to_overview_pos. */
+       overview_x -= OVERVIEW_TILE_SIZE;
+      }
+    } 
+    
+    canvas_put_rectangle(overview.store,
+                        overview_tile_color(ptile),
+                        overview_x, overview_y,
+                        OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
+
+    dirty_overview();
+  } do_in_natural_pos_end;
+}
+
+/**************************************************************************
+  Called if the map size is know or changes.
+**************************************************************************/
+void set_overview_dimensions(int width, int height)
+{
+  int shift = 0; /* used to calculate shift in iso view */
+
+  /* Set the scale of the overview map.  This attempts to limit the overview
+   * to 120 pixels wide or high. */
+  if (MAP_IS_ISOMETRIC) {
+    OVERVIEW_TILE_SIZE = MIN(MAX(120 / width, 1), 120 / height + 1);
+
+    /* Clip half tile left and right.  See comment in map_to_overview_pos. */
+    shift = (!topo_has_flag(TF_WRAPX) ? -OVERVIEW_TILE_SIZE : 0);
+  } else {
+    OVERVIEW_TILE_SIZE = MIN(120 / width + 1, 120 / height + 1);
+  }
+
+  overview.height = OVERVIEW_TILE_HEIGHT * height;
+  overview.width = OVERVIEW_TILE_WIDTH * width + shift; 
+
+  if (overview.store) {
+    canvas_free(overview.store);
+  }
+  overview.store = canvas_create(overview.width, overview.height);
+  canvas_put_rectangle(overview.store, COLOR_STD_BLACK,
+                      0, 0, overview.width, overview.height);
+  update_map_canvas_scrollbars_size();
+
+  /* Call gui specific function. */
+  map_size_changed();
+}
Index: client/overview_common.h
===================================================================
RCS file: client/overview_common.h
diff -N client/overview_common.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ client/overview_common.h    29 Mar 2005 20:39:55 -0000
@@ -0,0 +1,52 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 1996-2005 - Freeciv Development Team
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+
+#ifndef FC__OVERVIEW_COMMON_H
+#define FC__OVERVIEW_COMMON_H
+
+#include "fc_types.h"
+
+#include "canvas_g.h"
+
+/* Holds all information about the overview aka minimap. */
+struct overview {
+  /* The following fields are controlled by mapview_common.c. */
+  int map_x0, map_y0;
+  int width, height;           /* Size in pixels. */
+  struct canvas *store;
+};
+
+extern struct overview overview;
+
+/* The overview tile width and height are defined in terms of the base
+ * size.  For iso-maps the width is twice the height since "natural"
+ * coordinates are used.  For classical maps the width and height are
+ * equal.  The base size may be adjusted to get the correct scale. */
+extern int OVERVIEW_TILE_SIZE;
+#define OVERVIEW_TILE_WIDTH ((MAP_IS_ISOMETRIC ? 2 : 1) * OVERVIEW_TILE_SIZE)
+#define OVERVIEW_TILE_HEIGHT OVERVIEW_TILE_SIZE
+
+void map_to_overview_pos(int *overview_x, int *overview_y,
+                        int map_x, int map_y);
+void overview_to_map_pos(int *map_x, int *map_y,
+                        int overview_x, int overview_y);
+
+void refresh_overview_canvas(void);
+void overview_update_tile(struct tile *ptile);
+void set_overview_dimensions(int width, int height);
+
+void center_tile_overviewcanvas(struct tile *ptile);
+
+void flush_dirty_overview(void);
+
+#endif /* FC__OVERVIEW_COMMON_H */
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.484
diff -u -r1.484 packhand.c
--- client/packhand.c   28 Mar 2005 17:14:57 -0000      1.484
+++ client/packhand.c   29 Mar 2005 20:39:56 -0000
@@ -60,6 +60,7 @@
 #include "menu_g.h"
 #include "messagewin_g.h"
 #include "options.h"
+#include "overview_common.h"
 #include "pages_g.h"
 #include "plrdlg_g.h"
 #include "repodlgs_g.h"
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.280
diff -u -r1.280 tilespec.c
--- client/tilespec.c   28 Mar 2005 23:25:37 -0000      1.280
+++ client/tilespec.c   29 Mar 2005 20:39:57 -0000
@@ -257,8 +257,6 @@
 static const int DIR4_TO_DIR8[4] =
     { DIR8_NORTH, DIR8_SOUTH, DIR8_EAST, DIR8_WEST };
 
-int OVERVIEW_TILE_SIZE = 2;
-
 /* Don't reorder this enum since tilesets depend on it. */
 enum fog_style {
   FOG_AUTO, /* Fog is automatically appended by the code. */
@@ -4028,44 +4026,6 @@
      (COLOR_STD_RACE13 - COLOR_STD_RACE0 + 1));
 }
 
-/**********************************************************************
-  Return color for overview map tile.
-***********************************************************************/
-enum color_std overview_tile_color(struct tile *ptile)
-{
-  enum color_std color;
-  struct unit *punit;
-  struct city *pcity;
-
-  if (tile_get_known(ptile) == TILE_UNKNOWN) {
-    color=COLOR_STD_BLACK;
-  } else if((pcity=map_get_city(ptile))) {
-    if(pcity->owner==game.player_idx)
-      color=COLOR_STD_WHITE;
-    else
-      color=COLOR_STD_CYAN;
-  } else if ((punit=find_visible_unit(ptile))) {
-    if(punit->owner==game.player_idx)
-      color=COLOR_STD_YELLOW;
-    else
-      color=COLOR_STD_RED;
-  } else if (is_ocean(ptile->terrain)) {
-    if (tile_get_known(ptile) == TILE_KNOWN_FOGGED && draw_fog_of_war) {
-      color = COLOR_STD_RACE4;
-    } else {
-      color = COLOR_STD_OCEAN;
-    }
-  } else {
-    if (tile_get_known(ptile) == TILE_KNOWN_FOGGED && draw_fog_of_war) {
-      color = COLOR_STD_BACKGROUND;
-    } else {
-      color = COLOR_STD_GROUND;
-    }
-  }
-
-  return color;
-}
-
 /****************************************************************************
   Return the amount of time between calls to toggle_focus_unit_state.
   The main loop needs to call toggle_focus_unit_state about this often
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.140
diff -u -r1.140 tilespec.h
--- client/tilespec.h   28 Mar 2005 23:25:38 -0000      1.140
+++ client/tilespec.h   29 Mar 2005 20:39:57 -0000
@@ -132,7 +132,6 @@
                      const struct city *citymode);
 
 enum color_std player_color(const struct player *pplayer);
-enum color_std overview_tile_color(struct tile *ptile);
 
 double get_focus_unit_toggle_timeout(struct tileset *t);
 void reset_focus_unit_state(struct tileset *t);
@@ -200,14 +199,6 @@
                                      Output_type_id otype,
                                      const struct unit *punit);
 
-/* The overview tile width and height are defined in terms of the base
- * size.  For iso-maps the width is twice the height since "natural"
- * coordinates are used.  For classical maps the width and height are
- * equal.  The base size may be adjusted to get the correct scale. */
-extern int OVERVIEW_TILE_SIZE;
-#define OVERVIEW_TILE_WIDTH ((MAP_IS_ISOMETRIC ? 2 : 1) * OVERVIEW_TILE_SIZE)
-#define OVERVIEW_TILE_HEIGHT OVERVIEW_TILE_SIZE
-
 /* Tileset accessor functions. */
 bool tileset_is_isometric(struct tileset *t);
 int tileset_hex_width(struct tileset *t);
Index: client/gui-gtk-2.0/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapctrl.c,v
retrieving revision 1.48
diff -u -r1.48 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        28 Mar 2005 16:48:40 -0000      1.48
+++ client/gui-gtk-2.0/mapctrl.c        29 Mar 2005 20:39:57 -0000
@@ -26,6 +26,8 @@
 #include "support.h"
 #include "unit.h"
 
+#include "overview_common.h"
+
 #include "chatline.h"
 #include "citydlg.h"
 #include "civclient.h"
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.171
diff -u -r1.171 mapview.c
--- client/gui-gtk-2.0/mapview.c        28 Mar 2005 16:59:14 -0000      1.171
+++ client/gui-gtk-2.0/mapview.c        29 Mar 2005 20:39:57 -0000
@@ -46,6 +46,7 @@
 #include "gui_stuff.h"
 #include "mapctrl.h"
 #include "options.h"
+#include "overview_common.h"
 #include "tilespec.h"
 #include "text.h"
 #include "wldlg.h"

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12694) new client files for overview code, Jason Short <=