public static Image GetRegionImage(Image surfaceImage, GraphicsPath regionFillPath, GraphicsPath regionDrawPath, SurfaceOptions options) { if (regionFillPath != null) { Image img; Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds()); Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based(); Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle); using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone()) { MoveGraphicsPath(gp, -Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y)); img = ImageHelpers.CropImage(surfaceImage, newRegionArea, gp); if (options.DrawBorder) { GraphicsPath gpOutline = regionDrawPath ?? regionFillPath; using (GraphicsPath gp2 = (GraphicsPath)gpOutline.Clone()) { MoveGraphicsPath(gp2, -Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y)); img = ImageHelpers.DrawOutline(img, gp2); } } } return img; } return null; }
///<summary> /// Converts a <see cref="GraphicsPath"/> to a Geometry, flattening it first. ///</summary> /// <param name="shp">The <see cref="GraphicsPath"/></param> /// <param name="flatness">The flatness parameter to use</param> /// <param name="geomFact">The GeometryFactory to use</param> /// <returns>A Geometry representing the shape</returns> public static IGeometry Read(GraphicsPath shp, double flatness, IGeometryFactory geomFact) { var path = (GraphicsPath)shp.Clone(); path.Flatten(InvertY, (float)flatness); var pathIt = new GraphicsPathIterator(path); return Read(pathIt, geomFact); }
public static Image ApplyRegionPathToImage(Image backgroundImage, GraphicsPath regionFillPath, RegionCaptureOptions options) { if (backgroundImage != null && regionFillPath != null) { Image img; Rectangle regionArea = Rectangle.Round(regionFillPath.GetBounds()); Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based(); Rectangle newRegionArea = Rectangle.Intersect(regionArea, screenRectangle); using (GraphicsPath gp = (GraphicsPath)regionFillPath.Clone()) { using (Matrix matrix = new Matrix()) { gp.CloseFigure(); matrix.Translate(-Math.Max(0, regionArea.X), -Math.Max(0, regionArea.Y)); gp.Transform(matrix); } img = ImageHelpers.CropImage(backgroundImage, newRegionArea, gp); } return img; } return null; }
public PathGradientBrush(GraphicsPath path) { if (path == null) { throw new ArgumentNullException("path"); } var pathClone = (GraphicsPath)path.Clone(); pathClone.CloseAllFigures(); pathClone.Flatten(); pathPoints = pathClone.PathPoints; // make sure we have a closed path if (pathPoints[0] != pathPoints[pathPoints.Length - 1]) { var first = pathPoints [0]; var temps = new PointF[pathPoints.Length + 1]; for (var p = 0; p < pathPoints.Length; p++) { temps[p] = pathPoints[p]; } temps[temps.Length - 1] = first; pathPoints = temps; } rectangle = GeomUtilities.PolygonBoundingBox(pathPoints); centerPoint = GeomUtilities.PolygonCentroid(pathPoints); wrapMode = WrapMode.Clamp; // verify the winding of the polygon so that we cen calculate the // edges correctly var vt1 = pathPoints [0]; var vt2 = centerPoint; var vt3 = pathPoints [1]; var pWinding = vt1.X * vt2.Y - vt2.X * vt1.Y; pWinding += vt2.X * vt3.Y - vt3.X * vt2.Y; pWinding += vt3.X * vt1.Y - vt1.X * vt3.Y; // Positive is counter clockwise if (pWinding < 0) { polygonWinding = FillMode.Alternate; } blend = new Blend(1); blend.Factors = new float[] { 1.0f }; blend.Positions = new float[] { 1.0f }; }
public GraphicsPathIterator(GraphicsPath path) { // We do not have to have a path if (path == null) { path = new GraphicsPath(); } else { // We will clone the path so if things change it will not effect the iterator this.path = (GraphicsPath)path.Clone(); } }
public static GraphicsPath ClipPath(GraphicsPath subjectPath, CombineMode combineMode, GraphicsPath clipPath) { GpcWrapper.Polygon.Validate(combineMode); GpcWrapper.Polygon basePoly = new GpcWrapper.Polygon(subjectPath); GraphicsPath clipClone = (GraphicsPath)clipPath.Clone(); clipClone.CloseAllFigures(); GpcWrapper.Polygon clipPoly = new GpcWrapper.Polygon(clipClone); clipClone.Dispose(); GpcWrapper.Polygon clippedPoly = GpcWrapper.Polygon.Clip(combineMode, basePoly, clipPoly); GraphicsPath returnPath = clippedPoly.ToGraphicsPath(); returnPath.CloseAllFigures(); return returnPath; }
protected void DrawBwShape(Graphics g, GraphicsPath gpPass, float flOpacity, float flOutlineWidth, Color clBackground, Color clForecolour) { if (flOpacity > 0.0F) { GraphicsPath gp = (GraphicsPath)gpPass.Clone(); Matrix m = new Matrix(); m.Translate(this.m_pntDrawOffset.X, this.m_pntDrawOffset.Y); gp.Transform(m); Pen pen = new Pen(Color.FromArgb((int)(255.0F * flOpacity), clBackground), flOutlineWidth); pen.LineJoin = LineJoin.Round; g.DrawPath(pen, gp); SolidBrush brush = new SolidBrush(Color.FromArgb((int)(255.0F * flOpacity), clForecolour)); g.FillPath(brush, gp); brush.Dispose(); pen.Dispose(); m.Dispose(); gp.Dispose(); } }
public void Flatten_Arc () { GraphicsPath path = new GraphicsPath (); path.AddArc (0f, 0f, 100f, 100f, 30, 30); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); CompareFlats (path, clone); }
public void DrawPath(Graphics g, GraphicsPath path) { if(!BackColor.IsEmpty) { g.FillPath(new SolidBrush(BackColor), path); } if(!ForeColor.IsEmpty) { GraphicsPath cpath = (GraphicsPath)path.Clone(); cpath.Widen(new Pen(ForeColor, Thickness)); g.FillPath(new SolidBrush(ForeColor), path); } else g.DrawPath(Pens.Black, path); }
/// <summary> /// The draw shadow and path. /// </summary> /// <param name="parameter"> /// The parameter. /// </param> /// <param name="g"> /// The g. /// </param> /// <param name="path"> /// The path. /// </param> private static void DrawShadowAndPath(MakeBitmapParameter parameter, Graphics g, GraphicsPath path) { if (parameter.ShadowWidth > 0) { var shadowPath = (GraphicsPath)path.Clone(); for (int k = 0; k < parameter.ShadowWidth; k++) { var translateMatrix = new Matrix(); translateMatrix.Translate(1, 1); shadowPath.Transform(translateMatrix); var p1 = new Pen(Color.FromArgb(parameter.ShadowAlpha, parameter.ShadowColor), parameter.BorderWidth); SetLineJoin(parameter.LineJoin, p1); g.DrawPath(p1, shadowPath); p1.Dispose(); } } if (parameter.BorderWidth > 0) { var p1 = new Pen(parameter.BorderColor, parameter.BorderWidth); SetLineJoin(parameter.LineJoin, p1); g.DrawPath(p1, path); p1.Dispose(); } }
public Region(GraphicsPath path) { var clonePath = (GraphicsPath)path.Clone(); regionObject = clonePath; regionPath = new CGPath (); PlotPath (clonePath); clonePath.Flatten (); var flatPath = PointFArrayToIntArray (clonePath.PathPoints, scale); solution.Add (flatPath); regionList.Add (new RegionEntry (RegionType.Path, clonePath, flatPath)); regionBounds = regionPath.BoundingBox; }
public void Flatten_Polygon () { GraphicsPath path = new GraphicsPath (); path.AddPolygon (new Point[4] { new Point (0, 0), new Point (10, 10), new Point (20, 20), new Point (40, 40) }); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); ComparePaths (path, clone); }
public void Flatten_Line () { GraphicsPath path = new GraphicsPath (); path.AddLine (10f, 10f, 100f, 100f); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); ComparePaths (path, clone); }
/// <summary> /// Constructs a new PPath wrapping the given /// <see cref="System.Drawing.Drawing2D.GraphicsPath"> /// System.Drawing.Drawing2D.GraphicsPath</see>. /// </summary> /// <param name="path">The path to wrap.</param> public PPath(GraphicsPath path) { pen = DEFAULT_PEN; this.path = (GraphicsPath)path.Clone(); UpdateBoundsFromPath(); }
public void Paint(GraphicsPath path, Graphics g, int time, float opacity) { int num1 = 0; int num2 = 0; AnimFunc.CreateAnimateValues(this, time, out num1, out num2); path.FillMode = FillMode.Alternate; g.SmoothingMode = base.OwnerDocument.SmoothingMode; SpreadMethods methods1 = this.SpreadMethod; bool flag1 = this.Units == Units.UserSpaceOnUse; float single1 = this.CX; float single2 = this.CY; float single3 = this.R; float single4 = this.FX; float single5 = this.FY; PointF[] tfArray2 = new PointF[7] { new PointF(single1, single2), new PointF(single1 + single3, single2), new PointF(single1 + (single3 * ((float) Math.Sin(1.8325957145940459))), single2 + (single3 * ((float) Math.Cos(1.8325957145940459)))), new PointF(single1 + (single3 * ((float) Math.Sin(1.3089969389957472))), single2 + (single3 * ((float) Math.Cos(1.3089969389957472)))), new PointF(single1, single2 + single3), PointF.Empty, PointF.Empty } ; this.boundsPoints = tfArray2; GraphicsPath path1 = this.gradientpath; path1.Reset(); path1.AddEllipse((float) (single1 - single3), (float) (single2 - single3), (float) (2f * single3), (float) (2f * single3)); RectangleF ef1 = RectangleF.Empty; RectangleF ef2 = PathFunc.GetBounds(path); RectangleF ef3 = RectangleF.Empty; this.coord.Reset(); if (flag1) { ef3 = ((SVG) base.OwnerDocument.DocumentElement).ViewPort; } else { ef2 = new RectangleF(0f, 0f, 1f, 1f); ef3 = ef2; ef1 = PathFunc.GetBounds(path); this.coord.Translate(ef1.X, ef1.Y); this.coord.Scale(ef1.Width, ef1.Height); } //if (this.stops.Count==0)return; ColorBlend blend1 = new ColorBlend(this.Stops.Count); Color[] colorArray1 = new Color[this.Stops.Count]; float[] singleArray1 = new float[this.Stops.Count]; SvgElementCollection collection1 = this.Stops; for (int num3 = 0; num3 < collection1.Count; num3++) { GradientStop stop1 = (GradientStop) collection1[num3]; AnimFunc.CreateAnimateValues(stop1, time, out num1, out num2); int num4 = 0xff; if ((stop1.Opacity >= 0f) && (stop1.Opacity <= 255f)) { if (stop1.Opacity <= 1f) { num4 = (int) (stop1.Opacity * 255f); } else { num4 = (int) stop1.Opacity; } } num4 = (int) Math.Min((float) (opacity * 255f), (float) num4); Color color1 = stop1.Color; float single6 = Math.Min((float) 1f, Math.Max((float) 0f, stop1.ColorOffset)); colorArray1[num3] = Color.FromArgb(num4, color1.R, color1.G, color1.B); singleArray1[num3] = single6; } float[] singleArray2 = (float[]) singleArray1.Clone(); Color[] colorArray2 = (Color[]) colorArray1.Clone(); Array.Sort(singleArray2, colorArray2); Color color2 = colorArray2[0]; Color color3 = colorArray2[colorArray2.Length - 1]; if (singleArray2[0] != 0f) { float[] singleArray3 = (float[]) singleArray2.Clone(); Color[] colorArray3 = (Color[]) colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; colorArray2 = new Color[colorArray2.Length + 1]; colorArray3.CopyTo(colorArray2, 1); singleArray3.CopyTo(singleArray2, 1); singleArray2[0] = 0f; colorArray2[0] = color2; } if (singleArray2[singleArray2.Length - 1] != 1f) { float[] singleArray4 = (float[]) singleArray2.Clone(); Color[] colorArray4 = (Color[]) colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; singleArray4.CopyTo(singleArray2, 0); singleArray2[singleArray2.Length - 1] = 1f; colorArray2 = new Color[colorArray2.Length + 1]; colorArray4.CopyTo(colorArray2, 0); colorArray2[colorArray2.Length - 1] = color3; } if (methods1 == SpreadMethods.Pad) { float single7 = Math.Min((float) (single1 - single3), ef2.X); float single8 = Math.Min((float) (single2 - single3), ef2.Y); float single9 = Math.Max(single3, (float) (ef2.Width / 2f)); float single10 = this.cx - single3; float single11 = this.r; for (int num5 = 0; num5 < singleArray2.Length; num5++) { singleArray2[num5] = ((single10 + (single11 * singleArray2[num5])) - single7) / single9; } if (singleArray2[0] != 0f) { float[] singleArray5 = (float[]) singleArray2.Clone(); Color[] colorArray5 = (Color[]) colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; colorArray2 = new Color[colorArray2.Length + 1]; colorArray5.CopyTo(colorArray2, 1); singleArray5.CopyTo(singleArray2, 1); singleArray2[0] = 0f; colorArray2[0] = color2; } if (singleArray2[singleArray2.Length - 1] != 1f) { float[] singleArray6 = (float[]) singleArray2.Clone(); Color[] colorArray6 = (Color[]) colorArray2.Clone(); singleArray2 = new float[singleArray2.Length + 1]; singleArray6.CopyTo(singleArray2, 0); singleArray2[singleArray2.Length - 1] = 1f; colorArray2 = new Color[colorArray2.Length + 1]; colorArray6.CopyTo(colorArray2, 0); colorArray2[colorArray2.Length - 1] = color3; } } Array.Reverse(colorArray2); Array.Reverse(singleArray2); for (int num6 = 0; num6 < singleArray2.Length; num6++) { singleArray2[num6] = 1f - singleArray2[num6]; } Matrix matrix1 = this.Transform.Matrix.Clone(); path1 = (GraphicsPath) this.gradientpath.Clone(); path1.Transform(matrix1); this.brush = new PathGradientBrush(path1); blend1.Colors = colorArray2; blend1.Positions = singleArray2; this.brush.InterpolationColors = blend1; if (methods1 == SpreadMethods.Reflect) { this.brush.WrapMode = WrapMode.Tile; } else if (methods1 == SpreadMethods.Repeat) { this.brush.WrapMode = WrapMode.TileFlipXY; } else { this.brush.WrapMode = WrapMode.Clamp; } if (AttributeFunc.FindAttribute("fx", this).ToString() == string.Empty) { single4 = this.CX; } if (AttributeFunc.FindAttribute("fy", this).ToString() == string.Empty) { single5 = this.CY; } PointF[] tfArray3 = new PointF[1] { new PointF(single4, single5) } ; PointF[] tfArray1 = tfArray3; matrix1.TransformPoints(tfArray1); this.brush.CenterPoint = tfArray1[0]; g.FillPath(new SolidBrush(colorArray2[0]), path); GraphicsContainer container1 = g.BeginContainer(); g.Transform = this.coord; Matrix matrix2 = this.coord.Clone(); matrix2.Invert(); GraphicsPath path2 = (GraphicsPath) path.Clone(); path2.Transform(matrix2); g.FillPath(this.brush, path2); g.EndContainer(container1); this.pretime = -1; }
/// <summary> /// Paints the bundle on the canvas /// </summary> /// <param name="g"></param> public override void Paint(Graphics g) { GraphicsPath path = new GraphicsPath(); GraphicsPath shadow = new GraphicsPath(); g.SmoothingMode = SmoothingMode.HighQuality; //the shadow switch (mCurveType) { case MultiPointType.Straight: //g.DrawLines(ArtPalette.BlackPen, mPoints); path.AddLines(mPoints); break; case MultiPointType.Polygon: //g.DrawPolygon(ArtPalette.BlackPen, mPoints); path.AddPolygon(mPoints); break; case MultiPointType.Curve: //note that you can specify a tension of the curve here (greater than 0.0F) //g.DrawCurve(ArtPalette.BlackPen, mPoints); path.AddCurve(mPoints); break; } if (ArtPalette.EnableShadows) { shadow = (GraphicsPath) path.Clone(); Matrix m = new Matrix(); m.Translate(5, 5); shadow.Transform(m); g.FillPath(ArtPalette.ShadowBrush, shadow); } g.FillPath(this.mPaintStyle.GetBrush(Rectangle), path); if (IsSelected || Hovered) { g.DrawPath(ArtPalette.HighlightPen, path); } else { g.DrawPath(this.mPenStyle.DrawingPen(), path); } }
private void Widen2(Graphics g) { // Create a path and add two ellipses. GraphicsPath myPath = new GraphicsPath(); myPath.AddLines(new Point[] { new Point(20, 10), new Point(50, 50), new Point(80, 10) }); myPath.AddPolygon(new Point[] { new Point(20, 30), new Point(50, 70), new Point(80, 30) }); var cx = Bounds.Width; var cy = Bounds.Height; var clr = Color.Aquamarine; g.ScaleTransform((float)(cx / 300f), (float)(cy / 200f)); for (int i = 0; i < 6; i++) { GraphicsPath pathClone = (GraphicsPath)myPath.Clone(); Matrix matrix = new Matrix(); Pen penThin = new Pen(clr, 1); Pen penThick = new Pen(clr, 5); Pen penWiden = new Pen(clr, 7.5f); Brush brush = new SolidBrush(clr); matrix.Translate((i % 3) * 100, (i / 3) * 100); if (i < 3) pathClone.Transform(matrix); else pathClone.Widen(penWiden, matrix); switch (i % 3) { case 0: g.DrawPath(penThin, pathClone); break; case 1: g.DrawPath(penThick, pathClone); break; case 2: g.FillPath(brush, pathClone); break; } } }
public void IsOutlineVisible1(Graphics g) { GraphicsPath myPath = new GraphicsPath(); Rectangle rect = new Rectangle(20, 20, 100, 100); myPath.AddRectangle(rect); Pen testPen = new Pen(Color.AliceBlue, 20); var widePath = (GraphicsPath)myPath.Clone(); widePath.Widen(testPen); g.FillPath(Brushes.Wheat, widePath); g.DrawPath(Pens.Black, myPath); var point = new PointF(100, 50); bool visible = myPath.IsOutlineVisible(point, testPen, g); g.FillRectangle(Brushes.Red, new RectangleF(point.X, point.Y, 2, 2)); // Show the result. g.DrawString("Visible = " + visible, new Font("Arial", 12), Brushes.Red, point.X + 10, point.Y); point.X = 115; point.Y = 80; visible = myPath.IsOutlineVisible(point, testPen, g); g.FillRectangle(Brushes.Green, new RectangleF(point.X, point.Y, 2, 2)); // Show the result. g.DrawString("Visible = " + visible, new Font("Arial", 12), Brushes.Green, point.X + 10, point.Y); }
public void Flatten_Curve () { GraphicsPath path = new GraphicsPath (); path.AddCurve (new Point[4] { new Point (0, 0), new Point (40, 20), new Point (20, 40), new Point (40, 40) }); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); CompareFlats (path, clone); }
public GraphicsPath TransformPath(GraphicsPath path) { var p = (GraphicsPath)path.Clone(); p.Flatten(_Transform, 0.1f); return p; }
public void Flatten_Ellipse () { GraphicsPath path = new GraphicsPath (); path.AddEllipse (10f, 10f, 100f, 100f); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); CompareFlats (path, clone); }
// While still in design this function draws directly to the component. // Once design is complete it will paint to a image, then the image painted to the component for a little speed boost. private void DrawKillCircles(Graphics g, Kill kKill, KillDisplayDetails kddKillDetails) { PointF pntLineStart = new PointF((float)kKill.KillerLocation.X, (float)kKill.KillerLocation.Y); PointF pntLineEnd = new PointF((float)kKill.VictimLocation.X, (float)kKill.VictimLocation.Y); PointF pntLineHalfway = new PointF(pntLineStart.X - (pntLineStart.X - pntLineEnd.X) / 2, pntLineStart.Y - (pntLineStart.Y - pntLineEnd.Y) / 2 - 3); PointF pntLineHalfway2 = new PointF(pntLineStart.X - (pntLineStart.X - pntLineEnd.X) / 2, pntLineStart.Y - (pntLineStart.Y - pntLineEnd.Y) / 2 - 4); LinearGradientBrush killBrush = this.GetKillColour(this.KillColours, kKill, kddKillDetails); GraphicsPath gpKillCircles = new GraphicsPath(); gpKillCircles.AddEllipse(new Rectangle(kKill.KillerLocation.X - this.ErrorRadius, kKill.KillerLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); gpKillCircles.AddEllipse(new Rectangle(kKill.VictimLocation.X - this.ErrorRadius, kKill.VictimLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); gpKillCircles.FillMode = FillMode.Winding; //GraphicsPath gpKill = new GraphicsPath(); GraphicsPath gpKill = (GraphicsPath)gpKillCircles.Clone(); gpKill.AddClosedCurve(new PointF[] { pntLineStart, pntLineHalfway, pntLineEnd, pntLineHalfway2 }); //gpKill.AddEllipse(new Rectangle(kKill.KillerLocation.X - this.ErrorRadius, kKill.KillerLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); //gpKill.AddEllipse(new Rectangle(kKill.VictimLocation.X - this.ErrorRadius, kKill.VictimLocation.Y - this.ErrorRadius, this.ErrorRadius * 2, this.ErrorRadius * 2)); gpKill.FillMode = FillMode.Winding; GraphicsPath gpKillOutline = (GraphicsPath)gpKill.Clone(); //GraphicsPath gpKillOutline = new GraphicsPath(gpKill.PathPoints, gpKill.PathTypes); Matrix gpKillMatrix = new Matrix(); gpKillOutline.Widen(this.m_pTwoWidth, gpKillMatrix, 0.01F); Region reKillOutline = new Region(gpKillOutline); reKillOutline.Exclude(gpKill); reKillOutline.Exclude(gpKillCircles); Region reKill = new Region(gpKill); reKill.Union(gpKillCircles); //Region reKillDropshadow = new Region(gpKill); //reKillDropshadow.Union(gpKillCircles); //reKillDropshadow.Union(reKillOutline); //reKillDropshadow.Translate(0.4F, 1.0F); if (reKill.IsVisible(this.ClientPointToGame(this.PointToClient(Cursor.Position))) == true) { kddKillDetails.IsMouseOver = true; kddKillDetails.Opacity = 1.0F; } else { kddKillDetails.IsMouseOver = false; } //g.FillRegion(new SolidBrush(Color.FromArgb((int)(64.0F * kddKillDetails.Opacity), Color.Black)), reKillDropshadow); g.FillRegion(killBrush, reKill); g.FillRegion(new SolidBrush(Color.FromArgb((int)(255.0F * kddKillDetails.Opacity), Color.Black)), reKillOutline); if (this.LoadedMapImagePack != null) { Image imgDeathIcon = null; if (kKill.Headshot == true) { imgDeathIcon = this.LoadedMapImagePack.CompensateImageRotation(this.LoadedMapImagePack.GetIcon("Headshot")); } else { imgDeathIcon = this.LoadedMapImagePack.CompensateImageRotation(this.LoadedMapImagePack.GetIcon("Death")); } if (imgDeathIcon != null) { ColorMatrix colormatrix = new ColorMatrix(); colormatrix.Matrix00 = 1.0F; colormatrix.Matrix11 = 1.0F; colormatrix.Matrix22 = 1.0F; colormatrix.Matrix33 = kddKillDetails.Opacity; colormatrix.Matrix44 = 1.0F; ImageAttributes imgattr = new ImageAttributes(); imgattr.SetColorMatrix(colormatrix); Rectangle destRect = new Rectangle((int)pntLineEnd.X - 12, (int)pntLineEnd.Y - 12, 24, 24); g.DrawImage(imgDeathIcon, destRect, 0, 0, imgDeathIcon.Width, imgDeathIcon.Height, GraphicsUnit.Pixel, imgattr); imgattr.Dispose(); imgDeathIcon.Dispose(); } } this.DrawMapText(g, kKill.Victim.SoldierName, kKill.VictimLocation, 16, kddKillDetails.Opacity); this.DrawMapText(g, kKill.Killer.SoldierName, kKill.KillerLocation, 16, kddKillDetails.Opacity); killBrush.Dispose(); gpKillCircles.Dispose(); gpKill.Dispose(); gpKillOutline.Dispose(); gpKillMatrix.Dispose(); reKill.Dispose(); }
public void Flatten_Pie () { GraphicsPath path = new GraphicsPath (); path.AddPie (0, 0, 100, 100, 30, 30); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); CompareFlats (path, clone); }
protected override void GeneratePreviewReal() { if (listViewStyles.SelectedItems.Count != 1) return; if (pictureBoxPreview.Image != null) pictureBoxPreview.Image.Dispose(); var bmp = new Bitmap(pictureBoxPreview.Width, pictureBoxPreview.Height); using (Graphics g = Graphics.FromImage(bmp)) { // Draw background const int rectangleSize = 9; for (int y = 0; y < bmp.Height; y += rectangleSize) { for (int x = 0; x < bmp.Width; x += rectangleSize) { Color c = Color.WhiteSmoke; if (y % (rectangleSize * 2) == 0) { if (x % (rectangleSize * 2) == 0) c = Color.LightGray; } else { if (x % (rectangleSize * 2) != 0) c = Color.LightGray; } g.FillRectangle(new SolidBrush(c), x, y, rectangleSize, rectangleSize); } } // Draw text Font font; try { font = new Font(comboBoxFontName.Text, (float)numericUpDownFontSize.Value); } catch { font = new Font(Font, FontStyle.Regular); } g.TextRenderingHint = TextRenderingHint.AntiAlias; g.SmoothingMode = SmoothingMode.AntiAlias; var sf = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near }; var path = new GraphicsPath(); bool newLine = false; var sb = new StringBuilder(); sb.Append("This is a test!"); var measuredWidth = TextDraw.MeasureTextWidth(font, sb.ToString(), checkBoxFontBold.Checked) + 1; var measuredHeight = TextDraw.MeasureTextHeight(font, sb.ToString(), checkBoxFontBold.Checked) + 1; float left = 5; if (radioButtonTopLeft.Checked || radioButtonMiddleLeft.Checked || radioButtonBottomLeft.Checked) left = (float)numericUpDownMarginLeft.Value; else if (radioButtonTopRight.Checked || radioButtonMiddleRight.Checked || radioButtonBottomRight.Checked) left = bmp.Width - (measuredWidth + ((float)numericUpDownMarginRight.Value)); else left = ((float)(bmp.Width - measuredWidth * 0.8 + 15) / 2); float top = 2; if (radioButtonTopLeft.Checked || radioButtonTopCenter.Checked || radioButtonTopRight.Checked) top = (float)numericUpDownMarginVertical.Value; else if (radioButtonMiddleLeft.Checked || radioButtonMiddleCenter.Checked || radioButtonMiddleRight.Checked) top = (bmp.Height - measuredHeight) / 2; else top = bmp.Height - measuredHeight - ((int)numericUpDownMarginVertical.Value); top -= (int)numericUpDownShadowWidth.Value; if (radioButtonTopCenter.Checked || radioButtonMiddleCenter.Checked || radioButtonBottomCenter.Checked) left -= (int)(numericUpDownShadowWidth.Value / 2); const int leftMargin = 0; int pathPointsStart = -1; if (radioButtonOpaqueBox.Checked) { if (_isSubStationAlpha) g.FillRectangle(new SolidBrush(panelBackColor.BackColor), left, top, measuredWidth + 3, measuredHeight + 3); else g.FillRectangle(new SolidBrush(panelOutlineColor.BackColor), left, top, measuredWidth + 3, measuredHeight + 3); } TextDraw.DrawText(font, sf, path, sb, checkBoxFontItalic.Checked, checkBoxFontBold.Checked, checkBoxFontUnderline.Checked, left, top, ref newLine, leftMargin, ref pathPointsStart); int outline = (int)numericUpDownOutline.Value; // draw shadow if (numericUpDownShadowWidth.Value > 0 && radioButtonOutline.Checked) { var shadowPath = (GraphicsPath)path.Clone(); for (int i = 0; i < (int)numericUpDownShadowWidth.Value; i++) { var translateMatrix = new Matrix(); translateMatrix.Translate(1, 1); shadowPath.Transform(translateMatrix); using (var p1 = new Pen(Color.FromArgb(250, panelBackColor.BackColor), outline)) g.DrawPath(p1, shadowPath); } } if (outline > 0 && radioButtonOutline.Checked) { if (_isSubStationAlpha) g.DrawPath(new Pen(panelBackColor.BackColor, outline), path); else g.DrawPath(new Pen(panelOutlineColor.BackColor, outline), path); } g.FillPath(new SolidBrush(panelPrimaryColor.BackColor), path); } pictureBoxPreview.Image = bmp; }
public void Flatten_Rectangle () { GraphicsPath path = new GraphicsPath (); path.AddRectangle (new Rectangle (0, 0, 100, 100)); GraphicsPath clone = (GraphicsPath) path.Clone (); path.Flatten (); ComparePaths (path, clone); }
private void DrawDocWndVS2005(Graphics g, Pen penBlack, Pen penWhite, ref float n, ref int y, ref int h, ref int y0, StringFormat sf) { #region Document drawing - VS2005 Brush textBrush; Font textFont; y0 = DockPadding.Top - bottomDock; this.BackColor = SystemColors.Control; g.Clear(SystemColors.Control); sf.Alignment = StringAlignment.Center; showIcons = false; // Draw bounding rectangle. g.DrawRectangle(SystemPens.ControlDark, dockOffsetL, dockOffsetT, this.Width - 1 - dockOffsetL - dockOffsetR, this.Height - 1 - dockOffsetT - dockOffsetB); // Draw background rectangle. g.DrawLine(SystemPens.ControlDark, 1 + dockOffsetL, y0 + bottomDock - 4, Width - 2 - dockOffsetR, y0 + bottomDock - 4); // Draw each header tab. n = DockPadding.Left - 1 + 3; y = 6; h = -bottomDock + 9; int xMax = this.Width - 8 - 3 * 14; panelOverflow = false; for (int i = 0; i < panList.Count; i++) { DockPanel panel = panList[i] as DockPanel; if (i < panelOffset) { panel.TabRect = RectangleF.Empty; continue; } textFont = new Font(this.Font, FontStyle.Bold); SizeF panelSize = MeasurePanel(panel, g, false, textFont); if (n + (int)panelSize.Width >= xMax - 2) { panelOverflow = true; panelSize.Width = xMax - n - 2; } // Create graphic paths GraphicsPath path = new GraphicsPath(); // ...right border path.AddLine(n + panelSize.Width + 6, y0 + y + 2, n + panelSize.Width + 6, y0 + y - h - 1); // ...top border path.AddLine(n + panelSize.Width + 6, y0 + y + 2, n + panelSize.Width + 4, y0 + y); path.AddLine(n + panelSize.Width + 4, y0 + y, n + 18, y0 + y); path.AddLine(n + 18, y0 + y, n + 13, y0 + y + 3); // ...right line path.AddLine(n, y0 + bottomDock - 4, n + 13, y0 + y + 3); GraphicsPath closedPath = path.Clone() as GraphicsPath; // ...bottom line closedPath.AddLine(n, y0 + bottomDock - 4, n + panelSize.Width + 6, y0 + bottomDock - 4); panel.TabRect = closedPath.GetBounds(); if (panel == activePanel) g.FillPath(new SolidBrush(Color.White), closedPath); else g.FillPath(SystemBrushes.Control, closedPath); g.DrawPath(SystemPens.ControlDark, path); // Setup text. if ((panel == activePanel) && (this.ContainsFocus)) textFont = new Font(this.Font, FontStyle.Bold); else textFont = new Font(this.Font, FontStyle.Regular); textBrush = new SolidBrush(Color.Black); // Panel text. RectangleF rc = new RectangleF(n + 12, y0 + y - 3 + (bottomDock - 2 - panelSize.Height) / 2, panelSize.Width - 10, panelSize.Height); g.DrawString(panel.Form.Text, textFont, textBrush, rc, sf); n += (int)panelSize.Width; if (panelOverflow) break; } if (panelOverflow) { // Redraw background. g.FillRectangle(SystemBrushes.Control, xMax, y0 + 4, Width - 2 - xMax, bottomDock - 8); // Activate buttons. if (panelOffset < panList.Count - 1) btnTabR.Enabled = true; else btnTabR.Enabled = false; } else { btnTabR.Enabled = false; } sf.Alignment = StringAlignment.Near; #endregion }
private void DrawBackOneNote(RenderContext context, Rectangle gradientRect, Color backColor1, Color backColor2, PaletteColorStyle backColorStyle, float backColorAngle, VisualOrientation orientation, GraphicsPath path) { // Draw entire background in first color using (Brush backBrush = CreateColorBrush(gradientRect, backColor1, backColor1, backColorStyle, backColorAngle, orientation)) { context.Graphics.FillPath(backBrush, path); } // Make a copy of the original path, so we can change it GraphicsPath insetPath = (GraphicsPath)path.Clone(); // Offset by 1.5 pixels so the background shows around two of // the edges of the background we are about to draw switch (orientation) { case VisualOrientation.Top: insetPath.Transform(new Matrix(1, 0, 0, 1, 1.5f, 1.5f)); break; case VisualOrientation.Bottom: case VisualOrientation.Left: insetPath.Transform(new Matrix(1, 0, 0, 1, 1.5f, -1.5f)); break; case VisualOrientation.Right: insetPath.Transform(new Matrix(1, 0, 0, 1, -1.5f, 1.5f)); break; } using (Clipping clip = new Clipping(context.Graphics, path)) { // Draw the second color as the offset background using (Brush backBrush = CreateColorBrush(gradientRect, backColor2, backColor2, backColorStyle, backColorAngle, orientation)) { context.Graphics.FillPath(backBrush, insetPath); } } // Dispose of created resources insetPath.Dispose(); }
public void Flatten_Empty () { GraphicsPath path = new GraphicsPath (); GraphicsPath clone = (GraphicsPath) path.Clone (); // this is a no-op as there's nothing in the path path.Flatten (); ComparePaths (path, clone); }
public PathGradientBrush(GraphicsPath path) { if (path == null) throw new ArgumentNullException ("path"); var pathClone = (GraphicsPath)path.Clone (); pathClone.CloseAllFigures (); pathClone.Flatten (); pathPoints = pathClone.PathPoints; // make sure we have a closed path if (pathPoints[0] != pathPoints[pathPoints.Length - 1]) { var first = pathPoints [0]; var temps = new PointF[pathPoints.Length + 1]; for (var p = 0; p < pathPoints.Length; p++) temps[p] = pathPoints[p]; temps[temps.Length - 1] = first; pathPoints = temps; } rectangle = GeomUtilities.PolygonBoundingBox (pathPoints); centerPoint = GeomUtilities.PolygonCentroid (pathPoints); wrapMode = WrapMode.Clamp; // verify the winding of the polygon so that we cen calculate the // edges correctly var vt1 = pathPoints [0]; var vt2 = centerPoint; var vt3 = pathPoints [1]; var pWinding = vt1.X * vt2.Y - vt2.X * vt1.Y; pWinding += vt2.X * vt3.Y - vt3.X * vt2.Y; pWinding += vt3.X * vt1.Y - vt1.X * vt3.Y; // Positive is counter clockwise if (pWinding < 0) polygonWinding = FillMode.Alternate; blend = new Blend(1); blend.Factors = new float[]{ 1.0f}; blend.Positions = new float[] { 1.0f }; }
public void Flatten_NullFloat () { GraphicsPath path = new GraphicsPath (); GraphicsPath clone = (GraphicsPath) path.Clone (); // this is a no-op as there's nothing in the path // an no matrix to apply path.Flatten (null, 1f); ComparePaths (path, clone); }
public void GraphicsPath_Empty () { GraphicsPath gp = new GraphicsPath (); Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode"); CheckEmpty ("Empty.", gp); GraphicsPath clone = (GraphicsPath) gp.Clone (); Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode"); CheckEmpty ("Clone.", gp); gp.Reverse (); CheckEmpty ("Reverse.", gp); }
/// <summary> /// Draws a shadow around a rectangle. /// </summary> /// <param name="g">The current Graphics handle.</param> /// <param name="path">The path which should have a shadow.</param> /// <param name="color">The color of the shadow.</param> /// <param name="dx">The horizontal shift.</param> /// <param name="dy">The vertical shift.</param> /// <param name="blur">The blurness.</param> public static void DrawShadow(this Graphics g, GraphicsPath path, Color color, float dx, float dy, float blur) { blur = Math.Abs(blur); var bhalf = blur / 2f; var extendedPoints = (path.Clone() as GraphicsPath).PathPoints; var intendedPoints = (path.Clone() as GraphicsPath).PathPoints; var rect = path.GetBounds(); var wideX = blur / rect.Width; var wideY = blur / rect.Height; for (int i = 0; i < path.PathPoints.Length; i++) { extendedPoints[i].X += (extendedPoints[i].X - rect.Left) * wideX + dx - bhalf; extendedPoints[i].Y += (extendedPoints[i].Y - rect.Top) * wideY + dy - bhalf; intendedPoints[i].X += (rect.Left - intendedPoints[i].X) * wideX + dx + bhalf; intendedPoints[i].Y += (rect.Top - intendedPoints[i].Y) * wideY + dy + bhalf; } var extended = new GraphicsPath(extendedPoints, path.PathTypes); var intended = new GraphicsPath(intendedPoints, path.PathTypes); var region = new Region(extended); region.Exclude(path); g.FillRegion(new SolidBrush(color), region); if (blur > 0f) { region.Exclude(intended); var lgb = new PathGradientBrush(extended); lgb.CenterColor = color; var colors = new Color[3]; var positions = new float[3]; for (var i = 0; i < 3; i++) { colors[i] = Color.FromArgb(255 * (2 - i) / 2, color); positions[i] = (2f - i) / 2f; } lgb.InterpolationColors.Colors = colors; lgb.InterpolationColors.Positions = positions; g.FillRegion(lgb, region); } }