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

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: andrearo@xxxxxxxxxxxx, mburda@xxxxxxxxx, tuma@xxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#4543) Patch: scaling overview map
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Apr 2005 01:34:43 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=4543 >

Here is another step toward a properly scaling overview.

The basic logic is a bit complicated.

* Every now and then we recalculate the overview dimensions.
* When recalculating, a GUI function is called to see how big the
overview "should" be.
* Then the dimensions are calculated based on that.
* Then another GUI function is called to resize the overview widget to
be the calculated size.

The recalculation is done when the map (xsize/ysize) values are received
from the server.

In the gui_main.c part of the patch ***which is NOT intended to be
applied*** the recalcualation is also done whenever the container widget
(GtkDrawingArea) is resized.  Note the container widget is (basically)
never resized when it's on the panel.  Only if you detach it can you
resize it, and then it (buggily) just gets bigger and bigger (you can
increase the size but can't decrease it).  In the future this should be
made to work and maybe a GtkPane could be used to allow the user to
resize the panel itself (which is what the original patch did, but I
couldn't get it to work).

One final note: in the calculation of overview dimensions we always
round up.  This is probably bad from a GUI point of view; if the user
sizes the canvas he is giving the max size not the minimum size. 
However this is designed to give good results with the default panel size.

-jason

Index: client/overview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/overview_common.c,v
retrieving revision 1.1
diff -u -r1.1 overview_common.c
--- client/overview_common.c    31 Mar 2005 17:28:02 -0000      1.1
+++ client/overview_common.c    17 Apr 2005 08:28:40 -0000
@@ -15,6 +15,9 @@
 #include <config.h>
 #endif
 
+#include "log.h"
+
+#include "civclient.h" /* can_client_change_view() */
 #include "climap.h"
 #include "control.h"
 #include "options.h"
@@ -263,23 +266,38 @@
 /**************************************************************************
   Called if the map size is know or changes.
 **************************************************************************/
-void set_overview_dimensions(int width, int height)
+void calculate_overview_dimensions(void)
 {
-  int shift = 0; /* used to calculate shift in iso view */
+  int w, h;
+  int xfact = MAP_IS_ISOMETRIC ? 2 : 1;
 
-  /* Set the scale of the overview map.  This attempts to limit the overview
-   * to 120 pixels wide or high. */
-  if (MAP_IS_ISOMETRIC) {
-    OVERVIEW_TILE_SIZE = MIN(MAX(120 / width, 1), 120 / height + 1);
+  static int recursion = 0; /* Just to be safe. */
 
-    /* Clip half tile left and right.  See comment in map_to_overview_pos. */
-    shift = (!topo_has_flag(TF_WRAPX) ? -OVERVIEW_TILE_SIZE : 0);
-  } else {
-    OVERVIEW_TILE_SIZE = MIN(120 / width + 1, 120 / height + 1);
+  /* Clip half tile left and right.  See comment in map_to_overview_pos. */
+  int shift = (MAP_IS_ISOMETRIC && !topo_has_flag(TF_WRAPX)) ? -1 : 0;
+
+  if (recursion > 0 || map.xsize <= 0 || map.ysize <= 0) {
+    return;
   }
+  recursion++;
+
+  get_overview_area_dimensions(&w, &h);
 
-  overview.height = OVERVIEW_TILE_HEIGHT * height;
-  overview.width = OVERVIEW_TILE_WIDTH * width + shift; 
+  freelog(LOG_DEBUG, "Map size %d,%d - area size %d,%d",
+         map.xsize, map.ysize, w, h);
+
+  /* Set the scale of the overview map.  This attempts to limit the
+   * overview to the size of the area available.
+   *
+   * It rounds up since this gives good results with the default settings.
+   * It may need tweaking if the panel resizes itself. */
+  OVERVIEW_TILE_SIZE = MIN((w - 1) / (map.xsize * xfact) + 1,
+                          (h - 1) / map.ysize + 1);
+  OVERVIEW_TILE_SIZE = MAX(OVERVIEW_TILE_SIZE, 1);
+
+  overview.width
+    = OVERVIEW_TILE_WIDTH * map.xsize + shift * OVERVIEW_TILE_SIZE; 
+  overview.height = OVERVIEW_TILE_HEIGHT * map.ysize;
 
   if (overview.store) {
     canvas_free(overview.store);
@@ -290,5 +308,11 @@
   update_map_canvas_scrollbars_size();
 
   /* Call gui specific function. */
-  map_size_changed();
+  overview_size_changed();
+
+  if (can_client_change_view()) {
+    refresh_overview_canvas();
+  }
+
+  recursion--;
 }
Index: client/overview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/overview_common.h,v
retrieving revision 1.1
diff -u -r1.1 overview_common.h
--- client/overview_common.h    31 Mar 2005 17:28:02 -0000      1.1
+++ client/overview_common.h    17 Apr 2005 08:28:40 -0000
@@ -43,7 +43,7 @@
 
 void refresh_overview_canvas(void);
 void overview_update_tile(struct tile *ptile);
-void set_overview_dimensions(int width, int height);
+void calculate_overview_dimensions(void);
 
 void center_tile_overviewcanvas(struct tile *ptile);
 
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.491
diff -u -r1.491 packhand.c
--- client/packhand.c   15 Apr 2005 05:22:51 -0000      1.491
+++ client/packhand.c   17 Apr 2005 08:28:41 -0000
@@ -1327,7 +1327,7 @@
 
   generate_citydlg_dimensions();
 
-  set_overview_dimensions(map.xsize, map.ysize);
+  calculate_overview_dimensions();
 }
 
 /**************************************************************************
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.118
diff -u -r1.118 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       28 Mar 2005 16:59:14 -0000      1.118
+++ client/gui-gtk-2.0/gui_main.c       17 Apr 2005 08:28:41 -0000
@@ -67,6 +67,7 @@
 #include "messagewin.h"
 #include "optiondlg.h"
 #include "options.h"
+#include "overview_common.h"
 #include "pages.h"
 #include "spaceshipdlg.h"
 #include "resources.h"
@@ -686,6 +687,13 @@
   }
 }
 
+static void overviewcanvas_configure(GtkWidget *widget,
+                                    GdkEventConfigure * ev,
+                                    gpointer user_data)
+{
+  calculate_overview_dimensions();
+}
+
 /**************************************************************************
  do the heavy lifting for the widget setup.
 **************************************************************************/
@@ -751,7 +759,7 @@
   gtk_container_add(GTK_CONTAINER(vbox), ahbox);
   avbox = detached_widget_fill(ahbox);
 
-  align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
+  align = gtk_alignment_new(0.5, 0.5, 1.0, 1.0);
   gtk_box_pack_start(GTK_BOX(avbox), align, TRUE, TRUE, 0);
 
   overview_canvas = gtk_drawing_area_new();
@@ -772,6 +780,9 @@
   g_signal_connect(overview_canvas, "button_press_event",
                   G_CALLBACK(butt_down_overviewcanvas), NULL);
 
+  g_signal_connect(overview_canvas, "configure_event",
+                  G_CALLBACK(overviewcanvas_configure), NULL);
+
   /* The rest */
 
   ahbox = detached_widget_new();
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.172
diff -u -r1.172 mapview.c
--- client/gui-gtk-2.0/mapview.c        31 Mar 2005 17:28:03 -0000      1.172
+++ client/gui-gtk-2.0/mapview.c        17 Apr 2005 08:28:41 -0000
@@ -228,10 +228,19 @@
                            sprite_get_pixbuf(gov));
 }
 
+/****************************************************************************
+  Return the dimensions of the area (container widget; maximum size) for
+  the overview.
+****************************************************************************/
+void get_overview_area_dimensions(int *width, int *height)
+{
+  gdk_drawable_get_size(overview_canvas->window, width, height);
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
-void map_size_changed(void)
+void overview_size_changed(void)
 {
   gtk_widget_set_size_request(overview_canvas,
                              overview.width, overview.height);
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.63
diff -u -r1.63 mapview_g.h
--- client/include/mapview_g.h  28 Mar 2005 16:59:15 -0000      1.63
+++ client/include/mapview_g.h  17 Apr 2005 08:28:41 -0000
@@ -29,7 +29,8 @@
 void set_indicator_icons(struct sprite *bulb, struct sprite *sol,
                         struct sprite *flake, struct sprite *gov);
 
-void map_size_changed(void);
+void overview_size_changed(void);
+void get_overview_area_dimensions(int *width, int *height);
 struct canvas *get_overview_window(void);
 
 void flush_mapcanvas(int canvas_x, int canvas_y,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4543) Patch: scaling overview map, Jason Short <=