コード例 #1
0
        public void Paint(IActor actor, IWorldCoordinate coord, string text)
        {
            if (!Enabled)
            {
                return;
            }
            if (!IsEnabledFunc.Invoke())
            {
                return;
            }
            if (Brush == null)
            {
                return;
            }
            if (Radius <= 0)
            {
                return;
            }

            var missingPercent = FilledPercentFunc == null
                ? 0f
                : (100f - FilledPercentFunc.Invoke()) / 100f;

            coord = actor == null
                ? coord
                : actor.FloorCoordinate;

            var sectionsCounts = SectionsCountFunc.Invoke(this);

            Draw(coord, StartAngle, EndAngle, sectionsCounts, missingPercent, BackgroundBrush, Brush);
        }
コード例 #2
0
        public void Paint_OLD(IActor actor, IWorldCoordinate coord, string text)
        {
            if (!Enabled)
            {
                return;
            }
            if (Brush == null)
            {
                return;
            }
            if (Radius <= 0)
            {
                return;
            }
            if (!IsEnabledFunc.Invoke())
            {
                return;
            }

            var pct = FilledPercentFunc == null ? 100 : FilledPercentFunc.Invoke();

            using (var pg = Hud.Render.CreateGeometry())
            {
                using (var gs = pg.Open())
                {
                    var startAngleFull = 90f;
                    var endAngleFull   = 360f;
                    var fullAngleRange = endAngleFull - startAngleFull;
                    var halfRange      = fullAngleRange / 2f;
                    var angleStep      = fullAngleRange / 90f;
                    var halfStroke     = Stroke / 2f;

                    var start = Math.Max(startAngleFull, startAngleFull + halfRange * pct);
                    var end   = Math.Min(endAngleFull, endAngleFull - halfRange * pct);

                    if (start > end)
                    {
                        return;
                    }

                    var started            = false;
                    var returnVectors      = new List <Vector2>();
                    var innerVectors       = new List <Vector2>();
                    var innerReturnVectors = new List <Vector2>();
                    for (var angle = startAngleFull; angle <= endAngleFull; angle += angleStep)
                    {
                        var radians = (angle - 180f) * 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;

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

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

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

                        vector = actor.ToVector2(mx2, my2, 0);
                        returnVectors.Add(vector);
                    }

                    returnVectors.Reverse();
                    foreach (var returnVector in returnVectors)
                    {
                        gs.AddLine(returnVector);
                    }

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

                Brush.DrawGeometry(pg);

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