//畫圈 void MsrFlow::DrawACircle(CPoint point) { /* 在此畫出來的圈是以160*160大小 以中心點為參考點畫出來的 原函數是以左上角為參考點,在此修正誤差,將決定好的參考點 再往左往上各算一個半徑的距離,畫出來 */ //設定圈圈顏色=與背景相反顏色 COLORREF CircleColor; CircleColor = RGB(255,255,255)-BackGroundColor; //設定畫圈目標物位址 CWnd* pWndGrid = GetDlgItem(IDC_COLOR_PATTERN); CDC* pDC = pWndGrid->GetDC(); //設定畫筆 CPen aPen; aPen.CreatePen(PS_INSIDEFRAME,5,CircleColor); //設定暫存畫筆空間 CPen* pOldPen = pDC ->SelectObject(&aPen); //對圓修正誤差,從左上調到中心(開方形可繪區塊) CPoint StartDrawPoint(-80,-80); CPoint EndDrawPoint(80,80); CRect* pRect = new CRect(point+StartDrawPoint,point+EndDrawPoint); //畫下去(畫下圓形,起點0,0,終點0,0) CPoint Start(0,0); CPoint End(0,0); pDC->Arc(pRect,Start,End); //畫筆換回預設值 pDC->SelectObject(pOldPen); }
void CUnit::OnShowSelectedLine(){ //畫圓圈 CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC CPen penBlack; CPen penWhite; CPen* pOldPen; penBlack.CreatePen(PS_SOLID,1,RGB(0,0,0)); penWhite.CreatePen(PS_SOLID,1,RGB(255,255,255)); pOldPen = pDC->SelectObject(&penBlack); CRect rect; CPoint screenPoint(CConvert::GetScreenPointByMapPoint(mapPoint)); rect.SetRect( screenPoint.x-bmp->Width()/2-10, screenPoint.y-25, screenPoint.x+bmp->Width()/2+10, screenPoint.y+5); pDC->Arc(rect,rect.TopLeft(),rect.TopLeft()); rect.MoveToY(rect.top+1); pDC->SelectObject(&penWhite); pDC->Arc(rect,rect.TopLeft(),rect.TopLeft()); pDC->SelectObject(pOldPen); // CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC }
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(); } }