Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2941) RFC: canvas_put_sprite
Home

[Freeciv-Dev] (PR#2941) RFC: canvas_put_sprite

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2941) RFC: canvas_put_sprite
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Fri, 31 Jan 2003 18:34:02 -0800
Reply-to: rt@xxxxxxxxxxxxxx

[jdorje - Thu Jan 30 06:32:34 2003]:

> 3.  Introduce a single function, canvas_put_sprite(), that takes a
> void*
> (or a struct canvas *) as a parameter.  Now the function just draws
> the
> sprite onto the canvas that is specified.  In the case of the void*,
> this will probably just point to the pixmap/surface onto which the
> sprite will be drawn.  The problem here is that since the high-level
> mapview drawing routines are only designed for one mapview, we would
> need to introduce the hack that NULL refers to the "default" map
> canvas.
>   Later we can work to have all of these functions be passed (by the
> GUI) the parameter that specifies which map canvas.  (The city dialog
> functions will always be called by the GUI, so there is no trouble
> there
> for any of these 3 ideas.)  Using a struct canvas * instead means an
> additional level of indirection, but is slightly more type-safe (the
> NULL special case would still apply).  We might even be able to use a
> struct Sprite * that specifies the drawing target (again, with a NULL
> special-case).

This patch implements it this way, using a void*.  This is significantly
better IMO.  I could have introduced a struct canvas, but chose not to yet.

Does anybody have an opinion on this?

jason

Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.27
diff -u -r1.27 mapview_common.c
--- client/mapview_common.c     2003/01/31 09:09:58     1.27
+++ client/mapview_common.c     2003/02/01 00:00:26
@@ -495,9 +495,8 @@
                           width, height, height_unit,
                           draw);
     } else {
-      gui_map_put_black_tile_iso(canvas_x, canvas_y,
-                                offset_x, offset_y,
-                                width, height);
+      gui_put_sprite(NULL, canvas_x, canvas_y,
+                    sprites.black_tile, offset_x, offset_y, width, height);
     }
   }
 }
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.152
diff -u -r1.152 mapview.c
--- client/gui-gtk/mapview.c    2003/01/29 22:57:45     1.152
+++ client/gui-gtk/mapview.c    2003/02/01 00:00:27
@@ -903,18 +903,6 @@
 }
 
 /**************************************************************************
-  Draw some or all of a black tile onto the mapview canvas.
-**************************************************************************/
-void gui_map_put_black_tile_iso(int canvas_x, int canvas_y,
-                               int offset_x, int offset_y,
-                               int width, int height)
-{
-  pixmap_put_black_tile_iso(map_canvas_store, canvas_x, canvas_y,
-                           offset_x, offset_y,
-                           width, height);     
-}
-
-/**************************************************************************
   Flush the given part of the canvas buffer (if there is one) to the
   screen.
 **************************************************************************/
@@ -1185,6 +1173,19 @@
                  MIN(height, MAX(0, ssprite->height - offset_y)));
 
   gdk_gc_set_clip_mask(civ_gc, NULL);
+}
+
+/**************************************************************************
+  Draw some or all of a sprite onto the mapview or citydialog canvas.
+**************************************************************************/
+void gui_put_sprite(void *pcanvas, 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,
+                   sprite, offset_x, offset_y, width, 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.40
diff -u -r1.40 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/01/29 22:57:45     1.40
+++ client/gui-gtk-2.0/mapview.c        2003/02/01 00:00:28
@@ -932,18 +932,6 @@
 }
 
 /**************************************************************************
-  Draw some or all of a black tile onto the mapview canvas.
-**************************************************************************/
-void gui_map_put_black_tile_iso(int canvas_x, int canvas_y,
-                               int offset_x, int offset_y,
-                               int width, int height)
-{
-  pixmap_put_black_tile_iso(map_canvas_store, canvas_x, canvas_y,
-                           offset_x, offset_y,
-                           width, height);     
-}
-
-/**************************************************************************
   Flush the given part of the canvas buffer (if there is one) to the
   screen.
 **************************************************************************/
@@ -1258,6 +1246,19 @@
                  MIN(height, MAX(0, ssprite->height - offset_y)));
 
   gdk_gc_set_clip_mask(civ_gc, NULL);
+}
+
+/**************************************************************************
+  Draw some or all of a sprite onto the mapview or citydialog canvas.
+**************************************************************************/
+void gui_put_sprite(void *pcanvas, 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,
+                   sprite, offset_x, offset_y, width, height);
 }
 
 /**************************************************************************
Index: client/gui-sdl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/mapview.c,v
retrieving revision 1.15
diff -u -r1.15 mapview.c
--- client/gui-sdl/mapview.c    2003/01/31 17:29:06     1.15
+++ client/gui-sdl/mapview.c    2003/02/01 00:00:30
@@ -199,14 +199,15 @@
 }
 
 /**************************************************************************
-  Draw some or all of a black tile onto the mapview canvas.
+  Draw some or all of a sprite onto the mapview or citydialog canvas.
 **************************************************************************/
