/* * SetHotSpot - set the text in the hot spot window */ void SetHotSpot( img_node *node ) { WPI_PRES pres; if( HotSpotText == NULL || SetHotSpotText == NULL ) { return; } #ifdef __OS2_PM__ if( node->imgtype == CURSOR_IMG || node->imgtype == ICON_IMG ) { #else if( node->imgtype == CURSOR_IMG ) { #endif sprintf( HotSpotText, SetHotSpotText, hotspotPosition, node->hotspot.x, node->hotspot.y ); } else { sprintf( HotSpotText, "%s ", hotspotPosition ); } pres = _wpi_getpres( statusBarWnd ); StatusWndDrawLine( statusBar, pres, SmallFont, HotSpotText, -1 ); _wpi_releasepres( statusBarWnd, pres ); } /* SetHotSpot */ /* * DisplayImageText - display the text in the status window giving the * image type size and color scheme */ void DisplayImageText( img_node *node ) { WPI_PRES pres; switch( node->imgtype ) { case BITMAP_IMG: sprintf( ImageText, SetBitmapText, imgSizePosition, node->width, node->height, 1 << node->bitcount ); break; case ICON_IMG: sprintf( ImageText, SetIconText, imgSizePosition, node->width, node->height, 1 << node->bitcount ); break; case CURSOR_IMG: sprintf( ImageText, SetCursorText, imgSizePosition, node->width, node->height, 1 << node->bitcount ); break; default: return; } pres = _wpi_getpres( statusBarWnd ); StatusWndDrawLine( statusBar, pres, SmallFont, ImageText, -1 ); _wpi_releasepres( statusBarWnd, pres ); } /* DisplayImageText */
/* * ShowNewColor - replace the color of the color box and redisplay the boxes */ void ShowNewColor( int index, COLORREF newcolor, BOOL repaint ) { WPI_POINT topleft; WPI_POINT bottomright; WPI_PRES pres; WPI_PRES mempres; HDC hdc; HBITMAP oldbitmap; HBRUSH brush; HBRUSH oldbrush; HPEN blackpen; HPEN oldpen; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); paletteBox[index].color = newcolor; paletteBox[index].solid_color = _wpi_getnearestcolor( pres, newcolor ); _wpi_releasepres( HWND_DESKTOP, pres ); if( numberOfColors != 2 ) { topleft.x = (index / 2) * SQR_SIZE; bottomright.x = topleft.x + SQR_SIZE + 1; if( index / 2 == (index + 1) / 2 ) { topleft.y = 0; bottomright.y = SQR_SIZE + 1; } else { topleft.y = SQR_SIZE; bottomright.y = 2 * SQR_SIZE + 1; } pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); brush = _wpi_createsolidbrush( newcolor ); oldbrush = _wpi_selectobject( mempres, brush ); blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); oldpen = _wpi_selectobject( mempres, blackpen ); oldbitmap = _wpi_selectbitmap( mempres, hColorBitmap ); _wpi_cvth_pt( &topleft, colorsHeight ); _wpi_cvth_pt( &bottomright, colorsHeight ); _wpi_rectangle( mempres, topleft.x, topleft.y, bottomright.x, bottomright.y ); _wpi_selectobject( mempres, oldpen ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( blackpen ); _wpi_deleteobject( brush ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); } if( repaint ) { _wpi_invalidaterect( hColorsWnd, NULL, FALSE ); } } /* ShowNewColor */
/* * ResetColorPalette - reset the color palette to its original form (the way it * is when the program is first executed or the way it was * most recently loaded) in response to hitting the Restore button */ void ResetColorPalette( void ) { int i; COLORREF leftcolor; COLORREF rightcolor; COLORREF color; WPI_PRES pres; int leftindex; int rightindex; wie_clrtype lefttype; wie_clrtype righttype; if( currentPalIndex != COLOR_16 && currentPalIndex != COLOR_256 ) { return; } leftcolor = GetSelectedColor( LMOUSEBUTTON, NULL, &lefttype ); rightcolor = GetSelectedColor( RMOUSEBUTTON, NULL, &righttype ); leftindex = getColorIndex( leftcolor ); rightindex = getColorIndex( rightcolor ); for( i = 0; i < PALETTE_SIZE - 1; i++ ) { palette[currentPalIndex][i] = restorePalette[i]; ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed, palette[currentPalIndex][i].rgbGreen, palette[currentPalIndex][i].rgbBlue ), FALSE ); } /* * We do the last one separately to invalidate the window. */ palette[currentPalIndex][i] = restorePalette[i]; ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed, palette[currentPalIndex][i].rgbGreen, palette[currentPalIndex][i].rgbBlue ), TRUE ); if( lefttype == NORMAL_CLR ) { color = RGB( palette[currentPalIndex][leftindex].rgbRed, palette[currentPalIndex][leftindex].rgbGreen, palette[currentPalIndex][leftindex].rgbBlue ); pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); SetColor( LMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR ); _wpi_releasepres( HWND_DESKTOP, pres ); } if( righttype == NORMAL_CLR ) { color = RGB( palette[currentPalIndex][rightindex].rgbRed, palette[currentPalIndex][rightindex].rgbGreen, palette[currentPalIndex][rightindex].rgbBlue ); pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); SetColor( RMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR ); _wpi_releasepres( HWND_DESKTOP, pres ); } } /* ResetColorPalette */
/* * ReplacePaletteEntry - replace the current entry with the given RGB value */ void ReplacePaletteEntry( COLORREF newcolor ) { COLORREF cur_color; COLORREF nearestcolor; COLORREF screencolor; COLORREF rightcolor; wie_clrtype lefttype; wie_clrtype righttype; int index; int rightindex; WPI_PRES pres; if( currentPalIndex != COLOR_16 && currentPalIndex != COLOR_256 ) { return; } cur_color = GetSelectedColor( LMOUSEBUTTON, NULL, &lefttype ); if( lefttype == NORMAL_CLR ) { index = getColorIndex( cur_color ); rightcolor = GetSelectedColor( RMOUSEBUTTON, NULL, &righttype ); rightindex = getColorIndex( rightcolor ); palette[currentPalIndex][index].rgbRed = GetRValue( newcolor ); palette[currentPalIndex][index].rgbGreen = GetGValue( newcolor ); palette[currentPalIndex][index].rgbBlue = GetBValue( newcolor ); palette[currentPalIndex][index].rgbReserved = 0; ShowNewColor( index, newcolor, TRUE ); pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); SetColor( LMOUSEBUTTON, newcolor, _wpi_getnearestcolor( pres, newcolor ), NORMAL_CLR ); if( index == rightindex ) { SetColor( RMOUSEBUTTON, newcolor, _wpi_getnearestcolor( pres, newcolor ), NORMAL_CLR ); } _wpi_releasepres( HWND_DESKTOP, pres ); } else if( lefttype == SCREEN_CLR ) { pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); nearestcolor = _wpi_getnearestcolor( pres, newcolor ); _wpi_releasepres( HWND_DESKTOP, pres ); SetScreenClr( nearestcolor ); } else { pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); nearestcolor = _wpi_getnearestcolor( pres, newcolor ); _wpi_releasepres( HWND_DESKTOP, pres ); screencolor = GetInverseColor( nearestcolor ); SetScreenClr( screencolor ); } } /* ReplacePaletteEntry */
/* * GetXorBitmapInfo - Returns a pointer to a bitmap info structure ... memory * should be freed with FreeDIBitmapInfo. this is for * the xor part. */ BITMAPINFO2 *GetXorBitmapInfo( img_node *node ) { long size; WPI_BITMAPINFO *bmi; WPI_BITMAPINFOHEADER bmih; WPI_PRES pres; WPI_PRES mempres; HDC memdc; HBITMAP oldbitmap; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); size = BMPINFO2_SIZE( node->bitcount ); bmi = MemAlloc( size ); GetBitmapInfoHeader( &bmih, node ); memcpy( bmi, &bmih, sizeof(WPI_BITMAPINFOHEADER) ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); GpiQueryBitmapBits( mempres, 0, node->height, NULL, bmi ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); return( bmi ); } /* GetXorBitmapInfo */
/* * redrawViewWnd - process the WM_PAINT message for the view windows */ static void redrawViewWnd( HWND hwnd ) { WPI_PRES pres; WPI_PRES hps; WPI_PRES mempres; HDC memdc; HBITMAP bitmap; HBITMAP oldbitmap; img_node *node; PAINTSTRUCT ps; node = SelectFromViewHwnd( hwnd ); if( node == NULL ) { return; } hps = _wpi_beginpaint( hwnd, NULL, &ps ); drawBorder( node ); pres = _wpi_getpres( hwnd ); bitmap = CreateViewBitmap( node ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); oldbitmap = _wpi_selectbitmap( mempres, bitmap ); _wpi_bitblt( pres, BORDER_WIDTH, BORDER_WIDTH, node->width, node->height, mempres, 0, 0, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletebitmap( bitmap ); _wpi_deletecompatiblepres( mempres, memdc ); _wpi_releasepres( hwnd, pres ); _wpi_endpaint( hwnd, hps, &ps ); } /* redrawViewWnd */
/* * MakeBitmap - Makes the bitmap */ void MakeBitmap( img_node *node, BOOL isnew ) { HDC hdc; WPI_PRES pres; WPI_PRES mempres; HBITMAP oldbitmap; if (isnew) { InitXorAndBitmaps( node ); } else { /* * The AND bitmap won't really get used, but it should be around * since some functions are generic (ie for all image types) and * hence assume an AND bitmap exists. */ pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); node->handbitmap = _wpi_createbitmap(node->width, node->height, 1, 1, NULL ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); _wpi_patblt( mempres, 0, 0, node->width, node->height, BLACKNESS ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); } DisplayImageText( node ); } /* MakeBitmap */
/* * SetPosInStatus - set the position in the status window */ void SetPosInStatus( WPI_POINT *pt, WPI_POINT *pointsize, HWND hwnd ) { WPI_PRES pres; WPI_RECT rcclient; int x; int y; GetClientRect( hwnd, &rcclient ); if( _wpi_ptinrect( &rcclient, *pt ) && PositionText != NULL && SetPosText != NULL ) { if( pointsize->x == 0 ) { pointsize->x = 1; } if( pointsize->y == 0 ) { pointsize->y = 1; } x = pt->x / pointsize->x; y = pt->y / pointsize->y; sprintf( PositionText, SetPosText, leftBlock, x, y ); pres = _wpi_getpres( statusBarWnd ); StatusWndDrawLine( statusBar, pres, SmallFont, PositionText, -1 ); _wpi_releasepres( statusBarWnd, pres ); } } /* SetPosInStatus */
/* * SetBoxColors - set the values of the color boxes * - all coordinates are using the Windows convention of the * top left as the origin */ void SetBoxColors( palette_box *screen, palette_box *inverse, int num_colors, palette_box *avail_colors ) { short i; wie_clrtype type; WPI_PRES pres; COLORREF rgbcolor; leftColorIndex = getColorIndex( GetSelectedColor( LMOUSEBUTTON, NULL, &type ) ); rightColorIndex = getColorIndex( GetSelectedColor( RMOUSEBUTTON, NULL, &type ) ); chooseThePalette( num_colors ); /* * First initialize the screen color boxes. */ screen->box.left = SCRN_COL_X; screen->box.right = SCRN_COL_X + SQR_SIZE + 1; screen->box.top = SCRN_COL_Y; screen->box.bottom = SCRN_COL_Y + SQR_SIZE + 1; inverse->box.left = SCRN_COL_X; inverse->box.right = SCRN_COL_X + SQR_SIZE + 1; inverse->box.top = SCRN_COL_Y + SQR_SIZE; inverse->box.bottom = SCRN_COL_Y + 2 * SQR_SIZE + 1; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); for( i = 0; i < PALETTE_SIZE; i += 2 ) { rgbcolor = RGB( palette[currentPalIndex][i].rgbRed, palette[currentPalIndex][i].rgbGreen, palette[currentPalIndex][i].rgbBlue ); avail_colors[i].color = _wpi_getcolorindex( pres, rgbcolor ); if( num_colors == 2 ) { avail_colors[i].solid_color = WHITE; } else { avail_colors[i].solid_color = _wpi_getnearestcolor( pres, rgbcolor ); } avail_colors[i].box.left = (i / 2) * SQR_SIZE; avail_colors[i].box.top = 0; avail_colors[i].box.right = SQR_SIZE + (i / 2) * SQR_SIZE + 1; avail_colors[i].box.bottom = SQR_SIZE + 1; rgbcolor = RGB( palette[currentPalIndex][i + 1].rgbRed, palette[currentPalIndex][i + 1].rgbGreen, palette[currentPalIndex][i + 1].rgbBlue ); avail_colors[i + 1].color = _wpi_getcolorindex( pres, rgbcolor ); if( num_colors == 2 ) { avail_colors[i + 1].solid_color = BLACK; } else { avail_colors[i + 1].solid_color = _wpi_getnearestcolor( pres, rgbcolor ); } avail_colors[i + 1].box.left = avail_colors[i].box.left; avail_colors[i + 1].box.top = SQR_SIZE; avail_colors[i + 1].box.right = avail_colors[i].box.right; avail_colors[i + 1].box.bottom = SQR_SIZE * 2 + 1; } _wpi_releasepres( HWND_DESKTOP, pres ); } /* SetBoxColors */
/* * SetHintText - set the hint text */ void SetHintText( char *msg ) { char *text; int len; WPI_PRES pres; len = strlen( hintTextPosition ) + 1; if( msg != NULL ) { len += strlen( msg ); } else { len++; } text = (char *)MemAlloc( len ); if( text != NULL ) { strcpy( text, hintTextPosition ); if( msg != NULL ) { strcat( text, msg ); } else { strcat( text, " " ); } pres = _wpi_getpres( statusBarWnd ); StatusWndDrawLine( statusBar, pres, SmallFont, text, -1 ); _wpi_releasepres( statusBarWnd, pres ); MemFree( text ); } } /* SetHintText */
/* * selectColor - select the color */ static void selectColor( WPI_POINT *pt, HWND hwnd ) { int i; WPI_PRES pres; HWND currentwnd; int top; int bottom; WPI_RECT wrect; currentwnd = _wpi_getdlgitem( hwnd, BK_CURRENT ); pres = _wpi_getpres( currentwnd ); _wpi_mapwindowpoints( hwnd, currentwnd, pt, 1 ); _wpi_torgbmode( pres ); for( i = 0; i < 16; i++ ) { top = availColor[i].box.top; bottom = availColor[i].box.bottom; top = _wpi_cvth_y( top, 2 * SQR_SIZE ); bottom = _wpi_cvth_y( bottom, 2 * SQR_SIZE ); _wpi_setintwrectvalues( &wrect, availColor[i].box.left, top, availColor[i].box.right, bottom ); if( _wpi_ptinrect( &wrect, *pt ) ) { screenColor.color = availColor[i].color; DisplayColorBox( pres, &screenColor ); inverseColor.color = GetInverseColor( screenColor.color ); DisplayColorBox( pres, &inverseColor ); break; } } _wpi_releasepres( currentwnd, pres ); } /* selectColor */
/* * GetAndBitmapInfo - Returns a pointer to a bitmap info structure ... memory * should be freed with FreeDIBitmapInfo. this is for * the and part. */ BITMAPINFO2 *GetAndBitmapInfo( img_node *node ) { long size; WPI_BITMAPINFO *bmi; WPI_BITMAPINFOHEADER bmih; WPI_PRES pres; WPI_PRES mempres; HDC memdc; HBITMAP oldbitmap; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); size = BMPINFO2_SIZE( 1 ); bmi = MemAlloc( size ); GetBitmapInfoHeader( &bmih, node ); // Adjustments for the and mask bmih.cBitCount = 1; bmih.cbImage = BITS_TO_BYTES( node->bitcount, node->height ); bmih.cclrUsed = 2; memcpy( bmi, &bmih, sizeof(WPI_BITMAPINFOHEADER) ); oldbitmap = _wpi_selectobject( mempres, node->handbitmap ); GpiQueryBitmapBits( mempres, 0, node->height, NULL, bmi ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); bmi->cbImage = BITS_TO_BYTES( node->bitcount, 2*node->height ); bmi->cy = node->height * 2; return( bmi ); } /* GetAndBitmapInfo */
/* * SetSizeInStatus - set the size in the status line */ void SetSizeInStatus( HWND hwnd, WPI_POINT *startpt, WPI_POINT *endpt, WPI_POINT *pointsize ) { WPI_POINT pt1; WPI_POINT pt2; WPI_POINT pos; int width; int height; WPI_PRES pres; if( SetSizeText == NULL || PositionSizeText == NULL ) { return; } CheckBounds( hwnd, startpt ); CheckBounds( hwnd, endpt ); pt1.x = min( startpt->x, endpt->x ) / pointsize->x; pt1.y = min( startpt->y, endpt->y ) / pointsize->y; pt2.x = max( startpt->x, endpt->x ) / pointsize->x; pt2.y = max( startpt->y, endpt->y ) / pointsize->y; width = pt2.x - pt1.x + 1; height = pt2.y - pt1.y + 1; pos.x = endpt->x / pointsize->x; pos.y = endpt->y / pointsize->y; sprintf( PositionSizeText, SetSizeText, leftBlock, pos.x, pos.y, nextBlock, width, height ); pres = _wpi_getpres( statusBarWnd ); StatusWndDrawLine( statusBar, pres, SmallFont, PositionSizeText, -1 ); _wpi_releasepres( statusBarWnd, pres ); } /* SetSizeInStatus */
/* * 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 */
bool GetControlInfo( gui_window * wnd, unsigned id, HWND *hwnd, WPI_PRES *dc ) { if ( wnd && wnd->hwnd ) { *hwnd = _wpi_getdlgitem( wnd->hwnd, id ); if ( *hwnd != (HWND)NULL ) { *dc = _wpi_getpres( *hwnd ); return( *dc != NULLHANDLE ); } } return( false ); }
/* * CreateStatusFont - creates the font used in the status window */ void CreateStatusFont( void ) { WPI_LOGFONT logfont; WPI_PROC fp; WPI_PRES pres; pres = _wpi_getpres( HWND_DESKTOP ); #ifdef __OS2_PM__ _wpi_enumfonts( pres, NULL, (WPI_ENUMFONTPROC)EnumFontFunc, "Helv" ); fp = fp; #else fp = _wpi_makeprocinstance( EnumFontFunc, Instance ); #ifdef __NT__ EnumFonts( hdc, NULL, (LPVOID)fp, (LPARAM)(LPCSTR)"ms sans serif"); #else EnumFonts( hdc, NULL, (LPVOID)fp, (LPVOID)"ms sans serif"); #endif #endif _wpi_freeprocinstance( fp ); if( currentLogFont == NULL ) { // SmallFont = GetStockObject( ANSI_FIXED_FONT ); // GetObject( SmallFont, sizeof( LOGFONT ), (LPSTR) &logfont ); // SmallFont = CreateFontIndirect( &logfont ); } else { memcpy( &logfont, currentLogFont, sizeof(WPI_LOGFONT) ); // _wpi_setfontheight( &logfont, 11 ); // _wpi_setfontwidth( &logfont, 10 ); _wpi_setfontpointsize( &logfont, 10, 0, _wpi_fontmatch(&logfont) ); _wpi_createrealfont( logfont, SmallFont ); #if 0 SmallFont = CreateFont( 10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, currentLogFont->lfCharSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, currentLogFont->lfPitchAndFamily, currentLogFont->lfFaceName ); #endif free( currentLogFont ); currentLogFont = NULL; } _wpi_releasepres( HWND_DESKTOP, pres ); } /* CreateStatusFont */
/* * GetInverseColor - return the inverse color * - simply performing a bitwise NOT doesn't do the trick * so this method is employed */ COLORREF GetInverseColor( COLORREF color ) { int i; int num_colors; COLORREF solidcolor; COLORREF newcolor; WPI_PRES pres; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); /* * change this so that we check the number of colors the machine has */ num_colors = 16; solidcolor = _wpi_getnearestcolor( pres, color ); _wpi_releasepres( HWND_DESKTOP, pres ); for( i = 0; i < num_colors; i++ ) { if( solidcolor == RGB( solids[i].rgbRed, solids[i].rgbBlue, solids[i].rgbGreen ) ) { break; } } switch( i ) { case 0: case 2: case 4: case 6: case 8: case 10: case 12: case 14: newcolor = RGB( solids[i + 1].rgbRed, solids[i + 1].rgbBlue, solids[i + 1].rgbGreen ); return( RGB( solids[i + 1].rgbRed, solids[i + 1].rgbBlue, solids[i + 1].rgbGreen ) ); case 1: case 3: case 5: case 7: case 9: case 11: case 13: case 15: newcolor = RGB( solids[i - 1].rgbRed, solids[i - 1].rgbBlue, solids[i - 1].rgbGreen ); return( RGB( solids[i - 1].rgbRed, solids[i - 1].rgbBlue, solids[i - 1].rgbGreen ) ); default: return( WHITE ); } } /* GetInverseColor */
/* * 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 */
/* * ClearImageText - clear the text in the image size section */ void ClearImageText( void ) { WPI_PRES pres; char text[20]; strcpy( text, imgSizePosition ); strcat( text, " " ); pres = _wpi_getpres( statusBarWnd ); StatusWndDrawLine( statusBar, pres, SmallFont, text, -1 ); _wpi_releasepres( statusBarWnd, pres ); } /* ClearImageText */
/* * SetInitScreenColor - set the initial screen and inverse colors from * the profile information */ void SetInitScreenColor( COLORREF color ) { WPI_PRES pres; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); screenColor.color = _wpi_getnearestcolor( pres, color ); screenColor.solid_color = screenColor.color; _wpi_releasepres( HWND_DESKTOP, pres ); SetViewBkColor( screenColor.color ); } /* SetInitScreenColor */
/* * 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 */
/* * LineXorAnd - draw the line on the XOR and the AND bitmaps */ void LineXorAnd( COLORREF xorcolor, COLORREF andcolor, WPI_POINT *startpt, WPI_POINT *endpt ) { HPEN oldpen; HPEN hpen; HDC memdc; WPI_PRES pres; WPI_PRES mempres; HBITMAP oldbitmap; HDC anddc; anddc = anddc; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); hpen = _wpi_createpen( PS_SOLID, 0, xorcolor ); oldpen = _wpi_selectobject( mempres, hpen ); oldbitmap = _wpi_selectobject( mempres, activeImage->hxorbitmap ); _wpi_movetoex( mempres, startpt, NULL ); _wpi_lineto( mempres, endpt ); _wpi_setpixel( mempres, endpt->x, endpt->y, xorcolor ); _wpi_selectobject( mempres, oldpen ); _wpi_deleteobject( hpen ); _wpi_selectobject( mempres, oldbitmap ); if( activeImage->imgtype == BITMAP_IMG ) { _wpi_deletecompatiblepres( mempres, memdc ); return; } hpen = _wpi_createpen( PS_SOLID, 0, andcolor ); oldpen = _wpi_selectobject( mempres, hpen ); oldbitmap = _wpi_selectobject( mempres, activeImage->handbitmap ); _wpi_movetoex( mempres, startpt, NULL ); _wpi_lineto( mempres, endpt ); _wpi_setpixel( mempres, endpt->x, endpt->y, andcolor ); _wpi_selectobject( mempres, oldpen ); _wpi_deleteobject( hpen ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, anddc ); } /* LineXorAnd */
/* * RedrawPrevClip - redraw the area if a region has been selected and copied to the * clipboard OR if a region has been selected and then another is * selected (without a cut or copy in between) * - the hwnd parameter indicates which window to draw the clip rect on * - if the hwnd does not match the one associated with clipRect, we return */ void RedrawPrevClip( HWND hwnd ) { WPI_POINT pointsize; int prevROP2; HBRUSH blackbrush; HBRUSH oldbrush; HPEN whitepen; HPEN oldpen; WPI_PRES pres; WPI_RECTDIM left; WPI_RECTDIM top; WPI_RECTDIM right; WPI_RECTDIM bottom; img_node *node; if( !fEnableCutCopy || !_wpi_iswindow( Instance, hwnd ) || clipRect.hwnd != hwnd ) { return; } pointsize = GetPointSize( hwnd ); pres = _wpi_getpres( hwnd ); _wpi_torgbmode( pres ); prevROP2 = _wpi_setrop2( pres, R2_XORPEN ); blackbrush = _wpi_createsolidbrush( BLACK ); oldbrush = _wpi_selectobject( pres, blackbrush ); whitepen = _wpi_createpen( PS_SOLID, 0, WHITE ); oldpen = _wpi_selectobject( pres, whitepen ); _wpi_getrectvalues( clipRect.rect, &left, &top, &right, &bottom ); node = SelectImage( hwnd ); #ifdef __OS2_PM__ _wpi_rectangle( pres, left * pointsize.x + 1, bottom * pointsize.y + 1, right * pointsize.x, top * pointsize.y ); #else _wpi_rectangle( pres, left * pointsize.x, top * pointsize.y, right * pointsize.x, bottom * pointsize.y ); #endif _wpi_selectobject( pres, oldpen ); _wpi_selectobject( pres, oldbrush ); _wpi_setrop2( pres, prevROP2 ); _wpi_releasepres( hwnd, pres ); _wpi_deleteobject( whitepen ); _wpi_deleteobject( blackbrush ); } /* RedrawPrevClip */
/* * SetScreenClr - set the color to represent the screen */ void SetScreenClr( COLORREF screen_color ) { WPI_PRES pres; pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); screenColor.color = _wpi_getnearestcolor( pres, screen_color ); screenColor.solid_color = screenColor.color; _wpi_releasepres( HWND_DESKTOP, pres ); inverseColor.color = GetInverseColor( screenColor.color ); inverseColor.solid_color = inverseColor.color; VerifyCurrentClr( screenColor.color, inverseColor.color ); _wpi_invalidaterect( hScreenWnd, NULL, FALSE ); } /* SetScreenClr */
/* * writeDataInPieces - writes the xor data for the bitmap in chunks */ static bool writeDataInPieces( BITMAPINFO2 *bmi, FILE *fp, img_node *node ) { WPI_PRES pres; WPI_PRES mempres; HDC memdc; int scanline_count; int one_scanline_size; long chunk_size; int start; int num_lines; long byte_count; BYTE *buffer; HBITMAP oldbitmap; pres = _wpi_getpres( HWND_DESKTOP ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); _wpi_releasepres( HWND_DESKTOP, pres ); oldbitmap = _wpi_selectobject( mempres, node->hxorbitmap ); byte_count = BITS_TO_BYTES( node->bitcount * node->width, node->height ); start = 0; num_lines = SCANLINE_SIZE; one_scanline_size = BITS_TO_BYTES( node->width*node->bitcount, 1 ); scanline_count = node->height; chunk_size = one_scanline_size * num_lines; while( chunk_size > MAX_CHUNK ) { chunk_size >>= 1; num_lines = chunk_size / one_scanline_size; } buffer = calloc( chunk_size, sizeof( BYTE ) ); while( scanline_count > num_lines ) { GpiQueryBitmapBits( mempres, start, num_lines, buffer, bmi ); fwrite( buffer, sizeof( BYTE ), chunk_size, fp ); scanline_count -= num_lines; start += num_lines; byte_count -= chunk_size; } GpiQueryBitmapBits( mempres, start, scanline_count, buffer, bmi ); fwrite( buffer, sizeof( BYTE ), one_scanline_size * scanline_count, fp ); free( buffer ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); return( true ); } /* writeDataInPieces */
/* * OutlineLine - outline the line before it is drawn */ void OutlineLine( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt, WPI_POINT *prev_pt, BOOL firsttime ) { WPI_POINT startpt; WPI_POINT endpt; WPI_POINT prevpt; int prevROP2; HPEN holdpen; HPEN hwhitepen; WPI_PRES pres; CheckBounds( hwnd, start_pt ); CheckBounds( hwnd, end_pt ); startpt.x = MAKELOGPTX( start_pt->x ) + pointSize.x / 2; startpt.y = MAKELOGPTY( start_pt->y ) + pointSize.y / 2; endpt.x = MAKELOGPTX( end_pt->x ) + pointSize.x / 2; endpt.y = MAKELOGPTY( end_pt->y ) + pointSize.y / 2; pres = _wpi_getpres( hwnd ); _wpi_torgbmode( pres ); hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE ); holdpen = _wpi_selectobject( pres, hwhitepen ); prevROP2 = _wpi_setrop2( pres, R2_XORPEN ); if( !firsttime ) { CheckBounds( hwnd, prev_pt ); prevpt.x = MAKELOGPTX( prev_pt->x ) + pointSize.x / 2; prevpt.y = MAKELOGPTY( prev_pt->y ) + pointSize.y / 2; _wpi_movetoex( pres, &startpt, NULL ); _wpi_lineto( pres, &prevpt ); } _wpi_movetoex( pres, &startpt, NULL ); _wpi_lineto( pres, &endpt ); _wpi_setrop2( pres, prevROP2 ); _wpi_selectobject( pres, holdpen ); _wpi_deleteobject( hwhitepen ); _wpi_releasepres( hwnd, pres ); } /* OutlineLine */
/* * displayColors - display the colors */ static void displayColors( HWND hwnd ) { short i; WPI_PRES pres; HWND currentwnd; inverseColor.color = GetInverseColor( screenColor.color ); currentwnd = _wpi_getdlgitem( hwnd, BK_CURRENT ); pres = _wpi_getpres( currentwnd ); _wpi_torgbmode( pres ); DisplayColorBox( pres, &screenColor ); DisplayColorBox( pres, &inverseColor ); for( i = 0; i < 16; i++ ) { DisplayColorBox( pres, &availColor[i] ); } _wpi_releasepres( currentwnd, pres ); } /* displayColors */
bool GUIDrawStatusText( gui_window *wnd, const char *text ) { WPI_PRES pres; const char *out_text; if( !GUIHasStatus( wnd) ) { return( false ); } pres = _wpi_getpres( wnd->status ); if( ( text == NULL ) || ( *text == '\0' ) ) { out_text = LIT( Blank ); } else { out_text = text; } StatusWndDrawLine( GUIStatusWnd, pres, wnd->font, out_text, DT_SINGLELINE | DT_VCENTER | DT_LEFT ); _wpi_releasepres( wnd->status, pres ); if( ( text == NULL ) || ( *text == '\0' ) ) { GUIEVENTWND( wnd, GUI_STATUS_CLEARED, NULL ); } return( true ); }
/* * DragClipBitmap - routine to show the clipped bitmap */ void DragClipBitmap( HWND hwnd, WPI_POINT *newpt, WPI_POINT pointsize ) { int prevROP2; HBRUSH hbrush; HBRUSH holdbrush; HPEN hwhitepen; HPEN holdpen; WPI_PRES pres; pres = _wpi_getpres( hwnd ); if( pres == (HDC)NULL ) { return; } prevROP2 = _wpi_setrop2( pres, R2_XORPEN ); hbrush = _wpi_createsolidbrush( CLR_BLACK ); holdbrush = _wpi_selectobject( pres, hbrush ); hwhitepen = _wpi_createpen( PS_SOLID, 0, CLR_WHITE ); holdpen = _wpi_selectobject( pres, hwhitepen ); if( !firstTime ) { _wpi_rectangle( pres, prevPoint.x * pointsize.x, prevPoint.y * pointsize.y, prevPoint.x * pointsize.x + dragWidth, prevPoint.y * pointsize.y + dragHeight ); } _wpi_rectangle( pres, newpt->x * pointsize.x, newpt->y * pointsize.y, newpt->x * pointsize.x + dragWidth, newpt->y * pointsize.y + dragHeight ); _wpi_selectobject( pres, holdpen ); _wpi_selectobject( pres, holdbrush ); _wpi_deleteobject( hwhitepen ); _wpi_deleteobject( hbrush ); _wpi_setrop2( pres, prevROP2 ); _wpi_releasepres( hwnd, pres ); memcpy( &prevPoint, newpt, sizeof( WPI_POINT ) ); firstTime = false; } /* DragClipBitmap */