Beispiel #1
0
        public void DrawString(Font font, ref Utf16ValueStringBuilder text, Vector2 location, Color color, float scale = 1.0f)
        {
            int cursorX = (int)location.X;
            // location.Y += font.Height;

            var textSpan = text.AsSpan();

            // ReSharper disable once ForCanBeConvertedToForeach
            for (int i = 0; i < text.Length; i++)
            {
                if (!font.Characters.TryGetValue(textSpan[i], out var fontCharacter))
                {
                    continue;
                }

                int x = (int)(cursorX + (fontCharacter.Bearing.X * scale));
                int y = (int)(location.Y - (fontCharacter.Bearing.Y * scale));

                cursorX += (int)((fontCharacter.Advance >> 6) * scale);

                if (fontCharacter.Visible)
                {
                    Draw(font.FontAtlas,
                         new Rectangle(x,
                                       y,
                                       (int)(fontCharacter.Bounds.Width * scale),
                                       (int)(fontCharacter.Bounds.Height * scale)),
                         fontCharacter.Bounds,
                         color);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts ANSI color codes into mud color codes.  Note: This updates the StringBuilder directly.
        /// </summary>
        /// <param name="sb"></param>
        public static void AnsiToMudColorCodes(ref Utf16ValueStringBuilder sb)
        {
            var span = sb.AsSpan();

            // If there are no color codes don't bother loop through the replacements.
            if (!span.Contains('\x1B'))
            {
                return;
            }

            foreach (var item in ColorMap)
            {
                sb.Replace(item.AnsiColor.ToString(), item.AnsiColor.MudColorCode);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Converts mud color codes into ANSI color codes.  Note: This updates the StringBuilder directly.
        /// </summary>
        /// <param name="sb"></param>
        public static void MudToAnsiColorCodes(ref Utf16ValueStringBuilder sb)
        {
            var span = sb.AsSpan();

            // If there are no color codes don't bother loop through the replacements.
            if (!span.Contains('{'))
            {
                return;
            }

            // First the colors
            foreach (var item in ColorMap)
            {
                sb.Replace(item.AnsiColor.MudColorCode, item.AnsiColor.ToString());
            }

            // Next the styles
            foreach (var item in StyleMap)
            {
                sb.Replace(item.AnsiColor.MudColorCode, item.AnsiColor.ToString());
            }
        }
Beispiel #4
0
 /// <summary>Get the written buffer data.</summary>
 public ReadOnlySpan <char> AsSpan() => _vsb.AsSpan();