Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] Re: (PR#2269) PNG for freeciv
Home

[Freeciv-Dev] Re: (PR#2269) PNG for freeciv

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2269) PNG for freeciv
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Tue, 5 Nov 2002 15:33:53 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Jason Short via RT wrote:

> GTK2 support is easy; GdkPixbuf will load a PNG just as happily as an 
> XPM (and faster).  But it has to know the name of the file - this just 
> means adding a new entry to gfx_fileextensions.  Patch attached.  (When 
> loading PNG graphics under this patch, the GTK2 client gives all sorts 
> of warnings.  Vasco?)
> 
> GTK uses imlib - it works similarly (it even has the same warning messages).

It looks like when imlib loads an XPM, it always generates a mask.  But 
when it loads a PNG, it will not generate a mask if it is not necessary. 
  The mask therefore becomes NULL and has_mask is set to 0 [1].  In 
crop_sprite, we crop the mask as well as the sprite - without checking 
for this situation.  Thus we get lots of GDK warnings.

GdkPixbuf works similarly.

The attached patches fix this for GTK and GTK2.  In the process they get 
rid of ctor_sprite() (which was previously unused) and gives 
ctor_sprite_mask() its functionality if the mask is NULL.

[1] This should be a bool, not an int.  But that's a different issue.

jason

Index: client/gui-gtk/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/graphics.c,v
retrieving revision 1.44
diff -u -r1.44 graphics.c
--- client/gui-gtk/graphics.c   2002/11/05 21:00:45     1.44
+++ client/gui-gtk/graphics.c   2002/11/05 23:30:45
@@ -168,19 +168,21 @@
                           int x, int y,
                           int width, int height)
 {
-  GdkPixmap *mypixmap, *mask;
+  GdkPixmap *mypixmap, *mask = NULL;
 
   mypixmap = gdk_pixmap_new(root_window, width, height, -1);
 
   gdk_draw_pixmap(mypixmap, civ_gc, source->pixmap, x, y, 0, 0,
                  width, height);
 
-  mask=gdk_pixmap_new(mask_bitmap, width, height, 1);
-  gdk_draw_rectangle(mask, mask_bg_gc, TRUE, 0, 0, -1, -1 );
-           
-  gdk_draw_pixmap(mask, mask_fg_gc, source->mask, x, y, 0, 0,
-                 width, height);
-  
+  if (source->has_mask) {
+    mask = gdk_pixmap_new(mask_bitmap, width, height, 1);
+    gdk_draw_rectangle(mask, mask_bg_gc, TRUE, 0, 0, -1, -1 );
+
+    gdk_draw_pixmap(mask, mask_fg_gc, source->mask,
+                   x, y, 0, 0, width, height);
+  }
+
   return ctor_sprite_mask(mypixmap, mask, width, height);
 }
 
@@ -249,25 +251,9 @@
   gdk_bitmap_unref(mask);
 }
 
-#ifdef UNUSED
-/***************************************************************************
-...
-***************************************************************************/
-static SPRITE *ctor_sprite( GdkPixmap *mypixmap, int width, int height )
-{
-    SPRITE *mysprite = fc_malloc(sizeof(SPRITE));
-
-    mysprite->pixmap   = mypixmap;
-    mysprite->width    = width;
-    mysprite->height   = height;
-    mysprite->has_mask = 0;
-
-    return mysprite;
-}
-#endif
-
 /***************************************************************************
-...
+ Create a new sprite with the given pixmap, dimensions, and
+ (optional) mask.
 ***************************************************************************/
 SPRITE *ctor_sprite_mask( GdkPixmap *mypixmap, GdkPixmap *mask, 
                          int width, int height )
@@ -275,11 +261,12 @@
     SPRITE *mysprite = fc_malloc(sizeof(SPRITE));
 
     mysprite->pixmap   = mypixmap;
-    mysprite->mask     = mask;
+
+    mysprite->has_mask = (mask != NULL);
+    mysprite->mask = mask;
 
     mysprite->width    = width;
     mysprite->height   = height;
-    mysprite->has_mask = 1;
 
     return mysprite;
 }
Index: client/gui-gtk-2.0/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.c,v
retrieving revision 1.8
diff -u -r1.8 graphics.c
--- client/gui-gtk-2.0/graphics.c       2002/11/05 21:00:45     1.8
+++ client/gui-gtk-2.0/graphics.c       2002/11/05 23:16:41
@@ -166,19 +166,21 @@
                           int x, int y,
                           int width, int height)
 {
-  GdkPixmap *mypixmap, *mask;
+  GdkPixmap *mypixmap, *mask = NULL;
 
   mypixmap = gdk_pixmap_new(root_window, width, height, -1);
 
   gdk_draw_pixmap(mypixmap, civ_gc, source->pixmap, x, y, 0, 0,
                  width, height);
 
-  mask = gdk_pixmap_new(NULL, width, height, 1);
-  gdk_draw_rectangle(mask, mask_bg_gc, TRUE, 0, 0, -1, -1);
-           
-  gdk_draw_pixmap(mask, mask_fg_gc, source->mask, x, y, 0, 0,
-                 width, height);
-  
+  if (source->has_mask) {
+    mask = gdk_pixmap_new(NULL, width, height, 1);
+    gdk_draw_rectangle(mask, mask_bg_gc, TRUE, 0, 0, -1, -1);
+
+    gdk_draw_pixmap(mask, mask_fg_gc, source->mask,
+                   x, y, 0, 0, width, height);
+  }
+
   return ctor_sprite_mask(mypixmap, mask, width, height);
 }
 
@@ -247,25 +249,9 @@
   gdk_bitmap_unref(mask);
 }
 
-#ifdef UNUSED
-/***************************************************************************
-...
-***************************************************************************/
-static SPRITE *ctor_sprite( GdkPixmap *mypixmap, int width, int height )
-{
-    SPRITE *mysprite = fc_malloc(sizeof(SPRITE));
-
-    mysprite->pixmap   = mypixmap;
-    mysprite->width    = width;
-    mysprite->height   = height;
-    mysprite->has_mask = 0;
-
-    return mysprite;
-}
-#endif
-
 /***************************************************************************
-...
+ Create a new sprite with the given pixmap, dimensions, and
+ (optional) mask.
 ***************************************************************************/
 SPRITE *ctor_sprite_mask( GdkPixmap *mypixmap, GdkPixmap *mask, 
                          int width, int height )
@@ -273,11 +259,12 @@
     SPRITE *mysprite = fc_malloc(sizeof(SPRITE));
 
     mysprite->pixmap   = mypixmap;
-    mysprite->mask     = mask;
+
+    mysprite->has_mask = (mask != NULL);
+    mysprite->mask = mask;
 
     mysprite->width    = width;
     mysprite->height   = height;
-    mysprite->has_mask = 1;
 
     return mysprite;
 }

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