bool CLine::RInR(LPCRECT lpRect) { if(m_lStatus!=ST_NOMAL) return false; POINT ptTmp[4]; if((m_lx1-m_lx2)*(m_ly1-m_ly2)>=0) { ptTmp[0].x=m_lx1-1; ptTmp[0].y=m_ly1+1; ptTmp[1].x=m_lx1+1; ptTmp[1].y=m_ly1-1; ptTmp[2].x=m_lx2+1; ptTmp[2].y=m_ly2-1; ptTmp[3].x=m_lx2-1; ptTmp[3].y=m_ly2+1; } else { ptTmp[0].x=m_lx1+1; ptTmp[0].y=m_ly1+1; ptTmp[1].x=m_lx1-1; ptTmp[1].y=m_ly1-1; ptTmp[2].x=m_lx2-1; ptTmp[2].y=m_ly2-1; ptTmp[3].x=m_lx2+1; ptTmp[3].y=m_ly2+1; } CRgn rgnTmp; if(rgnTmp.CreatePolygonRgn(ptTmp,4,ALTERNATE)) { if(rgnTmp.RectInRegion(lpRect)) return true; } return false; }
void CResizableGrip::CSizeGrip::SetTriangularShape(BOOL bEnable) { m_bTriangular = bEnable; if (bEnable) { // set a triangular window region CRect rect; GetWindowRect(rect); rect.OffsetRect(-rect.TopLeft()); POINT arrPoints[] = { { rect.left, rect.bottom }, { rect.right, rect.bottom }, { rect.right, rect.top } }; CRgn rgnGrip; rgnGrip.CreatePolygonRgn(arrPoints, 3, WINDING); SetWindowRgn((HRGN)rgnGrip.Detach(), IsWindowVisible()); } else { SetWindowRgn((HRGN)NULL, IsWindowVisible()); } }
void TTransRemain::FillDest( TImage<unsigned char> &image, TPoint2D<int> &upCentre, TPoint2D<int> &downCentre, HDC &memHDC, const size_t radius) { CBrush bush; bush.CreateHatchBrush(HS_CROSS, RGB(255,255,255)); CRgn upRgn; upRgn.CreateEllipticRgn( upCentre.x()- radius, upCentre.y()-radius, upCentre.x()+ radius, upCentre.y()+radius); FillRgn(memHDC , upRgn, bush); CRgn downRgn; downRgn.CreateEllipticRgn( downCentre.x()-radius, downCentre.y()-radius, downCentre.x()+radius, downCentre.y()+radius); FillRgn(memHDC,downRgn, bush); CRgn midRgn; POINT midRect[4]; midRect[0].x = upCentre.x()-radius; midRect[0].y = upCentre.y(); midRect[1].x = downCentre.x()-radius; midRect[1].y = downCentre.y(); midRect[2].x = downCentre.x()+radius; midRect[2].y = downCentre.y(); midRect[3].x = upCentre.x()+radius; midRect[3].y = upCentre.y(); midRgn.CreatePolygonRgn(midRect, 4, ALTERNATE); FillRgn(memHDC, midRgn, bush); }
// **************************************************************************** // // Function Name: RWindowView::ValidateVectorRect( ) // // Description: Validates the given vector rect in this view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::ValidateVectorRect( const RRealVectorRect& rect ) { // // Only validate if we have a CWnd if( !GetCWnd() ) return; // Get the bounding rect... RRealVectorRect temp = rect; // Get our transformation... R2dTransform transform; ApplyTransform( transform, FALSE, FALSE ); // Apply it to our bounds... temp *= transform; // Convert the bounds to device units ::LogicalUnitsToDeviceUnits( temp, *this ); // Get the polygon points RRealPoint realPolygon[ 4 ]; temp.GetPolygonPoints( realPolygon ); // Create a polygon region RIntPoint polygon[4]; polygon[0] = realPolygon[0]; polygon[1] = realPolygon[1]; polygon[2] = realPolygon[2]; polygon[3] = realPolygon[3]; CRgn validateArea; validateArea.CreatePolygonRgn( reinterpret_cast<POINT*>( &polygon ), 4, ALTERNATE ); // Validate the region GetCWnd( ).ValidateRgn( &validateArea ); }
/* Description: Selects point cloud points using a 2D selection region. Parameters: view - [in] The view in which the selection region was defined. cloud - [in] The point cloud to test. points3d - [in] The 2D (screen) points that define the selection region. indices - [out] The indices of the points in the point cloud that lie inside of the selection region. Returns: The number of indices added to the output array. */ static int RhRegionSelectPointCloudPoints( CRhinoView* view, const ON_PointCloud& cloud, ON_SimpleArray<CPoint>& points2d, ON_SimpleArray<int>& indices ) { if( 0 == view ) return 0; const int index_count = indices.Count(); CRgn rgn; if( rgn.CreatePolygonRgn(points2d.Array(), points2d.Count(), WINDING) ) { ON_Xform w2s; view->ActiveViewport().VP().GetXform( ON::world_cs, ON::screen_cs, w2s ); int i; ON_3dPoint point; for( i = 0; i < cloud.m_P.Count(); i++ ) { point = cloud.m_P[i]; point.Transform( w2s ); if( rgn.PtInRegion((int)point.x, (int)point.y) ) indices.Append( i ); } } return indices.Count() - index_count; }
BOOL CTyBase::PointRgn(float x, float y, int Numble, PointStruct *PointList, float blc) { CRgn rgn; int x1,y1,i; CPoint bbcc[MAXPOINTNUM]; if(Numble < 3) return 0;//如果点的数目<3即不是一个区域返回不成功标志 ASSERT(Numble <= MAXPOINTNUM); //将点的坐标转变成屏幕坐标 x1 = (int)(x/blc); y1 = (int)(y/blc); //将封闭区域各点的坐标转成屏幕坐标 for(i = 0;i < Numble;i++) { bbcc[i].x = (int)((PointList[i].x)/blc); bbcc[i].y = (int)((PointList[i].y)/blc); } rgn.CreatePolygonRgn(bbcc,Numble,1);//初试化一个多边形区域 i = (rgn.PtInRegion(x1,y1)!=0); //如果在区域内j=1,否则j=0; rgn.DeleteObject(); //删除定义的rgn对象 return i; }
// rect must be in logical coordinates BOOL CDrawPoly::Intersects(const CRect& rect) { ASSERT_VALID(this); CRgn rgn; rgn.CreatePolygonRgn(m_points, m_nPoints, ALTERNATE); return rgn.RectInRegion(rect); }
void SEGMENT::CreateClipRgn( CDC *pDC, CRgn& rg ) { POINT pts[6]; for( int i = 0; i < 6; i++ ) { pts[i].x = froundl(m_ptClip[i].x); pts[i].y = froundl(m_ptClip[i].y); } pDC->LPtoDP( pts, 6 ); rg.CreatePolygonRgn( pts, 6, WINDING ); }
///////////////////////////////////////////////////////////////////// // // CXInfoTip::GetWindowRegion() // // DESCRIPTION // // Retrieves the window region // // RETURNS // // [BOOL] - TRUE on success, FALSE on failure // // PARAMETERS // // [pDC] - Pointer to display device context // [hRegion] - Filled with the calculated window region // [Size] - Filled with the calculated window size // or NULL. // ///////////////////////////////////////////////////////////////////// BOOL CXInfoTip::GetWindowRegion(CDC* pDC, HRGN* hRegion, CSize *Size /* = NULL */) { CRect rcWnd; POINT ptLeader[3]; CRgn LeaderRegion; CRgn CaptionRegion; CFont *pSysFont; ASSERT(pDC != NULL); ASSERT(hRegion != NULL); // Calculate the are for the tip text pSysFont = (CFont *)pDC->SelectObject(m_pFont); pDC->DrawText(m_szText, &rcWnd, DT_CALCRECT); pDC->SelectObject(pSysFont); // Adjust for the rounded corners rcWnd.InflateRect(CX_ROUNDED, CY_ROUNDED); // Adjust for icon if (m_hIcon != NULL) rcWnd.right = rcWnd.right + m_IconSize.cx + CX_ICON_MARGIN; if (rcWnd.Height() < m_IconSize.cy) rcWnd.bottom = rcWnd.top + m_IconSize.cy; // Calculate the leader triangle coordinates ptLeader[0].x = rcWnd.Width() - CX_ROUNDED; ptLeader[0].y = rcWnd.Height() - CY_ROUNDED; ptLeader[1].x = ptLeader[0].x; ptLeader[1].y = ptLeader[0].y + CY_LEADER; ptLeader[2].x = ptLeader[0].x - CX_LEADER; ptLeader[2].y = rcWnd.Height() - CY_ROUNDED; // Create the caption region CaptionRegion.CreateRoundRectRgn(0, 0, rcWnd.Width(), rcWnd.Height(), CX_ROUNDED, CY_ROUNDED); // Create the leader region LeaderRegion.CreatePolygonRgn(ptLeader, 3, ALTERNATE); // Create window region *hRegion = ::CreateRectRgn(0, 0, rcWnd.Width(), rcWnd.Height() + CY_LEADER); // Combine the regions CombineRgn(*hRegion, CaptionRegion.operator HRGN(), LeaderRegion.operator HRGN(), RGN_OR); // Set the window size if (Size != NULL) { Size->cx = rcWnd.Width(); Size->cy = rcWnd.Height() + CY_LEADER; } return TRUE; }
void CColorCell::OnDrawSelect(CDCHandle dc) { CBrushHandle brushWhite = (HBRUSH) ::GetStockObject (WHITE_BRUSH); CBrushHandle brushBlank = (HBRUSH) ::GetStockObject (BLACK_BRUSH); if (m_bAtFirstType) { if (m_crCell == RGB(255,255,255)) { CRgn rgnOne; rgnOne.CreatePolygonRgn(m_Points, 6, ALTERNATE); dc.FrameRgn(rgnOne, brushWhite, 3, 3); dc.FrameRgn(rgnOne, brushBlank, 2, 2); } else { CRgn rgnOne; rgnOne.CreatePolygonRgn(m_Points, 6, ALTERNATE); dc.FrameRgn(rgnOne, brushWhite, 3, 3); dc.FrameRgn(rgnOne, brushBlank, 1, 1); } } else { CRgn rgnOne, rgnTwo, rgnThree; CRect rcPos; rcPos = m_rcPosition; rcPos.DeflateRect(1, 1, 1, 1); rgnTwo.CreateRectRgnIndirect(&rcPos); dc.FrameRgn(rgnTwo, brushWhite, 2, 2); rcPos.InflateRect(2, 2, 2, 2); rgnThree.CreateRectRgnIndirect(&rcPos); dc.FrameRgn(rgnThree, brushBlank, 1, 1); } }
BOOL CResizeDlg::OnInitDialog() { BOOL bret = CDialog::OnInitDialog(); CRect cltRect; CBitmap cBmpSize; BITMAP Bitmap; GetClientRect(&cltRect); m_cltR0 = cltRect; ClientToScreen(&m_cltR0); m_cltRect = m_cltR0; cBmpSize.LoadOEMBitmap(OBM_SIZE); cBmpSize.GetBitmap(&Bitmap); m_wndSizeIcon.Create(NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, CRect(0, 0, Bitmap.bmWidth, Bitmap.bmHeight), this, m_idSizeIcon); m_wndSizeIcon.SetBitmap(cBmpSize); m_wndSizeIcon.SetWindowPos(&wndTop, cltRect.right - Bitmap.bmWidth, cltRect.bottom - Bitmap.bmHeight, 0, 0, SWP_NOSIZE); #if 0 CRgn cRgn; POINT bmpPt[3] = { { cltRect.right - Bitmap.bmWidth, cltRect.bottom }, { cltRect.right, cltRect.bottom - Bitmap.bmHeight}, { cltRect.right, cltRect.bottom } }; cRgn.CreatePolygonRgn(bmpPt, 3, WINDING); m_wndSizeIcon.SetWindowRgn(cRgn, TRUE); cRgn.Detach(); #endif cBmpSize.Detach(); AddControl(m_idSizeIcon, CST_REPOS, CST_REPOS, CST_REPOS, CST_REPOS); CRect wRect; GetWindowRect(&wRect); m_xMin = wRect.Width(); // default x limit m_yMin = wRect.Height(); // default y limit return bret; }
BOOL CColorCell::HitTest(CPoint point) { if (m_bAtFirstType) { CRgn rgn; rgn.CreatePolygonRgn(m_Points, 6, ALTERNATE); return rgn.PtInRegion(point); } else { CRgn rgn; rgn.CreateRectRgn(m_rcPosition.left, m_rcPosition.top, m_rcPosition.right, m_rcPosition.bottom); return rgn.PtInRegion(point); } }
BOOL CLine::IsSelect(CPoint pt) { CRgn rgn; CPoint Points[4]; Points[0].x = m_ptBegin.x; Points[0].y = m_ptBegin.y - 5; Points[1].x = m_ptBegin.x; Points[1].y = m_ptBegin.y + 5; Points[2].x = m_ptEnd.x; Points[2].y = m_ptEnd.y + 5; Points[3].x = m_ptEnd.x; Points[3].y = m_ptEnd.y - 5; rgn.CreatePolygonRgn(Points, 4, ALTERNATE); return rgn.PtInRegion(pt); }
////////////////// // Compute the the points, rect and region for a tab. // Input x is starting x pos. // int CFolderTab::ComputeRgn(CDC& dc, int x) { m_rgn.DeleteObject(); CRect& rc = m_rect; rc.SetRectEmpty(); // calculate desired text rectangle dc.DrawText(m_sText, &rc, DT_CALCRECT); rc.right += 2*CXOFFSET + 2*CXMARGIN; // add margins rc.bottom = rc.top + GetSystemMetrics(SM_CYHSCROLL); // ht = scrollbar ht rc += CPoint(x,0); // shift right // create trapezoid region CPoint pts[4]; GetTrapezoid(rc, pts); m_rgn.CreatePolygonRgn(pts, 4, WINDING); return rc.Width(); }
//********************************************************************************* void CBCGPVisualManagerVS2005::OnFillAutoHideButtonBackground (CDC* pDC, CRect rect, CBCGPAutoHideButton* pButton) { ASSERT_VALID (pDC); ASSERT_VALID (pButton); if (!m_bRoundedAutohideButtons) { return; } LPPOINT points; int nPoints = CreateAutoHideButtonRegion (rect, pButton->GetAlignment (), points); CRgn rgnClip; rgnClip.CreatePolygonRgn (points, nPoints, WINDING); pDC->SelectClipRgn (&rgnClip); if (globalData.m_nBitsPerPixel <= 8 || globalData.IsHighContastMode ()) { CBCGPVisualManager2003::OnFillAutoHideButtonBackground (pDC, rect, pButton); } else { BOOL bIsHorz = ((pButton->GetAlignment () & CBRS_ALIGN_ANY) == CBRS_ALIGN_LEFT || (pButton->GetAlignment () & CBRS_ALIGN_ANY) == CBRS_ALIGN_RIGHT); CBCGPDrawManager dm (*pDC); dm.FillGradient (rect, m_clrBarGradientDark, m_clrBarGradientLight, !bIsHorz); } pDC->SelectClipRgn (NULL); delete [] points; }
long CLine::HitTest(long x, long y) { if(!m_DnyAttr.m_Linked) return TK_NONE; CRect rtTemp; POINT pt; pt.x=x; pt.y=y; POINT ptTmp[4]; if((m_lx1-m_lx2)*(m_ly1-m_ly2)>=0) { ptTmp[0].x=m_lx1-DELTA; ptTmp[0].y=m_ly1+DELTA; ptTmp[1].x=m_lx1+DELTA; ptTmp[1].y=m_ly1-DELTA; ptTmp[2].x=m_lx2+DELTA; ptTmp[2].y=m_ly2-DELTA; ptTmp[3].x=m_lx2-DELTA; ptTmp[3].y=m_ly2+DELTA; } else { ptTmp[0].x=m_lx1+DELTA; ptTmp[0].y=m_ly1+DELTA; ptTmp[1].x=m_lx1-DELTA; ptTmp[1].y=m_ly1-DELTA; ptTmp[2].x=m_lx2-DELTA; ptTmp[2].y=m_ly2-DELTA; ptTmp[3].x=m_lx2+DELTA; ptTmp[3].y=m_ly2+DELTA; } CRgn rgnTmp; if(rgnTmp.CreatePolygonRgn(ptTmp,4,ALTERNATE)) { if(rgnTmp.PtInRegion(pt)) return TK_PUSH; } return TK_NONE; }
void FW_DropDownWnd::OnPaint() { CPaintDC dc(this); CRect rect; GetClientRect(&rect); dc.FillSolidRect(rect, GetSysColor(COLOR_APPWORKSPACE)); CRect rcText(0,0,0,0); dc.SetTextColor(GetSysColor(COLOR_WINDOW)); CBrush brush(GetSysColor(COLOR_WINDOW)); CBrush* pOldBrush = dc.SelectObject(&brush); //CFont* pOldFont = dc.SelectObject(&m_font); CString text; GetWindowText(text); dc.DrawText(text, rcText, DT_NOPREFIX | DT_CALCRECT); int width = 8; // Down arrow width. int space = 4; // Space between text and down arrow. rcText.OffsetRect(width, 0); rcText.bottom = rect.bottom; if (rcText.right > (rect.right - width*2 - space - rect.Height())) rcText.right = (rect.right - width*2 - space - rect.Height()); CRgn rgn; CPoint ptVertex[4]; CPoint org(rcText.right + space, rect.Height()/2 - width/4); ptVertex[0].x = org.x; ptVertex[0].y = org.y; ptVertex[1].x = org.x + width; ptVertex[1].y = org.y; ptVertex[2].x = org.x + width/2; ptVertex[2].y = org.y + width/2; ptVertex[3].x = org.x; ptVertex[3].y = org.y; VERIFY(rgn.CreatePolygonRgn( ptVertex, 4, ALTERNATE)); dc.DrawText(text, rcText, DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS); dc.PaintRgn(&rgn); rect.right = rcText.right + width*2 + space; m_buttonRect = rect; if (m_nDropDownState) { // Draw the button edge. COLORREF white = RGB(255,255,255); COLORREF black = RGB( 0, 0, 0); CPen bottomRight(PS_SOLID, 1, m_nDropDownState < 0 ? white : black); CPen topLeft(PS_SOLID, 1, m_nDropDownState < 0 ? black : white); --rect.bottom; CPen* pOldPen = dc.SelectObject(&topLeft); dc.MoveTo(rect.left, rect.bottom); dc.LineTo(rect.left, rect.top); dc.LineTo(rect.right, rect.top); dc.SelectObject(&bottomRight); dc.LineTo(rect.right, rect.bottom); dc.LineTo(rect.left, rect.bottom); dc.SelectObject(pOldPen); } //dc.SelectObject(pOldFont); dc.SelectObject(pOldBrush); }
/*************************************************** OnDraw - overloaded CUGCellType::OnDraw Draws the cells text on the left hand side using the CUGCellType::DrawText function, so that all standard text drawing capabilities are available. Draws the sort arrows on the right according to their current pressed/raised state. **See CUGCellType::OnDraw for more details about this function ****************************************************/ void CUGSpinButtonType::OnDraw(CDC *dc,RECT *rect,int col,long row, CUGCell *cell,int selected,int current) { if (!m_drawThemesSet) m_useThemes = cell->UseThemes(); int style = 0; if( cell->IsPropertySet( UGCELL_CELLTYPEEX_SET ) ) style = cell->GetCellTypeEx(); float fScale = 1.0; #ifdef UG_ENABLE_PRINTING fScale = m_ctrl->GetUGPrint()->GetPrintVScale(dc); #endif //if the cell is not current and hide button is on //then dont draw the button if( style & UGCT_SPINBUTTONHIDEBUTTON && !current) { CUGCellType::OnDraw(dc,rect,col,row,cell,selected,current); return; } DrawBorder(dc,rect,rect,cell); int t,x,y; RECT rectout; CPen * oldpen; int left = rect->left; int height = rect->bottom - rect->top; #ifdef UG_ENABLE_PRINTING if (dc->IsPrinting()) { rect->left += (int) fScale; rect->right -= (int) fScale; rect->top += (int) fScale; rect->bottom -= (int) fScale; } #endif rect->left = rect->right - (int) (fScale * btnWidth); // The Spin type does not contain themes we can use for selected or current, we use the same for both. UGXPThemeState topstate = UGXPThemes::GetState(selected > 0 || current > 0, false); //draw the top button t = rect->bottom; rect->bottom = rect->top + (rect->bottom - rect->top) / 2; if(btnTopDown && current){ cell->SetBorder(UG_BDR_RECESSED); DrawBorder(dc,rect,&rectout,cell); topstate = ThemeStatePressed; } else{ cell->SetBorder(UG_BDR_RAISED); DrawBorder(dc,rect,&rectout,cell); } if (!m_useThemes || !UGXPThemes::DrawBackground(NULL, *dc, XPCellTypeSpinUp, topstate, &rectout, NULL)) { //fill the border in dc->SetBkColor(GetSysColor(COLOR_BTNFACE)); dc->FillRect(&rectout,&brush); //draw the down arrow if( height >9 ){ if( dc->IsPrinting() ) { #ifdef UG_ENABLE_PRINTING CRgn rgn; int nWidth = rectout.right - rectout.left; int nHeight = rectout.bottom - rectout.top; POINT point[] = { {rectout.left + nWidth / 2, rectout.top + nHeight / 2 - (int) fScale} , {rectout.left + nWidth / 2 - (int) (2 * fScale), rectout.top + nHeight / 2 + (int) fScale} , {rectout.left + nWidth / 2 + (int) (2 * fScale), rectout.top + nHeight / 2 + (int) fScale} }; rgn.CreatePolygonRgn(point, 3, ALTERNATE); CBrush Brush; Brush.CreateSolidBrush(RGB(0, 0 , 0)); dc->FillRgn(&rgn, &Brush); #endif } else { x = ((btnWidth-5)/2) + rect->left; y = ((rect->bottom - rect->top -3)/2) + rect->top; dc->SelectObject((CPen*)CPen::FromHandle((HPEN)GetStockObject(BLACK_PEN))); dc->MoveTo(x,y+2); dc->LineTo(x+5,y+2); dc->MoveTo(x+1,y+1); dc->LineTo(x+4,y+1); dc->MoveTo(x+2,y); dc->LineTo(x+2,y+1); } } } //reset the rect rect->bottom = t; // The Spin type does not contain themes we can use for selected or current, we use the same for both. UGXPThemeState bottomstate = UGXPThemes::GetState(selected > 0 || current > 0, false); //draw the bottom button t = rect->top; rect->top = (rect->top +(rect->bottom - rect->top)/2); if(btnBottomDown && current){ cell->SetBorder(UG_BDR_RECESSED); DrawBorder(dc,rect,&rectout,cell); bottomstate = ThemeStatePressed; } else{ cell->SetBorder(UG_BDR_RAISED); DrawBorder(dc,rect,&rectout,cell); } //fill the border in dc->SetBkColor(GetSysColor(COLOR_BTNFACE)); dc->FillRect(&rectout,&brush); if (!m_useThemes || !UGXPThemes::DrawBackground(NULL, *dc, XPCellTypeSpinDown, bottomstate, &rectout, NULL)) { //draw the down arrow if(height >9){ if( dc->IsPrinting() ) { #ifdef UG_ENABLE_PRINTING CRgn rgn; int nWidth = rectout.right - rectout.left; int nHeight = rectout.bottom - rectout.top; POINT point[] = { {rectout.left + nWidth / 2 - (int) (2 * fScale), rectout.top + nHeight / 2 - (int) fScale} , {rectout.left + nWidth / 2 + (int) (2 * fScale), rectout.top + nHeight / 2 - (int) fScale} , {rectout.left + nWidth / 2, rectout.top + nHeight / 2 + (int) fScale} }; rgn.CreatePolygonRgn(point, 3, ALTERNATE); CBrush Brush; Brush.CreateSolidBrush(RGB(0, 0 , 0)); dc->FillRgn(&rgn, &Brush); #endif } else { x= ((btnWidth-5)/2) + rect->left; y = ((rect->bottom - rect->top -3)/2) + rect->top +1; dc->SelectObject((CPen*)CPen::FromHandle((HPEN)GetStockObject(BLACK_PEN))); dc->MoveTo(x,y); dc->LineTo(x+5,y); dc->MoveTo(x+1,y+1); dc->LineTo(x+4,y+1); dc->MoveTo(x+2,y+2); dc->LineTo(x+2,y+1); } } } //reset the rect rect->top = t; //make a line to separate the border from the rest ofthe cell oldpen = (CPen *)dc->SelectObject((CPen *)&pen); dc->MoveTo(rect->left - (int)fScale,rect->top); dc->LineTo(rect->left - (int)fScale,rect->bottom); dc->SelectObject(oldpen); //draw the text in using the default drawing routine rect->left = left; rect->right -= (int) ((btnWidth+1) * fScale); DrawText(dc,rect,0,col,row,cell,selected,current); return; }
void CPtEmtDytCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { pdc->FillRect(rcBounds.operator LPCRECT(), CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH))); if (FALSE == m_PtEmt.IsGrayOK()) { pdc->SetTextAlign(TA_CENTER|TA_BASELINE); CString pszText = _T("PtEmtDyt"); pdc->TextOut(rcBounds.Width() / 2, rcBounds.Height() / 2, pszText); } else { CRect rect(rcBounds); FLOAT winDiameter = rect.Width() * 1.0f; if (rect.Width() > rect.Height()) { winDiameter = rect.Height() * 1.0f; } winDiameter *= 0.9f; const FLOAT Diameter = 0.13f; m_Scale = winDiameter /Diameter; m_Center = CPoint(rect.right / 2, rect.bottom / 2); FLOAT mingray(1e20f), maxgray(-1e20f); for(SHORT i = 0; i < TotalElement; i++) { maxgray = max(maxgray, m_PtEmt.GetMGray(i)); mingray = min(mingray, m_PtEmt.GetMGray(i)); } TEXTMETRIC tm; CString str; CRgn rgn; CBrush br; pdc->GetTextMetrics(&tm); CPoint ColorBarPoint(10, int(m_Center.y * 2.0 / 3 + 10 * tm.tmHeight)); for(i = 0; i < lColorNum ;i++) { CRect rt(ColorBarPoint.x, ColorBarPoint.y-tm.tmHeight, ColorBarPoint.x+20, ColorBarPoint.y); br.CreateSolidBrush(lColorBegin + lColorEnd * (lColorNum-i-1) * lColorNum); pdc->FillRect(rt.operator LPCRECT(), &br); FLOAT ruler = mingray + (maxgray-mingray)*FLOAT(i)/(lColorNum - 1); str.Format(_T("%e"), ruler); ColorBarPoint.y -= tm.tmHeight; pdc->TextOut(ColorBarPoint.x + 23, ColorBarPoint.y, str); br.DeleteObject(); } // Draw Gray Picture for (i = 0 ; i < InsideElement; i++) { if (fabs(m_PtEmt.GetMGray(i)) > 0.000001) { CPoint point[4]; for(SHORT j = 0; j < 4; j++) { point[j] = _PToL(m_PtEmt.GetNodes(i, j)); } SHORT clrLevel = SHORT((lColorNum-1) * (m_PtEmt.GetMGray(i)-mingray) / (maxgray-mingray)); rgn.CreatePolygonRgn(point,4, ALTERNATE); br.CreateSolidBrush(lColorBegin + lColorEnd * (lColorNum-clrLevel-1) * lColorNum); pdc->FillRgn(&rgn, &br); br.DeleteObject(); rgn.DeleteObject(); } } for (i=0; i < DetectorNum; i++) { FLOAT startangle,stopangle; POINT startpoint,stoppoint; COMPLEX startnode,stopnode; int CurDR = int(DetectorRadius * m_Scale); startangle = FLOAT(PIE*(2*i+1)/DetectorNum-DetectorAngle/2.0*PIE/180.0); stopangle = FLOAT(startangle+DetectorAngle*PIE/180.0); startnode = COMPLEX(DetectorRadius*cos(startangle), DetectorRadius*sin(startangle)); stopnode = COMPLEX(DetectorRadius*cos(stopangle), DetectorRadius*sin(stopangle)); startpoint = _PToL(startnode); stoppoint = _PToL(stopnode); pdc->Arc(m_Center.x-CurDR + 60,m_Center.y-CurDR,m_Center.x+CurDR + 60,m_Center.y+CurDR, startpoint.x,startpoint.y,stoppoint.x,stoppoint.y); } CPoint pul, plr, pst; pul = _PToL(COMPLEX(-PipeRadius, -PipeRadius)); plr = _PToL(COMPLEX(PipeRadius, PipeRadius)); pst = _PToL(COMPLEX(PipeRadius, 0.0)); pdc->Arc(pul.x,pul.y,plr.x,plr.y,pst.x,pst.y,pst.x,pst.y); pul = _PToL(COMPLEX(-ScreenRadius, -ScreenRadius)); plr = _PToL(COMPLEX(ScreenRadius, ScreenRadius)); pst = _PToL(COMPLEX(ScreenRadius, 0.0)); pdc->Arc(pul.x,pul.y,plr.x,plr.y,pst.x,pst.y,pst.x,pst.y); } }
void CPLine::Draw( CDC *pDC, int m_DrwaMode, int m_DrwaMode1, short BackColor ) { //图形绘制函数 if (b_Delete) //如果已经处于删除状态 { return; } short LineType=m_LineType; short ColorPen=m_ColorPen; short ColorBrush=m_ColorBrush; if (m_DrwaMode1==1) //如果图形元素需要特殊显示 { if (m_LineType!=2)//如果图形元素采用的不是第二种线型(虚线),则采用第二种线型 { LineType=2; } else //如果图形元素采用的是第二种线型(虚线),则采用第三种线型 { ++LineType; } } else if (m_DrwaMode1==2)//如果需要用指定颜色绘制连续直线或多边形区域, //将笔色和填充色设置屏幕底色BackColor { ColorPen=BackColor; ColorBrush=BackColor; } //创建并初始化一个CPen对象 extern CGraphPara *p_GraphPara; CPen pen((int)LineType, (int)m_LineWide, p_GraphPara->GetColor(ColorPen)); CPen *pOldPen=pDC->SelectObject(&pen); CBrush brush(p_GraphPara->GetColor(m_ColorBrush)); CBrush *pOldBrush=pDC->SelectObject(&brush); POINT *ppoint; CRgn rgn; if(m_DrwaMode==0) pDC->SetROP2(R2_COPYPEN); else if( m_DrwaMode==1) pDC->SetROP2(R2_NOT); ppoint=new POINT[m_Numble+1]; for (int i=0; i<m_Numble; ++i) { ppoint[i].x=(long)m_PiontList[i].x; ppoint[i].y=(long)m_PiontList[i].y; } if (!b_Fill) // 如果是连续直线,则依次绘制各个线段 { ppoint[m_Numble]=ppoint[0]; pDC->MoveTo(ppoint[0].x, ppoint[0].y); for (i=0; i<m_Numble; ++i) { pDC->LineTo(ppoint[i].x, ppoint[i].y); } } else //如果是多边形 { if (m_DrwaMode1==0 || m_DrwaMode1==2) //如果是正常显示 { pDC->Polyline(ppoint,m_Numble); } else if (m_DrwaMode1==1) //如果是反色显示 { rgn.CreatePolygonRgn(ppoint,m_Numble,0); //创建一个CRgn对象 pDC->InvertRgn(&rgn); //将CRgn对象确定的区域反色显示 } } delete ppoint; //删除动态分配的结构数组 pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); }
void CLogGraph::drawHeader(CDC& dc) { XTPPaintManager()->GradientFill(&dc, m_rectHeader,m_crHeaderBack, RGB(0,0,0), FALSE); CPen* pOldPen, pen; CFont* pOldFont; CString fmt, s; int i; if (m_nScaleIndex != -1) drawScale(dc, m_nScaleIndex, m_rectScale, DT_RIGHT); if (m_nScaleIndex2 != -1) drawScale(dc, m_nScaleIndex2, m_rectScale2, DT_LEFT); // draw Header (로그 시작점, 로그 끝점 표시) CString tmp; pOldFont = dc.SelectObject(&m_fontHeader); dc.SetTextColor(m_crHeader); if (!m_bLoad)return; //short* a = new short [lib->mque_reclen(m_hQue)]; ////////////// tdata* tp = getTptr(m_nCurrentPos); // read date // lib->mque_getn(m_hQue, m_nCurrentPos+1, a); m_tStart = tp->time; s = tformat("%Y-%m-%d\r\n%H:%M:%S", m_tStart); tmp.Format("%s\r\n%d", s, m_nCurrentPos); dc.DrawText(tmp, &m_rectHeader, DT_LEFT); // lib->mque_getn(m_hQue, getWndQueLastPos()-1, a); tp = getTptr(getWndQueLastPos()-1); // m_tEnd = lib->mque_time(m_hQue); // s = tformat("%Y-%m-%d\r\n%H:%M:%S", (int)m_tEnd); tmp.Format("%s\r\n%d", s, getWndQueLastPos()); dc.DrawText(tmp, &m_rectHeader, DT_RIGHT); // delete a; // draw Header (nav button, zoom) int nav[4][20] = { // 20x20 짜리 nav button { 1,1, 4,1, 4,8, 18,1, 18,19, 4,12, 4,19, 1,19, 1,1, 0,0 }, // home { 1,10, 10,1, 10,8, 19,1, 19,19, 10,12, 10,19, 1,10, 0,0 }, // pgup { 1,1, 10,8, 10,1, 19,10, 10,19, 10,12, 1,19, 1,1, 0,0 }, // pgdn { 1,1, 16,8, 16,1, 19,1, 19,19, 16,19, 16,12, 1,19, 1,1, 0,0 } // end }; CRect r = m_rectHeader; int w = 20; // button width & height int iw = w - 4; // icon size CBrush brush; CRgn rgn; CPoint pt[20]; brush.CreateSolidBrush(RGB(255, 100, 100)); pen.CreatePen(PS_SOLID, 1, RGB(255, 255, 255)); pOldPen = dc.SelectObject(&pen); r.left = r.Width() / 2 - (w * 4) / 2; r.right = r.left + w * 4; r.bottom = r.top + w; int x = r.left; for (i = 0; i < 4; i++) { CRect rect = r; rect.left = x + 1; rect.right = x + w - 1; rect.top++; rect.bottom--; switch (i) { case 0 : m_rectHome = rect; break; case 1 : m_rectPgUp = rect; break; case 2 : m_rectPgDn = rect; break; case 3 : m_rectEnd = rect; break; } XTPPaintManager()->GradientFill(&dc, &rect, RGB(100,100,100), RGB(0,0,0), FALSE); int j; for (j = 0; nav[i][j] !=0; j+=2) { pt[j/2].x = int(double(nav[i][j]) * iw / 20.0) + x + 2; pt[j/2].y = int(double(nav[i][j+1]) * iw / 20.0) + r.top + 2; } VERIFY(rgn.CreatePolygonRgn(pt, j/2, WINDING)); dc.FillRgn(&rgn, &brush); rgn.DeleteObject(); x += w; } dc.SelectObject(pOldPen); r.top = r.top + w; r.DeflateRect(2, 2); r.bottom = m_rectHeader.bottom; m_rectZoom = r; XTPPaintManager()->GradientFill(&dc, &r, RGB(100,50,50), RGB(0,0,0), FALSE); s.Format("Zoom %.0f:1", m_fZoomFactor); dc.DrawText(s, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE); dc.SelectObject(pOldFont); }
BOOL CXInfoTip::GetWindowRegion(CDC* pDC, HRGN* hRegion, CSize *Size ) { CRect rcWnd (0,0,0,0); POINT ptLeader[3]; CRgn LeaderRegion; CRgn CaptionRegion; CFont *pSysFont; ASSERT(pDC != NULL); ASSERT(hRegion != NULL); pSysFont = (CFont *)pDC->SelectObject(&m_fntBold); CRect rcWnd1, rcWnd2; pDC->DrawText(m_strCaption + "\n", &rcWnd1, DT_CALCRECT); pDC->SelectObject (m_pFont); pDC->DrawText(m_szText, &rcWnd2, DT_CALCRECT); m_nCaptionHeight = rcWnd1.Height (); rcWnd.right = max (rcWnd1.Width (), rcWnd2.Width ()); rcWnd.bottom = m_nCaptionHeight + rcWnd2.Height (); if (m_bShowDSA) { CRect rcDSA; pDC->DrawText (LS (L_DONTSHOWTHISWINDOWAGAIN), &rcDSA, DT_CALCRECT); m_yDSA = rcWnd.bottom + rcDSA.Height (); rcWnd.bottom += 10 + rcDSA.Height (); m_cxDSA = rcDSA.Width (); rcWnd.right = max (rcWnd.right, m_cxDSA + 30); } pDC->SelectObject(pSysFont); rcWnd.InflateRect(CX_ROUNDED, CY_ROUNDED); if (m_hIcon != NULL) rcWnd.right = rcWnd.right + m_IconSize.cx + CX_ICON_MARGIN; if (rcWnd.Height() < m_IconSize.cy) rcWnd.bottom = rcWnd.top + m_IconSize.cy; ptLeader[0].x = rcWnd.Width() - CX_ROUNDED; ptLeader[0].y = rcWnd.Height() - CY_ROUNDED; ptLeader[1].x = ptLeader[0].x; ptLeader[1].y = ptLeader[0].y + CY_LEADER; ptLeader[2].x = ptLeader[0].x - CX_LEADER; ptLeader[2].y = rcWnd.Height() - CY_ROUNDED; CaptionRegion.CreateRoundRectRgn(0, 0, rcWnd.Width(), rcWnd.Height(), CX_ROUNDED, CY_ROUNDED); LeaderRegion.CreatePolygonRgn(ptLeader, 3, ALTERNATE); *hRegion = ::CreateRectRgn(0, 0, rcWnd.Width(), rcWnd.Height() + CY_LEADER); CombineRgn(*hRegion, CaptionRegion.operator HRGN(), LeaderRegion.operator HRGN(), RGN_OR); if (Size != NULL) { Size->cx = rcWnd.Width(); Size->cy = rcWnd.Height() + CY_LEADER; } return TRUE; }
/*************************************************** OnDraw - overloaded CUGCellType::OnDraw The drop list cell type draws its text using the base classes DrawText routine, plus draws the drop down button **See CUGCellType::OnDraw for more details about this function Params dc - device context to draw the cell with rect - rectangle to draw the cell in col - column that is being drawn row - row that is being drawn cell - cell that is being drawn selected- TRUE if the cell is selected, otherwise FALSE current - TRUE if the cell is the current cell, otherwise FALSE Return none ****************************************************/ void CUGDropListType::OnDraw(CDC *dc,RECT *rect,int col,long row,CUGCell *cell,int selected,int current) { if (!m_drawThemesSet) m_useThemes = cell->UseThemes(); int left = rect->left; RECT rectout; CPen * oldpen; int style = 0; if(cell->IsPropertySet(UGCELL_CELLTYPEEX_SET)) style = cell->GetCellTypeEx(); //if the cell is not current and hide button is on //then dont draw the button if(style&UGCT_DROPLISTHIDEBUTTON && !current){ CUGCellType::OnDraw(dc,rect,col,row,cell,selected,current); return; } float fScale = 1.0; #ifdef UG_ENABLE_PRINTING fScale = m_ctrl->GetUGPrint()->GetPrintVScale(dc); #endif RECT rcCombo = *rect; rcCombo.left = rcCombo.right - (int) (fScale * m_btnWidth); if(!m_useThemes || !UGXPThemes::DrawBackground(NULL, *dc, XPCellTypeData, UGXPThemes::GetState(selected > 0, current > 0), &rcCombo, NULL) || !UGXPThemes::DrawBackground(NULL, *dc, XPCellTypeCombo, UGXPThemes::GetState(selected > 0, current > 0), &rcCombo, NULL)) { DrawBorder(dc,rect,rect,cell); // The printer and the monitor have different resolutions. // So we should adjust the size of the button. rect->left = rect->right - (int) (fScale * m_btnWidth); #ifdef UG_ENABLE_PRINTING if (dc->IsPrinting()) { rect->left += (int) fScale; rect->right -= (int) fScale; rect->top += (int) fScale; rect->bottom -= (int) fScale; } #endif // draw the 3D border if(m_btnDown && current){ cell->SetBorder(UG_BDR_RECESSED); DrawBorder(dc,rect,&rectout,cell); } else{ cell->SetBorder(UG_BDR_RAISED); DrawBorder(dc,rect,&rectout,cell); } //fill the border in dc->FillRect(&rectout,&m_brush); //make a line to separate the border from the rest ofthe cell oldpen = (CPen *)dc->SelectObject((CPen *)&m_pen); dc->MoveTo(rect->left-1,rect->top); dc->LineTo(rect->left-1,rect->bottom); dc->SelectObject(oldpen); //draw the down arrow if (dc->IsPrinting()) { #ifdef UG_ENABLE_PRINTING CRgn rgn; int nWidth = rect->right - rect->left; int nHeight = rect->bottom - rect->top; POINT point[] = { {rect->left + nWidth * 3 / 10, rect->top + nHeight * 5 / 12} , {rect->left + nWidth * 7 / 10, rect->top + nHeight * 5 / 12}, {rect->left + nWidth / 2, rect->top + nHeight * 7 / 12} }; rgn.CreatePolygonRgn(point, 3, ALTERNATE); CBrush Brush; Brush.CreateSolidBrush(RGB(0,0,0)); dc->FillRgn(&rgn, &Brush); dc->SelectObject((CPen*)CPen::FromHandle((HPEN)GetStockObject(BLACK_PEN))); dc->MoveTo(rect->left,rect->top); dc->LineTo(rect->right,rect->top); #endif } else { int x= (int) ((fScale * m_btnWidth-5)/2) + rect->left; int y = ((rect->bottom - rect->top -3)/2) + rect->top; // create a pen object that will be used to draw the arrow on the button CPen *arrowPen = NULL; if ( cell->GetReadOnly() == TRUE ) { arrowPen = new CPen; arrowPen->CreatePen( PS_SOLID, 1, RGB(128,128,128)); } else arrowPen = (CPen*)CPen::FromHandle((HPEN)GetStockObject(BLACK_PEN)); oldpen = dc->SelectObject( arrowPen ); // draw the arrow dc->MoveTo(x,y); dc->LineTo(x+5,y); dc->MoveTo(x+1,y+1); dc->LineTo(x+4,y+1); dc->MoveTo(x+2,y+2); dc->LineTo(x+2,y+1); if ( cell->GetReadOnly() == TRUE ) { // clean up after temporary pen object dc->SelectObject(oldpen); arrowPen->DeleteObject(); delete arrowPen; // when the arrow is disabled, add a while outline line dc->SelectObject((CPen*)CPen::FromHandle((HPEN)GetStockObject(WHITE_PEN))); dc->MoveTo(x+3,y+2); dc->LineTo(x+5,y); dc->MoveTo(x+3,y+3); dc->LineTo(x+6,y); } } } //draw the text in using the default drawing routine rect->left = left; rect->right -= (int) (fScale * m_btnWidth+1); DrawText(dc,rect,0,col,row,cell,selected,current); }
void CDlgCreateVacuumPatch::DrawVacuumPatch() { if (m_VacuumPath != NULL) { CDC* pDC = GetDC(); CBrush ArrowBrush(COLORREF(0)); // CBrush BorderBrush(COLORREF(0x0)); /*Draw stuff*/ RECT OuterRect; robPOINT RobotPoint; POINT point; CRect ProbGridBmpUpdateRect; m_staVacuumPatchBounds.GetWindowRect(&ProbGridBmpUpdateRect); ScreenToClient(&ProbGridBmpUpdateRect); // CPoint SurfaceOffset = ProbGridBmpUpdateRect.TopLeft(); CRect SurfaceOffset = ProbGridBmpUpdateRect; RobotPoint.x = m_Bounds.left, RobotPoint.y = m_Bounds.top; point = RobotToDDSurface(RobotPoint, SurfaceOffset); OuterRect.left = point.x; OuterRect.top = point.y; RobotPoint.x = m_Bounds.right, RobotPoint.y = m_Bounds.bottom; point = RobotToDDSurface(RobotPoint, SurfaceOffset); OuterRect.right = point.x; OuterRect.bottom = point.y; // pDC->FrameRect(&OuterRect, &BorderBrush); unsigned short i = 0; double HeadForward = m_HeadForward; while (i < m_NumberPaths) { short CosFor = (short)Round(cos(HeadForward)); short SinFor = (short)Round(sin(HeadForward)); short CosNext = (short)Round(cos(m_HeadNext)); short SinNext = (short)Round(sin(m_HeadNext)); /*Draw line*/ POINT BmpPoint[4]; if (i != 0) { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i - 1].Arc2e, SurfaceOffset); } else { BmpPoint[0] = RobotToDDSurface(m_EntryPoint, SurfaceOffset); } pDC->MoveTo(BmpPoint[0]); BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc1s, SurfaceOffset); pDC->LineTo(BmpPoint[0]); /*Draw arrow head*/ double x1, y1, x2, y2; x1 = m_VacuumPath[i].Arc1s.x - 30 * CosFor; y1 = m_VacuumPath[i].Arc1s.y - 30 * SinFor; RobotPoint.x = x1, RobotPoint.y = y1; BmpPoint[0] = RobotToDDSurface(RobotPoint, SurfaceOffset); x2 = x1 - CosFor * 30 - CosNext * 30; y2 = y1 - SinFor * 30 - SinNext * 30; RobotPoint.x = x2, RobotPoint.y = y2; BmpPoint[1] = RobotToDDSurface(RobotPoint, SurfaceOffset); x2 = x1 - CosFor * 30 + CosNext * 30; y2 = y1 - SinFor * 30 + SinNext * 30; RobotPoint.x = x2, RobotPoint.y = y2; BmpPoint[2] = RobotToDDSurface(RobotPoint, SurfaceOffset); BmpPoint[3] = BmpPoint[0]; CRgn ArrowRegion; ArrowRegion.CreatePolygonRgn(BmpPoint, 4, ALTERNATE); pDC->FillRgn(&ArrowRegion, &ArrowBrush); /*If next vacuum path inside the patch, draw an arc to it*/ if (i < m_NumberPaths - 1) { /*Draw 2 arcs*/ /*Arc 1*/ CRect ArcRect; short TurnDiameter = ABS(m_VacuumPath[i].TurnDiameter); x1 = m_VacuumPath[i].Arc1s.x + CosFor * TurnDiameter / 2; y1 = m_VacuumPath[i].Arc1s.y + SinFor * TurnDiameter / 2; x2 = m_VacuumPath[i].Arc1s.x - CosFor * TurnDiameter / 2 + CosNext * TurnDiameter; y2 = m_VacuumPath[i].Arc1s.y - SinFor * TurnDiameter / 2 + SinNext * TurnDiameter; RobotPoint.x = x1, RobotPoint.y = y1; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.left = point.x, ArcRect.top = point.y; RobotPoint.x = x2, RobotPoint.y = y2; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.right = point.x, ArcRect.bottom = point.y; ArcRect.NormalizeRect(); if ((SinFor * CosNext == 1) || (CosFor * SinNext == -1)) { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc1e, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc1s, SurfaceOffset); } else { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc1s, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc1e, SurfaceOffset); } pDC->Arc(ArcRect, BmpPoint[0], BmpPoint[1]); /*Arc 2*/ x1 = m_VacuumPath[i].Arc2c.x + m_VacuumPath[i].Arc2r; y1 = m_VacuumPath[i].Arc2c.y + m_VacuumPath[i].Arc2r; RobotPoint.x = x1, RobotPoint.y = y1; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.left = point.x, ArcRect.top = point.y; x1 = m_VacuumPath[i].Arc2c.x - m_VacuumPath[i].Arc2r; y1 = m_VacuumPath[i].Arc2c.y - m_VacuumPath[i].Arc2r; RobotPoint.x = x1, RobotPoint.y = y1; point = RobotToDDSurface(RobotPoint, SurfaceOffset); ArcRect.right = point.x, ArcRect.bottom = point.y; ArcRect.NormalizeRect(); if ((SinFor * CosNext == 1) || (CosFor * SinNext == -1)) { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc2s, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc2e, SurfaceOffset); } else { BmpPoint[0] = RobotToDDSurface(m_VacuumPath[i].Arc2e, SurfaceOffset); BmpPoint[1] = RobotToDDSurface(m_VacuumPath[i].Arc2s, SurfaceOffset); } pDC->Arc(ArcRect, BmpPoint[0], BmpPoint[1]); } /*Onto next patch*/ HeadForward += pi; i++; } // BorderBrush.DeleteObject(); // ArrowBrush.DeleteObject(); } }
// rect must be in logical coordinates BOOL CDrawRect::Intersects(const CRect& rect) { ASSERT_VALID(this); CRect rectT = rect; rectT.NormalizeRect(); CRect fixed = m_position; fixed.NormalizeRect(); if ((rectT & fixed).IsRectEmpty()) return FALSE; CRgn rgn; switch (m_nShape) { case rectangle: case text: return TRUE; case roundRectangle: rgn.CreateRoundRectRgn(fixed.left, fixed.top, fixed.right, fixed.bottom, m_roundness.x, m_roundness.y); break; case ellipse: rgn.CreateEllipticRgnIndirect(fixed); break; case line: { int x = (m_logpen.lopnWidth.x + 5) / 2; int y = (m_logpen.lopnWidth.y + 5) / 2; POINT points[4]; points[0].x = fixed.left; points[0].y = fixed.top; points[1].x = fixed.left; points[1].y = fixed.top; points[2].x = fixed.right; points[2].y = fixed.bottom; points[3].x = fixed.right; points[3].y = fixed.bottom; if (fixed.left < fixed.right) { points[0].x -= x; points[1].x += x; points[2].x += x; points[3].x -= x; } else { points[0].x += x; points[1].x -= x; points[2].x -= x; points[3].x += x; } if (fixed.top < fixed.bottom) { points[0].y -= y; points[1].y += y; points[2].y += y; points[3].y -= y; } else { points[0].y += y; points[1].y -= y; points[2].y -= y; points[3].y += y; } rgn.CreatePolygonRgn(points, 4, ALTERNATE); } break; } return rgn.RectInRegion(fixed); }
void UVMapView::End() { active = false; // get the model: if (!nmarks || !material || !material->tex_diffuse) return; // if not adding to selection: if (select_mode == SELECT_REPLACE) { Clear(); } Bitmap* bmp = material->tex_diffuse; int w = bmp->Width(); int h = bmp->Height(); double cx = window->Width() / 2 + x_offset; double cy = window->Height() / 2 + y_offset; // if only one mark: if (nmarks < 2) { // find all selected verts: ListIter<Poly> iter = polys; while (++iter) { Poly* p = iter.value(); VertexSet* vset = p->vertex_set; for (int i = 0; i < p->nverts; i++) { int n1 = p->verts[i]; double tu1 = vset->tu[n1]; double tv1 = vset->tv[n1]; int x1 = (int) (cx + zoom * w * (tu1-0.5)); int y1 = (int) (cy + zoom * h * (tv1-0.5)); int dx = abs(marks[0].x - x1); int dy = abs(marks[0].y - y1); if (dx < 4 && dy < 4) { WORD p_index = iter.index(); DWORD value = (p_index << 16) | i; if (select_mode == SELECT_REMOVE) { for (auto svi = selverts.begin(); svi != selverts.end(); ++svi) { if (*svi == value) { selverts.erase(svi); } } } else { bool contains = false; for (auto svi = selverts.begin(); svi != selverts.end(); ++svi) { if (*svi == value) { contains = true; } } if (!contains) selverts.push_back(value); } } } } } // otherwise, build a region: else { CRgn rgn; rgn.CreatePolygonRgn(marks, nmarks, WINDING); // find all selected verts: ListIter<Poly> iter = polys; while (++iter) { Poly* p = iter.value(); VertexSet* vset = p->vertex_set; for (int i = 0; i < p->nverts; i++) { int n1 = p->verts[i]; double tu1 = vset->tu[n1]; double tv1 = vset->tv[n1]; int x1 = (int) (cx + zoom * w * (tu1-0.5)); int y1 = (int) (cy + zoom * h * (tv1-0.5)); CPoint p(x1,y1); if (rgn.PtInRegion(p)) { WORD p_index = iter.index(); DWORD value = (p_index << 16) | i; if (select_mode == SELECT_REMOVE) { for (auto svi = selverts.begin(); svi != selverts.end(); ++svi) { if (*svi == value) selverts.erase(svi); } } else { bool contains = false; for (auto svi = selverts.begin(); svi != selverts.end(); ++svi) { if (*svi == value) contains = true; } if (!contains) selverts.push_back(value); } } } } } nmarks = 0; }
void Site::Draw(CDC* pDC) { //设置TextOut的属性 CFont font; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 15; //字体的高 lf.lfWidth = 8; //字体宽 font.CreateFontIndirect(&lf); pDC->SelectObject(&font); HDC hdc=pDC->GetSafeHdc (); ::SetBkMode(hdc,TRANSPARENT); ::SetTextColor (hdc, RGB(255,255,0)); if(ID>0)//只绘制动态点,静态点副本不绘制! { COLORREF c=RGB(255-GetRValue(Color) ,255-GetGValue(Color) ,255-GetBValue(Color)); App_Veriable::DefaultSiteSeletedModeColor=c; CPen pen; if(ID==App_Veriable::SelectedSiteID)//选中的路径 { pen.CreatePen (PS_SOLID,1,App_Veriable::DefaultSiteSeletedModeColor); } else pen.CreatePen (PS_SOLID,1,Color); pDC->SelectObject(pen); if(Style=='C') pDC->Ellipse(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2); if(Style=='T') { pDC->MoveTo(Position.x,Position.y-sqrt(3.0)*Size/3); pDC->LineTo(Position.x-Size/2,Position.y+sqrt(3.0)*Size/6); pDC->MoveTo(Position.x-Size/2,Position.y+sqrt(3.0)*Size/6); pDC->LineTo(Position.x+Size/2,Position.y+sqrt(3.0)*Size/6); pDC->MoveTo(Position.x+Size/2,Position.y+sqrt(3.0)*Size/6); pDC->LineTo(Position.x,Position.y-sqrt(3.0)*Size/3); } if(Style=='R') pDC->Rectangle(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2); pen.DeleteObject(); CBrush brush; if(ID==App_Veriable::SelectedSiteID)//选中的路径 brush.CreateSolidBrush (App_Veriable::DefaultSiteSeletedModeColor); else brush.CreateSolidBrush (Color); pDC->SelectObject(brush); if(Style=='C') { /*CRgn c; c.CreateEllipticRgn(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.x+Size/2); pDC->FillRgn (&c,&brush); c.DeleteObject();*/ pDC->Ellipse(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2);//效果更好??? } if(Style=='T') { CPoint points[3]; points[0].x=Position.x; points[0].y=Position.y-sqrt(3.0)*Size/3; points[1].x=Position.x-Size/2; points[1].y=Position.y+sqrt(3.0)*Size/6; points[2].x=Position.x+Size/2; points[2].y=Position.y+sqrt(3.0)*Size/6; CRgn c; c.CreatePolygonRgn (points,3,WINDING); pDC->FillRgn (&c,&brush); c.DeleteObject(); } if(Style=='R') { CRgn c; c.CreateRectRgn (Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.y+Size/2); pDC->FillRgn (&c,&brush); c.DeleteObject(); /*pDC->Rectangle(Position.x-Size/2,Position.y-Size/2,Position.x+Size/2,Position.x+Size/2);*///不能用,好奇怪??? } if(this->SiteInfo!=App_Veriable::DefaultSiteInfo&&App_Veriable::ShowSiteInfo) pDC->TextOutW(this->Position.x,this->Position.y,this->SiteInfo); brush.DeleteObject(); } }
void COXTabViewContainer::DrawButton(CDC* pDC, CRect rect, HITTEST nButtonType) const { ASSERT_VALID(pDC); pDC->FillSolidRect(rect,::GetSysColor(COLOR_BTNFACE)); COLORREF clrTopLeft; COLORREF clrBottomRight; if(m_nPressedScrlBtn==nButtonType) { CPoint point; ::GetCursorPos(&point); ScreenToClient(&point); if(rect.PtInRect(point)) { clrBottomRight=::GetSysColor(COLOR_BTNFACE); clrTopLeft=::GetSysColor(COLOR_BTNFACE); rect.OffsetRect(1,1); } else { clrTopLeft=::GetSysColor(COLOR_BTNHILIGHT); clrBottomRight=::GetSysColor(COLOR_BTNSHADOW); } } else { clrTopLeft=::GetSysColor(COLOR_BTNHILIGHT); clrBottomRight=::GetSysColor(COLOR_BTNSHADOW); } pDC->Draw3dRect(rect,clrTopLeft,clrBottomRight); // draw arrows // rect.DeflateRect(2,2); CRect rectCopy=rect; POINT arrPoints[3]; CRgn rgn; CBrush brush; brush.CreateSolidBrush(::GetSysColor(COLOR_WINDOWTEXT)); switch(nButtonType) { // start case SCRLSTARTBTN: rectCopy.DeflateRect(rectCopy.Width()/4,rectCopy.Height()/6); rectCopy.left+=rectCopy.Width()/4-2; if(rectCopy.Height()%2==0) rectCopy.bottom+=1; rectCopy.right=rectCopy.left+2; pDC->FillSolidRect(rectCopy,::GetSysColor(COLOR_WINDOWTEXT)); // backward case SCRLBACKWARDBTN: rectCopy=rect; rectCopy.DeflateRect(rectCopy.Width()/4,rectCopy.Height()/6); if(nButtonType==SCRLSTARTBTN) rectCopy.left+=rectCopy.Width()/4; else rectCopy.right-=rectCopy.Width()/4; if(rectCopy.Height()%2==0) rectCopy.bottom++; arrPoints[0].x=rectCopy.right; arrPoints[0].y=rectCopy.top-1; arrPoints[1].x=rectCopy.right; arrPoints[1].y=rectCopy.bottom; arrPoints[2].x=rectCopy.left; arrPoints[2].y=rectCopy.top+rectCopy.Height()/2; rgn.CreatePolygonRgn(arrPoints,3,WINDING); pDC->FillRgn(&rgn,&brush); break; // end case SCRLENDBTN: rectCopy.DeflateRect(rectCopy.Width()/4,rectCopy.Height()/6); rectCopy.right-=rectCopy.Width()/4-2; if(rectCopy.Height()%2==0) rectCopy.bottom+=1; rectCopy.left=rectCopy.right-2; pDC->FillSolidRect(rectCopy,::GetSysColor(COLOR_WINDOWTEXT)); // forward case SCRLFORWARDBTN: rectCopy=rect; rectCopy.DeflateRect(rectCopy.Width()/4,rectCopy.Height()/6); if(nButtonType==SCRLENDBTN) rectCopy.right-=rectCopy.Width()/4; else rectCopy.left+=rectCopy.Width()/4; if(rectCopy.Height()%2==0) rectCopy.bottom++; arrPoints[0].x=rectCopy.right; arrPoints[0].y=rectCopy.top+rectCopy.Height()/2; arrPoints[1].x=rectCopy.left; arrPoints[1].y=rectCopy.top-1; arrPoints[2].x=rectCopy.left; arrPoints[2].y=rectCopy.bottom; rgn.CreatePolygonRgn(arrPoints,3,WINDING); pDC->FillRgn(&rgn,&brush); break; default: ASSERT(FALSE); } }
// this routine calculates the size and position of the window relative // to it's anchor point, and moves the window accordingly. The region is also // created and set here. void CBalloonHelp::PositionWindow() { CSize sizeWnd = CalcWindowSize(); CPoint ptTail[3]; CPoint ptTopLeft(0,0); CPoint ptBottomRight(sizeWnd.cx, sizeWnd.cy); // force recalculation of desktop m_screenRect.SetRectEmpty(); switch (GetBalloonQuadrant()) { case BQ_TOPLEFT: ptTopLeft.y = nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4 + nTIP_TAIL; ptTail[0].y = nTIP_TAIL+1; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = 1; break; case BQ_TOPRIGHT: ptTopLeft.y = nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4*3; ptTail[0].y = nTIP_TAIL+1; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4*3 + nTIP_TAIL; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = 1; break; case BQ_BOTTOMLEFT: ptBottomRight.y = sizeWnd.cy-nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4 + nTIP_TAIL; ptTail[0].y = sizeWnd.cy-nTIP_TAIL-2; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = sizeWnd.cy-2; break; case BQ_BOTTOMRIGHT: ptBottomRight.y = sizeWnd.cy-nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4*3; ptTail[0].y = sizeWnd.cy-nTIP_TAIL-2; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4*3 + nTIP_TAIL; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = sizeWnd.cy-2; break; default: ASSERT(FALSE); } // adjust for very narrow balloons if ( ptTail[0].x < nTIP_MARGIN ) ptTail[0].x = nTIP_MARGIN; if ( ptTail[0].x > sizeWnd.cx - nTIP_MARGIN ) ptTail[0].x = sizeWnd.cx - nTIP_MARGIN; if ( ptTail[1].x < nTIP_MARGIN ) ptTail[1].x = nTIP_MARGIN; if ( ptTail[1].x > sizeWnd.cx - nTIP_MARGIN ) ptTail[1].x = sizeWnd.cx - nTIP_MARGIN; if ( ptTail[2].x < nTIP_MARGIN ) ptTail[2].x = nTIP_MARGIN; if ( ptTail[2].x > sizeWnd.cx - nTIP_MARGIN ) ptTail[2].x = sizeWnd.cx - nTIP_MARGIN; // get window position CPoint ptAnchor = GetAnchorPoint(); CPoint ptOffs(ptAnchor.x - ptTail[1].x, ptAnchor.y - ptTail[1].y); // adjust position so all is visible CRect rectScreen; GetAnchorScreenBounds(rectScreen); int nAdjustX = 0; int nAdjustY = 0; if ( ptOffs.x < rectScreen.left ) nAdjustX = rectScreen.left-ptOffs.x; else if ( ptOffs.x + sizeWnd.cx >= rectScreen.right ) nAdjustX = rectScreen.right - (ptOffs.x + sizeWnd.cx); if ( ptOffs.y + nTIP_TAIL < rectScreen.top ) nAdjustY = rectScreen.top - (ptOffs.y + nTIP_TAIL); else if ( ptOffs.y + sizeWnd.cy - nTIP_TAIL >= rectScreen.bottom ) nAdjustY = rectScreen.bottom - (ptOffs.y + sizeWnd.cy - nTIP_TAIL); // reposition tail // uncomment two commented lines below to move entire tail // instead of just anchor point //ptTail[0].x -= nAdjustX; ptTail[1].x -= nAdjustX; //ptTail[2].x -= nAdjustX; ptOffs.x += nAdjustX; ptOffs.y += nAdjustY; // place window MoveWindow(ptOffs.x, ptOffs.y, sizeWnd.cx, sizeWnd.cy, TRUE); // apply region CRgn region; CRgn regionRound; CRgn regionComplete; region.CreatePolygonRgn(&ptTail[0], 3, ALTERNATE); regionRound.CreateRoundRectRgn(ptTopLeft.x,ptTopLeft.y,ptBottomRight.x,ptBottomRight.y,nTIP_MARGIN*3,nTIP_MARGIN*3); regionComplete.CreateRectRgn(0,0,1,1); regionComplete.CombineRgn(®ion, ®ionRound, RGN_OR); if ( NULL == m_rgnComplete.m_hObject ) m_rgnComplete.CreateRectRgn(0,0,1,1); if ( !m_rgnComplete.EqualRgn(®ionComplete) ) { m_rgnComplete.CopyRgn(®ionComplete); SetWindowRgn((HRGN)regionComplete.Detach(), TRUE); // There is a bug with layered windows and NC changes in Win2k // As a workaround, redraw the entire window if the NC area changed. // Changing the anchor point is the ONLY thing that will change the // position of the client area relative to the window during normal // operation. RedrawWindow(NULL, NULL, RDW_UPDATENOW| RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } }