Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] (PR#3966) add action_button_pressed function to mapctrl_co
Home

[Freeciv-Dev] (PR#3966) add action_button_pressed function to mapctrl_co

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3966) add action_button_pressed function to mapctrl_common
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Apr 2003 14:20:20 -0700
Reply-to: rt@xxxxxxxxxxxxxx

The attached patch adds a new function, action_button_pressed, to
mapctrl_common.  This is a wrapper for do_map_click that takes canvas
coordinates.  It is called by the GUI code.

The advantage of adding this function is that it allows the logic of the
GUI code to be simplified.  It is safer to call this function than to
have each GUI do the handling independently.  It can also potentially
give a more consistent interface.

After this patch, a slight cleanup to popit will allow
butt_down_mapcanvas (or whatever they're called in the different GUIs)
to get rid of all game logic.

jason

Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.12
diff -u -r1.12 mapctrl_common.c
--- client/mapctrl_common.c     2003/04/09 03:48:48     1.12
+++ client/mapctrl_common.c     2003/04/09 21:14:43
@@ -71,6 +71,24 @@
 }
 
 /**************************************************************************
+  Do some appropriate action when the "main" mouse button (usually
+  left-click) is pressed.  For more sophisticated user control use (or
+  write) a different xxx_button_pressed function.
+**************************************************************************/
+void action_button_pressed(int canvas_x, int canvas_y)
+{
+  int map_x, map_y;
+
+  if (can_client_change_view()) {
+    /* FIXME: Some actions here will need to check can_client_issue_orders.
+     * But all we can check is the lowest common requirement. */
+    if (canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
+      do_map_click(map_x, map_y);
+    }
+  }
+}
+
+/**************************************************************************
   Wakeup sentried units on the tile of the specified location.  Usually
   this is done with SHIFT+left-click.
 **************************************************************************/
Index: client/mapctrl_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.h,v
retrieving revision 1.7
diff -u -r1.7 mapctrl_common.h
--- client/mapctrl_common.h     2003/04/09 03:48:48     1.7
+++ client/mapctrl_common.h     2003/04/09 21:14:43
@@ -19,6 +19,7 @@
 
 bool get_turn_done_button_state(void);
 void scroll_mapview(enum direction8 gui_dir);
+void action_button_pressed(int canvas_x, int canvas_y);
 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);
