/* * ClearImage - clear the XOR and the AND bitmaps */ void ClearImage( void ) { WPI_PRES pres; WPI_PRES xorpres; WPI_PRES andpres; HDC xormemdc; HDC andmemdc; HBITMAP oldxor; HBITMAP oldand; img_node *node; WPI_RECT clear_area; IMGED_DIM left; IMGED_DIM top; IMGED_DIM right; IMGED_DIM bottom; int width; int height; node = GetCurrentNode(); if( node == NULL ) { return; } if( DoesRectExist( &clear_area ) ) { SetRectExists( FALSE ); } else { _wpi_setwrectvalues( &clear_area, 0, 0, node->width, node->height ); } pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xormemdc ); andpres = _wpi_createcompatiblepres( pres, Instance, &andmemdc ); _wpi_releasepres( HWND_DESKTOP, pres ); oldxor = _wpi_selectobject( xorpres, node->hxorbitmap ); oldand = _wpi_selectobject( andpres, node->handbitmap ); _wpi_getwrectvalues( clear_area, &left, &top, &right, &bottom ); width = _wpi_getwidthrect( clear_area ); height = _wpi_getheightrect( clear_area ); _wpi_patblt( xorpres, left, top, width, height, WHITENESS ); _wpi_patblt( andpres, left, top, width, height, BLACKNESS ); _wpi_selectobject( xorpres, oldxor ); _wpi_selectobject( andpres, oldand ); _wpi_deletecompatiblepres( xorpres, xormemdc ); _wpi_deletecompatiblepres( andpres, andmemdc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); PrintHintTextByID( WIE_AREACLEARED, NULL ); } /* ClearImage */
/* * GetAndBitmapInfo - Returns a pointer to a bitmap info structure ... memory * should be freed with FreeDIBitmapInfo. this is for * the and part. */ BITMAPINFO2 *GetAndBitmapInfo( img_node *node ) { long size; WPI_BITMAPINFO *bmi; WPI_BITMAPINFOHEADER bmih; WPI_PRES pres; WPI_PRES mempres; HDC memdc; HBITMAP oldbitmap; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); size = BMPINFO2_SIZE( 1 ); bmi = MemAlloc( size ); GetBitmapInfoHeader( &bmih, node ); // Adjustments for the and mask bmih.cBitCount = 1; bmih.cbImage = BITS_TO_BYTES( node->bitcount, node->height ); bmih.cclrUsed = 2; memcpy( bmi, &bmih, sizeof(WPI_BITMAPINFOHEADER) ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); GpiQueryBitmapBits( mempres, 0, node->height, NULL, bmi ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); bmi->cbImage = BITS_TO_BYTES( node->bitcount, 2*node->height ); bmi->cy = node->height * 2; return( bmi ); } /* GetAndBitmapInfo */
/* * redrawViewWnd - process the WM_PAINT message for the view windows */ static void redrawViewWnd( HWND hwnd ) { WPI_PRES pres; WPI_PRES hps; WPI_PRES mempres; HDC memdc; HBITMAP bitmap; HBITMAP oldbitmap; img_node *node; PAINTSTRUCT ps; node = SelectFromViewHwnd( hwnd ); if( node == NULL ) { return; } hps = _wpi_beginpaint( hwnd, NULL, &ps ); drawBorder( node ); pres = _wpi_getpres( hwnd ); bitmap = CreateViewBitmap( node ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); oldbitmap = _wpi_selectbitmap( mempres, bitmap ); _wpi_bitblt( pres, BORDER_WIDTH, BORDER_WIDTH, node->width, node->height, mempres, 0, 0, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletebitmap( bitmap ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_releasepres( hwnd, pres ); _wpi_endpaint( hwnd, hps, &ps ); } /* redrawViewWnd */
/* * paintColors - paint the available colors on the color palette */ static void paintColors( HWND hwnd ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; PAINTSTRUCT ps; HBITMAP bitmap; HBITMAP oldbitmap; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif _wpi_torgbmode( pres ); if( numberOfColors == 2 ) { bitmap = hMonoBitmap; } else { bitmap = hColorBitmap; } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectbitmap( mempres, bitmap ); _wpi_bitblt( pres, 0, 0, CUR_BMP_WIDTH, CUR_BMP_HEIGHT, mempres, 0, 0, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_endpaint( hwnd, pres, &ps ); } /* paintColors */
/* * MakeBitmap - Makes the bitmap */ void MakeBitmap( img_node *node, BOOL isnew ) { HDC hdc; WPI_PRES pres; WPI_PRES mempres; HBITMAP oldbitmap; if (isnew) { InitXorAndBitmaps( node ); } else { /* * The AND bitmap won't really get used, but it should be around * since some functions are generic (ie for all image types) and * hence assume an AND bitmap exists. */ pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); node->handbitmap = _wpi_createbitmap(node->width, node->height, 1, 1, NULL ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); _wpi_patblt( mempres, 0, 0, node->width, node->height, BLACKNESS ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); } DisplayImageText( node ); } /* MakeBitmap */
/* * GetXorBitmapInfo - Returns a pointer to a bitmap info structure ... memory * should be freed with FreeDIBitmapInfo. this is for * the xor part. */ BITMAPINFO2 *GetXorBitmapInfo( img_node *node ) { long size; WPI_BITMAPINFO *bmi; WPI_BITMAPINFOHEADER bmih; WPI_PRES pres; WPI_PRES mempres; HDC memdc; HBITMAP oldbitmap; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); size = BMPINFO2_SIZE( node->bitcount ); bmi = MemAlloc( size ); GetBitmapInfoHeader( &bmih, node ); memcpy( bmi, &bmih, sizeof(WPI_BITMAPINFOHEADER) ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); GpiQueryBitmapBits( mempres, 0, node->height, NULL, bmi ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); return( bmi ); } /* GetXorBitmapInfo */
/* * ShowNewColor - replace the color of the color box and redisplay the boxes */ void ShowNewColor( int index, COLORREF newcolor, BOOL repaint ) { WPI_POINT topleft; WPI_POINT bottomright; WPI_PRES pres; WPI_PRES mempres; HDC hdc; HBITMAP oldbitmap; HBRUSH brush; HBRUSH oldbrush; HPEN blackpen; HPEN oldpen; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); paletteBox[index].color = newcolor; paletteBox[index].solid_color = _wpi_getnearestcolor( pres, newcolor ); _wpi_releasepres( HWND_DESKTOP, pres ); if( numberOfColors != 2 ) { topleft.x = (index / 2) * SQR_SIZE; bottomright.x = topleft.x + SQR_SIZE + 1; if( index / 2 == (index + 1) / 2 ) { topleft.y = 0; bottomright.y = SQR_SIZE + 1; } else { topleft.y = SQR_SIZE; bottomright.y = 2 * SQR_SIZE + 1; } pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); brush = _wpi_createsolidbrush( newcolor ); oldbrush = _wpi_selectobject( mempres, brush ); blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); oldpen = _wpi_selectobject( mempres, blackpen ); oldbitmap = _wpi_selectbitmap( mempres, hColorBitmap ); _wpi_cvth_pt( &topleft, colorsHeight ); _wpi_cvth_pt( &bottomright, colorsHeight ); _wpi_rectangle( mempres, topleft.x, topleft.y, bottomright.x, bottomright.y ); _wpi_selectobject( mempres, oldpen ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( blackpen ); _wpi_deleteobject( brush ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); } if( repaint ) { _wpi_invalidaterect( hColorsWnd, NULL, FALSE ); } } /* ShowNewColor */
/* * CutImage - cuts the current clipping rectangle to the clipboard */ void CutImage( void ) { WPI_PRES pres; WPI_PRES mempres; HDC memdc; HBITMAP oldbitmap; short width; short height; img_node *node; WPI_RECTDIM left; WPI_RECTDIM right; WPI_RECTDIM top; WPI_RECTDIM bottom; node = GetCurrentNode(); if( node == NULL ) { return; } if( !fEnableCutCopy ) { _wpi_setwrectvalues( &clipRect.rect, 0, 0, node->width, node->height ); width = node->width; height = node->height; } else { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } copyImageToClipboard( width, height, node ); pres = _wpi_getpres( node->viewhwnd ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( node->viewhwnd, pres ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); _wpi_getrectvalues( clipRect.rect, &left, &top, &right, &bottom ); _wpi_patblt( mempres, left, top, width, height, WHITENESS ); _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); _wpi_patblt( mempres, left, top, width, height, BLACKNESS ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); InvalidateRect( node->viewhwnd, NULL, FALSE ); RecordImage( node->hwnd ); if( !fEnableCutCopy ) { PrintHintTextByID( WIE_ENTIREIMAGECUT, NULL ); } else { PrintHintTextByID( WIE_AREACUT, NULL ); fEnableCutCopy = FALSE; } BlowupImage( node->hwnd, NULL ); } /* CutImage */
/* * BlowupImage - stretch the view window into the window given by hwnd */ void BlowupImage( HWND hmdiwnd, WPI_PRES pres ) { HDC memdc; WPI_PRES mempres; WPI_RECT client; HBITMAP oldbitmap; HBITMAP newbitmap; HWND hwnd; img_node *node; BOOL new_pres; if( hmdiwnd != NULL ) { hwnd = hmdiwnd; } else { node = GetCurrentNode(); if( node == NULL ) { return; } hwnd = node->hwnd; } newbitmap = EnlargeImage( hwnd ); if( newbitmap == NULL ) { return; } new_pres = FALSE; if( pres == (WPI_PRES)NULL ) { pres = _wpi_getpres( hwnd ); new_pres = TRUE; } mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); oldbitmap = _wpi_selectobject( mempres, newbitmap ); if( ImgedConfigInfo.grid_on ) { showGrid( hwnd, mempres ); } else { GetClientRect( hwnd, &client ); _wpi_bitblt( pres, 0, 0, _wpi_getwidthrect( client ), _wpi_getheightrect( client ), mempres, 0, 0, SRCCOPY ); RedrawPrevClip( hwnd ); // Redraw if there was a clip region specified. } _wpi_selectobject( mempres, oldbitmap ); _wpi_deletebitmap( newbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); if( new_pres ) { _wpi_releasepres( hwnd, pres ); } } /* BlowupImage */
/* * SetCurrentNumColors - set the number of colors for this module */ void SetCurrentNumColors( int color_count ) { WPI_PRES pres; WPI_PRES mempres; HDC memdc; HBITMAP oldbitmap; numberOfColors = color_count; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); if( lButton.bitmap != NULL ) { _wpi_deletebitmap( lButton.bitmap ); } if( rButton.bitmap != NULL ) { _wpi_deletebitmap( rButton.bitmap ); } if( color_count == 2 ) { lButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); rButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); //} else if( color_count == 16 ) { } else { lButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); rButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); if( firstTime ) { mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_patblt( mempres, 0, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, BLACKNESS ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_patblt( mempres, 0, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, WHITENESS ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); firstTime = false; } } _wpi_releasepres( HWND_DESKTOP, pres ); } /* SetCurrentNumColors */
/* * DuplicateBitmap - produces a duplicate of the bitmap */ HBITMAP DuplicateBitmap( HBITMAP hbitmap ) { HDC srcdc; WPI_PRES srcpres; HDC destdc; WPI_PRES destpres; WPI_PRES pres; int width; int height; int planes; int bitspixel; HBITMAP newbitmap; HBITMAP oldbitmap; HBITMAP oldnewbitmap; _wpi_getbitmapparms( hbitmap, &width, &height, &planes, NULL, &bitspixel ); pres = _wpi_getpres( HWND_DESKTOP ); srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc ); destpres = _wpi_createcompatiblepres( pres, Instance, &destdc ); _wpi_releasepres( HWND_DESKTOP, pres ); newbitmap = _wpi_createbitmap( width, height, planes, bitspixel, NULL ); oldbitmap = _wpi_selectobject( srcpres, hbitmap ); oldnewbitmap = _wpi_selectobject( destpres, newbitmap ); _wpi_bitblt( destpres, 0, 0, width, height, srcpres, 0, 0, SRCCOPY ); _wpi_selectobject( srcpres, oldbitmap ); _wpi_selectobject( destpres, oldnewbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); _wpi_deletecompatiblepres( destpres, destdc ); return( newbitmap ); } /* DuplicateBitmap */
/* * LineXorAnd - draw the line on the XOR and the AND bitmaps */ void LineXorAnd( COLORREF xorcolor, COLORREF andcolor, WPI_POINT *startpt, WPI_POINT *endpt ) { HPEN oldpen; HPEN hpen; HDC memdc; WPI_PRES pres; WPI_PRES mempres; HBITMAP oldbitmap; HDC anddc; anddc = anddc; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); hpen = _wpi_createpen( PS_SOLID, 0, xorcolor ); oldpen = _wpi_selectobject( mempres, hpen ); oldbitmap = _wpi_selectobject( mempres, activeImage->hxorbitmap ); _wpi_movetoex( mempres, startpt, NULL ); _wpi_lineto( mempres, endpt ); _wpi_setpixel( mempres, endpt->x, endpt->y, xorcolor ); _wpi_selectobject( mempres, oldpen ); _wpi_deleteobject( hpen ); _wpi_selectobject( mempres, oldbitmap ); if( activeImage->imgtype == BITMAP_IMG ) { _wpi_deletecompatiblepres( mempres, memdc ); return; } hpen = _wpi_createpen( PS_SOLID, 0, andcolor ); oldpen = _wpi_selectobject( mempres, hpen ); oldbitmap = _wpi_selectobject( mempres, activeImage->handbitmap ); _wpi_movetoex( mempres, startpt, NULL ); _wpi_lineto( mempres, endpt ); _wpi_setpixel( mempres, endpt->x, endpt->y, andcolor ); _wpi_selectobject( mempres, oldpen ); _wpi_deleteobject( hpen ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, anddc ); } /* LineXorAnd */
/* * writeDataInPieces - writes the xor data for the bitmap in chunks */ static bool writeDataInPieces( BITMAPINFO2 *bmi, FILE *fp, img_node *node ) { WPI_PRES pres; WPI_PRES mempres; HDC memdc; int scanline_count; int one_scanline_size; long chunk_size; int start; int num_lines; long byte_count; BYTE *buffer; HBITMAP oldbitmap; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); byte_count = BITS_TO_BYTES( node->bitcount * node->width, node->height ); start = 0; num_lines = SCANLINE_SIZE; one_scanline_size = BITS_TO_BYTES( node->width*node->bitcount, 1 ); scanline_count = node->height; chunk_size = one_scanline_size * num_lines; while( chunk_size > MAX_CHUNK ) { chunk_size >>= 1; num_lines = chunk_size / one_scanline_size; } buffer = calloc( chunk_size, sizeof( BYTE ) ); while( scanline_count > num_lines ) { GpiQueryBitmapBits( mempres, start, num_lines, buffer, bmi ); fwrite( buffer, sizeof( BYTE ), chunk_size, fp ); scanline_count -= num_lines; start += num_lines; byte_count -= chunk_size; } GpiQueryBitmapBits( mempres, start, scanline_count, buffer, bmi ); fwrite( buffer, sizeof( BYTE ), one_scanline_size * scanline_count, fp ); free( buffer ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); return( true ); } /* writeDataInPieces */
/* * paintCurrent - paint the current window (process WM_PAINT) */ static void paintCurrent( HWND hwnd ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; PAINTSTRUCT ps; WPI_RECT rect; HBITMAP oldbitmap; int top; int bottom; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( pres ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_bitblt( pres, 0, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_bitblt( pres, CUR_RCOL_X - 1, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_setbackmode( pres, TRANSPARENT ); _wpi_settextcolor( pres, GetInverseColor( lButton.solid ) ); top = _wpi_cvth_y( CUR_COL_Y, currentHeight ); bottom = _wpi_cvth_y( CUR_COL_Y + CUR_SQR_SIZE, currentHeight ); _wpi_setintwrectvalues( &rect, CUR_LCOL_X, top, CUR_LCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "L", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_settextcolor( pres, GetInverseColor( rButton.solid ) ); _wpi_setintwrectvalues( &rect, CUR_RCOL_X, top, CUR_RCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "R", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_endpaint( hwnd, pres, &ps ); } /* paintCurrent */
/* * clipIntoArea - clip the bitmaps into the area when rotating */ static void clipIntoArea( img_node *node, WPI_RECT *rect, HBITMAP rotxorbmp, HBITMAP rotandbmp ) { WPI_PRES pres; WPI_PRES xorpres; HDC xordc; WPI_PRES andpres; HDC anddc; WPI_PRES rotxorpres; HDC rotxordc; WPI_PRES rotandpres; HDC rotanddc; HBITMAP oldxor; HBITMAP oldand; HBITMAP oldxorrot; HBITMAP oldandrot; short width; short height; WPI_POINT centre_pt; WPI_POINT topleft; short start_x; short start_y; short new_width; short new_height; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; IMGED_DIM bottom; width = (short)_wpi_getwidthrect( *rect ); height = (short)_wpi_getheightrect( *rect ); /* * PM NOTE: We use getwrectvalues so that 'topleft' can really be * replace with 'bottomleft' (which is our origin for blitting in PM). * Hence the value of 'top' is really the bottom of our rectangle. */ _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); centre_pt.x = (width / 2) + left; centre_pt.y = (height / 2) + top; topleft.x = __max( left, centre_pt.x - centre_pt.y + top ); topleft.y = __max( top, centre_pt.y - centre_pt.x + left ); if( topleft.x == left ) { start_x = (short)(left - (centre_pt.x - centre_pt.y + top)); new_width = width; } else { start_x = 0; new_width = height; } if( topleft.y == top ) { start_y = (short)(top - (centre_pt.y - centre_pt.x + left)); new_height = height; } else { start_y = 0; new_height = width; } pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc ); andpres = _wpi_createcompatiblepres( pres, Instance, &anddc ); rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc ); rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( xorpres ); _wpi_torgbmode( andpres ); _wpi_torgbmode( rotxorpres ); _wpi_torgbmode( rotandpres ); oldxor = _wpi_selectobject( xorpres, node->hxorbitmap ); oldand = _wpi_selectobject( andpres, node->handbitmap ); oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp ); oldandrot = _wpi_selectobject( rotandpres, rotandbmp ); _wpi_patblt( xorpres, left, top, width, height, WHITENESS ); _wpi_patblt( andpres, left, top, width, height, BLACKNESS ); _wpi_bitblt( xorpres, topleft.x, topleft.y, new_width, new_height, rotxorpres, start_x, start_y, SRCCOPY ); _wpi_bitblt( andpres, topleft.x, topleft.y, new_width, new_height, rotandpres, start_x, start_y, SRCCOPY ); _wpi_selectobject( xorpres, oldxor ); _wpi_selectobject( andpres, oldand ); _wpi_selectobject( rotxorpres, oldxorrot ); _wpi_selectobject( rotandpres, oldandrot ); _wpi_deletecompatiblepres( xorpres, xordc ); _wpi_deletecompatiblepres( andpres, anddc ); _wpi_deletecompatiblepres( rotxorpres, rotxordc ); _wpi_deletecompatiblepres( rotandpres, rotanddc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); } /* clipIntoArea */
/* * ShiftImage - shift the image in the given direction */ void ShiftImage( WORD shiftdirection ) { HBITMAP dup_and; HBITMAP dup_xor; HBITMAP oldbitmap; HBITMAP oldsrcbitmap; WPI_PRES pres; HDC memdc; WPI_PRES mempres; HDC srcdc; WPI_PRES srcpres; short x_src; short y_src; short x_dest; short y_dest; short width; short height; short min_width; short min_height; short rgn_width; short rgn_height; img_node *node; WPI_RECT rect; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; IMGED_DIM bottom; DWORD message; node = GetCurrentNode(); if( node == NULL ) { return; } dup_and = DuplicateBitmap( node->handbitmap ); dup_xor = DuplicateBitmap( node->hxorbitmap ); pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); _wpi_torgbmode( srcpres ); if( DoesRectExist( &rect ) ) { width = (short)_wpi_getwidthrect( rect ); height = (short)_wpi_getheightrect( rect ); } else { _wpi_setwrectvalues( &rect, 0, 0, node->width, node->height ); width = node->width; height = node->height; } _wpi_getwrectvalues( rect, &left, &top, &right, &bottom ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); _wpi_patblt( mempres, left, top, width, height, BLACKNESS ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); _wpi_patblt( mempres, left, top, width, height, WHITENESS ); oldsrcbitmap = _wpi_selectobject( srcpres, dup_xor ); x_src = (short)left; y_src = (short)top; x_dest =(short)left; y_dest = (short)top; min_width = (short)min( ImgedConfigInfo.shift, width ); min_height = (short)min( ImgedConfigInfo.shift, height ); rgn_width = width; rgn_height = height; switch( shiftdirection ) { case IMGED_LEFT: width -= min_width; x_src = x_src + min_width; message = WIE_IMAGESHIFTEDLEFT; break; case IMGED_RIGHT: width -= min_width; x_dest = x_dest + min_width; message = WIE_IMAGESHIFTEDRIGHT; break; case IMGED_UP: #ifndef __OS2_PM__ height -= min_height; y_src = y_src + min_height; #else height += min_height; y_src = y_src - min_height; #endif message = WIE_IMAGESHIFTEDUP; break; case IMGED_DOWN: #ifndef __OS2_PM__ height -= min_height; y_dest = y_dest + min_height; #else height += min_height; y_dest = y_dest - min_height; #endif message = WIE_IMAGESHIFTEDDOWN; break; default: break; } _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); _wpi_selectobject( srcpres, oldsrcbitmap ); oldsrcbitmap = _wpi_selectobject( srcpres, dup_and ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); if( IsShiftWrap() ) { switch( shiftdirection ) { case IMGED_LEFT: width = min_width; x_src = (short)left; x_dest = (short)(right - width); break; case IMGED_RIGHT: width = min_width; x_dest = (short)left; x_src = (short)(right - width); break; case SHIFT_UP: height = min_height; y_src = (short)top; y_dest = (short)(bottom - height); break; case SHIFT_DOWN: height = min_height; y_dest = (short)top; y_src = (short)(bottom - height); break; default: break; } _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); _wpi_selectobject( srcpres, oldsrcbitmap ); _wpi_selectobject( mempres, oldbitmap ); oldsrcbitmap = _wpi_selectobject( srcpres, dup_xor ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); _wpi_bitblt( mempres, x_dest, y_dest, width, height, srcpres, x_src, y_src, SRCCOPY ); } _wpi_selectobject( srcpres, oldsrcbitmap ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deleteobject( dup_xor ); _wpi_deleteobject( dup_and ); RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); InvalidateRect( node->viewhwnd, NULL, FALSE ); IEPrintAmtText( message, ImgedConfigInfo.shift ); } /* ShiftImage */
/* * SetColor - set the current colors */ void SetColor( int mousebutton, COLORREF color, COLORREF solid, wie_clrtype type ) { HDC hdc; WPI_PRES pres; WPI_PRES mempres; HBITMAP oldbitmap; HPEN blackpen; HPEN oldpen; HBRUSH brush; HBRUSH oldbrush; int top; int bottom; blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); if( mousebutton == LMOUSEBUTTON ) { lButton.color = color; lButton.solid = solid; lButton.type = type; if( lButton.bitmap != NULL ) { _wpi_deletebitmap( lButton.bitmap ); pres = _wpi_getpres( HWND_DESKTOP ); if( numberOfColors == 2 && type == NORMAL_CLR ) { lButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); } else { lButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_releasepres( HWND_DESKTOP, pres ); oldpen = _wpi_selectobject( mempres, blackpen ); brush = _wpi_createsolidbrush( solid ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( 0, currentHeight ); bottom = _wpi_cvth_y( CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); brush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( CUR_SQR_SIZE, currentHeight ); bottom = _wpi_cvth_y( 2 * CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); } } else { rButton.color = color; rButton.solid = solid; rButton.type = type; if( rButton.bitmap != NULL ) { _wpi_deletebitmap( rButton.bitmap ); pres = _wpi_getpres( HWND_DESKTOP ); if( numberOfColors == 2 && type == NORMAL_CLR ) { rButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); } else { rButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_releasepres( HWND_DESKTOP, pres ); oldpen = _wpi_selectobject( mempres, blackpen ); brush = _wpi_createsolidbrush( solid ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( 0, currentHeight ); bottom = _wpi_cvth_y( CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); brush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( CUR_SQR_SIZE, currentHeight ); bottom = _wpi_cvth_y( 2 * CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); } } _wpi_deleteobject( blackpen ); InvalidateRect( hCurrentWnd, NULL, TRUE ); } /* SetColor */
/* * rotateTheImage - create the rotated bitmaps */ static void rotateTheImage( img_node *node, int whichway, WPI_RECT *rect, HBITMAP rotxorbmp, HBITMAP rotandbmp ) { WPI_PRES pres; WPI_PRES rotxorpres; HDC rotxordc; WPI_PRES xorpres; HDC xordc; WPI_PRES rotandpres; HDC rotanddc; HBITMAP oldandrot; HBITMAP oldxorrot; HBITMAP oldxor; short new_height; short new_width; long i; long amt_done; long prev_amt; long total_amt; long temp; IMGED_DIM left; IMGED_DIM top; IMGED_DIM right; IMGED_DIM bottom; int x; int y; COLORREF color; bitmap_bits *xorbits; bitmap_bits *andbits; bitmap_bits *rotxorbits; bitmap_bits *rotandbits; new_height = (short)_wpi_getwidthrect( *rect ); new_width = (short)_wpi_getheightrect( *rect ); oldxor = NULL; amt_done = prev_amt = 0L; total_amt = (long)new_height * (long)new_width; i = 0L; _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); if( node->imgtype == BITMAP_IMG ) { pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc ); rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc ); rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( rotxorpres ); _wpi_torgbmode( rotandpres ); oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp ); oldandrot = _wpi_selectobject( rotandpres, rotandbmp ); _wpi_patblt( rotxorpres, 0, 0, new_width, new_height, WHITENESS ); _wpi_patblt( rotandpres, 0, 0, new_width, new_height, BLACKNESS ); _wpi_selectobject( rotxorpres, oldxorrot ); _wpi_selectobject( rotandpres, oldandrot ); _wpi_deletecompatiblepres( rotandpres, rotanddc ); _imged_getthebits( xorbits, xorpres, node->hxorbitmap, oldxor ); _imged_getthebits( rotxorbits, rotxorpres, rotxorbmp, oldxorrot ); if( whichway == ROTATE_COUNTERCLOCKWISE ) { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = _imged_getpixel( xorbits, xorpres, right - y - 1, top + x ); _imged_setpixel( rotxorbits, rotxorpres, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } else { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = _imged_getpixel( xorbits, xorpres, left + y, bottom - x - 1 ); _imged_setpixel( rotxorbits, rotxorpres, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } _imged_freethebits( xorbits, xorpres, node->hxorbitmap, FALSE, oldxor ); _imged_freethebits( rotxorbits, rotxorpres, rotxorbmp, TRUE, oldxorrot ); _wpi_deletecompatiblepres( xorpres, xordc ); _wpi_deletecompatiblepres( rotxorpres, rotxordc ); } else { // We can use the bits.c routines for icons and cursors. xorbits = GetTheBits( node->hxorbitmap ); andbits = GetTheBits( node->handbitmap ); rotxorbits = GetTheBits( rotxorbmp ); rotandbits = GetTheBits( rotandbmp ); if( whichway != IMGED_ROTATECC ) { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = MyGetPixel( xorbits, right - y - 1, top + x ); MySetPixel( rotxorbits, x, y, color ); color = MyGetPixel( andbits, right - y - 1, top + x ); MySetPixel( rotandbits, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } else { for( y = 0; y < new_height; y++ ) { for( x = 0; x < new_width; x++ ) { color = MyGetPixel( xorbits, left + y, bottom - x - 1 ); MySetPixel( rotxorbits, x, y, color ); color = MyGetPixel( andbits, left + y, bottom - x - 1 ); MySetPixel( rotandbits, x, y, color ); i++; temp = i * 100; amt_done = temp / total_amt; if( amt_done - prev_amt >= 2 ) { IEPrintRotateAmt( amt_done ); prev_amt = amt_done; } } } } FreeTheBits( xorbits, node->hxorbitmap, FALSE ); FreeTheBits( andbits, node->handbitmap, FALSE ); FreeTheBits( rotxorbits, rotxorbmp, TRUE ); FreeTheBits( rotandbits, rotandbmp, TRUE ); } } /* rotateTheImage */
/* * RegionXorAnd - Draws a filled or framed region (ellipse or rectangle) in * the View window. */ void RegionXorAnd( COLORREF xorcolour, COLORREF andcolour, BOOL fFillRgn, WPI_RECT *r, BOOL is_rect ) { HBRUSH oldbrush; HBRUSH hbrush; HPEN oldpen; HPEN hpen; WPI_PRES mempres; HDC memdc; WPI_PRES pres; HBITMAP oldbitmap; int left; int top; int right; int bottom; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); hpen = _wpi_createpen( PS_SOLID, 0, xorcolour ); oldpen = _wpi_selectobject( mempres, hpen ); oldbitmap = _wpi_selectobject( mempres, activeImage->hxorbitmap ); if ( fFillRgn ) { hbrush = _wpi_createsolidbrush( xorcolour ); } else { hbrush = _wpi_createnullbrush(); } oldbrush = _wpi_selectobject( mempres, hbrush ); _wpi_getintrectvalues( *r, &left, &top, &right, &bottom ); if (is_rect) { _wpi_rectangle( mempres, left, top, right, bottom ); } else { _wpi_ellipse( mempres, left, top, right, bottom ); } _wpi_selectobject( mempres, oldpen ); _wpi_deletepen( hpen ); _wpi_selectobject( mempres, oldbrush ); _wpi_selectobject( mempres, oldbitmap ); if (fFillRgn) { _wpi_deleteobject( hbrush ); } else { _wpi_deletenullbrush( hbrush ); } if( activeImage->imgtype == BITMAP_IMG ) { _wpi_deletecompatiblepres( mempres, memdc ); return; } hpen = _wpi_createpen( PS_SOLID, 0, andcolour ); oldpen = _wpi_selectobject( mempres, hpen ); oldbitmap = _wpi_selectobject( mempres, activeImage->handbitmap ); if ( fFillRgn ) { hbrush = _wpi_createsolidbrush( andcolour ); } else { hbrush = _wpi_createnullbrush(); } oldbrush = _wpi_selectobject( mempres, hbrush ); if (is_rect) { _wpi_rectangle( mempres, left, top, right, bottom ); } else { _wpi_ellipse( mempres, left, top, right, bottom ); } _wpi_selectobject( mempres, oldpen ); _wpi_deletepen( hpen ); _wpi_selectobject( mempres, oldbrush ); _wpi_selectobject( mempres, oldbitmap ); if (fFillRgn) { _wpi_deleteobject( hbrush ); } else { _wpi_deletenullbrush( hbrush ); } _wpi_deletecompatiblepres( mempres, memdc ); } /* RegionXorAnd */
/* * PasteImage - paste the image in the clipboard at the current point * - first check to see if the image was cut/copied from our program * - if it was, then we use the hXorClipped and hAndClipped bitmaps * we created in order to preserve the screen colors if ther were used * - otherwise, just copy from the clipboard */ void PasteImage( WPI_POINT *pt, WPI_POINT pointsize, HWND hwnd ) { HBITMAP hbitmap; HBITMAP hbitmapdup; HBITMAP holddup; HBITMAP oldbitmap; HBITMAP oldbitmap2; WPI_PRES pres; WPI_PRES mempres; HDC memdc; WPI_PRES clippres; HDC clipdc; WPI_RECT client; WPI_POINT truept; short width; short height; short clipwidth; short clipheight; img_node *node; int fstretchbmp; int bm_width, bm_height; WPI_RECTDIM left; WPI_RECTDIM right; WPI_RECTDIM top; WPI_RECTDIM bottom; WPI_RECTDIM client_l; WPI_RECTDIM client_r; WPI_RECTDIM client_t; WPI_RECTDIM client_b; #ifdef __OS2_PM__ int src_y, dest_y; #endif if( fEnableCutCopy ) { _wpi_getwrectvalues( clipRect.rect, &left, &top, &right, &bottom ); truept.x = left; truept.y = top; fstretchbmp = StretchPastedImage(); } else { truept.x = pt->x / pointsize.x; truept.y = pt->y / pointsize.y; fstretchbmp = -1; } node = SelectImage( hwnd ); pres = _wpi_getpres( node->viewhwnd ); if( _wpi_getclipboardowner( Instance ) == HMainWindow && node->imgtype != BITMAP_IMG ) { _wpi_getbitmapdim( hAndClipped, &bm_width, &bm_height ); GetClientRect( node->hwnd, &client ); if( fEnableCutCopy ) { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } else { _wpi_getrectvalues( client, &client_l, &client_t, &client_r, &client_b ); width = (short)( client_r / pointsize.x - truept.x ); if( width > (short)bm_width ) width = (short)bm_width; height = (short)( client_b / pointsize.y - truept.y ); if( height > (short)bm_height ) { height = (short)bm_height; } } mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_setstretchbltmode( mempres, COLORONCOLOR ); clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); oldbitmap2 = _wpi_selectbitmap( clippres, hAndClipped ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, BLACKNESS ); _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); hbitmapdup = DuplicateBitmap( hXorClipped ); _wpi_getoldbitmap( clippres, oldbitmap2 ); oldbitmap2 = _wpi_selectbitmap( clippres, hbitmapdup ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS ); #ifdef __OS2_PM__ if( bm_height > height ) { src_y = bm_height - height; dest_y = truept.y; } else { src_y = 0; dest_y = truept.y + (height - bm_height); } _wpi_bitblt( mempres, truept.x, dest_y, clipwidth, clipheight, clippres, 0, src_y, SRCCOPY ); #else _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); #endif } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY ); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_getoldbitmap( clippres, oldbitmap2 ); _wpi_deletebitmap( hbitmapdup ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deletecompatiblepres( clippres, clipdc ); } else { if( node->imgtype != BITMAP_IMG ) { CleanupClipboard(); } _wpi_openclipboard( Instance, HMainWindow ); hbitmap = _wpi_getclipboarddata( Instance, CF_BITMAP ); hbitmapdup = DuplicateBitmap( hbitmap ); _wpi_closeclipboard( Instance ); _wpi_getbitmapdim( hbitmapdup, &bm_width, &bm_height ); GetClientRect( node->hwnd, &client ); if( fEnableCutCopy ) { width = (short)_wpi_getwidthrect( clipRect.rect ); height = (short)_wpi_getheightrect( clipRect.rect ); } else { _wpi_getrectvalues( client, &client_l, &client_t, &client_r, &client_b ); width = (short)( client_r / pointsize.x - truept.x ); if( width > (short)bm_width ) width = (short)bm_width; height = (short)( client_b / pointsize.y - truept.y ); if( height > (short)bm_height ) { height = (short)bm_height; } } clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_setstretchbltmode( mempres, COLORONCOLOR ); holddup = _wpi_selectbitmap( clippres, hbitmapdup ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); if( fstretchbmp == FALSE ) { clipwidth = (short)bm_width; if( clipwidth > (short)width ) clipwidth = (short)width; clipheight = (short)bm_height; if( clipheight > (short)height ) clipheight = (short)height; _wpi_patblt( mempres, truept.x, truept.y, width, height, WHITENESS ); #ifdef __OS2_PM__ if( bm_height > height ) { src_y = bm_height - height; dest_y = truept.y; } else { src_y = 0; dest_y = truept.y + (height - bm_height); } _wpi_bitblt( mempres, truept.x, dest_y, clipwidth, clipheight, clippres, 0, src_y, SRCCOPY ); #else _wpi_bitblt( mempres, truept.x, truept.y, clipwidth, clipheight, clippres, 0, 0, SRCCOPY ); #endif } else if( fstretchbmp == TRUE ) { _wpi_stretchblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, bm_width, bm_height, SRCCOPY ); } else { _wpi_bitblt( mempres, truept.x, truept.y, width, height, clippres, 0, 0, SRCCOPY ); } _wpi_getoldbitmap( clippres, holddup ); _wpi_deletebitmap( hbitmapdup ); _wpi_deletecompatiblepres( clippres, clipdc ); _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); _wpi_patblt( mempres, truept.x, truept.y, width, height, BLACKNESS ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); } ReleaseCapture(); _wpi_releasepres( node->viewhwnd, pres ); InvalidateRect( node->viewhwnd, NULL, TRUE ); if( !fEnableCutCopy ) { _wpi_setcursor( prevCursor ); _wpi_destroycursor( pointCursor ); SetToolType( prevToolType ); } fEnableCutCopy = FALSE; RecordImage( hwnd ); BlowupImage( NULL, NULL ); PrintHintTextByID( WIE_BITMAPPASTED, NULL ); } /* PasteImage */
/* * copyImageToClipboard - copies the image to the clipboard */ static void copyImageToClipboard( short width, short height, img_node *node ) { HMENU hmenu; WPI_PRES pres; WPI_PRES mempres; HDC memdc; WPI_PRES clippres; HDC clipdc; HBITMAP hbitmap; HBITMAP oldbitmap; HBITMAP oldclipbitmap; HBITMAP viewbitmap; WPI_RECTDIM left; WPI_RECTDIM top; WPI_RECTDIM right; WPI_RECTDIM bottom; int clip_width, clip_height; CleanupClipboard(); pres = _wpi_getpres( node->viewhwnd ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); hbitmap = _wpi_createcompatiblebitmap( pres, width, height ); viewbitmap = CreateViewBitmap( node ); oldbitmap = _wpi_selectbitmap( mempres, viewbitmap ); oldclipbitmap = _wpi_selectbitmap( clippres, hbitmap ); clip_width = _wpi_getwidthrect( clipRect.rect ); clip_height = _wpi_getheightrect( clipRect.rect ); /* * use getwrectvalues because we want top and left to be our origins * (i.e. in PM the origin is the bottom) */ _wpi_getwrectvalues( clipRect.rect, &left, &top, &right, &bottom ); _wpi_bitblt( clippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_openclipboard( Instance, HMainWindow ); _wpi_emptyclipboard( Instance ); _wpi_setclipboarddata( Instance, CF_BITMAP, hbitmap, TRUE ); _wpi_closeclipboard( Instance ); _wpi_getoldbitmap( clippres, oldclipbitmap ); _wpi_deletecompatiblepres( clippres, clipdc ); clippres = _wpi_createcompatiblepres( pres, Instance, &clipdc ); hXorClipped = _wpi_createcompatiblebitmap( pres, width, height ); _wpi_getoldbitmap( mempres, oldbitmap ); oldbitmap = _wpi_selectbitmap( mempres, node->hxorbitmap ); oldclipbitmap = _wpi_selectbitmap( clippres, hXorClipped ); _wpi_bitblt( clippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_getoldbitmap( clippres, oldclipbitmap ); hAndClipped = _wpi_createcompatiblebitmap( pres, width, height ); oldbitmap = _wpi_selectbitmap( mempres, node->handbitmap ); oldclipbitmap = _wpi_selectbitmap( clippres, hAndClipped ); _wpi_bitblt( clippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_getoldbitmap( clippres, oldclipbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deletecompatiblepres( clippres, clipdc ); _wpi_deletebitmap( viewbitmap ); _wpi_releasepres( node->viewhwnd, pres ); hmenu = GetMenu( _wpi_getframe( HMainWindow ) ); _wpi_enablemenuitem( hmenu, IMGED_PASTE, TRUE, FALSE ); } /* copyImageToClipboard */
/* * CreateViewBitmap - create the bitmap on the screen (with the background * color as it should be, etc.) * - the caller is responsible for deleting the bitmap */ HBITMAP CreateViewBitmap( img_node *mdi_node ) { WPI_PRES pres; WPI_PRES xorandpres; WPI_PRES mempres; WPI_PRES freehandpres; HDC xoranddc; HDC memdc; HBITMAP newbitmap; HBITMAP oldxorandbitmap; HBITMAP oldbitmap; HBRUSH brush; HBRUSH oldbrush; img_node *node; COLORREF bkcolor; if( mdi_node != NULL ) { node = mdi_node; } else { node = GetCurrentNode(); if( node == NULL ) { return( NULL ); } } pres = _wpi_getpres( HWND_DESKTOP ); xorandpres = _wpi_createcompatiblepres( pres, Instance, &xoranddc ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); newbitmap = _wpi_createcompatiblebitmap( pres, node->width, node->height ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); _wpi_torgbmode( xorandpres ); bkcolor = GetViewBkColor(); #ifdef __OS2_PM__ _wpi_preparemono( mempres, BLACK, bkcolor ); #endif oldbitmap = _wpi_selectobject( mempres, newbitmap ); brush = _wpi_createsolidbrush( bkcolor ); oldbrush = _wpi_selectobject( mempres, brush ); _wpi_patblt( mempres, 0, 0, node->width, node->height, PATCOPY ); _wpi_selectobject( mempres, oldbrush ); _wpi_deletebrush( brush ); GetFreeHandPresentationSpaces( NULL, &freehandpres, NULL ); if( freehandpres == (WPI_PRES)NULL ) { oldxorandbitmap = _wpi_selectobject( xorandpres, node->handbitmap ); _wpi_bitblt( mempres, 0, 0, node->width, node->height, xorandpres, 0, 0, SRCAND ); _wpi_selectobject( xorandpres, oldxorandbitmap ); } else { _wpi_bitblt( mempres, 0, 0, node->width, node->height, freehandpres, 0, 0, SRCAND ); } GetFreeHandPresentationSpaces( NULL, NULL, &freehandpres ); if( freehandpres == (WPI_PRES)NULL ) { oldxorandbitmap = _wpi_selectobject( xorandpres, node->hxorbitmap ); _wpi_bitblt( mempres, 0, 0, node->width, node->height, xorandpres, 0, 0, SRCINVERT ); _wpi_selectobject( xorandpres, oldxorandbitmap ); } else { _wpi_bitblt( mempres, 0, 0, node->width, node->height, freehandpres, 0, 0, SRCINVERT ); } _wpi_deletecompatiblepres( xorandpres, xoranddc ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); return( newbitmap ); } /* CreateViewBitmap */
/* * IEStretchBlt */ static BOOL IEStretchBlt( WPI_PRES hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, WPI_PRES hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, DWORD fdwRop, int bitcount ) { POINT slines; POINT dlines; POINT num_strips; unsigned long linesize; int x, y; int sw, sh, dw, dh; WPI_PRES srcpres; HDC srcdc; HBITMAP oldbitmap; HBITMAP newbitmap; num_strips.x = nWidthDest / 256; num_strips.x++; #if 0 if( nWidthDest > 32 ) { /* use the version that returns exact bytes needed for bits */ linesize = BITS_INTO_BYTES( (unsigned long)(nWidthDest * bitcount), 1 ); } else { /* use the version that rounds up to 32 bits */ linesize = BITS_TO_BYTES( (unsigned long)(nWidthDest * bitcount), 1 ); } #else /* use the version that rounds up to 32 bits */ linesize = BITS_TO_BYTES( (unsigned long)(nWidthDest * bitcount), 1 ); #endif num_strips.y = ((unsigned long)nHeightDest * linesize) / (16 * 1024); num_strips.y++; if( num_strips.x > nWidthSrc ) { num_strips.x = nWidthSrc; } else if( num_strips.x < nWidthSrc ) { num_strips.x += num_strips.x % 2; } if( num_strips.y > nHeightSrc ) { num_strips.y = nHeightSrc; } else if( num_strips.y < nHeightSrc ) { num_strips.y += num_strips.y % 2; } slines.x = nWidthSrc / num_strips.x; dlines.x = ((unsigned long)slines.x * (unsigned long)nWidthDest) / (unsigned long)nWidthSrc; slines.y = nHeightSrc / num_strips.y; dlines.y = ((unsigned long)slines.y * (unsigned long)nHeightDest) / (unsigned long)nHeightSrc; srcpres = _wpi_createcompatiblepres( hdcDest, Instance, &srcdc ); newbitmap = _wpi_createcompatiblebitmap( hdcDest, dlines.x, dlines.y ); oldbitmap = _wpi_selectobject( srcpres, newbitmap ); sw = slines.x; dw = dlines.x; for( x = 0; slines.x * x <= nWidthSrc; x++ ) { if( slines.x * x + sw > nWidthSrc ) { sw = nWidthSrc - x * slines.x; dw = nWidthDest - x * dlines.x; } sh = slines.y; dh = dlines.y; for( y = 0; slines.y * y <= nHeightSrc; y++ ) { if( slines.y * y + sh > nHeightSrc ) { sh = nHeightSrc - y * slines.y; dh = nHeightDest - y * dlines.y; } _wpi_stretchblt( srcpres, 0, 0, dw, dh, hdcSrc, nXOriginSrc + slines.x * x, nYOriginSrc + slines.y * y, sw, sh, fdwRop ); _wpi_bitblt( hdcDest, nXOriginDest + dlines.x * x, nYOriginDest + dlines.y * y, dw, dh, srcpres, 0, 0, SRCCOPY ); } } _wpi_selectobject( srcpres, oldbitmap ); _wpi_deleteobject( newbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); return( TRUE ); } /* IEStretchBlt */
void GUIDrawBitmap( int hot_spot, WPI_PRES hdc, int nDrawX, int nDrawY, WPI_COLOUR bkcolour) { WPI_POINT src_org; WPI_POINT dst_org; WPI_POINT size; WPI_PRES memDC; HBITMAP old_bmp; HBITMAP bitmap; HDC new_hdc; #ifdef __NT__ HDC new_hdc2; HBITMAP oldbmp2; HDC mem2; COLORREF cr; #endif bitmap = GUIHotSpots[hot_spot - 1].bitmap; size.x = GUIHotSpots[hot_spot - 1].size.x; size.y = GUIHotSpots[hot_spot - 1].size.y; src_org.x = 0; src_org.y = 0; dst_org.x = nDrawX; dst_org.y = nDrawY; _wpi_dptolp( hdc, &size, 1 ); _wpi_dptolp( hdc, &dst_org, 1 ); _wpi_dptolp( hdc, &src_org, 1 ); memDC = _wpi_createcompatiblepres( hdc, GUIMainHInst, &new_hdc ); old_bmp = _wpi_selectbitmap( memDC, bitmap ); #ifdef __NT__ /* Skip transparency for huge bitmaps, only splashes and such... */ if( size.x < 50 && size.y < 50) { /* New, on WIN32 platforms, use TB_TransparentBlt() */ mem2 = _wpi_createcompatiblepres( hdc, GUIMainHInst, &new_hdc2 ); if( bitmap2 == NULL) bitmap2 = CreateCompatibleBitmap( hdc, 50, 50 ); oldbmp2 = _wpi_selectbitmap( mem2, bitmap2 ); /* Get background color of bitmap */ /* Expects 0,0 pos in original to be in background/transp. color */ cr = GetPixel(memDC, 0, 0); /* IMPORTANT: must set required new background color for dest bmp */ // SetBkColor( mem2, GetSysColor(COLOR_BTNFACE) ); SetBkColor( mem2, bkcolour ); TB_TransparentBlt( mem2, src_org.x, src_org.y, size.x, size.y, memDC, cr ); _wpi_bitblt( hdc, dst_org.x, dst_org.y, size.x, size.y, mem2, src_org.x, src_org.y, SRCCOPY ); /* Clean up */ _wpi_selectbitmap( mem2, oldbmp2 ); _wpi_deletecompatiblepres( mem2, hdc ); } else { // Normal for large bitmaps... _wpi_bitblt( hdc, dst_org.x, dst_org.y, size.x, size.y, memDC, src_org.x, src_org.y, SRCCOPY ); } #else _wpi_bitblt( hdc, dst_org.x, dst_org.y, size.x, size.y, memDC, src_org.x, src_org.y, SRCCOPY ); #endif if( old_bmp != NULLHANDLE ) { _wpi_getoldbitmap( memDC, old_bmp ); } _wpi_deletecompatiblepres( memDC, new_hdc ); }
/* * EnlargeImage - take an MDI window handle and enlarge the view bitmap * that goes with it * - returns a handle to the bitmap * - the bitmap must be deleted by the calling routine */ HBITMAP EnlargeImage( HWND hwnd ) { WPI_PRES pres; WPI_PRES srcpres; WPI_PRES destpres; HDC srcdc; HDC destdc; HBITMAP oldbitmap; HBITMAP newbitmap; HBITMAP olddestbitmap; HBITMAP viewbitmap; img_node *node; WPI_RECT rc; short width; short height; int window_width; int window_height; BITMAP bm; node = SelectImage( hwnd ); if( node == NULL ) { return( NULL ); } viewbitmap = CreateViewBitmap( node ); _wpi_getclientrect( hwnd, &rc ); /* * I add this so that if the window's client rect doesn't fit on the * screen, it will still enlarge to the right size. */ window_width = _wpi_getwidthrect( rc ); window_height = _wpi_getheightrect( rc ); if( window_width < node->width ) { window_width = node->width; } if( window_height < node->height ) { window_height = node->height; } pres = _wpi_getpres( HWND_DESKTOP ); srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc ); destpres = _wpi_createcompatiblepres( pres, Instance, &destdc ); newbitmap = _wpi_createcompatiblebitmap( pres, _wpi_getwidthrect( rc ), _wpi_getheightrect( rc ) ); _wpi_releasepres( HWND_DESKTOP, pres ); GetObject( newbitmap, sizeof( BITMAP ), &bm ); _wpi_torgbmode( destpres ); _wpi_torgbmode( srcpres ); olddestbitmap = _wpi_selectobject( destpres, newbitmap ); oldbitmap = _wpi_selectobject( srcpres, viewbitmap ); height = node->height; width = node->width; IEStretchBlt( destpres, 0, 0, _wpi_getwidthrect( rc ), _wpi_getheightrect( rc ), srcpres, 0, 0, width, height, SRCCOPY, bm.bmBitsPixel ); _wpi_selectobject( srcpres, oldbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); _wpi_deleteobject( viewbitmap ); _wpi_selectobject( destpres, olddestbitmap ); _wpi_deletecompatiblepres( destpres, destdc ); return( newbitmap ); } /* EnlargeImage */
/* * stretchIntoArea - stretch the rotated image into the area specified */ static void stretchIntoArea( img_node *node, WPI_RECT *rect, HBITMAP rotxorbmp, HBITMAP rotandbmp ) { WPI_PRES pres; WPI_PRES xorpres; HDC xordc; WPI_PRES andpres; HDC anddc; WPI_PRES rotxorpres; HDC rotxordc; WPI_PRES rotandpres; HDC rotanddc; HBITMAP oldxor; HBITMAP oldand; HBITMAP oldxorrot; HBITMAP oldandrot; short width; short height; IMGED_DIM left; IMGED_DIM right; IMGED_DIM bottom; IMGED_DIM top; width = (short)_wpi_getwidthrect( *rect ); height = (short)_wpi_getheightrect( *rect ); _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc ); andpres = _wpi_createcompatiblepres( pres, Instance, &anddc ); rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc ); rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( xorpres ); _wpi_torgbmode( andpres ); _wpi_torgbmode( rotxorpres ); _wpi_torgbmode( rotandpres ); oldxor = _wpi_selectobject( xorpres, node->hxorbitmap ); oldand = _wpi_selectobject( andpres, node->handbitmap ); oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp ); oldandrot = _wpi_selectobject( rotandpres, rotandbmp ); _wpi_setstretchbltmode( xorpres, STRETCH_COLOR ); _wpi_stretchblt( xorpres, left, top, width, height, rotxorpres, 0, 0, height, width, SRCCOPY ); _wpi_setstretchbltmode( andpres, STRETCH_COLOR ); _wpi_stretchblt( andpres, left, top, width, height, rotandpres, 0, 0, height, width, SRCCOPY ); _wpi_selectobject( xorpres, oldxor ); _wpi_selectobject( andpres, oldand ); _wpi_selectobject( rotxorpres, oldxorrot ); _wpi_selectobject( rotandpres, oldandrot ); _wpi_deletecompatiblepres( xorpres, xordc ); _wpi_deletecompatiblepres( andpres, anddc ); _wpi_deletecompatiblepres( rotxorpres, rotxordc ); _wpi_deletecompatiblepres( rotandpres, rotanddc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); } /* stretchIntoArea */
void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; WPI_RECT fill_area; #ifdef __OS2_PM__ ULONG flags; RECTL client; #endif isdlg=isdlg; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; /* Setup Paint */ wnd->ps = &ps; wnd->hdc = _wpi_beginpaint( hwnd, NULLHANDLE, wnd->ps ); _wpi_torgbmode( wnd->hdc ); _wpi_getpaintrect( wnd->ps, &fill_area ); #ifdef __OS2_PM__ fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); #endif #if defined( __NT__ ) if( isdlg ) { _wpi_fillrect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ), wnd->bk_brush ); } #endif if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } else { wnd->prev_font = NULL; } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } #ifdef __OS2_PM__ if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( wnd->hdc, &client, 1, 1, 0, 0, flags ); } #endif _wpi_endpaint( hwnd, wnd->hdc, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; } #else // this is some experimental PM stuff void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; PAINTSTRUCT fill_area; // experimenal stuff HPS hps; RECTL client; LONG width, height; ULONG flags; int compat_created; gui_paint_info *pinfo; // figure out which paint info to use if( !isdlg && wnd->root == hwnd ) { pinfo = &wnd->root_pinfo; } else { pinfo = &wnd->hwnd_pinfo; } pinfo->in_use++; compat_created = FALSE; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; if( isdlg ) { _wpi_getclientrect( hwnd, &client ); } else { WinQueryWindowRect( hwnd, &client ); } width = client.xRight - client.xLeft; height = client.yTop - client.yBottom; wnd->ps = &ps; //hps = _wpi_beginpaint( hwnd, pinfo->normal_pres, wnd->ps ); hps = _wpi_beginpaint( hwnd, NULL, wnd->ps ); if( pinfo->compatible_pres == (WPI_PRES)NULL ) { compat_created = TRUE; pinfo->compatible_pres = _wpi_createcompatiblepres( hps, GUIMainHInst, &pinfo->compatible_hdc ); pinfo->draw_bmp = _wpi_createcompatiblebitmap( hps, width, height ); pinfo->old_bmp = _wpi_selectbitmap( pinfo->compatible_pres, pinfo->draw_bmp ); } // the condition is here VERY conservative!! // its gains have to analyzed if( compat_created || pinfo->force_count ) { wnd->hdc = pinfo->compatible_pres; //wnd->hdc = hps; _wpi_torgbmode( wnd->hdc ); fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); wnd->prev_font = NULL; if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } if( pinfo->force_count ) { //pinfo->force_count--; } } //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); if( pinfo->in_use == 1 ) { //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); _wpi_bitblt( hps, ps.xLeft, ps.yBottom, ps.xRight - ps.xLeft, ps.yTop - ps.yBottom, wnd->hdc, ps.xLeft, ps.yBottom, SRCCOPY ); if( pinfo->delete_when_done ) { GUIFreePaintHandles( pinfo, TRUE ); } } if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( hps, &client, 1, 1, 0, 0, flags ); } _wpi_endpaint( hwnd, hps, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; if( pinfo->in_use ) { pinfo->in_use--; } } #endif void GUIInvalidatePaintHandles( gui_window *wnd ) { GUIFreeWndPaintHandles( wnd, FALSE ); }
/* * simpleRotate - simply rotate the image around the center of the given rectangle */ static void simpleRotate( img_node *node, WPI_RECT *rect, HBITMAP rotxorbmp, HBITMAP rotandbmp, BOOL rectexists ) { WPI_POINT topleft; WPI_POINT centre_pt; WPI_PRES pres; HDC xordc; WPI_PRES xorpres; HDC anddc; WPI_PRES andpres; HDC rotxordc; WPI_PRES rotxorpres; HDC rotanddc; WPI_PRES rotandpres; HBITMAP oldxor; HBITMAP oldand; HBITMAP oldxorrot; HBITMAP oldandrot; short width; short height; WPI_RECT new_rect; IMGED_DIM left; IMGED_DIM top; IMGED_DIM right; IMGED_DIM bottom; width = (short)_wpi_getwidthrect( *rect ); height = (short)_wpi_getheightrect( *rect ); /* * PM NOTE: The rectangle comes in with bottom = yTop and top = yBottom. * To use the same formula to calculate the center point and top left, we * use getwrectvalues. */ _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); centre_pt.x = (width / 2) + left; centre_pt.y = (height / 2) + top; topleft.x = centre_pt.x - centre_pt.y + top; topleft.y = centre_pt.y - centre_pt.x + left; pres = _wpi_getpres( HWND_DESKTOP ); xorpres = _wpi_createcompatiblepres( pres, Instance, &xordc ); andpres = _wpi_createcompatiblepres( pres, Instance, &anddc ); rotxorpres = _wpi_createcompatiblepres( pres, Instance, &rotxordc ); rotandpres = _wpi_createcompatiblepres( pres, Instance, &rotanddc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( xorpres ); _wpi_torgbmode( andpres ); _wpi_torgbmode( rotxorpres ); _wpi_torgbmode( rotandpres ); oldxor = _wpi_selectobject( xorpres, node->hxorbitmap ); oldand = _wpi_selectobject( andpres, node->handbitmap ); oldxorrot = _wpi_selectobject( rotxorpres, rotxorbmp ); oldandrot = _wpi_selectobject( rotandpres, rotandbmp ); _wpi_getwrectvalues( *rect, &left, &top, &right, &bottom ); _wpi_patblt( xorpres, left, top, width, height, WHITENESS ); _wpi_patblt( andpres, left, top, width, height, BLACKNESS ); _wpi_bitblt( xorpres, topleft.x, topleft.y, height, width, rotxorpres, 0, 0, SRCCOPY ); _wpi_bitblt( andpres, topleft.x, topleft.y, height, width, rotandpres, 0, 0, SRCCOPY ); _wpi_selectobject( xorpres, oldxor ); _wpi_selectobject( andpres, oldand ); _wpi_selectobject( rotxorpres, oldxorrot ); _wpi_selectobject( rotandpres, oldandrot ); _wpi_deletecompatiblepres( xorpres, xordc ); _wpi_deletecompatiblepres( andpres, anddc ); _wpi_deletecompatiblepres( rotxorpres, rotxordc ); _wpi_deletecompatiblepres( rotandpres, rotanddc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); RecordImage( node->hwnd ); if( DoKeepRect() ) { if( rectexists ) { _wpi_setwrectvalues( &new_rect, topleft.x, topleft.y, topleft.x+height, topleft.y + width ); SetDeviceClipRect( &new_rect ); } } else { rectexists = rectexists; new_rect = new_rect; SetRectExists( FALSE ); } BlowupImage( node->hwnd, NULL ); } /* simpleRotate */
void _L1GetPic( short x1, short y1, short x2, short y2, /*===============================*/ struct picture _WCI86HUGE *image ) /* Copy that portion of the screen inside the viewport to the buffer pointed by 'image'. */ { short dx; /* width of rectangle in pixels */ short dy; /* height of rectangle in pixels */ short t; #if defined( _DEFAULT_WINDOWS ) WPI_PRES dc; short srcy; #else short line_len; /* length of each line in bytes */ #if !defined( __386__ ) unsigned short new_off; #endif char *tmp; gr_device _FARD *dev_ptr; /* pointer to _CurrState->deviceptr */ char _WCI86HUGE *pic; /* buffer to store image */ copy_fn *copy; /* pointer to copy routine */ setup_fn *setup; #endif if( x1 > x2 ) { // ensure x1 < x2 t = x1; x1 = x2; x2 = t; } if( y1 > y2 ) { // ensure y1 < y2 t = y1; y1 = y2; y2 = t; } if( _L0BlockClip( &x1, &y1, &x2, &y2 ) != 0 ) { /* clip image to */ image->picwidth = 0; /* active viewport */ image->picheight = 0; _ErrorStatus = _GRNOOUTPUT; return; } dx = x2 - x1 + 1; /* row width in pixels */ dy = y2 - y1 + 1; /* height in pixel rows */ image->picwidth = dx; /* save width in image picture */ image->picheight = dy; /* save height in image picture */ #if defined( _DEFAULT_WINDOWS ) dc = _Mem_dc; // Create a memory DC to put the image in image->buffer = _wpi_createcompatiblepres( dc, _GetInst(), &( image->pdc ) ); image->bmp = _wpi_createcompatiblebitmap( dc, dx, dy ); if( ( image->buffer == NULL ) || ( image->bmp == NULL ) ) { _ErrorStatus = _GRINSUFFICIENTMEMORY; return; } _wpi_selectbitmap( image->buffer, image->bmp ); // Transfer the image to a memory DC #if defined( __OS2__ ) srcy = _wpi_cvth_y( y2, _GetPresHeight() ); #else srcy = y1; #endif _wpi_bitblt( image->buffer, 0, 0, dx, dy, dc, x1, srcy, SRCCOPY ); #else image->bpp = _CurrState->vc.bitsperpixel; /* save bpp - never used ? */ line_len = _RowLen( dx ); /* width of row in bytes */ _StartDevice(); dev_ptr = _CurrState->deviceptr; copy = dev_ptr->readrow; pic = &image->buffer; tmp = NULL; setup = dev_ptr->setup; for( ; y1 <= y2; ++y1 ) { /* copy screen image to buffer */ ( *setup )( x1, y1, 0 ); #if !defined( __386__ ) // check whether the entire row will fit in the buffer new_off = FP_OFF( pic ) + line_len - 1; if( new_off < FP_OFF( pic ) ) { if( tmp == NULL ) { // may have been already allocated if( _stackavail() - line_len > 0x100 ) { tmp = __alloca( _RoundUp( line_len ) ); } } if( tmp != NULL ) { ( *copy )( tmp, _Screen.mem, dx, _Screen.bit_pos, 0 ); for( t = 0; t < line_len; ++t ) { *pic = tmp[ t ]; ++pic; // the PIA function will handle this properly } } else { _ErrorStatus = _GRINSUFFICIENTMEMORY; pic += line_len; } } else { #endif ( *copy )( pic, _Screen.mem, dx, _Screen.bit_pos, 0 ); pic += line_len; #if !defined( __386__ ) } #endif } _ResetDevice(); #endif }
/* * FlipImage - flip the image along either the x-axis or the y-axis */ void FlipImage( WORD whichway ) { img_node *node; short width; short height; short destwidth; short destheight; short new_left; short new_top; WPI_RECT dims; HBITMAP xorflip; HBITMAP oldflip; HBITMAP oldbitmap; HBITMAP andflip; WPI_PRES pres; WPI_PRES mempres; HDC memdc; WPI_PRES flippres; HDC flipdc; HCURSOR prevcursor; IMGED_DIM bottom; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; node = GetCurrentNode(); if( node == NULL ) { return; } PrintHintTextByID( WIE_FLIPPINGIMAGE, NULL ); prevcursor = _wpi_setcursor( _wpi_getsyscursor( IDC_WAIT ) ); if( !DoesRectExist( &dims ) ) { _wpi_setwrectvalues( &dims, 0, 0, (IMGED_DIM)node->width, (IMGED_DIM)node->height ); } width = (short)_wpi_getwidthrect( dims ); height = (short)_wpi_getheightrect( dims ); pres = _wpi_getpres( HWND_DESKTOP ); if( node->bitcount == 1 ) { xorflip = _wpi_createbitmap( width, height, 1, 1, NULL ); } else { #if 1 xorflip = _wpi_createcompatiblebitmap( pres, width, height ); #else xorflip = _wpi_createbitmap( width, height, ColorPlanes, BitsPerPixel, NULL ); #endif } andflip = _wpi_createbitmap( width, height, 1, 1, NULL ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); flippres = _wpi_createcompatiblepres( pres, Instance, &flipdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_getrectvalues( dims, &left, &top, &right, &bottom ); _wpi_preparemono( flippres, BLACK, WHITE ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); oldflip = _wpi_selectobject( flippres, xorflip ); _wpi_bitblt( flippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( flippres, oldflip ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); oldflip = _wpi_selectobject( flippres, andflip ); _wpi_bitblt( flippres, 0, 0, width, height, mempres, left, top, SRCCOPY ); if( whichway == IMGED_FLIPVERT ) { destwidth = -1 * width; new_left = right - 1; new_top = top; destheight = height; } else { destwidth = width; new_left = left; new_top = bottom - 1; destheight = -1 * height; } _wpi_stretchblt( mempres, new_left, new_top, destwidth, destheight, flippres, 0, 0, width, height, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); _wpi_selectobject( flippres, oldflip ); oldflip = _wpi_selectobject( flippres, xorflip ); _wpi_stretchblt( mempres, new_left, new_top, destwidth, destheight, flippres, 0, 0, width, height, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( flippres, oldflip ); _wpi_deleteobject( xorflip ); _wpi_deleteobject( andflip ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_deletecompatiblepres( flippres, flipdc ); InvalidateRect( node->viewhwnd, NULL, TRUE ); if( !DoKeepRect() ) { SetRectExists( FALSE ); } RecordImage( node->hwnd ); BlowupImage( node->hwnd, NULL ); if( whichway == IMGED_FLIPHORZ ) { PrintHintTextByID( WIE_IMAGEREFLECTEDH, NULL ); } else { PrintHintTextByID( WIE_IMAGEREFLECTEDV, NULL ); } _wpi_setcursor( prevcursor ); } /* FlipImage */