Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7375) Unify some mapview code
Home

[Freeciv-Dev] (PR#7375) Unify some mapview code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7375) Unify some mapview code
From: "Raimar Falke" <i-freeciv-lists@xxxxxxxxxxxxx>
Date: Wed, 4 Feb 2004 07:11:18 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7375 >


With the new canvas_store_{create,free} function it is possible to
remove some more code.

Only Xaw and GTK1 changed.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "I heard if you play the NT-4.0-CD backwards, you get a satanic message."
 "That's nothing, if you play it forward, it installs NT-4.0"

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.74
diff -u -u -r1.74 mapview_common.c
--- client/mapview_common.c     2004/02/03 20:16:07     1.74
+++ client/mapview_common.c     2004/02/04 15:00:40
@@ -1719,7 +1719,69 @@
   overview.store = canvas_store_create(overview.width, overview.height);
   gui_put_rectangle(overview.store, COLOR_STD_BLACK, 0, 0, overview.width,
                    overview.height);
+  update_map_canvas_scrollbars_size();
 
   /* Call gui specific function. */
   map_size_changed();
+}
+
+/**************************************************************************
+  Called if the map in the GUI is resized.
+**************************************************************************/
+bool map_canvas_resized(int width, int height)
+{
+  int tile_width = (width + NORMAL_TILE_WIDTH - 1) / NORMAL_TILE_WIDTH;
+  int tile_height = (height + NORMAL_TILE_HEIGHT - 1) / NORMAL_TILE_HEIGHT;
+
+  if (mapview_canvas.tile_width == tile_width
+       && mapview_canvas.tile_height == tile_height) {
+      return FALSE;
+  }
+
+  /* Resized */
+
+  /* Since a resize is only triggered when the tile_*** changes, the canvas
+   * width and height must include the entire backing store - otherwise
+   * small resizings may lead to undrawn tiles. */
+  mapview_canvas.tile_width = tile_width;
+  mapview_canvas.tile_height = tile_height;
+
+  mapview_canvas.width = mapview_canvas.tile_width * NORMAL_TILE_WIDTH;
+  mapview_canvas.height = mapview_canvas.tile_height * NORMAL_TILE_HEIGHT;
+
+  if (mapview_canvas.store) {
+    canvas_store_free(mapview_canvas.store);
+  }
+  
+  mapview_canvas.store =
+      canvas_store_create(mapview_canvas.width, mapview_canvas.height);
+  gui_put_rectangle(mapview_canvas.store, COLOR_STD_BLACK, 0, 0,
+                   mapview_canvas.width, mapview_canvas.height);
+
+  if (map_exists() && map.tiles) {
+    update_map_canvas_visible();
+
+    update_map_canvas_scrollbars_size();
+    update_map_canvas_scrollbars();
+  }
+
+  return TRUE;
+}
+
+/**************************************************************************
+  Sets up the mapview_canvas and overview struts.
+**************************************************************************/
+void init_mapcanvas_and_overview(void)
+{
+  mapview_canvas.tile_width = 0;
+  mapview_canvas.tile_height = 0;
+  mapview_canvas.width = 0;
+  mapview_canvas.height = 0;
+  mapview_canvas.store = canvas_store_create(1, 1);
+
+  overview.map_x0 = 0;
+  overview.map_y0 = 0;
+  overview.width = 0;
+  overview.height = 0;
+  overview.store = NULL;
 }
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.40
diff -u -u -r1.40 mapview_common.h
--- client/mapview_common.h     2004/02/03 20:16:07     1.40
+++ client/mapview_common.h     2004/02/04 15:00:40
@@ -206,4 +206,7 @@
 void overview_update_tile(int x, int y);
 void set_overview_dimensions(int width, int height);
 
+bool map_canvas_resized(int width, int height);
+void init_mapcanvas_and_overview(void);
+
 #endif /* FC__MAPVIEW_COMMON_H */
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.144
diff -u -u -r1.144 gui_main.c
--- client/gui-gtk/gui_main.c   2004/02/03 20:16:07     1.144
+++ client/gui-gtk/gui_main.c   2004/02/04 15:00:41
@@ -71,8 +71,6 @@
 GtkWidget *map_canvas;                  /* GtkDrawingArea */
 GtkWidget *map_horizontal_scrollbar;
 GtkWidget *map_vertical_scrollbar;
