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

[Freeciv-Dev] Re: (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] Re: (PR#2941) RFC: canvas_put_sprite
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Mon, 3 Feb 2003 13:56:54 -0800
Reply-to: rt.freeciv.org@xxxxxxxxxxxxxx

Raimar Falke via RT wrote:
> On Fri, Jan 31, 2003 at 06:34:02PM -0800, Jason Short via RT wrote:
> 
>>[jdorje - Thu Jan 30 06:32:34 2003]:

>>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?
> 
> 
> Yes. Don't use void *. Both of "struct canvas { char dummy;};" or
> "typedef void *canvas_t." are better.

This version introduces a "typedef void canvas_t".  Eventually a struct 
canvas may be introduced, once we see more fully what is associated with 
a canvas (dimensions, origin, etc.).

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/03 21:54:39
@@ -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/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.20
diff -u -r1.20 mapview_common.h
--- client/mapview_common.h     2003/01/27 22:00:34     1.20
+++ client/mapview_common.h     2003/02/03 21:54:39
@@ -19,6 +19,7 @@
 #include "colors_g.h"
 
 struct unit;
+typedef void canvas_t;
 
 /*
 The bottom row of the map was sometimes hidden.
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.153
diff -u -r1.153 mapview.c
--- client/gui-gtk/mapview.c    2003/02/02 00:15:52     1.153
+++ client/gui-gtk/mapview.c    2003/02/03 21:54:39
@@ -897,18 +897,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.
 **************************************************************************/
@@ -1179,6 +1167,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(canvas_t *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.41
diff -u -r1.41 mapview.c
--- client/gui-gtk-2.0/mapview.c        2003/02/02 00:15:52     1.41
+++ client/gui-gtk-2.0/mapview.c        2003/02/03 21:54:40
@@ -926,18 +926,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.
 **************************************************************************/
@@ -1252,6 +1240,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(canvas_t *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.17
diff -u -r1.17 mapview.c
--- client/gui-sdl/mapview.c    2003/02/02 20:49:19     1.17
+++ client/gui-sdl/mapview.c    2003/02/03 21:54:42
@@ -201,14 +201,17 @@
 }
 
 /**************************************************************************
-  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(canvas_t *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;
+
+  /* FIXME: handle partial-sprite draws. */
+  assert(pcanvas == NULL);
+  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/03 21:54:42
@@ -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(canvas_t *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/03 21:54:42
@@ -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(canvas_t *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.120
diff -u -r1.120 mapview.c
--- client/gui-xaw/mapview.c    2003/02/02 00:15:52     1.120
+++ client/gui-xaw/mapview.c    2003/02/03 21:54:43
@@ -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(canvas_t *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);
 }
 
 /**************************************************************************
@@ -984,15 +1011,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/03 21:54:43
@@ -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(canvas_t *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]