Exemplo n.º 1
0
        private void UpdateArcGeometry(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale)
        {
            Point startPoint = StartAnchor.GetPoint(chartControl, chartPanel, chartScale);
            Point endPoint   = EndAnchor.GetPoint(chartControl, chartPanel, chartScale);

            if (arcGeometry != null && startPoint == cachedStartPoint && endPoint == cachedEndPoint)
            {
                return;
            }

            cachedEndPoint   = endPoint;
            cachedStartPoint = startPoint;

            if (arcGeometry != null && !arcGeometry.IsDisposed)
            {
                arcGeometry.Dispose();
            }

            Vector lineVec = endPoint - startPoint;
            float  width   = Math.Abs((float)lineVec.X);
            float  height  = Math.Abs((float)lineVec.Y);

            SharpDX.Direct2D1.ArcSegment arcSegment = new SharpDX.Direct2D1.ArcSegment
            {
                ArcSize        = SharpDX.Direct2D1.ArcSize.Small,
                Point          = new SharpDX.Vector2((float)endPoint.X, (float)endPoint.Y),
                SweepDirection = SharpDX.Direct2D1.SweepDirection.CounterClockwise,
                Size           = new SharpDX.Size2F(width, height)
            };

            // Create the arc between the line two end points
            arcGeometry = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
            SharpDX.Direct2D1.GeometrySink geometrySink = arcGeometry.Open();
            geometrySink.BeginFigure(new SharpDX.Vector2((float)startPoint.X, (float)startPoint.Y), SharpDX.Direct2D1.FigureBegin.Filled);
            geometrySink.AddArc(arcSegment);
            geometrySink.EndFigure(SharpDX.Direct2D1.FigureEnd.Open);
            geometrySink.Close();
        }