Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4613) "base" overview positions
Home

[Freeciv-Dev] (PR#4613) "base" overview positions

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4613) "base" overview positions
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 18 Jul 2003 12:42:24 -0700
Reply-to: rt@xxxxxxxxxxxxxx

The overview code deals with several concepts of coordinate systems:

- Map coordinates are the core type; functions accept these and 
iterators loop over them.

- Overview coordinates (see map_to_overview_pos/overview_to_map_pos) are 
the GUI (canvas) coordinates used on the minimap.  Since the minimap 
gets recentered based on wrapping these coordinates may change when the 
overview is recentered.  Each tile has dimensions 
OVERVIEW_TILE_WIDTHxOVERVIEW_TILE_HEIGHT in overview coordinates.

- Backing store coordinates are like overview coordinates, except 
wrapping is ignored.  Thus the map position (0,0) will always be at 
(0,0) in backing store coordinates.  The backing store is done this way 
so that if you recenter the mapview, although the overview coordinates 
will no longer be the same the backing store will be - so you can still 
use the same backing store; you just need to refresh the minimap with it.

Currently it is very easy to convert from a map position to a backing 
store position:

   gui_x = map_x * OVERVIEW_TILE_WIDTH;
   gui_y = map_y * OVERVIEW_TILE_HEIGHT;

but in the future this may not always be the case.  To make things 
simpler for the GUI, therefore, I would like to introduce a conversion 
function - tentatively called map_to_base_overview_pos (names welcome). 
  The attached patch does this for all GUIs which support overview 
coordinates.

jason

? rc
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.49
diff -u -r1.49 mapview_common.c
--- client/mapview_common.c     2003/07/18 01:12:09     1.49
+++ client/mapview_common.c     2003/07/18 19:34:32
@@ -1180,3 +1180,14 @@
   *map_x = map_adjust_x(overview_x / OVERVIEW_TILE_WIDTH + map_overview_x0);
   *map_y = overview_y / OVERVIEW_TILE_HEIGHT;
 }
+
+/**************************************************************************
+  Find the "base" (unwrapped) overview coordinates for a given map
+  position.
+**************************************************************************/
+void map_to_base_overview_pos(int *base_overview_x, int *base_overview_y,
+                             int map_x, int map_y)
+{
+  *base_overview_x = map_x * OVERVIEW_TILE_WIDTH;
+  *base_overview_y = map_y * OVERVIEW_TILE_HEIGHT;
+}
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.32
diff -u -r1.32 mapview_common.h
--- client/mapview_common.h     2003/07/18 01:12:09     1.32
+++ client/mapview_common.h     2003/07/18 19:34:32
@@ -185,6 +185,8 @@
                         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);
 
 extern int map_overview_x0;
 
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.173
diff -u -r1.173 mapview.c
--- client/gui-gtk/mapview.c    2003/07/18 01:12:09     1.173
+++ client/gui-gtk/mapview.c    2003/07/18 19:34:32
@@ -429,9 +429,13 @@
 void refresh_overview_canvas(void)
 {
   whole_map_iterate(x, y) {
+    int gui_x, gui_y;
+
+    map_to_base_overview_pos(&gui_x, &gui_y, x, y);
+
     set_overview_tile_foreground_color(x, y);
     gdk_draw_rectangle(overview_canvas_store, fill_bg_gc, TRUE,
-                      OVERVIEW_TILE_WIDTH * x, OVERVIEW_TILE_HEIGHT * y,
+                      gui_x, gui_y,
                       OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
   } whole_map_iterate_end;
 
@@ -444,15 +448,15 @@
 **************************************************************************/
 void overview_update_tile(int x, int y)
 {
-  int overview_x, overview_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,
-                    OVERVIEW_TILE_WIDTH * x, OVERVIEW_TILE_HEIGHT * y,
-                    OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
-  
+                    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-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.65
diff -u -r1.65 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/07/17 01:37:07     1.65
+++ client/gui-gtk-2.0/mapview.c        2003/07/18 19:34:32
@@ -481,9 +481,13 @@
 void refresh_overview_canvas(void)
 {
   whole_map_iterate(x, y) {
+    int gui_x, gui_y;
+
+    map_to_base_overview_pos(&gui_x, &gui_y, x, y);
+
     set_overview_tile_foreground_color(x, y);
     gdk_draw_rectangle(overview_canvas_store, fill_bg_gc, TRUE,
-                      OVERVIEW_TILE_WIDTH * x, OVERVIEW_TILE_HEIGHT * y,
+                      gui_x, gui_y,
                       OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
   } whole_map_iterate_end;
 
@@ -496,13 +500,14 @@
 **************************************************************************/
 void overview_update_tile(int x, int y)
 {
-  int overview_x, overview_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,
-                    OVERVIEW_TILE_WIDTH * x, OVERVIEW_TILE_HEIGHT * y,
+                    gui_x, gui_y,
                     OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
   
   gdk_draw_rectangle(overview_canvas->window, fill_bg_gc, TRUE,
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.72
diff -u -r1.72 mapview.c
--- client/gui-win32/mapview.c  2003/07/17 01:37:07     1.72
+++ client/gui-win32/mapview.c  2003/07/18 19:34:32
@@ -465,13 +465,14 @@
 {
   HDC hdc;
   RECT rc;
-  int overview_x, overview_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);
  
-  rc.left = OVERVIEW_TILE_WIDTH * x;
+  rc.left = base_x;
   rc.right = rc.left + OVERVIEW_TILE_WIDTH;
-  rc.top = OVERVIEW_TILE_HEIGHT * y;
+  rc.top = base_y;
   rc.bottom = rc.top + OVERVIEW_TILE_HEIGHT;
   FillRect(overviewstoredc,&rc,brush_std[overview_tile_color(x, y)]);
 
@@ -883,9 +884,13 @@
   RECT rc;
 
   whole_map_iterate(x, y) {
-    rc.left = OVERVIEW_TILE_WIDTH * x;
+    int gui_x, gui_y;
+
+    map_to_base_overview_pos(&gui_x, &gui_y, x, y);
+
+    rc.left = gui_x;
     rc.right = rc.left + OVERVIEW_TILE_WIDTH;
-    rc.top = OVERVIEW_TILE_HEIGHT * y;
+    rc.top = gui_y;
     rc.bottom = rc.top + OVERVIEW_TILE_HEIGHT;
     FillRect(overviewstoredc, &rc, brush_std[overview_tile_color(x, y)]);
 
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.139
diff -u -r1.139 mapview.c
--- client/gui-xaw/mapview.c    2003/07/18 01:12:09     1.139
+++ client/gui-xaw/mapview.c    2003/07/18 19:34:32
@@ -401,9 +401,13 @@
 void refresh_overview_canvas(void)
 {
   whole_map_iterate(x, y) {
+    int gui_x, gui_y;
+
+    map_to_base_overview_pos(&gui_x, &gui_y, x, y);
+
     set_overview_tile_foreground_color(x, y);
     XFillRectangle(display, overview_canvas_store, fill_bg_gc,
-                  OVERVIEW_TILE_WIDTH * x, OVERVIEW_TILE_HEIGHT * y,
+                  gui_x, gui_y,
                   OVERVIEW_TILE_WIDTH, OVERVIEW_TILE_HEIGHT);
   } whole_map_iterate_end;
 
@@ -416,15 +420,15 @@
 **************************************************************************/
 void overview_update_tile(int x, int y)
 {
-  int overview_x, overview_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,
-                OVERVIEW_TILE_WIDTH * x, OVERVIEW_TILE_HEIGHT * y,
+                gui_x, gui_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);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4613) "base" overview positions, Jason Short <=