Index: client/gui-gtk/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v
retrieving revision 1.82
diff -u -r1.82 mapctrl.c
--- client/gui-gtk/mapctrl.c    2003/04/09 20:47:43     1.82
+++ client/gui-gtk/mapctrl.c    2003/04/09 21:14:46
@@ -309,28 +309,24 @@
 gint butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev)
 {
   int xtile, ytile;
-  bool is_real;
 
   if (!can_client_change_view()) {
     return TRUE;
   }
 
+  gtk_widget_grab_focus(turn_done_button);
+
   if (ev->button == 1 && (ev->state & GDK_SHIFT_MASK)) {
     adjust_workers_button_pressed(ev->x, ev->y);
-    return TRUE;
-  }
-
-  is_real = canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y);
-
-  if (is_real && ev->button == 1) {
-    do_map_click(xtile, ytile);
-    gtk_widget_grab_focus(turn_done_button);
-  } else if (is_real
+  } else if (ev->button == 1) {
+    action_button_pressed(ev->x, ev->y);
+  } else if (canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y)
             && (ev->button == 2 || (ev->state & GDK_CONTROL_MASK))) {
     popit(ev, xtile, ytile);
   } else if (ev->button == 3) {
     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.22
diff -u -r1.22 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        2003/04/09 20:47:44     1.22
+++ client/gui-gtk-2.0/mapctrl.c        2003/04/09 21:14:46
@@ -301,28 +301,24 @@
 gboolean butt_down_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer data)
 {
   int xtile, ytile;
-  bool is_real;
 
   if (!can_client_change_view()) {
     return TRUE;
   }
 
+  gtk_widget_grab_focus(map_canvas);
+
   if (ev->button == 1 && (ev->state & GDK_SHIFT_MASK)) {
     adjust_workers_button_pressed(ev->x, ev->y);
-    return TRUE;
-  }
-
-  is_real = canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y);
-
-  if (is_real && ev->button == 1) {
-    do_map_click(xtile, ytile);
-    gtk_widget_grab_focus(map_canvas);
-  } else if (is_real
+  } else if (ev->button == 1) {
+    action_button_pressed(ev->x, ev->y);
+  } else if (canvas_to_map_pos(&xtile, &ytile, ev->x, ev->y)
             && (ev->button == 2 || (ev->state & GDK_CONTROL_MASK))) {
     popit(ev, xtile, ytile);
   } else if (ev->button == 3) {
     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.17
diff -u -r1.17 mapctrl.c
--- client/gui-sdl/mapctrl.c    2003/04/09 03:48:48     1.17
+++ client/gui-sdl/mapctrl.c    2003/04/09 21:14:51
@@ -771,7 +771,6 @@
 void button_down_on_map(SDL_MouseButtonEvent * pButtonEvent)
 {
   int col, row;
-  bool is_real;
 
   if (get_client_state() != CLIENT_GAME_RUNNING_STATE) {
     return;
@@ -784,17 +783,14 @@
   }
 #endif
   
-  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) {
-    if (is_real) {
-      do_map_click(col, row);
-    }
+    action_button_pressed(pButtonEvent->x, pButtonEvent->y);
   } else {
     if (pButtonEvent->button == SDL_BUTTON_MIDDLE) {
-      if (is_real) {
+      if (canvas_to_map_pos(&col, &row,
+                           (int) pButtonEvent->x, (int) pButtonEvent->y)) {
         popup_advanced_terrain_dialog(col, row);
       }
     } else {
Index: client/gui-win32/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapctrl.c,v
retrieving revision 1.25
diff -u -r1.25 mapctrl.c
--- client/gui-win32/mapctrl.c  2003/04/09 20:47:44     1.25
+++ client/gui-win32/mapctrl.c  2003/04/09 21:14:52
@@ -230,16 +230,15 @@
       break;
     }
     SetFocus(root_window);
-    if (!canvas_to_map_pos(&xtile, &ytile, LOWORD(lParam), HIWORD(lParam))) {
-      break;
-    }
     if (wParam&MK_SHIFT) {
       adjust_workers_button_pressed(LOWORD(lParam), HIWORD(lParam));
       wakeup_button_pressed(LOWORD(lParam), HIWORD(lParam));
-    } else if (wParam&MK_CONTROL){
+    } else if (wParam & MK_CONTROL
+              && canvas_to_map_pos(&xtile, &ytile,
+                                   LOWORD(lParam), HIWORD(lParam))) {
       popit(LOWORD(lParam),HIWORD(lParam),xtile,ytile);
     } else {
-      do_map_click(xtile,ytile);
+      action_button_pressed(LOWORD(lParam), HIWORD(lParam));
     }
     break;
   case WM_MBUTTONDOWN:
@@ -250,10 +249,9 @@
     break;
   case WM_RBUTTONDOWN:
     if (can_client_change_view()) {
-      bool is_real =
-        canvas_to_map_pos(&xtile, &ytile, LOWORD(lParam), HIWORD(lParam));
       if (wParam&MK_CONTROL) {
-        if (is_real) {
+        if (canvas_to_map_pos(&xtile, &ytile,
+                             LOWORD(lParam), HIWORD(lParam))) {
           popit(LOWORD(lParam), HIWORD(lParam), xtile, ytile);
         }
       } else {
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.70
diff -u -r1.70 mapctrl.c
--- client/gui-xaw/mapctrl.c    2003/04/09 20:47:44     1.70
+++ client/gui-xaw/mapctrl.c    2003/04/09 21:14:53
@@ -245,18 +245,15 @@
 {
   int x, y;
   XButtonEvent *ev=&event->xbutton;
-  bool is_real;
 
   if (!can_client_change_view()) {
     return;
   }
 
-  is_real = canvas_to_map_pos(&x, &y, ev->x, ev->y);
-
-  if (is_real && ev->button == Button1) {
-    do_map_click(x, y);
-  } else if (is_real &&
-            (ev->button == Button2 || ev->state & ControlMask)) {
+  if (ev->button == Button1) {
+    action_button_pressed(ev->x, ev->y);
+  } else if (canvas_to_map_pos(&x, &y, ev->x, ev->y)
+            && (ev->button == Button2 || ev->state & ControlMask)) {
     popit(ev->x, ev->y, x, y);
   } else if (ev->button == Button3) {
     recenter_button_pressed(ev->x, ev->y);

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