[Freeciv-Dev] Re: (PR#3726) Scroll map witth arrow keys
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
a-l@xxxxxxx wrote:
> 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.
Here's a slightly changed patch:
- scroll_map renamed to scroll_mapview.
- use can_client_change_view() to determine if the command is valid.
- Don't call get_center_tile_mapcanvas; this is unnecessary.
- Rename 'dir' parameter as gui_dir.
- Add a comment to the function.
There are three problems:
- Ross would say this is a misuse of DIR_DX/DIR_DY. And he'd be right.
- Ross would say this is a use of enum direction8, although I disagree
on this.
- Because of PR#2412 the scrolling does not work quite the way it should
(which is a reason to fix 2412).
I do think this function provides a nice framework for future work on
auto-scrolling. For instance gui-sdl in fullscreen mode should
(optionally) scroll the mapview when the mouse reaches the border - with
varying speed and range (which is not yet implemented).
jason
Index: client/mapctrl_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.c,v
retrieving revision 1.5
diff -u -r1.5 mapctrl_common.c
--- client/mapctrl_common.c 2003/01/09 19:21:17 1.5
+++ client/mapctrl_common.c 2003/03/15 00:27:39
@@ -43,6 +43,26 @@
}
/**************************************************************************
+ Scroll the mapview half a screen in the given direction. This is a GUI
+ direction; i.e., DIR8_NORTH is "up" on the mapview.
+**************************************************************************/
+void scroll_mapview(enum direction8 gui_dir)
+{
+ int map_x, map_y, canvas_x, canvas_y;
+
+ if (!can_client_change_view()) {
+ return;
+ }
+
+ canvas_x = mapview_canvas.width / 2;
+ canvas_y = mapview_canvas.height / 2;
+ canvas_x += DIR_DX[gui_dir] * mapview_canvas.width / 2;
+ canvas_y += DIR_DY[gui_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()
Index: client/mapctrl_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapctrl_common.h,v
retrieving revision 1.2
diff -u -r1.2 mapctrl_common.h
--- client/mapctrl_common.h 2003/01/09 19:21:17 1.2
+++ client/mapctrl_common.h 2003/03/15 00:27:39
@@ -17,6 +17,7 @@
#include "shared.h" /* bool type */
bool get_turn_done_button_state(void);
+void scroll_mapview(enum direction8 gui_dir);
void update_turn_done_button_state(void);
void update_line(int canvas_x, int canvas_y);
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.130
diff -u -r1.130 gui_main.c
--- client/gui-gtk/gui_main.c 2003/02/26 19:00:36 1.130
+++ client/gui-gtk/gui_main.c 2003/03/15 00:27:40
@@ -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:
@@ -301,6 +297,22 @@
case GDK_KP_7:
key_unit_move(DIR8_NORTHWEST);
break;
+
+ case GDK_Left:
+ scroll_mapview(DIR8_WEST);
+ break;
+
+ case GDK_Right:
+ scroll_mapview(DIR8_EAST);
+ break;
+
+ case GDK_Up:
+ scroll_mapview(DIR8_NORTH);
+ break;
+
+ case GDK_Down:
+ scroll_mapview(DIR8_SOUTH);
+ break;
case GDK_KP_Begin:
case GDK_Return:
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.46
diff -u -r1.46 gui_main.c
--- client/gui-gtk-2.0/gui_main.c 2003/03/02 17:43:16 1.46
+++ client/gui-gtk-2.0/gui_main.c 2003/03/15 00:27:40
@@ -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:
@@ -425,6 +421,22 @@
case GDK_KP_7:
key_unit_move(DIR8_NORTHWEST);
break;
+
+ case GDK_Left:
+ scroll_mapview(DIR8_WEST);
+ break;
+
+ case GDK_Right:
+ scroll_mapview(DIR8_EAST);
+ break;
+
+ case GDK_Up:
+ scroll_mapview(DIR8_NORTH);
+ break;
+
+ case GDK_Down:
+ scroll_mapview(DIR8_SOUTH);
+ break;
case GDK_KP_Begin:
case GDK_Return:
- [Freeciv-Dev] (PR#3529) Map Control patch, Jason Short, 2003/03/02
- Message not available
- Message not available
- [Freeciv-Dev] Re: (PR#3727) Rectangular selection with right-click-and-drag, a-l@xxxxxxx, 2003/03/20
- Message not available
- [Freeciv-Dev] Re: (PR#3727) Rectangular selection with right-click-and-drag, Jason Short, 2003/03/20
- Message not available
- [Freeciv-Dev] Re: (PR#3727) Rectangular selection with right-click-and-drag, rwetmore@xxxxxxxxxxxx, 2003/03/21
- Message not available
- [Freeciv-Dev] Re: (PR#3727) Rectangular selection with right-click-and-drag, a-l@xxxxxxx, 2003/03/23
- Message not available
- [Freeciv-Dev] Re: (PR#3727) Rectangular selection with right-click-and-drag, Jason Short, 2003/03/23
|
|