示例#1
0
        private void _drawItem(
            DrawingHandleScreen handle, ref float vOffset, float hOffset, Item item,
            SpriteFont font, StyleBox itemSelected)
        {
            var itemHeight = font.GetHeight(UIScale) + itemSelected.MinimumSize.Y;
            var selected   = item.Index == _selectedIndex;

            if (selected)
            {
                itemSelected.Draw(handle, UIBox2.FromDimensions(hOffset, vOffset, PixelWidth - hOffset, itemHeight));
            }

            if (!string.IsNullOrWhiteSpace(item.Text))
            {
                var offset   = itemSelected.GetContentOffset(Vector2.Zero);
                var baseLine = offset + new Vector2(hOffset, vOffset + font.GetAscent(UIScale));
                foreach (var chr in item.Text)
                {
                    baseLine += new Vector2(font.DrawChar(handle, chr, baseLine, UIScale, Color.White), 0);
                }
            }

            vOffset += itemHeight;
            hOffset += 5;
            foreach (var child in item.Children)
            {
                _drawItem(handle, ref vOffset, hOffset, child, font, itemSelected);
            }
        }
示例#2
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;
                }
                }
            }
        }