Esempio n. 1
0
        private Vector2 DrawItem(AlertDrawStyle drawStyle, Vector2 delta, Vector2 position, Vector2 padding, string text)
        {
            padding.X -= drawStyle.BorderWidth;
            padding.Y -= drawStyle.BorderWidth;
            double phi;
            var    distance      = delta.GetPolarCoordinates(out phi);
            float  compassOffset = Settings.TextSize + 8;
            var    textPos       = position.Translate(-padding.X - compassOffset, padding.Y);
            var    textSize      = Graphics.DrawText(text, textPos, drawStyle.TextColor, FontAlign.Right);
            var    iconSize      = drawStyle.IconIndex >= 0 ? textSize.Y : 0;
            var    fullHeight    = textSize.Y + 2 * padding.Y + 2 * drawStyle.BorderWidth;
            var    fullWidth     = textSize.X + 2 * padding.X + iconSize + 2 * drawStyle.BorderWidth + compassOffset;
            var    boxRect       = new RectangleF(position.X - fullWidth, position.Y, fullWidth - compassOffset, fullHeight);

            Graphics.DrawBox(boxRect, drawStyle.BackgroundColor);
            var rectUV     = MathHepler.GetDirectionsUV(phi, distance);
            var rectangleF = new RectangleF(position.X - padding.X - compassOffset + 6, position.Y + padding.Y, textSize.Y, textSize.Y);

            Graphics.DrawImage("directions.png", rectangleF, rectUV);

            if (iconSize > 0)
            {
                const float ICONS_IN_SPRITE = 4;
                var         iconX           = drawStyle.IconIndex / ICONS_IN_SPRITE;
                var         topLeft         = new System.Numerics.Vector2(textPos.X - iconSize - textSize.X, textPos.Y);
                var         topLeftUv       = new System.Numerics.Vector2(iconX, 0);

                Graphics.DrawImageGui("item_icons.png", topLeft, topLeft.Translate(iconSize, iconSize), topLeftUv,
                                      topLeftUv.Translate((drawStyle.IconIndex + 1) / ICONS_IN_SPRITE - iconX, 1));
            }

            if (drawStyle.BorderWidth > 0)
            {
                Graphics.DrawFrame(boxRect, drawStyle.BorderColor, drawStyle.BorderWidth);
            }

            return(new Vector2(fullWidth, fullHeight));
        }