123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System.Text;
- #if MONOGAME || FNA
- using Microsoft.Xna.Framework;
- #elif STRIDE
- using Stride.Core.Mathematics;
- #else
- using Color = Veldrid.RgbaFloat;
- #endif
- namespace FontStashSharp
- {
- internal ref struct TextColorSource
- {
- public TextSource TextSource;
- public Color? SingleColor;
- public Color[] Colors;
- public int ColorPosition;
- public TextColorSource(string text, Color color)
- {
- TextSource = new TextSource(text);
- SingleColor = color;
- Colors = null;
- ColorPosition = 0;
- }
- public TextColorSource(string text, Color[] colors)
- {
- TextSource = new TextSource(text);
- SingleColor = null;
- Colors = colors;
- ColorPosition = 0;
- }
- public TextColorSource(StringSegment text, Color color)
- {
- TextSource = new TextSource(text);
- SingleColor = color;
- Colors = null;
- ColorPosition = 0;
- }
- public TextColorSource(StringSegment text, Color[] colors)
- {
- TextSource = new TextSource(text);
- SingleColor = null;
- Colors = colors;
- ColorPosition = 0;
- }
- public TextColorSource(StringBuilder text, Color color)
- {
- TextSource = new TextSource(text);
- SingleColor = color;
- Colors = null;
- ColorPosition = 0;
- }
- public TextColorSource(StringBuilder text, Color[] colors)
- {
- TextSource = new TextSource(text);
- SingleColor = null;
- Colors = colors;
- ColorPosition = 0;
- }
- public bool IsNull => TextSource.IsNull;
- [System.Obsolete("Possible phase out.")]
- public bool GetNextCodepoint(out int codepoint, out Color color)
- {
- color = Color.Clear;
- if (!TextSource.GetNextCodepoint(out codepoint))
- {
- return false;
- }
- if (SingleColor != null)
- {
- color = SingleColor.Value;
- }
- else
- {
- color = Colors[ColorPosition];
- ++ColorPosition;
- }
- return true;
- }
-
- public bool GetNextCodepoint(out int codepoint)
- {
- return TextSource.GetNextCodepoint(out codepoint);
- }
-
- public Color GetNextColor()
- {
- var color = Color.Clear;
-
- if (SingleColor != null)
- {
- color = SingleColor.Value;
- }
- else
- {
- color = Colors[ColorPosition % Colors.Length];
- ++ColorPosition;
- }
-
- return color;
- }
- }
- }
|