Ejemplo n.º 1
0
    public DrawingSurface MidBar(
        float net,
        float low,
        float high,
        float width      = 0f,
        float height     = 0f,
        float pad        = 0.1f,
        Color?bgColour   = null,
        string text      = null,
        Color?textColour = null
        )
    {
        if (!this.drawing)
        {
            this.DrawStart();
        }
        low  = (float)Math.Abs(low);
        high = (float)Math.Abs(high);

        width   = (width == 0f) ? this.width - this.cursor.X : width;
        height  = (height == 0f) ? this.charSizeInPx.Y : height;
        height -= 1f;

        Vector2 pos = this.cursor + this.viewport.Position;

        pos.Y += (height / 2) + 1f;

        using (frame.Clip((int)pos.X, (int)(pos.Y - height / 2), (int)width, (int)height)) {
            this.frame.Add(new MySprite {
                Type            = SpriteType.TEXTURE,
                Alignment       = TextAlignment.CENTER,
                Data            = "SquareSimple",
                Position        = pos + new Vector2(width / 2, 0),
                Size            = new Vector2((float)Math.Sqrt(Math.Pow(width, 2) / 2), width),
                Color           = bgColour ?? this.colourGrey,
                RotationOrScale = this.ToRad(-45f),
            });
        }

        pad     = (float)Math.Round(pad * height);
        pos.X  += pad;
        width  -= 2 * pad;
        height -= 2 * pad;

        Color colour = DrawingSurface.stringToColour.Get("dimgreen");
        float pct    = (high == 0f ? 1f : (float)Math.Min(1f, net / high));

        if (net < 0)
        {
            pct    = (low == 0f ? -1f : (float)Math.Max(-1f, net / low));
            colour = DrawingSurface.stringToColour.Get("dimred");
        }
        float sideWidth = (float)Math.Abs(Math.Sqrt(2) * pct * width);
        float leftClip  = Math.Min((width / 2), (width / 2) * (1 + pct));
        float rightClip = Math.Max((width / 2), (width / 2) * (1 + pct));

        using (this.frame.Clip((int)(pos.X + leftClip), (int)(pos.Y - height / 2), (int)Math.Abs(rightClip - leftClip), (int)height)) {
            this.frame.Add(new MySprite {
                Type            = SpriteType.TEXTURE,
                Alignment       = TextAlignment.CENTER,
                Data            = "SquareSimple",
                Position        = pos + new Vector2(width / 2, 0),
                Size            = new Vector2(sideWidth / 2, width),
                Color           = colour,
                RotationOrScale = this.ToRad(-45f)
            });
        }

        this.frame.Add(new MySprite {
            Type            = SpriteType.TEXTURE,
            Alignment       = TextAlignment.CENTER,
            Data            = "SquareSimple",
            Position        = pos + new Vector2((width / 2), -1f),
            Size            = new Vector2(2f, height + 2f),
            Color           = Color.White,
            RotationOrScale = 0f
        });

        text = text ?? Util.PctString(pct);
        if (text != null && text != "")
        {
            this.cursor.X += net > 0 ? (width / 4) : (3 * width / 4);
            this.Text(text, textColour ?? this.surface.ScriptForegroundColor, textAlignment: TextAlignment.CENTER, scale: 0.8f);
        }
        else
        {
            this.cursor.X += width;
        }

        return(this);
    }