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(); }
// 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 shape.AddRectangle(Rect(0, 0, width, height)); shape.SetMarker(); // define "x"'s circle int 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; }
// 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 = height > 17 ? 14 : int((float)height * 0.78f + 0.5f); // size of bounding square for the circle Point p(width - c - 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 CAguraDlgBlue::gradationCenter(Graphics& g, CRect rt, Color& color1, Color& color2, BOOL bLine, Color& color3) { GraphicsPath gPath; int iHeight = rt.Width() / 4; int iWidth = rt.Width() / 4; RectF rtF((REAL)rt.left - iWidth, (REAL)rt.top - iHeight, (REAL)rt.Width() + iWidth * 2, (REAL)rt.Height() + iHeight * 2); gPath.AddEllipse(rtF); gPath.CloseFigure(); PathGradientBrush PGB(&gPath); PGB.SetCenterColor(color1); //would be some shade of blue, following your example int colCount = 1; PGB.SetSurroundColors(&color2, &colCount); //same as your center color, but with the alpha channel set to 0 //play with these numbers to get the glow effect you want REAL blendFactors[] = {0.0f, 0.1f, 0.3f, 1.0f}; REAL blendPos[] = {0.0f, 0.4f, 0.6f, 1.0f}; //sets how transition toward the center is shaped PGB.SetBlend(blendFactors, blendPos, 4); //sets the scaling on the center. you may want to have it elongated in the x-direction PGB.SetFocusScales(0.2f, 0.2f); RectF rtDraw((REAL)rt.left, (REAL)rt.top, (REAL)rt.Width(), (REAL)rt.Height()); g.FillRectangle(&PGB, rtDraw); if (bLine == TRUE) { Pen pen(color3, 1); g.DrawRectangle(&pen, rtDraw); } }
//原生GDI+ 绘制 void converDemo::drawOnNativeGdi(Graphics &graphics) { GraphicsPath path; path.AddEllipse(10, 10, 100, 100); path.AddRectangle(RectF(100, 100, 200, 250)); PathGradientBrush* brush = new PathGradientBrush(&path); Color colors[] = { Color(0, 0, 255), Color(0, 0, 0), Color(0, 255, 0), Color(255, 0, 0) }; REAL reals[] = { 0, 0.5, 0.8, 1 }; brush->SetInterpolationColors(colors, reals, 4); Matrix matrix; matrix.Translate(100, 0); matrix.Shear(0.15, 0.3); matrix.Scale(0.4, 0.2); matrix.Rotate(0.5); // brush->MultiplyTransform(&matrix, MatrixOrderAppend); RectF rect(convertQRectF2GpRectF(QRectF(100.0f, 100.0f, 200.0f, 400.0f))); graphics.FillRectangle(brush, rect); delete brush; }
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); }
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; }