示例#1
0
 public static void DrawText(RendererDestinationData destData, SdlDotNet.Graphics.Font font, string text, Color textColor, Point destinationPosition)
 {
     Surface textSurface = font.Render(text, textColor);
     destData.Blit(textSurface, destinationPosition);
     textSurface.Close();
 }
示例#2
0
 public void DrawText(SdlDotNet.Graphics.Font font, string text, Color textColor, Color backgroundColor, Point destinationPosition)
 {
     SdlVideo.Screen.Blit(font.Render(text, textColor, backgroundColor), destinationPosition);
 }
示例#3
0
        public static Surface CreateMultilineStringSurface(string[] lines, SdlDotNet.Graphics.Font font, Color c, TextAlign align)
        {
            Surface[] ts = new Surface[lines.Length];
            int idx = 0;
            int w = 0;
            int y = 0;
            int fh = (int)(font.Height * Constants.LineHeight);
            foreach (string line in lines)
            {
                if (!string.IsNullOrEmpty(line))
                {
                    ts[idx] = font.Render(line, c, true);
                    ts[idx].AlphaBlending = true;
                    if (w < ts[idx].Width) w = ts[idx].Width;
                }
                idx++;
                y += fh;
            }
            if (w <= 0 || y <= 0) return null;

            Surface ret = new Surface(w, y);
            y = 0;
            foreach (Surface s in ts)
            {
                if (s != null)
                {
                    int x = 0;
                    switch (align)
                    {
                        case TextAlign.Left:
                            x = 0;
                            break;
                        case TextAlign.Center:
                            x = (int)(w / 2.0 - s.Width / 2.0);
                            break;
                        case TextAlign.Right:
                            x = w - s.Width;
                            break;
                    }
                    ret.Blit(s, new Point(x, y));
                }
                y += fh;
            }
            foreach (Surface s in ts) if (s != null) s.Dispose();
            return ret;
        }
示例#4
0
 public static void DrawMultilineString(Surface s, string[] lines, SdlDotNet.Graphics.Font font, Color c, Point p)
 {
     int y = p.Y;
     int fh = (int)(font.Height * Constants.LineHeight);
     foreach (string line in lines)
     {
         if (!string.IsNullOrEmpty(line))
         {
             using (Surface ts = font.Render(line, c))
             {
                 s.Blit(ts, new Point(p.X, y));
             }
         }
         y += fh;
     }
 }
示例#5
0
 public static void CreateStrMenu(string[] items, Color c, SdlDotNet.Graphics.Font font, ref SurfaceCollection surfaces, ref Rectangle[] rects, int width = 300, int height = 30)
 {
     int y = 0; int idx = 0;
     if (height < 0) height = (int)(font.Height * Constants.MenuLineHeight);
     foreach (string mi in items)
     {
         Surface s = font.Render(mi, c, true);
         surfaces.Add(s);
         Rectangle r = new Rectangle(0, y, width, height);
         y = r.Bottom;
         rects[idx++] = r;
     }
 }
示例#6
0
 /// <summary>
 /// Creates a new TextSprite given the text, font, color, anti-aliasing flag and position.
 /// </summary>
 /// <param name="textItem">Text to display</param>
 /// <param name="font">The font to use when rendering.</param>
 /// <param name="color">Color of Text</param>
 /// <param name="antiAlias">A flag determining if it's to use anti-aliasing when rendering. Defaults to true.</param>
 /// <param name="position">Position of Sprite</param>
 public TextSprite(
     string textItem,
     SdlDotNet.Graphics.Font font,
     Color color,
     bool antiAlias,
     Point position)
     : base()
 {
     if (font == null)
     {
         throw new ArgumentNullException("font");
     }
     base.Surface = font.Render(textItem, color);
     this.textItem = textItem;
     this.font = font;
     this.color = color;
     this.antiAlias = antiAlias;
     base.Position = position;
     this.RenderInternal();
 }