/// <summary> /// Parse formatted text into separate parts. /// </summary> /// <remarks> /// PyraUI (Monogame) supports bold and italic formatting: /// Italic Text using _Example_ /// Bold Text using *Example* /// Nested formatting is not supported as it would increase the file size (more fonts). /// Colors can be done using [ColorName or #Hex]Text[] /// A color name (e.g. "Red") or hex code is put into brackets to signify the start of a new color. /// Empty brackets show the current color should be removed, and the last used color will be applied. /// (Like a stack) /// </remarks> private static IEnumerable<TextRenderProperties> ParseFormattedText(string text, Color color, FontStyle style) { var parts = new List<TextRenderProperties>(); var sb = new StringBuilder(); bool inBold = false, inItalic = false; var inColor = false; var colors = new Stack<Color>(); colors.Push(color); var ignoreColor = color == Color.Transparent; // Transparent signals not to parse colors. for (var i = 0; i < text.Length; i++) { var character = text[i]; // If we are in a color block, append the characters to the color name, or try and parse the name/color. if (inColor) { if (character == ']') { if (!ignoreColor) { var colorStr = sb.ToString(); // Remove current color if the brackets were empty. if (string.IsNullOrEmpty(colorStr)) colors.Pop(); else { var newColor = (Color) colorStr; colors.Push(newColor); } } inColor = false; sb.Clear(); } else sb.Append(character); } else { // Start/end bold text. if (character == '*') { parts.Add(new TextRenderProperties(sb.ToString(), colors.Peek(), inBold ? FontStyle.Bold : style)); inBold = !inBold; sb.Clear(); } // Start/end italic text. else if (character == '_') { parts.Add(new TextRenderProperties(sb.ToString(), colors.Peek(), inItalic ? FontStyle.Italic : style)); inItalic = !inItalic; sb.Clear(); } // Start a new color block. else if (character == '[') { parts.Add(new TextRenderProperties(sb.ToString(), colors.Peek(), inBold ? FontStyle.Bold : inItalic ? FontStyle.Italic : style)); inColor = true; sb.Clear(); } else sb.Append(character); } } if (colors.Count > 0) parts.Add(new TextRenderProperties(sb.ToString(), colors.Peek(), inBold ? FontStyle.Bold : style)); return parts; }
public TextRenderProperties(string text, Color color, FontStyle style) { Text = text; Color = color; Style = style; }
public override void StretchRectangle(Rectangle area, Color color, Rectangle bounds) { var shadow = (Texture2D) manager.Skin.Textures["shadow"]; var a = area.ToXNA(); var b = bounds.ToXNA(); var half = shadow.Width / 2; var col = color.ToXNA(); FillRectangle(area, color, area); manager.SpriteBatch.Draw(shadow, new RectangleXNA(b.X, b.Y, a.X - b.X, a.Y - b.Y), new RectangleXNA(0, 0, half, half), col); manager.SpriteBatch.Draw(shadow, new RectangleXNA(b.X, a.Y + a.Height, a.X - b.X, a.Y - b.Y), new RectangleXNA(0, half, half, half), col); manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X + a.Width, b.Y, a.X - b.X, a.Y - b.Y), new RectangleXNA(half, 0, half, half), col); manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X + a.Width, a.Y + a.Height, a.X - b.X, a.Y - b.Y), new RectangleXNA(half, half, half, half), col); manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X, b.Y, a.Width, a.Y - b.Y), new RectangleXNA(half, 0, 1, half), col); manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X, a.Y + a.Height, a.Width, a.Y - b.Y), new RectangleXNA(half, half, 1, half), col); manager.SpriteBatch.Draw(shadow, new RectangleXNA(b.X, a.Y, a.X - b.X, a.Height), new RectangleXNA(0, half, half, 1), col); manager.SpriteBatch.Draw(shadow, new RectangleXNA(a.X + a.Width, a.Y, a.X - b.X, a.Height), new RectangleXNA(half, half, half, 1), col); }
/// <summary> /// Stretches a rectangle to fill the bounds and create a shadow effect. /// </summary> public abstract void StretchRectangle(Rectangle area, Color color, Rectangle bounds);
public DropShadowEffect(Manager manager, int blurRadius, Color color) : base(manager) { BlurRadius = blurRadius; Color = color; }
public ColorBrush(Color color) { Color = color; }
public GradientBrush(Color start, Color end) { Start = start; End = end; }