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; } }
static bool DrawLine( gui_window *wnd, gui_point *start, gui_point *end, gui_line_styles style, gui_ord thickness, WPI_COLOUR colour ) { gui_point my_start; gui_point my_end; HPEN pen; int win_style; gui_coord coord; HPEN old_pen; int hscroll; int vscroll; WPI_POINT pt; int win_height; my_start = *start; my_end = *end; GUIScaleToScreenRPt( &my_start ); GUIScaleToScreenRPt( &my_end ); if( GUI_DO_VSCROLL( wnd ) ) { vscroll = GUIGetScrollPos( wnd, SB_VERT ); } else { vscroll = 0; } if( GUI_DO_HSCROLL( wnd ) ) { hscroll = GUIGetScrollPos( wnd, SB_HORZ ); } else { hscroll = 0; } switch( style ) { case GUI_PEN_SOLID : win_style = PS_SOLID; coord.x = thickness; GUIScaleToScreenR( &coord ); break; case GUI_PEN_DASH : coord.x = 1; win_style = PS_DASH; break; case GUI_PEN_DOT : coord.x = 1; win_style = PS_DOT; break; case GUI_PEN_DASHDOT : coord.x = 1; win_style = PS_DASHDOT; break; case GUI_PEN_DASHDOTDOT : coord.x = 1; win_style = PS_DASHDOTDOT; break; default: coord.x = 0; win_style = 0; break; } pen = _wpi_createpen( win_style, coord.x, colour ); old_pen = _wpi_selectpen( wnd->hdc, pen ); win_height = _wpi_getheightrect( wnd->hwnd_client_rect ); pt.x = my_start.x - hscroll; pt.y = my_start.y - vscroll; pt.y = _wpi_cvth_y_plus1( pt.y, win_height ); _wpi_movetoex( wnd->hdc, &pt, &pt ); pt.x = my_end.x - hscroll; pt.y = my_end.y - vscroll; pt.y = _wpi_cvth_y_plus1( pt.y, win_height ); _wpi_lineto( wnd->hdc, &pt ); if( old_pen != NULLHANDLE ) { _wpi_getoldpen( wnd->hdc, old_pen ); } _wpi_deletepen( pen ); return( true ); }
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 ); } } }