/* * 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 */
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 }
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 ); }
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */