int Window::drawLine(HDC hdc, int oy, std::wstring string, TextFont* fnt) { using namespace Gdiplus; int x = (showed ? 0 : leftMargin) - 5; int y = (showed ? 0 : topMargin) + oy; const wchar_t* text = string.c_str(); if (fnt == 0) fnt = font; Graphics graphics(hdc); graphics.SetSmoothingMode(SmoothingModeAntiAlias); FontFamily fontFamily; fnt->GetFamily(&fontFamily); RectF boundRect = fnt->getTextBounds(hdc, clientRect, text); x += ((clientRect.right - clientRect.left) - (int)(boundRect.GetRight() - boundRect.GetLeft()) - 2) / 2; y -= ((int)boundRect.GetBottom()) + 5; StringFormat strformat; GraphicsPath path; path.AddString(text, wcslen(text), &fontFamily, fnt->GetStyle(), graphics.GetDpiY() * fnt->GetSize() / 72, Gdiplus::Point(x, y), &strformat ); // Outline color + size Pen pen(Color(0, 0, 0), fnt->GetSize()/7); pen.SetLineJoin(LineJoinRound); graphics.DrawPath(&pen, &path); // Text color SolidBrush brush(Color(254, 254, 254)); graphics.FillPath(&brush, &path); Rect bounds; path.GetBounds(&bounds, 0, &pen); return (int)boundRect.GetBottom(); }
void CAngleLabel::SetRegion() { PointF* pPt = m_ptary.GetData(); PointF ptd[3]; ptd[0] = pPt[1]; ptd[1] = pPt[0]; ptd[2] = pPt[2]; Pen penDraw(Color(255, 0, 255, 0)); penDraw.SetDashStyle(m_nDashStyle); penDraw.SetWidth((float)m_nWidth); GraphicsPath path; path.AddLines(ptd, m_nPtCount); path.Widen(&penDraw); path.Outline(); m_Region.MakeEmpty(); m_Region.Union(&path); }
bool DiffusedShadowStrategy::DrawString( Gdiplus::Graphics* pGraphics, Gdiplus::FontFamily* pFontFamily, Gdiplus::FontStyle fontStyle, int nfontSize, const wchar_t*pszText, Gdiplus::Rect rtDraw, Gdiplus::StringFormat* pStrFormat) { using namespace Gdiplus; GraphicsPath path; Status status = path.AddString(pszText,wcslen(pszText),pFontFamily,fontStyle,nfontSize,rtDraw,pStrFormat); if(status!=Ok) return false; for(int i=1; i<=m_nThickness; ++i) { Pen pen(m_clrOutline,i); pen.SetLineJoin(LineJoinRound); pGraphics->DrawPath(&pen, &path); } Status status2 = Ok; if(m_bOutlinetext==false) { for(int i=1; i<=m_nThickness; ++i) { SolidBrush brush(m_clrText); status2 = pGraphics->FillPath(&brush, &path); } } else { SolidBrush brush(m_clrText); status2 = pGraphics->FillPath(&brush, &path); } return status2 == Ok; }
void CMyDlg::OnPaint() { CPaintDC dc(this); CRect rcClient; GetClientRect(&rcClient); Graphics graphics(dc); if (version&&bIsAero) graphics.Clear(Color.Black); else graphics.Clear(Color.White); Bitmap CacheImage(rcClient.Width(),rcClient.Height()); Graphics buffer(&CacheImage); buffer.SetSmoothingMode(SmoothingModeAntiAlias); buffer.SetInterpolationMode(InterpolationModeHighQualityBicubic); Image *logo; Image *button; ImageFromIDResource(2,"png",logo); ImageFromIDResource(1,"png",button); buffer.DrawImage(logo, -5,20); buffer.DrawImage(button, 165,122); buffer.DrawImage(button, 350,122); FontFamily fontFamily(version?L"微软雅黑":L"宋体"); StringFormat strformat; wchar_t pszbuf[512]; wsprintfW(pszbuf,L"本程序适用于 迅雷5.9 系列\n如果本软件有错,我概不负责,但我会尽力解决。\n只有极少数时候需要您指定安装目录(比如非官方版)。\n如果会员补丁失效,重新破解即可。\n\n\n请选择: 一键增强 %s取消增强\n\n2010年4月7日更新 www.shuax.com",version?L" ":L" "); GraphicsPath path; path.AddString(pszbuf, wcslen(pszbuf), &fontFamily, FontStyleRegular, version?15:16, Gdiplus::Point(version?90:80,version?9:20), &strformat ); Pen pen(Color(18, 255, 255, 255), 3.0); //pen.SetLineJoin(LineJoinRound); buffer.DrawPath(&pen, &path); SolidBrush brush(Color(0,0,0)); buffer.FillPath(&brush, &path); graphics.DrawImage(&CacheImage, 0, 0); graphics.ReleaseHDC(dc); }
bool TextDblOutlineStrategy::MeasureString( Gdiplus::Graphics* pGraphics, Gdiplus::FontFamily* pFontFamily, Gdiplus::FontStyle fontStyle, int nfontSize, const wchar_t*pszText, Gdiplus::Rect rtDraw, Gdiplus::StringFormat* pStrFormat, float* pfPixelsStartX, float* pfPixelsStartY, float* pfDestWidth, float* pfDestHeight ) { using namespace Gdiplus; GraphicsPath path; Status status = path.AddString(pszText,wcslen(pszText),pFontFamily,fontStyle,nfontSize,rtDraw,pStrFormat); if(status!=Ok) return false; *pfDestWidth= rtDraw.GetLeft(); *pfDestHeight= rtDraw.GetTop(); bool b = GDIPath::MeasureGraphicsPath(pGraphics, &path, pfPixelsStartX, pfPixelsStartY, pfDestWidth, pfDestHeight); if(false==b) return false; float pixelThick = 0.0f; b = GDIPath::ConvertToPixels(pGraphics,m_nThickness1+m_nThickness2,0.0f,NULL,NULL,&pixelThick,NULL); if(false==b) return false; *pfDestWidth += pixelThick; *pfDestHeight += pixelThick; return true; }
void CNormalPen::SetRegion() { PointF* pPt = m_ptary.GetData(); int nWidth = m_nWidth; if(m_nWidth < 3) { nWidth = 3; } Pen penDraw(m_crColor,(float)nWidth); penDraw.SetDashStyle(m_nDashStyle); penDraw.SetStartCap(m_nStartCap); penDraw.SetEndCap(m_nEndCap); penDraw.SetLineJoin(LineJoinRound); GraphicsPath path; path.AddCurve(pPt,m_nPtCount); path.Widen(&penDraw); path.Outline(); m_Region.MakeEmpty(); m_Region.Union(&path); }
void CRectangle::SetRegion() { float left = min(m_ptary[0].X,m_ptary[1].X); float top = min(m_ptary[0].Y,m_ptary[1].Y); float width = fabs(m_ptary[0].X - m_ptary[1].X); float height = fabs(m_ptary[0].Y - m_ptary[1].Y); /*PointF* pPt = m_ptary.GetData();*/ int nWidth = m_nWidth; if(m_nWidth < 6) { nWidth = 6; } Pen greenPen(Color(255, 0, 255, 0), (float)nWidth); GraphicsPath path; if(RS_ROUND == m_nRStyle) { CRect rc((int)left,(int)top,(int)(left + width),(int)(top + height)); INT offsetX = (rc.right - rc.left) * 20/100; INT offsetY = (rc.bottom - rc.top) * 20/100; path.AddArc(rc.right - offsetX, rc.top, offsetX, offsetY, 270, 90); path.AddArc(rc.right - offsetX, rc.bottom - offsetY, offsetX, offsetY, 0, 90); path.AddArc(rc.left, rc.bottom - offsetY, offsetX, offsetY, 90, 90); path.AddArc(rc.left, rc.top, offsetX, offsetY, 180, 90); path.AddLine(rc.left + offsetX, rc.top, rc.right - offsetX/2, rc.top); } else { RectF rcf(left,top,width,height); path.AddRectangle(rcf); } path.Widen(&greenPen); path.Outline(); m_Region.MakeEmpty(); m_Region.Union(&path); }
void CRevisionGraphWnd::DrawRoundedRect (GraphicsDevice& graphics, const Color& penColor, int penWidth, const Pen* pen, const Color& fillColor, const Brush* brush, const RectF& rect, int mask) { enum {POINT_COUNT = 8}; float radius = CORNER_SIZE * m_fZoomFactor; PointF points[POINT_COUNT]; CutawayPoints (rect, radius, points); if (graphics.graphics) { GraphicsPath path; if(mask & ROUND_UP) { path.AddArc (points[0].X, points[1].Y, radius, radius, 180, 90); path.AddArc (points[2].X, points[2].Y, radius, radius, 270, 90); }else { path.AddLine(points[0].X, points[1].Y, points[3].X, points[2].Y); } if(mask & ROUND_DOWN) { path.AddArc (points[5].X, points[4].Y, radius, radius, 0, 90); path.AddArc (points[7].X, points[7].Y, radius, radius, 90, 90); }else { path.AddLine(points[3].X, points[3].Y, points[4].X, points[5].Y); path.AddLine(points[4].X, points[5].Y, points[7].X, points[6].Y); } points[0].Y -= radius / 2; path.AddLine (points[7], points[0]); if (brush != NULL) { graphics.graphics->FillPath (brush, &path); } if (pen != NULL) graphics.graphics->DrawPath (pen, &path); } else if (graphics.pSVG) { graphics.pSVG->RoundedRectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height, penColor, penWidth, fillColor, (int)radius, mask); } }
void CQTTDemoView::MakeSmiley(GraphicsPath& path) { path.Reset(); path.AddEllipse(200, 350, 400, 400); Rect rcEye(330, 520, 10, 10); path.AddEllipse(rcEye); rcEye.Offset(140, 0); path.AddEllipse(rcEye); Rect rcMouth(370, 590, 60, 60); path.AddArc(rcMouth, 0.0f, 180.0f); path.CloseFigure(); }
GraphicsPath *GraphicsPathFromPathData(const char *s) { VecSegmented<SvgPathInstr> instr; if (!ParseSvgPathData(s, instr)) return nullptr; GraphicsPath *gp = ::new GraphicsPath(); PointF prevEnd(0.f, 0.f); for (SvgPathInstr& i : instr) { PathInstrType type = i.type; // convert relative coordinates to absolute based on end position of // previous element // TODO: support the rest of instructions if (MoveRel == type) { RelPointToAbs(prevEnd, i.v); type = MoveAbs; } else if (LineToRel == type) { RelPointToAbs(prevEnd, i.v); type = LineToAbs; } else if (HLineRel == type) { RelXToAbs(prevEnd, i.v); type = HLineAbs; } else if (VLineRel == type) { RelYToAbs(prevEnd, i.v); type = VLineAbs; } if (MoveAbs == type) { PointF p(i.v[0], i.v[1]); prevEnd = p; gp->StartFigure(); } else if (LineToAbs == type) { PointF p(i.v[0], i.v[1]); gp->AddLine(prevEnd, p); prevEnd = p; } else if (HLineAbs == type) { PointF p(prevEnd); p.X = i.v[0]; gp->AddLine(prevEnd, p); prevEnd = p; } else if (VLineAbs == type) { PointF p(prevEnd); p.Y = i.v[0]; gp->AddLine(prevEnd, p); prevEnd = p; } else if ((Close == type) || (Close2 == type)) { gp->CloseFigure(); } else { CrashIf(true); } } return gp; }
TEST(GraphicsPathTest, transform) { GraphicsPath<double> path; path.moveto(0,0); path.lineto(1,0); path.lineto(1,1); path.lineto(0,1); path.closepath(); Matrix m(1); m.scale(2,2); m.translate(10, 100); m.rotate(90); path.transform(m); ostringstream oss; path.writeSVG(oss, false); EXPECT_EQ(oss.str(), "M-100 10V12H-102V10Z"); }
void DrawRoundedRectangle(Gdiplus::Graphics* gr, Gdiplus::Rect r, int d, Gdiplus::Pen* p, Gdiplus::Brush*br){ using namespace Gdiplus; GraphicsPath gp; // d = min(min(d, r.Width),r.Height); gp.AddArc(r.X, r.Y, d, d, 180, 90); gp.AddArc(max(r.X + r.Width - d,r.X), r.Y, d, d, 270, 90); gp.AddArc(max(r.X, r.X + r.Width - d), max(r.Y, r.Y + r.Height - d), d, d, 0, 90); gp.AddArc(r.X, max(r.Y, r.Y + r.Height - d), d, d, 90, 90); gp.AddLine(r.X, max(r.Y, r.Y + r.Height - d), r.X, min(r.Y + d/2, r.GetBottom())); gp.CloseFigure(); if ( br ) { gr->FillPath(br, &gp); } gr->DrawPath(p, &gp); }
void CRectangle::DrawRoundRect(Graphics& graph,CRect rc) { Pen penDraw(m_crColor,(float)m_nWidth); INT offsetX = (rc.right - rc.left) * 20/100; INT offsetY = (rc.bottom - rc.top) * 20/100; GraphicsPath pt; pt.AddArc(rc.right - offsetX, rc.top, offsetX, offsetY, 270, 90); pt.AddArc(rc.right - offsetX, rc.bottom - offsetY, offsetX, offsetY, 0, 90); pt.AddArc(rc.left, rc.bottom - offsetY, offsetX, offsetY, 90, 90); pt.AddArc(rc.left, rc.top, offsetX, offsetY, 180, 90); pt.AddLine(rc.left + offsetX, rc.top, rc.right - offsetX/2, rc.top); graph.DrawPath(&penDraw,&pt); }
GraphicsPath* GdipCreateRoundRect( Rect& rect, int nRadius ) { GraphicsPath roundRect; int nDiameter = nRadius << 1; Rect arcRect( 0, 0, nDiameter, nDiameter ); arcRect.X = rect.GetLeft(); arcRect.Y = rect.GetTop(); roundRect.AddArc(arcRect, 180, 90); arcRect.X = rect.GetRight() - nDiameter; roundRect.AddArc(arcRect, 270, 90); arcRect.Y = rect.GetBottom() - nDiameter; roundRect.AddArc(arcRect, 0, 90); arcRect.X = rect.GetLeft(); roundRect.AddArc(arcRect, 90, 90); roundRect.CloseFigure(); return roundRect.Clone(); }
GraphicsPath* GdipCreateRoundRect( RectF& rect, int nRadius ) { GraphicsPath roundRect; float fDiameter = nRadius * 2.f; RectF arcRect( 0.f, 0.f, fDiameter, fDiameter ); arcRect.X = rect.GetLeft(); arcRect.Y = rect.GetTop(); roundRect.AddArc(arcRect, 180, 90); arcRect.X = rect.GetRight() - fDiameter; roundRect.AddArc(arcRect, 270, 90); arcRect.Y = rect.GetBottom() - fDiameter; roundRect.AddArc(arcRect, 0, 90); arcRect.X = rect.GetLeft(); roundRect.AddArc(arcRect, 90, 90); roundRect.CloseFigure(); return roundRect.Clone(); }
void FillCylinder(Graphics* pGfx, RectF rcClient, Brush* pFillBrush, Color cOutlineColor) { RectF rTopPlane(rcClient.X, rcClient.Y - 5, rcClient.Width, 5); RectF rBottomPlane(rcClient.X, rcClient.GetBottom() - 5, rcClient.Width, 5); // Outline pen Pen penOutline(cOutlineColor); // Draw body GraphicsPath gfxPath; gfxPath.AddArc(rTopPlane, 0, 180); gfxPath.AddArc(rBottomPlane, 180, -180); gfxPath.CloseFigure(); // Fill body pGfx->FillPath(pFillBrush, &gfxPath); // Outline body pGfx->DrawPath(&penOutline, &gfxPath); // Draw top plane gfxPath.Reset(); gfxPath.AddEllipse(rTopPlane); // Fill top plane pGfx->FillPath(pFillBrush, &gfxPath); // Outline top plane pGfx->DrawPath(&penOutline, &gfxPath); }
void CLMenu::DrawItem(CLMenuItem *item) { CRect r = ItemRect(item); item->dib->Resize(r.Width(), r.Height()); if(!item->dib->Ready()) { return; } Graphics g(item->dib->bmp); g.SetSmoothingMode(SmoothingModeNone); g.SetCompositingMode(CompositingModeSourceCopy); RectF rf(0, 0, (REAL)item->dib->Width(), (REAL)item->dib->Height()); SolidBrush brush(Color(255 * BCKG_OPACITY / 100, 0x10, 0x10, 0x10)); g.FillRectangle(&brush, rf); g.SetCompositingMode(CompositingModeSourceOver); if(item->selected) { //LinearGradientBrush brush(rf, 0xff6fa6de, 0xff1e6cbb, LinearGradientModeVertical); //g.FillRectangle(&brush, rf); RectF rx = rf; rx.Height /= 2; //rx.X++; //rx.Width -= 2; LinearGradientBrush brush(rx, 0xff5b9de1, 0xff3d7ebf, LinearGradientModeVertical); g.FillRectangle(&brush, rx); rx.Y += rx.Height; brush.SetLinearColors(0xff3076bc, 0xff4988c8); g.FillRectangle(&brush, rx); Pen pen(0xff3d7ebf); g.DrawLine(&pen, rx.X /*+ 1*/, rx.Y, rx.X + rx.Width /*- 1*/, rx.Y); } g.SetSmoothingMode(SmoothingModeAntiAlias); if(item->isLine) { Pen pen(0xff909090); g.DrawLine(&pen, rf.X + 2, rf.Y + rf.Height / 2, rf.X + rf.Width - 3, rf.Y + rf.Height / 2); } else { rf.X += 4; rf.Width -= 14; if(item->icon->Ready()) { RectF ri = rf; ri.Width = rf.Height * 0.9f; ri.Height = ri.Width; ri.Y += (rf.Height - ri.Height) / 2; rf.X += rf.Height; rf.Width -= rf.Height; float k = min(ri.Width / item->icon->Width(), ri.Height / item->icon->Height()); g.SetInterpolationMode(InterpolationModeHighQualityBicubic); ri.X += (ri.Width - item->icon->Width() * k) / 2; ri.Y += (ri.Height - item->icon->Height() * k) / 2; ri.Width = item->icon->Width() * k; ri.Height = item->icon->Height() * k; g.DrawImage(item->icon->bmp, ri); } RectF rc = rf; rc.Width = rf.Height * 0.42f; rc.Height = rc.Width; rc.Y += (rf.Height - rc.Height) / 2; if(item->checkbox) { if(item->checked) { Pen pen(0xffffffff); SolidBrush brush(0xffffffff); if(!item->enabled) { pen.SetColor(0xffb0b0b0); brush.SetColor(0xffb0b0b0); } GraphicsPath *path = new GraphicsPath(); path->AddLine(rc.X + rc.Width * 0.4f, rc.Y + rc.Height, rc.X + rc.Width * 0.9f, rc.Y); path->AddLine(rc.X + rc.Width * 0.9f, rc.Y, rc.X + rc.Width * 0.4f, rc.Y + rc.Height * 0.8f); path->AddLine(rc.X + rc.Width * 0.4f, rc.Y + rc.Height * 0.8f, rc.X, rc.Y + rc.Height * 0.6f); path->CloseFigure(); g.FillPath(&brush, path); g.DrawPath(&pen, path); delete path; } } if(!item->icon->Ready()) { rf.X += (rc.Height + 2); rf.Width -= (rc.Height + 2); } SolidBrush brush(0xff000000); Font font(L"Arial", FONT_SIZE); StringFormat *stringFormat = new StringFormat(); stringFormat->SetAlignment(StringAlignmentNear); stringFormat->SetLineAlignment(StringAlignmentCenter); stringFormat->SetTrimming(StringTrimmingEllipsisCharacter); stringFormat->SetFormatFlags(StringFormatFlagsLineLimit); //rf.Y++; //g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rf, stringFormat, &brush); brush.SetColor(0xffffffff); if(!item->enabled) { brush.SetColor(0xffb0b0b0); } //rf.Y--; g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rf, stringFormat, &brush); if(item->menu->ItemCount(TRUE)) { GraphicsPath *path = new GraphicsPath(); path->AddLine((REAL)(item->dib->Width() - 12), (REAL)(item->dib->Height() * 0.33), (REAL)(item->dib->Width() - 6), (REAL)(item->dib->Height() * 0.5)); path->AddLine((REAL)(item->dib->Width() - 6), (REAL)(item->dib->Height() * 0.5), (REAL)(item->dib->Width() - 12), (REAL)(item->dib->Height() * 0.67)); path->CloseFigure(); g.FillPath(&brush, path); delete path; } delete stringFormat; } }
/* ** Draws the meter on the double buffer ** */ bool CMeterLine::Draw(Graphics& graphics) { int maxSize = m_GraphHorizontalOrientation ? m_H : m_W; if (!CMeter::Draw(graphics) || maxSize <= 0) return false; double maxValue = 0.0; int counter = 0; // Find the maximum value if (m_Autoscale) { double newValue = 0; std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin(); counter = 0; for (; i != m_AllValues.end(); ++i) { double scale = m_ScaleValues[counter]; std::vector<double>::const_iterator j = (*i).begin(); for (; j != (*i).end(); ++j) { double val = (*j) * scale; newValue = max(newValue, val); } ++counter; } // Scale the value up to nearest power of 2 if (newValue > DBL_MAX / 2.0) { maxValue = DBL_MAX; } else { maxValue = 2.0; while (maxValue < newValue) { maxValue *= 2.0; } } } else { if (m_Measure) { maxValue = m_Measure->GetMaxValue(); std::vector<CMeasure*>::const_iterator i = m_Measures.begin(); for (; i != m_Measures.end(); ++i) { double val = (*i)->GetMaxValue(); maxValue = max(maxValue, val); } } if (maxValue == 0.0) { maxValue = 1.0; } } int x = GetX(); int y = GetY(); // Draw the horizontal lines if (m_HorizontalLines) { // Calc the max number of lines we should draw int maxLines = m_H / 4; // one line per 4 pixels is max int numOfLines; // Check the highest power of 2 that fits in maxLines int power = 2; while (power < maxLines) { power *= 2; } numOfLines = ((int)maxValue % power) + 1; Pen pen(m_HorizontalColor); REAL Y; for (int j = 0; j < numOfLines; ++j) { Y = (REAL)((j + 1) * m_H / (numOfLines + 1)); Y = y + m_H - Y - 1; graphics.DrawLine(&pen, (REAL)x, Y, (REAL)(x + m_W - 1), Y); // GDI+ } } // Draw all the lines if (m_GraphHorizontalOrientation) { const REAL W = m_W - 1.0f; counter = 0; std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin(); for (; i != m_AllValues.end(); ++i) { // Draw a line REAL X, oldX; const double scale = m_ScaleValues[counter] * W / maxValue; int pos = m_CurrentPos; oldX = (REAL)((*i)[pos] * scale); oldX = min(oldX, W); oldX = max(oldX, 0.0f); oldX = x + (m_GraphStartLeft ? oldX : W - oldX); // Cache all lines GraphicsPath path; if (!m_Flip) { for (int j = y + 1, R = y + m_H; j < R; ++j) { ++pos; if (pos >= m_H) pos = 0; X = (REAL)((*i)[pos] * scale); X = min(X, W); X = max(X, 0.0f); X = x + (m_GraphStartLeft ? X : W - X); path.AddLine(oldX, (REAL)(j - 1), X, (REAL)j); oldX = X; } } else { for (int j = y + m_H, R = y + 1; j > R; --j) { ++pos; if (pos >= m_H) pos = 0; X = (REAL)((*i)[pos] * scale); X = min(X, W); X = max(X, 0.0f); X = x + (m_GraphStartLeft ? X : W - X); path.AddLine(oldX, (REAL)(j - 1), X, (REAL)(j - 2)); oldX = X; } } // Draw cached lines Pen pen(m_Colors[counter], (REAL)m_LineWidth); pen.SetLineJoin(LineJoinBevel); graphics.DrawPath(&pen, &path); ++counter; } } else { const REAL H = m_H - 1.0f; counter = 0; std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin(); for (; i != m_AllValues.end(); ++i) { // Draw a line REAL Y, oldY; const double scale = m_ScaleValues[counter] * H / maxValue; int pos = m_CurrentPos; oldY = (REAL)((*i)[pos] * scale); oldY = min(oldY, H); oldY = max(oldY, 0.0f); oldY = y + (m_Flip ? oldY : H - oldY); // Cache all lines GraphicsPath path; if (!m_GraphStartLeft) { for (int j = x + 1, R = x + m_W; j < R; ++j) { ++pos; if (pos >= m_W) pos = 0; Y = (REAL)((*i)[pos] * scale); Y = min(Y, H); Y = max(Y, 0.0f); Y = y + (m_Flip ? Y : H - Y); path.AddLine((REAL)(j - 1), oldY, (REAL)j, Y); oldY = Y; } } else { for (int j = x + m_W, R = x + 1; j > R; --j) { ++pos; if (pos >= m_W) pos = 0; Y = (REAL)((*i)[pos] * scale); Y = min(Y, H); Y = max(Y, 0.0f); Y = y + (m_Flip ? Y : H - Y); path.AddLine((REAL)(j - 1), oldY, (REAL)(j - 2), Y); oldY = Y; } } // Draw cached lines Pen pen(m_Colors[counter], (REAL)m_LineWidth); pen.SetLineJoin(LineJoinBevel); graphics.DrawPath(&pen, &path); ++counter; } } return true; }
void CMyDialog::DrawCloseButton(CDC *pDC,int enumStatus) { Color clrStart,clrEnd,clrBorder,clrCloseMark; CRect rc; GetClientRect(rc); if (enumStatus==DTS_NORMAL) { clrStart=Color(231,231,231); clrEnd=Color(227,227,227); clrBorder=Color(158,158,158); clrCloseMark=Color(128,128,128); clrStart=Color(219,219,220); clrEnd=Color(190,192,193); } else if (enumStatus==DTS_HOVER) { clrStart=Color(245,28,6); clrEnd=Color(207,9,7); clrBorder=Color(187,5,0); clrCloseMark=Color(255,255,255); } else// if (enumStatus==DTS_CLICKED) { clrStart=Color(207,9,7); clrEnd=Color(245,28,6); clrBorder=Color(187,5,0); clrCloseMark=Color(255,255,255); } m_rcClose.SetRect(rc.right-36,1,rc.right-6,21); GraphicsPath path; int nRadius=4; Point point[5]; point[0]=Point(m_rcClose.right,m_rcClose.bottom-nRadius); point[1]=Point(m_rcClose.right,m_rcClose.top); point[2]=Point(m_rcClose.left,m_rcClose.top); point[3]=Point(m_rcClose.left,m_rcClose.bottom); point[4]=Point(m_rcClose.right-nRadius,m_rcClose.bottom); path.AddLines(point,5); path.AddArc(m_rcClose.right-2*nRadius,m_rcClose.bottom-2*nRadius,2*nRadius,2*nRadius,0,90); LinearGradientBrush linGrBrush( Rect(m_rcClose.left,m_rcClose.top,m_rcClose.Width(),m_rcClose.Height()), clrStart, clrEnd, LinearGradientModeVertical); Graphics gs(pDC->m_hDC); gs.FillPath(&linGrBrush,&path); CPoint ptCenter=m_rcClose.CenterPoint(); if (enumStatus==DTS_CLICKED) { ptCenter.Offset(1,1); } CPen penMark(PS_SOLID,2,clrCloseMark.ToCOLORREF()); CPen *pOldPen=pDC->SelectObject(&penMark); pDC->MoveTo(ptCenter.x-5,ptCenter.y-5); pDC->LineTo(ptCenter.x+5,ptCenter.y+5); pDC->MoveTo(ptCenter.x-5,ptCenter.y+5); pDC->LineTo(ptCenter.x+5,ptCenter.y-5); // CPen penBorder(PS_SOLID,1,clrBorder.ToCOLORREF()); // pDC->SelectObject(&penBorder); // pDC->MoveTo(m_rcClose.left-1,m_rcClose.top); // pDC->LineTo(m_rcClose.left-1,m_rcClose.bottom); pDC->SelectObject(pOldPen); }
unsigned int tabs_impl_win32::draw_tab(Graphics &g, unsigned int a_X, unsigned int a_Y, unsigned int a_Index){ if(a_X > get_size().m_Width) return a_X; Color c = Color(255, 44, 61, 91); if(m_ActiveTab == a_Index) c = Color(255, 255, 232, 166); else if(m_HoverTab == a_Index) c = Color(255, 100, 110, 117); SolidBrush b(c); SolidBrush t(m_ActiveTab == a_Index ? Color(255, 255, 248, 225) : c); SolidBrush black(Color(255, 0, 0, 0)); SolidBrush white(Color(255, 255, 255, 255)); SolidBrush closeDark(Color(255, 117, 99, 61)); SolidBrush closeLight(Color(255, 206, 212, 221)); Pen p(Color(255, 0, 0, 0)); Font font(L"Tahoma", 10); PointF origin(a_X + 5, a_Y + 3), originX(a_X + 10, a_Y + 5); RectF bb, close; std::string s = this->get_child_name(a_Index); std::wstring w(s.begin(), s.end()); // draw tab g.MeasureString(w.c_str(), w.size(), &font, origin, &bb); bb.Height = 25; originX.X += bb.Width + 5; close = RectF(originX.X, originX.Y, 15.f, 15.f); RectF::Union(bb, bb, close); GraphicsPath gp; // draw header int x = a_X; int y = a_Y; int headerHeight = get_size().m_Height / 2; int arcSize = 10; int width = bb.Width; // top part = arc gp.AddLine(x, y + headerHeight + arcSize / 2, x, y + arcSize / 2); gp.AddArc(x, y, arcSize, arcSize, 180.f, 90.f); gp.AddArc(x + width, y, arcSize, arcSize, 270.f, 90.f); gp.AddLine(x + width + arcSize, y + arcSize / 2, x + width + arcSize, y + headerHeight + arcSize / 2); g.FillPath(&t, &gp); bb.Width += arcSize; // bottom = rect g.FillRectangle(&b, a_X, a_Y + headerHeight, bb.Width, 10.f); g.DrawString(w.c_str(), w.size(), &font, origin, m_ActiveTab == a_Index ? &black : &white); // draw close button if(m_ActiveTab == a_Index || m_HoverTab == a_Index){ SolidBrush closeBrush(Color(190, 40, 30)); Pen hoverPen(Color::White, 2); Pen regularPen(Color(20, 20, 20), 2); Pen *p = ®ularPen; float shrink = 4; RectF lines = close; lines.X += shrink; lines.Y += shrink; lines.Width -= shrink * 2; lines.Height -= shrink * 2; // just get mouse position here instead of passing it through // from wm_mousemove POINT mouse; GetCursorPos(&mouse); ScreenToClient(m_hWndTabs, &mouse); if(close.Contains(mouse.x, mouse.y)) { g.FillEllipse(&closeBrush, close); p = &hoverPen; } g.DrawLine(p, lines.X, lines.Y, lines.X + lines.Width, lines.Y + lines.Height); g.DrawLine(p, lines.X + lines.Width, lines.Y, lines.X, lines.Y + lines.Height); } m_VisibleTabs[a_Index].m_BoundingBox = bb; m_VisibleTabs[a_Index].m_CloseBox = close; return bb.Width; }
/* ** Draws the meter on the double buffer ** */ bool MeterHistogram::Draw(Gfx::Canvas& canvas) { if (!Meter::Draw(canvas) || (m_Measures.size() >= 1 && !m_PrimaryValues) || (m_Measures.size() >= 2 && !m_SecondaryValues)) return false; Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext(); Measure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : nullptr; GraphicsPath primaryPath; GraphicsPath secondaryPath; GraphicsPath bothPath; Bitmap* primaryBitmap = m_PrimaryImage.GetImage(); Bitmap* secondaryBitmap = m_SecondaryImage.GetImage(); Bitmap* bothBitmap = m_OverlapImage.GetImage(); Gdiplus::Rect meterRect = GetMeterRectPadding(); // Default values (GraphStart=Right, GraphOrientation=Vertical) int i; int startValue = 0; int* endValueLHS = &i; int* endValueRHS = &meterRect.Width; int step = 1; int endValue = -1; //(should be 0, but need to simulate <=) // GraphStart=Left, GraphOrientation=Vertical if (!m_GraphHorizontalOrientation) { if (m_GraphStartLeft) { startValue = meterRect.Width - 1; endValueLHS = &endValue; endValueRHS = &i; step = -1; } } else { if (!m_Flip) { endValueRHS = &meterRect.Height; } else { startValue = meterRect.Height - 1; endValueLHS = &endValue; endValueRHS = &i; step = -1; } } // Horizontal or Vertical graph if (m_GraphHorizontalOrientation) { for (i = startValue; *endValueLHS < *endValueRHS; i += step) { double value = (m_MaxPrimaryValue == 0.0) ? 0.0 : m_PrimaryValues[(i + (m_MeterPos % meterRect.Height)) % meterRect.Height] / m_MaxPrimaryValue; value -= m_MinPrimaryValue; int primaryBarHeight = (int)(meterRect.Width * value); primaryBarHeight = min(meterRect.Width, primaryBarHeight); primaryBarHeight = max(0, primaryBarHeight); if (secondaryMeasure) { value = (m_MaxSecondaryValue == 0.0) ? 0.0 : m_SecondaryValues[(i + m_MeterPos) % meterRect.Height] / m_MaxSecondaryValue; value -= m_MinSecondaryValue; int secondaryBarHeight = (int)(meterRect.Width * value); secondaryBarHeight = min(meterRect.Width, secondaryBarHeight); secondaryBarHeight = max(0, secondaryBarHeight); // Check which measured value is higher int bothBarHeight = min(primaryBarHeight, secondaryBarHeight); // Cache image/color rectangle for the both lines { Rect& r = m_GraphStartLeft ? Rect(meterRect.X, meterRect.Y + startValue + (step * i), bothBarHeight, 1) : Rect(meterRect.X + meterRect.Width - bothBarHeight, meterRect.Y + startValue + (step * i), bothBarHeight, 1); bothPath.AddRectangle(r); // cache } // Cache the image/color rectangle for the rest if (secondaryBarHeight > primaryBarHeight) { Rect& r = m_GraphStartLeft ? Rect(meterRect.X + bothBarHeight, meterRect.Y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1) : Rect(meterRect.X + meterRect.Width - secondaryBarHeight, meterRect.Y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1); secondaryPath.AddRectangle(r); // cache } else { Rect& r = m_GraphStartLeft ? Rect(meterRect.X + bothBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1) : Rect(meterRect.X + meterRect.Width - primaryBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1); primaryPath.AddRectangle(r); // cache } } else { Rect& r = m_GraphStartLeft ? Rect(meterRect.X, meterRect.Y + startValue + (step * i), primaryBarHeight, 1) : Rect(meterRect.X + meterRect.Width - primaryBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight, 1); primaryPath.AddRectangle(r); // cache } } } else // GraphOrientation=Vertical { for (i = startValue; *endValueLHS < *endValueRHS; i += step) { double value = (m_MaxPrimaryValue == 0.0) ? 0.0 : m_PrimaryValues[(i + m_MeterPos) % meterRect.Width] / m_MaxPrimaryValue; value -= m_MinPrimaryValue; int primaryBarHeight = (int)(meterRect.Height * value); primaryBarHeight = min(meterRect.Height, primaryBarHeight); primaryBarHeight = max(0, primaryBarHeight); if (secondaryMeasure) { value = (m_MaxSecondaryValue == 0.0) ? 0.0 : m_SecondaryValues[(i + m_MeterPos) % meterRect.Width] / m_MaxSecondaryValue; value -= m_MinSecondaryValue; int secondaryBarHeight = (int)(meterRect.Height * value); secondaryBarHeight = min(meterRect.Height, secondaryBarHeight); secondaryBarHeight = max(0, secondaryBarHeight); // Check which measured value is higher int bothBarHeight = min(primaryBarHeight, secondaryBarHeight); // Cache image/color rectangle for the both lines { Rect& r = m_Flip ? Rect(meterRect.X + startValue + (step * i), meterRect.Y, 1, bothBarHeight) : Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - bothBarHeight, 1, bothBarHeight); bothPath.AddRectangle(r); // cache } // Cache the image/color rectangle for the rest if (secondaryBarHeight > primaryBarHeight) { Rect& r = m_Flip ? Rect(meterRect.X + startValue + (step * i), meterRect.Y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight) : Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight); secondaryPath.AddRectangle(r); // cache } else { Rect& r = m_Flip ? Rect(meterRect.X + startValue + (step * i), meterRect.Y + bothBarHeight, 1, primaryBarHeight - bothBarHeight) : Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - primaryBarHeight, 1, primaryBarHeight - bothBarHeight); primaryPath.AddRectangle(r); // cache } } else { Rect& r = m_Flip ? Rect(meterRect.X + startValue + (step * i), meterRect.Y, 1, primaryBarHeight) : Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - primaryBarHeight, 1, primaryBarHeight); primaryPath.AddRectangle(r); // cache } } } // Draw cached rectangles if (primaryBitmap) { Rect r(meterRect.X, meterRect.Y, primaryBitmap->GetWidth(), primaryBitmap->GetHeight()); graphics.SetClip(&primaryPath); graphics.DrawImage(primaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel); graphics.ResetClip(); } else { SolidBrush brush(m_PrimaryColor); graphics.FillPath(&brush, &primaryPath); } if (secondaryMeasure) { if (secondaryBitmap) { Rect r(meterRect.X, meterRect.Y, secondaryBitmap->GetWidth(), secondaryBitmap->GetHeight()); graphics.SetClip(&secondaryPath); graphics.DrawImage(secondaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel); graphics.ResetClip(); } else { SolidBrush brush(m_SecondaryColor); graphics.FillPath(&brush, &secondaryPath); } if (bothBitmap) { Rect r(meterRect.X, meterRect.Y, bothBitmap->GetWidth(), bothBitmap->GetHeight()); graphics.SetClip(&bothPath); graphics.DrawImage(bothBitmap, r, 0, 0, r.Width, r.Height, UnitPixel); graphics.ResetClip(); } else { SolidBrush brush(m_OverlapColor); graphics.FillPath(&brush, &bothPath); } } canvas.EndGdiplusContext(); return true; }
/* ** Draws the meter on the double buffer ** */ bool CMeterHistogram::Draw(Graphics& graphics) { if (!CMeter::Draw(graphics) || (m_Measures.size() >= 1 && !m_PrimaryValues) || (m_Measures.size() >= 2 && !m_SecondaryValues)) return false; CMeasure* secondaryMeasure = (m_Measures.size() >= 2) ? m_Measures[1] : NULL; GraphicsPath primaryPath; GraphicsPath secondaryPath; GraphicsPath bothPath; Bitmap* primaryBitmap = m_PrimaryImage.GetImage(); Bitmap* secondaryBitmap = m_SecondaryImage.GetImage(); Bitmap* bothBitmap = m_OverlapImage.GetImage(); int x = GetX(); int y = GetY(); // Default values (GraphStart=Right, GraphOrientation=Vertical) int i; int startValue = 0; int* endValueLHS = &i; int* endValueRHS = &m_W; int step = 1; int endValue = -1; //(should be 0, but need to simulate <=) // GraphStart=Left, GraphOrientation=Vertical if (!m_GraphHorizontalOrientation) { if (m_GraphStartLeft) { startValue = m_W - 1; endValueLHS = &endValue; endValueRHS = &i; step = -1; } } else { if (!m_Flip) { endValueRHS = &m_H; } else { startValue = m_H - 1; endValueLHS = &endValue; endValueRHS = &i; step = -1; } } // Horizontal or Vertical graph if (m_GraphHorizontalOrientation) { for (i = startValue; *endValueLHS < *endValueRHS; i += step) { double value = (m_MaxPrimaryValue == 0.0) ? 0.0 : m_PrimaryValues[(i + (m_MeterPos % m_H)) % m_H] / m_MaxPrimaryValue; value -= m_MinPrimaryValue; int primaryBarHeight = (int)(m_W * value); primaryBarHeight = min(m_W, primaryBarHeight); primaryBarHeight = max(0, primaryBarHeight); if (secondaryMeasure) { value = (m_MaxSecondaryValue == 0.0) ? 0.0 : m_SecondaryValues[(i + m_MeterPos) % m_H] / m_MaxSecondaryValue; value -= m_MinSecondaryValue; int secondaryBarHeight = (int)(m_W * value); secondaryBarHeight = min(m_W, secondaryBarHeight); secondaryBarHeight = max(0, secondaryBarHeight); // Check which measured value is higher int bothBarHeight = min(primaryBarHeight, secondaryBarHeight); // Cache image/color rectangle for the both lines { Rect& r = m_GraphStartLeft ? Rect(x, y + startValue + (step * i), bothBarHeight, 1) : Rect(x + m_W - bothBarHeight, y + startValue + (step * i), bothBarHeight, 1); bothPath.AddRectangle(r); // cache } // Cache the image/color rectangle for the rest if (secondaryBarHeight > primaryBarHeight) { Rect& r = m_GraphStartLeft ? Rect(x + bothBarHeight, y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1) : Rect(x + m_W - secondaryBarHeight, y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1); secondaryPath.AddRectangle(r); // cache } else { Rect& r = m_GraphStartLeft ? Rect(x + bothBarHeight, y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1) : Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1); primaryPath.AddRectangle(r); // cache } } else { Rect& r = m_GraphStartLeft ? Rect(x, y + startValue + (step * i), primaryBarHeight, 1) : Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight, 1); primaryPath.AddRectangle(r); // cache } } } else // GraphOrientation=Vertical { for (i = startValue; *endValueLHS < *endValueRHS; i += step) { double value = (m_MaxPrimaryValue == 0.0) ? 0.0 : m_PrimaryValues[(i + m_MeterPos) % m_W] / m_MaxPrimaryValue; value -= m_MinPrimaryValue; int primaryBarHeight = (int)(m_H * value); primaryBarHeight = min(m_H, primaryBarHeight); primaryBarHeight = max(0, primaryBarHeight); if (secondaryMeasure) { value = (m_MaxSecondaryValue == 0.0) ? 0.0 : m_SecondaryValues[(i + m_MeterPos) % m_W] / m_MaxSecondaryValue; value -= m_MinSecondaryValue; int secondaryBarHeight = (int)(m_H * value); secondaryBarHeight = min(m_H, secondaryBarHeight); secondaryBarHeight = max(0, secondaryBarHeight); // Check which measured value is higher int bothBarHeight = min(primaryBarHeight, secondaryBarHeight); // Cache image/color rectangle for the both lines { Rect& r = m_Flip ? Rect(x + startValue + (step * i), y, 1, bothBarHeight) : Rect(x + startValue + (step * i), y + m_H - bothBarHeight, 1, bothBarHeight); bothPath.AddRectangle(r); // cache } // Cache the image/color rectangle for the rest if (secondaryBarHeight > primaryBarHeight) { Rect& r = m_Flip ? Rect(x + startValue + (step * i), y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight) : Rect(x + startValue + (step * i), y + m_H - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight); secondaryPath.AddRectangle(r); // cache } else { Rect& r = m_Flip ? Rect(x + startValue + (step * i), y + bothBarHeight, 1, primaryBarHeight - bothBarHeight) : Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight - bothBarHeight); primaryPath.AddRectangle(r); // cache } } else { Rect& r = m_Flip ? Rect(x + startValue + (step * i), y, 1, primaryBarHeight) : Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight); primaryPath.AddRectangle(r); // cache } } } // Draw cached rectangles if (primaryBitmap) { Rect r(x, y, primaryBitmap->GetWidth(), primaryBitmap->GetHeight()); graphics.SetClip(&primaryPath); graphics.DrawImage(primaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel); graphics.ResetClip(); } else { SolidBrush brush(m_PrimaryColor); graphics.FillPath(&brush, &primaryPath); } if (secondaryMeasure) { if (secondaryBitmap) { Rect r(x, y, secondaryBitmap->GetWidth(), secondaryBitmap->GetHeight()); graphics.SetClip(&secondaryPath); graphics.DrawImage(secondaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel); graphics.ResetClip(); } else { SolidBrush brush(m_SecondaryColor); graphics.FillPath(&brush, &secondaryPath); } if (bothBitmap) { Rect r(x, y, bothBitmap->GetWidth(), bothBitmap->GetHeight()); graphics.SetClip(&bothPath); graphics.DrawImage(bothBitmap, r, 0, 0, r.Width, r.Height, UnitPixel); graphics.ResetClip(); } else { SolidBrush brush(m_OverlapColor); graphics.FillPath(&brush, &bothPath); } } return true; }
GraphicsPath* GdipCreateRoundRect( RectF& rect, int nRadiusLT, int nRadiusRT, int nRadiusRB, int nRadiusLB ) { GraphicsPath roundRect; if( nRadiusLT == 0 ) roundRect.AddLine( rect.GetLeft(), rect.GetTop(), rect.GetRight() - (nRadiusRT<<1), rect.GetTop() ); else roundRect.AddArc( RectF(rect.GetLeft(), rect.GetTop(), (float)(nRadiusLT<<1), (float)(nRadiusLT<<1)), 180, 90 ); if( nRadiusRT == 0 ) roundRect.AddLine( rect.GetRight(), rect.GetTop(), rect.GetRight(), rect.GetBottom()-(float)(nRadiusRB<<1) ); else roundRect.AddArc( RectF(rect.GetRight() - (float)(nRadiusRT<<1), rect.GetTop(), (float)(nRadiusRT<<1), (float)(nRadiusRT<<1)), 270, 90 ); if( nRadiusRB == 0 ) roundRect.AddLine( rect.GetRight(), rect.GetBottom(), rect.GetLeft()-(float)(nRadiusLB<<1), rect.GetBottom() ); else roundRect.AddArc( RectF(rect.GetRight() - (float)(nRadiusRB<<1), rect.GetBottom() -(float)(nRadiusRB<<1), (float)(nRadiusRB<<1), (float)(nRadiusRB<<1)), 0, 90 ); if( nRadiusLB == 0 ) roundRect.AddLine( rect.GetLeft(), rect.GetBottom(), rect.GetLeft(), rect.GetTop()-(float)(nRadiusLT<<1) ); else roundRect.AddArc( RectF(rect.GetLeft(), rect.GetBottom() -(float)(nRadiusLB<<1), (float)(nRadiusLB<<1), (float)(nRadiusLB<<1)), 90, 90 ); roundRect.CloseFigure(); return roundRect.Clone(); }
void CRevisionGraphWnd::DrawConnections (GraphicsDevice& graphics, const CRect& /*logRect*/, const CSize& offset) { CArray<PointF> points; CArray<CPoint> pts; if(graphics.graphics) graphics.graphics->SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); float penwidth = 2*m_fZoomFactor<1? 1:2*m_fZoomFactor; Gdiplus::Pen pen(Color(0,0,0),penwidth); // iterate over all visible lines edge e; forall_edges(e, m_Graph) { // get connection and point position const DPolyline &dpl = this->m_GraphAttr.bends(e); points.RemoveAll(); pts.RemoveAll(); PointF pt; pt.X = (REAL)m_GraphAttr.x(e->source()); pt.Y = (REAL)m_GraphAttr.y(e->source()); points.Add(pt); ListConstIterator<DPoint> it; for(it = dpl.begin(); it.valid(); ++it) { pt.X = (REAL)(*it).m_x; pt.Y = (REAL)(*it).m_y; points.Add(pt); } pt.X = (REAL)m_GraphAttr.x(e->target()); pt.Y = (REAL)m_GraphAttr.y(e->target()); points.Add(pt); points[0] = this->cutPoint(e->source(), 1, points[0], points[1]); points[points.GetCount()-1] = this->cutPoint(e->target(), 1, points[points.GetCount()-1], points[points.GetCount()-2]); // draw the connection for (int i = 0; i < points.GetCount(); ++i) { //CPoint pt; points[i].X = points[i].X * this->m_fZoomFactor - offset.cx; points[i].Y = points[i].Y * this->m_fZoomFactor - offset.cy; //pts.Add(pt); } if (graphics.graphics) { graphics.graphics->DrawLines(&pen, points.GetData(), (INT)points.GetCount()); } else if (graphics.pSVG) { Color color; color.SetFromCOLORREF(GetSysColor(COLOR_WINDOWTEXT)); graphics.pSVG->Polyline(points.GetData(), (int)points.GetCount(), Color(0,0,0), (int)penwidth); } else if (graphics.pGraphviz) { CString hash1 = _T("g") + m_logEntries[e->target()->index()].ToString().Left(g_Git.GetShortHASHLength()); CString hash2 = _T("g") + m_logEntries[e->source()->index()].ToString().Left(g_Git.GetShortHASHLength()); graphics.pGraphviz->DrawEdge(hash1, hash2); } //draw arrow double dx = points[1].X - points[0].X; double dy = points[1].Y - points[0].Y; double len = sqrt(dx*dx + dy*dy); dx = m_ArrowSize * m_fZoomFactor *dx /len; dy = m_ArrowSize * m_fZoomFactor *dy /len; double p1_x, p1_y, p2_x, p2_y; p1_x = dx * m_ArrowCos - dy * m_ArrowSin; p1_y = dx * m_ArrowSin + dy * m_ArrowCos; p2_x = dx * m_ArrowCos + dy * m_ArrowSin; p2_y = -dx * m_ArrowSin + dy * m_ArrowCos; //graphics.graphics->DrawLine(&pen, points[0].X,points[0].Y, points[0].X +p1_x,points[0].Y+p1_y); //graphics.graphics->DrawLine(&pen, points[0].X,points[0].Y, points[0].X +p2_x,points[0].Y+p2_y); GraphicsPath path; PointF arrows[5]; arrows[0].X = points[0].X; arrows[0].Y = points[0].Y; arrows[1].X = points[0].X + (REAL)p1_x; arrows[1].Y = points[0].Y + (REAL)p1_y; arrows[2].X = points[0].X + (REAL)dx*3/5; arrows[2].Y = points[0].Y + (REAL)dy*3/5; arrows[3].X = points[0].X + (REAL)p2_x; arrows[3].Y = points[0].Y + (REAL)p2_y; arrows[4].X = points[0].X; arrows[4].Y = points[0].Y; path.AddLines(arrows, 5); path.SetFillMode(FillModeAlternate); if(graphics.graphics) { graphics.graphics->DrawPath(&pen, &path); }else if(graphics.pSVG) { graphics.pSVG->DrawPath(arrows, 5, Color(0,0,0), (int)penwidth, Color(0,0,0)); } } }
void ProcessDateTime::UpdateTexture() { Status stat; RectF layoutBox; SIZE textSize; RectF boundingBox(0.0f, 0.0f, 32.0f, 32.0f); UpdateCurrentText(); if (bUpdateTexture) { bUpdateTexture = false; if (hFont) { DeleteObject(hFont); hFont = NULL; } hFont = GetFont(); if (!hFont) return; } StringFormat format(Gdiplus::StringFormat::GenericTypographic()); SetStringFormat(format); HDC hdc = CreateCompatibleDC(NULL); Font font(hdc, hFont); Graphics graphics(hdc); graphics.SetTextRenderingHint(TextRenderingHintAntiAlias); if (strCurrentText.IsValid()) { stat = graphics.MeasureString(strCurrentText, -1, &font, PointF(0.0f, 0.0f), &format, &boundingBox); if (stat != Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Gdiplus::Graphics::MeasureString failed: %u", (int)stat); if (bUseOutline) { //Note: since there's no path widening in DrawOutlineText the padding is half than what it was supposed to be. boundingBox.Width += outlineSize; boundingBox.Height += outlineSize; } } DeleteDC(hdc); hdc = NULL; if (boundingBox.Height < size) { textSize.cy = size; boundingBox.Height = float(size); } else textSize.cy = LONG(boundingBox.Height + EPSILON); textSize.cx = LONG(boundingBox.Width + EPSILON); //textSize.cx &= 0xFFFFFFFE; //textSize.cy &= 0xFFFFFFFE; textSize.cx += textSize.cx % 2; textSize.cy += textSize.cy % 2; ClampVal(textSize.cx, 32, 8192); ClampVal(textSize.cy, 32, 8192); //---------------------------------------------------------------------- // write image { HDC hTempDC = CreateCompatibleDC(NULL); BITMAPINFO bi; zero(&bi, sizeof(bi)); void* lpBits; BITMAPINFOHEADER &bih = bi.bmiHeader; bih.biSize = sizeof(bih); bih.biBitCount = 32; bih.biWidth = textSize.cx; bih.biHeight = textSize.cy; bih.biPlanes = 1; HBITMAP hBitmap = CreateDIBSection(hTempDC, &bi, DIB_RGB_COLORS, &lpBits, NULL, 0); Bitmap bmp(textSize.cx, textSize.cy, 4 * textSize.cx, PixelFormat32bppARGB, (BYTE*)lpBits); Graphics graphics(&bmp); SolidBrush brush(Gdiplus::Color(GetAlphaVal(opacity) | (color & 0x00FFFFFF))); DWORD bkColor; bkColor = ((strCurrentText.IsValid()) ? GetAlphaVal(0) : GetAlphaVal(0)); if (textSize.cx > boundingBox.Width || textSize.cy > boundingBox.Height) { stat = graphics.Clear(Gdiplus::Color(0x00000000)); if (stat != Gdiplus::Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::Clear failed: %u", (int)stat); SolidBrush *bkBrush = new SolidBrush(Gdiplus::Color(bkColor)); graphics.FillRectangle(bkBrush, boundingBox); delete bkBrush; } else { stat = graphics.Clear(Gdiplus::Color(bkColor)); if (stat != Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::Clear failed: %u", (int)stat); } graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias); graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver); graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); if (strCurrentText.IsValid()) { if (bUseOutline) { boundingBox.Offset(outlineSize / 2, outlineSize / 2); FontFamily fontFamily; GraphicsPath path; font.GetFamily(&fontFamily); path.AddString(strCurrentText, -1, &fontFamily, font.GetStyle(), font.GetSize(), boundingBox, &format); DrawOutlineText(&graphics, font, path, format, &brush); } else { stat = graphics.DrawString(strCurrentText, -1, &font, boundingBox, &format, &brush); if (stat != Gdiplus::Ok) Log::writeError(LOG_RTSPSERV, 1, "TextSource::UpdateTexture: Graphics::DrawString failed: %u", (int)stat); } } //---------------------------------------------------------------------- // upload texture if (textureSize.cx != textSize.cx || textureSize.cy != textSize.cy) { if (texture) { delete texture; texture = NULL; } mcpy(&textureSize, &textSize, sizeof(textureSize)); texture = CreateTexture(textSize.cx, textSize.cy, GS_BGRA, lpBits, FALSE, FALSE); } else if (texture) SetImage(texture,lpBits, GS_IMAGEFORMAT_BGRA, 4 * textSize.cx); if (!texture) { Log::writeError(LOG_RTSPSERV,1,"TextSource::UpdateTexture: could not create texture"); DeleteObject(hFont); } DeleteDC(hTempDC); DeleteObject(hBitmap); } }
// Calculates tab's elements, based on its width and height. // Generates a GraphicsPath, which is used for painting the tab, etc. bool Reshape(int dx, int dy) { dx--; if (width == dx && height == dy) return false; width = dx; height = dy; GraphicsPath shape; // define tab's body int c = int((float)height * 0.6f + 0.5f); // size of bounding square for the arc shape.AddArc(0, 0, c, c, 180.0f, 90.0f); shape.AddArc(width - c, 0, c, c, 270.0f, 90.0f); shape.AddLine(width, height, 0, height); shape.CloseFigure(); shape.SetMarker(); // define "x"'s circle c = int((float)height * 0.78f + 0.5f); // size of bounding square for the circle int maxC = DpiScaleX(hwnd, 17); if (height > maxC) { c = DpiScaleX(hwnd, 17); } Point p(width - c - DpiScaleX(hwnd, 3), (height - c) / 2); // circle's position shape.AddEllipse(p.X, p.Y, c, c); shape.SetMarker(); // define "x" int o = int((float)c * 0.286f + 0.5f); // "x"'s offset shape.AddLine(p.X+o, p.Y+o, p.X+c-o, p.Y+c-o); shape.StartFigure(); shape.AddLine(p.X+c-o, p.Y+o, p.X+o, p.Y+c-o); shape.SetMarker(); delete data; data = new PathData(); shape.GetPathData(data); return true; }
void CLMenu::DrawBckg() { CRect r; GetWindowRect(&r); bckg->Resize(r.Width(), r.Height()); if(!bckg->Ready()) { return; } Graphics g(bckg->dc); g.SetSmoothingMode(SmoothingModeAntiAlias); g.SetCompositingMode(CompositingModeSourceCopy); SolidBrush brush(Color(255 * 70 / 100, 0, 0, 0)); GraphicsPath *path = new GraphicsPath(); if(parent) { path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90); path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90); } else { switch(position) { case DockPositionTop: { path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90); path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 180, 90); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT + arrowOffset, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT); } break; case DockPositionBottom: { path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 0, 90); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT); } break; default: { path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90); path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90); } break; } } path->CloseFigure(); g.FillPath(&brush, path); delete path; if(parent) { bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2), SHADOW_SIZE); } else { switch(position) { case DockPositionTop: { bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2 + ARROW_HEIGHT, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2), SHADOW_SIZE); } break; case DockPositionBottom: { bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2 - ARROW_HEIGHT), SHADOW_SIZE); } break; default: { bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2), SHADOW_SIZE); } break; } } }
HRESULT CIGImageLibrary::OnDraw(ATL_DRAWINFO& di) { Graphics graphics (di.hdcDraw); // Middle part GraphicsPath path; path.AddRectangle (RectF (0, 0, IGIMAGELIBRARY_WIDTH, IGIMAGELIBRARY_HEIGHT)); PathGradientBrush pthGrBrush (&path); pthGrBrush.SetCenterPoint (PointF (0.7f * (float)IGIMAGELIBRARY_WIDTH, 0.3f * (float)IGIMAGELIBRARY_HEIGHT)); pthGrBrush.SetCenterColor (IGIMAGELIBRARY_COLOR_FRAMEIN); Color colors[] = {IGIMAGELIBRARY_COLOR_FRAMEOUT}; int count = 1; pthGrBrush.SetSurroundColors(colors, &count); graphics.FillPath (&pthGrBrush, &path); // Left part LinearGradientBrush linLeftGrBrush (PointF(0,0), PointF((float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0), IGIMAGELIBRARY_COLOR_BORDEROUT, IGIMAGELIBRARY_COLOR_BORDERMIDDLE); graphics.FillRectangle (&linLeftGrBrush, RectF (0, 0, (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS)); LinearGradientBrush linLeft2GrBrush (PointF ((float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f - 1.0f, 0), PointF (IGIMAGELIBRARY_BORDERWIDTH, 0), IGIMAGELIBRARY_COLOR_BORDERMIDDLE, IGIMAGELIBRARY_COLOR_BORDERIN); graphics.FillRectangle (&linLeft2GrBrush, RectF ((float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0, (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS)); // Right part LinearGradientBrush linRightGrBrush (PointF(IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_BORDERWIDTH - 1, 0), PointF(IGIMAGELIBRARY_WIDTH - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0), IGIMAGELIBRARY_COLOR_BORDERIN, IGIMAGELIBRARY_COLOR_BORDERMIDDLE); graphics.FillRectangle (&linRightGrBrush, RectF (IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_BORDERWIDTH, 0, (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS)); LinearGradientBrush linRight2GrBrush (PointF(IGIMAGELIBRARY_WIDTH - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f - 1.0f, 0), PointF(IGIMAGELIBRARY_WIDTH, 0), IGIMAGELIBRARY_COLOR_BORDERMIDDLE, IGIMAGELIBRARY_COLOR_BORDEROUT); graphics.FillRectangle (&linRight2GrBrush, RectF (IGIMAGELIBRARY_WIDTH - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0, (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS)); // Bottom part LinearGradientBrush linBottomGrBrush (PointF (0, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_BORDERWIDTH - 1.0f), PointF (0, IGIMAGELIBRARY_HEIGHT - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f), IGIMAGELIBRARY_COLOR_BORDERIN, IGIMAGELIBRARY_COLOR_BORDERMIDDLE); graphics.FillRectangle (&linBottomGrBrush, RectF (IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_BORDERWIDTH, IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERDIAM, (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f)); LinearGradientBrush linBottom2GrBrush (PointF(0,IGIMAGELIBRARY_HEIGHT - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f - 1.0f), PointF(0,IGIMAGELIBRARY_HEIGHT), IGIMAGELIBRARY_COLOR_BORDERMIDDLE, IGIMAGELIBRARY_COLOR_BORDEROUT); graphics.FillRectangle (&linBottom2GrBrush, RectF (IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_HEIGHT - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERDIAM, (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f)); // Bottom left part GraphicsPath pathBottomLeft; pathBottomLeft.AddEllipse (RectF (-5, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERDIAM, IGIMAGELIBRARY_CORNERDIAM + 10.0f, IGIMAGELIBRARY_CORNERDIAM)); PathGradientBrush pthGrBrushBottomLeft (&pathBottomLeft); Color colorsBottom[] = {IGIMAGELIBRARY_COLOR_BORDEROUT, IGIMAGELIBRARY_COLOR_BORDERMIDDLE, IGIMAGELIBRARY_COLOR_BORDERIN, IGIMAGELIBRARY_COLOR_FRAMEBORDER, IGIMAGELIBRARY_COLOR_FRAMEBORDER}; REAL interpPositionsBottom[] = { 0.0f, 0.28f, 0.49f, 0.50f, 1.0f}; pthGrBrushBottomLeft.SetInterpolationColors (colorsBottom, interpPositionsBottom, 5); graphics.FillRectangle (&pthGrBrushBottomLeft, RectF (0, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_CORNERRADIUS)); // Bottom right part REAL interpPositionsBottomRight[] = { 0.0f, 0.30f, 0.54f, 0.55f, 1.0f}; GraphicsPath pathBottomRight; pathBottomRight.AddEllipse (RectF (IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERDIAM, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERDIAM - 5, IGIMAGELIBRARY_CORNERDIAM, IGIMAGELIBRARY_CORNERDIAM + 10)); PathGradientBrush pthGrBrushBottomRight (&pathBottomRight); pthGrBrushBottomRight.SetInterpolationColors (colorsBottom, interpPositionsBottomRight, 5); graphics.FillRectangle (&pthGrBrushBottomRight, RectF (IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_CORNERRADIUS)); return S_OK; }
void CLMenu::DrawLayer(CDIB *dib) { if(!dib) { dib = CLMenu::dib; } CRect r; GetWindowRect(&r); dib->Assign(bckg); //dib.Resize(bckg.Width(), bckg.Height()); if(!dib->Ready()) { return; } Graphics g(dib->dc); g.SetSmoothingMode(SmoothingModeAntiAlias); g.SetCompositingMode(CompositingModeSourceCopy); SolidBrush brush(Color(255 * BCKG_OPACITY / 100, 0x10, 0x10, 0x10)); Pen pen(Color(0xd0, 0xd0, 0xd0), BORDER_SIZE); GraphicsPath *path = new GraphicsPath(); if(parent) { path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90); path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90); } else { switch(position) { case DockPositionTop: { path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90); path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 180, 90); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT); } break; case DockPositionBottom: { path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 0, 90); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE); path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT); } break; default: { path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90); path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90); path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90); path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90); } break; } } path->CloseFigure(); g.FillPath(&brush, path); g.SetCompositingMode(CompositingModeSourceOver); g.DrawPath(&pen, path); delete path; g.SetCompositingMode(CompositingModeSourceCopy); POSITION p = items.GetHeadPosition(); while(p) { UpdateItem(&g, items.GetAt(p)); items.GetNext(p); } }
void CXTPFlowGraphPaintManager::RecalcConnectionLayout(CXTPFlowGraphDrawContext* /*pDC*/, CXTPFlowGraphConnection* pConnection) { CXTPFlowGraphConnectionPoint* pFrom = pConnection->GetOutputPoint(); CXTPFlowGraphConnectionPoint* pTo = pConnection->GetInputPoint(); if (pFrom == NULL) return; CPoint ptFrom, ptTo; ptFrom = pFrom->GetNode()->GetLocation(); ptFrom.x += pFrom->GetNode()->GetSize().cx; ptFrom.y += pFrom->m_rcPoint.CenterPoint().y; if (pTo != NULL) { ptTo = pTo->GetNode()->GetLocation(); ptTo.y += pTo->m_rcPoint.CenterPoint().y; if (pTo->GetType() == xtpFlowGraphPointInputAndOutput) { if (ptFrom.x > ptTo.x) ptTo.x += pTo->GetNode()->GetSize().cx; } pConnection->m_ptInputPoint = ptTo; } else { ptTo = pConnection->m_ptInputPoint; } if (pFrom->GetType() == xtpFlowGraphPointInputAndOutput) { if (ptTo.x < ptFrom.x - pFrom->GetNode()->GetSize().cx / 2) ptFrom.x -= pFrom->GetNode()->GetSize().cx; } pConnection->m_ptOutputPoint = ptFrom; GraphicsPath* path = new GraphicsPath(); XTPFlowGraphConnectorType type = pConnection->GetStyle() == -1 ? m_nConnectorType : (XTPFlowGraphConnectorType)pConnection->GetStyle(); CPoint ptControlPoint = pConnection->GetControlPoint(); if (type == xtpFlowGraphConnectorStraight) { if (ptControlPoint != CPoint(-1, -1)) { Point pts[] = {Point(ptFrom.x, ptFrom.y), Point(ptControlPoint.x, ptControlPoint.y), Point(ptTo.x, ptTo.y) }; path->AddLines(pts, 3); } else { path->AddLine(ptFrom.x, ptFrom.y, ptTo.x, ptTo.y); } } else { if (ptControlPoint != CPoint(-1, -1)) { /*PointF pt[3] = {PointF((REAL)ptFrom.x, (REAL)ptFrom.y), PointF((REAL)pConnection->GetControlPoint().x, (REAL)pConnection->GetControlPoint().y), PointF((REAL)ptTo.x, (REAL)ptTo.y) }; path->AddCurve(pt, 3);*/ PointF pt2[4] = {PointF((REAL)ptFrom.x, (REAL)ptFrom.y), PointF((REAL)ptControlPoint.x, (REAL)ptFrom.y), PointF((REAL)ptControlPoint.x, (REAL)ptTo.y), PointF((REAL)ptTo.x, (REAL)ptTo.y) }; path->AddBeziers(pt2, 4); } else { PointF pt[4] = {PointF((REAL)ptFrom.x, (REAL)ptFrom.y), PointF((REAL)(ptFrom.x + ptTo.x) / 2, (REAL)ptFrom.y), PointF(REAL(ptFrom.x + ptTo.x) / 2, (REAL)ptTo.y), PointF((REAL)ptTo.x, (REAL)ptTo.y) }; path->AddBeziers(pt, 4); } } SAFE_DELETE(pConnection->m_pPath); pConnection->m_pPath = path; }