/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * InitPaletteBitmaps - initialize the available color bitmaps */ void InitPaletteBitmaps( HWND hwnd, HBITMAP *colorbitmap, HBITMAP *monobitmap ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; HBITMAP oldbitmap; COLORREF color; int i; int left_sqr; HBRUSH colorbrush; HBRUSH oldbrush; HPEN blackpen; HPEN oldpen; int top; int bottom; int height; pres = _wpi_getpres( hwnd ); *colorbitmap = _wpi_createcompatiblebitmap( pres, CUR_BMP_WIDTH, CUR_BMP_HEIGHT ); *monobitmap = _wpi_createbitmap( CUR_BMP_WIDTH, CUR_BMP_HEIGHT, 1, 1, NULL ); mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_releasepres( hwnd, pres ); _wpi_torgbmode( mempres ); blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); oldpen = _wpi_selectobject( mempres, blackpen ); oldbitmap = _wpi_selectobject( mempres, *colorbitmap ); /* * PM NOTE: All box coordinates are relative to the window's origin * of top left. So we convert the height for PM. */ left_sqr = 0; height = 2 * SQR_SIZE + 1; for( i = 0; i < PALETTE_SIZE; i += 2 ) { color = RGB( palette[COLOR_16][i].rgbRed, palette[COLOR_16][i].rgbGreen, palette[COLOR_16][i].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( 0, height ); bottom = _wpi_cvth_y( SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); color = RGB( palette[COLOR_16][i + 1].rgbRed, palette[COLOR_16][i + 1].rgbGreen, palette[COLOR_16][i + 1].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( SQR_SIZE, height ); bottom = _wpi_cvth_y( 2 * SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); left_sqr += SQR_SIZE; } _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, *monobitmap ); left_sqr = 0; for( i = 0; i < PALETTE_SIZE; i += 2 ) { color = RGB( palette[COLOR_2][i].rgbRed, palette[COLOR_2][i].rgbGreen, palette[COLOR_2][i].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( 0, height ); bottom = _wpi_cvth_y( SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); color = RGB( palette[COLOR_2][i + 1].rgbRed, palette[COLOR_2][i + 1].rgbGreen, palette[COLOR_2][i + 1].rgbBlue ); colorbrush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, colorbrush ); top = _wpi_cvth_y( SQR_SIZE, height ); bottom = _wpi_cvth_y( 2 * SQR_SIZE + 1, height ); _wpi_rectangle( mempres, left_sqr, top, left_sqr + SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( colorbrush ); left_sqr += SQR_SIZE; } _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_deleteobject( blackpen ); } /* InitPaletteBitmaps */