Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] (PR#3798) Change canvas_to_map_pos() from void to bool
Home

[Freeciv-Dev] (PR#3798) Change canvas_to_map_pos() from void to bool

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: a-l@xxxxxxx
Subject: [Freeciv-Dev] (PR#3798) Change canvas_to_map_pos() from void to bool
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 1 Apr 2003 19:26:15 -0800
Reply-to: rt@xxxxxxxxxxxxxx

[a-l@xxxxxxx - Wed Mar 26 16:06:34 2003]:

> Note: This requires #3779 (remove get_map_xy/get_canvas_xy).
> 
> canvas_to_map_pos()   is changed from "void" to "bool",
> and may now yield an unreal (but normal) tile.
> 
> --  Caller may also have to call nearest_real_pos()
>     if that's what you really really want.
> 
> --  All instances of get_map_xy()  in all clients (nothing in
>     gui-stub or gui-beos) are changed to canvas_to_map_pos()
>     according to #3779. The returned bool is checked, and the result
>     is either discarded or processed with nearest_real_pos().
> 
> Effects:
> 
> --  Cities will not pop up and units will not be selected when
>     you click on unreal tiles. It wasn't obvious which tile
>     you'd get anyway.
> 
> --  Goto lines do not appear when you move pointer in the black
>     (as in unreal, not fogged). An unreal tile _may_ be passed
>     to draw_line(), which now checks.
> 
> --  But you can still scroll the map by right-clicking on unreal
>     tiles, since convenience is more important than precision.
> 
> I tested isometric and tried to be meticulous with the modification
> in the clients I can't compile.

For testing, you should compile with debugging enabled (--enable-debug).
 This enables CHECK_MAP_POS, which will catch some mistakes (real and
imagined).

Attached is a tweaked version of this patch.  Changes include:

- Don't pass unreal coordinates to draw_line; instead have the caller
handle them.  This also avoids passing unreal coordinates to same_pos,
which is a no-no.  The handling of the unreal case is done the way it is
now (nearest_real_pos) rather than the way you handle it (undraw_line);
another alternative would be to do nothing (leaving the line where it is).

- Only call nearest_real_pos in the unreal case.

- Replace a block of gui-win32 code with a call to update_line.

- Remove get_map_xy macros, which are no longer used.

- Remove a spurious call to wakeup_sentried_units from gui-gtk-2.0.

- Fix some style.

- Change the semantics of normalize_map_pos so that unreal positions are
left unchanged.  This is faster and IMO more correct (see below), and
making it an official part of the interface is needed so that code like

  if (!normalize_map_pos(&x, &y)) nearest_real_pos(&x, &y);

will work.


Note that gui-xaw needed no changes, indicating that it doesn't use
canvas_to_map_pos as it should.  I'll look at this in more detail later.


Now, the longstanding question: what should normalize_map_pos do in the
unreal case?  Obviously they return FALSE, but what should happen to the
coordinates?  There are three choices:

1.  They are left unchanged.
2.  They are wrapped - so they will be "canonical" but not "real".
3.  They are made normal using nearest_real_pos.

Problem with #1 - it can lead to bugs if anyone tries to use the
unwrapped, unreal coordinates (which they shouldn't do).

Problems with #2 - it may not be possible under all future topologies. 
It introduces the concept of "canonical" coordinates (or as Arnstein put
it: "normal but not real", although that's incorrect), which is not used
anywhere else.  Callers might be tempted to use these coordinates (like
the original patch did, passing them to same_pos) which is bad.  It is
also slower than #1.

Problems with #3 - it is much slower.  It tempts the callers to use
these coordinates without thinking about it.  It can conceal errors when
this is done.

I am in favor of #1 (as I believe Ross is).  This patch makes that change.


The same choice applies to canvas_to_map_pos.  Here I am tempted to put:

  if (!normalize_map_pos(&x, &y)) {
    nearest_real_pos(&x, &y);
    return FALSE;
  }
  return TRUE;

in canvas_to_map_pos - this would save a fair amount of code since about
half the callers do this anyway.  But again it would conceal errors and
encourage misuse, so I haven't done this.  However, it does mean most
callers don't need to be changed - so it could be used as an
intermediate step.

jason

Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.47
diff -u -r1.47 goto.c
--- client/goto.c       2003/02/20 09:45:21     1.47
+++ client/goto.c       2003/04/02 03:23:46
@@ -822,10 +822,7 @@
   int start_index;
 
   assert(is_active);
-
-  /* Replace with check for is_normal_tile later */
-  assert(is_real_map_pos(dest_x, dest_y));
-  normalize_map_pos(&dest_x, &dest_y);
+  CHECK_MAP_POS(dest_x, dest_y);
 
   if (VECTOR(dest_x, dest_y) == 0) {
     undraw_line();
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.7
diff -u -r1.7 mapctrl_common.c
--- client/mapctrl_common.c     2003/04/01 16:48:33     1.7
+++ client/mapctrl_common.c     2003/04/02 03:23:46
@@ -58,7 +58,9 @@
   canvas_y = mapview_canvas.height / 2;
   canvas_x += DIR_DX[gui_dir] * mapview_canvas.width / 2;
   canvas_y += DIR_DY[gui_dir] * mapview_canvas.height / 2;
-  canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y);
+  if (!canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
+    nearest_real_pos(&map_x, &map_y);
+  }
   center_tile_mapcanvas(map_x, map_y);
 }
 
@@ -109,7 +111,9 @@
       && draw_goto_line) {
     int x, y, old_x, old_y;
 
-    canvas_to_map_pos(&x, &y, canvas_x, canvas_y);
+    if (!canvas_to_map_pos(&x, &y, canvas_x, canvas_y)) {
+      nearest_real_pos(&x, &y);
+    }
 
     get_line_dest(&old_x, &old_y);
     if (!same_pos(old_x, old_y, x, y)) {
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.38
diff -u -r1.38 mapview_common.c
--- client/mapview_common.c     2003/04/01 16:48:33     1.38
+++ client/mapview_common.c     2003/04/02 03:23:47
@@ -228,9 +228,12 @@
 }
 
 /**************************************************************************
-  Finds the map coordinates corresponding to pixel coordinates.
+  Finds the map coordinates corresponding to pixel coordinates.  Returns
+  TRUE if the position is real; in this case it will be normalized. Returns
+  FALSE if the tile is unreal - caller may use nearest_real_pos() if
+  required.
 **************************************************************************/
-void canvas_to_map_pos(int *map_x, int *map_y, int canvas_x, int canvas_y)
+bool canvas_to_map_pos(int *map_x, int *map_y, int canvas_x, int canvas_y)
 {
   if (is_isometric) {
     /* The basic operation here is a simple pi/4 rotation; however, we
@@ -270,11 +273,7 @@
   *map_x += mapview_canvas.map_x0;
   *map_y += mapview_canvas.map_y0;
 
-  /*
-   * If we are outside the map find the nearest tile, with distance as
-   * seen on the map.
-   */
-  nearest_real_pos(map_x, map_y);
+  return normalize_map_pos(map_x, map_y);
 }
 
 /**************************************************************************
@@ -283,8 +282,10 @@
 void get_center_tile_mapcanvas(int *map_x, int *map_y)
 {
   /* This sets the pointers map_x and map_y */
-  canvas_to_map_pos(map_x, map_y,
-                   mapview_canvas.width / 2, mapview_canvas.height / 2);
+  if (!canvas_to_map_pos(map_x, map_y,
+          mapview_canvas.width / 2, mapview_canvas.height / 2)) {
+    nearest_real_pos(map_x, map_y);
+  }
 }
 
 /**************************************************************************
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.27
diff -u -r1.27 mapview_common.h
--- client/mapview_common.h     2003/04/01 16:48:33     1.27
+++ client/mapview_common.h     2003/04/02 03:23:47
@@ -138,7 +138,7 @@
 enum color_std get_grid_color(int x1, int y1, int x2, int y2);
 
 bool map_to_canvas_pos(int *canvas_x, int *canvas_y, int map_x, int map_y);
-void canvas_to_map_pos(int *map_x, int *map_y, int canvas_x, int canvas_y);
+bool canvas_to_map_pos(int *map_x, int *map_y, int canvas_x, int canvas_y);
 
 void get_center_tile_mapcanvas(int *map_x, int *map_y);
 void center_tile_mapcanvas(int map_x, int map_y);
Index: client/gui-gtk/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v
retrieving revision 1.76
diff -u -r1.76 mapctrl.c
--- client/gui-gtk/mapctrl.c    2003/02/17 22:49:27     1.76
+++ client/gui-gtk/mapctrl.c    2003/04/02 03:23:47
@@ -302,9 +302,10 @@
     return TRUE;
   }
 
-  get_map_xy(ev->x, ev->y, &xtile, &ytile);
+  if (canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y)) {
+    wakeup_sentried_units(xtile, ytile);
+  }
 
-  wakeup_sentried_units(xtile, ytile);
   return TRUE;
 }
 
@@ -314,6 +315,7 @@
 gint butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev)
 {
   int xtile, ytile;
+  bool is_real;
 
   if (!can_client_change_view()) {
     return TRUE;
@@ -325,12 +327,16 @@
     return TRUE;
   }
 
-  get_map_xy(ev->x, ev->y, &xtile, &ytile);
+  is_real = canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y);
+  if (!is_real) {
+    nearest_real_pos(&xtile, &ytile);
+  }
 
-  if (ev->button == 1) {
+  if (is_real && ev->button == 1) {
     do_map_click(xtile, ytile);
     gtk_widget_grab_focus(turn_done_button);
-  } else if ((ev->button == 2) || (ev->state & GDK_CONTROL_MASK)) {
+  } else if (is_real
+            && (ev->button == 2 || (ev->state & GDK_CONTROL_MASK))) {
     popit(ev, xtile, ytile);
   } else if (ev->button == 3) {
     center_tile_mapcanvas(xtile, ytile);
@@ -373,7 +379,9 @@
     return;
   }
 
-  get_map_xy(ev->x, ev->y, &map_x, &map_y);
+  if (!canvas_to_map_pos(&map_x, &map_y, ev->x, ev->y)) {
+    return;
+  }
 
   pcity = find_city_near_tile(map_x, map_y);
   if (!pcity) {
@@ -453,7 +461,9 @@
   }
   
   gdk_window_get_pointer(map_canvas->window, &x, &y, NULL);
-  get_map_xy(x, y, &x, &y);
+  if (!canvas_to_map_pos(&x, &y, x, y)) {
+    nearest_real_pos(&x, &y);
+  }
 
   pcity = find_city_near_tile(x, y);
   if (!pcity) {
Index: client/gui-gtk/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.h,v
retrieving revision 1.20
diff -u -r1.20 mapview.h
--- client/gui-gtk/mapview.h    2003/04/01 16:48:33     1.20
+++ client/gui-gtk/mapview.h    2003/04/02 03:23:47
@@ -57,8 +57,6 @@
 #define map_canvas_store_theight mapview_canvas.tile_height
 
 /* Use of these wrapper functions is deprecated. */
-#define get_map_xy(canvas_x, canvas_y, map_x, map_y) \
-  canvas_to_map_pos(map_x, map_y, canvas_x, canvas_y)
 #define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
   map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
 
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.17
diff -u -r1.17 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        2003/02/17 22:49:27     1.17
+++ client/gui-gtk-2.0/mapctrl.c        2003/04/02 03:23:47
@@ -296,9 +296,10 @@
     return TRUE;
   }
 
-  get_map_xy(ev->x, ev->y, &xtile, &ytile);
+  if (canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y)) {
+    wakeup_sentried_units(xtile, ytile);
+  }
 
-  wakeup_sentried_units(xtile, ytile);
   return TRUE;
 }
 
@@ -308,6 +309,7 @@
 gboolean butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data)
 {
   int xtile, ytile;
+  bool is_real;
 
   if (!can_client_change_view()) {
     return TRUE;
@@ -319,12 +321,16 @@
     return TRUE;
   }
 
-  get_map_xy(ev->x, ev->y, &xtile, &ytile);
+  is_real = canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y);
+  if (!is_real) {
+    nearest_real_pos(&xtile, &ytile);
+  }
 
