Mercurial > dwindows
comparison win/dw.c @ 1243:c191a562c14a
Added new dw_pixmap_stretch_bitblt() function on Windows and OS/2.
Added new strech option to the test program to test this functionality.
OS/2 version is untested and I am not sure I got the math right...
GTK and Mac versions to come soon.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 19 Oct 2011 08:14:05 +0000 |
parents | 700ce342aab8 |
children | ed2119fc210d |
comparison
equal
deleted
inserted
replaced
1242:8e37ebb3fab7 | 1243:c191a562c14a |
---|---|
9022 * xsrc: X coordinate of source. | 9022 * xsrc: X coordinate of source. |
9023 * ysrc: Y coordinate of source. | 9023 * ysrc: Y coordinate of source. |
9024 */ | 9024 */ |
9025 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) | 9025 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) |
9026 { | 9026 { |
9027 dw_pixmap_stretch_bitblt(dest, destp, xdest, ydest, width, height, src, srcp, xsrc, ysrc, -1, -1); | |
9028 } | |
9029 | |
9030 /* | |
9031 * Copies from one surface to another allowing for stretching. | |
9032 * Parameters: | |
9033 * dest: Destination window handle. | |
9034 * destp: Destination pixmap. (choose only one). | |
9035 * xdest: X coordinate of destination. | |
9036 * ydest: Y coordinate of destination. | |
9037 * width: Width of the target area. | |
9038 * height: Height of the target area. | |
9039 * src: Source window handle. | |
9040 * srcp: Source pixmap. (choose only one). | |
9041 * xsrc: X coordinate of source. | |
9042 * ysrc: Y coordinate of source. | |
9043 * srcwidth: Width of area to copy. | |
9044 * srcheight: Height of area to copy. | |
9045 * Returns: | |
9046 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | |
9047 */ | |
9048 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) | |
9049 { | |
9027 HDC hdcdest; | 9050 HDC hdcdest; |
9028 HDC hdcsrc; | 9051 HDC hdcsrc; |
9029 static BLENDFUNCTION bf = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA }; | 9052 static BLENDFUNCTION bf = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA }; |
9030 | 9053 int swidth = srcwidth, sheight = srcheight; |
9054 | |
9055 /* Do some sanity checks */ | |
9031 if ( dest ) | 9056 if ( dest ) |
9032 hdcdest = GetDC( dest ); | 9057 hdcdest = GetDC( dest ); |
9033 else if ( destp ) | 9058 else if ( destp ) |
9034 hdcdest = destp->hdc; | 9059 hdcdest = destp->hdc; |
9035 else | 9060 else |
9036 return; | 9061 return DW_ERROR_GENERAL; |
9037 | 9062 |
9038 if ( src ) | 9063 if ( src ) |
9039 hdcsrc = GetDC( src ); | 9064 hdcsrc = GetDC( src ); |
9040 else if ( srcp ) | 9065 else if ( srcp ) |
9041 hdcsrc = srcp->hdc; | 9066 hdcsrc = srcp->hdc; |
9042 else | 9067 else |
9043 return; | 9068 return DW_ERROR_GENERAL; |
9069 | |
9070 if((srcheight == -1 || srcwidth == -1) && srcheight != srcwidth) | |
9071 return DW_ERROR_GENERAL; | |
9072 | |
9073 if(srcheight == -1 && srcwidth == -1) | |
9074 { | |
9075 swidth = width; | |
9076 sheight = height; | |
9077 } | |
9044 | 9078 |
9045 /* If it is a 32bpp bitmap (with alpha) use AlphaBlend unless it fails */ | 9079 /* If it is a 32bpp bitmap (with alpha) use AlphaBlend unless it fails */ |
9046 if ( srcp && srcp->depth == 32 && AlphaBlend( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, width, height, bf ) ) | 9080 if ( srcp && srcp->depth == 32 && AlphaBlend( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, swidth, sheight, bf ) ) |
9047 { | 9081 { |
9048 /* Don't do anything */ | 9082 /* Don't do anything */ |
9049 } | 9083 } |
9050 /* Otherwise perform special bitblt with manual transparency */ | 9084 /* Otherwise perform special bitblt with manual transparency */ |
9051 else if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT ) | 9085 else if ( srcp && srcp->transcolor != DW_RGB_TRANSPARENT ) |
9052 { | 9086 { |
9053 TransparentBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, width, height, RGB( DW_RED_VALUE(srcp->transcolor), DW_GREEN_VALUE(srcp->transcolor), DW_BLUE_VALUE(srcp->transcolor)) ); | 9087 TransparentBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, swidth, sheight, RGB( DW_RED_VALUE(srcp->transcolor), DW_GREEN_VALUE(srcp->transcolor), DW_BLUE_VALUE(srcp->transcolor)) ); |
9054 } | 9088 } |
9055 else | 9089 else |
9056 { | 9090 { |
9057 /* Finally fall back to the classic BitBlt */ | 9091 /* Finally fall back to the classic BitBlt */ |
9058 BitBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY ); | 9092 if( srcwidth == -1 && srcheight == -1) |
9093 BitBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, SRCCOPY ); | |
9094 else | |
9095 StretchBlt( hdcdest, xdest, ydest, width, height, hdcsrc, xsrc, ysrc, swidth, sheight, SRCCOPY ); | |
9059 } | 9096 } |
9060 if ( !destp ) | 9097 if ( !destp ) |
9061 ReleaseDC( dest, hdcdest ); | 9098 ReleaseDC( dest, hdcdest ); |
9062 if ( !srcp ) | 9099 if ( !srcp ) |
9063 ReleaseDC( src, hdcsrc ); | 9100 ReleaseDC( src, hdcsrc ); |
9101 | |
9102 return DW_ERROR_NONE; | |
9064 } | 9103 } |
9065 | 9104 |
9066 /* Run Beep() in a separate thread so it doesn't block */ | 9105 /* Run Beep() in a separate thread so it doesn't block */ |
9067 void _beepthread(void *data) | 9106 void _beepthread(void *data) |
9068 { | 9107 { |