From 6ce200cdae4bf4555a9f2ed60fa4d127c68cab9a Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sat, 24 May 2008 07:47:30 +0000 Subject: [PATCH] Allow the user to code his own ITextPrinterImplementation. --- .../Utilities/Fonts/IPrinterImplementation.cs | 27 ++++++++++++++++--- Source/Utilities/Fonts/TextPrinter.cs | 17 ++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Source/Utilities/Fonts/IPrinterImplementation.cs b/Source/Utilities/Fonts/IPrinterImplementation.cs index 1b332c9c..c849ed1f 100644 --- a/Source/Utilities/Fonts/IPrinterImplementation.cs +++ b/Source/Utilities/Fonts/IPrinterImplementation.cs @@ -15,10 +15,31 @@ namespace OpenTK.Graphics /// /// Defines the interface for TextPrinter implementations. /// - interface ITextPrinterImplementation + public interface ITextPrinterImplementation { - TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count); + /// + /// Caches a text fragment for future use. + /// + /// The vertex array for the text fragment. + /// The index array for the text fragment. Please use the indexCount parameter + /// instead of indices.Count, as the indices array may be larger than necessary for performance reasons. + /// The actual number of indices in the text fragment. + /// A TextHandle that can be used to draw the text fragment. + TextHandle Load(Vector2[] vertices, ushort[] indices, int indexCount); + + /// + /// Draws the specified cached text fragment. + /// + /// The TextHandle corresponding to the desired text fragment. void Draw(TextHandle handle); - void Draw(Vector2[] vertices, ushort[] indices, int index_count); + + /// + /// Draws a text fragment, without caching. + /// + /// The vertex array for the text fragment. + /// The index array for the text fragment. Please use the indexCount parameter + /// instead of indices.Count, as the indices array may be larger than necessary for performance reasons. + /// The actual number of indices in the text fragment. + void Draw(Vector2[] vertices, ushort[] indices, int indexCount); } } diff --git a/Source/Utilities/Fonts/TextPrinter.cs b/Source/Utilities/Fonts/TextPrinter.cs index b66cacb9..f46f5c4e 100644 --- a/Source/Utilities/Fonts/TextPrinter.cs +++ b/Source/Utilities/Fonts/TextPrinter.cs @@ -28,23 +28,30 @@ namespace OpenTK.Graphics public class TextPrinter : ITextPrinter { //static Regex break_point = new Regex("[ .,/*-+?\\!=]", RegexOptions.Compiled | RegexOptions.IgnoreCase); - //static char[] split_chars = new char[] - //{ - // ' ', '\n', '\t', ',', '.', '/', '?', '!', ';', '\\', '-', '+', '*', '=' + //static char[] split_chars = new char[] + //{ + // ' ', '\n', '\t', ',', '.', '/', '?', '!', ';', '\\', '-', '+', '*', '=' //}; static ITextPrinterImplementation printer; - float[] viewport = new float[4]; + float[] viewport = new float[4]; // Interleaved, vertex, texcoord, vertex, etc... Starts with 8 chars, will expand as needed. Vector2[] vertices = new Vector2[8 * 8]; ushort[] indices = new ushort[6 * 8]; - #region --- Constructor --- + #region --- Constructors --- /// /// Constructs a new TextPrinter object. /// public TextPrinter() { } + public TextPrinter(ITextPrinterImplementation implementation) + { + if (implementation == null) + throw new ArgumentNullException("implementation"); + printer = implementation; + } + #endregion #region --- Private Members ---