/* * 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 */
/* * 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 */
/* * 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 */
/* * RotateImage - rotate the image either clockwise or counterclockwise */ void RotateImage( WORD whichway ) { img_node *node; HBITMAP rotxorbmp; HBITMAP rotandbmp; HCURSOR prevcursor; int rotate_type; WPI_RECT rotate_rect; BOOL rectexists; short new_width; short new_height; WPI_PRES pres; node = GetCurrentNode(); if( node == NULL ) { return; } prevcursor = _wpi_setcursor( _wpi_getsyscursor( IDC_WAIT ) ); PrintHintTextByID( WIE_ROTATINGIMAGE, NULL ); if( DoesRectExist( &rotate_rect ) ) { rectexists = TRUE; new_width = (short)_wpi_getheightrect( rotate_rect ); new_height = (short)_wpi_getwidthrect( rotate_rect ); } else { rectexists = FALSE; _wpi_setwrectvalues( &rotate_rect, 0, 0, (IMGED_DIM)node->width, (IMGED_DIM)node->height ); new_width = node->height; new_height = node->width; } if( node->bitcount == 1 ) { rotxorbmp = _wpi_createbitmap( new_width, new_height, 1, 1, NULL ); } else { #if 1 pres = _wpi_getpres( HWND_DESKTOP ); rotxorbmp = _wpi_createcompatiblebitmap( pres, new_width, new_height ); _wpi_releasepres( HWND_DESKTOP, pres ); #else rotxorbmp = _wpi_createbitmap( new_width, new_height, ColorPlanes, BitsPerPixel, NULL ); #endif } rotandbmp = _wpi_createbitmap( new_width, new_height, 1, 1, NULL ); rotateTheImage( node, whichway, &rotate_rect, rotxorbmp, rotandbmp ); rotate_type = GetRotateType(); if( rotate_type == SIMPLE_ROTATE ) { simpleRotate( node, &rotate_rect, rotxorbmp, rotandbmp, rectexists ); } else if( rotate_type == CLIP_ROTATE ) { clipIntoArea( node, &rotate_rect, rotxorbmp, rotandbmp ); } else { stretchIntoArea( node, &rotate_rect, rotxorbmp, rotandbmp ); } _wpi_deleteobject( rotxorbmp ); _wpi_deleteobject( rotandbmp ); if( whichway == IMGED_ROTATECC ) { PrintHintTextByID( WIE_IMAGEROTATEDCCW, NULL ); } else { PrintHintTextByID( WIE_IMAGEROTATEDCW, NULL ); } _wpi_setcursor( prevcursor ); } /* RotateImage */
/* * SnapPicture - minimize the image editor and prepare to snap the picture */ void SnapPicture( void ) { img_node *node; POINT pt; HWND hwnd; RECT cliprect; node = GetCurrentNode(); if( node == NULL ) { return; } firstTime = 2; GetCursorPos( &pt ); if( DoesRectExist( &cliprect ) ) { snapWidth = cliprect.right - cliprect.left; snapHeight = cliprect.bottom - cliprect.top; topLeft.x = cliprect.left; topLeft.y = cliprect.top; rectExists = TRUE; } else { snapWidth = node->width; snapHeight = node->height; topLeft.x = 0; topLeft.y = 0; rectExists = FALSE; } if( IsZoomed( HMainWindow ) ) { previousState = SW_SHOWMAXIMIZED; } else { previousState = SW_SHOWNORMAL; } snapWindow = node->hwnd; #ifdef __NT__ hwnd = hwnd; RegisterSnapClass( Instance ); ShowWindow( HMainWindow, SW_SHOWMINIMIZED ); ShowWindow( HMainWindow, SW_HIDE ); InvalidateRect( HWND_DESKTOP, NULL, TRUE ); // force the desktop window to be redrawn RedrawWindow( HWND_DESKTOP, NULL, NULL, RDW_ERASE | RDW_UPDATENOW | RDW_ERASENOW | RDW_ALLCHILDREN | RDW_INVALIDATE ); SetDeskTopHook( deskTopWindowHook ); deskTopWindow = DisplayDesktop( HMainWindow ); #else SetCapture( node->hwnd ); ShowWindow( HMainWindow, SW_SHOWMINIMIZED ); ShowWindow( HMainWindow, SW_HIDE ); hwnd = WindowFromPoint( pt ); #if 0 if( hwnd == GetDesktopWindow() ) { return; } #endif // this code makes sure that the window under the cursor is redrawn // Why? gets rid of the XOR turd RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN | RDW_INVALIDATE ); #endif prevToolType = SetToolType( IMGED_SNAP ); prevCursor = SetCursor( NULL ); #ifdef __NT__ SetCapture( node->hwnd ); #endif PostMessage( node->hwnd, WM_MOUSEMOVE, (WPARAM)0, MAKELPARAM( pt.x, pt.y ) ); Yield(); } /* SnapPicture */