示例#1
0
        public void Draw(
            DrawingHandleScreen handle,
            SpriteFont font,
            UIBox2 drawBox,
            float verticalOffset,
            // A stack for format tags.
            // This stack contains the format tag to RETURN TO when popped off.
            // So when a new color tag gets hit this stack gets the previous color pushed on.
            Stack <FormattedMessage.Tag> formatStack, float uiScale)
        {
            // The tag currently doing color.
            var currentColorTag = TagBaseColor;

            var globalBreakCounter = 0;
            var lineBreakIndex     = 0;
            var baseLine           = drawBox.TopLeft + new Vector2(0, font.GetAscent(uiScale) + verticalOffset);

            formatStack.Clear();
            foreach (var tag in Message.Tags)
            {
                switch (tag)
                {
                case FormattedMessage.TagColor tagColor:
                    formatStack.Push(currentColorTag);
                    currentColorTag = tagColor;
                    break;

                case FormattedMessage.TagPop _:
                    var popped = formatStack.Pop();
                    switch (popped)
                    {
                    case FormattedMessage.TagColor tagColor:
                        currentColorTag = tagColor;
                        break;

                    default:
                        throw new InvalidOperationException();
                    }

                    break;

                case FormattedMessage.TagText tagText:
                {
                    var text = tagText.Text;
                    for (var i = 0; i < text.Length; i++, globalBreakCounter++)
                    {
                        var chr = text[i];
                        if (lineBreakIndex < LineBreaks.Count &&
                            LineBreaks[lineBreakIndex] == globalBreakCounter)
                        {
                            baseLine        = new Vector2(drawBox.Left, baseLine.Y + font.GetLineHeight(uiScale));
                            lineBreakIndex += 1;
                        }

                        var advance = font.DrawChar(handle, chr, baseLine, uiScale, currentColorTag.Color);
                        baseLine += new Vector2(advance, 0);
                    }

                    break;
                }
                }
            }
        }
示例#2
0
 protected override void DoDraw(DrawingHandleScreen handle, UIBox2 box)
 {
     handle.DrawRect(box, BackgroundColor);
 }
 internal static float DrawChar(this SpriteFont font, DrawingHandleScreen handle, char character, Vector2 baseLine, float uiScale, Color color)
 {
     return(0f);
 }