/// <summary> /// Constructs a new picture with the given texture. /// </summary> /// <param name="texture">The texture that the picture should use.</param> public Picture(Texture texture) : this() { if (texture == null) throw new ArgumentNullException(nameof(texture)); this.texture = texture; }
/// <summary> /// Constructs new drawable text for the given text with the given font-family, font-size and string format. /// The text will be restricted in width to the given maxWidth. /// </summary> /// <param name="text">The text that should be drawn.</param> /// <param name="fontFamily">The font family with which the text should be drawn.</param> /// <param name="emSize">The size at which the text should be drawn.</param> /// <param name="color">The color the text should be drawn with.</param> /// <param name="maxWidth">The maximum width the text should fit in.</param> /// <param name="format">Formatting options for the drawn text.</param> public Text(string text, string fontFamily, float emSize, Color color, int maxWidth, StringFormat format) { // cache? Font font = new Font(fontFamily, emSize); SizeF stringSize = graphics.MeasureString(text, font, maxWidth, format); Bitmap bmp = new Bitmap((int)stringSize.Width + 1, (int)stringSize.Height + 1); System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(bmp); gfx.DrawString(text, font, new SolidBrush(color), new PointF(0, 0)); texture = new Texture(bmp); }
/// <summary> /// Disposes of the internal texture the picture uses. /// </summary> public void Dispose() { texture.Dispose(); texture = null; }