void CAngleLabel::DrawHotShape(Graphics& graph) { SolidBrush sbrush(Color::White); Pen penDraw(Color::Blue, 3); PointF ptLT; ptLT.X = m_ptary[0].X - m_nWidth; ptLT.Y = m_ptary[0].Y - m_nWidth; Rect rect((int)ptLT.X, (int)ptLT.Y, m_nWidth * 2, m_nWidth * 2); graph.DrawEllipse(&penDraw, rect); graph.FillEllipse(&sbrush, rect); ptLT.X = m_ptary[1].X - m_nWidth; ptLT.Y = m_ptary[1].Y - m_nWidth; rect.X = (int)ptLT.X; rect.Y = (int)ptLT.Y; rect.Width = m_nWidth * 2; rect.Height = m_nWidth * 2; graph.DrawEllipse(&penDraw, rect); graph.FillEllipse(&sbrush, rect); ptLT.X = m_ptary[2].X - m_nWidth; ptLT.Y = m_ptary[2].Y - m_nWidth; rect.X = (int)ptLT.X; rect.Y = (int)ptLT.Y; rect.Width = m_nWidth * 2; rect.Height = m_nWidth * 2; graph.DrawEllipse(&penDraw, rect); graph.FillEllipse(&sbrush, rect); }
void CCircleView::Draw(CDC* pDC, const std::vector<CElement*>& selection, CElement* highlight) { Color theColor = ColorToDraw(selection, highlight); Graphics g = pDC->GetSafeHdc(); Pen pen(theColor, penWidth); SolidBrush brush(fillColor); g.SetSmoothingMode(SmoothingModeAntiAlias); g.FillEllipse(&brush, *enclosingRect); g.DrawEllipse(&pen, *enclosingRect); }
void UIButton::onPaintFrame(Graphics& graphics, Rect rect) { Pen pen(m_button.m_frameColor, m_button.m_frameWidth); switch (m_buttonType) { case UITYPE_BUTTON_RECTANGLE: graphics.DrawRectangle(&pen, rect); break; case UITYPE_BUTTON_CIRCLE: graphics.DrawEllipse(&pen, rect); break; default: break; } }
// #define DrawPolygonMacro void drawBezierSmoothPoly(HDC hdc, AlpointsList &points, float f, COLORREF color) { if(points.count()<3) return; GdiPlusIniter ginit; Graphics *graphics = Graphics::FromHDC(hdc); graphics->SetSmoothingMode(SmoothingModeHighQuality); graphics->SetCompositingMode(CompositingModeSourceOver); Pen pen(Color::Red); pen.SetLineJoin(LineJoinRound); pen.SetLineCap(LineCapRound,LineCapRound, DashCapRound); // 绘制多边形 #if defined(DrawPolygonMacro) pen.SetColor(Color::Blue); pen.SetDashStyle(DashStyleDash); for(int i=0; i<points.count() - 1; i++){ Point p1(points[i+0].x, -points[i+0].y); Point p2(points[i+1].x, -points[i+1].y); graphics->DrawLine(&pen, p1, p2 ); } #endif #if defined(ThroghtEveryPoint) ALPoint b, e, n, c1, c2, c3; int last = 0; for(int i=0; i<points.count()-1; i++){ if( distance(points[last], points[i+1])<4 ){ continue; } b = points[last]; e = points[i+1]; n = points[i+2]; c1 = last==0? points[0]:c3; c2 = cubicBezierControlPoint(b, e, n, &c3, f); { // 绘制控制点!!! #if 0 pen.SetDashStyle(DashStyleDot); pen.SetColor(Color::Green); Point p1(c2.x, -c2.y); Point p2(c3.x, -c3.y); graphics->DrawEllipse(&pen, p1.X-1, p1.Y-1,2,2); graphics->DrawEllipse(&pen, p2.X-1, p2.Y-1,2,2); graphics->DrawLine(&pen, p1, p2); #endif } pen.SetDashStyle(DashStyleSolid); pen.SetColor(Color::Red); Point p1(b.x, -b.y); Point p2(c1.x, -c1.y); Point p3(c2.x, -c2.y); Point p4(e.x, -e.y); graphics->DrawBezier(&pen, p1,p2,p3,p4); last = i+1; } #else // 使用顶点作为控制点!!!!! pen.SetColor(Color::Red); pen.SetDashStyle(DashStyleSolid); int last = 0; float bx,by,cx,cy,ex,ey; for(int i=0; i<points.count(); i++){ bx = i==0?points[0].x:ex; by = i==0?points[0].y:ey; ex = (points[i+1].x + points[i+2].x)/2; ey = (points[i+1].y + points[i+2].y)/2; cx = points[i+1].x; cy = points[i+1].y; // b(t) = (1-t)^2*p0 + 2t(1-t)*p1 + t^2*p2 float x0 = bx, y0 = -by; for(float t=0.02; t<=1.0; t+=0.02){ float x1 = square(1-t)*bx + 2*t*(1-t)*cx + square(t)*ex; float y1 = square(1-t)*by + 2*t*(1-t)*cy + square(t)*ey; y1 = -y1; graphics->DrawLine(&pen,x0, y0,x1,y1); x0 = x1; y0 = y1; } } #endif }