Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] Re: (PR#7301) Unified and cached overview
Home

[Freeciv-Dev] Re: (PR#7301) Unified and cached overview

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#7301) Unified and cached overview
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Sun, 25 Jan 2004 02:42:14 -0800
Reply-to: rt@xxxxxxxxxxx

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

On Sat, Jan 24, 2004 at 08:34:28AM -0800, Jason Short wrote:
> 
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=7301 >
> 
> On Sat, 24 Jan 2004, Raimar Falke wrote:
> 
> >
> > <URL: http://rt.freeciv.org/Ticket/Display.html?id=7301 >
> >
> >
> > The patch does two things:
> >
> > First it moves a lot of overview related code to mapview common. This
> > is possible since we have with struct canvas_store efficiently a nice
> > abstraction of a canvas. This is enough to remove almost all overview
> > drawing code from the various guis.
> 
> Yes.
> 
> Rather than have a function to return the overview canvas store you should
> put this variable into mapview_common.h.  See mapview_canvas and
> map_overview_x0 that are already there.

Done. I have also made some other cleanups. There are no almost no
traces of overview handling left in mapview.c

> > The second part is to cache the overview so that if only the position
> > of the main map view is changed the overview doesn't have to be
> > redrawn completely like it is done in the current code.
> 
> Huh?  This is already the case.  I don't see what you've changed here.

You are correct. *looking* It wasn't the case in the old code base
which I used for gui-fs (March 2003). I have updated my code version
to CVS HEAD some weeks ago. And it still worked and was still slow. So
it is/was a problem with too much freedom. I as a client implementor I
got the freedom to implement the overview drawing and I did the wrong
thing. So with the unification comes a the strict framework what the
client has to implement and all the public high-level interface
functions are implemented in mapview_common. There is now no way to
implement it wrong.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Sit, disk, sit. Good boy. Now spin up. Very good. Here's a netscape
  cookie for you. Fetch me some data. Come on, you can do it. No, not that
  data. Bad disk. Bad." 
    -- Calle Dybedahl, alt.sysadmin.recovery

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.124
diff -u -u -r1.124 control.c
--- client/control.c    2004/01/20 21:52:06     1.124
+++ client/control.c    2004/01/25 10:37:28
@@ -1142,7 +1142,6 @@
   draw_fog_of_war ^= 1;
   update_map_canvas_visible();
   refresh_overview_canvas();
-  refresh_overview_viewrect();
 }
 
 /**************************************************************************
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.73
diff -u -u -r1.73 mapview_common.c
--- client/mapview_common.c     2004/01/25 06:37:50     1.73
+++ client/mapview_common.c     2004/01/25 10:37:31
@@ -32,13 +32,12 @@
 #include "mapview_common.h"
 
 struct canvas mapview_canvas;
+struct overview overview;
 
-/* Overview oordinates of the upper left corner of the map overview. */
-int map_overview_x0, map_overview_y0;
-
 static void base_canvas_to_map_pos(int *map_x, int *map_y,
                                   int canvas_x, int canvas_y);
 static void center_tile_overviewcanvas(int map_x, int map_y);
+static void get_mapview_corners(int x[4], int y[4]);
 
 /**************************************************************************
  Refreshes a single tile on the map canvas.
@@ -336,7 +335,6 @@
     center_tile_overviewcanvas(map_center_x, map_center_y);
     update_map_canvas_visible();
     update_map_canvas_scrollbars();
-    refresh_overview_viewrect();
     if (hover_state == HOVER_GOTO || hover_state == HOVER_PATROL) {
       create_line_at_mouse_pos();
     }
@@ -1514,6 +1512,45 @@
 }
 
 /**************************************************************************
+  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_store *dest = overview.window;
+
+  {
+    struct canvas_store *src = overview.store;
+    int x = overview.map_x0 * OVERVIEW_TILE_WIDTH;
+    int y = overview.map_y0 * OVERVIEW_TILE_HEIGHT;
+    int ix = overview.width - x;
+    int iy = overview.height - y;
+
+    gui_copy_canvas(dest, src, 0, 0, ix, iy, x, y);
+    gui_copy_canvas(dest, src, 0, y, ix, 0, x, iy);
+    gui_copy_canvas(dest, src, x, 0, 0, iy, ix, y);
+    gui_copy_canvas(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];
+
+      gui_put_line(dest, COLOR_STD_WHITE, LINE_NORMAL, src_x, src_y,
+                  dest_x - src_x, dest_y - src_y);
+    }
+  }
+}
+
+/**************************************************************************
   Center the overview around the mapview.
 **************************************************************************/
 static void center_tile_overviewcanvas(int map_x, int map_y)
@@ -1522,18 +1559,19 @@
   map_to_native_pos(&map_x, &map_y, map_x, map_y);
 
   /* NOTE: this embeds the map wrapping in the overview code.  This is
-   * basically necessary for the overview to be efficiently updated.  See
-   * refresh_overview_viewrect(). */
+   * basically necessary for the overview to be efficiently
+   * updated. */
   if (topo_has_flag(TF_WRAPX)) {
-    map_overview_x0 = FC_WRAP(map_x - map.xsize / 2, map.xsize);
+    overview.map_x0 = FC_WRAP(map_x - map.xsize / 2, map.xsize);
   } else {
-    map_overview_x0 = 0;
+    overview.map_x0 = 0;
   }
   if (topo_has_flag(TF_WRAPY)) {
-    map_overview_y0 = FC_WRAP(map_y - map.ysize / 2, map.ysize);
+    overview.map_y0 = FC_WRAP(map_y - map.ysize / 2, map.ysize);
   } else {
-    map_overview_y0 = 0;
+    overview.map_y0 = 0;
   }
+  redraw_overview();
 }
 
 /**************************************************************************
@@ -1549,8 +1587,8 @@
    *
    * NOTE: this embeds the map wrapping in the overview code. */
   map_to_native_pos(&gui_x, &gui_y, map_x, map_y);
