コード例 #1
0
        public static void DrawWorldCirclePartial(this IBrush brush,
                                                  float radius, int sectionsCount, float stroke,
                                                  IWorldCoordinate coord,
                                                  float startAngle, float endAngle,
                                                  CapStyle endCapStyle = CapStyle.Flat, CapStyle startCapStyle = CapStyle.Flat,
                                                  float missingPercent = 0, IBrush bgBrush = null)
        {
            var fullAngleRange = endAngle - startAngle;
            var halfRange      = fullAngleRange / 2f;
            var halfStroke     = stroke / 2f;

            var start = Math.Max(startAngle, startAngle + halfRange * missingPercent);
            var end   = Math.Min(endAngle, endAngle - halfRange * missingPercent);

            if (start > end || start < 0 || end < 0 || start > 360)
            {
                return;
            }

            using (var pg = Hud.Render.CreateGeometry())
            {
                using (var gs = pg.Open())
                {
                    var outerVectors = ArcVectors(radius + halfStroke, coord, start, end, sectionsCount);
                    var innerVectors = ArcVectors(radius - halfStroke, coord, start, end, sectionsCount);

                    gs.BeginFigure(outerVectors.First(), FigureBegin.Filled);
                    foreach (var v in outerVectors.Skip(1))
                    {
                        gs.AddLine(v);
                    }

                    //TODO: if rounded cap, add half circle
                    innerVectors.Reverse();
                    foreach (var v in innerVectors)
                    {
                        gs.AddLine(v);
                    }
                    //TODO: if rounded cap, add half circle

                    gs.EndFigure(FigureEnd.Closed);
                    gs.Close();

                    if (bgBrush != null)
                    {
                        bgBrush.DrawGeometry(pg);
                    }

                    brush.DrawGeometry(pg);
                }
            }
        }
コード例 #2
0
        private void Draw(IWorldCoordinate coord, float startAngle, float endAngle, int sectionsCount,
                          float missingPercent, IBrush bgBrush, IBrush brush)
        {
            var fullAngleRange = endAngle - startAngle;
            var halfRange      = fullAngleRange / 2f;
            var angleStep      = fullAngleRange / sectionsCount;
            var halfStroke     = Stroke / 2f;

            var start = Math.Max(startAngle, startAngle + halfRange * missingPercent);
            var end   = Math.Min(endAngle, endAngle - halfRange * missingPercent);

            if (start > end || start < 0 || end < 0 || start > 360)
            {
                return;
            }

            IScreenCoordinate previousCoord = default(IScreenCoordinate);

            for (var angle = start; angle <= end; angle += angleStep)
            {
                if (angle + angleStep > end) //if it's the last step
                {
                    angle = end;
                }

                //convert to radiant for ease of use, and set top == 0f, counter clockwise up to 360.
                var radians = (angle - 135f) * Math.PI / 180.0f;
                var cos     = (float)Math.Cos(radians);
                var sin     = (float)Math.Sin(radians);

                var mx = (Radius + halfStroke) * cos;
                var my = (Radius + halfStroke) * sin;

                if (previousCoord == default(IScreenCoordinate))
                {
                    previousCoord = coord.Offset(mx, my, 0).ToScreenCoordinate();
                    continue;
                }

                var currentCoord = coord.Offset(mx, my, 0).ToScreenCoordinate();

                brush.DrawLine(previousCoord.X, previousCoord.Y, currentCoord.X, currentCoord.Y);

                previousCoord = currentCoord;
            }

            return;

            using (var pg = Hud.Render.CreateGeometry())
            {
                using (var gs = pg.Open())
                {
                    var outerVectors    = new List <Vector2>();
                    var innerVectors    = new List <Vector2>();
                    var capsCoordinates = new List <IWorldCoordinate>();

                    for (var angle = start; angle <= end; angle += angleStep)
                    {
                        if (angle + angleStep > end) //if it's the last step
                        {
                            angle = end;
                        }

                        //convert to radiant for ease of use, and set top == 0f, counter clockwise up to 360.
                        var radians = (angle - 135f) * Math.PI / 180.0f;
                        var cos     = (float)Math.Cos(radians);
                        var sin     = (float)Math.Sin(radians);

                        if (angle == start || angle == end)
                        {
                            capsCoordinates.Add(coord.Offset(Radius * cos, Radius * sin, 0));
                        }

                        //outer point
                        var mx = (Radius + halfStroke) * cos;
                        var my = (Radius + halfStroke) * sin;

                        var vector = coord.ToVector2(mx, my, 0);
                        outerVectors.Add(vector);

                        //inner point
                        var mx2 = (Radius - halfStroke) * cos;
                        var my2 = (Radius - halfStroke) * sin;

                        vector = coord.ToVector2(mx2, my2, 0);
                        innerVectors.Add(vector);
                    }

                    gs.BeginFigure(outerVectors.First(), FigureBegin.Filled);
                    foreach (var v in outerVectors.Skip(1))
                    {
                        gs.AddLine(v);
                    }

                    ////TODO: if rounded cap, add half circle
                    //var capCoord = capsCoordinates.Last();
                    //for (var angle = 135f; angle < 315f; angle += 1f)
                    //{
                    //    if (angle + angleStep > end) //if it's the last step
                    //        angle = end;

                    //    //convert to radiant for ease of use, and set top == 0f, counter clockwise up to 360.
                    //    var radians = angle * Math.PI / 180.0f;
                    //    var cos = (float)Math.Cos(radians);
                    //    var sin = (float)Math.Sin(radians);

                    //    var mx = halfStroke * cos;
                    //    var my = halfStroke * sin;

                    //    var vector = capCoord.ToVector2(mx - 3, my - 3, 0);
                    //    gs.AddLine(vector);
                    //}

                    innerVectors.Reverse();
                    foreach (var v in innerVectors)
                    {
                        gs.AddLine(v);
                    }

                    //TODO: if rounded cap, add half circle

                    gs.EndFigure(FigureEnd.Closed);

                    //gs.BeginFigure(capsCoordinates.Last().ToVector2(), FigureBegin.Filled);
                    //var capCoord = capsCoordinates.Last();
                    //for (var angle = 90f; angle < 270f; angle += 9f)
                    //{
                    //    if (angle + angleStep > end) //if it's the last step
                    //        angle = end;

                    //    //convert to radiant for ease of use, and set top == 0f, counter clockwise up to 360.
                    //    var radians = angle * Math.PI / 180.0f;
                    //    var cos = (float)Math.Cos(radians);
                    //    var sin = (float)Math.Sin(radians);

                    //    var mx = halfStroke * cos;
                    //    var my = halfStroke * sin;

                    //    var vector = capCoord.ToVector2(mx, my, 0);
                    //    gs.AddLine(vector);
                    //}
                    //gs.EndFigure(FigureEnd.Closed);

                    //
                    gs.Close();

                    if (bgBrush != null)
                    {
                        bgBrush.DrawGeometry(pg);
                    }

                    brush.DrawGeometry(pg);
                }
            }
        }
