Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] (PR#3505) move canvas dimensions into mapview_canvas struc
Home

[Freeciv-Dev] (PR#3505) move canvas dimensions into mapview_canvas struc

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3505) move canvas dimensions into mapview_canvas struct
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 22 Feb 2003 17:18:55 -0800
Reply-to: rt@xxxxxxxxxxxxxx

The remaining mapview canvas dimensions - width, height, tile_width, and 
tile_height - are still tracked solely by the GUI.  This patch moves 
them into the mapview_canvas struct.

The users of the values may vary.  For instance most code in 
mapview_common still calls get_mapview_dimensions() to get these values. 
  In a later patch, this function can be removed and the values can be 
accessed directly.

What was needed varies from GUI to GUI:

- GTK, GTK2, XAW, and Win32 GUIs tracked the value of the tile_width and 
tile_height.  In these cases I simply introduced a macro to alias the 
new variable name from the old.

- The win32 GUI tracked the value of the width and height, again an 
alias was all that was needed.

- For GTK, GTK2, and XAW guis the width and height are set in a single 
place, when the window is resized.  Note, this is the same place where 
tile_width and tile_height are calculated.  It is a simple matter to 
initialize the values here.  gui-gtk has an additional caveat because 
the canvas_store is allocated to the initial size of 
tile_width/tile_height (the others use a map_resize function and handle 
things differently/better).

- gui-sdl does not track these values at all.  So, we have to initialize 
them when the mapview is allocated.  But these buffers are first 
allocated before the tileset is loaded, so in that case we don't 
initialize tile_width and tile_height until after loading the tileset.

- gui-mui has no support.  At some point in the near future (probably, 
right after get_mapview_dimensions is removed) I'll make a list of 
needed changes for Sebastian.

This patch has been tested under all GUIs (although gui-sdl and 
gui-win32 are in an inconsistent state right now).

jason

Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.23
diff -u -r1.23 mapview_common.h
--- client/mapview_common.h     2003/02/22 13:15:30     1.23
+++ client/mapview_common.h     2003/02/23 01:09:00
@@ -24,10 +24,8 @@
 
 struct canvas {
   int map_x0, map_y0;
-#if 0 /* These values are still in the GUI. */
   int width, height;
   int tile_width, tile_height;
-#endif
   struct canvas_store *store;
 };
 
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.129
diff -u -r1.129 gui_main.c
--- client/gui-gtk/gui_main.c   2003/02/20 23:14:33     1.129
+++ client/gui-gtk/gui_main.c   2003/02/23 01:09:01
@@ -74,8 +74,6 @@
 GtkWidget *map_vertical_scrollbar;
 GdkPixmap *map_canvas_store;            /* this pixmap acts as a backing store 
                                          * for the map_canvas widget */
-int map_canvas_store_twidth = 1;
-int map_canvas_store_theight = 1;
 
 GtkWidget *overview_canvas;             /* GtkDrawingArea */
 GdkPixmap *overview_canvas_store;       /* this pixmap acts as a backing store 
@@ -914,6 +912,9 @@
 
   timer_id = gtk_timeout_add(TIMER_INTERVAL, timer_callback, NULL);
 
+  /* Start with a 1x1 window (GTK doesn't like 0x0). */
+  map_canvas_store_twidth = 1;
+  map_canvas_store_theight = 1;
   map_canvas_store = gdk_pixmap_new(root_window,
                                  map_canvas_store_twidth * NORMAL_TILE_WIDTH,
                                  map_canvas_store_theight * NORMAL_TILE_HEIGHT,
Index: client/gui-gtk/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.h,v
retrieving revision 1.9
diff -u -r1.9 gui_main.h
--- client/gui-gtk/gui_main.h   2003/01/27 22:27:58     1.9
+++ client/gui-gtk/gui_main.h   2003/02/23 01:09:01
@@ -31,8 +31,6 @@
 extern GdkPixmap *      black50;
 extern GdkPixmap *      mask_bitmap;
 extern GdkPixmap *      map_canvas_store;
-extern int              map_canvas_store_twidth;
-extern int              map_canvas_store_theight;
 extern GdkPixmap *      overview_canvas_store;
 extern int              overview_canvas_store_width;
 extern int              overview_canvas_store_height;
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.159
diff -u -r1.159 mapview.c
--- client/gui-gtk/mapview.c    2003/02/22 13:15:30     1.159
+++ client/gui-gtk/mapview.c    2003/02/23 01:09:02
@@ -695,6 +695,9 @@
 
   gdk_window_get_size(w->window, &width, &height);
 
+  mapview_canvas.width = width;
+  mapview_canvas.height = height;
+
   tile_width=(width+NORMAL_TILE_WIDTH-1)/NORMAL_TILE_WIDTH;
   tile_height=(height+NORMAL_TILE_HEIGHT-1)/NORMAL_TILE_HEIGHT;
 
Index: client/gui-gtk/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.h,v
retrieving revision 1.17
diff -u -r1.17 mapview.h
--- client/gui-gtk/mapview.h    2003/02/22 13:15:30     1.17
+++ client/gui-gtk/mapview.h    2003/02/23 01:09:02
@@ -55,5 +55,7 @@
 /* These values are stored in the mapview_canvas struct now. */
 #define map_view_x0 mapview_canvas.map_x0
 #define map_view_y0 mapview_canvas.map_y0
+#define map_canvas_store_twidth mapview_canvas.tile_width
+#define map_canvas_store_theight mapview_canvas.tile_height
 
 #endif  /* FC__MAPVIEW_H */
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.41
diff -u -r1.41 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       2003/02/12 22:49:51     1.41
+++ client/gui-gtk-2.0/gui_main.c       2003/02/23 01:09:03
@@ -74,8 +74,6 @@
 GtkWidget *map_vertical_scrollbar;
 GdkPixmap *map_canvas_store;            /* this pixmap acts as a backing store 
                                          * for the map_canvas widget */
-int map_canvas_store_twidth = 1;
-int map_canvas_store_theight = 1;
 
 GtkWidget *overview_canvas;             /* GtkDrawingArea */
 GdkPixmap *overview_canvas_store;       /* this pixmap acts as a backing store 
Index: client/gui-gtk-2.0/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.h,v
retrieving revision 1.5
diff -u -r1.5 gui_main.h
--- client/gui-gtk-2.0/gui_main.h       2003/01/27 22:27:58     1.5
+++ client/gui-gtk-2.0/gui_main.h       2003/02/23 01:09:03
@@ -35,8 +35,6 @@
 extern GdkPixmap *      black50;
 extern GdkPixmap *      mask_bitmap;
 extern GdkPixmap *      map_canvas_store;
-extern int              map_canvas_store_twidth;
-extern int              map_canvas_store_theight;
 extern GdkPixmap *      overview_canvas_store;
 extern int              overview_canvas_store_width;
 extern int              overview_canvas_store_height;
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.47
diff -u -r1.47 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/02/22 13:15:30     1.47
+++ client/gui-gtk-2.0/mapview.c        2003/02/23 01:09:04
@@ -704,7 +704,10 @@
 
   tile_width = (ev->width + NORMAL_TILE_WIDTH - 1) / NORMAL_TILE_WIDTH;
   tile_height = (ev->height + NORMAL_TILE_HEIGHT - 1) / NORMAL_TILE_HEIGHT;
-  
+
+  mapview_canvas.width = ev->width;
+  mapview_canvas.height = ev->height;
+
   if (map_canvas_store_twidth !=tile_width ||
       map_canvas_store_theight!=tile_height) { /* resized? */
 
Index: client/gui-gtk-2.0/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.h,v
retrieving revision 1.8
diff -u -r1.8 mapview.h
--- client/gui-gtk-2.0/mapview.h        2003/02/22 13:15:30     1.8
+++ client/gui-gtk-2.0/mapview.h        2003/02/23 01:09:04
@@ -57,5 +57,7 @@
 /* These values are stored in the mapview_canvas struct now. */
 #define map_view_x0 mapview_canvas.map_x0
 #define map_view_y0 mapview_canvas.map_y0
+#define map_canvas_store_twidth mapview_canvas.tile_width
+#define map_canvas_store_theight mapview_canvas.tile_height
 
 #endif  /* FC__MAPVIEW_H */
Index: client/gui-sdl/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/graphics.c,v
retrieving revision 1.13
diff -u -r1.13 graphics.c
--- client/gui-sdl/graphics.c   2003/02/21 03:40:06     1.13
+++ client/gui-sdl/graphics.c   2003/02/23 01:09:05
@@ -834,6 +834,13 @@
                        "Setting resolution to: %d x %d %d bpp"),
          __FILE__, __LINE__, iWidth, iHeight, iDepth);
 
