/* * paintColors - paint the available colors on the color palette */ static void paintColors( HWND hwnd ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; PAINTSTRUCT ps; HBITMAP bitmap; HBITMAP oldbitmap; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif _wpi_torgbmode( pres ); if( numberOfColors == 2 ) { bitmap = hMonoBitmap; } else { bitmap = hColorBitmap; } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectbitmap( mempres, bitmap ); _wpi_bitblt( pres, 0, 0, CUR_BMP_WIDTH, CUR_BMP_HEIGHT, mempres, 0, 0, SRCCOPY ); _wpi_getoldbitmap( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_endpaint( hwnd, pres, &ps ); } /* paintColors */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * paintPalette - repaint the color palette */ static void paintPalette( HWND hwnd ) { WPI_PRES hdc; WPI_POINT pt; HPEN holdpen; HPEN hgraypen; HPEN hwhitepen; PAINTSTRUCT rect; WPI_RECT client; int height; hdc = _wpi_beginpaint( hwnd, NULL, &rect ); #ifdef __OS2_PM__ WinFillRect( hdc, &rect, CLR_PALEGRAY ); #endif _wpi_torgbmode( hdc ); GetClientRect( hwnd, &client ); height = _wpi_getheightrect( client ); #if defined( __NT__ ) FillRect( (HDC)hdc, (CONST RECT*)&client, hbrush ); #endif #if defined( __NT__ ) hgraypen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) ); #else hgraypen = _wpi_createpen( PS_SOLID, 0, DKGRAY ); #endif holdpen = _wpi_selectobject( hdc, hgraypen ); pt.x = 2; pt.y = 50; _wpi_cvth_pt( &pt, height ); _wpi_movetoex( hdc, &pt, NULL ); pt.y = 6; _wpi_cvth_pt( &pt, height ); _wpi_lineto( hdc, &pt ); pt.x = 90; _wpi_lineto( hdc, &pt ); _wpi_selectobject( hdc, holdpen ); _wpi_deleteobject( hgraypen ); #if defined( __NT__ ) hwhitepen = _wpi_createpen( PS_SOLID, 0, GetSysColor( COLOR_BTNHIGHLIGHT ) ); #else hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE ); #endif holdpen = _wpi_selectobject( hdc, hwhitepen ); pt.y = 50; _wpi_cvth_pt( &pt, height ); _wpi_lineto( hdc, &pt ); pt.x = 2; _wpi_lineto( hdc, &pt ); _wpi_selectobject( hdc, holdpen ); _wpi_deleteobject( hwhitepen ); _wpi_endpaint( hwnd, hdc, &rect ); } /* paintPalette */
/* * paintCurrent - paint the current window (process WM_PAINT) */ static void paintCurrent( HWND hwnd ) { WPI_PRES pres; WPI_PRES mempres; HDC hdc; PAINTSTRUCT ps; WPI_RECT rect; HBITMAP oldbitmap; int top; int bottom; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( pres ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_bitblt( pres, 0, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_bitblt( pres, CUR_RCOL_X - 1, 0, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, mempres, 0, 0, SRCCOPY ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, hdc ); _wpi_setbackmode( pres, TRANSPARENT ); _wpi_settextcolor( pres, GetInverseColor( lButton.solid ) ); top = _wpi_cvth_y( CUR_COL_Y, currentHeight ); bottom = _wpi_cvth_y( CUR_COL_Y + CUR_SQR_SIZE, currentHeight ); _wpi_setintwrectvalues( &rect, CUR_LCOL_X, top, CUR_LCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "L", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_settextcolor( pres, GetInverseColor( rButton.solid ) ); _wpi_setintwrectvalues( &rect, CUR_RCOL_X, top, CUR_RCOL_X + CUR_SQR_SIZE, bottom ); _wpi_drawtext( pres, "R", 1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); _wpi_endpaint( hwnd, pres, &ps ); } /* paintCurrent */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * 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 */
/* * paintScreen - paint the screen and inverse window */ static void paintScreen( HWND hwnd ) { WPI_PRES pres; PAINTSTRUCT ps; pres = _wpi_beginpaint( hwnd, NULL, &ps ); #ifdef __OS2_PM__ WinFillRect( pres, &ps, CLR_PALEGRAY ); #endif _wpi_torgbmode( pres ); if( fShowScreenClr ) { DisplayColorBox( pres, &screenColor ); DisplayColorBox( pres, &inverseColor ); } _wpi_endpaint( hwnd, pres, &ps ); } /* paintScreen */
/* * 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 */
three_d_handle ENTRYPOINT three_d_begin(WPI_PRES win_dc, RECTL * draw_area ) { int save_state; WPI_POINT pt; rgn_off(); Win_dc = win_dc; Is_metafile = FALSE; save_state = _wpi_savepres( win_dc ); _wpi_setmapmode( win_dc, MM_TEXT ); _winitwindow( draw_area ); _wsetwindow( 0.0, 0.0, 1.0, 1.0 ); _wpi_torgbmode( win_dc ); _wpi_setbackmode( win_dc, OPAQUE ); pt.x = 0; pt.y = 0; _wpi_setbrushorigin( win_dc, &pt ); #define MY_ZOOM 1.4 #define MY_LIGHT 2.0 _w3init( &Three_d, MY_ZOOM, MY_LIGHT, LIGHT_VERT_MID, TRUE ); return( save_state ); }
/* * OutlineRectangle - outline a rectangle with the XOR pen */ void OutlineRectangle( bool firsttime, WPI_PRES pres, WPI_RECT *prevrc, WPI_RECT *newrc ) { int prevrop2; HBRUSH holdbrush; HBRUSH nullbrush; HPEN holdpen; HPEN whitepen; int left, top, right, bottom; _wpi_torgbmode( pres ); nullbrush = _wpi_createnullbrush(); whitepen = _wpi_createpen( PS_SOLID, 0, WHITE ); holdbrush = _wpi_selectobject( pres, nullbrush ); holdpen = _wpi_selectobject( pres, whitepen ); prevrop2 = _wpi_setrop2( pres, R2_XORPEN ); if( !firsttime ) { _wpi_getintrectvalues( *prevrc, &left, &top, &right, &bottom ); /* * In this case don't call _wpi_convertheight because of the * way the rectangle values are set in iedraw.c */ _wpi_rectangle( pres, left, top, right, bottom ); } _wpi_getintrectvalues( *newrc, &left, &top, &right, &bottom ); _wpi_rectangle( pres, left, top, right, bottom ); _wpi_selectobject( pres, holdbrush ); _wpi_selectobject( pres, holdpen ); _wpi_setrop2( pres, prevrop2 ); _wpi_deleteobject( whitepen ); _wpi_deletenullbrush( nullbrush ); } /* OutlineRectangle */
/* * SetColor - set the current colors */ void SetColor( int mousebutton, COLORREF color, COLORREF solid, wie_clrtype type ) { HDC hdc; WPI_PRES pres; WPI_PRES mempres; HBITMAP oldbitmap; HPEN blackpen; HPEN oldpen; HBRUSH brush; HBRUSH oldbrush; int top; int bottom; blackpen = _wpi_createpen( PS_SOLID, 0, BLACK ); if( mousebutton == LMOUSEBUTTON ) { lButton.color = color; lButton.solid = solid; lButton.type = type; if( lButton.bitmap != NULL ) { _wpi_deletebitmap( lButton.bitmap ); pres = _wpi_getpres( HWND_DESKTOP ); if( numberOfColors == 2 && type == NORMAL_CLR ) { lButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); } else { lButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, lButton.bitmap ); _wpi_releasepres( HWND_DESKTOP, pres ); oldpen = _wpi_selectobject( mempres, blackpen ); brush = _wpi_createsolidbrush( solid ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( 0, currentHeight ); bottom = _wpi_cvth_y( CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); brush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( CUR_SQR_SIZE, currentHeight ); bottom = _wpi_cvth_y( 2 * CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); } } else { rButton.color = color; rButton.solid = solid; rButton.type = type; if( rButton.bitmap != NULL ) { _wpi_deletebitmap( rButton.bitmap ); pres = _wpi_getpres( HWND_DESKTOP ); if( numberOfColors == 2 && type == NORMAL_CLR ) { rButton.bitmap = _wpi_createbitmap( CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1, 1, 1, NULL ); } else { rButton.bitmap = _wpi_createcompatiblebitmap( pres, CUR_SQR_SIZE + 1, 2 * CUR_SQR_SIZE + 1 ); } mempres = _wpi_createcompatiblepres( pres, Instance, &hdc ); _wpi_torgbmode( mempres ); oldbitmap = _wpi_selectobject( mempres, rButton.bitmap ); _wpi_releasepres( HWND_DESKTOP, pres ); oldpen = _wpi_selectobject( mempres, blackpen ); brush = _wpi_createsolidbrush( solid ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( 0, currentHeight ); bottom = _wpi_cvth_y( CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); brush = _wpi_createsolidbrush( color ); oldbrush = _wpi_selectobject( mempres, brush ); top = _wpi_cvth_y( CUR_SQR_SIZE, currentHeight ); bottom = _wpi_cvth_y( 2 * CUR_SQR_SIZE + 1, currentHeight ); _wpi_rectangle( mempres, 0, top, CUR_SQR_SIZE + 1, bottom ); _wpi_selectobject( mempres, oldbrush ); _wpi_deleteobject( brush ); _wpi_selectobject( mempres, oldbitmap ); _wpi_selectobject( mempres, oldpen ); _wpi_deletecompatiblepres( mempres, hdc ); } } _wpi_deleteobject( blackpen ); InvalidateRect( hCurrentWnd, NULL, TRUE ); } /* SetColor */
/* * 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 */
/* * 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 */
void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; WPI_RECT fill_area; #ifdef __OS2_PM__ ULONG flags; RECTL client; #endif isdlg=isdlg; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; /* Setup Paint */ wnd->ps = &ps; wnd->hdc = _wpi_beginpaint( hwnd, NULLHANDLE, wnd->ps ); _wpi_torgbmode( wnd->hdc ); _wpi_getpaintrect( wnd->ps, &fill_area ); #ifdef __OS2_PM__ fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); #endif #if defined( __NT__ ) if( isdlg ) { _wpi_fillrect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ), wnd->bk_brush ); } #endif if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } else { wnd->prev_font = NULL; } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } #ifdef __OS2_PM__ if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( wnd->hdc, &client, 1, 1, 0, 0, flags ); } #endif _wpi_endpaint( hwnd, wnd->hdc, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; } #else // this is some experimental PM stuff void GUIPaint( gui_window *wnd, HWND hwnd, bool isdlg ) { HDC prev_hdc; PAINTSTRUCT *prev_ps; gui_row_num row_num; PAINTSTRUCT ps; PAINTSTRUCT fill_area; // experimenal stuff HPS hps; RECTL client; LONG width, height; ULONG flags; int compat_created; gui_paint_info *pinfo; // figure out which paint info to use if( !isdlg && wnd->root == hwnd ) { pinfo = &wnd->root_pinfo; } else { pinfo = &wnd->hwnd_pinfo; } pinfo->in_use++; compat_created = FALSE; /* save old state */ prev_hdc = wnd->hdc; prev_ps = wnd->ps; if( isdlg ) { _wpi_getclientrect( hwnd, &client ); } else { WinQueryWindowRect( hwnd, &client ); } width = client.xRight - client.xLeft; height = client.yTop - client.yBottom; wnd->ps = &ps; //hps = _wpi_beginpaint( hwnd, pinfo->normal_pres, wnd->ps ); hps = _wpi_beginpaint( hwnd, NULL, wnd->ps ); if( pinfo->compatible_pres == (WPI_PRES)NULL ) { compat_created = TRUE; pinfo->compatible_pres = _wpi_createcompatiblepres( hps, GUIMainHInst, &pinfo->compatible_hdc ); pinfo->draw_bmp = _wpi_createcompatiblebitmap( hps, width, height ); pinfo->old_bmp = _wpi_selectbitmap( pinfo->compatible_pres, pinfo->draw_bmp ); } // the condition is here VERY conservative!! // its gains have to analyzed if( compat_created || pinfo->force_count ) { wnd->hdc = pinfo->compatible_pres; //wnd->hdc = hps; _wpi_torgbmode( wnd->hdc ); fill_area = *(wnd->ps); if( isdlg ) { _wpi_inflaterect( GUIMainHInst, &fill_area, 10, 10); } WinFillRect( wnd->hdc, &fill_area, GUIGetBack( wnd, GUI_BACKGROUND ) ); wnd->prev_font = NULL; if( wnd->font != NULL ) { wnd->prev_font = _wpi_selectfont( wnd->hdc, wnd->font ); } /* send paint to app */ GUIGetUpdateRows( wnd, hwnd, &row_num.start, &row_num.num ); if( row_num.num > 0 ) { GUIEVENTWND( wnd, GUI_PAINT, &row_num ); } /* finish painting */ if( wnd->prev_font != NULL ) { _wpi_getoldfont( wnd->hdc, wnd->prev_font ); wnd->prev_font = NULL; } if( pinfo->force_count ) { //pinfo->force_count--; } } //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); if( pinfo->in_use == 1 ) { //_wpi_bitblt( hps, client.xLeft, client.yBottom, width, height, // wnd->hdc, 0, 0, SRCCOPY ); _wpi_bitblt( hps, ps.xLeft, ps.yBottom, ps.xRight - ps.xLeft, ps.yTop - ps.yBottom, wnd->hdc, ps.xLeft, ps.yBottom, SRCCOPY ); if( pinfo->delete_when_done ) { GUIFreePaintHandles( pinfo, TRUE ); } } if( isdlg ) { flags = DB_AREAATTRS | DB_DLGBORDER; #ifdef _M_I86 if( WinQueryActiveWindow( HWND_DESKTOP, FALSE ) != hwnd ) { #else if( WinQueryActiveWindow( HWND_DESKTOP ) != hwnd ) { #endif //if( _wpi_getfocus() != hwnd ) { flags |= DB_PATINVERT; } WinQueryWindowRect( hwnd, &client ); WinDrawBorder( hps, &client, 1, 1, 0, 0, flags ); } _wpi_endpaint( hwnd, hps, wnd->ps ); /* restore old state */ wnd->hdc = prev_hdc; wnd->ps = prev_ps; if( pinfo->in_use ) { pinfo->in_use--; } } #endif void GUIInvalidatePaintHandles( gui_window *wnd ) { GUIFreeWndPaintHandles( wnd, FALSE ); }
/* * OutlineRegion - displays the potential region (rectangle or ellipse) * on the draw area. */ void OutlineRegion( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt, WPI_POINT *prev_pt, BOOL firsttime ) { WPI_POINT topleft; WPI_POINT bottomright; WPI_POINT prevtl; // previous top left point WPI_POINT prevbr; // previous bottom right point int prevROP2; HBRUSH hbrush; HBRUSH holdbrush; HPEN hwhitepen; HPEN holdpen; int temp; WPI_PRES pres; CheckBounds( hwnd, start_pt ); CheckBounds( hwnd, end_pt ); CheckBounds( hwnd, prev_pt ); _wpi_setpoint(&topleft, MAKELOGPTX(start_pt->x), MAKELOGPTY(start_pt->y)); _wpi_setpoint(&bottomright, MAKELOGPTX(end_pt->x), MAKELOGPTY(end_pt->y)); if (topleft.x > bottomright.x) { temp = (short)bottomright.x; bottomright.x = topleft.x + pointSize.x; topleft.x = temp; } else { bottomright.x += pointSize.x; } if (topleft.y > bottomright.y) { temp = (int)bottomright.y; bottomright.y = topleft.y + pointSize.y; topleft.y = temp; } else { bottomright.y += pointSize.y; } prevtl.x = MAKELOGPTX( start_pt->x ); prevtl.y = MAKELOGPTY( start_pt->y ); prevbr.x = MAKELOGPTX( prev_pt->x ); prevbr.y = MAKELOGPTY( prev_pt->y ); if (prevtl.x > prevbr.x) { temp = (int)prevbr.x; prevbr.x = prevtl.x + pointSize.x; prevtl.x = temp; } else { prevbr.x += pointSize.x; } if (prevtl.y > prevbr.y) { temp = (int)prevbr.y; prevbr.y = prevtl.y + pointSize.y; prevtl.y = temp; } else { prevbr.y += pointSize.y; } ++prevtl.x; ++prevtl.y; ++topleft.x; ++topleft.y; pres = _wpi_getpres( hwnd ); _wpi_torgbmode( pres ); prevROP2 = _wpi_setrop2( pres, R2_XORPEN ); hbrush = _wpi_createsolidbrush( BLACK ); hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE ); holdbrush = _wpi_selectobject( pres, hbrush ); holdpen = _wpi_selectobject( pres, hwhitepen ); if (!firsttime) { if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) { _wpi_ellipse( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y ); } else { _wpi_rectangle( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y ); } } if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) { _wpi_ellipse( pres, topleft.x, topleft.y, bottomright.x, bottomright.y ); } else { _wpi_rectangle( pres, topleft.x, topleft.y, bottomright.x, bottomright.y ); } _wpi_selectobject( pres, holdpen ); _wpi_selectobject( pres, holdbrush ); _wpi_deleteobject( hwhitepen ); _wpi_deleteobject( hbrush ); _wpi_setrop2( pres, prevROP2 ); _wpi_releasepres( hwnd, pres ); } /* OutlineRegion */
/* * 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 */
/* * 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 */
/* * 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 */
/* * CreateViewBitmap - create the bitmap on the screen (with the background * color as it should be, etc.) * - the caller is responsible for deleting the bitmap */ HBITMAP CreateViewBitmap( img_node *mdi_node ) { WPI_PRES pres; WPI_PRES xorandpres; WPI_PRES mempres; WPI_PRES freehandpres; HDC xoranddc; HDC memdc; HBITMAP newbitmap; HBITMAP oldxorandbitmap; HBITMAP oldbitmap; HBRUSH brush; HBRUSH oldbrush; img_node *node; COLORREF bkcolor; if( mdi_node != NULL ) { node = mdi_node; } else { node = GetCurrentNode(); if( node == NULL ) { return( NULL ); } } pres = _wpi_getpres( HWND_DESKTOP ); xorandpres = _wpi_createcompatiblepres( pres, Instance, &xoranddc ); mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); newbitmap = _wpi_createcompatiblebitmap( pres, node->width, node->height ); _wpi_releasepres( HWND_DESKTOP, pres ); _wpi_torgbmode( mempres ); _wpi_torgbmode( xorandpres ); bkcolor = GetViewBkColor(); #ifdef __OS2_PM__ _wpi_preparemono( mempres, BLACK, bkcolor ); #endif oldbitmap = _wpi_selectobject( mempres, newbitmap ); brush = _wpi_createsolidbrush( bkcolor ); oldbrush = _wpi_selectobject( mempres, brush ); _wpi_patblt( mempres, 0, 0, node->width, node->height, PATCOPY ); _wpi_selectobject( mempres, oldbrush ); _wpi_deletebrush( brush ); GetFreeHandPresentationSpaces( NULL, &freehandpres, NULL ); if( freehandpres == (WPI_PRES)NULL ) { oldxorandbitmap = _wpi_selectobject( xorandpres, node->handbitmap ); _wpi_bitblt( mempres, 0, 0, node->width, node->height, xorandpres, 0, 0, SRCAND ); _wpi_selectobject( xorandpres, oldxorandbitmap ); } else { _wpi_bitblt( mempres, 0, 0, node->width, node->height, freehandpres, 0, 0, SRCAND ); } GetFreeHandPresentationSpaces( NULL, NULL, &freehandpres ); if( freehandpres == (WPI_PRES)NULL ) { oldxorandbitmap = _wpi_selectobject( xorandpres, node->hxorbitmap ); _wpi_bitblt( mempres, 0, 0, node->width, node->height, xorandpres, 0, 0, SRCINVERT ); _wpi_selectobject( xorandpres, oldxorandbitmap ); } else { _wpi_bitblt( mempres, 0, 0, node->width, node->height, freehandpres, 0, 0, SRCINVERT ); } _wpi_deletecompatiblepres( xorandpres, xoranddc ); _wpi_selectobject( mempres, oldbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); return( newbitmap ); } /* CreateViewBitmap */
/* * EnlargeImage - take an MDI window handle and enlarge the view bitmap * that goes with it * - returns a handle to the bitmap * - the bitmap must be deleted by the calling routine */ HBITMAP EnlargeImage( HWND hwnd ) { WPI_PRES pres; WPI_PRES srcpres; WPI_PRES destpres; HDC srcdc; HDC destdc; HBITMAP oldbitmap; HBITMAP newbitmap; HBITMAP olddestbitmap; HBITMAP viewbitmap; img_node *node; WPI_RECT rc; short width; short height; int window_width; int window_height; BITMAP bm; node = SelectImage( hwnd ); if( node == NULL ) { return( NULL ); } viewbitmap = CreateViewBitmap( node ); _wpi_getclientrect( hwnd, &rc ); /* * I add this so that if the window's client rect doesn't fit on the * screen, it will still enlarge to the right size. */ window_width = _wpi_getwidthrect( rc ); window_height = _wpi_getheightrect( rc ); if( window_width < node->width ) { window_width = node->width; } if( window_height < node->height ) { window_height = node->height; } pres = _wpi_getpres( HWND_DESKTOP ); srcpres = _wpi_createcompatiblepres( pres, Instance, &srcdc ); destpres = _wpi_createcompatiblepres( pres, Instance, &destdc ); newbitmap = _wpi_createcompatiblebitmap( pres, _wpi_getwidthrect( rc ), _wpi_getheightrect( rc ) ); _wpi_releasepres( HWND_DESKTOP, pres ); GetObject( newbitmap, sizeof( BITMAP ), &bm ); _wpi_torgbmode( destpres ); _wpi_torgbmode( srcpres ); olddestbitmap = _wpi_selectobject( destpres, newbitmap ); oldbitmap = _wpi_selectobject( srcpres, viewbitmap ); height = node->height; width = node->width; IEStretchBlt( destpres, 0, 0, _wpi_getwidthrect( rc ), _wpi_getheightrect( rc ), srcpres, 0, 0, width, height, SRCCOPY, bm.bmBitsPixel ); _wpi_selectobject( srcpres, oldbitmap ); _wpi_deletecompatiblepres( srcpres, srcdc ); _wpi_deleteobject( viewbitmap ); _wpi_selectobject( destpres, olddestbitmap ); _wpi_deletecompatiblepres( destpres, destdc ); return( newbitmap ); } /* EnlargeImage */