Exemple #1
0
 public void AddLine(PointF point1, PointF point2)
 {
     sink.AddLines(
         new s.DrawingPointF[]
     {
         point1.ToWpf(),
         point2.ToWpf()
     });
 }
Exemple #2
0
 public void AddLines(IEnumerable <Vector2> points)
 {
     geometrySink.AddLines(points.Select(p => new RawVector2()
     {
         X = p.X, Y = p.Y
     }).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);
 }
        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 #5
0
        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();
        }
Exemple #6
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();
            }
Exemple #7
0
 public override void Create(D2D.GeometrySink sink)
 {
     sink.AddLines(_points.Select(x => (RawVector2)x).ToArray());
 }