Mercurial > dwindows
comparison gtk/dw.c @ 1245:3a2ffe3a7eae
Implemented dw_pixmap_stretch_bitblt() on GTK3...
GTK2 support for printing contexts is there but not tested.
GTK2 pixmap/drawable support to come if possible.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 19 Oct 2011 09:40:23 +0000 |
parents | 3bc6244279c0 |
children | c228c90f95cb |
comparison
equal
deleted
inserted
replaced
1244:db26b9622769 | 1245:3a2ffe3a7eae |
---|---|
8586 DW_MUTEX_UNLOCK; | 8586 DW_MUTEX_UNLOCK; |
8587 } | 8587 } |
8588 | 8588 |
8589 #if GTK_CHECK_VERSION(2,10,0) | 8589 #if GTK_CHECK_VERSION(2,10,0) |
8590 /* Cairo version of dw_pixmap_bitblt() from GTK3, use if either pixmap is a cairo surface */ | 8590 /* Cairo version of dw_pixmap_bitblt() from GTK3, use if either pixmap is a cairo surface */ |
8591 void _cairo_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) | 8591 void _cairo_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) |
8592 { | 8592 { |
8593 int _locked_by_me = FALSE; | 8593 int _locked_by_me = FALSE; |
8594 cairo_t *cr = NULL; | 8594 cairo_t *cr = NULL; |
8595 int retval = DW_ERROR_GENERAL; | |
8595 | 8596 |
8596 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || (!srcp->image && !srcp->pixmap)))) | 8597 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || (!srcp->image && !srcp->pixmap)))) |
8597 return; | 8598 return retval; |
8598 | 8599 |
8599 DW_MUTEX_LOCK; | 8600 DW_MUTEX_LOCK; |
8600 if(dest) | 8601 if(dest) |
8601 { | 8602 { |
8602 GdkWindow *window = gtk_widget_get_window(dest); | 8603 GdkWindow *window = gtk_widget_get_window(dest); |
8603 /* Safety check for non-existant windows */ | 8604 /* Safety check for non-existant windows */ |
8604 if(!window || !GDK_IS_WINDOW(window)) | 8605 if(!window || !GDK_IS_WINDOW(window)) |
8605 { | 8606 { |
8606 DW_MUTEX_UNLOCK; | 8607 DW_MUTEX_UNLOCK; |
8607 return; | 8608 return retval; |
8608 } | 8609 } |
8609 cr = gdk_cairo_create(window); | 8610 cr = gdk_cairo_create(window); |
8610 } | 8611 } |
8611 else if(destp && destp->image) | 8612 else if(destp && destp->image) |
8612 cr = cairo_create(destp->image); | 8613 cr = cairo_create(destp->image); |
8613 | 8614 |
8614 if(cr) | 8615 if(cr) |
8615 { | 8616 { |
8617 double xscale = 1, yscale = 1; | |
8618 | |
8619 if(srcwidth != -1 && srcheight != -1) | |
8620 { | |
8621 xscale = (double)width / (double)srcwidth; | |
8622 yscale = (double)height / (double)srcheight; | |
8623 cairo_scale(cr, xscale, yscale); | |
8624 } | |
8625 | |
8616 #if GTK_CHECK_VERSION(2,24,0) | 8626 #if GTK_CHECK_VERSION(2,24,0) |
8617 if(src) | 8627 if(src) |
8618 gdk_cairo_set_source_window (cr, gtk_widget_get_window(src), xdest -xsrc, ydest - ysrc); | 8628 gdk_cairo_set_source_window (cr, gtk_widget_get_window(src), xdest -xsrc, ydest - ysrc); |
8619 else | 8629 else |
8620 #endif | 8630 #endif |
8621 if(srcp && srcp->image) | 8631 if(srcp && srcp->image) |
8622 cairo_set_source_surface (cr, srcp->image, xdest - xsrc, ydest - ysrc); | 8632 cairo_set_source_surface (cr, srcp->image, (xdest - xsrc) / xscale, (ydest - ysrc) / yscale); |
8623 else if(srcp && srcp->pixmap && !srcp->bitmap) | 8633 else if(srcp && srcp->pixmap && !srcp->bitmap) |
8624 gdk_cairo_set_source_pixmap (cr, srcp->pixmap, xdest - xsrc, ydest - ysrc); | 8634 gdk_cairo_set_source_pixmap (cr, srcp->pixmap, (xdest - xsrc) / xscale, (ydest - ysrc) / yscale); |
8625 else if(srcp && srcp->pixmap && srcp->bitmap) | 8635 else if(srcp && srcp->pixmap && srcp->bitmap) |
8626 { | 8636 { |
8627 cairo_pattern_t *mask_pattern; | 8637 cairo_pattern_t *mask_pattern; |
8628 | 8638 |
8629 /* hack to get the mask pattern */ | 8639 /* hack to get the mask pattern */ |
8630 gdk_cairo_set_source_pixmap(cr, srcp->bitmap, xdest, ydest); | 8640 gdk_cairo_set_source_pixmap(cr, srcp->bitmap, xdest / xscale, ydest / yscale); |
8631 mask_pattern = cairo_get_source(cr); | 8641 mask_pattern = cairo_get_source(cr); |
8632 cairo_pattern_reference(mask_pattern); | 8642 cairo_pattern_reference(mask_pattern); |
8633 | 8643 |
8634 gdk_cairo_set_source_pixmap(cr, srcp->pixmap, xdest - xsrc, ydest - ysrc); | 8644 gdk_cairo_set_source_pixmap(cr, srcp->pixmap, (xdest - xsrc) / xscale, (ydest - ysrc) / yscale); |
8635 cairo_rectangle(cr, xdest, ydest, width, height); | 8645 cairo_rectangle(cr, xdest / xscale, ydest / yscale, width, height); |
8636 cairo_clip(cr); | 8646 cairo_clip(cr); |
8637 cairo_mask(cr, mask_pattern); | 8647 cairo_mask(cr, mask_pattern); |
8638 cairo_destroy(cr); | 8648 cairo_destroy(cr); |
8639 DW_MUTEX_UNLOCK; | 8649 DW_MUTEX_UNLOCK; |
8640 return; | 8650 return DW_ERROR_NONE; |
8641 } | 8651 } |
8642 | 8652 |
8643 cairo_rectangle(cr, xdest, ydest, width, height); | 8653 cairo_rectangle(cr, xdest / xscale, ydest / yscale, width, height); |
8644 cairo_fill(cr); | 8654 cairo_fill(cr); |
8645 cairo_destroy(cr); | 8655 cairo_destroy(cr); |
8646 } | 8656 retval = DW_ERROR_NONE; |
8647 DW_MUTEX_UNLOCK; | 8657 } |
8658 DW_MUTEX_UNLOCK; | |
8659 return retval; | |
8648 } | 8660 } |
8649 #endif | 8661 #endif |
8650 | 8662 |
8651 /* | 8663 /* |
8652 * Copies from one item to another. | 8664 * Copies from one item to another. |
8660 * src: Source window handle. | 8672 * src: Source window handle. |
8661 * srcp: Source pixmap. (choose only one). | 8673 * srcp: Source pixmap. (choose only one). |
8662 * xsrc: X coordinate of source. | 8674 * xsrc: X coordinate of source. |
8663 * ysrc: Y coordinate of source. | 8675 * ysrc: Y coordinate of source. |
8664 */ | 8676 */ |
8665 void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) | 8677 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) |
8678 { | |
8679 dw_pixmap_stretch_bitblt(dest, destp, xdest, ydest, width, height, src, srcp, xsrc, ysrc, -1, -1); | |
8680 } | |
8681 | |
8682 /* | |
8683 * Copies from one surface to another allowing for stretching. | |
8684 * Parameters: | |
8685 * dest: Destination window handle. | |
8686 * destp: Destination pixmap. (choose only one). | |
8687 * xdest: X coordinate of destination. | |
8688 * ydest: Y coordinate of destination. | |
8689 * width: Width of the target area. | |
8690 * height: Height of the target area. | |
8691 * src: Source window handle. | |
8692 * srcp: Source pixmap. (choose only one). | |
8693 * xsrc: X coordinate of source. | |
8694 * ysrc: Y coordinate of source. | |
8695 * srcwidth: Width of area to copy. | |
8696 * srcheight: Height of area to copy. | |
8697 * Returns: | |
8698 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | |
8699 */ | |
8700 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) | |
8666 { | 8701 { |
8667 /* Ok, these #ifdefs are going to get a bit confusing because | 8702 /* Ok, these #ifdefs are going to get a bit confusing because |
8668 * when using gdk-pixbuf, pixmaps are really pixbufs, so we | 8703 * when using gdk-pixbuf, pixmaps are really pixbufs, so we |
8669 * have to use the pixbuf functions on them, and thus convoluting | 8704 * have to use the pixbuf functions on them, and thus convoluting |
8670 * the code here a bit. -Brian | 8705 * the code here a bit. -Brian |
8671 */ | 8706 */ |
8672 int _locked_by_me = FALSE; | 8707 int _locked_by_me = FALSE; |
8673 GdkGC *gc = NULL; | 8708 GdkGC *gc = NULL; |
8709 int retval = DW_ERROR_GENERAL; | |
8674 | 8710 |
8675 #if GTK_CHECK_VERSION(2,10,0) | 8711 #if GTK_CHECK_VERSION(2,10,0) |
8676 if((destp && destp->image) || (srcp && srcp->image)) | 8712 if((destp && destp->image) || (srcp && srcp->image)) |
8677 { | 8713 return _cairo_pixmap_bitblt(dest, destp, xdest, ydest, width, height, src, srcp, xsrc, ysrc, srcwidth, srcheight); |
8678 _cairo_pixmap_bitblt(dest, destp, xdest, ydest, width, height, src, srcp, xsrc, ysrc); | |
8679 return; | |
8680 } | |
8681 #endif | 8714 #endif |
8682 | 8715 |
8683 if((!dest && (!destp || !destp->pixmap)) || (!src && (!srcp || !srcp->pixmap))) | 8716 if((!dest && (!destp || !destp->pixmap)) || (!src && (!srcp || !srcp->pixmap))) |
8684 return; | 8717 return retval; |
8685 | 8718 |
8686 DW_MUTEX_LOCK; | 8719 DW_MUTEX_LOCK; |
8687 if(dest) | 8720 if(dest) |
8688 gc = _set_colors(dest->window); | 8721 gc = _set_colors(dest->window); |
8689 else if(src) | 8722 else if(src) |
8711 { | 8744 { |
8712 gdk_gc_set_clip_mask( gc, NULL ); | 8745 gdk_gc_set_clip_mask( gc, NULL ); |
8713 gdk_gc_set_clip_origin( gc, 0, 0 ); | 8746 gdk_gc_set_clip_origin( gc, 0, 0 ); |
8714 } | 8747 } |
8715 gdk_gc_unref( gc ); | 8748 gdk_gc_unref( gc ); |
8716 } | 8749 retval = DW_ERROR_NONE; |
8717 DW_MUTEX_UNLOCK; | 8750 } |
8751 DW_MUTEX_UNLOCK; | |
8752 return retval; | |
8718 } | 8753 } |
8719 | 8754 |
8720 /* | 8755 /* |
8721 * Emits a beep. | 8756 * Emits a beep. |
8722 * Parameters: | 8757 * Parameters: |