Mercurial > dwindows
comparison gtk/dw.c @ 1249:b31056c321a2
Got dw_pixmap_stretch_bitblt() mostly working for GTK2...
Haven't figured out how to apply the alpha mask to the converted pixbuf yet.
This won't be supported on GTK1 at all.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 19 Oct 2011 21:29:23 +0000 |
parents | c228c90f95cb |
children | 28c2c7e6671c |
comparison
equal
deleted
inserted
replaced
1248:398ac8c90317 | 1249:b31056c321a2 |
---|---|
8724 else if(srcp) | 8724 else if(srcp) |
8725 gc = gdk_gc_new(srcp->pixmap); | 8725 gc = gdk_gc_new(srcp->pixmap); |
8726 | 8726 |
8727 if ( gc ) | 8727 if ( gc ) |
8728 { | 8728 { |
8729 /* | |
8730 * If we have a bitmap (mask) in the source pixmap, then set the clipping region | |
8731 */ | |
8732 if ( srcp && srcp->bitmap ) | |
8733 { | |
8734 gdk_gc_set_clip_mask( gc, srcp->bitmap ); | |
8735 gdk_gc_set_clip_origin( gc, xdest, ydest ); | |
8736 } | |
8737 | |
8738 #if GTK_MAJOR_VERSION > 1 | 8729 #if GTK_MAJOR_VERSION > 1 |
8739 if(srcwidth != -1) | 8730 if(srcwidth != -1) |
8740 { | 8731 { |
8741 GdkPixbuf *pbdst, *pbsrc = gdk_pixbuf_get_from_drawable(NULL, src ? src->window : srcp->pixmap, NULL, xsrc, ysrc, 0, 0, srcwidth, srcheight); | 8732 /* There are no scaling functions for pixmaps/bitmaps so we need to convert |
8733 * the drawable to a pixbuf, scale it to the correct size for the bitblt then | |
8734 * draw the resulting scaled copy and free the left over pixbufs. | |
8735 */ | |
8736 GdkPixbuf *pbdst, *pbsrc = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, srcwidth, srcheight); | |
8737 /* Now that with have a pixbuf with alpha, copy from the drawable to create the source */ | |
8738 gdk_pixbuf_get_from_drawable(pbsrc, src ? src->window : srcp->pixmap, NULL, xsrc, ysrc, 0, 0, srcwidth, srcheight); | |
8742 | 8739 |
8740 /* If the pixmap has an associated alpha mask, include that in the pixbuf */ | |
8741 //if( srcp && srcp->bitmap ) | |
8742 // Need to apply the mask to the pixmap if possible here | |
8743 /* Scale the pixbuf to the desired size */ | |
8744 pbdst = gdk_pixbuf_scale_simple(pbsrc, width, height, GDK_INTERP_BILINEAR); | |
8745 /* Create a new clipping mask from the scaled pixbuf */ | |
8743 if( srcp && srcp->bitmap ) | 8746 if( srcp && srcp->bitmap ) |
8744 gdk_pixbuf_render_threshold_alpha(pbsrc, srcp->bitmap, xsrc, ysrc, 0, 0, srcwidth, srcheight, 255); | 8747 { |
8745 pbdst = gdk_pixbuf_scale_simple(pbsrc, width, height, GDK_INTERP_BILINEAR); | 8748 GdkBitmap *bitmap = gdk_pixmap_new(NULL, width, height, 1); |
8749 gdk_pixbuf_render_threshold_alpha(pbdst, bitmap, 0, 0, 0, 0, width, height, 1); | |
8750 gdk_gc_set_clip_mask( gc, bitmap ); | |
8751 gdk_gc_set_clip_origin( gc, xdest, ydest ); | |
8752 gdk_bitmap_unref(bitmap); | |
8753 } | |
8754 /* Draw the final pixbuf onto the destination drawable */ | |
8746 gdk_draw_pixbuf(dest ? dest->window : destp->pixmap, gc, pbdst, 0, 0, xdest, ydest, width, height, GDK_RGB_DITHER_NONE, 0, 0); | 8755 gdk_draw_pixbuf(dest ? dest->window : destp->pixmap, gc, pbdst, 0, 0, xdest, ydest, width, height, GDK_RGB_DITHER_NONE, 0, 0); |
8756 /* Cleanup so we don't leak */ | |
8747 gdk_pixbuf_unref(pbsrc); | 8757 gdk_pixbuf_unref(pbsrc); |
8748 gdk_pixbuf_unref(pbdst); | 8758 gdk_pixbuf_unref(pbdst); |
8749 } | 8759 } |
8750 else | 8760 else |
8751 #endif | 8761 #endif |
8762 { | |
8763 /* | |
8764 * If we have a bitmap (mask) in the source pixmap, then set the clipping region | |
8765 */ | |
8766 if ( srcp && srcp->bitmap ) | |
8767 { | |
8768 gdk_gc_set_clip_mask( gc, srcp->bitmap ); | |
8769 gdk_gc_set_clip_origin( gc, xdest, ydest ); | |
8770 } | |
8752 gdk_draw_pixmap( dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height ); | 8771 gdk_draw_pixmap( dest ? dest->window : destp->pixmap, gc, src ? src->window : srcp->pixmap, xsrc, ysrc, xdest, ydest, width, height ); |
8772 | |
8773 } | |
8753 | 8774 |
8754 /* | 8775 /* |
8755 * Reset the clipping region | 8776 * Reset the clipping region |
8756 */ | 8777 */ |
8757 if ( srcp && srcp->bitmap ) | 8778 if ( srcp && srcp->bitmap ) |
8758 { | 8779 { |
8759 gdk_gc_set_clip_mask( gc, NULL ); | 8780 gdk_gc_set_clip_mask( gc, NULL ); |
8760 gdk_gc_set_clip_origin( gc, 0, 0 ); | 8781 gdk_gc_set_clip_origin( gc, 0, 0 ); |
8761 } | 8782 } |
8783 | |
8762 gdk_gc_unref( gc ); | 8784 gdk_gc_unref( gc ); |
8763 retval = DW_ERROR_NONE; | 8785 retval = DW_ERROR_NONE; |
8764 } | 8786 } |
8765 DW_MUTEX_UNLOCK; | 8787 DW_MUTEX_UNLOCK; |
8766 return retval; | 8788 return retval; |