-GdkPixmap *map_canvas_store;            /* this pixmap acts as a backing store 
-                                         * for the map_canvas widget */
 
 GtkWidget *overview_canvas;             /* GtkDrawingArea */
 
@@ -947,17 +945,8 @@
 
   timer_id = gtk_timeout_add(TIMER_INTERVAL, timer_callback, NULL);
 
-  /* Start with a 1x1 window (GTK doesn't like 0x0). */
-  mapview_canvas.tile_width = 1;
-  mapview_canvas.tile_height = 1;
-  mapview_canvas.width = mapview_canvas.tile_width * NORMAL_TILE_WIDTH;
-  mapview_canvas.height = mapview_canvas.tile_height * NORMAL_TILE_HEIGHT;
-
-  mapview_canvas.store =
-      canvas_store_create(mapview_canvas.width, mapview_canvas.height);
-  map_canvas_store = mapview_canvas.store->pixmap;
+  init_mapcanvas_and_overview();
 
-  overview.store = NULL;
   overview.window = fc_malloc(sizeof(*overview.window));
   overview.window->pixmap = overview_canvas->window;
   overview.window->pixcomm = NULL;
Index: client/gui-gtk/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.h,v
retrieving revision 1.13
diff -u -u -r1.13 gui_main.h
--- client/gui-gtk/gui_main.h   2004/02/03 20:16:07     1.13
+++ client/gui-gtk/gui_main.h   2004/02/04 15:00:41
@@ -38,7 +38,6 @@
 extern GdkPixmap *      gray25;
 extern GdkPixmap *      black50;
 extern GdkPixmap *      mask_bitmap;
-extern GdkPixmap *      map_canvas_store;
 extern GdkPixmap *      single_tile_pixmap;
 extern GtkText *        main_message_area;
 extern GtkWidget *      text_scrollbar;
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.190
diff -u -u -r1.190 mapview.c
--- client/gui-gtk/mapview.c    2004/02/03 20:16:07     1.190
+++ client/gui-gtk/mapview.c    2004/02/04 15:00:42
@@ -50,6 +50,8 @@
 
 #include "mapview.h"
 
+#define map_canvas_store (mapview_canvas.store->pixmap)
+
 static void pixmap_put_overlay_tile(GdkDrawable *pixmap,
                                    int canvas_x, int canvas_y,
                                    struct Sprite *ssprite);
