/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * drawPt - Actually draws the point on the drawing region. (uses LineDDA) */ void CALLBACK drawPt( int xpos, int ypos, WPI_PARAM2 lparam ) { HBRUSH colourbrush; HBRUSH oldbrush; HPEN colourpen; HPEN oldpen; COLORREF selected_colour; COLORREF dithered; short mousebutton; WPI_PRES pres; HWND hwnd; short area_x; short area_y; short width; short height; short i; short j; WPI_POINT pt; WPI_RECT rcclient; wie_clrtype type; int brushsize; BOOL gridvisible; hwnd = (HWND)GET_HWND_PARAM2( lparam ); mousebutton = currentMouseButton; _wpi_getclientrect( hwnd, &rcclient ); brushsize = ImgedConfigInfo.brush_size; gridvisible = ImgedConfigInfo.grid_on && (pointSize.x >= POINTSIZE_MIN && pointSize.y >= POINTSIZE_MIN); if ((!gridvisible) && (toolType == IMGED_FREEHAND)) { area_x = xpos * pointSize.x; area_y = ypos * pointSize.y; width = (short)pointSize.x; height = (short)pointSize.y; } else if ((!gridvisible) && (toolType == IMGED_BRUSH)) { area_x = max(0, xpos-brushsize/2) * pointSize.x; area_y = max(0, ypos-brushsize/2) * pointSize.y; width = (short)(brushsize * pointSize.x); height = (short)(brushsize * pointSize.y); /* * We just have to check that we don't spill over the image dimensions */ area_x = min( area_x, _wpi_getwidthrect(rcclient)-width ); area_y = min( area_y, _wpi_getheightrect(rcclient)-width ); } else if ((gridvisible) && (toolType == IMGED_FREEHAND)) { area_x = xpos * pointSize.x+1; area_y = ypos * pointSize.y+1; width = (short)(pointSize.x-1); height = (short)(pointSize.y-1); } else { area_x = max(0, xpos-brushsize/2) * pointSize.x+1; area_y = max(0, ypos-brushsize/2) * pointSize.y+1; width = (short)(pointSize.x - 1); height = (short)(pointSize.y - 1); /* * We just have to check that we don't spill over the image dimensions */ area_x = min( area_x, _wpi_getwidthrect(rcclient) - pointSize.x * brushsize+1 ); area_y = min( area_y, _wpi_getheightrect(rcclient) - pointSize.y * brushsize+1 ); } pres = _wpi_getpres( hwnd ); _wpi_torgbmode( pres ); dithered = GetSelectedColour( mousebutton, &selected_colour, &type ); colourbrush = _wpi_createsolidbrush( selected_colour ); oldbrush = _wpi_selectobject(pres, colourbrush); colourpen = _wpi_createpen(PS_SOLID, 0, selected_colour); oldpen = _wpi_selectobject(pres, colourpen); if (gridvisible && (toolType == IMGED_BRUSH)) { for (i=0; i < brushsize; ++i) { for (j=0; j < brushsize; ++j) { _wpi_patblt(pres, area_x+i*pointSize.x, area_y+j*pointSize.y, width, height, PATCOPY); } } } else { _wpi_patblt(pres, area_x, area_y, width, height, PATCOPY); } _wpi_selectobject(pres, oldbrush); _wpi_selectobject(pres, oldpen); _wpi_releasepres( hwnd, pres ); _wpi_deleteobject( colourbrush ); _wpi_deleteobject( colourpen ); pt.x = area_x / pointSize.x; pt.y = area_y / pointSize.y; if (toolType == IMGED_BRUSH) { if (type == SCREEN_CLR) { BrushThePoints(selected_colour, BLACK, WHITE, &pt, brushsize); } else if (type == INVERSE_CLR) { BrushThePoints(selected_colour, WHITE, WHITE, &pt, brushsize); } else { BrushThePoints(selected_colour, selected_colour, BLACK, &pt, brushsize); } } else { if (type == SCREEN_CLR) { DrawThePoints(selected_colour, BLACK, WHITE, &pt); } else if (type == INVERSE_CLR) { DrawThePoints(selected_colour, WHITE, WHITE, &pt); } else { DrawThePoints(selected_colour, selected_colour, BLACK, &pt); } } } /* drawPt */
/* * DrawSinglePoint - needed for when the mouse button is initially pressed. */ void DrawSinglePoint( HWND hwnd, WPI_POINT *pt, short mousebutton ) { HBRUSH colourbrush; HBRUSH oldbrush; HPEN colourpen; HPEN oldpen; COLORREF selected_colour; COLORREF dithered; short truncated_x; short truncated_y; short i; short j; WPI_POINT logical_pt; WPI_RECT rcclient; short width; short height; short wndwidth; short wndheight; wie_clrtype type; WPI_PRES pres; int brushsize; BOOL gridvisible; GetClientRect( hwnd, &rcclient ); wndwidth = _wpi_getwidthrect( rcclient ); wndheight = _wpi_getheightrect( rcclient ); brushsize = ImgedConfigInfo.brush_size; CheckBounds( hwnd, pt ); gridvisible = ImgedConfigInfo.grid_on && (pointSize.x >= POINTSIZE_MIN && pointSize.y >= POINTSIZE_MIN); if (gridvisible) { if (toolType == IMGED_BRUSH) { truncated_x = max(0, (pt->x/pointSize.x - brushsize/2)) * pointSize.x+1; truncated_y = max(0, (pt->y/pointSize.y - brushsize/2)) * pointSize.y+1; width = (short)(pointSize.x - 1); height = (short)(pointSize.y - 1); /* * We just have to check that we don't spill over the image dimensions */ truncated_x = min(truncated_x, wndwidth-pointSize.x*brushsize+1); truncated_y = min(truncated_y, wndheight-pointSize.y*brushsize+1); } else { truncated_x = ( pt->x / pointSize.x) * pointSize.x + 1; truncated_y = ( pt->y / pointSize.y) * pointSize.y + 1; width = (short)(pointSize.x - 1); height = (short)(pointSize.y - 1); } } else { if (toolType == IMGED_BRUSH) { truncated_x = max(0, (pt->x / pointSize.x - brushsize/2)) * pointSize.x; truncated_y = max(0, (pt->y / pointSize.y - brushsize/2)) * pointSize.y; width = (short)(pointSize.x * brushsize); height = (short)(pointSize.y * brushsize); /* * We just have to check that we don't spill over the image dimensions */ truncated_x = min( truncated_x, wndwidth-width ); truncated_y = min( truncated_y, wndheight-width ); } else { truncated_x = ( pt->x / pointSize.x) * pointSize.x; truncated_y = ( pt->y / pointSize.y) * pointSize.y; width = (short)pointSize.x; height = (short)pointSize.y; } } logical_pt.x = truncated_x / pointSize.x; logical_pt.y = truncated_y / pointSize.y; pres = _wpi_getpres( hwnd ); _wpi_torgbmode( pres ); dithered = GetSelectedColour(mousebutton, &selected_colour, &type); colourbrush = _wpi_createsolidbrush( selected_colour ); oldbrush = _wpi_selectobject( pres, colourbrush ); colourpen = _wpi_createpen( PS_SOLID, 0, selected_colour ); oldpen = _wpi_selectobject( pres, colourpen ); if (gridvisible && (toolType == IMGED_BRUSH)) { for (i=0; i < brushsize; ++i) { for (j=0; j < brushsize; ++j) { _wpi_patblt(pres, truncated_x+i*pointSize.x, truncated_y+j*pointSize.y, width, height, PATCOPY); } } } else { _wpi_patblt(pres, truncated_x, truncated_y, width, height, PATCOPY); } _wpi_selectobject( pres, oldbrush ); _wpi_selectobject( pres, oldpen ); _wpi_releasepres( hwnd, pres ); _wpi_deleteobject( colourbrush ); _wpi_deleteobject( colourpen ); /* * draws the points in the view window */ if (toolType == IMGED_BRUSH) { if (type == SCREEN_CLR) { BrushThePoints(selected_colour, BLACK, WHITE, &logical_pt, brushsize); } else if (type == INVERSE_CLR) { BrushThePoints(selected_colour, WHITE, WHITE, &logical_pt, brushsize); } else { BrushThePoints(selected_colour, selected_colour, BLACK, &logical_pt, brushsize); } } else { if (type == SCREEN_CLR) { DrawThePoints(selected_colour, BLACK, WHITE, &logical_pt); } else if (type == INVERSE_CLR) { DrawThePoints(selected_colour, WHITE, WHITE, &logical_pt); } else { DrawThePoints(selected_colour, selected_colour, BLACK, &logical_pt); } } } /* DrawSinglePoint */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */