Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4543) scaling overview map
Home

[Freeciv-Dev] (PR#4543) scaling overview map

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4543) scaling overview map
From: "andrearo@xxxxxxxxxxxx" <andrearo@xxxxxxxxxxxx>
Date: Fri, 11 Jul 2003 17:44:46 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch allows scaling of the overview map, like in Civ2.
It also sets a decent scale to the overview map when
starting a new game, to handle very large/small maps.
Comments?

Andreas Røsdal
diff -ruN -Xfreeciv/diff_ignore freeciv/client/gui-gtk/gui_main.c 
freeciv_overview/client/gui-gtk/gui_main.c
--- freeciv/client/gui-gtk/gui_main.c   2003-07-03 06:58:34.000000000 +0200
+++ freeciv_overview/client/gui-gtk/gui_main.c  2003-07-12 01:41:22.000000000 
+0200
@@ -152,6 +152,8 @@
 static void select_unit_pixmap_callback(GtkWidget *w, GdkEvent *ev, 
                                         gpointer data);
 static gint timer_callback(gpointer data);
+static gboolean hpane_callback(GtkWidget *widget, GdkEventButton *event,
+                               gpointer user_data);
 
 /**************************************************************************
   Print extra usage information, including one line help on each option,
@@ -522,18 +524,18 @@
 {
   GtkWidget *box, *ebox, *hbox, *vbox;
   GtkWidget *avbox, *ahbox;
-  GtkWidget *frame, *table, *paned, *menubar, *text;
+  GtkWidget *frame, *table, *vpaned, *hpaned, *menubar, *text;
   GtkStyle  *text_style, *style;
   int i;
 
   /* the window is divided into two panes. "top" and "message window" */ 
-  paned = gtk_vpaned_new();
-  gtk_container_add(GTK_CONTAINER(toplevel), paned);
+  vpaned = gtk_vpaned_new();
+  gtk_container_add(GTK_CONTAINER(toplevel), vpaned);
 
   /* *** everything in the top *** */
 
   top_vbox = gtk_vbox_new(FALSE, 5);
-  gtk_paned_pack1(GTK_PANED(paned), top_vbox, TRUE, FALSE);
+  gtk_paned_pack1(GTK_PANED(vpaned), top_vbox, TRUE, FALSE);
   
   setup_menus(toplevel, &menubar);
   gtk_box_pack_start(GTK_BOX(top_vbox), menubar, FALSE, FALSE, 0);
@@ -541,10 +543,16 @@
   hbox = gtk_hbox_new(FALSE, 0);
   gtk_box_pack_start(GTK_BOX(top_vbox), hbox, TRUE, TRUE, 0);
 
+  hpaned = gtk_hpaned_new();
+  gtk_paned_set_gutter_size(GTK_PANED(hpaned), 0);
+  gtk_paned_set_handle_size(GTK_PANED(hpaned), 8);
+  gtk_box_pack_start(GTK_BOX(hbox), hpaned, TRUE, TRUE, 0);
+  gtk_signal_connect_after(GTK_OBJECT(hpaned), "button_release_event",
+                           GTK_SIGNAL_FUNC(hpane_callback), NULL);
+
   /* this holds the overview canvas, production info, etc. */
   vbox = gtk_vbox_new(FALSE, 3);
-  gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
-
+  gtk_paned_pack1(GTK_PANED(hpaned),vbox, FALSE, TRUE);
 
   /* overview canvas */
   ahbox = detached_widget_new();
@@ -690,7 +698,7 @@
   /* Map canvas and scrollbars */
 
   table = gtk_table_new(2, 2, FALSE);
