Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] (PR#3947) add recenter_button_pressed to mapctrl_common
Home

[Freeciv-Dev] (PR#3947) add recenter_button_pressed to mapctrl_common

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3947) add recenter_button_pressed to mapctrl_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 6 Apr 2003 23:10:14 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch continues the mini-cleanup of the mouse interface code by
adding a new function, recenter_button_pressed, to mapctrl_common.  The
function is called by the GUI code.

The main advantage is that it reduces the number of callers of
nearest_real_pos.  It also introduces extra safety by assuring that the
operation is correctly handled (i.e., makes sure can_client_change_view
is not forgotten - in a future patch the GUI code should not need to
check this at all).  Finally, it makes the possible introduction of a
center_pixel_mapcanvas function easier.

jason

? client/gui-gtk/output
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.11
diff -u -r1.11 mapctrl_common.c
--- client/mapctrl_common.c     2003/04/06 21:52:24     1.11
+++ client/mapctrl_common.c     2003/04/07 06:00:16
@@ -131,6 +131,22 @@
 }
 
 /**************************************************************************
+  Recenter the map on the canvas location, on user request.  Usually this
+  is done with a right-click.
+**************************************************************************/
+void recenter_button_pressed(int canvas_x, int canvas_y)
+{
+  int map_x, map_y;
+
+  if (can_client_change_view()) {
+    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);
+  }
+}
+
+/**************************************************************************
  Update the turn done button state.
 **************************************************************************/
 void update_turn_done_button_state()
Index: client/mapctrl_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.h,v
retrieving revision 1.6
diff -u -r1.6 mapctrl_common.h
--- client/mapctrl_common.h     2003/04/06 21:52:24     1.6
+++ client/mapctrl_common.h     2003/04/07 06:00:16
@@ -21,6 +21,7 @@
 void scroll_mapview(enum direction8 gui_dir);
 void wakeup_button_pressed(int canvas_x, int canvas_y);
 void adjust_workers_button_pressed(int canvas_x, int canvas_y);
+void recenter_button_pressed(int canvas_x, int canvas_y);
 void update_turn_done_button_state(void);
 void update_line(int canvas_x, int canvas_y);
 
Index: client/gui-gtk/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v
retrieving revision 1.80
diff -u -r1.80 mapctrl.c
--- client/gui-gtk/mapctrl.c    2003/04/06 21:52:24     1.80
+++ client/gui-gtk/mapctrl.c    2003/04/07 06:00:17
@@ -321,9 +321,6 @@
   }
 
   is_real = canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y);
-  if (!is_real) {
-    nearest_real_pos(&xtile, &ytile);
-  }
 
   if (is_real && ev->button == 1) {
     do_map_click(xtile, ytile);
@@ -332,7 +329,7 @@
             && (ev->button == 2 || (ev->state & GDK_CONTROL_MASK))) {
     popit(ev, xtile, ytile);
   } else if (ev->button == 3) {
-    center_tile_mapcanvas(xtile, ytile);
+    recenter_button_pressed(ev->x, ev->y);
   }
   return TRUE;
 }
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.20
diff -u -r1.20 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        2003/04/06 21:52:24     1.20
+++ client/gui-gtk-2.0/mapctrl.c        2003/04/07 06:00:17
@@ -313,9 +313,6 @@
   }
 
   is_real = canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y);
-  if (!is_real) {
-    nearest_real_pos(&xtile, &ytile);
-  }
 
   if (is_real && ev->button == 1) {
     do_map_click(xtile, ytile);
@@ -324,7 +321,7 @@
             && (ev->button == 2 || (ev->state & GDK_CONTROL_MASK))) {
     popit(ev, xtile, ytile);
   } else if (ev->button == 3) {
-    center_tile_mapcanvas(xtile, ytile);
+    recenter_button_pressed(ev->x, ev->y);
   }
   return TRUE;
 }
Index: client/gui-sdl/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapctrl.c,v
retrieving revision 1.16
diff -u -r1.16 mapctrl.c
--- client/gui-sdl/mapctrl.c    2003/04/06 21:52:24     1.16
+++ client/gui-sdl/mapctrl.c    2003/04/07 06:00:18
@@ -798,10 +798,7 @@
         popup_advanced_terrain_dialog(col, row);
       }
     } else {
-      if (!is_real) {
-        nearest_real_pos(&col, &row);
-      }
-      center_tile_mapcanvas(col, row);
+      recenter_button_pressed(pButtonEvent->x, pButtonEvent->y);
       flush_dirty();
     }
   }
Index: client/gui-win32/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapctrl.c,v
retrieving revision 1.23
diff -u -r1.23 mapctrl.c
--- client/gui-win32/mapctrl.c  2003/04/06 21:52:24     1.23
+++ client/gui-win32/mapctrl.c  2003/04/07 06:00:18
@@ -257,10 +257,7 @@
           popit(LOWORD(lParam), HIWORD(lParam), xtile, ytile);
         }
       } else {
-        if (!is_real) {
-          nearest_real_pos(&xtile, &ytile);
-        }
-        center_tile_mapcanvas(xtile, ytile);
+       recenter_button_pressed(LOWORD(lParam), HIWORD(lParam));
       }
     }
     break;
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.68
diff -u -r1.68 mapctrl.c
--- client/gui-xaw/mapctrl.c    2003/04/06 21:52:24     1.68
+++ client/gui-xaw/mapctrl.c    2003/04/07 06:00:18
@@ -245,21 +245,21 @@
 {
   int x, y;
   XButtonEvent *ev=&event->xbutton;
+  bool is_real;
 
   if (!can_client_change_view()) {
     return;
   }
 
-  if (!canvas_to_map_pos(&x, &y, ev->x, ev->y)) {
-    nearest_real_pos(&x, &y);
-  }
+  is_real = canvas_to_map_pos(&x, &y, ev->x, ev->y);
 
-  if (ev->button==Button1)
+  if (is_real && ev->button == Button1) {
     do_map_click(x, y);
-  else if (ev->button==Button2||ev->state&ControlMask)
+  } else if (is_real &&
+            (ev->button == Button2 || ev->state & ControlMask)) {
     popit(ev->x, ev->y, x, y);
-  else if (ev->button == Button3) {
-    center_tile_mapcanvas(x, y);
+  } else if (ev->button == Button3) {
+    recenter_button_pressed(ev->x, ev->y);
   }
 }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#3947) add recenter_button_pressed to mapctrl_common, Jason Short <=