static void get_obj_settings( /***************************/ /* set brush and pen based on fill type, for normal objects (polys, pies) */ int fill_type, HPEN *pen, HBRUSH *brush ) { switch( fill_type ) { case FILL_BORDER: // border only: interior not touched (pen) *pen = _wpi_createpen( Set_pen_style, 1, Set_color ); *brush = _wpi_createnullbrush(); Old_pen = _wpi_selectpen( Win_dc, *pen ); Old_brush = _wpi_selectbrush( Win_dc, *brush ); break; case FILL_INTERIOR: // interior only: border not touched (brush) /* Windows has a nasty bug. NULL_PEN generates a 'non-written' border. 'Width' = 0 doesn't help either. With NULL_PEN, behaviour depends on the primitive: rectangles goof, polygons are OK. Anyway, gist is that we gotta live with it! */ //*pen = CreatePen( PS_SOLID, 0, _wpi_getrgb( 0, 0, 0 ) ); *pen = _wpi_createnullpen(); *brush = cgr_make_brush( Set_color, Set_fill_style ); Old_pen = _wpi_selectpen( Win_dc, *pen ); Old_brush = _wpi_selectbrush( Win_dc, *brush ); break; case FILL_BORDER_CLEAR: // border WITH interior erased to bkgd (pen) *pen = _wpi_createpen( Set_pen_style, 1, Set_color ); *brush = cgr_make_brush( GetBkColor( Win_dc ), FILL_SOLID ); Old_pen = _wpi_selectpen( Win_dc, *pen ); Old_brush = _wpi_selectbrush( Win_dc, *brush ); break; case FILL_BORDER_FILL: // border and interior (pen & brush) *pen = _wpi_createpen( Set_pen_style, 1, Set_color ); *brush = cgr_make_brush( Set_color, Set_fill_style ); Old_pen = _wpi_selectpen( Win_dc, *pen ); Old_brush = _wpi_selectbrush( Win_dc, *brush ); break; } }
/* * initPRES - initialize our presentation space for drawing text */ static bool initPRES( statwnd *sw, WPI_PRES pres ) { if( sw->sectionDataFont == NULL ) { return( false ); } #ifdef __NT__ oldFont = _wpi_selectfont( pres, systemDataFont ); #else oldFont = _wpi_selectfont( pres, sw->sectionDataFont ); #endif oldBrush = _wpi_selectbrush( pres, brushButtonFace ); oldBkColor = _wpi_getbackcolour( pres ); _wpi_setbackcolour( pres, colorButtonFace ); #ifdef __OS2_PM__ GpiSetBackMix( pres, BM_OVERPAINT ); #else oldTextColor = GetTextColor( pres ); SetTextColor( pres, colorTextFace ); #endif return( true ); } /* initPRES */
/* * 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 */
void GUIDrawTextBitmapRGB( gui_window *wnd, const char *text, size_t length, int height, gui_coord *pos, WPI_COLOUR fore, WPI_COLOUR back, gui_ord extentx, bool draw_extent, int bitmap ) { int nDrawX, nDrawY; UINT lenx; HBRUSH brush; HBRUSH old_brush; HPEN pen; HPEN old_pen; int old_rop; size_t num_chars; WPI_RECT rect; gui_coord indent; int hscroll_pos; gui_coord extent; WPI_COLOUR colour; GUI_RECTDIM left, top, right, bottom; GUI_RECTDIM paint_left, paint_top, paint_right, paint_bottom; WPI_RECT paint_rect; WPI_RECT draw_rect; //draw_cache dcache; if( ( wnd->hdc == NULLHANDLE ) || ( wnd->ps == NULL ) || ( ( text == NULL ) && ( bitmap == 0 ) ) || ( ( bitmap != 0 ) && ( height == 0 ) ) ) { return; } old_rop = 0; old_brush = (HBRUSH)NULL; brush = (HBRUSH)NULL; old_pen = (HPEN)NULL; pen = (HPEN)NULL; GUIGetMetrics( wnd ); if( !bitmap ) { height = AVGYCHAR(GUItm); } rect = wnd->hwnd_client; _wpi_getrectvalues( rect, &left, &top, &right, &bottom); _wpi_getpaintrect( wnd->ps, &paint_rect ); _wpi_getwrectvalues( paint_rect, &paint_left, &paint_top, &paint_right, &paint_bottom ); top = paint_top / height * height; bottom = ( paint_bottom + height - 1) / height * height; if( GUI_DO_HSCROLL( wnd ) ) { hscroll_pos = GUIGetScrollPos( wnd, SB_HORZ ); } else { hscroll_pos = 0; } if( bitmap == 0 ) { num_chars = strlen( text ); if( num_chars > length ) { num_chars = length; } } indent.x = pos->x; indent.y = pos->y; GUIScaleToScreenR( &indent ); nDrawY = indent.y; if( GUI_DO_VSCROLL( wnd ) ) { nDrawY -= GUIGetScrollPos( wnd, SB_VERT ); } nDrawX = left; nDrawX += ( indent.x - hscroll_pos ); if( bitmap > 0 ) { lenx = length ; } else { lenx = GUIGetTextExtentX( wnd, text, num_chars ); } if( draw_extent ) { /* blanks out some portion of rest of the line */ if( extentx != GUI_NO_COLUMN ) { extent.x = extentx; GUIScaleToScreen( &extent ); right = nDrawX + extent.x; } } else { right = nDrawX + lenx; } nDrawY = _wpi_cvth_y_size( nDrawY, _wpi_getheightrect(wnd->hwnd_client), height ); _wpi_setrectvalues( &draw_rect, nDrawX, nDrawY, right, nDrawY+height ); if( GUIIsRectInUpdateRect( wnd, &draw_rect ) ) { colour = _wpi_getnearestcolor( wnd->hdc, back ); brush = _wpi_createsolidbrush( colour ); pen = _wpi_createpen( PS_SOLID, 1, colour ); if( pen == NULLHANDLE ) { GUIError(LIT( Pen_Failed )); } old_brush = _wpi_selectbrush( wnd->hdc, brush ); old_pen = _wpi_selectpen( wnd->hdc, pen ); #ifdef __OS2_PM__ _wpi_rectangle( wnd->hdc, nDrawX, nDrawY+1, right, nDrawY + height - 1 ); #else _wpi_rectangle( wnd->hdc, nDrawX, nDrawY, right, nDrawY + height); #endif /* if visible even with scrolling */ if( nDrawX < ( paint_right + hscroll_pos ) ) { if( bitmap > 0 ) { GUIDrawBitmap( bitmap, wnd->hdc, nDrawX, nDrawY, colour); } else { #ifdef __OS2_PM__ nDrawY += _wpi_metricdescent( GUItm ); #endif old_rop = _wpi_setrop2( wnd->hdc, R2_COPYPEN ); SetText( wnd, fore, back ); _wpi_textout( wnd->hdc, nDrawX, nDrawY, text, num_chars ); } } /* restore old resources */ if( old_rop != 0 ) { _wpi_setrop2( wnd->hdc, old_rop ); } if( old_brush != (HBRUSH)NULL ) { _wpi_getoldbrush( wnd->hdc, old_brush ); } if( brush != (HBRUSH)NULL ) { _wpi_deletebrush( brush ); } if( old_pen != (HPEN)NULL ) { _wpi_getoldpen( wnd->hdc, old_pen ); } if( pen != (HPEN)NULL ) { _wpi_deletepen( pen ); } } }