-  gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, TRUE, 0);
+  gtk_paned_pack2(GTK_PANED(hpaned),table, TRUE, TRUE);
 
   frame = gtk_frame_new(NULL);
   gtk_table_attach(GTK_TABLE(table), frame, 0, 1, 0, 1,
@@ -733,7 +741,7 @@
   /* *** The message window -- this is a detachable widget *** */
 
   ahbox = detached_widget_new();
-  gtk_paned_pack2(GTK_PANED(paned), ahbox, TRUE, TRUE);
+  gtk_paned_pack2(GTK_PANED(vpaned), ahbox, TRUE, TRUE);
   avbox = detached_widget_fill(ahbox);
 
   hbox = gtk_hbox_new(FALSE, 0);
@@ -773,7 +781,7 @@
 
   /* Other things to take care of */
 
-  gtk_widget_show_all(paned);
+  gtk_widget_show_all(vpaned);
   gtk_widget_hide(more_arrow_pixmap);
 
   if (!map_scrollbars) {
@@ -1171,3 +1179,24 @@
   gdk_input_remove(gdk_input_id);
   gdk_window_set_cursor(root_window, NULL);
 }
+
+/**************************************************************************
+ The user resized the horizontally aligned panes. Resize the overview map.
+**************************************************************************/
+static gboolean hpane_callback(GtkWidget *widget, GdkEventButton *event,
+                               gpointer user_data)
+{
+  int width = (map.xsize * OVERVIEW_TILE_WIDTH) + (map.xsize / 2) + event->x;
+
+  if (width / map.xsize < 1) {
+    return TRUE;
+  }
+  OVERVIEW_TILE_WIDTH =  width / map.xsize;
+  OVERVIEW_TILE_HEIGHT = OVERVIEW_TILE_WIDTH;
+  gtk_paned_set_position(GTK_PANED(widget), -1);
+  if (get_client_state() == CLIENT_GAME_RUNNING_STATE) {
+    set_overview_dimensions(map.xsize, map.ysize);
+    refresh_overview_canvas();
+  }
+  return TRUE;
+}
diff -ruN -Xfreeciv/diff_ignore freeciv/client/gui-gtk-2.0/gui_main.c 
freeciv_overview/client/gui-gtk-2.0/gui_main.c
--- freeciv/client/gui-gtk-2.0/gui_main.c       2003-07-03 06:58:34.000000000 
+0200
+++ freeciv_overview/client/gui-gtk-2.0/gui_main.c      2003-07-12 
01:40:50.000000000 +0200
@@ -165,6 +165,8 @@
 static gint timer_callback(gpointer data);
 static gboolean show_conn_popup(GtkWidget *view, GdkEventButton *ev,
                                gpointer data);
+static void hpane_resized(GObject *object, GParamSpec *pspec, 
+                          gpointer data);
 static char *network_charset = NULL;
 
 
@@ -650,7 +652,8 @@
 static void setup_widgets(void)
 {
   GtkWidget *box, *ebox, *hbox, *sbox, *align, *label;
-  GtkWidget *frame, *table, *table2, *paned, *menubar, *sw, *text, *view;
+  GtkWidget *frame, *table, *table2, *menubar, *sw, *text, *view;
+  GtkWidget *vpaned, *hpaned;
   GtkStyle *style;
   int i;
   struct Sprite *sprite;
@@ -659,13 +662,13 @@
   main_tips = gtk_tooltips_new();
 
   /* the window is divided into two panes. "top" and "message window" */ 
-  paned = gtk_vpaned_new();
-  gtk_container_add(GTK_CONTAINER(toplevel), paned);
+  vpaned = gtk_vpaned_new();
+  gtk_container_add(GTK_CONTAINER(toplevel), vpaned);
 
   /* *** everything in the top *** */
 
   top_vbox = gtk_vbox_new(FALSE, 5);
-  gtk_paned_pack1(GTK_PANED(paned), top_vbox, TRUE, FALSE);
+  gtk_paned_pack1(GTK_PANED(vpaned), top_vbox, TRUE, FALSE);
   
   setup_menus(toplevel, &menubar);
   gtk_box_pack_start(GTK_BOX(top_vbox), menubar, FALSE, FALSE, 0);
@@ -673,10 +676,14 @@
   hbox = gtk_hbox_new(FALSE, 0);
   gtk_box_pack_start(GTK_BOX(top_vbox), hbox, TRUE, TRUE, 0);
 
+  hpaned = gtk_hpaned_new();
+  gtk_box_pack_start(GTK_BOX(hbox), hpaned, TRUE, TRUE, 0);
+  g_signal_connect(G_OBJECT(hpaned), "notify::position", 
+                   G_CALLBACK(hpane_resized), NULL);
+
   /* this holds the overview canvas, production info, etc. */
   vbox = gtk_vbox_new(FALSE, 3);
-  gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
-
+  gtk_paned_pack1(GTK_PANED(hpaned),vbox, FALSE, TRUE);
 
   /* overview canvas */
   ahbox = detached_widget_new();
@@ -881,7 +888,7 @@
   /* Map canvas and scrollbars */
 
   table = gtk_table_new(2, 2, FALSE);
-  gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, TRUE, 0);
+  gtk_paned_pack2(GTK_PANED(hpaned),table, TRUE, TRUE);
 
   frame = gtk_frame_new(NULL);
   gtk_table_attach(GTK_TABLE(table), frame, 0, 1, 0, 1,
@@ -932,7 +939,7 @@
   /* *** The message window -- this is a detachable widget *** */
 
   sbox = detached_widget_new();
-  gtk_paned_pack2(GTK_PANED(paned), sbox, TRUE, TRUE);
+  gtk_paned_pack2(GTK_PANED(vpaned), sbox, TRUE, TRUE);
   avbox = detached_widget_fill(sbox);
 
   sw = gtk_scrolled_window_new(NULL, NULL);
@@ -975,7 +982,7 @@
 
   /* Other things to take care of */
 
-  gtk_widget_show_all(paned);
+  gtk_widget_show_all(vpaned);
   gtk_widget_hide(more_arrow_pixmap);
 
   if (!map_scrollbars) {
@@ -1473,3 +1480,25 @@
   gtk_input_remove(input_id);
   gdk_window_set_cursor(root_window, NULL);
 }
+
+/**************************************************************************
+ The user resized the horizontally aligned panes. Resize the overview map.
+**************************************************************************/
+static void hpane_resized(GObject *object, GParamSpec *spec,
+                          gpointer data) 
+{
+  gint width;
+
+  g_object_get(object, spec->name, &width, NULL);
+  if (map.xsize == 0) {
+    return;
+  } else if (width / map.xsize < 1) {
+    return;
+  }
+  OVERVIEW_TILE_WIDTH = width / map.xsize ;
+  OVERVIEW_TILE_HEIGHT = OVERVIEW_TILE_WIDTH;
+  if (get_client_state() == CLIENT_GAME_RUNNING_STATE) {
+    refresh_overview_canvas();
+    set_overview_dimensions(map.xsize, map.ysize);
+  }
+}
diff -ruN -Xfreeciv/diff_ignore freeciv/client/packhand.c 
freeciv_overview/client/packhand.c
--- freeciv/client/packhand.c   2003-07-10 06:58:34.000000000 +0200
+++ freeciv_overview/client/packhand.c  2003-07-12 01:37:42.000000000 +0200
@@ -1109,7 +1109,10 @@
 
   map_allocate();
   init_client_goto();
-  
+  /* Set the scale of the overview map. */
+  OVERVIEW_TILE_WIDTH = (120 / map.xsize) + 1;
+  OVERVIEW_TILE_HEIGHT = OVERVIEW_TILE_WIDTH;
+
   set_overview_dimensions(map.xsize, map.ysize);
 }
 


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