Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] (PR#6346) unify modification of the mapview origin
Home

[Freeciv-Dev] (PR#6346) unify modification of the mapview origin

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#6346) unify modification of the mapview origin
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 30 Sep 2003 18:14:47 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch adds a new function, set_mapview_origin().  This is called to 
change the origin of the mapview.

- This removes some duplicated code.

- Wrapping vs. clipping operations are generalized (e.g., gen-topologies).

- At least one buglet is fixed (currently when scrolling the overview is 
not recentered).

- This gives one single place to add any new operations to be done here 
(e.g., calculation of the center tile position).

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.62
diff -u -r1.62 mapview_common.c
--- client/mapview_common.c     2003/09/30 19:01:22     1.62
+++ client/mapview_common.c     2003/10/01 02:00:36
@@ -289,6 +289,50 @@
 }
 
 /****************************************************************************
+  Change the mapview origin, clip it, and update everything.
+****************************************************************************/
+static void set_mapview_origin(int map_x0, int map_y0)
+{
+  int nat_x0, nat_y0, xmin, xmax, ymin, ymax, xsize, ysize;
+
+  /* First wrap/clip the position.  Wrapping is done in native positions
+   * while clipping is done in scroll (native) positions. */
+  map_to_native_pos(&nat_x0, &nat_y0, map_x0, map_y0);
+  get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize);
+
+  if (topo_has_flag(TF_WRAPX)) {
+    nat_x0 = WRAP(nat_x0, map.xsize);
+  } else {
+    nat_x0 = CLIP(xmin, nat_x0, xmax - xsize);
+  }
+
+  if (topo_has_flag(TF_WRAPY)) {
+    nat_y0 = WRAP(nat_y0, map.ysize);
+  } else {
+    nat_y0 = CLIP(ymin, nat_y0, ymax - ysize);
+  }
+
+  native_to_map_pos(&map_x0, &map_y0, nat_x0, nat_y0);
+
+  /* Then update everything. */
+  if (mapview_canvas.map_x0 != map_x0 || mapview_canvas.map_y0 != map_y0) {
+    int map_center_x, map_center_y;
+
+    mapview_canvas.map_x0 = map_x0;
+    mapview_canvas.map_y0 = map_y0;
+
+    get_center_tile_mapcanvas(&map_center_x, &map_center_y);
+    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();
+    }
+  }
+}
+
+/****************************************************************************
   Return the range of values that the mapview origin can take, in scroll
   positions.  Useful for scrollbars or when manually clipping the window.
 ****************************************************************************/
@@ -316,21 +360,10 @@
 ****************************************************************************/
 void set_mapview_scroll_pos(int scroll_x, int scroll_y)
 {
-  int xmin, ymin, xmax, ymax, xsize, ysize, x0, y0;
-
-  get_mapview_scroll_window(&xmin, &ymin, &xmax, &ymax, &xsize, &ysize);
-  native_to_map_pos(&x0, &y0, scroll_x, scroll_y);
+  int map_x0, map_y0;
 
-  x0 = CLIP(xmin, x0, xmax - xsize);
-  y0 = CLIP(ymin, y0, ymax - ysize);
-
-  if (x0 != mapview_canvas.map_x0 || y0 != mapview_canvas.map_y0) {
-    mapview_canvas.map_x0 = x0;
-    mapview_canvas.map_y0 = y0;
-
-    update_map_canvas_visible();
-    refresh_overview_viewrect();
-  }
+  native_to_map_pos(&map_x0, &map_y0, scroll_x, scroll_y);
+  set_mapview_origin(map_x0, map_y0);
 }
 
 /**************************************************************************
@@ -362,25 +395,8 @@
     map_x -= mapview_canvas.tile_width / 2;
     map_y -= mapview_canvas.tile_height / 2;
   }
-
-  /* Wrap. */
-  map_x = map_adjust_x(map_x);
 
-  /* Clip. */
-  map_y = map_adjust_y(map_y);
-  map_y = MIN(map_y,
-             map.ysize + EXTRA_BOTTOM_ROW - mapview_canvas.tile_height);
-
-  /* Now that we've determined the new origin, update everything. */
-  mapview_canvas.map_x0 = map_x;
-  mapview_canvas.map_y0 = map_y;
-  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();
-  }
+  set_mapview_origin(map_x, map_y);
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#6346) unify modification of the mapview origin, Jason Short <=