Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9343) new client-common function key_city_overlay
Home

[Freeciv-Dev] (PR#9343) new client-common function key_city_overlay

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9343) new client-common function key_city_overlay
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 11 Jul 2004 21:12:44 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9343 >

This patch unifies the city overlay toggling operation that's present in 
gui-gtk, gui-gtk-2.0, and gui-xaw.  No doubt it will be helpful for 
other GUIs as well.

jason

Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.37
diff -u -r1.37 mapctrl_common.c
--- client/mapctrl_common.c     25 Jun 2004 23:35:55 -0000      1.37
+++ client/mapctrl_common.c     12 Jul 2004 04:08:30 -0000
@@ -305,6 +305,24 @@
 }
 
 /**************************************************************************
+  The user pressed the overlay-city button (t) while the mouse was at the
+  given canvas position.
+**************************************************************************/
+void key_city_overlay(int canvas_x, int canvas_y)
+{
+  int map_x, map_y;
+
+  if (can_client_change_view()
+      && canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y)) {
+    struct city *pcity = find_city_near_tile(map_x, map_y);
+
+    if (pcity) {
+      toggle_city_color(pcity);
+    }
+  }
+}
+
+/**************************************************************************
  Shift-Left-Click on owned city or any visible unit to copy.
 **************************************************************************/
 void clipboard_copy_production(int tile_x, int tile_y)
Index: client/mapctrl_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.h,v
retrieving revision 1.17
diff -u -r1.17 mapctrl_common.h
--- client/mapctrl_common.h     23 Apr 2004 22:58:05 -0000      1.17
+++ client/mapctrl_common.h     12 Jul 2004 04:08:30 -0000
@@ -35,6 +35,8 @@
 void cancel_tile_hiliting(void);
 void toggle_tile_hilite(int tile_x, int tile_y);
 
+void key_city_overlay(int canvas_x, int canvas_y);
+
 void clipboard_copy_production(int tile_x, int tile_y);
 void clipboard_paste_production(struct city *pcity);
 void upgrade_canvas_clipboard(void);
Index: client/gui-gtk/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapctrl.c,v
retrieving revision 1.98
diff -u -r1.98 mapctrl.c
--- client/gui-gtk/mapctrl.c    10 Jun 2004 01:04:53 -0000      1.98
+++ client/gui-gtk/mapctrl.c    12 Jul 2004 04:08:31 -0000
@@ -393,25 +393,8 @@
 **************************************************************************/
 void key_city_workers(GtkWidget *w, GdkEventKey *ev)
 {
-  int x,y;
-  struct city *pcity;
-
-  if (!can_client_change_view()) {
-    return;
-  }
+  int x, y;
   
   gdk_window_get_pointer(map_canvas->window, &x, &y, NULL);
-  if (!canvas_to_map_pos(&x, &y, x, y)) {
-    nearest_real_pos(&x, &y);
-  }
-
-  pcity = find_city_near_tile(x, y);
-  if (!pcity) {
-    return;
-  }
-
-  /* Shade tiles on usage */
-  toggle_city_color(pcity);
+  key_city_overlay(x, 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.40
diff -u -r1.40 mapctrl.c
--- client/gui-gtk-2.0/mapctrl.c        10 Jun 2004 01:04:53 -0000      1.40
+++ client/gui-gtk-2.0/mapctrl.c        12 Jul 2004 04:08:31 -0000
@@ -373,25 +373,8 @@
 **************************************************************************/
 void key_city_workers(GtkWidget *w, GdkEventKey *ev)
 {
-  int x,y;
-  struct city *pcity;
-
-  if (!can_client_change_view()) {
-    return;
-  }
+  int x, y;
   
   gdk_window_get_pointer(map_canvas->window, &x, &y, NULL);
-  if (!canvas_to_map_pos(&x, &y, x, y)) {
-    nearest_real_pos(&x, &y);
-  }
-
-  pcity = find_city_near_tile(x, y);
-  if (!pcity) {
-    return;
-  }
-
-  /* Shade tiles on usage */
-  toggle_city_color(pcity);
+  key_city_overlay(x, y);
 }
-
-
Index: client/gui-xaw/mapctrl.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapctrl.c,v
retrieving revision 1.85
diff -u -r1.85 mapctrl.c
--- client/gui-xaw/mapctrl.c    10 Jun 2004 01:04:53 -0000      1.85
+++ client/gui-xaw/mapctrl.c    12 Jul 2004 04:08:31 -0000
@@ -259,23 +259,7 @@
 **************************************************************************/
 void mapctrl_key_city_workers(XEvent *event)
 {
-  int x,y;
-  XButtonEvent *ev=&event->xbutton;
-  struct city *pcity;
-
-  if (!can_client_change_view()) {
-    return;
-  }
-
-  if (!canvas_to_map_pos(&x, &y, ev->x, ev->y)) {
-    return;
-  }
-
-  pcity = find_city_near_tile(x,y);
-  if(!pcity) return;
-
-  /* Shade tiles on usage */
-  toggle_city_color(pcity);
+  key_city_overlay(event->xbutton->x, event->xbutton->y);
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9343) new client-common function key_city_overlay, Jason Short <=