[Freeciv-Dev] (PR#3453) canvas and canvas_store structures
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Raimar is not happy with using a void* to pass around information about
the mapview and citydlg canvases.
The alternative I have come up with introduces a new GUI struct, 'struct
canvas_store'. This stores information about the map buffer (which may
be just one of several canvas buffers in use) for that particular
canvas. It is (or, will be) passed around instead of the canvas_t
*canvas when calling GUI drawing functions.
At the same time I introduce the 'struct canvas' which stores
information about the underlying canvas. This is primarily useful for
the mapview - currently all the mapview information is stored by the GUI
and accessed through functions, but it would be easier (and faster) to
store it all in one location.
This patch should be considered a design change; I will follow it up
with patches that:
- Remove the map_canvas_store variable from many GUIs (xaw, gtk, gtk2)
- Move the additional canvas parameters for the mapview into
mapview_canvas variable.
- Use those variables instead of calling the accessor functions.
These changes are fairly easy (but will have large diffs) once the cure
functionality is in place.
(Note, this patch supercedes the put_one_tile patch, PR#3017.)
jason
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.29
diff -u -r1.29 mapview_common.c
--- client/mapview_common.c 2003/02/08 22:52:45 1.29
+++ client/mapview_common.c 2003/02/17 00:19:36
@@ -29,6 +29,8 @@
#include "mapview_common.h"
#include "tilespec.h"
+struct canvas mapview_canvas;
+
/**************************************************************************
Refreshes a single tile on the map canvas.
**************************************************************************/
@@ -504,7 +506,7 @@
width, height, height_unit,
draw);
} else {
- gui_put_sprite(NULL, canvas_x, canvas_y,
+ gui_put_sprite(mapview_canvas.store, canvas_x, canvas_y,
sprites.black_tile, offset_x, offset_y, width, height);
}
}
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.21
diff -u -r1.21 mapview_common.h
--- client/mapview_common.h 2003/02/07 08:35:02 1.21
+++ client/mapview_common.h 2003/02/17 00:19:36
@@ -19,7 +19,18 @@
#include "colors_g.h"
struct unit;
-typedef void canvas_t;
+struct canvas_store;
+
+struct canvas {
+#if 0 /* These values are still in the GUI. */
+ int map_x0, map_y0;
+ int width, height;
+ int tile_width, tile_height;
+#endif
+ struct canvas_store *store;
+};
+
+extern struct canvas mapview_canvas;
/*
The bottom row of the map was sometimes hidden.
Index: client/gui-gtk/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/graphics.h,v
retrieving revision 1.11
diff -u -r1.11 graphics.h
--- client/gui-gtk/graphics.h 2002/09/28 03:33:09 1.11
+++ client/gui-gtk/graphics.h 2003/02/17 00:19:36
@@ -26,6 +26,11 @@
int height;
};
+struct canvas_store
+{
+ GdkPixmap *pixmap;
+};
+
typedef struct Sprite SPRITE;
void create_overlay_unit (GtkWidget *pixcomm, int i);
Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.128
diff -u -r1.128 gui_main.c
--- client/gui-gtk/gui_main.c 2003/02/12 22:49:51 1.128
+++ client/gui-gtk/gui_main.c 2003/02/17 00:19:36
@@ -918,6 +918,8 @@
map_canvas_store_twidth * NORMAL_TILE_WIDTH,
map_canvas_store_theight * NORMAL_TILE_HEIGHT,
-1);
+ mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
+ mapview_canvas.store->pixmap = map_canvas_store;
overview_canvas_store = gdk_pixmap_new(root_window,
overview_canvas_store_width,
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.155
diff -u -r1.155 mapview.c
--- client/gui-gtk/mapview.c 2003/02/08 22:52:46 1.155
+++ client/gui-gtk/mapview.c 2003/02/17 00:19:37
@@ -717,6 +717,7 @@
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,
@@ -1171,13 +1172,12 @@
/**************************************************************************
Draw some or all of a sprite onto the mapview or citydialog canvas.
**************************************************************************/
-void gui_put_sprite(canvas_t *pcanvas, int canvas_x, int canvas_y,
+void gui_put_sprite(struct canvas_store *pcanvas_store,
+ int canvas_x, int canvas_y,
struct Sprite *sprite,
int offset_x, int offset_y, int width, int height)
{
- GdkPixmap *pm = pcanvas ? pcanvas : map_canvas_store;
-
- pixmap_put_sprite(pm, canvas_x, canvas_y,
+ pixmap_put_sprite(pcanvas_store->pixmap, canvas_x, canvas_y,
sprite, offset_x, offset_y, width, height);
}
Index: client/gui-gtk-2.0/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.h,v
retrieving revision 1.2
diff -u -r1.2 graphics.h
--- client/gui-gtk-2.0/graphics.h 2002/10/13 23:23:31 1.2
+++ client/gui-gtk-2.0/graphics.h 2003/02/17 00:19:37
@@ -26,6 +26,11 @@
int height;
};
+struct canvas_store
+{
+ GdkPixmap *pixmap;
+};
+
typedef struct Sprite SPRITE;
void create_overlay_unit (GtkWidget *pixcomm, int i);
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.43
diff -u -r1.43 mapview.c
--- client/gui-gtk-2.0/mapview.c 2003/02/08 22:52:46 1.43
+++ client/gui-gtk-2.0/mapview.c 2003/02/17 00:19:38
@@ -29,6 +29,7 @@
#include "government.h" /* government_graphic() */
#include "log.h"
#include "map.h"
+#include "mem.h"
#include "player.h"
#include "rand.h"
#include "support.h"
@@ -722,6 +723,11 @@
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;
+
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();
@@ -1244,13 +1250,12 @@
/**************************************************************************
Draw some or all of a sprite onto the mapview or citydialog canvas.
**************************************************************************/
-void gui_put_sprite(canvas_t *pcanvas, int canvas_x, int canvas_y,
+void gui_put_sprite(struct canvas_store *pcanvas_store,
+ int canvas_x, int canvas_y,
struct Sprite *sprite,
int offset_x, int offset_y, int width, int height)
{
- GdkPixmap *pm = pcanvas ? pcanvas : map_canvas_store;
-
- pixmap_put_sprite(pm, canvas_x, canvas_y,
+ pixmap_put_sprite(pcanvas_store->pixmap, canvas_x, canvas_y,
sprite, offset_x, offset_y, width, height);
}
Index: client/gui-sdl/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/graphics.c,v
retrieving revision 1.11
diff -u -r1.11 graphics.c
--- client/gui-sdl/graphics.c 2003/02/14 17:16:23 1.11
+++ client/gui-sdl/graphics.c 2003/02/17 00:19:39
@@ -708,6 +708,9 @@
Main.screen = NULL;
Main.rects_count = 0;
+ mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
+ mapview_canvas.store->surf = NULL;
+
iFlags |= SDL_INIT_NOPARACHUTE;
if (SDL_WasInit(SDL_INIT_AUDIO)) {
@@ -787,6 +790,7 @@
exit(-30);
}
+ mapview_canvas.store->surf = Main.screen;
freelog(LOG_DEBUG, _("(File %s %d): "
"Setting resolution to: %d x %d %d bpp"),
Index: client/gui-sdl/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/graphics.h,v
retrieving revision 1.5
diff -u -r1.5 graphics.h
--- client/gui-sdl/graphics.h 2003/01/30 19:09:26 1.5
+++ client/gui-sdl/graphics.h 2003/02/17 00:19:39
@@ -36,6 +36,10 @@
#define GET_SURF(s) fc__extension((SDL_Surface *)s)
#define GET_SPRI(s) fc__extension((struct Sprite *)s)
+struct canvas_store {
+ struct SDL_Surface *surf;
+};
+
struct Sdl {
int rects_count; /* update rect. list counter */
SDL_Rect rects[RECT_LIMIT]; /* update rect. list */
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.20
diff -u -r1.20 mapview.c
--- client/gui-sdl/mapview.c 2003/02/10 21:43:41 1.20
+++ client/gui-sdl/mapview.c 2003/02/17 00:19:40
@@ -202,15 +202,14 @@
/**************************************************************************
Draw some or all of a sprite onto the mapview or citydialog canvas.
**************************************************************************/
-void gui_put_sprite(canvas_t *pcanvas, int canvas_x, int canvas_y,
+void gui_put_sprite(struct canvas_store *pcanvas_store,
+ int canvas_x, int canvas_y,
struct Sprite *sprite,
int offset_x, int offset_y, int width, int height)
{
- SDL_Surface *surf = pcanvas ? pcanvas : Main.screen;
-
/* FIXME: handle partial-sprite draws. */
- assert(pcanvas == NULL);
- blit_entire_src((SDL_Surface *)sprite, surf, canvas_x, canvas_y);
+ blit_entire_src(GET_SURF(sprite), pcanvas_store->surf,
+ canvas_x, canvas_y);
}
void flush_mapcanvas( int canvas_x , int canvas_y ,
Index: client/gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.26
diff -u -r1.26 mapview.c
--- client/gui-stub/mapview.c 2003/02/07 08:35:03 1.26
+++ client/gui-stub/mapview.c 2003/02/17 00:19:40
@@ -207,7 +207,8 @@
/**************************************************************************
Draw some or all of a sprite onto the mapview or citydialog canvas.
**************************************************************************/
-void gui_put_sprite(canvas_t *pcanvas, int canvas_x, int canvas_y,
+void gui_put_sprite(struct canvas_store *pcanvas_store,
+ int canvas_x, int canvas_y,
struct Sprite *sprite,
int offset_x, int offset_y, int width, int height)
{
Index: client/gui-win32/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/graphics.h,v
retrieving revision 1.5
diff -u -r1.5 graphics.h
--- client/gui-win32/graphics.h 2002/12/07 09:59:18 1.5
+++ client/gui-win32/graphics.h 2003/02/17 00:19:40
@@ -35,6 +35,13 @@
int height;
int cache_id;
};
+
+struct canvas_store
+{
+ HDC hdc;
+ HBITMAP bitmap;
+};
+
void draw_sprite(struct Sprite *sprite,HDC hdc,int x, int y);
void draw_sprite_part(struct Sprite *sprite,HDC hdc,
int x, int y, int w, int h,int xsrc,int ysrc);
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.55
diff -u -r1.55 mapview.c
--- client/gui-win32/mapview.c 2003/02/08 22:52:46 1.55
+++ client/gui-win32/mapview.c 2003/02/17 00:19:41
@@ -113,6 +113,12 @@
if (mapstorebitmap) DeleteObject(mapstorebitmap);
mapstorebitmap=newbmp;
ReleaseDC(map_window,hdc);
+
+ if (!mapview_canvas.store) {
+ mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
+ }
+ mapview_canvas.store->hdc = NULL;
+ mapview_canvas.store->bitmap = mapstorebitmap;
map_view_width=(map_win_width+NORMAL_TILE_WIDTH-1)/NORMAL_TILE_WIDTH;
map_view_height=(map_win_height+NORMAL_TILE_HEIGHT-1)/NORMAL_TILE_HEIGHT;
@@ -1355,7 +1361,8 @@
/**************************************************************************
Draw some or all of a sprite onto the mapview or citydialog canvas.
**************************************************************************/
-void gui_put_sprite(canvas_t *pcanvas, int canvas_x, int canvas_y,
+void gui_put_sprite(struct canvas_store *pcanvas_store,
+ int canvas_x, int canvas_y,
struct Sprite *sprite,
int offset_x, int offset_y, int width, int height)
{
@@ -1363,9 +1370,8 @@
HBITMAP old;
/* FIXME: we don't want to have to recreate the hdc each time! */
- assert(pcanvas == NULL);
- hdc = CreateCompatibleDC(NULL);
- old = SelectObject(hdc, mapstorebitmap);
+ hdc = CreateCompatibleDC(pcanvas_store->hdc);
+ old = SelectObject(hdc, panvas_store->bitmap);
pixmap_put_overlay_tile_draw(hdc, canvas_x, canvas_y,
sprite, offset_x, offset_y,
Index: client/gui-xaw/graphics.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/graphics.h,v
retrieving revision 1.8
diff -u -r1.8 graphics.h
--- client/gui-xaw/graphics.h 2001/01/30 23:38:53 1.8
+++ client/gui-xaw/graphics.h 2003/02/17 00:19:41
@@ -24,6 +24,10 @@
int has_mask;
};
+struct canvas_store {
+ Pixmap pixmap;
+};
+
Pixmap create_overlay_unit(int i);
extern struct Sprite *intro_gfx_sprite;
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.122
diff -u -r1.122 mapview.c
--- client/gui-xaw/mapview.c 2003/02/08 22:52:46 1.122
+++ client/gui-xaw/mapview.c 2003/02/17 00:19:42
@@ -30,6 +30,7 @@
#include "game.h"
#include "government.h" /* government_graphic() */
#include "map.h"
+#include "mem.h"
#include "player.h"
#include "rand.h"
#include "support.h"
@@ -594,6 +595,11 @@
map_canvas_store_twidth*NORMAL_TILE_WIDTH,
map_canvas_store_theight*NORMAL_TILE_HEIGHT,
display_depth);
+
+ if (!mapview_canvas.store) {
+ mapview_canvas.store = fc_malloc(sizeof(*mapview_canvas.store));
+ }
+ mapview_canvas.store->pixmap = map_canvas_store;
}
/**************************************************************************
@@ -647,13 +653,12 @@
/**************************************************************************
Draw some or all of a sprite onto the mapview or citydialog canvas.
**************************************************************************/
-void gui_put_sprite(canvas_t *pcanvas, int canvas_x, int canvas_y,
+void gui_put_sprite(struct canvas_store *pcanvas_store,
+ int canvas_x, int canvas_y,
struct Sprite *sprite,
int offset_x, int offset_y, int width, int height)
{
- Pixmap pm = pcanvas ? *(Pixmap*)pcanvas : map_canvas_store;
-
- pixmap_put_sprite(pm, canvas_x, canvas_y,
+ pixmap_put_sprite(pcanvas_store->pixmap, canvas_x, canvas_y,
sprite, offset_x, offset_y, width, height);
}
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.31
diff -u -r1.31 mapview_g.h
--- client/include/mapview_g.h 2003/02/07 08:35:03 1.31
+++ client/include/mapview_g.h 2003/02/17 00:19:42
@@ -44,7 +44,7 @@
int offset_x, int offset_y, int offset_y_unit,
int width, int height, int height_unit,
enum draw_type draw);
-void gui_put_sprite(canvas_t *pcanvas,
+void gui_put_sprite(struct canvas_store *pcanvas_store,
int canvas_x, int canvas_y,
struct Sprite *sprite,
int offset_x, int offset_y,
- [Freeciv-Dev] (PR#3453) canvas and canvas_store structures,
Jason Short <=
|
|