--- freeciv-1.11.10-dev/client/civclient.c.scrollbar Sun Aug 5 18:47:54 2001 +++ freeciv-1.11.10-dev/client/civclient.c Mon Aug 6 00:31:09 2001 @@ -145,9 +145,11 @@ } } else if ((option = get_option("--tiles",argv,&i,argc)) != NULL) { tile_set_name=option; - } else { - fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]); - exit(1); + } else { + if (! ui_valid_option(argv[i])) { + fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]); + exit(1); + } } i++; } /* of while */ --- freeciv-1.11.10-dev/client/gui-stub/gui_main.c.scrollbar Sun Jul 9 23:31:23 2000 +++ freeciv-1.11.10-dev/client/gui-stub/gui_main.c Mon Aug 6 00:44:01 2001 @@ -5,6 +5,12 @@ #include "gui_main.h" +int +ui_valid_option(char *arg) +{ + return (is_option("--help", arg)); +} + void ui_main(int argc, char *argv[]) { --- freeciv-1.11.10-dev/client/gui-gtk/gui_main.c.scrollbar Fri Aug 3 04:08:39 2001 +++ freeciv-1.11.10-dev/client/gui-gtk/gui_main.c Mon Aug 6 00:32:58 2001 @@ -145,9 +145,16 @@ static void print_usage(const char *argv0) { /* add client-specific usage information here */ + fprintf(stderr, _(" --use-scroll-buttons\tUse scroll buttons instead of scrollbars\n")); fprintf(stderr, _("Report bugs to <%s>.\n"), BUG_EMAIL_ADDRESS); } + +int ui_valid_option(char *arg) +{ + return (is_option("--use-scroll-buttons", arg) || is_option("--help", arg)); +} + /************************************************************************** ... **************************************************************************/ @@ -163,6 +170,9 @@ print_usage(argv[0]); exit(0); } + if (is_option("--use-scroll-buttons", argv[i])) { + using_scrollbars = 0; + } i += 1; } } @@ -363,11 +373,13 @@ GtkWidget *ahbox; GtkWidget *frame; + GtkWidget *map_scroll_button; GtkWidget *menubar; GtkWidget *table; GtkWidget *ebox, *paned; GtkStyle *text_style; int i; + gint *dir; paned = gtk_vpaned_new(); gtk_container_add(GTK_CONTAINER(toplevel), paned); @@ -545,14 +557,25 @@ gtk_table_attach_defaults(GTK_TABLE(table), more_arrow_pixmap, 4, 5, 1, 2); } - table = gtk_table_new( 2, 2, FALSE ); + if (using_scrollbars) { + table = gtk_table_new( 2, 2, FALSE ); + } else { + table = gtk_table_new( 3, 3, FALSE ); + } gtk_box_pack_start( GTK_BOX( hbox ), table, TRUE, TRUE, 0 ); frame = gtk_frame_new( NULL ); - gtk_table_attach(GTK_TABLE(table), frame, - 0, 1, 0, 1, - GTK_EXPAND|GTK_SHRINK|GTK_FILL, - GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 ); + if (using_scrollbars) { + gtk_table_attach(GTK_TABLE(table), frame, + 0, 1, 0, 1, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 ); + } else { + gtk_table_attach(GTK_TABLE(table), frame, + 1, 2, 1, 2, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0 ); + } map_canvas = gtk_drawing_area_new(); @@ -564,14 +587,113 @@ gtk_drawing_area_size(GTK_DRAWING_AREA(map_canvas), 510, 300); gtk_container_add(GTK_CONTAINER(frame), map_canvas); - map_horizontal_scrollbar = gtk_hscrollbar_new(NULL); - gtk_table_attach(GTK_TABLE(table), map_horizontal_scrollbar, 0, 1, 1, 2, - GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); + if (using_scrollbars) { + map_horizontal_scrollbar = gtk_hscrollbar_new(NULL); + gtk_table_attach(GTK_TABLE(table), map_horizontal_scrollbar, 0, 1, 1, 2, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); + + map_vertical_scrollbar = gtk_vscrollbar_new(NULL); + gtk_table_attach(GTK_TABLE(table), map_vertical_scrollbar, 1, 2, 0, 1, + 0, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0); + } - map_vertical_scrollbar = gtk_vscrollbar_new(NULL); - gtk_table_attach(GTK_TABLE(table), map_vertical_scrollbar, 1, 2, 0, 1, - 0, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0); + if (!using_scrollbars) { + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=1; + dir[1]=is_isometric?-1:0; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("N\no\nr\nt\nh\nE\na\ns\nt"):_("E\na\ns\nt")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 2, 3, 1, 2, + 0, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=is_isometric?1:0; + dir[1]=1; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("SouthEast"):_("South")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 1, 2, 2, 3, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=-1; + dir[1]=is_isometric?1:0; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("S\no\nu\nt\nh\nW\ne\ns\nt"):_("W\ne\ns\nt")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 0, 1, 1, 2, + 0, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=is_isometric?-1:0; + dir[1]=-1; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("NorthWest"):_("North")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 1, 2, 0, 1, + GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); + gtk_signal_connect(GTK_OBJECT( map_scroll_button ), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=is_isometric?0:1; + dir[1]=-1; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("N"):_("NE")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 2, 3, 0, 1, + GTK_SHRINK, GTK_SHRINK, 0, 0); + gtk_signal_connect(GTK_OBJECT( map_scroll_button ), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=is_isometric?0:-1; + dir[1]=1; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("S"):_("SW")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 0, 1, 2, 3, + GTK_SHRINK, GTK_SHRINK, 0, 0); + gtk_signal_connect(GTK_OBJECT( map_scroll_button ), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=-1; + dir[1]=is_isometric?0:-1; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("W"):_("NW")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 0, 1, 0, 1, + GTK_SHRINK, GTK_SHRINK, 0, 0); + gtk_signal_connect(GTK_OBJECT( map_scroll_button ), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + + dir=(gint*)malloc(2*sizeof(int)); + dir[0]=1; + dir[1]=is_isometric?0:1; + map_scroll_button=gtk_button_new_with_label(is_isometric?_("E"):_("SE")); + gtk_table_attach(GTK_TABLE(table), map_scroll_button, 2, 3, 2, 3, + GTK_SHRINK, GTK_SHRINK, 0, 0); + gtk_signal_connect(GTK_OBJECT( map_scroll_button ), "button_press_event", + GTK_SIGNAL_FUNC(map_scroll_push_callback), + (gpointer)dir); + gtk_signal_connect(GTK_OBJECT(map_scroll_button), "button_release_event", + GTK_SIGNAL_FUNC(map_scroll_release_callback),NULL); + } /* using_scrollbars */ /* Event signals */ gtk_signal_connect( GTK_OBJECT( map_canvas ), "expose_event", GTK_SIGNAL_FUNC( map_canvas_expose ), NULL ); @@ -607,7 +729,6 @@ text_style->text[GTK_STATE_INSENSITIVE]= text_style->text[GTK_STATE_NORMAL]; gtk_widget_set_style (text, text_style); - gtk_text_set_word_wrap(GTK_TEXT(text), 1); main_message_area = GTK_TEXT (text); --- freeciv-1.11.10-dev/client/gui-gtk/mapview.h.scrollbar Sun Feb 4 05:45:20 2001 +++ freeciv-1.11.10-dev/client/gui-gtk/mapview.h Sun Aug 5 19:00:18 2001 @@ -48,9 +48,19 @@ void scrollbar_jump_callback(GtkAdjustment *adj, gpointer hscrollbar); void update_map_canvas_scrollbars_size(void); + +void map_scroll_push_callback(GtkWidget* w, GtkAdjustment *adj, gpointer data); +void map_scroll_release_callback(GtkWidget* w,GtkAdjustment* adj,gpointer data); +gint map_scroll_timeout_handler(gpointer data); +gint adjust_scroll_speed(gpointer data); +void map_scroll(int n); + void get_map_xy(int canvas_x, int canvas_y, int *map_x, int *map_y); /* contains the x0, y0 coordinates of the upper left corner block */ extern int map_view_x0, map_view_y0; + +/* Use scrollbars? */ +extern int using_scrollbars; #endif /* FC__MAPVIEW_H */ --- freeciv-1.11.10-dev/client/gui-gtk/mapview.c.scrollbar Sat Jul 28 09:23:18 2001 +++ freeciv-1.11.10-dev/client/gui-gtk/mapview.c Sun Aug 5 18:58:27 2001 @@ -24,6 +24,8 @@ #include #include +#include + #include "fcintl.h" #include "game.h" #include "government.h" /* government_graphic() */ @@ -67,11 +69,39 @@ #define EXTRA_BOTTOM_ROW (is_isometric ? 6 : 1) /* contains the x0, y0 coordinates of the upper left corner block */ -int map_view_x0, map_view_y0; +int map_view_x0, map_view_y0, map_view_dx, map_view_dy; /* used by map_canvas expose func */ int force_full_repaint; +#define MAXSCROLLSPEED ((map.xsize + map.ysize)/6 + 1) +/* #define MAXSCROLLSPEED 50 */ +#define SCROLLTIMEINTERVALUPDATEINTERVAL 100 +#define INITIALSCROLLSPEED 5 +#define BUTTONDOWNPAUSE (1000/INITIALSCROLLSPEED) + +/* Whether or not we're using scrollbars. Referenced by gui_main.c as well */ +int using_scrollbars = 1; + +/* how much time to wait until we scroll again with the button down */ +int scroll_speed; + +/* used to store the timeout tag for button handling */ +gint button_timeout_tag = 0; + +/* used to store the timeout tag for interval adjustment */ +gint adjust_timeout_tag = 0; + +/* used to store how long it took to draw the last map update */ +gdouble map_update_time = 0.0; + +/* used to track which button press this is. Needed so that fast buttonpresses + * don't also activate the background scroll handler and scroll you more than + * you want. + */ +int buttonpress_instance = 0; +int buttonrelease_instance = 0; + /* T: area above the actual tile. M: the top of the actual tile. B: the bottom of the actual tile. @@ -142,7 +172,6 @@ static GtkObject *map_hadj, *map_vadj; - /************************************************************************** ... **************************************************************************/ @@ -1870,11 +1899,13 @@ last_pcity=pcity; } + /************************************************************************** ... **************************************************************************/ void update_map_canvas_scrollbars(void) { + if (!using_scrollbars) return; gtk_adjustment_set_value(GTK_ADJUSTMENT(map_hadj), map_view_x0); gtk_adjustment_set_value(GTK_ADJUSTMENT(map_vadj), map_view_y0); } @@ -1884,6 +1915,7 @@ **************************************************************************/ void update_map_canvas_scrollbars_size(void) { + if (!using_scrollbars) return; map_hadj=gtk_adjustment_new(-1, 0, map.xsize, 1, map_canvas_store_twidth, map_canvas_store_twidth); map_vadj=gtk_adjustment_new(-1, 0, map.ysize+EXTRA_BOTTOM_ROW, 1, @@ -1932,7 +1964,115 @@ } } + +/************************************************************************** +... +**************************************************************************/ +int map_scroll_start_continuous_scrolling(gpointer data) { + scroll_speed = (gint)data; + map_scroll_timeout_handler((gpointer)buttonpress_instance); + /* button_timeout_tag = gtk_timeout_add(1000/scroll_speed, + map_scroll_timeout_handler, (gpointer)buttonpress_instance); */ + adjust_timeout_tag = gtk_timeout_add(SCROLLTIMEINTERVALUPDATEINTERVAL, + adjust_scroll_speed, (gpointer)buttonpress_instance); + return FALSE; +} + +/************************************************************************** +... +**************************************************************************/ +void map_scroll_push_callback(GtkWidget* w, GtkAdjustment* adj, gpointer data){ + gint *dir=data; + if (buttonpress_instance > buttonrelease_instance) return; + buttonpress_instance++; + map_view_dx=dir[0]; + map_view_dy=dir[1]; + map_scroll(1); + if (button_timeout_tag > 0) gtk_timeout_remove(button_timeout_tag); + if (adjust_timeout_tag > 0) gtk_timeout_remove(adjust_timeout_tag); + map_update_time = 0.0; + button_timeout_tag = gtk_timeout_add(BUTTONDOWNPAUSE, + map_scroll_start_continuous_scrolling, + (gpointer)INITIALSCROLLSPEED); +} + +/************************************************************************** +... +**************************************************************************/ +void map_scroll_release_callback(GtkWidget* w, GtkAdjustment* adj, + gpointer data){ + map_view_dx=0; + map_view_dy=0; + buttonrelease_instance++; + if (button_timeout_tag > 0) gtk_timeout_remove(button_timeout_tag); + if (adjust_timeout_tag > 0) gtk_timeout_remove(adjust_timeout_tag); + button_timeout_tag = 0; + adjust_timeout_tag = 0; +} + +/************************************************************************** +... +**************************************************************************/ + +void map_scroll(int n) { + map_view_x0 += n * map_view_dx; + map_view_y0 += n * map_view_dy; + /* Be paranoid, in case abs(map_view_x0) > 2*map.xsize... */ + while (map_view_x0>map.xsize) + map_view_x0 -= map.xsize; + while (map_view_x0<0) + map_view_x0 += map.xsize; + if (map_view_y0>map.ysize+EXTRA_BOTTOM_ROW-map_canvas_store_theight) + map_view_y0=map.ysize+EXTRA_BOTTOM_ROW-map_canvas_store_theight; + if (map_view_y0<0) + map_view_y0=0; + update_map_canvas_visible(); + refresh_overview_viewrect(); + gdk_flush(); +} + +gint adjust_scroll_speed(gpointer data){ + if ((int)data != buttonpress_instance || (map_view_dx == 0 && + map_view_dy == 0)) return FALSE; + scroll_speed ++; + if (scroll_speed > MAXSCROLLSPEED) { + scroll_speed = MAXSCROLLSPEED; + return FALSE; + } + return TRUE; +} + +gint map_scroll_timeout_handler(gpointer data){ + static GTimer *timer = NULL; + gdouble interval; + gint timeout = 0; + static gint oldtimeout = 0; + static gdouble old_map_update_time = 0.0; + if ((int)data != buttonpress_instance || (map_view_dx == 0 && + map_view_dy == 0)) return FALSE; + if ( timer == NULL ) timer = g_timer_new(); + if ( button_timeout_tag == 0 ) oldtimeout = 0; + interval = 1.0 / scroll_speed; + g_timer_reset(timer); + g_timer_start(timer); + map_scroll(1 + (int)((old_map_update_time + map_update_time) / + (2.0*interval))); + g_timer_stop(timer); + old_map_update_time = map_update_time; + map_update_time = g_timer_elapsed(timer, NULL); + oldtimeout = timeout; + timeout = 1000/scroll_speed - (gint)map_update_time; + /* if (timeout < (1000/MAXSCROLLSPEED)) timeout = 1000/MAXSCROLLSPEED; */ + if (timeout < 1) timeout = 1; + if (timeout != oldtimeout) { + button_timeout_tag = gtk_timeout_add(timeout, + map_scroll_timeout_handler, data); + return FALSE; + } + return TRUE; +} + /************************************************************************** draw a line from src_x,src_y -> dest_x,dest_y on both map_canvas and map_canvas_store --- freeciv-1.11.10-dev/client/gui-mui/gui_main.c.scrollbar Tue Jul 31 12:04:06 2001 +++ freeciv-1.11.10-dev/client/gui-mui/gui_main.c Mon Aug 6 00:45:20 2001 @@ -109,6 +109,14 @@ /************************************************************************** ... **************************************************************************/ +int ui_valid_option(char *arg) +{ + return (is_option("--help", arg)); +} + +/************************************************************************** +... +**************************************************************************/ static void parse_options(int argc, char **argv) { int i; --- freeciv-1.11.10-dev/client/gui-xaw/gui_main.c.scrollbar Tue Jan 30 15:38:53 2001 +++ freeciv-1.11.10-dev/client/gui-xaw/gui_main.c Mon Aug 6 00:46:17 2001 @@ -228,6 +228,14 @@ /************************************************************************** ... **************************************************************************/ +int ui_valid_option(char *arg) +{ + return (is_option("--help", arg)); +} + +/************************************************************************** +... +**************************************************************************/ static void parse_options(int argc, char **argv) { int i; --- freeciv-1.11.10-dev/client/include/gui_main_g.h.scrollbar Sun Jul 9 23:31:25 2000 +++ freeciv-1.11.10-dev/client/include/gui_main_g.h Mon Aug 6 00:24:48 2001 @@ -16,6 +16,7 @@ struct unit; void ui_main(int argc, char *argv[]); +int ui_valid_option(char *arg); void sound_bell(void); void enable_turn_done_button(void); void add_net_input(int);