Exemple #1
0
        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;
            }
        }
Exemple #2
0
        public void AddBezier(PointF pt1, PointF pt2, PointF pt3, PointF pt4)
        {
            sink.AddLine(pt1.ToWpf());

            sink.AddBezier(
                new sd.BezierSegment
            {
                Point1 = pt2.ToWpf(),
                Point2 = pt3.ToWpf(),
                Point3 = pt4.ToWpf()
            });
        }
        /// <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 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 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;
            }
        }
Exemple #6
0
 public void LineTo(Location p)
 {
     _sink.AddLine(p.ToD2D());
 }
Exemple #7
0
 public void AddLine(Vector2 point)
 {
     geometrySink.AddLine(point);
 }
Exemple #8
0
            //---------------------------------------------------------------------------------------------------------
            /// <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 override void Create(D2D.GeometrySink sink)
 {
     sink.AddLine(Point);
 }