/// <summary> /// Creates the specified sink. /// </summary> /// <param name="sink">The sink.</param> public override void Create(D2D.GeometrySink sink) { sink.AddBezier(new D2D.BezierSegment() { Point1 = P1, Point2 = P2, Point3 = P3 }); }
public override void Create(D2D.GeometrySink sink) { sink.AddArc(new D2D.ArcSegment() { ArcSize = ArcSize, Point = Point, RotationAngle = Rotation, Size = Size, SweepDirection = SweepDirection }); }
public static void AddEllipseGeometry( this D2D.GeometrySink sink, Jupiter.Media.EllipseGeometry ellipseGeometry) { // Start the ellipse at 9 o'clock. sink.BeginFigure( new Vector2( (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX), (float)(ellipseGeometry.Center.Y)), D2D.FigureBegin.Filled); // Do almost full ellipse in one arc (there is .00001 pixel size missing) sink.AddArc( new D2D.ArcSegment { Point = new Vector2( (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX), (float)(ellipseGeometry.Center.Y + 0.00001)), Size = new Size2F( (float)(ellipseGeometry.RadiusX * 2), (float)(ellipseGeometry.RadiusY * 2)), RotationAngle = 0, SweepDirection = D2D.SweepDirection.Clockwise, ArcSize = D2D.ArcSize.Large }); // Close the ellipse sink.EndFigure(D2D.FigureEnd.Closed); }
/// <summary> /// Sets the content to all lines in the given polygon. /// </summary> /// <param name="polygon">The polygon.</param> public unsafe void SetContent(Polygon2D polygon) { polygon.EnsureNotNull(nameof(polygon)); polygon.Vertices.EnsureMoreThanZeroElements($"{nameof(polygon)}.{nameof(polygon.Vertices)}"); using (D2D.GeometrySink geoSink = m_d2dGeometry.Open()) { ReadOnlyCollection <Vector2> vertices = polygon.Vertices; // Start the figure Vector2 startPoint = vertices[0]; geoSink.BeginFigure( *(SDXM.RawVector2 *) & startPoint, D2D.FigureBegin.Filled); // Add all lines int vertexCount = vertices.Count; for (int loop = 1; loop < vertexCount; loop++) { Vector2 actVectorOrig = vertices[loop]; geoSink.AddLine(*(SDXM.RawVector2 *) & actVectorOrig); } // End the figure geoSink.EndFigure(D2D.FigureEnd.Closed); geoSink.Close(); } }
public PathBuilder(D2D.GeometrySink sink) { if (sink == null) { throw new ArgumentNullException(); } _sink = sink; }
public PathBuilder(D2D.GeometrySink sink) { if(sink==null) { throw new ArgumentNullException(); } _sink = sink; }
public static void AddGeometryGroup(this D2D.GeometrySink sink, GeometryGroup geometryGroup, RectangleF rect) { sink.SetFillMode(geometryGroup.FillRule.ToSharpDX()); foreach (var childGeometry in geometryGroup.Children) { sink.AddGeometry(childGeometry, rect); } }
public void DrawCircle(Renderer renderer, Vector2 center, float radius, float step, double a, double b, ref D2D1.PathGeometry outline, int col, float txt) { D2D1.PathGeometry path = new D2D1.PathGeometry(renderer.D2DFactory); D2D1.GeometrySink s = path.Open(); s.SetFillMode(D2D1.FillMode.Winding); s.BeginFigure(center + new Vector2((float)Math.Cos(a) * radius, (float)Math.Sin(a) * radius), D2D1.FigureBegin.Filled); for (double i = a; i <= b; i += Math.PI * .05) { s.AddLine(center + new Vector2((float)Math.Cos(i) * radius, (float)Math.Sin(i) * radius)); } s.AddLine(center + new Vector2((float)Math.Cos(b) * radius, (float)Math.Sin(b) * radius)); s.AddLine(center); s.EndFigure(D2D1.FigureEnd.Closed); s.Close(); s.Dispose(); renderer.D2DContext.FillGeometry(path, renderer.Brushes[Colors[col % Colors.Length]]); if (path.FillContainsPoint(Input.MousePos, 1)) { if (txt == 0) { txt = radius + 50; } RawRectangleF r = new RawRectangleF(center.X - 100, center.Y - txt, center.X + 100, center.Y - txt + 16); renderer.D2DContext.FillRectangle(r, renderer.Brushes["TransparentBlack"]); renderer.Consolas14.TextAlignment = DWrite.TextAlignment.Leading; renderer.D2DContext.DrawText( Name + " (" + Stopwatch.Elapsed.TotalMilliseconds.ToString("F1") + "ms)", renderer.Consolas14, r, renderer.Brushes[Colors[col % Colors.Length]], D2D1.DrawTextOptions.None, D2D1.MeasuringMode.GdiNatural); txt += 16; outline = path; } else { path.Dispose(); } double t = 0; foreach (Profiler p in Children) { col++; //if (p.ParentTickOffset > 0) // t += (p.ParentTickOffset / (double)Stopwatch.Elapsed.Ticks) * (b - a); double f = (p.Stopwatch.Elapsed.Ticks / (double)Stopwatch.Elapsed.Ticks) * (b - a); p.DrawCircle(renderer, center, radius - step, step, a + t, a + t + f, ref outline, col, txt); t += f; } }
public static void AddPathGeometry( this D2D.GeometrySink sink, Jupiter.Media.PathGeometry pathGeometry) { sink.SetFillMode(pathGeometry.FillRule.ToSharpDX()); foreach (var childFigure in pathGeometry.Figures) { sink.AddPathFigure(childFigure); } }
public static void AddLineGeometry( this D2D.GeometrySink sink, Jupiter.Media.LineGeometry lineGeometry) { sink.BeginFigure( lineGeometry.StartPoint.ToSharpDX(), D2D.FigureBegin.Hollow); sink.AddLine( lineGeometry.EndPoint.ToSharpDX()); sink.EndFigure(D2D.FigureEnd.Open); }
public void CloseSink() { // This must be called before rendering the path. if (sink != null) { if (isInFigure) sink.EndFigure(sd.FigureEnd.Open); isInFigure = false; sink.Close(); sink.Dispose(); sink = null; } }
public static void AddPathFigure( this D2D.GeometrySink sink, Jupiter.Media.PathFigure pathFigure) { sink.BeginFigure( pathFigure.StartPoint.ToSharpDX(), pathFigure.IsFilled ? D2D.FigureBegin.Filled : D2D.FigureBegin.Hollow); foreach (var segment in pathFigure.Segments) { sink.AddPathFigureSegment(segment); } sink.EndFigure(pathFigure.IsClosed ? D2D.FigureEnd.Closed : D2D.FigureEnd.Open); }
public void CloseSink() { // This must be called before rendering the path. if (sink != null) { if (isInFigure) { sink.EndFigure(sd.FigureEnd.Open); } isInFigure = false; sink.Close(); sink.Dispose(); sink = null; } }
/// <summary> /// Creates the specified sink. /// </summary> /// <param name="sink">The sink.</param> public void Create(D2D.GeometrySink sink) { sink.BeginFigure(StartPoint, Filled ? D2D.FigureBegin.Filled : D2D.FigureBegin.Hollow); for (var i = 0; i < Segments.Count; ++i) { var flag = D2D.PathSegment.None; var segment = Segments[i]; if (!segment.IsStroked) { flag |= D2D.PathSegment.ForceUnstroked; } if (segment.IsSmoothJoined) { flag |= D2D.PathSegment.ForceRoundLineJoin; } sink.SetSegmentFlags(flag); segment.Segment.Create(sink); } sink.EndFigure(Closed ? D2D.FigureEnd.Closed : D2D.FigureEnd.Open); }
public override void Create(D2D.GeometrySink sink) { var bezierSegments = new List <D2D.BezierSegment>(); for (int i = 0; i < _bezierPoints.Count; i += 3) { int index = i; var segment = new D2D.BezierSegment { }; segment.Point1 = _bezierPoints[index]; if ((index + 1) < _bezierPoints.Count) { segment.Point2 = _bezierPoints[index + 1]; } if ((index + 2) < _bezierPoints.Count) { segment.Point3 = _bezierPoints[index + 2]; } bezierSegments.Add(segment); } sink.AddBeziers(bezierSegments.ToArray()); }
public static void AddRectangleGeometry( this D2D.GeometrySink sink, Jupiter.Media.RectangleGeometry rectangleGeometry) { sink.BeginFigure( new Vector2( (float)(rectangleGeometry.Rect.Left), (float)(rectangleGeometry.Rect.Top)), D2D.FigureBegin.Filled); sink.AddLines( new [] { new Vector2( (float)(rectangleGeometry.Rect.Right), (float)(rectangleGeometry.Rect.Top)), new Vector2( (float)(rectangleGeometry.Rect.Right), (float)(rectangleGeometry.Rect.Bottom)), new Vector2( (float)(rectangleGeometry.Rect.Left), (float)(rectangleGeometry.Rect.Bottom)), }); sink.EndFigure(D2D.FigureEnd.Closed); }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Обновление данных арки /// </summary> //--------------------------------------------------------------------------------------------------------- public override void Update() { XDisposer.SafeDispose(ref mD2DGeometry); mD2DGeometry = new Direct2D.PathGeometry(XDirect2DManager.D2DFactory); mD2DGeometrySink = mD2DGeometry.Open(); mD2DGeometrySink.BeginFigure(mStartPoint.ToRawVector2(), mIsFilled ? Direct2D.FigureBegin.Filled : Direct2D.FigureBegin.Hollow); Direct2D.ArcSegment arc_segment = new Direct2D.ArcSegment(); arc_segment.ArcSize = mIsLargeArc ? Direct2D.ArcSize.Large : Direct2D.ArcSize.Small; arc_segment.Point = mEndPoint.ToRawVector2(); arc_segment.RotationAngle = mRotationAngle; arc_segment.Size = new SharpDX.Size2F(mRadiusX, mRadiusY); arc_segment.SweepDirection = mIsClockwiseDirection ? Direct2D.SweepDirection.Clockwise : Direct2D.SweepDirection.CounterClockwise; mD2DGeometrySink.AddArc(arc_segment); mD2DGeometrySink.EndFigure(mIsClosed ? Direct2D.FigureEnd.Closed : Direct2D.FigureEnd.Open); mD2DGeometrySink.Close(); XDisposer.SafeDispose(ref mD2DGeometrySink); mBoundsRect = mD2DGeometry.GetWidenedBounds(2).ToRect(); }
public static void AddGeometry(this D2D.GeometrySink sink, Geometry geometry, RectangleF rect) { var geometryGroup = geometry as Jupiter.Media.GeometryGroup; if (geometryGroup != null) { sink.AddGeometryGroup(geometryGroup, rect); } var lineGeometry = geometry as Jupiter.Media.LineGeometry; if (lineGeometry != null) { sink.AddLineGeometry(lineGeometry); } var rectangleGeometry = geometry as Jupiter.Media.RectangleGeometry; if (rectangleGeometry != null) { sink.AddRectangleGeometry(rectangleGeometry); } var ellipseGeometry = geometry as Jupiter.Media.EllipseGeometry; if (ellipseGeometry != null) { sink.AddEllipseGeometry(ellipseGeometry); } var pathGeometry = geometry as Jupiter.Media.PathGeometry; if (pathGeometry != null) { sink.AddPathGeometry(pathGeometry); } }
public static void AddPathFigureSegment( this D2D.GeometrySink sink, Jupiter.Media.PathSegment segment) { var bezierSegment = segment as BezierSegment; if (bezierSegment != null) { sink.AddBezier( new D2D.BezierSegment { Point1 = bezierSegment.Point1.ToSharpDX(), Point2 = bezierSegment.Point2.ToSharpDX(), Point3 = bezierSegment.Point3.ToSharpDX() }); return; } var lineSegment = segment as LineSegment; if (lineSegment != null) { sink.AddLine( lineSegment.Point.ToSharpDX()); return; } var polyBezierSegment = segment as PolyBezierSegment; if (polyBezierSegment != null) { var beziers = new D2D.BezierSegment[polyBezierSegment.Points.Count / 3]; for (int i = 0; i < beziers.Length; i++) { beziers[i].Point1 = polyBezierSegment.Points[i * 3].ToSharpDX(); beziers[i].Point2 = polyBezierSegment.Points[i * 3 + 1].ToSharpDX(); beziers[i].Point3 = polyBezierSegment.Points[i * 3 + 2].ToSharpDX(); } sink.AddBeziers(beziers); return; } var polyLineSegment = segment as PolyLineSegment; if (polyLineSegment != null) { var lines = new SharpDX.Vector2[polyLineSegment.Points.Count]; for (int i = 0; i < lines.Length; i++) { lines[i] = polyLineSegment.Points[i].ToSharpDX(); } sink.AddLines(lines); return; } var quadraticBezierSegment = segment as QuadraticBezierSegment; if (quadraticBezierSegment != null) { sink.AddQuadraticBezier( new D2D.QuadraticBezierSegment { Point1 = quadraticBezierSegment.Point1.ToSharpDX(), Point2 = quadraticBezierSegment.Point2.ToSharpDX() }); return; } var polyQuadraticBezierSegment = segment as PolyQuadraticBezierSegment; if (polyQuadraticBezierSegment != null) { var quadraticBeziers = new D2D.QuadraticBezierSegment[polyBezierSegment.Points.Count / 2]; for (int i = 0; i < quadraticBeziers.Length; i++) { quadraticBeziers[i].Point1 = polyBezierSegment.Points[i * 2].ToSharpDX(); quadraticBeziers[i].Point2 = polyBezierSegment.Points[i * 2 + 1].ToSharpDX(); } sink.AddQuadraticBeziers(quadraticBeziers); return; } var arcSegment = segment as ArcSegment; if (arcSegment != null) { sink.AddArc( new D2D.ArcSegment { Point = arcSegment.Point.ToSharpDX(), Size = arcSegment.Size.ToSharpDX(), RotationAngle = (float)arcSegment.RotationAngle, SweepDirection = arcSegment.SweepDirection.ToSharpDX(), ArcSize = arcSegment.IsLargeArc ? D2D.ArcSize.Large : D2D.ArcSize.Small }); return; } }
public GraphicsPathHandler() { this.Control = new sd.PathGeometry(SDFactory.Instance); this.sink = this.Control.Open(); }
public override void Create(D2D.GeometrySink sink) { sink.AddLine(Point); }
public abstract void Create(D2D.GeometrySink sink);
public override void Create(D2D.GeometrySink sink) { sink.AddLines(_points.Select(x => (RawVector2)x).ToArray()); }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Обновление данных геометрии /// </summary> //--------------------------------------------------------------------------------------------------------- public override void Update() { XDisposer.SafeDispose(ref mD2DGeometry); mD2DGeometry = new Direct2D.PathGeometry(XDirect2DManager.D2DFactory); mD2DGeometrySink = mD2DGeometry.Open(); CCadSegment current_figure = mSegments[0]; mD2DGeometrySink.BeginFigure(current_figure.BasePoint.ToRawVector2(), current_figure.IsFilled ? Direct2D.FigureBegin.Filled : Direct2D.FigureBegin.Hollow); Int32 current_new_figure = 0; for (Int32 i = 0; i < mSegments.Count; i++) { CCadSegment current_segment = mSegments[i]; // Если новая фигура if (current_segment.IsNewFigure && current_new_figure != i) { // Закрывает текущую фигуру mD2DGeometrySink.EndFigure(current_figure.IsClosed ? Direct2D.FigureEnd.Closed : Direct2D.FigureEnd.Open); // Открываем новую фигуру mD2DGeometrySink.BeginFigure(current_segment.BasePoint.ToRawVector2(), current_segment.IsFilled ? Direct2D.FigureBegin.Filled : Direct2D.FigureBegin.Hollow); current_figure = current_segment; current_new_figure = i; } switch (current_segment.SegmentType) { case TCadSegmentType.Points: { CCadSegmentPoints points = current_segment as CCadSegmentPoints; mD2DGeometrySink.AddLines(points.Points.ConvertToDirect2DRawVectors()); } break; case TCadSegmentType.Line: { CCadSegmentLine line = current_segment as CCadSegmentLine; mD2DGeometrySink.AddLine(line.EndPoint.ToRawVector2()); } break; case TCadSegmentType.Arc: { CCadSegmentArc arc = current_segment as CCadSegmentArc; Direct2D.ArcSegment arc_segment = new Direct2D.ArcSegment(); arc_segment.ArcSize = arc.mIsLargeArc ? Direct2D.ArcSize.Large : Direct2D.ArcSize.Small; arc_segment.Point = arc.mEndPoint.ToRawVector2(); arc_segment.RotationAngle = arc.mRotationAngle; arc_segment.Size = new Size2F(arc.mRadiusX, arc.mRadiusY); arc_segment.SweepDirection = arc.mIsClockwiseDirection ? Direct2D.SweepDirection.Clockwise : Direct2D.SweepDirection.CounterClockwise; mD2DGeometrySink.AddArc(arc_segment); } break; case TCadSegmentType.Bezier: break; default: break; } } // Закрывает текущую фигуру mD2DGeometrySink.EndFigure(current_figure.IsClosed ? Direct2D.FigureEnd.Closed : Direct2D.FigureEnd.Open); mD2DGeometrySink.Close(); XDisposer.SafeDispose(ref mD2DGeometrySink); mBoundsRect = mD2DGeometry.GetWidenedBounds(2).ToRect(); }
public static void Draw2D(Renderer renderer) { if (!DrawDebug) { return; } Profiler.Begin("Debug 2d Draw"); renderer.Consolas14.TextAlignment = DWrite.TextAlignment.Leading; renderer.Consolas14.ParagraphAlignment = DWrite.ParagraphAlignment.Center; float line = 1; renderer.D2DContext.DrawText( string.Format("{0} triangles, {1} nodes, {2} trees/{3} imposters [{4} waiting / {5} generating]", TrianglesDrawn.ToString("N0"), NodesDrawn.ToString("N0"), TreesDrawn.ToString("N0"), ImposterDrawn.ToString("N0"), QuadNode.GenerateQueue.Count, QuadNode.Generating.Count), renderer.Consolas14, new RawRectangleF(10, renderer.Viewport.Height - line * 25, 300, renderer.Viewport.Height - (line - 1) * 25), renderer.Brushes["White"]); line++; renderer.D2DContext.DrawText( string.Format("[{0}, {1}]", Planet.min, Planet.max), renderer.Consolas14, new RawRectangleF(10, renderer.Viewport.Height - line * 25, 300, renderer.Viewport.Height - (line - 1) * 25), renderer.Brushes["White"]); line++; #region logs renderer.Consolas14.TextAlignment = DWrite.TextAlignment.Leading; renderer.Consolas14.WordWrapping = DWrite.WordWrapping.NoWrap; renderer.Consolas14.ParagraphAlignment = DWrite.ParagraphAlignment.Center; float lh = 10; float ly = 10; for (int i = 0; i < logs.Count; i++) { renderer.D2DContext.DrawText(logs[i].ToString(), renderer.Consolas14, new RawRectangleF(7, ly - 3, 7 + 200, ly - 3 + lh), renderer.Brushes["White"]); ly += lh + 5; } ly = renderer.ResolutionY - 10 - lh; foreach (KeyValuePair <string, string> l in tracks) { renderer.D2DContext.DrawText(l.Value, renderer.Consolas14, new RawRectangleF(renderer.ResolutionX * .75f - 200 - 3, ly - 3, renderer.ResolutionX * .75f + 200 + 3, ly + lh + 3), renderer.Brushes["White"]); ly -= lh + 5; } ly = renderer.ResolutionY - 10 - lh; foreach (KeyValuePair <string, string> l in immediateTrack) { renderer.D2DContext.DrawText(l.Value, renderer.Consolas14, new RawRectangleF(renderer.ResolutionX * .75f - 200 - 3 - 50, ly - 3, renderer.ResolutionX * .75f + 200 + 3 - 50, ly + lh + 3), renderer.Brushes["White"]); ly -= lh + 5; } #endregion #region graph float min = frameGraph[0].FrameTimeMS; float max = frameGraph[0].FrameTimeMS; for (int i = 0; i < frameGraph.Count; i++) { min = Math.Min(min, frameGraph[i].FrameTimeMS); max = Math.Max(max, frameGraph[i].FrameTimeMS); } float step = Math.Max((int)((max - min) / 10 / .5f) * .5f, .5f); min = (int)Math.Floor(min / step) * step; max = (int)Math.Ceiling(max / step) * step; RawRectangleF grect = new RawRectangleF(renderer.ResolutionX - 360, 10, renderer.ResolutionX - 10, 360); float xScale = (grect.Right - grect.Left - 30) / frameGraphSize; float ppf = (grect.Bottom - grect.Top - 20) / (max - min); // pixels per ms RawVector2[] pts = new RawVector2[frameGraph.Count]; List <RawVector2> marks = new List <RawVector2>(); for (int i = 0; i < frameGraph.Count; i++) { pts[i] = new RawVector2(grect.Left + 30 + i * xScale, MathUtil.Clamp(grect.Bottom - 20 - (frameGraph[i].FrameTimeMS - min) * ppf, grect.Top, grect.Bottom - 20)); } D2D1.PathGeometry graphline = new D2D1.PathGeometry(renderer.D2DFactory); D2D1.GeometrySink graphsink = graphline.Open(); graphsink.SetFillMode(D2D1.FillMode.Winding); graphsink.BeginFigure(pts[0], D2D1.FigureBegin.Hollow); graphsink.AddLines(pts); graphsink.EndFigure(D2D1.FigureEnd.Open); graphsink.Close(); renderer.D2DContext.FillRectangle(grect, renderer.Brushes["TransparentBlack"]); renderer.D2DContext.DrawLine( // y axis new RawVector2(grect.Left + 30, grect.Bottom - (max - min) * ppf - 20), new RawVector2(grect.Left + 30, grect.Bottom - 20), renderer.Brushes["White"], 2); renderer.D2DContext.DrawLine( new RawVector2(grect.Left + 30, grect.Bottom - 20), new RawVector2(grect.Right, grect.Bottom - 20), renderer.Brushes["White"], 2); // x axis renderer.Consolas14.TextAlignment = DWrite.TextAlignment.Trailing; renderer.Consolas14.ParagraphAlignment = DWrite.ParagraphAlignment.Center; for (float ms = min; ms <= max; ms += step) { float y = grect.Bottom - 20 - (ms - min) * ppf; // y axis numbers if (ms.ToString().Length <= 3) { renderer.D2DContext.DrawText(ms.ToString(), renderer.Consolas14, new RawRectangleF(grect.Left, y, grect.Left + 25, y), renderer.Brushes["White"]); } if (ms > min) { renderer.D2DContext.DrawLine(new RawVector2(grect.Left + 28, y), new RawVector2(grect.Right, y), renderer.Brushes["White"], .25f); } } renderer.D2DContext.DrawGeometry(graphline, renderer.Brushes["CornflowerBlue"]); // graph line // x axis label renderer.Consolas14.TextAlignment = DWrite.TextAlignment.Trailing; renderer.Consolas14.ParagraphAlignment = DWrite.ParagraphAlignment.Far; renderer.D2DContext.DrawText(frameGraphSize + " frames", renderer.Consolas14, new RawRectangleF(grect.Right, grect.Bottom, grect.Right, grect.Bottom), renderer.Brushes["White"]); // y axis label renderer.Consolas14.TextAlignment = DWrite.TextAlignment.Center; renderer.Consolas14.ParagraphAlignment = DWrite.ParagraphAlignment.Near; renderer.D2DContext.DrawText("Draw+Update Time (ms)", renderer.Consolas14, // y axis label new RawRectangleF(grect.Left + 30, grect.Top, grect.Right, grect.Top), renderer.Brushes["White"]); #endregion Profiler.End(); }
internal GeometrySink(SharpDX.Direct2D1.GeometrySink sink) { geometrySink = ToDispose(sink); }