/* * Win_CreateColorPal - create the color palette for the Windows version */ void Win_CreateColorPal( void ) { char *title; title = IEAllocRCString( WIE_COLORPALETTETITLE ); #ifndef __NT__ HColorPalette = CreateWindow( PaletteClass, /* Window class name */ title, WS_POPUPWINDOW | WS_CAPTION, /* Window style */ ImgedConfigInfo.pal_xpos, /* Initial X position */ ImgedConfigInfo.pal_ypos, /* Initial Y position */ CP_WIDTH + 2, /* Initial X size */ CP_HEIGHT + 15, /* Initial Y size */ HMainWindow, /* Parent window handle */ (HMENU)NULL, /* Window menu handle */ Instance, /* Program instance handle */ NULL ); /* Create parameters */ #else HColorPalette = CreateWindowEx( WS_EX_TOOLWINDOW, PaletteClass, /* Window class name */ title, WS_POPUPWINDOW | WS_CAPTION, /* Window style */ ImgedConfigInfo.pal_xpos, /* Initial X position */ ImgedConfigInfo.pal_ypos, /* Initial Y position */ CP_WIDTH + 2, /* Initial X size */ CP_HEIGHT + 15, /* Initial Y size */ HMainWindow, /* Parent window handle */ (HMENU)NULL, /* Window menu handle */ Instance, /* Program instance handle */ NULL ); /* Create parameters */ #endif if( title != NULL ) { IEFreeRCString( title ); } if( HColorPalette != (HWND)NULL ) { RECT rect; int w, h; _wpi_getclientrect( HColorPalette, &rect ); w = _wpi_getwidthrect( rect ); h = _wpi_getheightrect( rect ); if( w < CP_WIDTH || h < CP_HEIGHT ) { GetWindowRect( HColorPalette, &rect ); w = _wpi_getwidthrect( rect ) + (CP_WIDTH - w); h = _wpi_getheightrect( rect ) + (CP_HEIGHT - h); SetWindowPos( HColorPalette, HWND_TOP, 0, 0, w, h, SWP_SIZE | SWP_NOZORDER | SWP_NOMOVE ); } } SendMessage( HColorPalette, WM_SETFONT, (DWORD)SmallFont, 0L ); } /* Win_CreateColorPal */
/* * IECopyImage - copy the current clipping rectangle to the clipboard * * 1) Copy the bitmap to the clipboard (so other apps can use it). * 2) Make a copy of the XOR bitmap and the AND bitmaps so that if * screen colors are involved, they will be preserved. * Later, we check the owner of the clipboard to see if we really * want to use the XOR/AND bitmaps or not. */ void IECopyImage( void ) { short width; short height; img_node *node; 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 = _wpi_getwidthrect( clipRect.rect ); height = _wpi_getheightrect( clipRect.rect ); } copyImageToClipboard( width, height, node ); if( !fEnableCutCopy ) { PrintHintTextByID( WIE_ENTIREIMAGECOPIED, NULL ); } else { PrintHintTextByID( WIE_AREACOPIED, NULL ); RedrawPrevClip( node->hwnd ); fEnableCutCopy = FALSE; } } /* IECopyImage */
void GUISetMenu( gui_window *wnd, HMENU hmenu ) { HWND frame; WPI_RECT rect; gui_coord size; int height; #ifndef __OS2_PM__ HMENU omenu; #endif #ifndef __OS2_PM__ omenu = GUIGetHMENU( wnd ); #endif frame = GUIGetParentFrameHWND( wnd ); _wpi_getclientrect( frame, &rect ); height = _wpi_getheightrect( rect ); _wpi_setmenu( frame, hmenu ); _wpi_getclientrect( frame, &rect ); if( height != ( size.y = _wpi_getheightrect( rect ) ) ) { size.x = _wpi_getwidthrect( rect ); GUIDoResize( wnd, GUIGetParentHWND( wnd ), &size ); } #ifndef __OS2_PM__ if( omenu != (HMENU)NULL ) { _wpi_destroymenu( omenu ); } #endif }
/* * GetPointSize - returns the point size. */ WPI_POINT GetPointSize( HWND hwnd ) { WPI_POINT pt = {0, 0}; img_node *node; WPI_RECT rc; int width; int height; node = SelectImage( hwnd ); if (!node) return( pt ); GetClientRect( hwnd, &rc ); width = _wpi_getwidthrect(rc); height = _wpi_getheightrect(rc); pt.x = width / node->width; pt.y = height / node->height; if( pt.x == 0 ) { pt.x = 1; } if( pt.y == 0 ) { pt.y = 1; } return( pt ); } /* GetPointSize */
/* * ResetDrawArea - Resets the drawing area when a new image is selected from * the select icon menu option. (only for icon files). */ void ResetDrawArea( img_node *node ) { WPI_RECT rcclient; WPI_RECT rc; WPI_PARAM2 lparam; short new_width; short new_height; GetClientRect( node->hwnd, &rcclient ); pointSize.x = max (1, _wpi_getwidthrect(rcclient) / node->width); pointSize.y = max (1, _wpi_getheightrect(rcclient) / node->height); if (ImgedConfigInfo.square_grid) { GetClientRect( ClientWindow, &rc ); if (pointSize.y * node->height > _wpi_getheightrect(rc) ) { pointSize.y = pointSize.x; } else { pointSize.x = pointSize.y; } /* * I add 1 to cause ResizeChild to resize the window. */ new_width = (short)(pointSize.x*node->width+1); new_height = (short)(pointSize.y*node->height+1); lparam = WPI_MAKEP2(new_width, new_height); ResizeChild(lparam, node->hwnd, TRUE ); } BlowupImage( node->hwnd, NULL ); } /* ResetDrawArea */
/* * MaximizeCurrentChild - make the current edit window as large as it can possibly be */ void MaximizeCurrentChild( void ) { short max_width; short max_height; WPI_POINT max_pt_size; WPI_RECT client; WPI_RECT rect; WPI_RECT rc; img_node *node; short x_adjustment; short y_adjustment; node = GetCurrentNode(); if( node == NULL ) { return; } GetClientRect( node->hwnd, &rc ); GetWindowRect( node->hwnd, &rect ); x_adjustment = _wpi_getwidthrect( rect ) - _wpi_getwidthrect( rc ); y_adjustment = _wpi_getheightrect( rect ) - _wpi_getheightrect( rc ); GetClientRect( ClientWindow, &client ); max_width = (short)_wpi_getwidthrect( client ); max_height = (short)_wpi_getheightrect( client ); max_pt_size.x = max_width / node->width; max_pt_size.y = max_height / node->height; if( ImgedConfigInfo.square_grid ) { if( max_pt_size.x > max_pt_size.y ) max_pt_size.x = max_pt_size.y; max_pt_size.y = max_pt_size.x; } if( max_pt_size.x <= pointSize.x && max_pt_size.y <= pointSize.y ) { return; } max_width = max_pt_size.x * node->width + x_adjustment; max_height = max_pt_size.y * node->height + y_adjustment; SetWindowPos( node->hwnd, HWND_TOP, 0, 0, max_width, max_height, SWP_SIZE | SWP_MOVE | SWP_ZORDER | SWP_SHOWWINDOW ); } /* MaximizeCurrentChild */
/* * CalculateDims - calculate the size of the "pixel" in the drawing * area and establish the device draw area size */ void CalculateDims( short img_width, short img_height, short *area_width, short *area_height ) { int point_size1; int point_size2; int max_width; int max_height; WPI_RECT rcclient; int x_adj; int y_adj; GetClientRect( ClientWindow, &rcclient ); x_adj = (short)(2 * _wpi_getsystemmetrics( SM_CXFRAME )); y_adj = (short)(2 * _wpi_getsystemmetrics( SM_CYFRAME ) + _wpi_getsystemmetrics( SM_CYCAPTION )); #if 0 max_width = _wpi_getwidthrect( rcclient ) - x_adj - origin->x; max_height = _wpi_getheightrect( rcclient ) - y_adj - origin->y; #else max_width = _wpi_getwidthrect( rcclient ) - x_adj; max_height = _wpi_getheightrect( rcclient ) - y_adj; #endif point_size1 = max( 1, max_width / img_width ); point_size2 = max( 1, max_height / img_height ); if( point_size1 < 1 ) { point_size1 = 1; } if( point_size2 < 1 ) { point_size2 = 1; } pointSize.x = min( point_size1, point_size2 ); while( pointSize.x * img_width < MIN_DRAW_WIN_WIDTH ) { pointSize.x++; } pointSize.y = pointSize.x; *area_width = (short)(pointSize.x * img_width); *area_height = (short)(pointSize.y * img_height); } /* CalculateDims */
/* * 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 */
/* * 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 */
void GUISetRowCol( gui_window *wnd, gui_coord *size ) { gui_coord my_size; if( size == NULL ) { my_size.y = _wpi_getheightrect( wnd->hwnd_client_rect ); my_size.x = _wpi_getwidthrect( wnd->hwnd_client_rect ); } else { my_size = *size; } GUIToText( &my_size, wnd ); wnd->num_rows = my_size.y; wnd->num_cols = my_size.x; }
/* * CreateDrawnImage - Creates the enlarged image in the drawing area. (used * when activating a new image or selecting a new image). */ void CreateDrawnImage( img_node *node ) { WPI_RECT rcclient; int cx; int cy; GetClientRect( node->hwnd, &rcclient ); hDrawArea = node->hwnd; cx = _wpi_getwidthrect(rcclient); cy = _wpi_getheightrect(rcclient); cx = cx / node->width; cy = cy / node->height; pointSize.x = max (1, cx); pointSize.y = max (1, cy); } /* CreateDrawnImage */
/* * ResetViewWindow - when a new MDI child is activated, reset the position * of the view window * - first check if only 1 view window is being shown, or all of them */ void ResetViewWindow( HWND hwnd ) { WPI_RECT currentloc; WPI_RECT newloc; WPI_RECTDIM left; WPI_RECTDIM top; WPI_RECTDIM right; WPI_RECTDIM bottom; HWND hframe; HWND currentframe; hframe = _wpi_getframe( hwnd ); if( hViewWindow != NULL ) { currentframe = _wpi_getframe( hViewWindow ); } else { currentframe = NULL; } if( fOneViewWindow ) { _wpi_getwindowrect( hframe, &newloc ); if( hViewWindow != NULL ) { _wpi_getwindowrect( currentframe, ¤tloc ); ShowWindow( currentframe, SW_HIDE ); } else { currentloc = newloc; } _wpi_getrectvalues( currentloc, &left, &top, &right, &bottom ); SetWindowPos( hframe, NULL, left, top, _wpi_getwidthrect( newloc ), _wpi_getheightrect( newloc ), SWP_MOVE | SWP_SIZE | SWP_NOZORDER | SWP_HIDEWINDOW ); hViewWindow = hwnd; ShowWindow( hframe, showState ); } else { hViewWindow = hwnd; ShowWindow( hframe, showState ); _wpi_bringwindowtotop( hframe ); } #ifndef __OS2_PM__ RedrawWindow( hwnd, NULL, NULL, RDW_UPDATENOW ); #endif } /* ResetViewWindow */
/* * showGrid - Display the grid on the draw area. */ static void showGrid( HWND hwnd, WPI_PRES mempres ) { short i; short psx; short psy; WPI_RECT rcclient; HPEN hblackpen; HPEN holdpen; img_node *node; short width; short height; IMGED_DIM left; IMGED_DIM right; IMGED_DIM top; IMGED_DIM bottom; WPI_PRES pres; WPI_POINT startpt; WPI_POINT endpt; node = SelectImage( hwnd ); _wpi_torgbmode( mempres ); GetClientRect( hwnd, &rcclient ); width = (short)( _wpi_getwidthrect(rcclient) ); height = (short)( _wpi_getheightrect(rcclient) ); if (((width / node->width) < POINTSIZE_MIN) || ((height / node->height) < POINTSIZE_MIN)) { psx = 0; psy = 0; } else { psx = width / node->width; psy = height / node->height; hblackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); holdpen = _wpi_selectobject( mempres, hblackpen ); _wpi_getrectvalues( rcclient, &left, &top, &right, &bottom ); for (i=0; i < width; i = i + psx) { _wpi_setpoint( &startpt, i, top ); _wpi_setpoint( &endpt, i, bottom ); _wpi_movetoex( mempres, &startpt, NULL ); _wpi_lineto( mempres, &endpt ); } for (i=0; i <= height; i = i + psy) { _wpi_setpoint( &startpt, left, i ); _wpi_setpoint( &endpt, right, i ); _wpi_movetoex( mempres, &startpt, NULL ); _wpi_lineto( mempres, &endpt ); } _wpi_selectobject( mempres, holdpen ); _wpi_deleteobject( hblackpen ); } pres = _wpi_getpres( hwnd ); _wpi_bitblt( pres, 0, 0, width, height, mempres, 0, 0, SRCCOPY ); _wpi_releasepres( hwnd, pres ); RedrawPrevClip(hwnd); // Redraws if there was a clip region specified. } /* showGrid */
/* * ResizeChild - resizes the draw area of the child window. */ void ResizeChild( WPI_PARAM2 lparam, HWND hwnd, BOOL firsttime ) { short min_width; short width; short height; img_node *node; short x_adjustment; short y_adjustment; short new_width; short new_height; WPI_POINT point_size; WPI_POINT max; HWND frame; HMENU hmenu; WPI_RECT rc; WPI_RECT rect; frame = _wpi_getframe( hwnd ); width = LOWORD( lparam ); #ifdef __OS2_PM__ height = SHORT2FROMMP( lparam ); #else height = HIWORD( lparam ); #endif GetClientRect( hwnd, &rc ); GetWindowRect( hwnd, &rect ); if( frame ) { GetClientRect( frame, &rc ); GetWindowRect( frame, &rect ); } max.x = _wpi_getsystemmetrics( SM_CXSCREEN ); max.y = _wpi_getsystemmetrics( SM_CYSCREEN ); x_adjustment = _wpi_getwidthrect( rect ) - _wpi_getwidthrect( rc ); y_adjustment = _wpi_getheightrect( rect ) - _wpi_getheightrect( rc ); #if 1 min_width = MIN_DRAW_WIN_WIDTH; #else min_width = (short)(2*_wpi_getsystemmetrics(SM_CXSIZE)) + x_adjustment + 8; // fudge factor to allow some of title bar to show #endif #ifdef __OS2_PM__ ++y_adjustment; #endif node = SelectImage( hwnd ); if (!node) return; // the following assumes that max.x >> min_width point_size.x = min( max.x / node->width, width / node->width ); point_size.x = max( min_width / node->width + 1, point_size.x ); point_size.y = min( max.y / node->height, height / node->height ); point_size.y = max( 1, point_size.y ); if( ImgedConfigInfo.square_grid ) { point_size.x = min( point_size.x, point_size.y ); if( point_size.x < ( min_width / node->width + 1 ) ) { point_size.x = min_width / node->width + 1; } if( point_size.x > ( max.y / node->height ) ) { hmenu = GetMenu( _wpi_getframe(HMainWindow) ); CheckSquareGrid( hmenu ); } else { point_size.y = point_size.x; } } new_width = (short)(point_size.x * node->width + x_adjustment); new_height = (short)(point_size.y * node->height + y_adjustment); pointSize = point_size; if( (pointSize.x*node->width != width) || (pointSize.y*node->height != height) ) { SetWindowPos( frame, HWND_TOP, 0, 0, new_width, new_height, SWP_SIZE | SWP_ZORDER | SWP_NOMOVE | SWP_SHOWWINDOW); SetGridSize( pointSize.x, pointSize.y ); } if( !firsttime ) { BlowupImage( node->hwnd, NULL ); } } /* ResizeChild */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * WinCreateViewWin - create the view window for the Windows version */ HWND WinCreateViewWin( HWND hviewwnd, BOOL foneview, int *showstate, int width, int height ) { HWND hwnd; RECT location; int x, y; int h_adj; int v_adj; if( hviewwnd != NULL && foneview ) { GetWindowRect( hviewwnd, &location ); x = location.left; y = location.top; } else { x = ImgedConfigInfo.view_xpos; y = ImgedConfigInfo.view_ypos; } width += 2 * BORDER_WIDTH; height += 2 * BORDER_WIDTH; h_adj = 2 * GetSystemMetrics( SM_CXDLGFRAME ); v_adj = 2 * GetSystemMetrics( SM_CYDLGFRAME ) + #ifndef __NT__ GetSystemMetrics( SM_CYCAPTION ) - 1; #else GetSystemMetrics( SM_CYSMCAPTION ) - 1; #endif #ifndef __NT__ hwnd = CreateWindow( ViewWinClass, /* Window class name */ "View", WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE | WS_CLIPSIBLINGS | WS_DLGFRAME, /* Window style */ x, /* Initial X position */ y, /* Initial Y position */ h_adj + width, /* Initial X size */ v_adj + height, /* Initial Y size */ HMainWindow, /* Parent window handle */ (HMENU) NULL, /* Window menu handle */ Instance, /* Program instance handle */ NULL ); /* Create parameters */ #else hwnd = CreateWindowEx( WS_EX_TOOLWINDOW, ViewWinClass, /* Window class name */ "View", WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE | WS_CLIPSIBLINGS | WS_DLGFRAME, /* Window style */ x, /* Initial X position */ y, /* Initial Y position */ h_adj + width, /* Initial X size */ v_adj + height, /* Initial Y size */ HMainWindow, /* Parent window handle */ (HMENU) NULL, /* Window menu handle */ Instance, /* Program instance handle */ NULL ); /* Create parameters */ #endif ShowWindow( hwnd, SW_HIDE ); if( hwnd != (HWND)NULL ) { RECT rect; int w, h; _wpi_getclientrect( hwnd, &rect ); w = _wpi_getwidthrect( rect ); h = _wpi_getheightrect( rect ); if( w < width || h < height ) { GetWindowRect( hwnd, &rect ); w = _wpi_getwidthrect( rect ) + (width - w); h = _wpi_getheightrect( rect ) + (height - h); SetWindowPos( hwnd, HWND_TOP, 0, 0, w, h, SWP_SIZE | SWP_NOZORDER | SWP_NOMOVE ); } } if( ImgedConfigInfo.show_state & SET_SHOW_VIEW ) { *showstate = SW_SHOWNORMAL; } else { *showstate = SW_HIDE; } return( hwnd ); } /* WinCreateViewWin */
/* * WinNewDrawPad - create a new drawing pad for Windows version */ HWND WinNewDrawPad( img_node *node ) { MDICREATESTRUCT mdicreate; short y_adjustment; short x_adjustment; short pad_x; short pad_y; int i; img_node *temp; POINT origin; char filename[_MAX_PATH]; HWND drawarea; HMENU sys_menu; node->viewhwnd = CreateViewWin( node->width, node->height ); pad_x = 0; pad_y = 0; temp = node->nexticon; for( i = 1; i < node->num_of_images; i++ ) { temp->viewhwnd = node->viewhwnd; temp = temp->nexticon; } if( node->imgtype == BITMAP_IMG ) { mdicreate.szClass = DrawAreaClassB; } else if( node->imgtype == ICON_IMG ) { mdicreate.szClass = DrawAreaClassI; } else { mdicreate.szClass = DrawAreaClassC; } GetFnameFromPath( node->fname, filename ); mdicreate.szTitle = filename; mdicreate.hOwner = Instance; x_adjustment = (short)(2 * GetSystemMetrics( SM_CXFRAME )); y_adjustment = (short)(2 * GetSystemMetrics( SM_CYFRAME ) + GetSystemMetrics( SM_CYCAPTION ) - 1); origin.x = 0; origin.y = 0; FindOrigin( &origin ); CalculateDims( node->width, node->height, &pad_x, &pad_y ); mdicreate.cx = x_adjustment + pad_x; mdicreate.cy = y_adjustment + pad_y; mdicreate.x = origin.x; mdicreate.y = origin.y; mdicreate.style = WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_CLIPSIBLINGS | WS_DLGFRAME | WS_MINIMIZEBOX | WS_THICKFRAME; mdicreate.lParam = (LPARAM)(LPVOID)node; drawarea = (HWND)SendMessage( ClientWindow, WM_MDICREATE, 0, (LPARAM)(LPVOID)&mdicreate ); if( drawarea != (HWND)NULL ) { RECT rect; int w, h; _wpi_getclientrect( drawarea, &rect ); w = _wpi_getwidthrect( rect ); h = _wpi_getheightrect( rect ); if( w != pad_x || h != pad_y ) { GetWindowRect( drawarea, &rect ); w = _wpi_getwidthrect( rect ) + (pad_x - w); h = _wpi_getheightrect( rect ) + (pad_y - h); SetWindowPos( drawarea, HWND_TOP, 0, 0, w, h, SWP_SIZE | SWP_NOZORDER | SWP_NOMOVE ); } } if( ImgedIsDDE ) { sys_menu = GetSystemMenu( drawarea, FALSE ); if( sys_menu != (HMENU)NULL ) { EnableMenuItem( sys_menu, SC_CLOSE, MF_GRAYED ); } } BlowupImage( NULL, NULL ); return( drawarea ); } /* WinNewDrawPad */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * ImgEdFrameProc - handle messages for the image editor application */ WPI_MRESULT CALLBACK ImgEdFrameProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam, WPI_PARAM2 lparam ) { static BOOL window_destroyed = FALSE; static HMENU hmenu; ctl_id cmdid; img_node *node; WPI_RECT rcmain; #ifndef __OS2_PM__ about_info ai; #endif WPI_RECTDIM left, top; if( !window_destroyed ) { enableMainItems( hmenu ); } switch( msg ) { case UM_EXIT: _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L ); /* fall through */ case UM_EXIT_NO_SAVE: if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) { break; } #ifndef __OS2_PM__ _wpi_destroywindow( _wpi_getframe( hwnd ) ); #else _wpi_sendmessage( hwnd, WM_CLOSE, 0, 0 ); #endif break; case UM_SAVE_ALL: SaveAllImages(); break; case WM_CREATE: hmenu = _wpi_getmenu( _wpi_getframe( hwnd ) ); #ifndef __OS2_PM__ createClientWindow( hwnd ); #endif if( !InitStatusLine( hwnd ) ) { return( -1 ); } InitFunctionBar( hwnd ); InitIconInfo(); InitializeCursors(); /* * Set values from profile information ... */ if( ImgedConfigInfo.brush_size <= 5 && ImgedConfigInfo.brush_size >= 2 ) { checkBrushItem( hmenu, IMGED_2x2 - 2 + ImgedConfigInfo.brush_size ); } if( ImgedConfigInfo.grid_on ) { CheckGridItem( hmenu ); } if( ImgedConfigInfo.square_grid ) { CheckSquareGrid( hmenu ); } if( ImgedConfigInfo.show_state & SET_SHOW_VIEW ) { CheckViewItem( hmenu ); } _wpi_enablemenuitem( hmenu, IMGED_CRESET, FALSE, FALSE ); _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, FALSE, FALSE ); #ifndef __OS2_PM__ // not necessary for PM InitMenus( hmenu ); #endif SetHintText( IEAppTitle ); return( 0 ); #ifdef __NT__ case WM_DROPFILES: OpenImage( (HANDLE)wparam ); break; #endif case WM_MOVE: _wpi_getwindowrect( hwnd, &rcmain ); if( !ImgedConfigInfo.ismaximized ) { ImgedConfigInfo.last_xpos = ImgedConfigInfo.x_pos; ImgedConfigInfo.last_ypos = ImgedConfigInfo.y_pos; _wpi_getrectvalues( rcmain, &left, &top, NULL, NULL ); ImgedConfigInfo.x_pos = (short)left; ImgedConfigInfo.y_pos = (short)top; } return( 0 ); case WM_SIZE: ResizeFunctionBar( lparam ); ResizeStatusBar( lparam ); #ifndef __OS2_PM__ if( ClientWindow != NULL ) { setClientSize( hwnd ); } #else resizeClientArea( lparam ); #endif if( !_imgwpi_issizeminimized( wparam ) && !_imgwpi_issizemaximized( wparam ) ) { _wpi_getwindowrect( hwnd, &rcmain ); ImgedConfigInfo.width = (short)_wpi_getwidthrect( rcmain ); ImgedConfigInfo.height = (short)_wpi_getheightrect( rcmain ); ImgedConfigInfo.ismaximized = FALSE; } else { ImgedConfigInfo.x_pos = ImgedConfigInfo.last_xpos; ImgedConfigInfo.y_pos = ImgedConfigInfo.last_ypos; ImgedConfigInfo.ismaximized = _imgwpi_issizemaximized( wparam ); } return( FALSE ); case WM_MENUSELECT: #ifndef __OS2_PM__ if( GET_WM_MENUSELECT_FLAGS( wparam, lparam ) & MF_SEPARATOR ) { break; } if( GET_WM_MENUSELECT_FLAGS( wparam, lparam ) & MF_SYSMENU ) { PrintHintTextByID( WIE_SYSMENUOPERATIONS, NULL ); break; } #endif ShowHintText( LOWORD( wparam ) ); break; case WM_COMMAND: cmdid = LOWORD( wparam ); if( !IEIsMenuIDValid( hmenu, cmdid ) ) { break; } switch( cmdid ) { case IMGED_NEW: if( !ImgedIsDDE ) { if( !NewImage( UNDEF_IMG, NULL ) ) { PrintHintTextByID( WIE_NEIMAGENOTCREATED, NULL ); } } break; case IMGED_CLOSE: node = GetCurrentNode(); if( node != NULL ) { _wpi_sendmessage( node->hwnd, WM_CLOSE, 0, 0L ); } break; case IMGED_CLOSEALL: CloseAllImages(); break; case IMGED_HELP: IEHelpRoutine(); break; case IMGED_HELP_SEARCH: IEHelpSearchRoutine(); break; case IMGED_HELP_ON_HELP: IEHelpOnHelpRoutine(); break; case IMGED_ABOUT: #ifndef __OS2_PM__ ai.owner = hwnd; ai.inst = Instance; ai.name = IEAllocRCString( WIE_ABOUTTEXT ); ai.version = IEAllocRCString( WIE_ABOUTVERSION ); ai.title = IEAllocRCString( WIE_ABOUTTITLE ); DoAbout( &ai ); if( ai.name != NULL ) { IEFreeRCString( ai.name ); } if( ai.version != NULL ) { IEFreeRCString( ai.version ); } if( ai.title != NULL ) { IEFreeRCString( ai.title ); } #endif break; #ifndef __OS2_PM__ case IMGED_DDE_UPDATE_PRJ: IEUpdateDDEEditSession(); break; #endif case IMGED_SAVE_AS: SaveFile( SB_SAVE_AS ); break; case IMGED_SAVE: SaveFile( SB_SAVE ); break; case IMGED_OPEN: if( !ImgedIsDDE ) { OpenImage( NULL ); } break; case IMGED_CLEAR: ClearImage(); break; case IMGED_NEWIMG: AddNewIcon(); break; case IMGED_SELIMG: SelectIconImg(); break; case IMGED_DELIMG: DeleteIconImg(); break; case IMGED_UNDO: UndoOp(); break; case IMGED_REDO: RedoOp(); break; case IMGED_REST: RestoreImage(); break; case IMGED_SNAP: #ifndef __OS2_PM__ SnapPicture(); #endif break; case IMGED_RIGHT: case IMGED_LEFT: case IMGED_UP: case IMGED_DOWN: ShiftImage( cmdid ); break; case IMGED_FLIPHORZ: case IMGED_FLIPVERT: FlipImage( cmdid ); break; case IMGED_ROTATECC: case IMGED_ROTATECL: RotateImage( cmdid ); break; case IMGED_PASTE: PlaceAndPaste(); break; case IMGED_COPY: IECopyImage(); break; case IMGED_CUT: CutImage(); break; case IMGED_COLOR: CheckPaletteItem( hmenu ); break; case IMGED_VIEW: CheckViewItem( hmenu ); break; case IMGED_TOOLBAR: CheckToolbarItem( hmenu ); break; case IMGED_SQUARE: CheckSquareGrid( hmenu ); break; case IMGED_SIZE: ChangeImageSize(); break; case IMGED_GRID: CheckGridItem( hmenu ); break; case IMGED_MAXIMIZE: MaximizeCurrentChild(); break; case IMGED_SETTINGS: SelectOptions(); break; case IMGED_2x2: case IMGED_3x3: case IMGED_4x4: case IMGED_5x5: checkBrushItem( hmenu, cmdid ); break; case IMGED_CEDIT: #ifndef __OS2_PM__ EditColors(); #endif break; case IMGED_CRESET: #ifndef __OS2_PM__ RestoreColors(); #endif break; case IMGED_CSCREEN: ChooseBkColor(); break; case IMGED_SCOLOR: #ifndef __OS2_PM__ SaveColorPalette(); #endif break; case IMGED_LCOLOR: #ifndef __OS2_PM__ if( LoadColorPalette() ) { _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, TRUE, FALSE ); } #endif break; case IMGED_RCOLOR: RestoreColorPalette(); break; case IMGED_FREEHAND: case IMGED_LINE: case IMGED_RECTO: case IMGED_RECTF: case IMGED_CIRCLEO: case IMGED_CIRCLEF: case IMGED_FILL: case IMGED_BRUSH: case IMGED_CLIP: case IMGED_HOTSPOT: SetToolType( cmdid ); PushToolButton( cmdid ); break; case IMGED_ARRANGE: #ifndef __OS2_PM__ SendMessage( ClientWindow, WM_MDIICONARRANGE, 0, 0L ); #endif break; case IMGED_TILE: #ifndef __OS2_PM__ SendMessage( ClientWindow, WM_MDITILE, MDITILE_VERTICAL, 0L ); #endif break; case IMGED_CASCADE: #ifndef __OS2_PM__ SendMessage( ClientWindow, WM_MDICASCADE, MDITILE_SKIPDISABLED, 0L ); #endif break; case IMGED_EXIT: _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L ); if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) { break; } #ifndef __OS2_PM__ _wpi_destroywindow( _wpi_getframe( hwnd ) ); #else _wpi_sendmessage( hwnd, WM_CLOSE, 0, 0 ); #endif break; default: #if 1 return( _imgwpi_defframeproc( hwnd, ClientWindow, msg, wparam, lparam ) ); #else return( 0 ); #endif } return( 0 ); #ifndef __OS2_PM__ case WM_COMPACTING: RelieveUndos(); return 0; #endif case WM_QUERYENDSESSION: if( _wpi_isiconic( _wpi_getframe( hwnd ) ) ) { if( ImgedConfigInfo.ismaximized ) { _wpi_maximizewindow( _wpi_getframe( hwnd ) ); } else { _wpi_showwindow( _wpi_getframe( hwnd ), SW_SHOWNORMAL ); } } _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L ); if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) { return( 0 ); } return( (WPI_MRESULT)1 ); case WM_CLOSE: // wParam is non-zero if the DDE connection died if( !wparam && !ImgEdEnableMenuInput ) { // this prevents the user from closing the editor during // DDE initialization return( 0 ); } _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L ); #ifdef __OS2_PM__ return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) ); #else if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) { return( 0 ); } window_destroyed = TRUE; _wpi_destroywindow( _wpi_getframe( hwnd ) ); return( 0 ); #endif case WM_DESTROY: #ifndef __OS2_PM__ WWinHelp( HMainWindow, "resimg.hlp", HELP_QUIT, 0 ); #endif FiniStatusLine(); CleanupClipboard(); CleanupCursors(); CloseToolBar(); CloseFunctionBar(); _wpi_deletefont( SmallFont ); _wpi_postquitmessage( 0 ); return( 0 ); default: break; } return( _imgwpi_defframeproc( hwnd, ClientWindow, msg, wparam, lparam ) ); } /* ImgEdFrameProc */
/* * 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 */
/* * drawBorder - draw the border for the view window */ static void drawBorder( img_node *node ) { WPI_PRES presborder; HPEN hgraypen; HPEN hwhitepen; HPEN hblackpen; HPEN holdpen; WPI_RECT rcclient; HBRUSH hnewbrush; HBRUSH holdbrush; HBRUSH nullbrush; int width; int height; #ifndef __NT__ WPI_POINT pt; #endif int top; int bottom; presborder = _wpi_getpres( node->viewhwnd ); #if defined( __NT__ ) hwhitepen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNHIGHLIGHT ) ); hblackpen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNTEXT ) ); #else hwhitepen = _wpi_createpen( PS_SOLID, 0, CLR_WHITE ); hblackpen = _wpi_createpen( PS_SOLID, 0, CLR_BLACK ); #endif GetClientRect( node->viewhwnd, &rcclient ); width = _wpi_getwidthrect( rcclient ); height = _wpi_getheightrect( rcclient ); if( node->imgtype != BITMAP_IMG ) { #if defined( __NT__ ) hgraypen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) ); #else hgraypen = _wpi_createpen( PS_SOLID, 0, CLR_DARKGRAY ); #endif holdpen = _wpi_selectobject( presborder, hgraypen ); #if defined( __NT__ ) hnewbrush = _wpi_createsolidbrush( GetSysColor( COLOR_BTNFACE ) ); #else hnewbrush = _wpi_createsolidbrush( CLR_PALEGRAY ); #endif holdbrush = _wpi_selectobject( presborder, hnewbrush ); top = 0; bottom = height; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); _wpi_rectangle( presborder, 0, top, width, bottom ); /* * Draw black border and selected background color in the view window. */ _wpi_selectobject( presborder, hblackpen ); _wpi_selectobject( presborder, holdbrush ); _wpi_deleteobject( hnewbrush ); hnewbrush = _wpi_createsolidbrush( bkgroundColor ); _wpi_selectobject( presborder, hnewbrush ); top = BORDER_WIDTH - 1; bottom = height - BORDER_WIDTH + 1; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); #ifndef __NT__ /* * Draw the border relative to the size of the object being displayed, * not the window containing it. */ _wpi_rectangle( presborder, BORDER_WIDTH - 1, top, node->width + BORDER_WIDTH + 1, top + node->height + 2 ); #endif _wpi_selectobject( presborder, holdbrush ); _wpi_selectobject( presborder, holdpen ); _wpi_deleteobject( hnewbrush ); } else { #ifdef __OS2_PM__ // I can't seem to get the thick pen to work so I'm using this // method. hgraypen = _wpi_createpen( PS_SOLID, 0, CLR_PALEGRAY ); holdpen = _wpi_selectobject( presborder, hgraypen ); hnewbrush = _wpi_createsolidbrush( CLR_PALEGRAY ); holdbrush = _wpi_selectobject( presborder, hnewbrush ); _wpi_rectangle( presborder, 0, 0, width + 1, BORDER_WIDTH + 1 ); _wpi_rectangle( presborder, 0, 0, BORDER_WIDTH + 1, height + 1 ); _wpi_rectangle( presborder, 0, height - BORDER_WIDTH, width + 1, height + 1 ); _wpi_rectangle( presborder, width - BORDER_WIDTH, 0, width + 1, height + 1 ); _wpi_selectobject( presborder, holdbrush ); _wpi_deleteobject( hnewbrush ); _wpi_selectobject( presborder, holdpen ); _wpi_deleteobject( hgraypen ); #else #if defined( __NT__ ) hgraypen = _wpi_createpen( PS_INSIDEFRAME, BORDER_WIDTH, GetSysColor( COLOR_BTNFACE ) ); #else hgraypen = _wpi_createpen( PS_INSIDEFRAME, BORDER_WIDTH, CLR_PALEGRAY ); #endif holdpen = _wpi_selectobject( presborder, hgraypen ); nullbrush = _wpi_createnullbrush(); holdbrush = _wpi_selectbrush( presborder, nullbrush ); _wpi_rectangle( presborder, 0, 0, rcclient.right, rcclient.bottom ); _wpi_getoldbrush( presborder, holdbrush ); _wpi_selectobject( presborder, holdpen ); _wpi_deleteobject( hgraypen ); _wpi_deletenullbrush( nullbrush ); #endif nullbrush = _wpi_createnullbrush(); #if defined( __NT__ ) hgraypen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) ); #else hgraypen = _wpi_createpen( PS_SOLID, 0, CLR_DARKGRAY ); #endif holdbrush = _wpi_selectbrush( presborder, nullbrush ); holdpen = _wpi_selectobject( presborder, hgraypen ); top = 0; bottom = height; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); _wpi_rectangle( presborder, 0, top, width, bottom ); _wpi_selectobject( presborder, hblackpen ); top = BORDER_WIDTH - 1; bottom = height - BORDER_WIDTH + 1; top = _wpi_cvth_y( top, height ); bottom = _wpi_cvth_y( bottom, height ); #ifndef __NT__ /* * Draw the border relative to the size of the object being displayed, * not the window containing it. */ _wpi_rectangle( presborder, BORDER_WIDTH - 1, top, node->width + BORDER_WIDTH + 1, top + node->height + 2 ); #endif _wpi_selectobject( presborder, holdpen ); _wpi_selectbrush( presborder, holdbrush ); _wpi_deletenullbrush( nullbrush ); } /* * Give the view window the 3D effect. */ #ifndef __NT__ holdpen = _wpi_selectobject( presborder, hwhitepen ); _wpi_setpoint( &pt, 0, height - 1 ); _wpi_cvth_pt( &pt, height ); _wpi_movetoex( presborder, &pt, NULL ); _wpi_setpoint( &pt, 0, 0 ); _wpi_cvth_pt( &pt, height ); _wpi_lineto( presborder, &pt ); pt.x = width; _wpi_lineto( presborder, &pt ); _wpi_setpoint( &pt, width - BORDER_WIDTH + 1, BORDER_WIDTH - 2 ); _wpi_cvth_pt( &pt, height ); _wpi_movetoex( presborder, &pt, NULL ); pt.y = height - BORDER_WIDTH + 1; _wpi_cvth_pt( &pt, height ); _wpi_lineto( presborder, &pt ); pt.x = BORDER_WIDTH - 2; _wpi_lineto( presborder, &pt ); _wpi_selectobject( presborder, hgraypen ); _wpi_setpoint( &pt, BORDER_WIDTH - 2, BORDER_WIDTH - 2 ); _wpi_cvth_pt( &pt, height ); _wpi_lineto( presborder, &pt ); pt.x = width - BORDER_WIDTH + 1; _wpi_lineto( presborder, &pt ); _wpi_selectobject( presborder, holdpen ); #endif _wpi_deleteobject( hgraypen ); _wpi_deleteobject( hwhitepen ); _wpi_deleteobject( hblackpen ); _wpi_releasepres( node->viewhwnd, presborder ); } /* drawBorder */
/* * 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 */