コード例 #3
0
        public static void Draw(this IBrush brush,
                                float radius, int sectionsCount, float stroke,
                                IWorldCoordinate coord,
                                float startAngle, float endAngle,
                                CapStyle endCapStyle = CapStyle.Flat, CapStyle startCapStyle = CapStyle.Flat,
                                float missingPercent = 0, IBrush bgBrush = null)
        {
            var fullAngleRange = endAngle - startAngle;
            var halfRange      = fullAngleRange / 2f;
            var angleStep      = fullAngleRange / sectionsCount;
            var halfStroke     = stroke / 2f;

            var start = Math.Max(startAngle, startAngle + halfRange * missingPercent);
            var end   = Math.Min(endAngle, endAngle - halfRange * missingPercent);

            if (start > end || start < 0 || end < 0 || start > 360)
            {
                return;
            }

            using (var pg = Hud.Render.CreateGeometry())
            {
                using (var gs = pg.Open())
                {
                    var started      = false;
                    var outerVectors = new List <Vector2>();
                    var innerVectors = new List <Vector2>();

                    for (var angle = start; angle <= end; angle += angleStep)
                    {
                        if (angle + angleStep > end) //if it's the last step, round the end
                        {
                            angle = end;
                        }

                        //convert to radiant for ease of use, and set top == 0f, counter clockwise up to 360.
                        var radians = (angle - 135f) * Math.PI / 180.0f;
                        var cos     = (float)Math.Cos(radians);
                        var sin     = (float)Math.Sin(radians);

                        //outer point
                        var mx = (radius + halfStroke) * cos;
                        var my = (radius + halfStroke) * sin;

                        var vector = coord.ToVector2(mx, my, 0);

                        if (started)
                        {
                        }

                        if (!started)
                        {
                            started = true;
                            gs.BeginFigure(vector, FigureBegin.Filled);
                        }

                        outerVectors.Add(vector);

                        //inner point, store for later use
                        var mx2 = (radius - halfStroke) * cos;
                        var my2 = (radius - halfStroke) * sin;

                        vector = coord.ToVector2(mx2, my2, 0);
                        innerVectors.Add(vector);
                    }

                    foreach (var v in outerVectors.Skip(1))
                    {
                        gs.AddLine(v);
                    }

                    //TODO: if rounded cap, add half circle
                    innerVectors.Reverse();
                    foreach (var v in innerVectors)
                    {
                        gs.AddLine(v);
                    }
                    //TODO: if rounded cap, add half circle

                    gs.EndFigure(FigureEnd.Closed);
                    gs.Close();

                    if (bgBrush != null)
                    {
                        bgBrush.DrawGeometry(pg);
                    }

                    brush.DrawGeometry(pg);
                }
            }
        }