/// <summary> /// /// </summary> /// <param name="region"></param> /// <param name="element"></param> private void CombinePaths(GraphicsPath path, SvgElement element) { var graphicsElement = element as SvgVisualElement; if (graphicsElement != null && graphicsElement.Path != null) { path.FillMode = (graphicsElement.ClipRule == SvgClipRule.NonZero) ? FillMode.Winding : FillMode.Alternate; GraphicsPath childPath = graphicsElement.Path; if (graphicsElement.Transforms != null) { foreach (SvgTransform transform in graphicsElement.Transforms) { childPath.Transform(transform.Matrix); } } path.AddPath(childPath, false); } foreach (SvgElement child in element.Children) { this.CombinePaths(path, child); } }
public void AddPath(IGraphicsPath path, bool connect = false) { if (path != null && !path.IsEmpty) // avoid throwing an exception if the path is empty - consistent across platforms. { Control.AddPath(path.ToSD(), connect); } }
public static void WarpPath(GraphicsPath path, PointF[] destPoints, RectangleF srcRect, Matrix matrix = null, WarpMode warpMode = WarpMode.Perspective, float flatness = 0.25f) { if (path.PointCount == 0) return; path.Flatten(matrix, flatness); var pathData = path.PathData; var pnts = path.PathPoints; var srcPoints = new PointF[] { new PointF(srcRect.Left, srcRect.Top), new PointF(srcRect.Right, srcRect.Top), new PointF(srcRect.Left, srcRect.Bottom), new PointF(srcRect.Right, srcRect.Bottom) }; var count = pnts.Length; float x1, y1; int i; if (warpMode == WarpMode.Perspective) { CalcProjectiveXformCoeffs(srcPoints, destPoints, out coeffs); for (i = 0; i < count; i++) { x1 = pnts[i].X; y1 = pnts[i].Y; var factor = 1.0f / (coeffs[6] * x1 + coeffs[7] * y1 + 1.0f); pnts[i].X = (float)(factor * (coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2])); pnts[i].Y = (float)(factor * (coeffs[3] * x1 + coeffs[4] * y1 + coeffs[5])); } } else { CalcBilinearXformCoeffs(srcPoints, destPoints, out coeffs); for (i = 0; i < count; i++) { x1 = pnts[i].X; y1 = pnts[i].Y; pnts[i].X = (float)(coeffs[0] * x1 + coeffs[1] * y1 + coeffs[2] * x1 * y1 + coeffs[3]); pnts[i].Y = (float)(coeffs[4] * x1 + coeffs[5] * y1 + coeffs[6] * x1 * y1 + coeffs[7]); } } GraphicsPath warpedPath = new GraphicsPath(pnts, pathData.Types); if (warpedPath != null) { FillMode fm = path.FillMode; path.Reset(); path.FillMode = fm; path.AddPath(warpedPath, true); warpedPath.Dispose(); } }
protected override void DrawShape(GraphicsPath g) { g.AddPath(Settings.Screen.ShapeUnit, true); //g.AddClosedCurve(new[] // { // new Point(0, TOTAL_HEIGHT/2 - 1), new Point(TOTAL_WIDTH/2, TOTAL_HEIGHT), // new Point(TOTAL_WIDTH, TOTAL_HEIGHT/2 - 1) // }); }
protected virtual void DrawHighlight(GraphicsPath graphicsPath, Graphics graphics) { if (!Tracked) return; using (var hi = new GraphicsPath()) { hi.AddEllipse(0, 0, TOTAL_WIDTH, TOTAL_HEIGHT); graphicsPath.AddPath(hi, true); } }
public void AddStringToPath(ISvgRenderer renderer, GraphicsPath path, string text, PointF location) { var textPath = GetPath(renderer, text, null, false); if (textPath.PointCount > 0) { using (var translate = new Matrix()) { translate.Translate(location.X, location.Y); textPath.Transform(translate); path.AddPath(textPath, false); } } }
/// <summary> /// /// </summary> /// <param name="region"></param> /// <param name="element"></param> private void CombinePaths(GraphicsPath path, SvgElement element) { var graphicsElement = element as SvgVisualElement; if (graphicsElement != null && graphicsElement.Path != null) { path.FillMode = (graphicsElement.ClipRule == SvgClipRule.NonZero) ? FillMode.Winding : FillMode.Alternate; path.AddPath(graphicsElement.Path, false); } foreach (SvgElement child in element.Children) { this.CombinePaths(path, child); } }
/// <summary> /// Exports a figure, created by Potrace from a Bitmap to a svg-formatted string ///It should be SVG-formattted /// </summary> /// <param name="Fig">Arraylist, which contains vectorinformations about the Curves</param> /// <param name="Width">Width of the Bitmap</param> /// <param name="Height">Height of the Bitmap</param> /// <returns></returns> public static Bitmap Export2GDIPlus(ArrayList Fig, int Width,int Height ) { Image I= new Bitmap(Width,Height); Graphics g = Graphics.FromImage(I); g.FillRectangle(new SolidBrush(Color.White),0,0,Width,Height); GraphicsPath gp = new GraphicsPath(); for (int i = 0; i < Fig.Count; i++) { ArrayList CurveArray = (ArrayList)Fig[i]; GraphicsPath Contour = null; GraphicsPath Hole = null; GraphicsPath Current = null; for (int j = 0; j < CurveArray.Count; j++) { if (j == 0) { Contour = new GraphicsPath(); Current = Contour; } else { Hole = new GraphicsPath(); Current = Hole; } Potrace.Curve[] Curves = (Potrace.Curve[])CurveArray[j]; float factor = 1; for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) Current.AddBezier((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].ControlPointA.x * factor, (float)Curves[k].ControlPointA.y * factor, (float)Curves[k].ControlPointB.x * factor, (float)Curves[k].ControlPointB.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); else Current.AddLine((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); } if (j > 0) Contour.AddPath(Hole, false); } gp.AddPath(Contour, false); } g.FillPath(Brushes.Black, gp); return (Bitmap)I; }
private GraphicsPath GetOutline_ToolWindow(int index) { Rectangle rectTab = GetTabRectangle(index); rectTab.Intersect(TabsRectangle); rectTab = RectangleToScreen(DrawHelper.RtlTransform(this, rectTab)); Rectangle rectPaneClient = DockPane.RectangleToScreen(DockPane.ClientRectangle); GraphicsPath path = new GraphicsPath(); GraphicsPath pathTab = GetTabOutline(Tabs[index], true, true); path.AddPath(pathTab, true); path.AddLine(rectTab.Left, rectTab.Top, rectPaneClient.Left, rectTab.Top); path.AddLine(rectPaneClient.Left, rectTab.Top, rectPaneClient.Left, rectPaneClient.Top); path.AddLine(rectPaneClient.Left, rectPaneClient.Top, rectPaneClient.Right, rectPaneClient.Top); path.AddLine(rectPaneClient.Right, rectPaneClient.Top, rectPaneClient.Right, rectTab.Top); path.AddLine(rectPaneClient.Right, rectTab.Top, rectTab.Right, rectTab.Top); return path; }
/// <summary> /// Get the object outline for arrangements in object world coordinates. /// </summary> /// <returns>Object outline for arrangements in object world coordinates</returns> public override GraphicsPath GetObjectOutlineForArrangements() { GraphicsPath result = new GraphicsPath(); foreach (var ele in _groupedObjects) result.AddPath(ele.GetObjectOutlineForArrangements(), false); return result; }
public void OnLoad(EventArgs e) { Bitmap bmp = new Bitmap(this.Height*0x06, this.Height*0x02); Graphics g = Graphics.FromImage(bmp); g.CompositingQuality = CompositingQuality.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; float w = 6.0f*this.Height; int hInt = this.Height; float h = (float)hInt; float margin = h/48.0f; float m2 = 2.0f*margin; float r = h/36.0f;///36.0f float r2 = 2.0f*r; float h_2 = 0.5f*h; float Ro = h_2-margin; float alpha = (float)(180.0d/Math.PI*Math.Acos(1.0d-0.5d*r/Ro)); float beta = (float)(180.0d/Math.PI*Math.Acos(1.0d-r/Ro)); float betaY = (float)Math.Sqrt(Ro*Ro-(Ro-r)*(Ro-r)); float sqrtR2 = (float)(Math.Sqrt(0.5d)*(h-m2-r2)); float __R2 = h_2-margin-r; __R2 *= __R2; for(int l = 0x00; l < 0x02; l++) { using(GraphicsPath gpNocturne = new GraphicsPath()) { //left wing gpNocturne.AddArc(0.5f*w-h+m2, margin, h-m2, h-m2, 180.0f+alpha, 360.0f-2.0f*alpha); gpNocturne.AddArc(0.5f*w+2.0f*(m2-h)+r, margin, h-m2, h-m2, alpha, 90.0f-alpha); gpNocturne.AddLine(0.5f*w+1.5f*m2+r-1.5f*h, h-margin, h_2, h-margin); gpNocturne.AddArc(margin, margin, h-m2, h-m2, 90.0f, 90.0f-beta); gpNocturne.AddLine(margin+r, h_2+betaY, margin+r, h-margin); gpNocturne.AddLine(margin+r, h-margin, margin, h-margin); gpNocturne.AddLine(margin, h-margin, margin, margin); gpNocturne.AddLine(margin, margin, margin+r, margin); gpNocturne.AddLine(margin+r, margin, margin+r, h_2-betaY); gpNocturne.AddArc(margin, margin, h-m2, h-m2, 180.0f+beta, 90.0f-beta); gpNocturne.AddLine(h_2, margin, 0.5f*w+1.5f*m2+r-1.5f*h, margin); gpNocturne.AddArc(0.5f*w+2.0f*(m2-h)+r, margin, h-m2, h-m2, 270.0f, 90.0f-alpha); gpNocturne.CloseFigure(); //right wing gpNocturne.AddArc(0.5f*w, margin, h-m2, h-m2, 360.0f-alpha, 2.0f*alpha-360.0f); gpNocturne.AddArc(0.5f*w+h-m2-r, margin, h-m2, h-m2, 180.0f-alpha, alpha-90.0f); gpNocturne.AddLine(0.5f*w+2.0f*(h-m2)-r, h-margin, w-h_2, h-margin); gpNocturne.AddArc(w-h+margin, margin, h-m2, h-m2, 90.0f, beta-90.0f); gpNocturne.AddLine(w-margin-r, h_2+betaY, w-margin-r, h-margin); gpNocturne.AddLine(w-margin-r, h-margin, w-margin, h-margin); gpNocturne.AddLine(w-margin, h-margin, w-margin, margin); gpNocturne.AddLine(w-margin, margin, w-margin-r, margin); gpNocturne.AddLine(w-margin-r, margin, w-margin-r, h_2-betaY); gpNocturne.AddArc(w-h+margin, margin, h-m2, h-m2, -beta, beta-90.0f); gpNocturne.AddLine(w-h_2, margin, 0.5f*w+2.0f*(h-m2)-r, margin); gpNocturne.AddArc(0.5f*w+h-m2-r, margin, h-m2, h-m2, 270.0f, alpha-90.0f); gpNocturne.CloseFigure(); if(l == 0x00) g.FillPath(EgyptInformation.Brushes.EgyptNocturne, gpNocturne); else g.FillPath(EgyptInformation.Brushes.EgyptPaintBlue, gpNocturne); //g.FillPath(new SolidBrush(Color.FromArgb(0x4c,0x41,0x0b)),gpNocturne); using(GraphicsPath gpGold = new GraphicsPath()) { gpGold.AddPath(gpNocturne, false); //left inner gpGold.AddArc(margin+r, margin+r, h-m2-r2, h-m2-r2, 90.0f, 180.0f); gpGold.AddArc(0.5f*w+2.0f*(m2-h)+r2, margin+r, h-m2-r2, h-m2-r2, 270.0f, 180.0f); gpGold.CloseFigure(); //left ellipse gpGold.AddEllipse(0.5f*w-h+m2+r, margin+r, h-m2-r2, h-m2-r2); gpGold.CloseFigure(); //right inner gpGold.AddArc(w-h+margin+r, margin+r, h-m2-r2, h-m2-r2, 90.0f, -180.0f); gpGold.AddArc(0.5f*w+h-m2, margin+r, h-m2-r2, h-m2-r2, 270.0f, -180.0f); gpGold.CloseFigure(); //right ellipse gpGold.AddEllipse(0.5f*w+r, margin+r, h-m2-r2, h-m2-r2); gpGold.CloseFigure(); g.FillPath(EgyptInformation.Brushes.EgyptGold, gpGold); GraphicsUtils.DrawGlass(g, gpGold); } Matrix M = new Matrix(); M.Scale(sqrtR2, sqrtR2); RectangleF bounds; Matrix Mtrans = new Matrix(); GraphicsPath gpHedjet = EgyptInformation.GraphicsPaths.Hedjet(); gpHedjet.Transform(M); bounds = gpHedjet.GetBounds(); Mtrans.Translate(-0.5f*bounds.Width, 0.0f); Mtrans.Scale(-1.0f, 1.0f, MatrixOrder.Append); Mtrans.Translate(0.5f*(w-h+m2), h_2-0.5f*bounds.Height, MatrixOrder.Append); gpHedjet.Transform(Mtrans); g.FillPath(EgyptInformation.Brushes.EgyptPaintWhite, gpHedjet); GraphicsUtils.DrawGlass(g, gpHedjet); GraphicsPath gpDeshret = EgyptInformation.GraphicsPaths.Deshret(); gpDeshret.Transform(M); bounds = gpDeshret.GetBounds(); Mtrans.Reset(); Mtrans.Translate(0.5f*(w+h-m2-bounds.Width), h_2-0.5f*bounds.Height); gpDeshret.Transform(Mtrans); g.FillPath(EgyptInformation.Brushes.EgyptPaintRed, gpDeshret); GraphicsUtils.DrawGlass(g, gpDeshret); } g.TranslateTransform(0.0f, h); } BitmapData bmd = bmp.LockBits(new Rectangle(0x00, 0x00, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); this.texturePointer = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, this.texturePointer); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.LinearMipmapLinear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear); Glu.Glu.Build2DMipmap(Glu.TextureTarget.Texture2D, (int)PixelInternalFormat.Four, bmp.Width, bmp.Height, OpenTK.Graphics.PixelFormat.Bgra, Glu.PixelType.UnsignedByte, bmd.Scan0); bmp.UnlockBits(bmd); }
// internal static GraphicsPath GetLineCap(LineAnchor lineCap, int capsize, out float capinset) { //WE DO NOT SUPPORT ARROWCAPS FOR ANGULAR CONNECTORS FOR NOW capinset = 0.0f; capinset = (float)capsize / 2; Size capSize = new Size(capsize, capsize); GraphicsPath lineCapPath = new GraphicsPath(); switch (lineCap) { case LineAnchor.Arrow: case LineAnchor.ArrowAnchor: int arcRadius = capSize.Height / 3; lineCapPath.AddLine(capSize.Width / 2, -capSize.Height, 0, 0); lineCapPath.AddLine(0, 0, -capSize.Width / 2, -capSize.Height); lineCapPath.AddLine(-capSize.Width / 2, -capSize.Height, 0, -capSize.Height + arcRadius); lineCapPath.AddLine(0, -capSize.Height + arcRadius, capSize.Width / 2, -capSize.Height); capinset = capSize.Height - arcRadius; break; case LineAnchor.Diamond: case LineAnchor.DiamondAnchor: lineCapPath.AddLine(0, -capSize.Height, capSize.Width / 2, -capSize.Height / 2); lineCapPath.AddLine(capSize.Width / 2, -capSize.Height / 2, 0, 0); lineCapPath.AddLine(0, 0, -capSize.Width / 2, -capSize.Height / 2); lineCapPath.AddLine(-capSize.Width / 2, -capSize.Height / 2, 0, -capSize.Height); break; case LineAnchor.Round: case LineAnchor.RoundAnchor: lineCapPath.AddEllipse(new Rectangle(-capSize.Width / 2, -capSize.Height, capSize.Width, capSize.Height)); break; case LineAnchor.Rectangle: case LineAnchor.RectangleAnchor: lineCapPath.AddRectangle(new Rectangle(-capSize.Width / 2, -capSize.Height, capSize.Width, capSize.Height)); break; case LineAnchor.RoundedRectangle: case LineAnchor.RoundedRectangleAnchor: arcRadius = capSize.Height / 4; lineCapPath.AddPath(ActivityDesignerPaint.GetRoundedRectanglePath(new Rectangle(-capSize.Width / 2, -capSize.Height, capSize.Width, capSize.Height), arcRadius), true); break; } lineCapPath.CloseFigure(); return lineCapPath; }
public static GraphicsPath CreatePath(SvgPathElement element) { GraphicsPath gp = new GraphicsPath(); SvgPointF initPoint = new SvgPointF(0, 0); SvgPointF lastPoint = new SvgPointF(0, 0); ISvgPathSeg segment = null; SvgPathSegMoveto pathMoveTo = null; SvgPathSegLineto pathLineTo = null; SvgPathSegCurveto pathCurveTo = null; SvgPathSegArc pathArc = null; ISvgPathSegList segments = element.PathSegList; int nElems = segments.NumberOfItems; for (int i = 0; i < nElems; i++) { segment = segments.GetItem(i); if (DynamicCast.Cast(segment, out pathMoveTo)) { //SvgPathSegMoveto seg = (SvgPathSegMoveto)segment; gp.StartFigure(); lastPoint = initPoint = pathMoveTo.AbsXY; } else if (DynamicCast.Cast(segment, out pathLineTo)) { //SvgPathSegLineto seg = (SvgPathSegLineto)segment; SvgPointF p = pathLineTo.AbsXY; gp.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y); lastPoint = p; } else if (DynamicCast.Cast(segment, out pathCurveTo)) { // SvgPathSegCurveto seg = (SvgPathSegCurveto)segment; SvgPointF xy = pathCurveTo.AbsXY; SvgPointF x1y1 = pathCurveTo.CubicX1Y1; SvgPointF x2y2 = pathCurveTo.CubicX2Y2; gp.AddBezier(lastPoint.X, lastPoint.Y, x1y1.X, x1y1.Y, x2y2.X, x2y2.Y, xy.X, xy.Y); lastPoint = xy; } else if (DynamicCast.Cast(segment, out pathArc)) { //SvgPathSegArc seg = (SvgPathSegArc)segment; SvgPointF p = pathArc.AbsXY; if (lastPoint.Equals(p)) { // If the endpoints (x, y) and (x0, y0) are identical, then this // is equivalent to omitting the elliptical arc segment entirely. } else if (pathArc.R1 == 0 || pathArc.R2 == 0) { // Ensure radii are valid gp.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y); } else { CalculatedArcValues calcValues = pathArc.GetCalculatedArcValues(); GraphicsPath gp2 = new GraphicsPath(); gp2.StartFigure(); gp2.AddArc((float)(calcValues.Cx - calcValues.CorrRx), (float)(calcValues.Cy - calcValues.CorrRy), (float)calcValues.CorrRx * 2, (float)calcValues.CorrRy * 2, (float)calcValues.AngleStart, (float)calcValues.AngleExtent); Matrix matrix = new Matrix(); matrix.Translate(-(float)calcValues.Cx, -(float)calcValues.Cy); gp2.Transform(matrix); matrix = new Matrix(); matrix.Rotate((float)pathArc.Angle); gp2.Transform(matrix); matrix = new Matrix(); matrix.Translate((float)calcValues.Cx, (float)calcValues.Cy); gp2.Transform(matrix); gp.AddPath(gp2, true); } lastPoint = p; } else if (segment is SvgPathSegClosePath) { gp.CloseFigure(); lastPoint = initPoint; } } string fillRule = element.GetPropertyValue("fill-rule"); if (fillRule == "evenodd") gp.FillMode = FillMode.Alternate; else gp.FillMode = FillMode.Winding; return gp; }
private GraphicsPath GetCircularBarPath(GaugeCircularScale scale) { GraphicsPath path = new GraphicsPath(); Rectangle r = _Bounds; r.Inflate(Width / 2, Width / 2); path.AddArc(r, _StartAngle, _SweepAngle); if (_RoundAngle != 0) { if (GaugePointer.BarStyle != BarPointerStyle.Square) { Point pt = scale.GetPoint(_Bounds.Width/2, _StartAngle + _SweepAngle); Point pt2 = scale.GetPoint(_Bounds.Width/2, _StartAngle + _SweepAngle + _RoundAngle); int dx = pt2.X - pt.X; int dy = pt2.Y - pt.Y; double n = Math.Max(1, Math.Sqrt((dx * dx) + (dy * dy))); float angle = (_StartAngle + _SweepAngle) % 360; using (GraphicsPath path2 = new GraphicsPath()) { Matrix matrix = new Matrix(); matrix.RotateAt(angle, pt); r.X = pt.X - Width/2 + 1; r.Y = pt.Y - (int) n; r.Width = Width - 1; r.Height = (int) (n*2); if (GaugePointer.BarStyle == BarPointerStyle.Rounded) { path2.AddArc(r, 0, _SweepAngle + _RoundAngle > 0 ? 180 : -180); } else { path2.AddLine(new Point(r.Right, r.Y + r.Height/2), new Point(r.X + Width/2, _SweepAngle + _RoundAngle > 0 ? r.Bottom : r.Y)); } path2.Transform(matrix); path.AddPath(path2, true); } } } r = _Bounds; r.Inflate(-Width / 2, -Width / 2); path.AddArc(r, _StartAngle + _SweepAngle, -_SweepAngle); path.CloseFigure(); return (path); }
/// <summary>Draws visual code connecting lines that connect the Cuda code to PTX code. These are a visual aid that help in understanding PTX.</summary> private void ReDrawLines() { if (!LinesEnabled) return; txtSrc.Refresh(); txtDst.Refresh(); if (linesInfo.Count > 0) { GraphicsPath path = new GraphicsPath(FillMode.Winding); byte[] types = { (byte)PathPointType.Start, 3, 3, 3, 1, 3, 3, 3, 1 }; int txtSrcRowHeight = txtSrc.Lines.FirstVisible.Height; int txtSrcfirstVisible = txtSrc.Lines.FirstVisible.Number; int txtSrcVisibleLineCt = txtSrc.Lines.VisibleCount; int txtSrcOverExtendPixels = 4; float txtSrcFontSz = (txtSrc.Font.Size + (float)txtSrc.ZoomFactor) * 0.75f ; int txtDstRowHeight = txtDst.Lines.FirstVisible.Height; int txtDstfirstVisible = txtDst.Lines.FirstVisible.Number; int txtDstVisibleLineCt = txtDst.Lines.VisibleCount; int txtDstOverExtendPixels = 4; foreach (LineInfo arrowInfo in linesInfo) if (arrowInfo.srcLineNo > 0) { const int width = 1; int s_x = (int)(txtSrc.Lines[arrowInfo.srcLineNo - 1].Length * (txtSrcFontSz+1)); // get source-x width s_x = Math.Min(s_x, txtSrc.Width-15); // make sure it does not start past the end of the screen int s_y = (int)((arrowInfo.srcLineNo - txtSrcfirstVisible) * txtSrcRowHeight) - (txtSrcRowHeight / 2); int d_x = txtSrc.Width + 30; int d_y = (int)((arrowInfo.lineNo - txtDstfirstVisible) * txtDstRowHeight) - (txtDstRowHeight / 2); if (s_y < (0 - txtSrcOverExtendPixels) * txtSrcRowHeight) continue; if (s_y > (0 + txtSrcVisibleLineCt + txtSrcOverExtendPixels) * txtSrcRowHeight) continue; if (d_y < (0 - txtDstOverExtendPixels) * txtDstRowHeight) continue; if (d_y > (0 + txtDstVisibleLineCt + txtDstOverExtendPixels) * txtDstRowHeight) continue; Point[] pts2 = { new Point(s_x, s_y), new Point(s_x + 60, s_y), new Point(d_x - 60, d_y), new Point(d_x, d_y), new Point(d_x, d_y + width), new Point(d_x - 60, d_y + width), new Point(s_x + 60, s_y + width), new Point(s_x, s_y + width), new Point(s_x, s_y) }; GraphicsPath subpath = new GraphicsPath(pts2, types); path.AddPath(subpath, false); } linesDrawPanel.Region = new Region(path); path.Dispose(); } linesDrawPanel.Visible = true; // added 1-1-2015 }
public override void AddToGraphicsPath(System.Drawing.Drawing2D.GraphicsPath path) { path.AddPath(this.path, false); }
/// <summary> /// potrace draw /// </summary> private void draw() { if (ListOfCurveArray == null) return; Graphics g = Graphics.FromImage(pictureBox1.Image); GraphicsPath gp = new GraphicsPath(); for (int i = 0; i < ListOfCurveArray.Count; i++) { ArrayList CurveArray = (ArrayList)ListOfCurveArray[i]; GraphicsPath Contour = null; GraphicsPath Hole = null; GraphicsPath Current = null; for (int j = 0; j < CurveArray.Count; j++) { if (j == 0) { Contour = new GraphicsPath(); Current = Contour; } else { Hole = new GraphicsPath(); Current = Hole; } Potrace.Curve[] Curves = (Potrace.Curve[])CurveArray[j]; float factor = 1; if (checkBox2.Checked) factor = (trackBar1.Value + 1); for (int k = 0; k < Curves.Length; k++) { if (Curves[k].Kind == Potrace.CurveKind.Bezier) Current.AddBezier((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].ControlPointA.x * factor, (float)Curves[k].ControlPointA.y * factor, (float)Curves[k].ControlPointB.x * factor, (float)Curves[k].ControlPointB.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); else Current.AddLine((float)Curves[k].A.x * factor, (float)Curves[k].A.y * factor, (float)Curves[k].B.x * factor, (float)Curves[k].B.y * factor); } if (j > 0) Contour.AddPath(Hole, false); } gp.AddPath(Contour, false); } if (checkBox1.Checked) g.DrawPath(Pens.Red, gp); if (checkBox2.Checked) showPoints(); }
internal static GraphicsPath GetDesignerPath(ActivityDesigner designer, Point offset, Size inflate, DesignerEdges edgeToInflate, bool enableRoundedCorners) { GraphicsPath path = new GraphicsPath(); Rectangle bounds = designer.Bounds; bounds.Offset(offset); if ((edgeToInflate & DesignerEdges.Left) > DesignerEdges.None) { bounds.X -= inflate.Width; bounds.Width += inflate.Width; } if ((edgeToInflate & DesignerEdges.Right) > DesignerEdges.None) { bounds.Width += inflate.Width; } if ((edgeToInflate & DesignerEdges.Top) > DesignerEdges.None) { bounds.Y -= inflate.Height; bounds.Height += inflate.Height; } if ((edgeToInflate & DesignerEdges.Bottom) > DesignerEdges.None) { bounds.Height += inflate.Height; } if ((designer == ActivityDesigner.GetSafeRootDesigner(designer.Activity.Site)) && (((IWorkflowRootDesigner) designer).InvokingDesigner == null)) { path.AddRectangle(bounds); return path; } ActivityDesignerTheme designerTheme = designer.DesignerTheme; if ((enableRoundedCorners && (designerTheme != null)) && (designerTheme.DesignerGeometry == DesignerGeometry.RoundedRectangle)) { path.AddPath(GetRoundedRectanglePath(bounds, 8), true); return path; } path.AddRectangle(bounds); return path; }
protected override void DrawShape(GraphicsPath g) { g.AddPath(Settings.Screen.ShapePlayer, true); }
internal static GraphicsPath GetLineCap(LineAnchor lineCap, int capsize, out float capinset) { int num; capinset = 0f; capinset = capsize; Size size = new Size(capsize, capsize); GraphicsPath path = new GraphicsPath(); switch (lineCap) { case LineAnchor.Arrow: case LineAnchor.ArrowAnchor: num = size.Height / 3; path.AddLine(size.Width / 2, -size.Height, 0, 0); path.AddLine(0, 0, -size.Width / 2, -size.Height); path.AddLine(-size.Width / 2, -size.Height, 0, -size.Height + num); path.AddLine(0, -size.Height + num, size.Width / 2, -size.Height); capinset = size.Height - num; break; case LineAnchor.Diamond: case LineAnchor.DiamondAnchor: path.AddLine(0, -size.Height, size.Width / 2, -size.Height / 2); path.AddLine(size.Width / 2, -size.Height / 2, 0, 0); path.AddLine(0, 0, -size.Width / 2, -size.Height / 2); path.AddLine(-size.Width / 2, -size.Height / 2, 0, -size.Height); break; case LineAnchor.Round: case LineAnchor.RoundAnchor: path.AddEllipse(new Rectangle(-size.Width / 2, -size.Height, size.Width, size.Height)); break; case LineAnchor.Rectangle: case LineAnchor.RectangleAnchor: path.AddRectangle(new Rectangle(-size.Width / 2, -size.Height, size.Width, size.Height)); break; case LineAnchor.RoundedRectangle: case LineAnchor.RoundedRectangleAnchor: num = size.Height / 4; path.AddPath(GetRoundedRectanglePath(new Rectangle(-size.Width / 2, -size.Height, size.Width, size.Height), num), true); break; } path.CloseFigure(); return path; }
public WordGlyph(Word word) { Word = word; var path = new GraphicsPath(); Figure = new SolidFigure(path); if (Word.Polygons != null && Word.Polygons.Count > 0) foreach (Polygon polygon in Word.Polygons) path.AddPath(Functions.GeneratePathFromPoints(polygon.ConvertToDrawingPoints()), false); Figures = new List<Figure>(); if (Word.Polygons != null && Word.Polygons.Count > 0) { foreach (Polygon polygon in Word.Polygons) Figures.Add(new SolidFigure(Functions.GeneratePathFromPoints(polygon.ConvertToDrawingPoints()))); } Figure.Path.CloseAllFigures(); ; Childs = new List<Glyph>(); }
static private GraphicsPath Complex () { GraphicsPath path = new GraphicsPath (); path.AddPath (Pie (), false); path.AddPath (Rectangle (), true); path.AddPath (Polygon (), false); return path; }
private GraphicsPath CreateClippingRegion(SvgClipPathElement clipPath) { GraphicsPath path = new GraphicsPath(); foreach (XmlNode node in clipPath.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } // Handle a case where the clip element has "use" element as a child... if (String.Equals(node.LocalName, "use")) { SvgUseElement useElement = (SvgUseElement)node; XmlElement refEl = useElement.ReferencedElement; if (refEl != null) { XmlElement refElParent = (XmlElement)refEl.ParentNode; useElement.OwnerDocument.Static = true; useElement.CopyToReferencedElement(refEl); refElParent.RemoveChild(refEl); useElement.AppendChild(refEl); foreach (XmlNode useChild in useElement.ChildNodes) { if (useChild.NodeType != XmlNodeType.Element) { continue; } SvgStyleableElement element = useChild as SvgStyleableElement; if (element != null && element.RenderingHint == SvgRenderingHint.Shape) { GraphicsPath childPath = CreatePath(element); if (childPath != null) { string clipRule = element.GetPropertyValue("clip-rule"); path.FillMode = (clipRule == "evenodd") ? FillMode.Alternate : FillMode.Winding; path.AddPath(childPath, true); } } } useElement.RemoveChild(refEl); useElement.RestoreReferencedElement(refEl); refElParent.AppendChild(refEl); useElement.OwnerDocument.Static = false; } } else { SvgStyleableElement element = node as SvgStyleableElement; if (element != null && element.RenderingHint == SvgRenderingHint.Shape) { GraphicsPath childPath = CreatePath(element); if (childPath != null) { string clipRule = element.GetPropertyValue("clip-rule"); path.FillMode = (clipRule == "evenodd") ? FillMode.Alternate : FillMode.Winding; path.AddPath(childPath, true); } } } } return path; }
private static GraphicsPath CreateWKBMultiPolygon(BinaryReader reader, WkbByteOrder byteOrder, Func<System.Windows.Point, System.Windows.Point> geoToPixel) { GraphicsPath gp = new GraphicsPath(); // Get the number of Polygons. int numPolygons = (int)ReadUInt32(reader, byteOrder); // Loop on the number of polygons. for (int i = 0; i < numPolygons; i++) { // read polygon header reader.ReadByte(); ReadUInt32(reader, byteOrder); // TODO: Validate type // Create the next polygon and add it to the array. gp.AddPath(CreateWKBPolygon(reader, byteOrder, geoToPixel), false); } //Create and return the MultiPolygon. return gp; }
internal static GraphicsPath GetDesignerPath(ActivityDesigner designer, Rectangle bounds, ActivityDesignerTheme designerTheme) { GraphicsPath designerPath = new GraphicsPath(); if (designer == GetSafeRootDesigner(designer.Activity.Site) && ((IWorkflowRootDesigner)designer).InvokingDesigner == null) { designerPath.AddRectangle(bounds); } else { // Work around: This should come from AmbientTheme.ArcDiameter // but it is internal int arcDiameter = 8; if (designerTheme != null && designerTheme.DesignerGeometry == DesignerGeometry.RoundedRectangle) designerPath.AddPath(ActivityDesignerPaint.GetRoundedRectanglePath(bounds, arcDiameter), true); else designerPath.AddRectangle(bounds); } return designerPath; }
public void AddPath () { GraphicsPath gpr = new GraphicsPath (); gpr.AddRectangle (new Rectangle (1, 1, 2, 2)); GraphicsPath gp = new GraphicsPath (); gp.AddPath (gpr, true); CheckRectangle (gp, 4); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = ClientRectangle; rect.Width--; rect.Height--; Rectangle innerRect = rect; innerRect.Inflate(-ClockWidth, -ClockWidth); using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(innerRect); using (LinearGradientBrush brush = new LinearGradientBrush( innerRect, Color.White, _baseColor, 70f)) { Blend blend = new Blend(); blend.Positions = new float[] { 0f, .2f, .3f, .5f, .7f, .8f, 1f }; blend.Factors = new float[] { 0f, .15f, .5f, .8f, .5f, .15f, 0f }; brush.Blend = blend; g.FillPath(brush, path); } using (Pen pen = new Pen(_borderColor, 5f)) { g.DrawPath(pen, path); } using (GraphicsPath outerPath = new GraphicsPath()) { outerPath.AddEllipse(rect); using (Pen pen = new Pen(_borderColor)) { g.DrawPath(pen, outerPath); } outerPath.AddPath(path, false); outerPath.CloseFigure(); using (LinearGradientBrush brush = new LinearGradientBrush( rect, SystemColors.ControlDark, Color.White, 135f)) { Blend blend = new Blend(); blend.Positions = new float[] { 0f, .1f, .3f, .5f, .7f, .9f, 1f }; blend.Factors = new float[] { 0f, .2f, .9f, 1f, .9f, .2f, 0f }; brush.Blend = blend; g.FillPath(brush, outerPath); } } } float radius = innerRect.Width / 2.0f; DrawTick(g, _tickVlue, radius, radius - ClockWidth); DrawFinger(g, innerRect, _fingerValue, radius); }
public void StartClose_AddPath_NoConnect () { GraphicsPath inner = new GraphicsPath (); inner.AddArc (10, 10, 100, 100, 90, 180); GraphicsPath path = new GraphicsPath (); path.AddLine (1, 1, 2, 2); path.AddPath (inner, false); path.AddLine (10, 10, 20, 20); byte[] types = path.PathTypes; // check first types Assert.AreEqual (0, types[0], "start/Line"); Assert.AreEqual (0, types[2], "start/Path"); // check last types Assert.AreEqual (3, types[path.PointCount - 3], "end/Path"); Assert.AreEqual (1, types[path.PointCount - 1], "end/Line"); }
private GraphicsPath GetOutline_Document(int index) { Rectangle rectTab = GetTabRectangle(index); rectTab.X -= rectTab.Height / 2; rectTab.Intersect(TabsRectangle); rectTab = RectangleToScreen(DrawHelper.RtlTransform(this, rectTab)); Rectangle rectPaneClient = DockPane.RectangleToScreen(DockPane.ClientRectangle); GraphicsPath path = new GraphicsPath(); GraphicsPath pathTab = GetTabOutline_Document(Tabs[index], true, true, true); path.AddPath(pathTab, true); if (DockPane.DockPanel.DocumentTabStripLocation == DocumentTabStripLocation.Bottom) { path.AddLine(rectTab.Right, rectTab.Top, rectPaneClient.Right, rectTab.Top); path.AddLine(rectPaneClient.Right, rectTab.Top, rectPaneClient.Right, rectPaneClient.Top); path.AddLine(rectPaneClient.Right, rectPaneClient.Top, rectPaneClient.Left, rectPaneClient.Top); path.AddLine(rectPaneClient.Left, rectPaneClient.Top, rectPaneClient.Left, rectTab.Top); path.AddLine(rectPaneClient.Left, rectTab.Top, rectTab.Right, rectTab.Top); } else { path.AddLine(rectTab.Right, rectTab.Bottom, rectPaneClient.Right, rectTab.Bottom); path.AddLine(rectPaneClient.Right, rectTab.Bottom, rectPaneClient.Right, rectPaneClient.Bottom); path.AddLine(rectPaneClient.Right, rectPaneClient.Bottom, rectPaneClient.Left, rectPaneClient.Bottom); path.AddLine(rectPaneClient.Left, rectPaneClient.Bottom, rectPaneClient.Left, rectTab.Bottom); path.AddLine(rectPaneClient.Left, rectTab.Bottom, rectTab.Right, rectTab.Bottom); } return path; }
public void Reverse_Path () { using (GraphicsPath gp = new GraphicsPath ()) { GraphicsPath path = new GraphicsPath (); path.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4); path.AddLine (1, 2, 3, 4); gp.AddPath (path, true); PointF[] bp = gp.PathPoints; byte[] expected = new byte[] { 0, 1, 1, 3, 3, 3 }; gp.Reverse (); PointF[] ap = gp.PathPoints; byte[] at = gp.PathTypes; int count = gp.PointCount; Assert.AreEqual (bp.Length, count, "PointCount"); for (int i = 0; i < count; i++) { Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ()); Assert.AreEqual (expected[i], at[i], "Type" + i.ToString ()); } } }
/// <summary> /// Makes a border path /// </summary> /// <param name="border">Desired border</param> /// <param name="b">Box wich the border corresponds</param> /// <param name="r"></param> /// <param name="isLineStart">Specifies if the border is for a starting line (no bevel on left)</param> /// <param name="isLineEnd">Specifies if the border is for an ending line (no bevel on right)</param> /// <returns>Beveled border path</returns> public static GraphicsPath GetBorderPath(Border border, Box b, RectangleF r, bool isLineStart, bool isLineEnd) { var pts = new PointF[4]; float bwidth = 0; GraphicsPath corner = null; switch (border) { case Border.Top: bwidth = b.ActualBorderTopWidth; pts[0] = RoundP(new PointF(r.Left + b.ActualCornerNW, r.Top), b); pts[1] = RoundP(new PointF(r.Right - b.ActualCornerNE, r.Top), b); pts[2] = RoundP(new PointF(r.Right - b.ActualCornerNE, r.Top + bwidth), b); pts[3] = RoundP(new PointF(r.Left + b.ActualCornerNW, r.Top + bwidth), b); if (isLineEnd && b.ActualCornerNE == 0f) pts[2].X -= b.ActualBorderRightWidth; if (isLineStart && b.ActualCornerNW == 0f) pts[3].X += b.ActualBorderLeftWidth; if (b.ActualCornerNW > 0f) corner = CreateCorner(b, r, 1); break; case Border.Right: bwidth = b.ActualBorderRightWidth; pts[0] = RoundP(new PointF(r.Right - bwidth, r.Top + b.ActualCornerNE), b); pts[1] = RoundP(new PointF(r.Right, r.Top + b.ActualCornerNE), b); pts[2] = RoundP(new PointF(r.Right, r.Bottom - b.ActualCornerSE), b); pts[3] = RoundP(new PointF(r.Right - bwidth, r.Bottom - b.ActualCornerSE), b); if (b.ActualCornerNE == 0f) pts[0].Y += b.ActualBorderTopWidth; if (b.ActualCornerSE == 0f) pts[3].Y -= b.ActualBorderBottomWidth; if (b.ActualCornerNE > 0f) corner = CreateCorner(b, r, 2); break; case Border.Bottom: bwidth = b.ActualBorderBottomWidth; pts[0] = RoundP(new PointF(r.Left + b.ActualCornerSW, r.Bottom - bwidth), b); pts[1] = RoundP(new PointF(r.Right - b.ActualCornerSE, r.Bottom - bwidth), b); pts[2] = RoundP(new PointF(r.Right - b.ActualCornerSE, r.Bottom), b); pts[3] = RoundP(new PointF(r.Left + b.ActualCornerSW, r.Bottom), b); if (isLineStart && b.ActualCornerSW == 0f) pts[0].X += b.ActualBorderLeftWidth; if (isLineEnd && b.ActualCornerSE == 0f) pts[1].X -= b.ActualBorderRightWidth; if (b.ActualCornerSE > 0f) corner = CreateCorner(b, r, 3); break; case Border.Left: bwidth = b.ActualBorderLeftWidth; pts[0] = RoundP(new PointF(r.Left, r.Top + b.ActualCornerNW), b); pts[1] = RoundP(new PointF(r.Left + bwidth, r.Top + b.ActualCornerNW), b); pts[2] = RoundP(new PointF(r.Left + bwidth, r.Bottom - b.ActualCornerSW), b); pts[3] = RoundP(new PointF(r.Left, r.Bottom - b.ActualCornerSW), b); if (b.ActualCornerNW == 0f) pts[1].Y += b.ActualBorderTopWidth; if (b.ActualCornerSW == 0f) pts[2].Y -= b.ActualBorderBottomWidth; if (b.ActualCornerSW > 0f) corner = CreateCorner(b, r, 4); break; } var path = new GraphicsPath(pts, new[] { (byte) PathPointType.Line, (byte) PathPointType.Line, (byte) PathPointType.Line, (byte) PathPointType.Line }); if (corner != null) { path.AddPath(corner, true); } return path; }
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius) { int diameter = radius; Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter)); //GraphicsPath path = new GraphicsPath(); path = new GraphicsPath(); path2 = new GraphicsPath(); ////左上角 //path.AddArc(arcRect, 180, 90); ////右上角 //arcRect.X = rect.Right - diameter; //path.AddArc(arcRect,270,90); ////右下角 //arcRect.Y = rect.Bottom - diameter; //path.AddArc(arcRect,0,90); ////左下角 //arcRect.X = rect.Left; //path.AddArc(arcRect,90,90); #region 添加扇形Example /* private void AddPieExample(PaintEventArgs e) { // Create a pie slice of a circle using the AddPie method. GraphicsPath myPath = new GraphicsPath(); myPath.AddPie(20, 20, 70, 70, -45, 90); // Draw the path to the screen. Pen myPen = new Pen(Color.Black, 2); e.Graphics.DrawPath(myPen, myPath); } */ #endregion #region 添加string Example Rectangle rect1 = new Rectangle(60, 17, 115, 30); string stringText = "Sample Text"; FontFamily family = new FontFamily("Arial"); int fontStyle = (int)FontStyle.Italic; int emSize = 9; // path2.AddString(stringText, family, fontStyle, emSize, rect1, format); #endregion //Point origin = new Point(20, 20); StringFormat format = StringFormat.GenericDefault; path.AddEllipse( 0, 0, 65,65); //path2.AddPie(25, 18, 40, 30, -45, 70); path2.AddRectangle(rect1); path2.AddPath(path, true); path.CloseFigure(); path2.CloseFigure(); return path2; }