-  if (ev->button == 1) {
+  if (is_real && ev->button == 1) {
     do_map_click(xtile, ytile);
     gtk_widget_grab_focus(map_canvas);
-  } else if ((ev->button == 2) || (ev->state & GDK_CONTROL_MASK)) {
+  } else if (is_real
+            && (ev->button == 2 || (ev->state & GDK_CONTROL_MASK))) {
     popit(ev, xtile, ytile);
   } else if (ev->button == 3) {
     center_tile_mapcanvas(xtile, ytile);
@@ -367,7 +373,9 @@
     return;
   }
 
-  get_map_xy(ev->x, ev->y, &map_x, &map_y);
+  if (!canvas_to_map_pos(&map_x, &map_y, ev->x, ev->y)) {
+    return;
+  }
 
   pcity = find_city_near_tile(map_x, map_y);
   if (!pcity) {
@@ -447,7 +455,9 @@
   }
   
   gdk_window_get_pointer(map_canvas->window, &x, &y, NULL);
-  get_map_xy(x, y, &x, &y);
+  if (!canvas_to_map_pos(&x, &y, x, y)) {
+    nearest_real_pos(&x, &y);
+  }
 
   pcity = find_city_near_tile(x, y);
   if (!pcity) {
Index: client/gui-gtk-2.0/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.h,v
retrieving revision 1.11
diff -u -r1.11 mapview.h
--- client/gui-gtk-2.0/mapview.h        2003/04/01 16:48:33     1.11
+++ client/gui-gtk-2.0/mapview.h        2003/04/02 03:23:47
@@ -59,8 +59,6 @@
 #define map_canvas_store_theight mapview_canvas.tile_height
 
 /* Use of these wrapper functions is deprecated. */
-#define get_map_xy(canvas_x, canvas_y, map_x, map_y) \
-  canvas_to_map_pos(map_x, map_y, canvas_x, canvas_y)
 #define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
   map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
 
Index: client/gui-mui/mapclass.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapclass.c,v
retrieving revision 1.91
diff -u -r1.91 mapclass.c
--- client/gui-mui/mapclass.c   2003/02/08 22:52:46     1.91
+++ client/gui-mui/mapclass.c   2003/04/02 03:23:49
@@ -1538,7 +1538,11 @@
        if (_isinobject(msg->imsg->MouseX, msg->imsg->MouseY))
        {
           int x, y;
-          get_map_xy(msg->imsg->MouseX - _mleft(o), msg->imsg->MouseY - 
_mtop(o), &x, &y);
+          if (!canvas_to_map_pos(&x, &y,
+                                msg->imsg->MouseX - _mleft(o),
+                                msg->imsg->MouseY - _mtop(o))) {
+            nearest_real_pos(&x, &y);
+          }
 
          if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
          {
@@ -1610,7 +1614,10 @@
       struct tile *ptile;
       int x,y;
 
-      get_map_xy(msg->mx - _mleft(o), msg->my - _mtop(o), &x, &y);
+      if (!canvas_to_map_pos(&x, &y,
+                            msg->mx - _mleft(o), msg->my - _mtop(o)))  {
+        nearest_real_pos(&x, &y);
+      }
 
       ptile = map_get_tile(x, y);
 
Index: client/gui-mui/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.h,v
retrieving revision 1.6
diff -u -r1.6 mapview.h
--- client/gui-mui/mapview.h    2003/04/01 16:48:33     1.6
+++ client/gui-mui/mapview.h    2003/04/02 03:23:49
@@ -20,8 +20,6 @@
 void create_line_at_mouse_pos(void);
 
 /* Use of these wrapper functions is deprecated. */
-#define get_map_xy(canvas_x, canvas_y, map_x, map_y) \
-  canvas_to_map_pos(map_x, map_y, canvas_x, canvas_y)
 #define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
   map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
 
Index: client/gui-sdl/finddlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/finddlg.c,v
retrieving revision 1.6
diff -u -r1.6 finddlg.c
--- client/gui-sdl/finddlg.c    2003/03/20 13:37:52     1.6
+++ client/gui-sdl/finddlg.c    2003/04/02 03:23:49
@@ -157,7 +157,10 @@
   
   h = WINDOW_TILE_HIGH + 3 + FRAME_WH;
   
-  get_map_xy(Main.map->w/2 , Main.map->h/2 , &orginal_x , &orginal_y);
+  if (!canvas_to_map_pos(&orginal_x, &orginal_y,
+                        Main.map->w/2, Main.map->h/2)) {
+    nearest_real_pos(&orginal_x, &orginal_y);
+  }
   
   pFind_City_Dlg = MALLOC(sizeof(struct ADVANCED_DLG));
   
Index: client/gui-sdl/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapctrl.c,v
retrieving revision 1.14
diff -u -r1.14 mapctrl.c
--- client/gui-sdl/mapctrl.c    2003/03/20 13:37:52     1.14
+++ client/gui-sdl/mapctrl.c    2003/04/02 03:23:49
@@ -773,6 +773,7 @@
 void button_down_on_map(SDL_MouseButtonEvent * pButtonEvent)
 {
   int col, row;
+  bool is_real;
 
   if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
     return;
@@ -785,15 +786,23 @@
   }
 #endif
   
-  get_map_xy((int) pButtonEvent->x, (int) pButtonEvent->y, &col, &row);
+  is_real = canvas_to_map_pos(&col, &row,
+                             (int) pButtonEvent->x, (int) pButtonEvent->y);
   draw_goto_patrol_lines = FALSE;
   
   if (pButtonEvent->button == SDL_BUTTON_LEFT) {
-    do_map_click(col, row);
+    if (is_real) {
+      do_map_click(col, row);
+    }
   } else {
     if (pButtonEvent->button == SDL_BUTTON_MIDDLE) {
-      popup_advanced_terrain_dialog(col , row);
+      if (is_real) {
+        popup_advanced_terrain_dialog(col, row);
+      }
     } else {
+      if (!is_real) {
+        nearest_real_pos(&col, &row);
+      }
       center_tile_mapcanvas(col, row);
       flush_dirty();
     }
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.40
diff -u -r1.40 mapview.c
--- client/gui-sdl/mapview.c    2003/03/20 13:37:52     1.40
+++ client/gui-sdl/mapview.c    2003/04/02 03:23:50
@@ -1221,7 +1221,10 @@
     map_h = mapview_canvas.tile_height;
     
 #if 0
-    get_map_xy(0, 0, &Wx, &Wy);        /* take from Main Map */
+    /* take from Main Map */
+    if (!canvas_to_map_pos(&Wx, &Wy, 0, 0)) {
+      nearest_real_pos(&Wx, &Wy);
+    }
 #endif
     
     Wx = map_view_x0 * Mini_map_cell_w + FRAME_WH;
Index: client/gui-sdl/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.h,v
retrieving revision 1.9
diff -u -r1.9 mapview.h
--- client/gui-sdl/mapview.h    2003/04/01 16:48:33     1.9
+++ client/gui-sdl/mapview.h    2003/04/02 03:23:50
@@ -43,8 +43,6 @@
 void flush_all(void);
 
 /* Use of these wrapper functions is deprecated. */
-#define get_map_xy(canvas_x, canvas_y, map_x, map_y) \
-  canvas_to_map_pos(map_x, map_y, canvas_x, canvas_y)
 #define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
   map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
 
Index: client/gui-win32/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapctrl.c,v
retrieving revision 1.20
diff -u -r1.20 mapctrl.c
--- client/gui-win32/mapctrl.c  2003/02/17 22:49:27     1.20
+++ client/gui-win32/mapctrl.c  2003/04/02 03:23:51
@@ -58,18 +58,7 @@
 *************************************************************************/
 void map_handle_move(int window_x, int window_y)
 {
-  int x, y, old_x, old_y;
-
-  if ((hover_state == HOVER_GOTO || hover_state == HOVER_PATROL)
-      && draw_goto_line) {
-    get_map_xy(window_x, window_y, &x, &y);
-    
-    get_line_dest(&old_x, &old_y);
-    if (old_x != x || old_y != y) {
-      draw_line(x, y);
-    }
-  }
-  
+  update_line(window_x, window_y);
 }
 
 /*************************************************************************
@@ -278,7 +267,9 @@
       break;
     }
     SetFocus(root_window);
-    get_map_xy(LOWORD(lParam),HIWORD(lParam),&xtile,&ytile);
+    if (!canvas_to_map_pos(&xtile, &ytile, LOWORD(lParam), HIWORD(lParam))) {
+      break;
+    }
     if (wParam&MK_SHIFT) {
       adjust_workers(xtile,ytile);
       wakeup_sentried_units(xtile,ytile);
@@ -289,18 +280,24 @@
     }
     break;
   case WM_MBUTTONDOWN:
-    if (can_client_change_view()) {
-      get_map_xy(LOWORD(lParam), HIWORD(lParam), &xtile, &ytile);
+    if (can_client_change_view()
+        && canvas_to_map_pos(&xtile, &ytile, LOWORD(lParam), HIWORD(lParam))) {
       popit(LOWORD(lParam), HIWORD(lParam), xtile, ytile);
     }
     break;
   case WM_RBUTTONDOWN:
     if (can_client_change_view()) {
-      get_map_xy(LOWORD(lParam),HIWORD(lParam),&xtile,&ytile);
+      bool is_real =
+        canvas_to_map_pos(&xtile, &ytile, LOWORD(lParam), HIWORD(lParam));
       if (wParam&MK_CONTROL) {
-       popit(LOWORD(lParam),HIWORD(lParam),xtile,ytile);       
+        if (is_real) {
+          popit(LOWORD(lParam), HIWORD(lParam), xtile, ytile);
+        }
       } else {
-       center_tile_mapcanvas(xtile,ytile);
+        if (!is_real) {
+          nearest_real_pos(&xtile, &ytile);
+        }
+        center_tile_mapcanvas(xtile, ytile);
       }
     }
     break;
Index: client/gui-win32/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.h,v
retrieving revision 1.9
diff -u -r1.9 mapview.h
--- client/gui-win32/mapview.h  2003/04/01 16:48:33     1.9
+++ client/gui-win32/mapview.h  2003/04/02 03:23:51
@@ -39,8 +39,6 @@
 #define map_view_height mapview_canvas.tile_height
 
 /* Use of these wrapper functions is deprecated. */
-#define get_map_xy(canvas_x, canvas_y, map_x, map_y) \
-  canvas_to_map_pos(map_x, map_y, canvas_x, canvas_y)
 #define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
   map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
 
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.64
diff -u -r1.64 mapctrl.c
--- client/gui-xaw/mapctrl.c    2003/02/17 22:49:27     1.64
+++ client/gui-xaw/mapctrl.c    2003/04/02 03:23:51
@@ -264,7 +264,9 @@
     return;
   }
 
-  get_map_xy(ev->x, ev->y, &x, &y);
+  if (!canvas_to_map_pos(&x, &y, ev->x, ev->y)) {
+    nearest_real_pos(&x, &y);
+  }
 
   if (ev->button==Button1)
     do_map_click(x, y);
Index: client/gui-xaw/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.h,v
retrieving revision 1.16
diff -u -r1.16 mapview.h
--- client/gui-xaw/mapview.h    2003/04/01 16:48:33     1.16
+++ client/gui-xaw/mapview.h    2003/04/02 03:23:51
@@ -57,8 +57,6 @@
 #define map_canvas_store_theight mapview_canvas.tile_height
 
 /* Use of these wrapper functions is deprecated. */
-#define get_map_xy(canvas_x, canvas_y, map_x, map_y) \
-  canvas_to_map_pos(map_x, map_y, canvas_x, canvas_y)
 #define get_canvas_xy(map_x, map_y, canvas_x, canvas_y) \
   map_to_canvas_pos(canvas_x, canvas_y, map_x, map_y)
 
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.136
diff -u -r1.136 map.c
--- common/map.c        2003/02/20 09:45:21     1.136
+++ common/map.c        2003/04/02 03:23:52
@@ -1314,16 +1314,21 @@
 }
 
 /**************************************************************************
-Normalizes the map position. Returns TRUE if it is real, FALSE otherwise.
+  If the map position is real, it is normalized and TRUE is returned.
+  If it is unreal, it is left unchanged and FALSE is returned.
 **************************************************************************/
 bool normalize_map_pos(int *x, int *y)
 {
+  if (*y < 0 || *y >= map.ysize) {
+    return FALSE;
+  }
+
   while (*x < 0)
     *x += map.xsize;
   while (*x >= map.xsize)
     *x -= map.xsize;
 
-  return (0 <= *y && *y < map.ysize);
+  return TRUE;
 }
 
 /**************************************************************************

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