[Freeciv-Dev] Re: (PR#7375) Unify some mapview code
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7375 >
On Wed, Feb 04, 2004 at 12:31:53PM -0800, Raimar Falke wrote:
>
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=7375 >
>
> On Wed, Feb 04, 2004 at 07:11:18AM -0800, Raimar Falke wrote:
> >
> > <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.
>
> Changes:
> - also change GTK2 client
- correct use of init_mapcanvas_and_overview in gtk2
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"From what I am reading Win98 and NT5.0 will be getting rid of all that
crap anyway. Seems that Microsoft has invented something called TCP/IP and
another really revolutionary concept called DNS that eliminates the
netbios crap too. All that arping from browsers is going to go away.
I also hear rumors that they are on the verge of breakthrough discoveries
called NFS, and LPD too. Given enough time and money, they might
eventually invent Unix."
-- George Bonser in linux-kernel
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 20:53:22
@@ -22,6 +22,7 @@
#include "support.h"
#include "timing.h"
+#include "civclient.h"
#include "climap.h"
#include "control.h"
#include "goto.h"
@@ -1719,7 +1720,70 @@
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() && can_client_change_view()) {
+ update_map_canvas_visible();
+
+ update_map_canvas_scrollbars_size();
+ update_map_canvas_scrollbars();
+ refresh_overview_canvas();
+ }
+
+ 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 20:53:22
@@ -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 20:53:23
@@ -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 20:53:23
@@ -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 20:53:25
@@ -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-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.65
diff -u -u -r1.65 gui_main.c
--- client/gui-gtk-2.0/gui_main.c 2004/02/04 20:06:12 1.65
+++ client/gui-gtk-2.0/gui_main.c 2004/02/04 20:53:26
@@ -73,8 +73,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 */
GdkPixmap *overview_canvas_store; /* this pixmap acts as a backing store
@@ -1194,7 +1192,8 @@
timer_id = gtk_timeout_add(TIMER_INTERVAL, timer_callback, NULL);
- overview.store = NULL;
+ init_mapcanvas_and_overview();
+
overview.window = fc_malloc(sizeof(*overview.window));
overview.window->pixmap = overview_canvas->window;
overview.window->pixcomm = NULL;
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.9
diff -u -u -r1.9 gui_main.h
--- client/gui-gtk-2.0/gui_main.h 2003/07/23 13:46:02 1.9
+++ client/gui-gtk-2.0/gui_main.h 2004/02/04 20:53:26
@@ -42,10 +42,6 @@
extern GdkPixmap * gray25;
extern GdkPixmap * black50;
extern GdkPixmap * mask_bitmap;
-extern GdkPixmap * map_canvas_store;
-extern GdkPixmap * overview_canvas_store;
-extern int overview_canvas_store_width;
-extern int overview_canvas_store_height;
extern GdkPixmap * single_tile_pixmap;
extern GtkTextView * main_message_area;
extern GtkWidget * text_scrollbar;
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.90
diff -u -u -r1.90 mapview.c
--- client/gui-gtk-2.0/mapview.c 2004/02/04 20:06:12 1.90
+++ client/gui-gtk-2.0/mapview.c 2004/02/04 20:53:27
@@ -51,6 +51,8 @@
#include "citydlg.h" /* For reset_city_dialogs() */
#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);
@@ -478,54 +480,10 @@
static bool map_center = TRUE;
static bool map_configure = FALSE;
-gboolean map_canvas_configure(GtkWidget *w, GdkEventConfigure *ev,
+gboolean map_canvas_configure(GtkWidget * w, GdkEventConfigure * ev,
gpointer data)
{
- int tile_width, tile_height;
-
- tile_width = (ev->width + NORMAL_TILE_WIDTH - 1) / NORMAL_TILE_WIDTH;
- tile_height = (ev->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;
-
- /* Check if we resized the mapview. */
- if (mapview_canvas.tile_width != tile_width
- || mapview_canvas.tile_height != tile_height) {
-
- if (map_canvas_store) {
- g_object_unref(map_canvas_store);
- }
-
- mapview_canvas.tile_width = tile_width;
- mapview_canvas.tile_height = tile_height;
-
- map_canvas_store = gdk_pixmap_new(ev->window,
- tile_width * NORMAL_TILE_WIDTH,
- tile_height * NORMAL_TILE_HEIGHT,
- -1);
-
- if (!mapview_canvas.store) {
- mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
- }
- mapview_canvas.store->pixmap = map_canvas_store;
- mapview_canvas.store->pixcomm = NULL;
-
- gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
- gdk_draw_rectangle(map_canvas_store, fill_bg_gc, TRUE, 0, 0, -1, -1);
- update_map_canvas_scrollbars_size();
-
- if (can_client_change_view()) {
- if (map_exists()) { /* do we have a map at all */
- update_map_canvas_visible();
- update_map_canvas_scrollbars();
- refresh_overview_canvas();
- }
- }
-
+ if (map_canvas_resized(ev->width, ev->height)) {
map_configure = TRUE;
}
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 20:53:28
@@ -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 20:53:28
@@ -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 20:53:29
@@ -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 20:53:29
@@ -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 20:53:29
@@ -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);
|
|