-  gui_x -= map_overview_x0;
-  gui_y -= map_overview_y0;
+  gui_x -= overview.map_x0;
+  gui_y -= overview.map_y0;
   if (topo_has_flag(TF_WRAPX)) {
     gui_x = FC_WRAP(gui_x, map.xsize);
   }
@@ -1567,8 +1605,8 @@
 void overview_to_map_pos(int *map_x, int *map_y,
                         int overview_x, int overview_y)
 {
-  int nat_x = overview_x / OVERVIEW_TILE_WIDTH + map_overview_x0;
-  int nat_y = overview_y / OVERVIEW_TILE_HEIGHT + map_overview_y0;
+  int nat_x = overview_x / OVERVIEW_TILE_WIDTH + overview.map_x0;
+  int nat_y = overview_y / OVERVIEW_TILE_HEIGHT + overview.map_y0;
 
   native_to_map_pos(map_x, map_y, nat_x, nat_y);
   if (!normalize_map_pos(map_x, map_y)) {
@@ -1581,7 +1619,7 @@
   Find the corners of the mapview, in overview coordinates.  Used to draw
   the "mapview window" rectangle onto the overview.
 **************************************************************************/
-void get_mapview_corners(int x[4], int y[4])
+static void get_mapview_corners(int x[4], int y[4])
 {
   map_to_overview_pos(&x[0], &y[0],
                      mapview_canvas.map_x0, mapview_canvas.map_y0);
@@ -1639,32 +1677,47 @@
 }
 
 /**************************************************************************
-  Find the "base" (unwrapped) overview coordinates for a given map
-  position.  This may be used by the GUI code to draw to the minimap's
-  backing store.
+  Redraw the entire backing store for the overview minimap.
+**************************************************************************/
+void refresh_overview_canvas(void)
+{
+  whole_map_iterate(x, y) {
+    overview_update_tile(x, y);
+  } whole_map_iterate_end;
+  redraw_overview();
+}
+
+/**************************************************************************
+...
 **************************************************************************/
-void map_to_base_overview_pos(int *base_overview_x, int *base_overview_y,
-                             int map_x, int map_y)
+void overview_update_tile(int map_x, int map_y)
 {
+  int base_x, base_y;
+
   /* Base overview positions are just like native positions, but scaled to
    * the overview tile dimensions. */
-  map_to_native_pos(base_overview_x, base_overview_y, map_x, map_y);
-  *base_overview_x *= OVERVIEW_TILE_WIDTH;
-  *base_overview_y *= OVERVIEW_TILE_HEIGHT;
+  map_to_native_pos(&base_x, &base_y, map_x, map_y);
+  base_x *= OVERVIEW_TILE_WIDTH;
+  base_y *= OVERVIEW_TILE_HEIGHT;
+
+  gui_put_rectangle(overview.store,
+                   overview_tile_color(map_x, map_y), base_x, base_y,
+                   OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
 }
 
 /**************************************************************************
-  Redraw the entire backing store for the overview minimap.
+...
 **************************************************************************/
-void base_refresh_overview_canvas(struct canvas_store *pbacking_store)
+void set_overview_dimensions(int width, int height)
 {
-  whole_map_iterate(x, y) {
-    int gui_x, gui_y;
+  overview.width = OVERVIEW_TILE_WIDTH * width;
+  overview.height = OVERVIEW_TILE_HEIGHT * height;
 
-    map_to_base_overview_pos(&gui_x, &gui_y, x, y);
-
-    gui_put_rectangle(pbacking_store, overview_tile_color(x, y),
-                     gui_x, gui_y,
-                     OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
-  } whole_map_iterate_end;
+  if (overview.store) {
+    canvas_store_free(overview.store);
+  }
+  overview.store = canvas_store_create(overview.width, overview.height);
+  gui_put_rectangle(overview.store, COLOR_STD_BLACK, 0, 0, overview.width,
+                   overview.height);
+  map_size_changed();
 }
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.39
diff -u -u -r1.39 mapview_common.h
--- client/mapview_common.h     2003/09/30 19:01:22     1.39
+++ client/mapview_common.h     2004/01/25 10:37:31
@@ -29,7 +29,18 @@
   struct canvas_store *store;
 };
 
+struct overview {
+  /* controlled by mapview_common.c */
+  int map_x0, map_y0;
+  int width, height;           /* Size in pixels. */
+  struct canvas_store *store;
+
+  /* controlled by mapview.c */
+  struct canvas_store *window;
+};
+
 extern struct canvas mapview_canvas;
+extern struct overview overview;
 
 /*
 The bottom row of the map was sometimes hidden.
@@ -189,13 +200,9 @@
                         int map_x, int map_y);
 void overview_to_map_pos(int *map_x, int *map_y,
                         int overview_x, int overview_y);
-void map_to_base_overview_pos(int *base_overview_x, int *base_overview_y,
-                             int map_x, int map_y);
-
-void base_refresh_overview_canvas(struct canvas_store *pbacking_store);
-
-void get_mapview_corners(int overview_x_array[4], int overview_y_array[4]);
 
-extern int map_overview_x0, map_overview_y0;
+void refresh_overview_canvas(void);
+void overview_update_tile(int x, int y);
+void set_overview_dimensions(int width, int height);
 
 #endif /* FC__MAPVIEW_COMMON_H */
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.345
diff -u -u -r1.345 packhand.c
--- client/packhand.c   2004/01/20 21:52:07     1.345
+++ client/packhand.c   2004/01/25 10:37:36
@@ -328,7 +328,6 @@
 
   if (get_client_state() == CLIENT_GAME_RUNNING_STATE) {
     refresh_overview_canvas();
-    refresh_overview_viewrect();
     player_set_unit_focus_status(game.player_ptr);
 
     update_info_label();       /* get initial population right */
@@ -344,7 +343,6 @@
 
   if (get_client_state() == CLIENT_GAME_OVER_STATE) {
     refresh_overview_canvas();
-    refresh_overview_viewrect();
 
     update_info_label();
     update_unit_focus();
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.142
diff -u -u -r1.142 gui_main.c
--- client/gui-gtk/gui_main.c   2004/01/24 02:58:55     1.142
+++ client/gui-gtk/gui_main.c   2004/01/25 10:37:36
@@ -75,10 +75,6 @@
                                          * for the map_canvas widget */
 
 GtkWidget *overview_canvas;             /* GtkDrawingArea */
-GdkPixmap *overview_canvas_store;       /* this pixmap acts as a backing store 
-                                         * for the overview_canvas widget */
-int overview_canvas_store_width = 2 * 80;
-int overview_canvas_store_height = 2 * 50;
 
 GdkPixmap *single_tile_pixmap;          /* this pixmap is used when 
                                          * moving units etc */
@@ -954,21 +950,16 @@
   /* Start with a 1x1 window (GTK doesn't like 0x0). */
   map_canvas_store_twidth = 1;
   map_canvas_store_theight = 1;
-  map_canvas_store = gdk_pixmap_new(root_window,
-                                 map_canvas_store_twidth * NORMAL_TILE_WIDTH,
-                                 map_canvas_store_theight * NORMAL_TILE_HEIGHT,
-                                 -1);
-  mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
-  mapview_canvas.store->pixmap = map_canvas_store;
-  mapview_canvas.store->pixcomm = NULL;
-
-  overview_canvas_store = gdk_pixmap_new(root_window,
-                                         overview_canvas_store_width,
-                                         overview_canvas_store_height, -1);
-
-  gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_WHITE]);
-  gdk_draw_rectangle(overview_canvas_store, fill_bg_gc, TRUE, 0, 0,
-                     overview_canvas_store_width, 
overview_canvas_store_height);
+
+  mapview_canvas.store =
+      canvas_store_create(map_canvas_store_twidth * NORMAL_TILE_WIDTH,
+                         map_canvas_store_theight * NORMAL_TILE_HEIGHT);
+  map_canvas_store = mapview_canvas.store->pixmap;
+
+  overview.store = NULL;
+  overview.window = fc_malloc(sizeof(*overview.window));
+  overview.window->pixmap = overview_canvas->window;
+  overview.window->pixcomm = NULL;
 
   single_tile_pixmap = gdk_pixmap_new(root_window, 
                                      UNIT_TILE_WIDTH, UNIT_TILE_HEIGHT, -1);
Index: client/gui-gtk/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.h,v
retrieving revision 1.12
diff -u -u -r1.12 gui_main.h
--- client/gui-gtk/gui_main.h   2003/07/23 13:46:01     1.12
+++ client/gui-gtk/gui_main.h   2004/01/25 10:37:36
@@ -39,9 +39,6 @@
 extern GdkPixmap *      black50;
 extern GdkPixmap *      mask_bitmap;
 extern GdkPixmap *      map_canvas_store;
-extern GdkPixmap *      overview_canvas_store;
-extern int              overview_canvas_store_width;
-extern int              overview_canvas_store_height;
 extern GdkPixmap *      single_tile_pixmap;
 extern GtkText *        main_message_area;
 extern GtkWidget *      text_scrollbar;
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.187
diff -u -u -r1.187 mapview.c
--- client/gui-gtk/mapview.c    2004/01/11 17:45:03     1.187
+++ client/gui-gtk/mapview.c    2004/01/25 10:37:36
@@ -381,118 +381,60 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void set_overview_dimensions(int x, int y)
+void map_size_changed(void)
 {
-  overview_canvas_store_width = OVERVIEW_TILE_WIDTH * x;
-  overview_canvas_store_height = OVERVIEW_TILE_HEIGHT * y;
-
-  if (overview_canvas_store)
-    gdk_pixmap_unref(overview_canvas_store);
-  
-  overview_canvas_store        = gdk_pixmap_new(root_window,
-                         overview_canvas_store_width,
-                         overview_canvas_store_height, -1);
-
-  gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
-  gdk_draw_rectangle(overview_canvas_store, fill_bg_gc, TRUE,
-                    0, 0,
-                    overview_canvas_store_width, overview_canvas_store_height);
-
-  gtk_widget_set_usize(overview_canvas,
-                      OVERVIEW_TILE_WIDTH * x, OVERVIEW_TILE_HEIGHT * y);
+  gtk_widget_set_usize(overview_canvas, overview.width, overview.height);
   update_map_canvas_scrollbars_size();
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-gint overview_canvas_expose(GtkWidget *w, GdkEventExpose *ev)
+struct canvas_store *canvas_store_create(int width, int height)
 {
-  if (!can_client_change_view()) {
-    if(radar_gfx_sprite)
-      gdk_draw_pixmap(overview_canvas->window, civ_gc,
-                     radar_gfx_sprite->pixmap, ev->area.x, ev->area.y,
-                     ev->area.x, ev->area.y, ev->area.width, ev->area.height);
-    return TRUE;
-  }
-  
-  refresh_overview_viewrect();
-  return TRUE;
-}
+  struct canvas_store *result = fc_malloc(sizeof(*result));
 
-/**************************************************************************
-...
-**************************************************************************/
-static void set_overview_tile_foreground_color(int x, int y)
-{
-  gdk_gc_set_foreground(fill_bg_gc,
-                       colors_standard[overview_tile_color(x, y)]);
+  result->pixmap = gdk_pixmap_new(root_window, width, height, -1);
+  result->pixcomm = NULL;
+  return result;
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-void refresh_overview_canvas(void)
+void canvas_store_free(struct canvas_store *store)
 {
-  struct canvas_store store = {overview_canvas_store};
-
-  base_refresh_overview_canvas(&store);
+  gdk_pixmap_unref(store->pixmap);
+  assert(store->pixcomm == NULL);
+  free(store);
 }
 
-
 /**************************************************************************
 ...
 **************************************************************************/
-void overview_update_tile(int x, int y)
+gint overview_canvas_expose(GtkWidget *w, GdkEventExpose *ev)
 {
-  int overview_x, overview_y, base_x, base_y;
-
-  map_to_overview_pos(&overview_x, &overview_y, x, y);
-  map_to_base_overview_pos(&base_x, &base_y, x, y);
+  if (!can_client_change_view()) {
+    if(radar_gfx_sprite)
+      gdk_draw_pixmap(overview_canvas->window, civ_gc,
+                     radar_gfx_sprite->pixmap, ev->area.x, ev->area.y,
+                     ev->area.x, ev->area.y, ev->area.width, ev->area.height);
+    return TRUE;
+  }
   
-  set_overview_tile_foreground_color(x, y);
-  gdk_draw_rectangle(overview_canvas_store, fill_bg_gc, TRUE,
-                    base_x, base_y,
-                    OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);  
-  gdk_draw_rectangle(overview_canvas->window, fill_bg_gc, TRUE,
-                    overview_x, overview_y,
-                    OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
+  refresh_overview_canvas();
+  return TRUE;
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-void refresh_overview_viewrect(void)
+void gui_copy_canvas(struct canvas_store *dest, struct canvas_store *src,
+                    int src_x, int src_y, int dest_x, int dest_y, int width,
+                    int height)
 {
-  int x0 = OVERVIEW_TILE_WIDTH * map_overview_x0;
-  int x1 = OVERVIEW_TILE_WIDTH * (map.xsize - map_overview_x0);
-  int y0 = OVERVIEW_TILE_HEIGHT * map_overview_y0;
-  int y1 = OVERVIEW_TILE_HEIGHT * (map.ysize - map_overview_y0);
-  int gui_x[4], gui_y[4], i;
-
-  /* (map_overview_x0, map_overview_y0) splits the map into four
-   * rectangles.  Draw each of these rectangles to the screen, in turn. */
-  gdk_draw_pixmap(overview_canvas->window, civ_gc, overview_canvas_store,
-                 x0, y0, 0, 0, x1, y1);
-  gdk_draw_pixmap(overview_canvas->window, civ_gc, overview_canvas_store,
-                 0, y0, x1, 0, x0, y1);
-  gdk_draw_pixmap(overview_canvas->window, civ_gc, overview_canvas_store,
-                 x0, 0, 0, y1, x1, y0);
-  gdk_draw_pixmap(overview_canvas->window, civ_gc, overview_canvas_store,
-                 0, 0, x1, y1, x0, y0);
-
-  /* Now draw the mapview window rectangle onto the overview. */
-  gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_WHITE]);
-  get_mapview_corners(gui_x, gui_y);
-  for (i = 0; i < 4; i++) {
-    int src_x = gui_x[i];
-    int src_y = gui_y[i];
-    int dest_x = gui_x[(i + 1) % 4];
-    int dest_y = gui_y[(i + 1) % 4];
-
-    gdk_draw_line(overview_canvas->window, civ_gc,
-                 src_x, src_y, dest_x, dest_y);
-  }
+  gdk_draw_pixmap(dest->pixmap, fill_bg_gc, src->pixmap,
+                 src_x, src_y, dest_x, dest_y, width, height);
 }
 
 /**************************************************************************
@@ -572,8 +514,6 @@
        update_map_canvas_visible();
 
        update_map_canvas_scrollbars();
-
-       refresh_overview_viewrect();
       }
       else {
        gdk_draw_pixmap( map_canvas->window, civ_gc, map_canvas_store,
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.85
diff -u -u -r1.85 mapview.c
--- client/gui-gtk-2.0/mapview.c        2004/01/11 17:45:03     1.85
+++ client/gui-gtk-2.0/mapview.c        2004/01/25 10:37:39
@@ -463,7 +463,7 @@
     return TRUE;
   }
   
-  refresh_overview_viewrect();
+  refresh_overview();
   return TRUE;
 }
 
@@ -474,37 +474,6 @@
 {
   gdk_gc_set_foreground(fill_bg_gc,
                        colors_standard[overview_tile_color(x, y)]);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void refresh_overview_canvas(void)
-{
-  struct canvas_store store = {overview_canvas_store};
-
-  base_refresh_overview_canvas(&store);
-}
-
-
-/**************************************************************************
-...
-**************************************************************************/
-void overview_update_tile(int x, int y)
-{
-  int overview_x, overview_y, base_x, base_y;
-
-  map_to_overview_pos(&overview_x, &overview_y, x, y);
-  map_to_base_overview_pos(&base_x, &base_y, x, y);
-
-  set_overview_tile_foreground_color(x, y);
-  gdk_draw_rectangle(overview_canvas_store, fill_bg_gc, TRUE,
-                    base_x, base_y,
-                    OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
-  
-  gdk_draw_rectangle(overview_canvas->window, fill_bg_gc, TRUE,
-                    overview_x, overview_y,
-                    OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
 }
 
 /**************************************************************************
Index: client/gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.63
diff -u -u -r1.63 mapview.c
--- client/gui-mui/mapview.c    2003/11/14 12:26:57     1.63
+++ client/gui-mui/mapview.c    2004/01/25 10:37:39
@@ -378,23 +378,6 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void refresh_overview_canvas(void)
-{
-  DoMethod(main_overview_area, MUIM_Overview_Refresh);
-}
-
-
-/**************************************************************************
-...
-**************************************************************************/
-void overview_update_tile(int x, int y)
-{
-  DoMethod(main_overview_area, MUIM_Overview_RefreshSingle, x, y);
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 void refresh_overview_viewrect(void)
 {
   DoMethod(main_overview_area, MUIM_Overview_Refresh);
Index: client/gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.35
diff -u -u -r1.35 mapview.c
--- client/gui-stub/mapview.c   2003/11/14 12:26:57     1.35
+++ client/gui-stub/mapview.c   2004/01/25 10:37:40
@@ -126,14 +126,6 @@
 }
 
 /**************************************************************************
-  Update the tile for the given map position on the overview.
-**************************************************************************/
-void overview_update_tile(int map_x, int map_y)
-{
-  /* PORTME */
-}
-
-/**************************************************************************
   Draw a description for the given city.  (canvas_x, canvas_y) is the
   canvas position of the city itself.
 **************************************************************************/
@@ -302,14 +294,6 @@
   Draw a nuke mushroom cloud at the given tile.
 **************************************************************************/
 void put_nuke_mushroom_pixmaps(int map_x, int map_y)
-{
-  /* PORTME */
-}
-
-/**************************************************************************
-  Refresh (update) the entire map overview.
-**************************************************************************/
-void refresh_overview_canvas(void)
 {
   /* PORTME */
 }
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.85
diff -u -u -r1.85 mapview.c
--- client/gui-win32/mapview.c  2003/12/19 10:39:58     1.85
+++ client/gui-win32/mapview.c  2004/01/25 10:37:40
@@ -415,34 +415,6 @@
 }
 
 /**************************************************************************
-
-**************************************************************************/
-void
-overview_update_tile(int x, int y)
-{
-  HDC hdc;
-  RECT rc;
-  int overview_x, overview_y, base_x, base_y;
-
-  map_to_overview_pos(&overview_x, &overview_y, x, y);
-  map_to_base_overview_pos(&base_x, &base_y, x, y);
- 
-  rc.left = base_x;
-  rc.right = rc.left + OVERVIEW_TILE_WIDTH;
-  rc.top = base_y;
-  rc.bottom = rc.top + OVERVIEW_TILE_HEIGHT;
-  FillRect(overviewstoredc,&rc,brush_std[overview_tile_color(x, y)]);
-
-  hdc=GetDC(root_window);
-  rc.left = overview_x + overview_win_x;
-  rc.top = overview_y + overview_win_y;
-  rc.right = rc.left + OVERVIEW_TILE_WIDTH;
-  rc.bottom = rc.top + OVERVIEW_TILE_HEIGHT;
-  FillRect(hdc,&rc,brush_std[overview_tile_color(x,y)]);
-  ReleaseDC(root_window,hdc);
-}
-
-/**************************************************************************
   Flush the given part of the canvas buffer (if there is one) to the
   screen.
 **************************************************************************/
@@ -836,17 +808,6 @@
     Sleep(1000); 
     update_map_canvas(x-1, y-1, 3, 3, TRUE);
   }
-}
-
-/**************************************************************************
-
-**************************************************************************/
-void
-refresh_overview_canvas(void)
-{
-  struct canvas_store store = {overviewstoredc};
-
-  base_refresh_overview_canvas(&store);
 }
 
 /**************************************************************************
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.85
diff -u -u -r1.85 gui_main.c
--- client/gui-xaw/gui_main.c   2004/01/24 02:58:55     1.85
+++ client/gui-xaw/gui_main.c   2004/01/25 10:37:42
@@ -201,10 +201,6 @@
 /* this pixmap acts as a backing store for the map_canvas widget */
 Pixmap map_canvas_store = 0;
 
-/* this pixmap acts as a backing store for the overview_canvas widget */
-Pixmap overview_canvas_store;
-int overview_canvas_store_width, overview_canvas_store_height;
-
 /* this pixmap is used when moving units etc */
 Pixmap single_tile_pixmap;
 
@@ -451,13 +447,10 @@
                                  timer_callback, NULL);
 
   map_canvas_resize();
-
-  overview_canvas_store=0;
-  set_overview_dimensions(80, 50);
 
-  XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_WHITE]);
-  XFillRectangle(display, overview_canvas_store, fill_bg_gc, 0, 0, 
-                overview_canvas_store_width, overview_canvas_store_height);
+  overview.store = NULL;
+  overview.window = fc_malloc(sizeof(*overview.window));
+  overview.window->pixmap = XtWindow(overview_canvas);
 
   single_tile_pixmap=XCreatePixmap(display, XtWindow(overview_canvas), 
                                   UNIT_TILE_WIDTH,
Index: client/gui-xaw/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.h,v
retrieving revision 1.11
diff -u -u -r1.11 gui_main.h
--- client/gui-xaw/gui_main.h   2003/12/01 19:32:04     1.11
+++ client/gui-xaw/gui_main.h   2004/01/25 10:37:42
@@ -34,9 +34,6 @@
 extern Pixmap       gray25;
 extern Pixmap       single_tile_pixmap;
 extern Pixmap       map_canvas_store;
-extern Pixmap       overview_canvas_store;
-extern int          overview_canvas_store_width;
-extern int          overview_canvas_store_height;
 extern Widget       map_vertical_scrollbar;
 extern Widget       map_horizontal_scrollbar;
 extern Widget       left_column_form;
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.151
diff -u -u -r1.151 mapview.c
--- client/gui-xaw/mapview.c    2003/11/19 17:30:51     1.151
+++ client/gui-xaw/mapview.c    2004/01/25 10:37:43
@@ -122,14 +122,12 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void set_overview_dimensions(int x, int y)
+void map_size_changed(void)
 {
   Dimension h, w;
 
-  XtVaSetValues(overview_canvas,
-               XtNwidth, OVERVIEW_TILE_WIDTH * x,
-               XtNheight, OVERVIEW_TILE_HEIGHT * y,
-               NULL);
+  XtVaSetValues(overview_canvas, XtNwidth, overview.width, XtNheight,
+               overview.height, NULL);
 
   XtVaGetValues(left_column_form, XtNheight, &h, NULL);
   XtVaSetValues(map_form, XtNheight, h, NULL);
@@ -137,19 +135,28 @@
   XtVaGetValues(below_menu_form, XtNwidth, &w, NULL);
   XtVaSetValues(menu_form, XtNwidth, w, NULL);
   XtVaSetValues(bottom_form, XtNwidth, w, NULL);
+}
 
-  overview_canvas_store_width = OVERVIEW_TILE_WIDTH * x;
-  overview_canvas_store_height = OVERVIEW_TILE_HEIGHT * y;
+/**************************************************************************
+...
+**************************************************************************/
+struct canvas_store *canvas_store_create(int width, int height)
+{
+  struct canvas_store *result = fc_malloc(sizeof(*result));
 
-  if(overview_canvas_store)
-    XFreePixmap(display, overview_canvas_store);
-  
-  overview_canvas_store=XCreatePixmap(display, XtWindow(overview_canvas), 
-                                     overview_canvas_store_width,
-                                     overview_canvas_store_height,
-                                     display_depth);
+  result->pixmap =
+      XCreatePixmap(display, root_window, width, height, display_depth);
+  return result;
 }
 
+/**************************************************************************
+...
+**************************************************************************/
+void canvas_store_free(struct canvas_store *store)
+{
+  XFreePixmap(display, store->pixmap);
+  free(store);
+}
 
 /**************************************************************************
 ...
@@ -380,87 +387,20 @@
 
   XtVaGetValues(w, XtNheight, &height, XtNwidth, &width, NULL);
   
-  refresh_overview_viewrect();
-}
-
-
-/**************************************************************************
-...
-**************************************************************************/
-static void set_overview_tile_foreground_color(int x, int y)
-{
-  XSetForeground(display, fill_bg_gc,
-                colors_standard[overview_tile_color(x, y)]);
-}
-
-
-/**************************************************************************
-...
-**************************************************************************/
-void refresh_overview_canvas(void)
-{
-  struct canvas_store store = {overview_canvas_store};
-
-  base_refresh_overview_canvas(&store);
-}
-
-
-/**************************************************************************
-...
-**************************************************************************/
-void overview_update_tile(int x, int y)
-{
-  int overview_x, overview_y, base_x, base_y;
-
-  map_to_overview_pos(&overview_x, &overview_y, x, y);
-  map_to_base_overview_pos(&base_x, &base_y, x, y);
-
-  set_overview_tile_foreground_color(x, y);
-  XFillRectangle(display, overview_canvas_store, fill_bg_gc,
-                base_x, base_y,
-                OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
-  XFillRectangle(display, XtWindow(overview_canvas), fill_bg_gc, 
-                overview_x, overview_y,
-                OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
+  refresh_overview_canvas();
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-void refresh_overview_viewrect(void)
+void gui_copy_canvas(struct canvas_store *dest, struct canvas_store *src,
+                    int src_x, int src_y, int dest_x, int dest_y, int width,
+                    int height)
 {
-  int x0 = OVERVIEW_TILE_WIDTH * map_overview_x0;
-  int x1 = OVERVIEW_TILE_WIDTH * (map.xsize - map_overview_x0);
-  int y0 = OVERVIEW_TILE_HEIGHT * map_overview_y0;
-  int y1 = OVERVIEW_TILE_HEIGHT * (map.ysize - map_overview_y0);
-  int gui_x[4], gui_y[4], i;
-
-  /* (map_overview_x0, map_overview_y0) splits the map into four
-   * rectangles.  Draw each of these rectangles to the screen, in turn. */
-  XCopyArea(display, overview_canvas_store, XtWindow(overview_canvas),
-           civ_gc, x0, y0, x1, y1, 0, 0);
-  XCopyArea(display, overview_canvas_store, XtWindow(overview_canvas),
-           civ_gc, 0, y0, x0, y1, x1, 0);
-  XCopyArea(display, overview_canvas_store, XtWindow(overview_canvas),
-           civ_gc, x0, 0, x1, y0, 0, y1);
-  XCopyArea(display, overview_canvas_store, XtWindow(overview_canvas),
-           civ_gc, 0, 0, x0, y0, x1, y1);
-
-  /* Now draw the mapview window rectangle onto the overview. */
-  XSetForeground(display, civ_gc, colors_standard[COLOR_STD_WHITE]);
-  get_mapview_corners(gui_x, gui_y);
-  for (i = 0; i < 4; i++) {
-    int src_x = gui_x[i];
-    int src_y = gui_y[i];
-    int dest_x = gui_x[(i + 1) % 4];
-    int dest_y = gui_y[(i + 1) % 4];
-
-    XDrawLine(display, XtWindow(overview_canvas), civ_gc,
-             src_x, src_y, dest_x, dest_y);
-  }
+  XCopyArea(display, src->pixmap, dest->pixmap, civ_gc, src_x, src_y, width,
+           height, dest_x, dest_y);
 }
 
-
 /**************************************************************************
 ...
 **************************************************************************/
@@ -522,7 +462,6 @@
       update_map_canvas_visible();
 
       update_map_canvas_scrollbars();
-      refresh_overview_viewrect();
     } else {
       XCopyArea(display, map_canvas_store, XtWindow(map_canvas),
                civ_gc,
@@ -541,9 +480,6 @@
 {
   Dimension width, height;
 
-  if (map_canvas_store)
-    XFreePixmap(display, map_canvas_store);
-
   XtVaGetValues(map_canvas, XtNwidth, &width, XtNheight, &height, NULL);
 
   mapview_canvas.width = width;
@@ -551,16 +487,14 @@
 
   map_canvas_store_twidth=((width-1)/NORMAL_TILE_WIDTH)+1;
   map_canvas_store_theight=((height-1)/NORMAL_TILE_HEIGHT)+1;
-
-  map_canvas_store=XCreatePixmap(display, XtWindow(map_canvas),
-                                map_canvas_store_twidth*NORMAL_TILE_WIDTH,
-                                map_canvas_store_theight*NORMAL_TILE_HEIGHT,
-                                display_depth);
 
-  if (!mapview_canvas.store) {
-    mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
+  if (mapview_canvas.store) {
+    canvas_store_free(mapview_canvas.store);
   }
-  mapview_canvas.store->pixmap = map_canvas_store;
+  mapview_canvas.store =
+      canvas_store_create(map_canvas_store_twidth * NORMAL_TILE_WIDTH,
+                         map_canvas_store_theight * NORMAL_TILE_HEIGHT);
+  map_canvas_store = mapview_canvas.store->pixmap;
 }
 
 /**************************************************************************
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.41
diff -u -u -r1.41 mapview_g.h
--- client/include/mapview_g.h  2003/11/14 12:26:58     1.41
+++ client/include/mapview_g.h  2004/01/25 10:37:43
@@ -28,8 +28,9 @@
 void update_city_descriptions(void);
 void set_indicator_icons(int bulb, int sol, int flake, int gov);
 
-void set_overview_dimensions(int x, int y);
-void overview_update_tile(int x, int y);
+void map_size_changed(void);
+struct canvas_store *canvas_store_create(int width, int height);
+void canvas_store_free(struct canvas_store *store);
 
 void show_city_desc(struct city *pcity, int canvas_x, int canvas_y);
 void prepare_show_city_descriptions(void);
@@ -53,6 +54,10 @@
 void gui_put_line(struct canvas_store *pcanvas_store, enum color_std color,
                  enum line_type ltype, int start_x, int start_y,
                  int dx, int dy);
+void gui_copy_canvas(struct canvas_store *dest, struct canvas_store *src,
+                    int src_x, int src_y, int dest_x, int dest_y, int width,
+                    int height);
+
 void flush_mapcanvas(int canvas_x, int canvas_y,
                     int pixel_width, int pixel_height);
 void dirty_rect(int canvas_x, int canvas_y,
@@ -72,9 +77,6 @@
 void decrease_unit_hp_smooth(struct unit *punit0, int hp0, 
                             struct unit *punit1, int hp1);
 void put_nuke_mushroom_pixmaps(int x, int y);
-
-void refresh_overview_canvas(void);
-void refresh_overview_viewrect(void);
 
 void draw_segment(int src_x, int src_y, int dir);
 void draw_selection_rectangle(int canvas_x, int canvas_y, int w, int h);

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