Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2003:
[Freeciv-Dev] (PR#6949) Keyboardless Goto
Home

[Freeciv-Dev] (PR#6949) Keyboardless Goto

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#6949) Keyboardless Goto
From: "Arnstein Lindgard" <a-l@xxxxxxx>
Date: Tue, 25 Nov 2003 09:33:00 -0800
Reply-to: rt@xxxxxxxxxxx

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

Feature: Local option "Keyboardless Goto". Gtk[12].
Dependency: PR#6948 Quickselect unit.

Normal way:
- Select unit.
- Press "G".
- Click on destination.

New way:
- Click on unit.
- Release mouse button on destination.

Combining the feature from PR#6948, it is also possible to "<control>
left/right click" on a stack or a city, and launch the goto when you
release the left/right button.

When you already have the unit in focus:
- Depress left mouse button on an empty tile.
- Release left mouse button on destination tile.

This is similar to Civ3.

Note that the goto hover state is only activated if the mouse pointer
moves beyond the tile you clicked and the mouse button is still down,
to avoid mouse typos.


Arnstein


diff -ruN -Xdiff_ignore quickselect/client/control.c 
keyboardless_goto/client/control.c
--- quickselect/client/control.c        Mon Nov 24 23:54:27 2003
+++ keyboardless_goto/client/control.c  Tue Nov 25 07:26:28 2003
@@ -1305,6 +1305,7 @@
   struct city *pcity = map_get_city(xtile, ytile);
   struct tile *ptile = map_get_tile(xtile, ytile);
   struct unit *punit = player_find_unit_by_id(game.player_ptr, hover_unit);
+  bool maybe_goto = FALSE;
 
   if (punit && hover_state != HOVER_NONE) {
     switch (hover_state) {
@@ -1336,37 +1337,38 @@
     }
     set_hover_state(NULL, HOVER_NONE);
     update_unit_info_label(punit);
-    return;
   }
 
-  /* Bypass stack popup if quickselect is specified. */
-  if (qtype) {
+  /* Bypass stack or city popup if quickselect is specified. */
+  else if (qtype) {
     struct unit *qunit = quickselect(ptile, qtype);
     if (qunit) {
       set_unit_focus_and_select(qunit);
+      maybe_goto = keyboardless_goto;
     }
-    return;
   }
-
   /* Otherwise use popups. */
-
-  if (pcity && game.player_idx==pcity->owner) {
+  else if (pcity && game.player_idx==pcity->owner) {
     popup_city_dialog(pcity, FALSE);
-    return;
   }
-  
-  if (unit_list_size(&ptile->units) == 1
+  else if (unit_list_size(&ptile->units) == 0 && !pcity
+           && punit_focus) {
+    maybe_goto = keyboardless_goto;
+  }
+  else if (unit_list_size(&ptile->units) == 1
       && !unit_list_get(&ptile->units, 0)->occupy) {
     struct unit *punit=unit_list_get(&ptile->units, 0);
     if(game.player_idx==punit->owner) {
       if(can_unit_do_activity(punit, ACTIVITY_IDLE)) {
+        maybe_goto = keyboardless_goto;
        set_unit_focus_and_select(punit);
       }
     } else if (pcity) {
       /* Don't hide the unit in the city. */
       popup_unit_select_dialog(ptile);
     }
-  } else if(unit_list_size(&ptile->units) > 0) {
+  }
+  else if(unit_list_size(&ptile->units) > 0) {
     /* The stack list is always popped up, even if it includes enemy units.
      * If the server doesn't want the player to know about them it shouldn't
      * tell him!  The previous behavior would only pop up the stack if you
@@ -1375,6 +1377,12 @@
      * the tile (inconsistent). */
     popup_unit_select_dialog(ptile);
   }
+
+  /* See mapctrl_common.c */
+  keyboardless_goto_start_x = maybe_goto ? xtile : -1;
+  keyboardless_goto_start_y = maybe_goto ? ytile : -1;
+  keyboardless_goto_button_down = maybe_goto;
+  keyboardless_goto_active = FALSE;
 }
 
 /**************************************************************************
diff -ruN -Xdiff_ignore quickselect/client/gui-gtk/mapctrl.c 
keyboardless_goto/client/gui-gtk/mapctrl.c
--- quickselect/client/gui-gtk/mapctrl.c        Mon Nov 24 21:58:33 2003
+++ keyboardless_goto/client/gui-gtk/mapctrl.c  Tue Nov 25 06:49:13 2003
@@ -187,11 +187,15 @@
 }
 
 /**************************************************************************
- Handle 'Right Mouse Button released'.
+ Handle 'Mouse button released'. Because of the quickselect feature,
+ the release of both left and right mousebutton can launch the goto.
 **************************************************************************/
 gint butt_release_mapcanvas(GtkWidget *w, GdkEventButton *ev)
 {
-  if(ev->button == 3 && (rbutton_down || hover_state != HOVER_NONE))  {
+  if (ev->button == 1 || ev->button == 3) {
+    release_goto_button(ev->x, ev->y);
+  }
+  if (ev->button == 3 && (rbutton_down || hover_state != HOVER_NONE))  {
     release_right_button(ev->x, ev->y);
   }
 
@@ -339,6 +343,9 @@
 {
   update_line(event->x, event->y);
   update_rect_at_mouse_pos();
+  if (keyboardless_goto_button_down && hover_state == HOVER_NONE) {
+    maybe_activate_keyboardless_goto(event->x, event->y);
+  }
   return TRUE;
 }
 
diff -ruN -Xdiff_ignore quickselect/client/gui-gtk-2.0/mapctrl.c 
keyboardless_goto/client/gui-gtk-2.0/mapctrl.c
--- quickselect/client/gui-gtk-2.0/mapctrl.c    Mon Nov 24 23:11:01 2003
+++ keyboardless_goto/client/gui-gtk-2.0/mapctrl.c      Tue Nov 25 06:39:37 2003
@@ -167,10 +167,14 @@
 }
 
 /**************************************************************************
- Handle 'Right Mouse Button released'.
+ Handle 'Mouse button released'. Because of the quickselect feature,
+ the release of both left and right mousebutton can launch the goto.
 **************************************************************************/
 gboolean butt_release_mapcanvas(GtkWidget *w, GdkEventButton *ev, gpointer 
data)
 {
+  if (ev->button == 1 || ev->button == 3) {
+    release_goto_button(ev->x, ev->y);
+  }
   if(ev->button == 3 && (rbutton_down || hover_state != HOVER_NONE))  {
     release_right_button(ev->x, ev->y);
   }
@@ -320,6 +324,10 @@
 {
   update_line(ev->x, ev->y);
   update_rect_at_mouse_pos();
+  if (keyboardless_goto_button_down && keyboardless_goto &&
+      hover_state == HOVER_NONE) {
+    maybe_activate_keyboardless_goto(event->x, event->y);
+  }
   return TRUE;
 }
 
diff -ruN -Xdiff_ignore quickselect/client/mapctrl_common.c 
keyboardless_goto/client/mapctrl_common.c
--- quickselect/client/mapctrl_common.c Mon Nov 24 21:54:11 2003
+++ keyboardless_goto/client/mapctrl_common.c   Tue Nov 25 05:56:49 2003
@@ -54,6 +54,12 @@
 static int clipboard = -1;
 static bool clipboard_is_unit;
 
+/* Goto with drag and drop. */
+bool keyboardless_goto_button_down = FALSE;
+bool keyboardless_goto_active = FALSE;
+int keyboardless_goto_start_x = -1,
+    keyboardless_goto_start_y = -1;
+
 /* Update the workers for a city on the map, when the update is received */
 struct city *city_workers_display = NULL;
 
@@ -383,6 +389,44 @@
   }
 }
 
+/**************************************************************************
+...
+**************************************************************************/
+void release_goto_button(int canvas_x, int canvas_y)
+{
+  int tile_x, tile_y;
+
+  if (keyboardless_goto_active && hover_state == HOVER_GOTO &&
+      canvas_to_map_pos(&tile_x, &tile_y, canvas_x, canvas_y)) {
+    struct unit *punit =
+        player_find_unit_by_id(game.player_ptr, hover_unit);
+    do_unit_goto(tile_x, tile_y);
+    set_hover_state(NULL, HOVER_NONE);
+    update_unit_info_label(punit);
+  }
+  keyboardless_goto_active = FALSE;
+  keyboardless_goto_button_down = FALSE;
+  keyboardless_goto_start_x = keyboardless_goto_start_y = -1;
+}
+
+/**************************************************************************
+ The goto hover state is only activated when the mouse pointer moves
+ beyond the tile where the button was depressed, to avoid mouse typos.
+**************************************************************************/
+void maybe_activate_keyboardless_goto(int canvas_x, int canvas_y)
+{
+  int tile_x, tile_y;
+
+  if (get_unit_in_focus() &&
+      canvas_to_map_pos(&tile_x, &tile_y, canvas_x, canvas_y) &&
+      !same_pos(keyboardless_goto_start_x,
+                keyboardless_goto_start_y,
+                tile_x, tile_y)) {
+    keyboardless_goto_active = TRUE;
+    request_unit_goto();
+  }
+}
+
 /**************************************************************************
  Return TRUE iff the turn done button is enabled.
 **************************************************************************/
diff -ruN -Xdiff_ignore quickselect/client/mapctrl_common.h 
keyboardless_goto/client/mapctrl_common.h
--- quickselect/client/mapctrl_common.h Mon Nov 24 22:36:26 2003
+++ keyboardless_goto/client/mapctrl_common.h   Tue Nov 25 04:51:18 2003
@@ -23,6 +23,10 @@
 extern bool rectangle_active;
 extern bool tiles_hilited_cities;
 
+extern bool keyboardless_goto_button_down;
+extern bool keyboardless_goto_active;
+extern int keyboardless_goto_start_x, keyboardless_goto_start_y;
+
 void anchor_selection_rectangle(int canvas_x, int canvas_y);
 void update_selection_rectangle(int canvas_x, int canvas_y);
 
@@ -34,6 +38,10 @@
 void upgrade_canvas_clipboard(void);
 
 void release_right_button(int canvas_x, int canvas_y);
+
+void release_goto_button(int canvas_x, int canvas_y);
+void maybe_activate_keyboardless_goto(int canvas_x, int canvas_y);
+
 bool get_turn_done_button_state(void);
 void scroll_mapview(enum direction8 gui_dir);
 void action_button_pressed(int canvas_x, int canvas_y,
diff -ruN -Xdiff_ignore quickselect/client/options.c 
keyboardless_goto/client/options.c
--- quickselect/client/options.c        Fri Nov 14 09:28:42 2003
+++ keyboardless_goto/client/options.c  Tue Nov 25 06:24:59 2003
@@ -72,6 +72,7 @@
 bool dialogs_on_top = TRUE;
 bool ask_city_name = TRUE;
 bool popup_new_cities = TRUE;
+bool keyboardless_goto = TRUE;
 
 /* This option is currently set by the client - not by the user. */
 bool update_city_text_in_refresh_tile = TRUE;
@@ -120,6 +121,7 @@
   GEN_BOOL_OPTION(auto_turn_done,           N_("End Turn when done moving")),
   GEN_BOOL_OPTION(meta_accelerators,        N_("Use Alt/Meta for accelerators 
(GTK+ only)")),
   GEN_BOOL_OPTION(map_scrollbars,          N_("Show Map Scrollbars (GTK+ 
only)")),
+  GEN_BOOL_OPTION(keyboardless_goto,        N_("Keyboardless goto (GTK+ 
only)")),
   GEN_BOOL_OPTION(dialogs_on_top,          N_("Keep dialogs on top (GTK+ 2.0 
only)")),
   GEN_BOOL_OPTION(ask_city_name,            N_("Prompt for city names")),
   GEN_BOOL_OPTION(popup_new_cities,         N_("Pop up city dialog for new 
cities")),
diff -ruN -Xdiff_ignore quickselect/client/options.h 
keyboardless_goto/client/options.h
--- quickselect/client/options.h        Wed Jul 23 15:46:01 2003
+++ keyboardless_goto/client/options.h  Tue Nov 25 03:33:35 2003
@@ -46,6 +46,7 @@
 extern bool ask_city_name;
 extern bool popup_new_cities;
 extern bool update_city_text_in_refresh_tile;
+extern bool keyboardless_goto;
 
 enum client_option_type {
   COT_BOOL,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#6949) Keyboardless Goto, Arnstein Lindgard <=