Example #1
0
 /// <summary>
 /// Draws the specified text
 /// </summary>
 /// <param name="text">The text to draw</param>
 /// <param name="position">The position at which to start drawing the text</param>
 /// <param name="font">The <see cref="System.Drawing.Font"/> of the text to draw</param>
 /// <param name="brush">The <see cref="Media.Brush"/> with which to draw the text</param>
 public void DrawText(string text, Media.Point position, Font font, Media.Brush brush)
 {
     Color color;
     Bitmap bitmap;
     Graphics graphics;
     PointF textLocation;
     OpenTK.Graphics.TextExtents textExtents;
     if (string.IsNullOrWhiteSpace(text))
     {
         return;
     }
     if (!typeof(Media.SolidColorBrush).IsAssignableFrom(brush.GetType()))
     {
         throw new NotSupportedException("Only the SolidColorBrush type is currently supported as brush argument of the DrawingContext's 'DrawText' method");
     }
     color = ((Media.SolidColorBrush)brush).Color;
     bitmap = new Bitmap(10, 10);
     graphics = Graphics.FromImage(bitmap);
     textLocation = position.ToPointF();
     textExtents = DrawingContext.MeasureTextExtents(text, font);
     DrawingContext.TextPrinter.Begin();
     DrawingContext.TextPrinter.Print(text, font, color, new RectangleF(position.ToPointF().X, position.ToPointF().Y, textExtents.BoundingBox.Width * 1.5f, textExtents.BoundingBox.Height * 1.5f), OpenTK.Graphics.TextPrinterOptions.Default, OpenTK.Graphics.TextAlignment.Near);
     DrawingContext.TextPrinter.End();
 }