[Freeciv-Dev] (PR#6178) draw overview using native coordinates
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch changes the overview to use native coordinates. This means
that even with different types of maps (specifically iso-maps) the
overview representation will be rectangular and friendly. The same
reason this representation is good for array storage makes it good for
display in the rectangular overview window.
It is important to note that the GUI should not think of overview
coordinates as being equivalent to native coordinates. This is all
abstracted away behind the overview conversion functions. We can pretty
much consider these conversion functions to be a part of the core
topology code - they embed the wrapping of the map as well as the link
between overview and native coordinates. Embedding the wrapping is
necessary so that refreshing the overview window may be efficiently done.
With this patch the overview will work fairly well with all 8
gen-topologies topologies. Eventually we will probably want to have the
overview wrap in the Y direction as well (as the gen-topologies patch in
freeciv-test does). Also get_mapview_corners will need some changes to
work with iso-maps (but these changes are mathematically obtuse and
probably need to be seen in action to be believed).
jason
? diff
? client/diff
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.58
diff -u -r1.58 mapview_common.c
--- client/mapview_common.c 2003/08/12 18:54:37 1.58
+++ client/mapview_common.c 2003/09/17 02:45:38
@@ -1285,8 +1285,18 @@
**************************************************************************/
static void center_tile_overviewcanvas(int map_x, int map_y)
{
- /* Currently we just center the overview canvas around the tile. */
- map_overview_x0 = map_adjust_x(map_x - map.xsize / 2);
+ /* The overview coordinates are equivalent to native coordinates. */
+ 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(). */
+ if (topo_has_flag(TF_WRAPX)) {
+ map_overview_x0 = WRAP(map_x - map.xsize / 2, map.xsize);
+ } else {
+ map_overview_x0 = 0;
+ }
+ /* TODO: Y-wrapping of overview */
}
/**************************************************************************
@@ -1295,8 +1305,20 @@
void map_to_overview_pos(int *overview_x, int *overview_y,
int map_x, int map_y)
{
- *overview_x = OVERVIEW_TILE_WIDTH * map_adjust_x(map_x - map_overview_x0);
- *overview_y = OVERVIEW_TILE_HEIGHT * map_y;
+ int gui_x, gui_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. */
+ map_to_native_pos(&gui_x, &gui_y, map_x, map_y);
+ gui_x -= map_overview_x0;
+ if (topo_has_flag(TF_WRAPX)) {
+ gui_x = WRAP(gui_x, map.xsize);
+ }
+ /* TODO: Y-wrapping of overview */
+ *overview_x = OVERVIEW_TILE_WIDTH * gui_x;
+ *overview_y = OVERVIEW_TILE_HEIGHT * gui_y;
}
/**************************************************************************
@@ -1305,8 +1327,15 @@
void overview_to_map_pos(int *map_x, int *map_y,
int overview_x, int overview_y)
{
- *map_x = map_adjust_x(overview_x / OVERVIEW_TILE_WIDTH + map_overview_x0);
- *map_y = overview_y / OVERVIEW_TILE_HEIGHT;
+ int nat_x = overview_x / OVERVIEW_TILE_WIDTH + map_overview_x0;
+ int nat_y = overview_y / OVERVIEW_TILE_HEIGHT;
+ /* TODO: Y-wrapping of overview */
+
+ native_to_map_pos(map_x, map_y, nat_x, nat_y);
+ if (!normalize_map_pos(map_x, map_y)) {
+ /* All positions on the overview should be valid. */
+ assert(FALSE);
+ }
}
/**************************************************************************
@@ -1360,10 +1389,11 @@
void map_to_base_overview_pos(int *base_overview_x, int *base_overview_y,
int map_x, int map_y)
{
- /* Base overview positions are just like map positions, but scaled to
+ /* Base overview positions are just like native positions, but scaled to
* the overview tile dimensions. */
- *base_overview_x = map_x * OVERVIEW_TILE_WIDTH;
- *base_overview_y = map_y * OVERVIEW_TILE_HEIGHT;
+ 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;
}
/**************************************************************************
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#6178) draw overview using native coordinates,
Jason Short <=
|
|