Mercurial > dwindows
comparison gtk3/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 | 3df86772b625 |
comparison
equal
deleted
inserted
replaced
1244:db26b9622769 | 1245:3a2ffe3a7eae |
---|---|
7316 * src: Source window handle. | 7316 * src: Source window handle. |
7317 * srcp: Source pixmap. (choose only one). | 7317 * srcp: Source pixmap. (choose only one). |
7318 * xsrc: X coordinate of source. | 7318 * xsrc: X coordinate of source. |
7319 * ysrc: Y coordinate of source. | 7319 * ysrc: Y coordinate of source. |
7320 */ | 7320 */ |
7321 void dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) | 7321 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) |
7322 { | 7322 { |
7323 /* Ok, these #ifdefs are going to get a bit confusing because | 7323 dw_pixmap_stretch_bitblt(dest, destp, xdest, ydest, width, height, src, srcp, xsrc, ysrc, -1, -1); |
7324 * when using gdk-pixbuf, pixmaps are really pixbufs, so we | 7324 } |
7325 * have to use the pixbuf functions on them, and thus convoluting | 7325 |
7326 * the code here a bit. -Brian | 7326 /* |
7327 */ | 7327 * Copies from one surface to another allowing for stretching. |
7328 * Parameters: | |
7329 * dest: Destination window handle. | |
7330 * destp: Destination pixmap. (choose only one). | |
7331 * xdest: X coordinate of destination. | |
7332 * ydest: Y coordinate of destination. | |
7333 * width: Width of the target area. | |
7334 * height: Height of the target area. | |
7335 * src: Source window handle. | |
7336 * srcp: Source pixmap. (choose only one). | |
7337 * xsrc: X coordinate of source. | |
7338 * ysrc: Y coordinate of source. | |
7339 * srcwidth: Width of area to copy. | |
7340 * srcheight: Height of area to copy. | |
7341 * Returns: | |
7342 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | |
7343 */ | |
7344 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) | |
7345 { | |
7328 int _locked_by_me = FALSE; | 7346 int _locked_by_me = FALSE; |
7329 cairo_t *cr = NULL; | 7347 cairo_t *cr = NULL; |
7348 int retval = DW_ERROR_GENERAL; | |
7330 | 7349 |
7331 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || !srcp->image))) | 7350 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || !srcp->image))) |
7332 return; | 7351 return retval; |
7333 | 7352 |
7334 DW_MUTEX_LOCK; | 7353 DW_MUTEX_LOCK; |
7335 if(dest) | 7354 if(dest) |
7336 { | 7355 { |
7337 GdkWindow *window = gtk_widget_get_window(dest); | 7356 GdkWindow *window = gtk_widget_get_window(dest); |
7338 /* Safety check for non-existant windows */ | 7357 /* Safety check for non-existant windows */ |
7339 if(!window || !GDK_IS_WINDOW(window)) | 7358 if(!window || !GDK_IS_WINDOW(window)) |
7340 { | 7359 { |
7341 DW_MUTEX_UNLOCK; | 7360 DW_MUTEX_UNLOCK; |
7342 return; | 7361 return retval; |
7343 } | 7362 } |
7344 cr = gdk_cairo_create(window); | 7363 cr = gdk_cairo_create(window); |
7345 } | 7364 } |
7346 else if(destp) | 7365 else if(destp) |
7347 cr = cairo_create(destp->image); | 7366 cr = cairo_create(destp->image); |
7348 | 7367 |
7349 if(cr) | 7368 if(cr) |
7350 { | 7369 { |
7370 double xscale = 1, yscale = 1; | |
7371 | |
7372 if(srcwidth != -1 && srcheight != -1) | |
7373 { | |
7374 xscale = (double)width / (double)srcwidth; | |
7375 yscale = (double)height / (double)srcheight; | |
7376 cairo_scale(cr, xscale, yscale); | |
7377 } | |
7378 | |
7351 if(src) | 7379 if(src) |
7352 gdk_cairo_set_source_window (cr, gtk_widget_get_window(src), xdest -xsrc, ydest - ysrc); | 7380 gdk_cairo_set_source_window (cr, gtk_widget_get_window(src), (xdest + xsrc) / xscale, (ydest + ysrc) / yscale); |
7353 else if(srcp) | 7381 else if(srcp) |
7354 cairo_set_source_surface (cr, srcp->image, xdest - xsrc, ydest - ysrc); | 7382 cairo_set_source_surface (cr, srcp->image, (xdest + xsrc) / xscale, (ydest + ysrc) / yscale); |
7355 | 7383 |
7356 cairo_rectangle(cr, xdest, ydest, width, height); | 7384 cairo_rectangle(cr, xdest / xscale, ydest / yscale, width, height); |
7357 cairo_fill(cr); | 7385 cairo_fill(cr); |
7358 cairo_destroy(cr); | 7386 cairo_destroy(cr); |
7359 } | 7387 retval = DW_ERROR_NONE; |
7360 DW_MUTEX_UNLOCK; | 7388 } |
7389 DW_MUTEX_UNLOCK; | |
7390 return retval; | |
7361 } | 7391 } |
7362 | 7392 |
7363 /* | 7393 /* |
7364 * Emits a beep. | 7394 * Emits a beep. |
7365 * Parameters: | 7395 * Parameters: |