@@ -383,7 +385,6 @@
 void map_size_changed(void)
 {
   gtk_widget_set_usize(overview_canvas, overview.width, overview.height);
-  update_map_canvas_scrollbars_size();
 }
 
 /**************************************************************************
@@ -442,47 +443,12 @@
 gint map_canvas_expose(GtkWidget *w, GdkEventExpose *ev)
 {
   gint height, width;
-  int tile_width, tile_height;
   gboolean map_resized;
   static int exposed_once = 0;
 
   gdk_window_get_size(w->window, &width, &height);
-
-  tile_width=(width+NORMAL_TILE_WIDTH-1)/NORMAL_TILE_WIDTH;
-  tile_height=(height+NORMAL_TILE_HEIGHT-1)/NORMAL_TILE_HEIGHT;
 
-  /* Since a resize is only triggered when the tile_*** changes, the canvas
-   * width and height must include the entire backing store - otherwise
-   * small resizings may lead to undrawn tiles. */
-  mapview_canvas.width = tile_width * NORMAL_TILE_WIDTH;
-  mapview_canvas.height = tile_height * NORMAL_TILE_HEIGHT;
-
-  map_resized=FALSE;
-  if (mapview_canvas.tile_width != tile_width
-      || mapview_canvas.tile_height != tile_height) { /* resized? */
-    gdk_pixmap_unref(map_canvas_store);
-  
-    mapview_canvas.tile_width = tile_width;
-    mapview_canvas.tile_height = tile_height;
-/*
-    gtk_drawing_area_size(GTK_DRAWING_AREA(map_canvas),
-                   mapview_canvas.tile_width,
-                   mapview_canvas.tile_height);
-*/
-    map_canvas_store= gdk_pixmap_new( map_canvas->window,
-                   tile_width*NORMAL_TILE_WIDTH,
-                   tile_height*NORMAL_TILE_HEIGHT,
-                   -1 );
-    mapview_canvas.store->pixmap = map_canvas_store;
-
-    gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
-    gdk_draw_rectangle(map_canvas_store, fill_bg_gc, TRUE,
-                      0, 0,
-                      NORMAL_TILE_WIDTH * mapview_canvas.tile_width,
-                      NORMAL_TILE_HEIGHT * mapview_canvas.tile_height);
-    update_map_canvas_scrollbars_size();
-    map_resized=TRUE;
-  }
+  map_resized = map_canvas_resized(width, height);
 
   if (!can_client_change_view()) {
     if (!intro_gfx_sprite) {
@@ -511,17 +477,10 @@
       scaled_intro_sprite = NULL;
     }
 
-    if (map_exists()) { /* do we have a map at all */
-      if(map_resized) {
-       update_map_canvas_visible();
-
-       update_map_canvas_scrollbars();
-      }
-      else {
-       gdk_draw_pixmap( map_canvas->window, civ_gc, map_canvas_store,
-               ev->area.x, ev->area.y, ev->area.x, ev->area.y,
-               ev->area.width, ev->area.height );
-      }
+    if (map_exists() && !map_resized) {
+      gdk_draw_pixmap(map_canvas->window, civ_gc, map_canvas_store,
+                     ev->area.x, ev->area.y, ev->area.x, ev->area.y,
+                     ev->area.width, ev->area.height);
     }
     refresh_overview_canvas();
   }
Index: client/gui-xaw/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v
retrieving revision 1.86
diff -u -u -r1.86 gui_main.c
--- client/gui-xaw/gui_main.c   2004/02/03 20:16:08     1.86
+++ client/gui-xaw/gui_main.c   2004/02/04 15:00:43
@@ -198,9 +198,6 @@
 Widget more_arrow_label;
 Window root_window;
 
-/* this pixmap acts as a backing store for the map_canvas widget */
-Pixmap map_canvas_store = 0;
-
 /* this pixmap is used when moving units etc */
 Pixmap single_tile_pixmap;
 
@@ -446,9 +443,8 @@
   x_interval_id = XtAppAddTimeOut(app_context, TIMER_INTERVAL,
                                  timer_callback, NULL);
 
-  map_canvas_resize();
+  init_mapcanvas_and_overview();
 
-  overview.store = NULL;
   overview.window = fc_malloc(sizeof(*overview.window));
   overview.window->pixmap = XtWindow(overview_canvas);
 
Index: client/gui-xaw/gui_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.h,v
retrieving revision 1.12
diff -u -u -r1.12 gui_main.h
--- client/gui-xaw/gui_main.h   2004/02/03 20:16:08     1.12
+++ client/gui-xaw/gui_main.h   2004/02/04 15:00:43
@@ -33,7 +33,6 @@
 extern Pixmap       gray50;
 extern Pixmap       gray25;
 extern Pixmap       single_tile_pixmap;
-extern Pixmap       map_canvas_store;
 extern Widget       map_vertical_scrollbar;
 extern Widget       map_horizontal_scrollbar;
 extern Widget       left_column_form;
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.155
diff -u -u -r1.155 mapview.c
--- client/gui-xaw/mapview.c    2004/02/03 20:16:08     1.155
+++ client/gui-xaw/mapview.c    2004/02/04 15:00:44
@@ -52,6 +52,8 @@
 
 #include "mapview.h"
 
+#define map_canvas_store (mapview_canvas.store->pixmap)
+
 static void pixmap_put_overlay_tile(Pixmap pixmap, int x, int y,
                                    struct Sprite *ssprite);
 static void put_line(Pixmap pm, int x, int y, int dir);
@@ -411,11 +413,11 @@
                       void *client_data)
 {
   Dimension width, height;
-  int tile_width, tile_height;
+  bool map_resized;
 
   XtVaGetValues(w, XtNwidth, &width, XtNheight, &height, NULL);
-  tile_width=(width+NORMAL_TILE_WIDTH-1)/NORMAL_TILE_WIDTH;
-  tile_height=(height+NORMAL_TILE_HEIGHT-1)/NORMAL_TILE_HEIGHT;
+
+  map_resized = map_canvas_resized(width, height);
 
   if (!can_client_change_view()) {
     if (!intro_gfx_sprite) {
@@ -441,12 +443,6 @@
                 event->xexpose.x, event->xexpose.y,
                 event->xexpose.width, event->xexpose.height,
                 event->xexpose.x, event->xexpose.y);
-
-    /* resized? */
-    if (mapview_canvas.tile_width != tile_width
-       || mapview_canvas.tile_height != tile_height) {
-      map_canvas_resize();
-    }
     return;
   }
   if(scaled_intro_pixmap) {
@@ -454,57 +450,17 @@
     scaled_intro_pixmap=0; scaled_intro_pixmap_height=0;
   }
 
-  if (map_exists()) { /* do we have a map at all */
-    /* resized? */
-    if (mapview_canvas.tile_width != tile_width
-       || mapview_canvas.tile_height!=tile_height) {
-      map_canvas_resize();
-
-      XFillRectangle(display, map_canvas_store, fill_bg_gc, 0, 0, 
-                    NORMAL_TILE_WIDTH * mapview_canvas.tile_width,
-                    NORMAL_TILE_HEIGHT * mapview_canvas.tile_height);
-
-      update_map_canvas_visible();
-
-      update_map_canvas_scrollbars();
-    } else {
-      XCopyArea(display, map_canvas_store, XtWindow(map_canvas),
-               civ_gc,
-               event->xexpose.x, event->xexpose.y,
-               event->xexpose.width, event->xexpose.height,
-               event->xexpose.x, event->xexpose.y);
-    }
+  if (map_exists() && !map_resized) {
+    XCopyArea(display, map_canvas_store, XtWindow(map_canvas),
+             civ_gc,
+             event->xexpose.x, event->xexpose.y,
+             event->xexpose.width, event->xexpose.height,
+             event->xexpose.x, event->xexpose.y);
   }
   refresh_overview_canvas();
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-void map_canvas_resize(void)
-{
-  Dimension width, height;
-
-  XtVaGetValues(map_canvas, XtNwidth, &width, XtNheight, &height, NULL);
-
-  mapview_canvas.tile_width = ((width - 1) / NORMAL_TILE_WIDTH) + 1;
-  mapview_canvas.tile_height = ((height - 1) / NORMAL_TILE_HEIGHT) + 1;
-  
-  /* Since a resize is only triggered when the tile_*** changes, the canvas
-   * width and height must include the entire backing store - otherwise
-   * small resizings may lead to undrawn tiles. */
-  mapview_canvas.width = mapview_canvas.tile_width * NORMAL_TILE_WIDTH;
-  mapview_canvas.height = mapview_canvas.tile_height * NORMAL_TILE_HEIGHT;
-
-  if (mapview_canvas.store) {
-    canvas_store_free(mapview_canvas.store);
-  }
-  mapview_canvas.store =
-      canvas_store_create(mapview_canvas.width, mapview_canvas.height);
-  map_canvas_store = mapview_canvas.store->pixmap;
-}
-
-/**************************************************************************
   Draw some or all of a tile onto the mapview canvas.
 **************************************************************************/
 void gui_map_put_tile_iso(int map_x, int map_y,
@@ -702,6 +658,14 @@
 
   XawScrollbarSetThumb(map_horizontal_scrollbar, top_h, shown_h);
   XawScrollbarSetThumb(map_vertical_scrollbar, top_v, shown_v);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void update_map_canvas_scrollbars_size(void)
+{
+  /* Nothing */
 }
 
 /**************************************************************************
Index: client/gui-xaw/mapview.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.h,v
retrieving revision 1.19
diff -u -u -r1.19 mapview.h
--- client/gui-xaw/mapview.h    2004/01/28 18:53:31     1.19
+++ client/gui-xaw/mapview.h    2004/02/04 15:00:44
@@ -37,7 +37,6 @@
                            void *client_data);
 void map_canvas_expose(Widget w, XEvent *event, Region exposed, 
                       void *client_data);
-void map_canvas_resize(void);
 
 void pixmap_put_black_tile(Pixmap pm, int canvas_x, int canvas_y);
 void pixmap_frame_tile_red(Pixmap pm, int canvas_x, int canvas_y);
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.42
diff -u -u -r1.42 mapview_g.h
--- client/include/mapview_g.h  2004/02/03 20:16:08     1.42
+++ client/include/mapview_g.h  2004/02/04 15:00:44
@@ -66,6 +66,7 @@
 void flush_dirty(void);
 
 void update_map_canvas_scrollbars(void);
+void update_map_canvas_scrollbars_size(void);
 
 void put_cross_overlay_tile(int x,int y);
 void put_city_workers(struct city *pcity, int color);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7375) Unify some mapview code, Raimar Falke <=