Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2003:
[Freeciv-Dev] (PR#3726) Scroll map witth arrow keys
Home

[Freeciv-Dev] (PR#3726) Scroll map witth arrow keys

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3726) Scroll map witth arrow keys
From: "a-l@xxxxxxx" <a-l@xxxxxxx>
Date: Thu, 13 Mar 2003 17:46:29 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Parent: (PR#3529) Map Control patch

On Sun, 2 Mar 2003 01:41:50 -0800
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:

> One of the small features is the keyboard map scrolling.  A few thoughts
> on that:

> Seems like this would be more easily done in pixel coordinates. 
> Something like:
> 
>   get_center_tile_mapcanvas(&map_x, &map_y);
>   map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y);
>   canvas_x += DIR_DX[dir] * mapview_canvas.width / 2;
>   canvas_y += DIR_DY[dir] * mapview_canvas.height / 2;
>   canvas_to_map_pos(&map_x, &map_y, canvas_x, canvas_y);
>   center_tile_mapcanvas(map_x, map_y);

That was very elegant. New standalone patch, for GTK1 and GTK2.


Arnstein


diff -ruN -Xdiff_ignore cvs/client/gui-gtk/gui_main.c 
Scroll/client/gui-gtk/gui_main.c
--- cvs/client/gui-gtk/gui_main.c       Fri Feb 28 12:52:16 2003
+++ Scroll/client/gui-gtk/gui_main.c    Sun Mar  9 17:29:48 2003
@@ -246,7 +246,6 @@
 
   if (!client_is_observer()) {
     switch (ev->keyval) {
-      case GDK_Up:
       case GDK_KP_Up:
       case GDK_8:
       case GDK_KP_8:
@@ -260,7 +259,6 @@
        key_unit_move(DIR8_NORTHEAST);
        break;
 
-      case GDK_Right:
       case GDK_KP_Right:
       case GDK_6:
       case GDK_KP_6:
@@ -274,7 +272,6 @@
        key_unit_move(DIR8_SOUTHEAST);
        break;
 
-      case GDK_Down:
       case GDK_KP_Down:
       case GDK_2:
       case GDK_KP_2:
@@ -288,7 +285,6 @@
        key_unit_move(DIR8_SOUTHWEST);
        break;
 
-      case GDK_Left:
       case GDK_KP_Left:
       case GDK_4:
       case GDK_KP_4:
@@ -302,6 +298,22 @@
        key_unit_move(DIR8_NORTHWEST);
        break;
 
+      case GDK_Left:
+        scroll_map(DIR8_WEST);
+        break;
+
+      case GDK_Right:
+        scroll_map(DIR8_EAST);
+        break;
+
+      case GDK_Up:
+        scroll_map(DIR8_NORTH);
+        break;
+
+      case GDK_Down:
+        scroll_map(DIR8_SOUTH);
+        break;
+
       case GDK_KP_Begin:
       case GDK_Return:
       case GDK_KP_Enter:
diff -ruN -Xdiff_ignore cvs/client/gui-gtk-2.0/gui_main.c 
Scroll/client/gui-gtk-2.0/gui_main.c
--- cvs/client/gui-gtk-2.0/gui_main.c   Fri Mar  7 12:16:16 2003
+++ Scroll/client/gui-gtk-2.0/gui_main.c        Sun Mar  9 20:06:14 2003
@@ -370,7 +370,6 @@
 
   if (!client_is_observer()) {
     switch (ev->keyval) {
-      case GDK_Up:
       case GDK_KP_Up:
       case GDK_8:
       case GDK_KP_8:
@@ -384,7 +383,6 @@
        key_unit_move(DIR8_NORTHEAST);
        break;
 
-      case GDK_Right:
       case GDK_KP_Right:
       case GDK_6:
       case GDK_KP_6:
@@ -398,7 +396,6 @@
        key_unit_move(DIR8_SOUTHEAST);
        break;
 
-      case GDK_Down:
       case GDK_KP_Down:
       case GDK_2:
       case GDK_KP_2:
@@ -412,7 +409,6 @@
        key_unit_move(DIR8_SOUTHWEST);
        break;
 
-      case GDK_Left:
       case GDK_KP_Left:
       case GDK_4:
       case GDK_KP_4:
@@ -426,6 +422,22 @@
        key_unit_move(DIR8_NORTHWEST);
        break;
 
+      case GDK_Left:
+        scroll_map(DIR8_WEST);
+        break;
+
+      case GDK_Right:
+        scroll_map(DIR8_EAST);
+        break;
+
+      case GDK_Up:
+        scroll_map(DIR8_NORTH);
+        break;
+
+      case GDK_Down:
+        scroll_map(DIR8_SOUTH);
+        break;
+
       case GDK_KP_Begin:
       case GDK_Return:
       case GDK_KP_Enter:
diff -ruN -Xdiff_ignore cvs/client/mapctrl_common.c 
Scroll/client/mapctrl_common.c
--- cvs/client/mapctrl_common.c Fri Jan 10 05:56:34 2003
+++ Scroll/client/mapctrl_common.c      Sun Mar  9 18:05:06 2003
@@ -43,6 +43,25 @@
 }
 
 /**************************************************************************
+...
+**************************************************************************/
+void scroll_map(enum direction8 dir)
+{
+  int map_x, map_y, canvas_x, canvas_y;
+
+  if (get_client_state() < CLIENT_GAME_RUNNING_STATE) {
+    return;
+  }
+
+  get_center_tile_mapcanvas(&map_x, &map_y);
+  get_canvas_xy(map_x, map_y, &canvas_x, &canvas_y);
+  canvas_x += DIR_DX[dir] * mapview_canvas.width / 2;
+  canvas_y += DIR_DY[dir] * mapview_canvas.height / 2;
+  get_map_xy(canvas_x, canvas_y, &map_x, &map_y);
+  center_tile_mapcanvas(map_x, map_y);
+}
+
+/**************************************************************************
  Update the turn done button state.
 **************************************************************************/
 void update_turn_done_button_state()
diff -ruN -Xdiff_ignore cvs/client/mapctrl_common.h 
Scroll/client/mapctrl_common.h
--- cvs/client/mapctrl_common.h Fri Jan 10 05:56:34 2003
+++ Scroll/client/mapctrl_common.h      Sun Mar  9 17:47:04 2003
@@ -17,6 +17,7 @@
 #include "shared.h"            /* bool type */
 
 bool get_turn_done_button_state(void);
+void scroll_map(enum direction8 dir);
 void update_turn_done_button_state(void);
 void update_line(int canvas_x, int canvas_y);
 

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