-void gui_map_put_black_tile_iso(int canvas_x, int canvas_y,
-                               int offset_x, int offset_y,
-                               int width, int height)
+void gui_put_sprite(void *pcanvas, int canvas_x, int canvas_y,
+                   struct Sprite *sprite,
+                   int offset_x, int offset_y, int width, int height)
 {
-  blit_entire_src((SDL_Surface *)sprites.black_tile,
-                 Main.screen, canvas_x, canvas_y);
+  SDL_Surface *surf = pcanvas ? pcanvas : Main.screen;
+
+  blit_entire_src((SDL_Surface *)sprite, 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.25
diff -u -r1.25 mapview.c
--- client/gui-stub/mapview.c   2003/01/29 22:57:46     1.25
+++ client/gui-stub/mapview.c   2003/02/01 00:00:30
@@ -205,11 +205,11 @@
 }
 
 /**************************************************************************
-  Draw some or all of a black tile onto the mapview canvas.
+  Draw some or all of a sprite onto the mapview or citydialog canvas.
 **************************************************************************/
-void gui_map_put_black_tile_iso(int canvas_x, int canvas_y,
-                               int offset_x, int offset_y,
-                               int width, int height)
+void gui_put_sprite(void *pcanvas, int canvas_x, int canvas_y,
+                   struct Sprite *sprite,
+                   int offset_x, int offset_y, int width, int height)
 {
   /* PORTME */
 }
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.53
diff -u -r1.53 mapview.c
--- client/gui-win32/mapview.c  2003/01/29 22:57:46     1.53
+++ client/gui-win32/mapview.c  2003/02/01 00:00:31
@@ -1351,22 +1351,23 @@
 }
 
 /**************************************************************************
-  Draw some or all of a black tile onto the mapview canvas.
+  Draw some or all of a sprite onto the mapview or citydialog canvas.
 **************************************************************************/
-void gui_map_put_black_tile_iso(int canvas_x, int canvas_y,
-                               int offset_x, int offset_y,
-                               int width, int height)
+void gui_put_sprite(void *pcanvas, int canvas_x, int canvas_y,
+                   struct Sprite *sprite,
+                   int offset_x, int offset_y, int width, int height)
 {
   HDC hdc;
   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);
 
-  pixmap_put_black_tile_iso(hdc, canvas_x, canvas_y,
-                           offset_x, offset_y,
-                           width, height);
+  pixmap_put_overlay_tile_draw(hdc, canvas_x, canvas_y,
+                              sprite, offset_x, offset_y,
+                              width, height, 0);
 
   SelectObject(hdc, old);
   DeleteDC(hdc);
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.119
diff -u -r1.119 mapview.c
--- client/gui-xaw/mapview.c    2003/01/29 22:57:46     1.119
+++ client/gui-xaw/mapview.c    2003/02/01 00:00:32
@@ -621,14 +621,41 @@
 }
 
 /**************************************************************************
-  Draw some or all of a black tile onto the mapview canvas.
+  Draw a single masked sprite to the pixmap.
 **************************************************************************/
-void gui_map_put_black_tile_iso(int canvas_x, int canvas_y,
-                               int offset_x, int offset_y,
-                               int width, int height)
+static void pixmap_put_sprite(Pixmap pixmap,
+                             int canvas_x, int canvas_y,
+                             struct Sprite *sprite,
+                             int offset_x, int offset_y,
+                             int width, int height)
+{
+  if (sprite->mask) {
+    XSetClipOrigin(display, civ_gc, canvas_x, canvas_y);
+    XSetClipMask(display, civ_gc, sprite->mask);
+  }
+
+  XCopyArea(display, sprite->pixmap, pixmap, 
+           civ_gc,
+           offset_x, offset_y,
+           width, height, 
+           canvas_x, canvas_y);
+
+  if (sprite->mask) {
+    XSetClipMask(display, civ_gc, None);
+  }
+}
+
+/**************************************************************************
+  Draw some or all of a sprite onto the mapview or citydialog canvas.
+**************************************************************************/
+void gui_put_sprite(void *pcanvas, int canvas_x, int canvas_y,
+                   struct Sprite *sprite,
+                   int offset_x, int offset_y, int width, int height)
 {
-  /* PORTME */
-  assert(0);
+  Pixmap pm = pcanvas ? *(Pixmap*)pcanvas : map_canvas_store;
+
+  pixmap_put_sprite(pm, canvas_x, canvas_y,
+                   sprite, offset_x, offset_y, width, height);
 }
 
 /**************************************************************************
@@ -990,15 +1017,9 @@
                                    struct Sprite *ssprite)
 {
   if (!ssprite) return;
-      
-  XSetClipOrigin(display, civ_gc, canvas_x, canvas_y);
-  XSetClipMask(display, civ_gc, ssprite->mask);
-      
-  XCopyArea(display, ssprite->pixmap, pixmap, 
-           civ_gc, 0, 0,
-           ssprite->width, ssprite->height, 
-           canvas_x, canvas_y);
-  XSetClipMask(display, civ_gc, None); 
+
+  pixmap_put_sprite(pixmap, canvas_x, canvas_y,
+                   ssprite, 0, 0, ssprite->width, ssprite->height);
 }
 
 /**************************************************************************
Index: client/include/mapview_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/mapview_g.h,v
retrieving revision 1.30
diff -u -r1.30 mapview_g.h
--- client/include/mapview_g.h  2003/01/29 22:57:46     1.30
+++ client/include/mapview_g.h  2003/02/01 00:00:32
@@ -44,9 +44,11 @@
                          int offset_x, int offset_y, int offset_y_unit,
                          int width, int height, int height_unit,
                          enum draw_type draw);
-void gui_map_put_black_tile_iso(int canvas_x, int canvas_y,
-                               int offset_x, int offset_y,
-                               int width, int height);
+void gui_put_sprite(void *pcanvas,
+                   int canvas_x, int canvas_y,
+                   struct Sprite *sprite,
+                   int offset_x, int offset_y,
+                   int width, int height);
 void flush_mapcanvas(int canvas_x, int canvas_y,
                     int pixel_width, int pixel_height);
 

[Prev in Thread] Current Thread [Next in Thread]