+  mapview_canvas.width = iWidth;
+  mapview_canvas.height = iHeight;
+  if (NORMAL_TILE_WIDTH > 0) {
+    mapview_canvas.tile_width = (iWidth - 1) / NORMAL_TILE_WIDTH + 1;
+    mapview_canvas.tile_height = (iHeight - 1) / NORMAL_TILE_HEIGHT + 1;
+  }
+
   FREESURFACE(Main.map);
   Main.map = SDL_DisplayFormat(Main.screen);
   
Index: client/gui-sdl/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/gui_main.c,v
retrieving revision 1.14
diff -u -r1.14 gui_main.c
--- client/gui-sdl/gui_main.c   2003/02/22 10:31:08     1.14
+++ client/gui-sdl/gui_main.c   2003/02/23 01:09:06
@@ -664,6 +664,11 @@
 
   tilespec_load_tiles();
 
+  mapview_canvas.tile_width = (mapview_canvas.width - 1)
+         / NORMAL_TILE_WIDTH + 1;
+  mapview_canvas.tile_height = (mapview_canvas.height - 1)
+         / NORMAL_TILE_HEIGHT + 1;
+
   load_cursors();
   tilespec_setup_theme();
   
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.26
diff -u -r1.26 mapview.c
--- client/gui-sdl/mapview.c    2003/02/22 13:15:30     1.26
+++ client/gui-sdl/mapview.c    2003/02/23 01:09:07
@@ -321,10 +321,9 @@
 **************************************************************************/
 void center_tile_mapcanvas(int col, int row)
 {
-  int ww = (Main.screen->w - 1) / NORMAL_TILE_WIDTH + 1;
-  int hh = (Main.screen->h - 1) / NORMAL_TILE_HEIGHT + 1;
-       
-  base_center_tile_mapcanvas(col, row, &map_view_x0, &map_view_y0, ww, hh);
+  base_center_tile_mapcanvas(col, row, &map_view_x0, &map_view_y0,
+                            mapview_canvas.tile_width,
+                            mapview_canvas.tile_height);
   
   update_map_canvas_visible();
   refresh_overview_viewrect();
@@ -1175,8 +1174,8 @@
     map_area.h = 100;
     /* The x's and y's are in overview coordinates. */
 
-    map_w = (Main.gui->w + NORMAL_TILE_WIDTH - 1) / NORMAL_TILE_WIDTH;
-    map_h = (Main.gui->h + NORMAL_TILE_HEIGHT - 1) / NORMAL_TILE_HEIGHT;
+    map_w = mapview_canvas.tile_width;
+    map_h = mapview_canvas.tile_height;
     
 #if 0
     get_map_xy(0, 0, &Wx, &Wy);        /* take from Main Map */
Index: client/gui-win32/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/gui_main.c,v
retrieving revision 1.21
diff -u -r1.21 gui_main.c
--- client/gui-win32/gui_main.c 2003/01/23 21:39:32     1.21
+++ client/gui-win32/gui_main.c 2003/02/23 01:09:07
@@ -75,8 +75,6 @@
 int main_win_height;
 int map_win_x;
 int map_win_y;
-int map_win_width;
-int map_win_height;
 int taxinfoline_y;
 int indicator_y;
 int overview_win_x;
Index: client/gui-win32/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/gui_main.h,v
retrieving revision 1.5
diff -u -r1.5 gui_main.h
--- client/gui-win32/gui_main.h 2003/01/23 21:39:32     1.5
+++ client/gui-win32/gui_main.h 2003/02/23 01:09:07
@@ -121,8 +121,6 @@
 extern HFONT font_12arial;
 extern int map_win_x;
 extern int map_win_y;
-extern int map_win_width;
-extern int map_win_height;
 extern HWND root_window;
 extern void do_mainwin_layout(void);
 extern int overview_win_x;
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.59
diff -u -r1.59 mapview.c
--- client/gui-win32/mapview.c  2003/02/22 13:15:30     1.59
+++ client/gui-win32/mapview.c  2003/02/23 01:09:08
@@ -60,8 +60,6 @@
 extern HBITMAP BITMAP2HBITMAP(BITMAP *bmp);
 
 extern void do_mainwin_layout();
-int map_view_width;
-int map_view_height;
 
 extern int seconds_to_turndone;   
 void update_map_canvas_scrollbars_size(void);
Index: client/gui-win32/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.h,v
retrieving revision 1.6
diff -u -r1.6 mapview.h
--- client/gui-win32/mapview.h  2003/02/22 13:15:30     1.6
+++ client/gui-win32/mapview.h  2003/02/23 01:09:08
@@ -31,11 +31,13 @@
 void overview_expose(HDC hdc);
 void map_handle_hscroll(int pos);
 void map_handle_vscroll(int pos);
-extern int map_view_width;
-extern int map_view_height;
 
 /* These values are stored in the mapview_canvas struct now. */
 #define map_view_x mapview_canvas.map_x0
 #define map_view_y mapview_canvas.map_y0
+#define map_win_width mapview_canvas.width
+#define map_win_height mapview_canvas.height
+#define map_view_width mapview_canvas.tile_width
+#define map_view_height mapview_canvas.tile_height
 
 #endif  /* FC__MAPVIEW_H */
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.78
diff -u -r1.78 gui_main.c
--- client/gui-xaw/gui_main.c   2003/02/12 22:49:52     1.78
+++ client/gui-xaw/gui_main.c   2003/02/23 01:09:09
@@ -192,7 +192,6 @@
 
 /* this pixmap acts as a backing store for the map_canvas widget */
 Pixmap map_canvas_store = 0;
-int map_canvas_store_twidth, map_canvas_store_theight;
 
 /* this pixmap acts as a backing store for the overview_canvas widget */
 Pixmap overview_canvas_store;
Index: client/gui-xaw/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.h,v
retrieving revision 1.8
diff -u -r1.8 gui_main.h
--- client/gui-xaw/gui_main.h   2001/01/30 23:38:53     1.8
+++ client/gui-xaw/gui_main.h   2003/02/23 01:09:09
@@ -33,8 +33,6 @@
 extern Pixmap       gray25;
 extern Pixmap       single_tile_pixmap;
 extern Pixmap       map_canvas_store;
-extern int          map_canvas_store_twidth;
-extern int          map_canvas_store_theight;
 extern Pixmap       overview_canvas_store;
 extern int          overview_canvas_store_width;
 extern int          overview_canvas_store_height;
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.126
diff -u -r1.126 mapview.c
--- client/gui-xaw/mapview.c    2003/02/22 13:15:30     1.126
+++ client/gui-xaw/mapview.c    2003/02/23 01:09:10
@@ -585,6 +585,10 @@
     XFreePixmap(display, map_canvas_store);
 
   XtVaGetValues(map_canvas, XtNwidth, &width, XtNheight, &height, NULL);
+
+  mapview_canvas.width = width;
+  mapview_canvas.height = height;
+
   map_canvas_store_twidth=((width-1)/NORMAL_TILE_WIDTH)+1;
   map_canvas_store_theight=((height-1)/NORMAL_TILE_HEIGHT)+1;
 
Index: client/gui-xaw/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.h,v
retrieving revision 1.13
diff -u -r1.13 mapview.h
--- client/gui-xaw/mapview.h    2003/02/22 13:15:30     1.13
+++ client/gui-xaw/mapview.h    2003/02/23 01:09:10
@@ -55,5 +55,7 @@
 /* These values are stored in the mapview_canvas struct now. */
 #define map_view_x0 mapview_canvas.map_x0
 #define map_view_y0 mapview_canvas.map_y0
+#define map_canvas_store_twidth mapview_canvas.tile_width
+#define map_canvas_store_theight mapview_canvas.tile_height
 
 #endif  /* FC__MAPVIEW_H */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#3505) move canvas dimensions into mapview_canvas struct, Jason Short <=