コード例 #1
0
ファイル: Renderer.cs プロジェクト: Pyratron/PyraUI
 /// <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;
 }
コード例 #2
0
ファイル: Renderer.cs プロジェクト: Pyratron/PyraUI
 public TextRenderProperties(string text, Color color, FontStyle style)
 {
     Text = text;
     Color = color;
     Style = style;
 }
コード例 #3
0
ファイル: Renderer.cs プロジェクト: Pyratron/PyraUI
        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);
        }
コード例 #4
0
ファイル: Renderer.cs プロジェクト: Pyratron/PyraUI
 /// <summary>
 /// Stretches a rectangle to fill the bounds and create a shadow effect.
 /// </summary>
 public abstract void StretchRectangle(Rectangle area, Color color, Rectangle bounds);
コード例 #5
0
ファイル: DropShadowEffect.cs プロジェクト: Pyratron/PyraUI
 public DropShadowEffect(Manager manager, int blurRadius, Color color)
     : base(manager)
 {
     BlurRadius = blurRadius;
     Color = color;
 }
コード例 #6
0
ファイル: ColorBrush.cs プロジェクト: Pyratron/PyraUI
 public ColorBrush(Color color)
 {
     Color = color;
 }
コード例 #7
0
ファイル: GradientBrush.cs プロジェクト: Pyratron/PyraUI
 public GradientBrush(Color start, Color end)
 {
     Start = start;
     End = end;
 }