[Freeciv-Dev] (PR#7672) get_mapview_window
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7672 >
The common client code is able to access the overview window. A
function get_overview_window is used.
We'd like to do this with the mapview window as well. This may not be
strictly necessary if all drawing to the window is buffered. However
some drawing is not buffered - and if we did buffer it performance would
be hurt (this is quite noticable with goto lines; see draw_line).
So either we have a global mapview_canvas.window or we have a
get_mapview_window function. Either way, we need to confront the design
problems that we face.
The problem is that windows aren't necessarily treated the same way as
backing stores. The clearest example of this is in gui-win32. Here we
cannot just write to the window, we must first Get and later Release a
"DC" for the window. Presumably the get/release operations are not
particularly efficient. We can hold onto the DC permanently (never
releasing it), but this _may_ cause problems because (1) on Win9x
systems there may be a limited number of DCs available and (2) some
later code may try to Get the same DC again. Another alternative is to
provide a release_mapview_window function, but IMO this is just
propogating the library's problem up into the core client code.
This patch implements get_mapview_window and uses it to move
put_cross_overlay_tile into the common code. For gui-win32 we Get the
DC and hold onto it permanently.
I think that this interface will work, but that the above method is bad.
We should Get and Release the DC each time we do a draw. This may be
slower but is probably more reliable.
Do any win32 developers have any ideas on this? And are there other
backends that will have a problem with this interface?
jason
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.87
diff -u -r1.87 mapview_common.c
--- client/mapview_common.c 8 Mar 2004 07:20:49 -0000 1.87
+++ client/mapview_common.c 8 Mar 2004 08:22:57 -0000
@@ -1603,6 +1603,24 @@
}
}
+/****************************************************************************
+ Draws a cross-hair overlay on a tile. It is drawn directly to the window
+ (not to the backing store).
+****************************************************************************/
+void put_cross_overlay_tile(int map_x, int map_y)
+{
+ int canvas_x, canvas_y, w, h;
+
+ if (map_to_canvas_pos(&canvas_x, &canvas_y, map_x, map_y)) {
+ get_sprite_dimensions(sprites.user.attention, &w, &h);
+
+ gui_put_sprite_full(get_mapview_window(),
+ canvas_x + (NORMAL_TILE_WIDTH - w) / 2,
+ canvas_y + (NORMAL_TILE_HEIGHT - h) / 2,
+ sprites.user.attention);
+ }
+}
+
/**************************************************************************
Find the "best" city to associate with the selected tile.
a. A city working the tile is the best
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.50
diff -u -r1.50 mapview_common.h
--- client/mapview_common.h 8 Mar 2004 07:20:49 -0000 1.50
+++ client/mapview_common.h 8 Mar 2004 08:22:57 -0000
@@ -194,6 +194,7 @@
struct unit *punit1, int hp1);
void move_unit_map_canvas(struct unit *punit,
int map_x, int map_y, int dx, int dy);
+void put_cross_overlay_tile(int map_x, int map_y);
struct city *find_city_near_tile(int x, int y);
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.203
diff -u -r1.203 mapview.c
--- client/gui-gtk/mapview.c 8 Mar 2004 07:20:49 -0000 1.203
+++ client/gui-gtk/mapview.c 8 Mar 2004 08:22:57 -0000
@@ -52,9 +52,6 @@
#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);
static void put_line(GdkDrawable *pm, int x, int y, int dir);
static void pixmap_put_overlay_tile_draw(GdkDrawable *pixmap,
@@ -333,6 +330,18 @@
}
/****************************************************************************
+ Return a canvas that is the mapview window.
+****************************************************************************/
+struct canvas *get_mapview_window(void)
+{
+ static struct canvas store;
+
+ store.pixmap = map_canvas->window;
+
+ return &store;
+}
+
+/****************************************************************************
Return a canvas that is the overview window.
****************************************************************************/
struct canvas *get_overview_window(void)
@@ -660,26 +669,6 @@
}
/**************************************************************************
-...
-**************************************************************************/
-static void pixmap_put_overlay_tile(GdkDrawable *pixmap,
- int canvas_x, int canvas_y,
- struct Sprite *ssprite)
-{
- if (!ssprite)
- return;
-
- gdk_gc_set_clip_origin(civ_gc, canvas_x, canvas_y);
- gdk_gc_set_clip_mask(civ_gc, ssprite->mask);
-
- gdk_draw_pixmap(pixmap, civ_gc, ssprite->pixmap,
- 0, 0,
- canvas_x, canvas_y,
- ssprite->width, ssprite->height);
- gdk_gc_set_clip_mask(civ_gc, NULL);
-}
-
-/**************************************************************************
Place part of a (possibly masked) sprite on a pixmap.
**************************************************************************/
static void pixmap_put_sprite(GdkDrawable *pixmap,
@@ -814,20 +803,6 @@
MIN(width, MAX(0, ssprite->width-offset_x)),
MIN(height, MAX(0, ssprite->height-offset_y)));
gdk_gc_set_clip_mask(fill_tile_gc, NULL);
- }
-}
-
-/**************************************************************************
- Draws a cross-hair overlay on a tile
-**************************************************************************/
-void put_cross_overlay_tile(int x, int y)
-{
- int canvas_x, canvas_y;
-
- if (map_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
- pixmap_put_overlay_tile(map_canvas->window,
- canvas_x, canvas_y,
- sprites.user.attention);
}
}
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.103
diff -u -r1.103 mapview.c
--- client/gui-gtk-2.0/mapview.c 8 Mar 2004 07:20:49 -0000 1.103
+++ client/gui-gtk-2.0/mapview.c 8 Mar 2004 08:22:57 -0000
@@ -53,9 +53,6 @@
#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);
static void put_line(GdkDrawable *pm, int x, int y, int dir);
static void pixmap_put_overlay_tile_draw(GdkDrawable *pixmap,
@@ -379,6 +376,18 @@
}
/****************************************************************************
+ Return a canvas that is the mapview window.
+****************************************************************************/
+struct canvas *get_mapview_window(void)
+{
+ static struct canvas store;
+
+ store.pixmap = map_canvas->window;
+
+ return &store;
+}
+
+/****************************************************************************
Return a canvas that is the overview window.
****************************************************************************/
struct canvas *get_overview_window(void)
@@ -730,26 +739,6 @@
}
/**************************************************************************
-...
-**************************************************************************/
-static void pixmap_put_overlay_tile(GdkDrawable *pixmap,
- int canvas_x, int canvas_y,
- struct Sprite *ssprite)
-{
- if (!ssprite)
- return;
-
- gdk_gc_set_clip_origin(civ_gc, canvas_x, canvas_y);
- gdk_gc_set_clip_mask(civ_gc, ssprite->mask);
-
- gdk_draw_drawable(pixmap, civ_gc, ssprite->pixmap,
- 0, 0,
- canvas_x, canvas_y,
- ssprite->width, ssprite->height);
- gdk_gc_set_clip_mask(civ_gc, NULL);
-}
-
-/**************************************************************************
Place part of a (possibly masked) sprite on a pixmap.
**************************************************************************/
static void pixmap_put_sprite(GdkDrawable *pixmap,
@@ -895,20 +884,6 @@
MIN(width, MAX(0, ssprite->width-offset_x)),
MIN(height, MAX(0, ssprite->height-offset_y)));
gdk_gc_set_clip_mask(fill_tile_gc, NULL);
- }
-}
-
-/**************************************************************************
- Draws a cross-hair overlay on a tile
-**************************************************************************/
-void put_cross_overlay_tile(int x, int y)
-{
- int canvas_x, canvas_y;
-
- if (map_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
- pixmap_put_overlay_tile(map_canvas->window,
- canvas_x, canvas_y,
- sprites.user.attention);
}
}
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.100
diff -u -r1.100 mapview.c
--- client/gui-win32/mapview.c 8 Mar 2004 07:20:50 -0000 1.100
+++ client/gui-win32/mapview.c 8 Mar 2004 08:22:57 -0000
@@ -107,6 +107,23 @@
free(store);
}
+/****************************************************************************
+ Return a canvas that is the mapview window.
+****************************************************************************/
+struct canvas *get_mapview_window(void)
+{
+ static struct canvas store;
+ static bool initted = FALSE;
+
+ if (!initted) {
+ /* HACK: we create a DC for the map window once and hold onto it. */
+ store.hdc = GetDC(map_window);
+ initted = TRUE;
+ }
+
+ return &store;
+}
+
static struct canvas overview_store;
/****************************************************************************
@@ -647,22 +664,6 @@
SelectObject(hdc, old);
DeleteDC(hdc);
-}
-
-/**************************************************************************
-
-**************************************************************************/
-void
-put_cross_overlay_tile(int x,int y)
-{
- HDC hdc;
- int canvas_x, canvas_y;
- get_canvas_xy(x, y, &canvas_x, &canvas_y);
- if (tile_visible_mapcanvas(x, y)) {
- hdc=GetDC(map_window);
- draw_sprite(sprites.user.attention,hdc,canvas_x,canvas_y);
- ReleaseDC(map_window,hdc);
- }
}
/**************************************************************************
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.166
diff -u -r1.166 mapview.c
--- client/gui-xaw/mapview.c 8 Mar 2004 07:20:50 -0000 1.166
+++ client/gui-xaw/mapview.c 8 Mar 2004 08:22:59 -0000
@@ -54,8 +54,6 @@
#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);
/* the intro picture is held in this pixmap, which is scaled to
@@ -104,6 +102,18 @@
}
/****************************************************************************
+ Return a canvas that is the mapview window.
+****************************************************************************/
+struct canvas *get_mapview_window(void)
+{
+ static struct canvas store;
+
+ store.pixmap = XtWindow(map_canvas);
+
+ return &store;
+}
+
+/****************************************************************************
Return a canvas that is the overview window.
****************************************************************************/
struct canvas *get_overview_window(void)
@@ -742,32 +752,6 @@
canvas_x, canvas_y,
NORMAL_TILE_WIDTH, NORMAL_TILE_HEIGHT);
}
-
-/**************************************************************************
-...
-**************************************************************************/
-static void pixmap_put_overlay_tile(Pixmap pixmap, int canvas_x, int canvas_y,
- struct Sprite *ssprite)
-{
- if (!ssprite) return;
-
- pixmap_put_sprite(pixmap, canvas_x, canvas_y,
- ssprite, 0, 0, ssprite->width, ssprite->height);
-}
-
-/**************************************************************************
- Draws a cross-hair overlay on a tile
-**************************************************************************/
-void put_cross_overlay_tile(int x,int y)
-{
- int canvas_x, canvas_y;
-
- if (map_to_canvas_pos(&canvas_x, &canvas_y, x, y)) {
- pixmap_put_overlay_tile(XtWindow(map_canvas), canvas_x, canvas_y,
- sprites.user.attention);
- }
-}
-
/**************************************************************************
Shade the tiles around a city to indicate the location of workers
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.48
diff -u -r1.48 mapview_g.h
--- client/include/mapview_g.h 8 Mar 2004 07:20:50 -0000 1.48
+++ client/include/mapview_g.h 8 Mar 2004 08:22:59 -0000
@@ -31,6 +31,8 @@
void map_size_changed(void);
struct canvas *canvas_store_create(int width, int height);
void canvas_store_free(struct canvas *store);
+
+struct canvas *get_mapview_window(void);
struct canvas *get_overview_window(void);
void show_city_desc(struct city *pcity, int canvas_x, int canvas_y);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#7672) get_mapview_window,
Jason Short <=
|
|