mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 17:25:28 +00:00
Deleted OpenTK.Utilities project.
This commit is contained in:
parent
bb49daff4c
commit
6b46659b0e
77
Source/Examples/Properties/Resources.Designer.cs
generated
77
Source/Examples/Properties/Resources.Designer.cs
generated
|
@ -1,7 +1,7 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:2.0.50727.4918
|
||||
// Runtime Version:2.0.50727.3074
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
|
@ -164,15 +164,16 @@ namespace Examples.Properties {
|
|||
///using System.Diagnostics;
|
||||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///using OpenTK.Input;
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
///{
|
||||
///#if false
|
||||
/// /// <summary>
|
||||
/// /// Shows how to render and scroll large amounts of text.
|
||||
/// /// </summary>
|
||||
/// [Example("Font rendering (advanced)", [rest of string was truncated]";.
|
||||
/// [Example("Font rende [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string FontRenderingAdvanced {
|
||||
get {
|
||||
|
@ -181,23 +182,17 @@ namespace Examples.Properties {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to using System;
|
||||
///using System.Collections.Generic;
|
||||
///using System.ComponentModel;
|
||||
///using System.Data;
|
||||
///using System.Drawing;
|
||||
///using System.Text;
|
||||
///using System.Windows.Forms;
|
||||
///using OpenTK.Graphics;
|
||||
///
|
||||
///namespace Examples.WinForms
|
||||
///{
|
||||
/// [Example("Font rendering (basic)", ExampleCategory.OpenTK, "Fonts", Difficulty = 1, Documentation = "FontRenderingBasic")]
|
||||
/// public partial class FontRenderingBasic : Form
|
||||
/// {
|
||||
/// #region Fields
|
||||
///
|
||||
/// float[] sizes = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1 [rest of string was truncated]";.
|
||||
/// Looks up a localized string similar to #region License
|
||||
/////
|
||||
///// The Open Toolkit Library License
|
||||
/////
|
||||
///// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
/////
|
||||
///// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
///// of this software and associated documentation files (the "Software"), to deal
|
||||
///// in the Software without restriction, including without limitation the rights to
|
||||
///// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
///// the Software, and to permit persons to whom the Softwa [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string FontRenderingBasic {
|
||||
get {
|
||||
|
@ -279,13 +274,13 @@ namespace Examples.Properties {
|
|||
///using System.Threading;
|
||||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///using OpenTK.Input;
|
||||
///
|
||||
///namespace Examples.Tests
|
||||
///{
|
||||
/// [Example("GameWindow states", ExampleCategory.OpenTK, "Test", Documentation="GameWindowStates")]
|
||||
/// public class GameWindowStates : Ga [rest of string was truncated]";.
|
||||
/// public class GameWindowStat [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string GameWindowStates {
|
||||
get {
|
||||
|
@ -312,10 +307,9 @@ namespace Examples.Properties {
|
|||
///using System.Diagnostics;
|
||||
///using System.Threading;
|
||||
///
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///using OpenTK.Platform;
|
||||
///
|
||||
///#endr [rest of string was truncated]";.
|
||||
/// [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string GLControlGameLoop {
|
||||
get {
|
||||
|
@ -408,9 +402,8 @@ namespace Examples.Properties {
|
|||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
///{ [rest of string was truncated]";.
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///
/// [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string JuliaSetFractal {
|
||||
get {
|
||||
|
@ -459,13 +452,14 @@ namespace Examples.Properties {
|
|||
///using System.IO;
|
||||
///
|
||||
///using OpenTK.Audio;
|
||||
///using OpenTK.Audio.OpenAL;
|
||||
///
|
||||
///namespace Examples
|
||||
///{
|
||||
/// [Example("Playback", ExampleCategory.OpenAL, "1.1", Documentation="Playback")]
|
||||
/// public class Playback
|
||||
/// {
|
||||
/// static readonly string filename = Path.Comb [rest of string was truncated]";.
|
||||
/// static readonly [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string Playback {
|
||||
get {
|
||||
|
@ -510,13 +504,13 @@ namespace Examples.Properties {
|
|||
///using System.Windows.Forms;
|
||||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///
|
||||
///#endregion
|
||||
///
|
||||
///namespace Examples.WinForms
|
||||
///{
|
||||
/// [Example("Simple GLControl", ExampleCategory.OpenTK, "GLControl", 1, Document [rest of string was truncated]";.
|
||||
/// [Example("Simple GLControl", ExampleCategory.OpenTK, "GLControl", 1, D [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string SimpleGLControl {
|
||||
get {
|
||||
|
@ -565,7 +559,7 @@ namespace Examples.Properties {
|
|||
///using System.Diagnostics;
|
||||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///using OpenTK.Input;
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
|
@ -573,7 +567,7 @@ namespace Examples.Properties {
|
|||
/// /// <summary>
|
||||
/// /// Demonstrates the GameWindow class.
|
||||
/// /// </summary>
|
||||
/// [Example("Simple Window", ExampleCategory.OpenTK, "GameWindow", Documentati [rest of string was truncated]";.
|
||||
/// [Example("Simple Window", ExampleCategory.OpenTK, "GameWindow", Docu [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string SimpleWindow {
|
||||
get {
|
||||
|
@ -597,12 +591,13 @@ namespace Examples.Properties {
|
|||
///using System.ComponentModel;
|
||||
///
|
||||
///using OpenTK.Audio;
|
||||
///using OpenTK.Audio.OpenAL;
|
||||
///
|
||||
///namespace Examples.OpenAL
|
||||
///{
|
||||
/// // Not working correctly (sound pops).
|
||||
///
|
||||
/// //[Example("Streaming Playback", ExampleCateg [rest of string was truncated]";.
|
||||
/// //[Example("Strea [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string StreamingPlayback {
|
||||
get {
|
||||
|
@ -620,19 +615,18 @@ namespace Examples.Properties {
|
|||
///#endregion
|
||||
///
|
||||
///using System;
|
||||
///using System.Diagnostics;
|
||||
///
|
||||
///using OpenTK.Audio;
|
||||
///using OpenTK.Audio.OpenAL;
|
||||
///
|
||||
///using AlContext = System.IntPtr;
|
||||
///using AlDevice = System.IntPtr;
|
||||
///using System.Diagnostics;
|
||||
///
|
||||
///namespace Examples
|
||||
///{
|
||||
/// [Example("AudioContext Test", ExampleCategory.OpenTK, "Test", 0, false)]
|
||||
/// class TestApp
|
||||
/// {
|
||||
/// publ [rest of string was truncated]";.
|
||||
/// class [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string TestAudioContext {
|
||||
get {
|
||||
|
@ -748,13 +742,14 @@ namespace Examples.Properties {
|
|||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///using OpenTK.Platform;
|
||||
///
|
||||
///#endregion
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
///{
|
||||
/// [Example("Vertex Buffer Objects", ExampleCategory.OpenGL, "1.5", false, Documentation="Vert [rest of string was truncated]";.
|
||||
/// [Example("Vertex Buffer Objects", ExampleCategory.OpenGL, "1 [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string VertexBufferObject {
|
||||
get {
|
||||
|
@ -775,7 +770,7 @@ namespace Examples.Properties {
|
|||
///using System.Drawing;
|
||||
///
|
||||
///using OpenTK;
|
||||
///using OpenTK.Graphics;
|
||||
///using OpenTK.Graphics.OpenGL;
|
||||
///using Examples.Shapes;
|
||||
///
|
||||
///namespace Examples.Tutorial
|
||||
|
@ -783,7 +778,7 @@ namespace Examples.Properties {
|
|||
/// /// <summary>
|
||||
/// /// Demonstrates fixed-function OpenGL lighting. Example is incomplete (documentation).
|
||||
/// /// </summary>
|
||||
/// [Example("Vertex Lighting", ExampleCategory.OpenG [rest of string was truncated]";.
|
||||
/// [Example("Vertex Lighting", ExampleCategor [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string VertexLighting {
|
||||
get {
|
||||
|
|
|
@ -1,235 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenTK.Audio
|
||||
{
|
||||
/// <summary>
|
||||
/// Encapsulates a sound stream and provides decoding and streaming capabilities.
|
||||
/// </summary>
|
||||
public class AudioReader : IDisposable
|
||||
{
|
||||
static object reader_lock = new object();
|
||||
static List<AudioReader> readers = new List<AudioReader>();
|
||||
|
||||
bool disposed;
|
||||
Stream stream;
|
||||
AudioReader implementation;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
#region static AudioReader()
|
||||
|
||||
static AudioReader()
|
||||
{
|
||||
// TODO: Plugin architecture for sound formats. This is overkill now that we only have a WaveReader (future proofing).
|
||||
readers.Add(new WaveReader());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region protected AudioReader()
|
||||
|
||||
protected AudioReader() { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public AudioReader(string filename)
|
||||
|
||||
/// <summary>Creates a new AudioReader that can read the specified sound file.</summary>
|
||||
/// <param name="filename">The path to the sound file.</param>
|
||||
/// <returns>A new OpenTK.Audio.AudioReader, which can be used to read from the specified sound file.</returns>
|
||||
public AudioReader(string filename)
|
||||
: this(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public AudioReader(Stream s)
|
||||
|
||||
/// <summary>Creates a new AudioReader that can read the specified soundstream.</summary>
|
||||
/// <param name="s">The System.IO.Stream to read from.</param>
|
||||
/// <returns>A new OpenTK.Audio.AudioReader, which can be used to read from the specified sound stream.</returns>
|
||||
public AudioReader(Stream s)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (reader_lock)
|
||||
{
|
||||
foreach (AudioReader reader in readers)
|
||||
{
|
||||
long pos = s.Position;
|
||||
if (reader.Supports(s))
|
||||
{
|
||||
s.Position = pos;
|
||||
implementation = (AudioReader)
|
||||
reader.GetType().GetConstructor(
|
||||
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public |
|
||||
System.Reflection.BindingFlags.Instance,
|
||||
null,
|
||||
new Type[] { typeof(Stream) },
|
||||
null)
|
||||
.Invoke(new object[] { s });
|
||||
return;
|
||||
}
|
||||
s.Position = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
s.Close();
|
||||
throw;
|
||||
}
|
||||
throw new NotSupportedException("Could not find a decoder for the specified sound stream.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Members ---
|
||||
|
||||
#region public virtual bool Supports(Stream s)
|
||||
|
||||
/// <summary>When overriden in a derived class, checks if the decoder supports the specified sound stream.</summary>
|
||||
/// <param name="s">The System.IO.Stream to check.</param>
|
||||
/// <returns>True if the sound stream is supported; false otherwise.</returns>
|
||||
public virtual bool Supports(Stream s)
|
||||
{
|
||||
if (implementation != null)
|
||||
return implementation.Supports(s);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public virtual SoundData<SampleType> ReadSamples(long count)
|
||||
|
||||
/// <summary>
|
||||
/// When overriden in a derived class, reads and decodes the specified number of samples from the sound stream.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of samples to read and decode.</param>
|
||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
||||
public virtual SoundData ReadSamples(long count)
|
||||
{
|
||||
if (implementation != null)
|
||||
return implementation.ReadSamples(count);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public virtual SoundData<SampleType> ReadToEnd()
|
||||
|
||||
/// <summary>
|
||||
/// When overriden in a derived class, reads and decodes the sound stream.
|
||||
/// </summary>
|
||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
||||
public virtual SoundData ReadToEnd()
|
||||
{
|
||||
if (implementation != null)
|
||||
return implementation.ReadToEnd();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public virtual int Frequency
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public virtual int Frequency
|
||||
{
|
||||
get
|
||||
{
|
||||
if (implementation != null)
|
||||
return implementation.Frequency;
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected set
|
||||
{
|
||||
if (implementation != null)
|
||||
implementation.Frequency = value;
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public virtual bool EndOfFile
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the AudioReader has reached the end of the file.
|
||||
/// </summary>
|
||||
public virtual bool EndOfFile
|
||||
{
|
||||
get
|
||||
{
|
||||
if (implementation != null)
|
||||
return implementation.EndOfFile;
|
||||
|
||||
return this.Stream.Position >= this.Stream.Length;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Protected Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the input <see cref="System.IO.Stream"/> of the AudioReader.
|
||||
/// </summary>
|
||||
protected virtual Stream Stream
|
||||
{
|
||||
get { return stream; }
|
||||
set { stream = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>Closes the underlying Stream and disposes of the AudioReader resources.</summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
void Dispose(bool manual)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (manual)
|
||||
if (this.Stream != null)
|
||||
this.Stream.Close();
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes this AudioReader.
|
||||
/// </summary>
|
||||
~AudioReader()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Audio
|
||||
{
|
||||
/// <summary>Represents exceptions related to OpenTK.Audio.AudioReader objects.</summary>
|
||||
public class AudioReaderException : AudioException
|
||||
{
|
||||
/// <summary>Constructs a new AudioReaderException.</summary>
|
||||
public AudioReaderException() : base() { }
|
||||
/// <summary>Constructs a new AudioReaderException with the specified error message.</summary>
|
||||
/// <param name="message">The error message of the AudioReaderException.</param>
|
||||
public AudioReaderException(string message) : base(message) { }
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace OpenTK.Audio
|
||||
{
|
||||
#if false
|
||||
/// <summary>Defines methods to load and hold sound buffer.</summary>
|
||||
public class Sound<SampleType> : IDisposable
|
||||
{
|
||||
bool disposed;
|
||||
SoundReader<SampleType> reader;
|
||||
SoundData<SampleType> data;
|
||||
|
||||
public Sound(Stream s)
|
||||
{
|
||||
if (s == null) throw new ArgumentNullException("s", "Must be a valid System.IO.Stream.");
|
||||
|
||||
reader = SoundReader.Create(s);
|
||||
}
|
||||
|
||||
public Sound(string filename)
|
||||
{
|
||||
if (String.IsNullOrEmpty(filename)) throw new ArgumentNullException("s", "Must be a valid System.IO.Stream.");
|
||||
|
||||
reader = SoundReader.Create(filename);
|
||||
}
|
||||
|
||||
#region --- Public Members ---
|
||||
|
||||
public SoundData ReadSamples(int count)
|
||||
{
|
||||
if (count <= 0) throw new ArgumentOutOfRangeException("count", "Must be larger than zero.");
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SoundData ReadToEnd()
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
public SoundData SoundData { get { return data; } }
|
||||
|
||||
public void WriteToBuffer(int buffer, int length)
|
||||
{
|
||||
if (buffer == 0) throw new ArgumentOutOfRangeException("buffer", "May not be zero.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IDisposable Members ---
|
||||
|
||||
/// <summary>Disposes of the sound buffer.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool manual)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (manual)
|
||||
reader.Dispose();
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~Sound()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -1,266 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using OpenTK.Audio;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK.Audio
|
||||
{
|
||||
internal sealed class WaveReader : AudioReader
|
||||
{
|
||||
SoundData decoded_data;
|
||||
|
||||
//RIFF header
|
||||
string signature;
|
||||
int riff_chunck_size;
|
||||
string format;
|
||||
|
||||
//WAVE header
|
||||
string format_signature;
|
||||
int format_chunk_size;
|
||||
short audio_format;
|
||||
short channels;
|
||||
int sample_rate;
|
||||
int byte_rate;
|
||||
short block_align;
|
||||
short bits_per_sample;
|
||||
|
||||
//DATA header
|
||||
string data_signature;
|
||||
int data_chunk_size;
|
||||
|
||||
BinaryReader reader;
|
||||
|
||||
internal WaveReader() { }
|
||||
|
||||
internal WaveReader(Stream s)
|
||||
{
|
||||
if (s == null) throw new ArgumentNullException();
|
||||
if (!s.CanRead) throw new ArgumentException("Cannot read from specified Stream.");
|
||||
|
||||
reader = new BinaryReader(s);
|
||||
this.Stream = s;
|
||||
}
|
||||
|
||||
#if false
|
||||
/// <summary>
|
||||
/// Writes the WaveSound's data to the specified OpenAL buffer in the correct format.
|
||||
/// </summary>
|
||||
/// <param name="bid">
|
||||
/// A <see cref="System.UInt32"/>
|
||||
/// </param>
|
||||
public void WriteToBuffer(uint bid)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
//fix the array as a byte
|
||||
fixed (byte* p_Data = _Data)
|
||||
{
|
||||
if (Channels == 1)
|
||||
{
|
||||
if (BitsPerSample == 16)
|
||||
{
|
||||
Console.Write("Uploading 16 bit mono data to OpenAL...");
|
||||
AL.BufferData(bid, ALFormat.Mono16, (IntPtr)p_Data, _Data.Length, SampleRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BitsPerSample == 8)
|
||||
{
|
||||
Console.Write("Uploading 8 bit mono data to OpenAL...");
|
||||
AL.BufferData(bid, ALFormat.Mono8, (IntPtr)p_Data, _Data.Length, SampleRate);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Channels == 2)
|
||||
{
|
||||
if (BitsPerSample == 16)
|
||||
{
|
||||
Console.Write("Uploading 16 bit stereo data to OpenAL...");
|
||||
AL.BufferData(bid, ALFormat.Stereo16, (IntPtr)p_Data, _Data.Length, SampleRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BitsPerSample == 8)
|
||||
{
|
||||
Console.Write("Uploading 8 bit stereo data to OpenAL...");
|
||||
AL.BufferData(bid, ALFormat.Stereo8, (IntPtr)p_Data, _Data.Length, SampleRate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes all relevent information about the WaveSound to the console window.
|
||||
/// </summary>
|
||||
public void DumpParamsToConsole()
|
||||
{
|
||||
Console.WriteLine("AudioFormat:" + AudioFormat);
|
||||
Console.WriteLine("Channels:" + Channels);
|
||||
Console.WriteLine("SampleRate:" + SampleRate);
|
||||
Console.WriteLine("ByteRate:" + ByteRate);
|
||||
Console.WriteLine("BlockAlign:" + BlockAlign);
|
||||
Console.WriteLine("BitsPerSample:" + BitsPerSample);
|
||||
}
|
||||
|
||||
/// <value>
|
||||
/// Returns the WaveSound's raw sound data as an array of bytes.
|
||||
/// </value>
|
||||
public byte[] Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Data;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#region --- Public Members ---
|
||||
|
||||
#region public override bool Supports(Stream s)
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the specified stream contains valid WAVE/RIFF buffer.
|
||||
/// </summary>
|
||||
/// <param name="s">The System.IO.Stream to check.</param>
|
||||
/// <returns>True if the stream is a valid WAVE/RIFF file; false otherwise.</returns>
|
||||
public override bool Supports(Stream s)
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(s);
|
||||
return this.ReadHeaders(reader);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override SoundData ReadSamples(int samples)
|
||||
|
||||
/// <summary>
|
||||
/// Reads and decodes the specified number of samples from the sound stream.
|
||||
/// </summary>
|
||||
/// <param name="samples">The number of samples to read and decode.</param>
|
||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
||||
public override SoundData ReadSamples(long samples)
|
||||
{
|
||||
if (samples > reader.BaseStream.Length - reader.BaseStream.Position)
|
||||
samples = reader.BaseStream.Length - reader.BaseStream.Position;
|
||||
|
||||
//while (samples > decoded_data.Data.Length * (bits_per_sample / 8))
|
||||
// Array.Resize<byte>(ref decoded_data.Data, decoded_data.Data.Length * 2);
|
||||
|
||||
decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate),
|
||||
reader.ReadBytes((int)samples));
|
||||
|
||||
return decoded_data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override SoundData ReadToEnd()
|
||||
|
||||
/// <summary>
|
||||
/// Reads and decodes the sound stream.
|
||||
/// </summary>
|
||||
/// <returns>An OpenTK.Audio.SoundData object that contains the decoded buffer.</returns>
|
||||
public override SoundData ReadToEnd()
|
||||
{
|
||||
try
|
||||
{
|
||||
//read the buffer into a byte array, even if the format is 16 bit
|
||||
//decoded_data = new byte[data_chunk_size];
|
||||
|
||||
decoded_data = new SoundData(new SoundFormat(channels, bits_per_sample, sample_rate),
|
||||
reader.ReadBytes((int)reader.BaseStream.Length));
|
||||
|
||||
Debug.WriteLine("decoded!");
|
||||
|
||||
//return new SoundData(decoded_data, new SoundFormat(channels, bits_per_sample, sample_rate));
|
||||
return decoded_data;
|
||||
}
|
||||
catch (AudioReaderException)
|
||||
{
|
||||
reader.Close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Protected Members ---
|
||||
|
||||
protected override Stream Stream
|
||||
{
|
||||
get { return base.Stream; }
|
||||
set
|
||||
{
|
||||
base.Stream = value;
|
||||
if (!ReadHeaders(reader))
|
||||
throw new AudioReaderException("Invalid WAVE/RIFF file: invalid or corrupt signature.");
|
||||
|
||||
Debug.Write(String.Format("Opened WAVE/RIFF file: ({0}, {1}, {2}, {3}) ", sample_rate.ToString(), bits_per_sample.ToString(),
|
||||
channels.ToString(), audio_format.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Private Members ---
|
||||
|
||||
// Tries to read the WAVE/RIFF headers, and returns true if they are valid.
|
||||
bool ReadHeaders(BinaryReader reader)
|
||||
{
|
||||
// Don't explicitly call reader.Close()/.Dispose(), as that will close the inner stream.
|
||||
// There's no such danger if the BinaryReader isn't explicitly destroyed.
|
||||
|
||||
// RIFF header
|
||||
signature = new string(reader.ReadChars(4));
|
||||
if (signature != "RIFF")
|
||||
return false;
|
||||
|
||||
riff_chunck_size = reader.ReadInt32();
|
||||
|
||||
format = new string(reader.ReadChars(4));
|
||||
if (format != "WAVE")
|
||||
return false;
|
||||
|
||||
// WAVE header
|
||||
format_signature = new string(reader.ReadChars(4));
|
||||
if (format_signature != "fmt ")
|
||||
return false;
|
||||
|
||||
format_chunk_size = reader.ReadInt32();
|
||||
audio_format = reader.ReadInt16();
|
||||
channels = reader.ReadInt16();
|
||||
sample_rate = reader.ReadInt32();
|
||||
byte_rate = reader.ReadInt32();
|
||||
block_align = reader.ReadInt16();
|
||||
bits_per_sample = reader.ReadInt16();
|
||||
|
||||
data_signature = new string(reader.ReadChars(4));
|
||||
if (data_signature != "data")
|
||||
return false;
|
||||
|
||||
data_chunk_size = reader.ReadInt32();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
[Obsolete()]
|
||||
class DisplayListTextHandle : TextHandle
|
||||
{
|
||||
public DisplayListTextHandle(int handle) : base(handle) { }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("TextHandle (display list): {0}", Handle);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool manual)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (manual)
|
||||
{
|
||||
GL.DeleteLists(Handle, 1);
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides text printing through OpenGL 1.1 Display Lists.
|
||||
/// </summary>
|
||||
[Obsolete()]
|
||||
class DisplayListTextPrinter : ITextPrinterImplementation
|
||||
{
|
||||
#region IPrinter Members
|
||||
|
||||
public TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count)
|
||||
{
|
||||
DisplayListTextHandle handle = new DisplayListTextHandle(GL.GenLists(1));
|
||||
|
||||
GL.NewList(handle.Handle, ListMode.Compile);
|
||||
|
||||
this.Draw(vertices, indices, index_count);
|
||||
|
||||
GL.EndList();
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
public void Draw(TextHandle handle)
|
||||
{
|
||||
GL.CallList(handle.Handle);
|
||||
}
|
||||
|
||||
public void Draw(Vector2[] vertices, ushort[] indices, int index_count)
|
||||
{
|
||||
GL.Begin(BeginMode.Triangles);
|
||||
|
||||
for (int i = 0; i < index_count; i++)
|
||||
//foreach (ushort index in indices)
|
||||
{
|
||||
GL.TexCoord2(vertices[indices[i] + 1]);
|
||||
GL.Vertex2(vertices[indices[i]]);
|
||||
}
|
||||
|
||||
GL.End();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,176 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
using Graphics = System.Drawing.Graphics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single character of a specific Font.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
struct Glyph : IPackable<Glyph>
|
||||
{
|
||||
char character;
|
||||
Font font;
|
||||
SizeF size;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
// Constructs a new Glyph that represents the given character and Font.
|
||||
public Glyph(char c, Font f, SizeF s)
|
||||
{
|
||||
if (f == null)
|
||||
throw new ArgumentNullException("f", "You must specify a valid font");
|
||||
character = c;
|
||||
font = f;
|
||||
size = s;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public char Character
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character represented by this Glyph.
|
||||
/// </summary>
|
||||
public char Character
|
||||
{
|
||||
get { return character; }
|
||||
private set { character = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Font Font
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Font of this Glyph.
|
||||
/// </summary>
|
||||
public Font Font
|
||||
{
|
||||
get { return font; }
|
||||
private set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("Font", "Glyph font cannot be null");
|
||||
|
||||
font = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override bool Equals(object obj)
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given object is equal (memberwise) to the current Glyph.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj to check.</param>
|
||||
/// <returns>True, if the object is identical to the current Glyph.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Glyph)
|
||||
return this.Equals((Glyph)obj);
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Describes this Glyph object.
|
||||
/// </summary>
|
||||
/// <returns>Returns a System.String describing this Glyph.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("'{0}', {1} {2}, {3} {4}, ({5}, {6})", Character, Font.Name, font.Style, font.Size, font.Unit, Width, Height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override int GetHashCode()
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the hashcode for this Glyph.
|
||||
/// </summary>
|
||||
/// <returns>A System.Int32 containing a hashcode that uniquely identifies this Glyph.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return character.GetHashCode() ^ font.GetHashCode() ^ size.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public SizeF Size
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of this Glyph.
|
||||
/// </summary>
|
||||
public SizeF Size { get { return size; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public RectangleF Rectangle
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bounding box of this Glyph.
|
||||
/// </summary>
|
||||
public RectangleF Rectangle { get { return new RectangleF(PointF.Empty, Size); } }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IPackable<T> Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the width of the Glyph in pixels.
|
||||
/// </summary>
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)System.Math.Ceiling(size.Width);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an integer representing the height of the Glyph in pixels.
|
||||
/// </summary>
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)System.Math.Ceiling(size.Height);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IEquatable<Glyph> Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Compares the current Glyph with the given Glyph.
|
||||
/// </summary>
|
||||
/// <param name="other">The Glyph to compare to.</param>
|
||||
/// <returns>True if both Glyphs represent the same character of the same Font, false otherwise.</returns>
|
||||
public bool Equals(Glyph other)
|
||||
{
|
||||
return Character == other.Character && Font == other.Font && Size == other.Size;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
[Obsolete]
|
||||
public interface IFont : IDisposable
|
||||
{
|
||||
void LoadGlyphs(string glyphs);
|
||||
float Height { get; }
|
||||
void MeasureString(string str, out float width, out float height);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the interface for TextPrinter implementations.
|
||||
/// </summary>
|
||||
[Obsolete("Use ITextOutputProvider instead")]
|
||||
public interface ITextPrinterImplementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Caches a text fragment for future use.
|
||||
/// </summary>
|
||||
/// <param name="vertices">The vertex array for the text fragment.</param>
|
||||
/// <param name="indices">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.</param>
|
||||
/// <param name="indexCount">The actual number of indices in the text fragment.</param>
|
||||
/// <returns>A TextHandle that can be used to draw the text fragment.</returns>
|
||||
TextHandle Load(Vector2[] vertices, ushort[] indices, int indexCount);
|
||||
|
||||
/// <summary>
|
||||
/// Draws the specified cached text fragment.
|
||||
/// </summary>
|
||||
/// <param name="handle">The TextHandle corresponding to the desired text fragment.</param>
|
||||
void Draw(TextHandle handle);
|
||||
|
||||
/// <summary>
|
||||
/// Draws a text fragment, without caching.
|
||||
/// </summary>
|
||||
/// <param name="vertices">The vertex array for the text fragment.</param>
|
||||
/// <param name="indices">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.</param>
|
||||
/// <param name="indexCount">The actual number of indices in the text fragment.</param>
|
||||
void Draw(Vector2[] vertices, ushort[] indices, int indexCount);
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a handle to cached text.
|
||||
/// </summary>
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
public class TextHandle : IDisposable
|
||||
{
|
||||
internal string Text;
|
||||
internal System.Drawing.Font GdiPFont;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new TextHandle,
|
||||
/// </summary>
|
||||
/// <param name="handle"></param>
|
||||
internal TextHandle(int handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
internal TextHandle(string text, System.Drawing.Font font)
|
||||
{
|
||||
Text = text;
|
||||
GdiPFont = font;
|
||||
}
|
||||
|
||||
private int handle;
|
||||
protected TextureFont font;
|
||||
protected bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the handle of the cached text run. Call the OpenTK.Graphics.ITextPrinter.Draw() method
|
||||
/// to draw the text represented by this TextHandle.
|
||||
/// </summary>
|
||||
public int Handle
|
||||
{
|
||||
get { return handle; }
|
||||
protected set { handle = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the TextureFont used for this text run.
|
||||
/// </summary>
|
||||
public TextureFont Font
|
||||
{
|
||||
get { return font; }
|
||||
internal set { font = value; }
|
||||
}
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Returns a System.String that represents the current TextHandle.
|
||||
/// </summary>
|
||||
/// <returns>a System.String that descibes the current TextHandle.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("TextHandle: {0}", Handle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IDisposable Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Frees the resource consumed by the TextHandle.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
protected virtual void Dispose(bool manual) { }
|
||||
~TextHandle() { this.Dispose(false); }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,563 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
using Graphics = System.Drawing.Graphics;
|
||||
using PixelFormat = OpenTK.Graphics.OpenGL.PixelFormat;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
[Obsolete("Use System.Drawing.Font instead")]
|
||||
public class TextureFont : IFont
|
||||
{
|
||||
internal Font font;
|
||||
Dictionary<char, RectangleF> loaded_glyphs = new Dictionary<char, RectangleF>(64);
|
||||
|
||||
Bitmap bmp;
|
||||
Graphics gfx;
|
||||
// TODO: We need to be able to use multiple font sheets.
|
||||
static int texture;
|
||||
static TexturePacker<Glyph> pack;
|
||||
static int texture_width, texture_height;
|
||||
static readonly StringFormat default_string_format = StringFormat.GenericTypographic; // Check the constructor, too, for additional flags.
|
||||
static readonly StringFormat load_glyph_string_format = StringFormat.GenericDefault;
|
||||
static SizeF maximum_graphics_size;
|
||||
|
||||
int[] data = new int[256]; // Used to upload the glyph buffer to the OpenGL texture.
|
||||
|
||||
object upload_lock = new object();
|
||||
|
||||
static readonly char[] newline_characters = new char[] { '\n', '\r' };
|
||||
|
||||
#region --- Constructor ---
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new TextureFont, using the specified System.Drawing.Font.
|
||||
/// </summary>
|
||||
/// <param name="font">The System.Drawing.Font to use.</param>
|
||||
public TextureFont(Font font)
|
||||
{
|
||||
if (font == null)
|
||||
throw new ArgumentNullException("font", "Argument to TextureFont constructor cannot be null.");
|
||||
|
||||
this.font = font;
|
||||
|
||||
bmp = new Bitmap(font.Height * 2, font.Height * 2);
|
||||
gfx = Graphics.FromImage(bmp);
|
||||
maximum_graphics_size = gfx.ClipBounds.Size;
|
||||
|
||||
// Adjust font rendering mode. Small sizes look blurry without gridfitting, so turn
|
||||
// that on. Increasing contrast also seems to help.
|
||||
if (font.Size <= 18.0f)
|
||||
{
|
||||
gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||
//gfx.TextContrast = 11;
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||
//gfx.TextContrast = 0;
|
||||
}
|
||||
|
||||
default_string_format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new TextureFont, using the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="family">The System.Drawing.FontFamily to use for the typeface.</param>
|
||||
/// <param name="emSize">The em size to use for the typeface.</param>
|
||||
public TextureFont(FontFamily family, float emSize)
|
||||
: this(new Font(family, emSize))
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new TextureFont, using the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="family">The System.Drawing.FontFamily to use for the typeface.</param>
|
||||
/// <param name="emSize">The em size to use for the typeface.</param>
|
||||
/// <param name="style">The style to use for the typeface.</param>
|
||||
public TextureFont(FontFamily family, float emSize, FontStyle style)
|
||||
: this(new Font(family, emSize, style))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public void LoadGlyphs(string glyphs)
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the specified glyphs for rendering.
|
||||
/// </summary>
|
||||
/// <param name="glyphs">The glyphs to prepare for rendering.</param>
|
||||
public void LoadGlyphs(string glyphs)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
foreach (char c in glyphs)
|
||||
{
|
||||
if (Char.IsWhiteSpace(c))
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
if (!loaded_glyphs.ContainsKey(c))
|
||||
LoadGlyph(c, out rect);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Print(e.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void LoadGlyph(char glyph)
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the specified glyph for rendering.
|
||||
/// </summary>
|
||||
/// <param name="glyph">The glyph to prepare for rendering.</param>
|
||||
public void LoadGlyph(char glyph)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
if (!loaded_glyphs.ContainsKey(glyph))
|
||||
LoadGlyph(glyph, out rect);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool GlyphData(char glyph, out float width, out float height, out RectangleF textureRectangle, out int texture)
|
||||
|
||||
/// <summary>
|
||||
/// Returns the characteristics of a loaded glyph.
|
||||
/// </summary>
|
||||
/// <param name="glyph">The character corresponding to this glyph.</param>
|
||||
/// <param name="width">The width of this glyph.</param>
|
||||
/// <param name="height">The height of this glyph (line spacing).</param>
|
||||
/// <param name="textureRectangle">The bounding box of the texture buffer of this glyph.</param>
|
||||
/// <param name="texture">The handle to the texture that contains this glyph.</param>
|
||||
/// <returns>True if the glyph has been loaded, false otherwise.</returns>
|
||||
/// <seealso cref="LoadGlyphs"/>
|
||||
public bool GlyphData(char glyph, out float width, out float height, out RectangleF textureRectangle, out int texture)
|
||||
{
|
||||
if (loaded_glyphs.TryGetValue(glyph, out textureRectangle))
|
||||
{
|
||||
width = textureRectangle.Width * texture_width;
|
||||
height = textureRectangle.Height * texture_height;
|
||||
texture = TextureFont.texture;
|
||||
return true;
|
||||
}
|
||||
width = height = texture = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public float Height
|
||||
|
||||
/// <summary>
|
||||
/// Gets a float indicating the default line spacing of this font.
|
||||
/// </summary>
|
||||
public float Height
|
||||
{
|
||||
get { return font.Height; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public float Width
|
||||
|
||||
/// <summary>
|
||||
/// Gets a float indicating the default size of this font, in points.
|
||||
/// </summary>
|
||||
public float Width
|
||||
{
|
||||
get { return font.SizeInPoints; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void MeasureString(string str, out float width, out float height, bool accountForOverhangs)
|
||||
|
||||
/// <summary>
|
||||
/// Measures the width of the specified string.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to measure.</param>
|
||||
/// <param name="width">The measured width.</param>
|
||||
/// <param name="height">The measured height.</param>
|
||||
/// <param name="accountForOverhangs">If true, adds space to account for glyph overhangs. Set to true if you wish to measure a complete string. Set to false if you wish to perform layout on adjacent strings.</param>
|
||||
[Obsolete("Returns invalid results - use MeasureText() instead")]
|
||||
public void MeasureString(string str, out float width, out float height, bool accountForOverhangs)
|
||||
{
|
||||
System.Drawing.StringFormat format = accountForOverhangs ? System.Drawing.StringFormat.GenericDefault : System.Drawing.StringFormat.GenericTypographic;
|
||||
|
||||
System.Drawing.SizeF size = gfx.MeasureString(str, font, 16384, format);
|
||||
height = size.Height;
|
||||
width = size.Width;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void MeasureString(string str, out float width, out float height)
|
||||
|
||||
/// <summary>
|
||||
/// Measures the width of the specified string.
|
||||
/// </summary>
|
||||
/// <param name="str">The string to measure.</param>
|
||||
/// <param name="width">The measured width.</param>
|
||||
/// <param name="height">The measured height.</param>
|
||||
/// <seealso cref="MeasureString(string, out float, out float, bool)"/>
|
||||
[Obsolete("Returns invalid results - use MeasureText() instead")]
|
||||
public void MeasureString(string str, out float width, out float height)
|
||||
{
|
||||
MeasureString(str, out width, out height, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public RectangleF MeasureText(string text)
|
||||
|
||||
/// <summary>
|
||||
/// Calculates size information for the specified text.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to measure.</param>
|
||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
||||
public RectangleF MeasureText(string text)
|
||||
{
|
||||
return MeasureText(text, SizeF.Empty, default_string_format, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public RectangleF MeasureText(string text, SizeF bounds)
|
||||
|
||||
/// <summary>
|
||||
/// Calculates size information for the specified text.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to measure.</param>
|
||||
/// <param name="bounds">A SizeF structure containing the maximum desired width and height of the text. Default is SizeF.Empty.</param>
|
||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
||||
public RectangleF MeasureText(string text, SizeF bounds)
|
||||
{
|
||||
return MeasureText(text, bounds, default_string_format, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public RectangleF MeasureText(string text, SizeF bounds, StringFormat format)
|
||||
|
||||
/// <summary>
|
||||
/// Calculates size information for the specified text.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to measure.</param>
|
||||
/// <param name="bounds">A SizeF structure containing the maximum desired width and height of the text. Pass SizeF.Empty to disable wrapping calculations. A width or height of 0 disables the relevant calculation.</param>
|
||||
/// <param name="format">A StringFormat object which specifies the measurement format of the string. Pass null to use the default StringFormat (StringFormat.GenericTypographic).</param>
|
||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
||||
public RectangleF MeasureText(string text, SizeF bounds, StringFormat format)
|
||||
{
|
||||
return MeasureText(text, bounds, format, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public RectangleF MeasureText(string text, SizeF bounds, StringFormat format, IList<RectangleF> ranges)
|
||||
|
||||
IntPtr[] regions = new IntPtr[GdiPlus.MaxMeasurableCharacterRanges];
|
||||
CharacterRange[] characterRanges = new CharacterRange[GdiPlus.MaxMeasurableCharacterRanges];
|
||||
|
||||
/// <summary>
|
||||
/// Calculates size information for the specified text.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to measure.</param>
|
||||
/// <param name="bounds">A SizeF structure containing the maximum desired width and height of the text. Pass SizeF.Empty to disable wrapping calculations. A width or height of 0 disables the relevant calculation.</param>
|
||||
/// <param name="format">A StringFormat object which specifies the measurement format of the string. Pass null to use the default StringFormat (StringFormat.GenericDefault).</param>
|
||||
/// <param name="ranges">Fills the specified IList of RectangleF structures with position information for individual characters. If this argument is null, these calculations are skipped.</param>
|
||||
/// <returns>A RectangleF containing the bounding box for the specified text.</returns>
|
||||
public RectangleF MeasureText(string text, SizeF bounds, StringFormat format, List<RectangleF> ranges)
|
||||
{
|
||||
if (String.IsNullOrEmpty(text))
|
||||
return RectangleF.Empty;
|
||||
|
||||
if (bounds == SizeF.Empty)
|
||||
bounds = maximum_graphics_size;
|
||||
|
||||
if (format == null)
|
||||
format = default_string_format;
|
||||
|
||||
// TODO: What should we do in this case?
|
||||
if (ranges == null)
|
||||
ranges = new List<RectangleF>();
|
||||
|
||||
ranges.Clear();
|
||||
|
||||
PointF origin = PointF.Empty;
|
||||
SizeF size = SizeF.Empty;
|
||||
|
||||
IntPtr native_graphics = GdiPlus.GetNativeGraphics(gfx);
|
||||
IntPtr native_font = GdiPlus.GetNativeFont(font);
|
||||
IntPtr native_string_format = GdiPlus.GetNativeStringFormat(format);
|
||||
|
||||
RectangleF layoutRect = new RectangleF(PointF.Empty, bounds);
|
||||
|
||||
int height = 0;
|
||||
|
||||
// It seems that the mere presence of \n and \r characters
|
||||
// is enough for Mono to botch the layout (even if these
|
||||
// characters are not processed.) We'll need to find a
|
||||
// different way to perform layout on Mono, probably
|
||||
// through Pango.
|
||||
// Todo: This workaround allocates memory.
|
||||
//if (Configuration.RunningOnMono)
|
||||
{
|
||||
string[] lines = text.Replace("\r", String.Empty).Split(newline_characters);
|
||||
foreach (string s in lines)
|
||||
{
|
||||
ranges.AddRange(GetCharExtents(
|
||||
s, height, 0, s.Length, layoutRect,
|
||||
native_graphics, native_font, native_string_format));
|
||||
height += font.Height;
|
||||
}
|
||||
}
|
||||
|
||||
return new RectangleF(ranges[0].X, ranges[0].Y, ranges[ranges.Count - 1].Right, ranges[ranges.Count - 1].Bottom);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Private Methods ---
|
||||
|
||||
#region private void PrepareTexturePacker()
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the optimal size for the font texture and TexturePacker, and creates both.
|
||||
/// </summary>
|
||||
private void PrepareTexturePacker()
|
||||
{
|
||||
// Calculate the size of the texture packer. We want a power-of-two size
|
||||
// that is less than 1024 (supported in Geforce256-era cards), but large
|
||||
// enough to hold at least 256 (16*16) font glyphs.
|
||||
// TODO: Find the actual card limits, maybe?
|
||||
int size = (int)(font.Size * 16);
|
||||
size = (int)System.Math.Pow(2.0, System.Math.Ceiling(System.Math.Log((double)size, 2.0)));
|
||||
if (size > 1024)
|
||||
size = 1024;
|
||||
|
||||
texture_width = size;
|
||||
texture_height = size;
|
||||
pack = new TexturePacker<Glyph>(texture_width, texture_height);
|
||||
|
||||
GL.GenTextures(1, out texture);
|
||||
GL.BindTexture(TextureTarget.Texture2D, texture);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
|
||||
if (GL.SupportsExtension("Version12"))
|
||||
{
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
|
||||
}
|
||||
else
|
||||
{
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Clamp);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Clamp);
|
||||
}
|
||||
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha, texture_width, texture_height, 0,
|
||||
OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private void LoadGlyph(char c, out RectangleF rectangle)
|
||||
|
||||
// Adds the specified caharacter to the texture packer.
|
||||
private void LoadGlyph(char c, out RectangleF rectangle)
|
||||
{
|
||||
if (pack == null)
|
||||
PrepareTexturePacker();
|
||||
|
||||
RectangleF glyph_rect = MeasureText(c.ToString(), SizeF.Empty, load_glyph_string_format);
|
||||
SizeF glyph_size = new SizeF(glyph_rect.Right, glyph_rect.Bottom); // We need to do this, since the origin might not be (0, 0)
|
||||
Glyph g = new Glyph(c, font, glyph_size);
|
||||
Rectangle rect;
|
||||
|
||||
try
|
||||
{
|
||||
pack.Add(g, out rect);
|
||||
}
|
||||
catch (InvalidOperationException expt)
|
||||
{
|
||||
// TODO: The TexturePacker is full, create a new font sheet.
|
||||
Trace.WriteLine(expt);
|
||||
throw;
|
||||
}
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, texture);
|
||||
|
||||
gfx.Clear(System.Drawing.Color.Transparent);
|
||||
gfx.DrawString(g.Character.ToString(), g.Font, System.Drawing.Brushes.White, 0.0f, 0.0f, default_string_format);
|
||||
|
||||
BitmapData bitmap_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,
|
||||
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
|
||||
GL.PushClientAttrib(ClientAttribMask.ClientPixelStoreBit);
|
||||
try
|
||||
{
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1.0f);
|
||||
GL.PixelStore(PixelStoreParameter.UnpackRowLength, bmp.Width);
|
||||
GL.TexSubImage2D(TextureTarget.Texture2D, 0, (int)rect.Left, (int)rect.Top,
|
||||
rect.Width, rect.Height,
|
||||
OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
|
||||
PixelType.UnsignedByte, bitmap_data.Scan0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GL.PopClientAttrib();
|
||||
}
|
||||
|
||||
bmp.UnlockBits(bitmap_data);
|
||||
|
||||
rectangle = RectangleF.FromLTRB(
|
||||
rect.Left / (float)texture_width,
|
||||
rect.Top / (float)texture_height,
|
||||
rect.Right / (float)texture_width,
|
||||
rect.Bottom / (float)texture_height);
|
||||
|
||||
loaded_glyphs.Add(g.Character, rectangle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GetCharExtents
|
||||
|
||||
// Gets the bounds of each character in a line of text.
|
||||
// The line is processed in blocks of 32 characters (GdiPlus.MaxMeasurableCharacterRanges).
|
||||
IEnumerable<RectangleF> GetCharExtents(string text, int height, int line_start, int line_length,
|
||||
RectangleF layoutRect, IntPtr native_graphics, IntPtr native_font, IntPtr native_string_format)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
int line_end = line_start + line_length;
|
||||
while (line_start < line_end)
|
||||
{
|
||||
//if (text[line_start] == '\n' || text[line_start] == '\r')
|
||||
//{
|
||||
// line_start++;
|
||||
// continue;
|
||||
//}
|
||||
|
||||
int num_characters = (line_end - line_start) > GdiPlus.MaxMeasurableCharacterRanges ?
|
||||
GdiPlus.MaxMeasurableCharacterRanges :
|
||||
line_end - line_start;
|
||||
int status = 0;
|
||||
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
characterRanges[i] = new CharacterRange(line_start + i, 1);
|
||||
|
||||
IntPtr region;
|
||||
status = GdiPlus.CreateRegion(out region);
|
||||
regions[i] = region;
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
}
|
||||
|
||||
status = GdiPlus.SetStringFormatMeasurableCharacterRanges(native_string_format, num_characters, characterRanges);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
status = GdiPlus.MeasureCharacterRanges(native_graphics, text, text.Length,
|
||||
native_font, ref layoutRect, native_string_format, num_characters, regions);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
GdiPlus.GetRegionBounds(regions[i], native_graphics, ref rect);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
GdiPlus.DeleteRegion(regions[i]);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
rect.Y += height;
|
||||
yield return rect;
|
||||
}
|
||||
|
||||
line_start += num_characters;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Internal Methods ---
|
||||
|
||||
#region internal int Texture
|
||||
|
||||
/// <summary>
|
||||
/// Gets the handle to the texture were this font resides.
|
||||
/// </summary>
|
||||
internal int Texture
|
||||
{
|
||||
get { return TextureFont.texture; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- IDisposable Members ---
|
||||
|
||||
bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Releases all resources used by this OpenTK.Graphics.TextureFont.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
private void Dispose(bool manual)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
pack = null;
|
||||
if (manual)
|
||||
{
|
||||
GL.DeleteTextures(1, ref texture);
|
||||
font.Dispose();
|
||||
gfx.Dispose();
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes this TextureFont.
|
||||
/// </summary>
|
||||
~TextureFont()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides text printing through OpenGL 1.5 vertex buffer objects.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
class VboTextPrinter : ITextPrinterImplementation
|
||||
{
|
||||
static int allocated_handles;
|
||||
static int vector2_size = Marshal.SizeOf(new Vector2());
|
||||
|
||||
#region --- IPrinter Members ---
|
||||
|
||||
public TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count)
|
||||
{
|
||||
VboTextHandle handle = new VboTextHandle(++allocated_handles);
|
||||
|
||||
GL.GenBuffers(1, out handle.vbo_id);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, handle.vbo_id);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * vector2_size), vertices,
|
||||
BufferUsageHint.StaticDraw);
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
|
||||
GL.GenBuffers(1, out handle.ebo_id);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, handle.ebo_id);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices,
|
||||
BufferUsageHint.StaticDraw);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
||||
|
||||
handle.element_count = indices.Length;
|
||||
return handle;
|
||||
}
|
||||
|
||||
public void Draw(TextHandle handle)
|
||||
{
|
||||
VboTextHandle vbo = (VboTextHandle)handle;
|
||||
|
||||
//GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);
|
||||
|
||||
//GL.EnableClientState(EnableCap.TextureCoordArray);
|
||||
GL.EnableClientState(EnableCap.VertexArray);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo.vbo_id);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo.ebo_id);
|
||||
|
||||
GL.TexCoordPointer(2, TexCoordPointerType.Float, vector2_size, (IntPtr)vector2_size);
|
||||
GL.VertexPointer(2, VertexPointerType.Float, vector2_size, IntPtr.Zero);
|
||||
|
||||
GL.DrawElements(BeginMode.Triangles, vbo.element_count, DrawElementsType.UnsignedShort, IntPtr.Zero);
|
||||
//GL.DrawArrays(BeginMode.LineLoop, 0, vbo.element_count);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
|
||||
|
||||
GL.DisableClientState(EnableCap.VertexArray);
|
||||
//GL.DisableClientState(EnableCap.TextureCoordArray);
|
||||
|
||||
//GL.PopClientAttrib();
|
||||
}
|
||||
|
||||
public void Draw(Vector2[] vertices, ushort[] indices, int index_count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region class VboTextHandle : TextHandle
|
||||
|
||||
/// <summary>
|
||||
/// Contains the necessary information to print text through the VboTextPrinter implementation.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
class VboTextHandle : TextHandle
|
||||
{
|
||||
public VboTextHandle(int handle) : base(handle) { }
|
||||
|
||||
internal int vbo_id; // vertex buffer object id.
|
||||
internal int ebo_id; // index buffer object id.
|
||||
internal int element_count; // Number of elements in the ebo.
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("TextHandle (vbo): {0} ({1} element(s), vbo id: {2}, ebo id: {3}",
|
||||
Handle, element_count / 6, vbo_id, ebo_id);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Encapsulates an OpenGL texture.
|
||||
/// </summary>
|
||||
class AlphaTexture2D : Texture2D
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Texture.
|
||||
/// </summary>
|
||||
public AlphaTexture2D(int width, int height)
|
||||
: base(width, height)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Members
|
||||
|
||||
protected override PixelInternalFormat InternalFormat
|
||||
{
|
||||
get { return PixelInternalFormat.Alpha; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents exceptions related to IGraphicsResources.
|
||||
/// </summary>
|
||||
public class GraphicsResourceException : Exception
|
||||
{
|
||||
/// <summary>Constructs a new GraphicsResourceException.</summary>
|
||||
public GraphicsResourceException() : base() { }
|
||||
/// <summary>Constructs a new string with the specified error message.</summary>
|
||||
public GraphicsResourceException(string message) : base(message) { }
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a common interface to all OpenGL resources.
|
||||
/// </summary>
|
||||
interface IGraphicsResource : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the GraphicsContext that owns this resource.
|
||||
/// </summary>
|
||||
IGraphicsContext Context { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of this IGraphicsResource.
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using OpenTK.Graphics.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the interface for a TextPrinter.
|
||||
/// </summary>
|
||||
public interface ITextPrinter : IDisposable
|
||||
{
|
||||
#region Print
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
void Print(string text, Font font, Color color);
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
void Print(string text, Font font, Color color, RectangleF rect);
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to print text.</param>
|
||||
void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Measure
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
TextExtents Measure(string text, Font font);
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
TextExtents Measure(string text, Font font, RectangleF rect);
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment);
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Begin
|
||||
|
||||
/// <summary>
|
||||
/// Sets up a resolution-dependent orthographic projection.
|
||||
/// </summary>
|
||||
void Begin();
|
||||
|
||||
#endregion
|
||||
|
||||
#region End
|
||||
|
||||
/// <summary>
|
||||
/// Restores the projection and modelview matrices to their previous state.
|
||||
/// </summary>
|
||||
void End();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Obsolete
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
void Draw(TextHandle handle);
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
void Draw(string text, TextureFont font);
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
void Prepare(string text, TextureFont font, out TextHandle handle);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
class RgbaTexture2D : Texture2D
|
||||
{
|
||||
public RgbaTexture2D(int width, int height)
|
||||
: base(width, height)
|
||||
{ }
|
||||
|
||||
protected override PixelInternalFormat InternalFormat
|
||||
{
|
||||
get { return PixelInternalFormat.Rgba; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
struct CachedGlyphInfo
|
||||
{
|
||||
public readonly Texture2D Texture;
|
||||
public readonly RectangleF RectangleNormalized;
|
||||
public Rectangle Rectangle
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(
|
||||
(int)(RectangleNormalized.X * Texture.Width),
|
||||
(int)(RectangleNormalized.Y * Texture.Height),
|
||||
(int)(RectangleNormalized.Width * Texture.Width),
|
||||
(int)(RectangleNormalized.Height * Texture.Height));
|
||||
}
|
||||
}
|
||||
|
||||
// Rect denotes the absolute position of the glyph in the texture [0, Texture.Width], [0, Texture.Height].
|
||||
public CachedGlyphInfo(Texture2D texture, Rectangle rect)
|
||||
{
|
||||
Texture = texture;
|
||||
RectangleNormalized = new RectangleF(
|
||||
rect.X / (float)texture.Width,
|
||||
rect.Y / (float)texture.Height,
|
||||
rect.Width / (float)texture.Width,
|
||||
rect.Height / (float)texture.Height);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
sealed class GL11TextOutputProvider : GL1TextOutputProvider
|
||||
{
|
||||
#region Fields
|
||||
|
||||
TextQuality quality;
|
||||
GlyphCache cache;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constuctors
|
||||
|
||||
public GL11TextOutputProvider(TextQuality quality)
|
||||
{
|
||||
if (quality == TextQuality.High || quality == TextQuality.Default)
|
||||
this.quality = TextQuality.Medium;
|
||||
else
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Members
|
||||
|
||||
protected override void SetBlendFunction()
|
||||
{
|
||||
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // For grayscale
|
||||
}
|
||||
|
||||
protected override void SetColor(Color color)
|
||||
{
|
||||
GL.Color3(color);
|
||||
}
|
||||
|
||||
protected override TextQuality TextQuality
|
||||
{
|
||||
get { return quality; }
|
||||
}
|
||||
|
||||
protected override GlyphCache Cache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cache == null)
|
||||
{
|
||||
if (GL.GetString(StringName.Renderer).Contains("ProSavage/Twister"))
|
||||
cache = new GlyphCache<RgbaTexture2D>();
|
||||
else
|
||||
cache = new GlyphCache<AlphaTexture2D>();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
sealed class GL12TextOutputProvider : GL1TextOutputProvider
|
||||
{
|
||||
#region Fields
|
||||
|
||||
TextQuality quality;
|
||||
GlyphCache cache;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constuctors
|
||||
|
||||
public GL12TextOutputProvider(TextQuality quality)
|
||||
{
|
||||
this.quality = quality;
|
||||
|
||||
cache = new GlyphCache<RgbaTexture2D>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void SetBlendFunction()
|
||||
{
|
||||
GL.BlendFunc(BlendingFactorSrc.ConstantColorExt, BlendingFactorDest.OneMinusSrcColor);
|
||||
}
|
||||
|
||||
protected override void SetColor(Color color)
|
||||
{
|
||||
GL.Color3(Color.White);
|
||||
GL.BlendColor(color);
|
||||
}
|
||||
|
||||
protected override TextQuality TextQuality
|
||||
{
|
||||
get { return quality; }
|
||||
}
|
||||
|
||||
protected override GlyphCache Cache
|
||||
{
|
||||
get { return cache; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,339 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
abstract class GL1TextOutputProvider : ITextOutputProvider
|
||||
{
|
||||
#region Fields
|
||||
|
||||
// Triangle lists, sorted by texture.
|
||||
Dictionary<Texture2D, List<Vector2>> active_lists = new Dictionary<Texture2D, List<Vector2>>();
|
||||
Queue<List<Vector2>> inactive_lists = new Queue<List<Vector2>>();
|
||||
|
||||
#pragma warning disable 0649
|
||||
struct Viewport { public int X, Y, Width, Height; }
|
||||
#pragma warning restore 0649
|
||||
|
||||
// Used to save the current state in Begin() and restore it in End()
|
||||
Stack<Matrix4> projection_stack = new Stack<Matrix4>();
|
||||
Stack<Matrix4> modelview_stack = new Stack<Matrix4>();
|
||||
Stack<Matrix4> texture_stack = new Stack<Matrix4>();
|
||||
Stack<Viewport> viewport_stack = new Stack<Viewport>();
|
||||
|
||||
// Used as temporary storage when saving / restoring the current state.
|
||||
Viewport viewport = new Viewport();
|
||||
Matrix4 matrix = new Matrix4();
|
||||
|
||||
// TextBlock - display list cache.
|
||||
// Todo: we need a cache eviction strategy.
|
||||
const int block_cache_capacity = 32;
|
||||
readonly Dictionary<int, int> block_cache = new Dictionary<int, int>(block_cache_capacity);
|
||||
|
||||
bool disposed;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GL1TextOutputProvider()
|
||||
{
|
||||
inactive_lists.Enqueue(new List<Vector2>());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITextOutputProvider Members
|
||||
|
||||
#region Print
|
||||
|
||||
public void Print(ref TextBlock block, Color color, IGlyphRasterizer rasterizer)
|
||||
{
|
||||
GL.PushAttrib(AttribMask.CurrentBit | AttribMask.TextureBit | AttribMask.EnableBit | AttribMask.ColorBufferBit | AttribMask.DepthBufferBit);
|
||||
|
||||
GL.Enable(EnableCap.Texture2D);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
SetBlendFunction();
|
||||
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
|
||||
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)All.Modulate);
|
||||
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvColor, new Color4(0, 0, 0, 0));
|
||||
|
||||
GL.Disable(EnableCap.TextureGenQ);
|
||||
GL.Disable(EnableCap.TextureGenR);
|
||||
GL.Disable(EnableCap.TextureGenS);
|
||||
GL.Disable(EnableCap.TextureGenT);
|
||||
|
||||
RectangleF position;
|
||||
|
||||
SetColor(color);
|
||||
|
||||
int block_hash = block.GetHashCode();
|
||||
if (block_cache.ContainsKey(block_hash))
|
||||
{
|
||||
GL.CallList(block_cache[block_hash]);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (TextExtents extents = rasterizer.MeasureText(ref block))
|
||||
{
|
||||
// Build layout
|
||||
int current = 0;
|
||||
foreach (Glyph glyph in block)
|
||||
{
|
||||
// Do not render whitespace characters or characters outside the clip rectangle.
|
||||
if (glyph.IsWhiteSpace || extents[current].Width == 0 || extents[current].Height == 0)
|
||||
{
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
else if (!Cache.Contains(glyph))
|
||||
Cache.Add(glyph, rasterizer, TextQuality);
|
||||
|
||||
CachedGlyphInfo info = Cache[glyph];
|
||||
position = extents[current++];
|
||||
|
||||
// Use the real glyph width instead of the measured one (we want to achieve pixel perfect output).
|
||||
position.Size = info.Rectangle.Size;
|
||||
|
||||
if (!active_lists.ContainsKey(info.Texture))
|
||||
{
|
||||
if (inactive_lists.Count > 0)
|
||||
{
|
||||
List<Vector2> list = inactive_lists.Dequeue();
|
||||
list.Clear();
|
||||
active_lists.Add(info.Texture, list);
|
||||
}
|
||||
else
|
||||
{
|
||||
active_lists.Add(info.Texture, new List<Vector2>());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Interleaved array: Vertex, TexCoord, Vertex, ...
|
||||
List<Vector2> current_list = active_lists[info.Texture];
|
||||
current_list.Add(new Vector2(info.RectangleNormalized.Left, info.RectangleNormalized.Top));
|
||||
current_list.Add(new Vector2(position.Left, position.Top));
|
||||
current_list.Add(new Vector2(info.RectangleNormalized.Left, info.RectangleNormalized.Bottom));
|
||||
current_list.Add(new Vector2(position.Left, position.Bottom));
|
||||
current_list.Add(new Vector2(info.RectangleNormalized.Right, info.RectangleNormalized.Bottom));
|
||||
current_list.Add(new Vector2(position.Right, position.Bottom));
|
||||
|
||||
current_list.Add(new Vector2(info.RectangleNormalized.Right, info.RectangleNormalized.Bottom));
|
||||
current_list.Add(new Vector2(position.Right, position.Bottom));
|
||||
current_list.Add(new Vector2(info.RectangleNormalized.Right, info.RectangleNormalized.Top));
|
||||
current_list.Add(new Vector2(position.Right, position.Top));
|
||||
current_list.Add(new Vector2(info.RectangleNormalized.Left, info.RectangleNormalized.Top));
|
||||
current_list.Add(new Vector2(position.Left, position.Top));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Render
|
||||
int display_list = 0;
|
||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
||||
{
|
||||
display_list = GL.GenLists(1);
|
||||
// Mesa Indirect gerates an InvalidOperation error right after
|
||||
// GL.EndList() when using ListMode.CompileAndExecute.
|
||||
// Using ListMode.Compile as a workaround.
|
||||
GL.NewList(display_list, ListMode.Compile);
|
||||
}
|
||||
foreach (Texture2D key in active_lists.Keys)
|
||||
{
|
||||
List<Vector2> list = active_lists[key];
|
||||
|
||||
key.Bind();
|
||||
|
||||
GL.Begin(BeginMode.Triangles);
|
||||
|
||||
for (int i = 0; i < list.Count; i += 2)
|
||||
{
|
||||
GL.TexCoord2(list[i]);
|
||||
GL.Vertex2(list[i + 1]);
|
||||
}
|
||||
|
||||
GL.End();
|
||||
}
|
||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
||||
{
|
||||
GL.EndList();
|
||||
block_cache.Add(block_hash, display_list);
|
||||
GL.CallList(display_list);
|
||||
}
|
||||
|
||||
// Clean layout
|
||||
foreach (List<Vector2> list in active_lists.Values)
|
||||
{
|
||||
//list.Clear();
|
||||
inactive_lists.Enqueue(list);
|
||||
}
|
||||
|
||||
active_lists.Clear();
|
||||
}
|
||||
|
||||
GL.PopAttrib();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Clear
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Cache.Clear();
|
||||
foreach (int display_list in block_cache.Keys)
|
||||
GL.DeleteLists(display_list, 1);
|
||||
block_cache.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Begin
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(this.GetType().ToString());
|
||||
|
||||
GraphicsContext.Assert();
|
||||
|
||||
// Save the state of everything we are going to modify:
|
||||
// the current matrix mode, viewport state and the projection, modelview and texture matrices.
|
||||
// All these will be restored in the TextPrinter.End() method.
|
||||
int current_matrix;
|
||||
GL.GetInteger(GetPName.MatrixMode, out current_matrix);
|
||||
|
||||
GL.GetInteger(GetPName.Viewport, out viewport.X);
|
||||
viewport_stack.Push(viewport);
|
||||
|
||||
GL.GetFloat(GetPName.ProjectionMatrix, out matrix.Row0.X);
|
||||
projection_stack.Push(matrix);
|
||||
GL.GetFloat(GetPName.ModelviewMatrix, out matrix.Row0.X);
|
||||
modelview_stack.Push(matrix);
|
||||
GL.GetFloat(GetPName.TextureMatrix, out matrix.Row0.X);
|
||||
texture_stack.Push(matrix);
|
||||
|
||||
// Prepare to draw text. We want pixel perfect precision, so we setup a 2D mode,
|
||||
// with size equal to the window (in pixels).
|
||||
// While we could also render text in 3D mode, it would be very hard to get
|
||||
// pixel-perfect precision.
|
||||
GL.MatrixMode(MatrixMode.Projection);
|
||||
GL.LoadIdentity();
|
||||
GL.Ortho(viewport.X, viewport.Width, viewport.Height, viewport.Y, -1.0, 1.0);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Modelview);
|
||||
GL.LoadIdentity();
|
||||
|
||||
GL.MatrixMode(MatrixMode.Texture);
|
||||
GL.LoadIdentity();
|
||||
|
||||
GL.MatrixMode((MatrixMode)current_matrix);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region End
|
||||
|
||||
public void End()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(this.GetType().ToString());
|
||||
|
||||
GraphicsContext.Assert();
|
||||
|
||||
int current_matrix;
|
||||
GL.GetInteger(GetPName.MatrixMode, out current_matrix);
|
||||
|
||||
viewport = viewport_stack.Pop();
|
||||
GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Texture);
|
||||
matrix = texture_stack.Pop();
|
||||
GL.LoadMatrix(ref matrix);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Modelview);
|
||||
matrix = modelview_stack.Pop();
|
||||
GL.LoadMatrix(ref matrix);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Projection);
|
||||
matrix = projection_stack.Pop();
|
||||
GL.LoadMatrix(ref matrix);
|
||||
|
||||
GL.MatrixMode((MatrixMode)current_matrix);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Members
|
||||
|
||||
protected abstract void SetBlendFunction();
|
||||
|
||||
protected abstract void SetColor(Color color);
|
||||
|
||||
protected abstract TextQuality TextQuality { get; }
|
||||
|
||||
protected abstract GlyphCache Cache { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Members
|
||||
|
||||
public static GL1TextOutputProvider Create(TextQuality quality)
|
||||
{
|
||||
if (!GL.SupportsExtension("Version12") || !GL.SupportsFunction("BlendColor") || quality == TextQuality.Low || quality == TextQuality.Medium)
|
||||
return new GL11TextOutputProvider(quality);
|
||||
else
|
||||
return new GL12TextOutputProvider(quality);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
Cache.Dispose();
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,501 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing.Text;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
sealed class GdiPlusGlyphRasterizer : IGlyphRasterizer
|
||||
{
|
||||
#region Fields
|
||||
|
||||
// Note: as an optimization, we store the TextBlock hashcode instead of the TextBlock itself.
|
||||
Dictionary<int, TextExtents> block_cache = new Dictionary<int, TextExtents>();
|
||||
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new Bitmap(1, 1));
|
||||
|
||||
IntPtr[] regions = new IntPtr[GdiPlus.MaxMeasurableCharacterRanges];
|
||||
CharacterRange[] characterRanges = new CharacterRange[GdiPlus.MaxMeasurableCharacterRanges];
|
||||
|
||||
Bitmap glyph_surface;
|
||||
System.Drawing.Graphics glyph_renderer;
|
||||
|
||||
readonly List<RectangleF> measured_glyphs = new List<RectangleF>(256);
|
||||
|
||||
readonly ObjectPool<PoolableTextExtents> text_extents_pool = new ObjectPool<PoolableTextExtents>();
|
||||
|
||||
// Check the constructor, too, for additional flags.
|
||||
// Used for measuring text. Can set the leftToRight, rightToLeft, vertical and measure trailing spaces flags.
|
||||
readonly StringFormat measure_string_format = new StringFormat(StringFormat.GenericDefault);
|
||||
readonly StringFormat measure_string_format_tight = new StringFormat(StringFormat.GenericTypographic);
|
||||
// Used for loading glyphs. Only use leftToRight!
|
||||
readonly StringFormat load_glyph_string_format = new StringFormat(StringFormat.GenericDefault);
|
||||
readonly StringFormat load_glyph_string_format_tight = new StringFormat(StringFormat.GenericTypographic);
|
||||
|
||||
static readonly char[] newline_characters = new char[] { '\n', '\r' };
|
||||
|
||||
static readonly SizeF MaximumGraphicsClipSize;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static GdiPlusGlyphRasterizer()
|
||||
{
|
||||
using (Bitmap bmp = new Bitmap(1, 1))
|
||||
using (System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(bmp))
|
||||
{
|
||||
MaximumGraphicsClipSize = gfx.ClipBounds.Size;
|
||||
}
|
||||
}
|
||||
|
||||
public GdiPlusGlyphRasterizer()
|
||||
{
|
||||
measure_string_format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoClip;
|
||||
measure_string_format_tight.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGlyphRasterizer Members
|
||||
|
||||
#region Rasterize
|
||||
|
||||
public Bitmap Rasterize(Glyph glyph)
|
||||
{
|
||||
return Rasterize(glyph, TextQuality.Default);
|
||||
}
|
||||
|
||||
public Bitmap Rasterize(Glyph glyph, TextQuality quality)
|
||||
{
|
||||
EnsureSurfaceSize(ref glyph_surface, ref glyph_renderer, glyph.Font);
|
||||
SetTextRenderingOptions(glyph_renderer, glyph.Font, quality);
|
||||
|
||||
RectangleF r2 = new RectangleF();
|
||||
|
||||
glyph_renderer.Clear(Color.Transparent);
|
||||
|
||||
glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty, //new Point(glyph_surface.Width, 0),
|
||||
glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : load_glyph_string_format_tight);
|
||||
|
||||
r2 = FindEdges(glyph_surface, true);
|
||||
|
||||
//if ((default_string_format.FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0)
|
||||
//{
|
||||
// glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty, //new Point(glyph_surface.Width, 0),
|
||||
// load_glyph_string_format);//glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
||||
|
||||
// r2 = FindEdges(glyph_surface, true);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// glyph_renderer.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, Point.Empty,
|
||||
// load_glyph_string_format_tight); //glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
||||
|
||||
// r2 = FindEdges(glyph_surface, false);
|
||||
//}
|
||||
|
||||
return glyph_surface.Clone(r2, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MeasureText
|
||||
|
||||
public TextExtents MeasureText(ref TextBlock block)
|
||||
{
|
||||
return MeasureText(ref block, TextQuality.Default);
|
||||
}
|
||||
|
||||
public TextExtents MeasureText(ref TextBlock block, TextQuality quality)
|
||||
{
|
||||
// First, check if we have cached this text block. Do not use block_cache.TryGetValue, to avoid thrashing
|
||||
// the user's TextBlockExtents struct.
|
||||
int hashcode = block.GetHashCode();
|
||||
if (block_cache.ContainsKey(hashcode))
|
||||
return block_cache[hashcode];
|
||||
|
||||
// If this block is not cached, we have to measure it and (potentially) place it in the cache.
|
||||
TextExtents extents = MeasureTextExtents(ref block, quality);
|
||||
|
||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
||||
block_cache.Add(hashcode, extents);
|
||||
|
||||
return extents;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Clear
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
block_cache.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
#region EnsureSurfaceSize
|
||||
|
||||
void EnsureSurfaceSize(ref Bitmap bmp, ref System.Drawing.Graphics gfx, Font font)
|
||||
{
|
||||
if (bmp == null || bmp.Width < 2 * font.Size || bmp.Height < 2 * font.Size)
|
||||
{
|
||||
if (bmp != null)
|
||||
bmp.Dispose();
|
||||
if (gfx != null)
|
||||
gfx.Dispose();
|
||||
|
||||
bmp = new Bitmap((int)(2 * font.Size), (int)(2 * font.Size));
|
||||
gfx = System.Drawing.Graphics.FromImage(bmp);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SetRenderingOptions
|
||||
|
||||
// Modify rendering settings (antialiasing, grid fitting) to improve appearance.
|
||||
void SetTextRenderingOptions(System.Drawing.Graphics gfx, Font font, TextQuality quality)
|
||||
{
|
||||
switch (quality)
|
||||
{
|
||||
case TextQuality.Default:
|
||||
gfx.TextRenderingHint = TextRenderingHint.SystemDefault;
|
||||
break;
|
||||
|
||||
case TextQuality.High:
|
||||
gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
break;
|
||||
|
||||
case TextQuality.Medium:
|
||||
if (font.Size <= 18.0f)
|
||||
gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||
else
|
||||
gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||
break;
|
||||
|
||||
case TextQuality.Low:
|
||||
if (font.Size <= 18.0f)
|
||||
gfx.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
|
||||
else
|
||||
gfx.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MeasureTextExtents
|
||||
|
||||
TextExtents MeasureTextExtents(ref TextBlock block, TextQuality quality)
|
||||
{
|
||||
// Todo: Parse layout options:
|
||||
StringFormat format = block.Font.Italic ? measure_string_format : measure_string_format_tight;
|
||||
//StringFormat format = measure_string_format_tight;
|
||||
|
||||
if (block.Direction == TextDirection.Vertical)
|
||||
format.FormatFlags |= StringFormatFlags.DirectionVertical;
|
||||
else
|
||||
format.FormatFlags &= ~StringFormatFlags.DirectionVertical;
|
||||
|
||||
if (block.Direction == TextDirection.RightToLeft)
|
||||
format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
|
||||
else
|
||||
format.FormatFlags &= ~StringFormatFlags.DirectionRightToLeft;
|
||||
|
||||
if (block.Alignment == TextAlignment.Near)
|
||||
format.Alignment = StringAlignment.Near;
|
||||
else if (block.Alignment == TextAlignment.Center)
|
||||
format.Alignment = StringAlignment.Center;
|
||||
else
|
||||
format.Alignment = StringAlignment.Far;
|
||||
|
||||
TextExtents extents = text_extents_pool.Acquire();
|
||||
|
||||
RectangleF rect = block.Bounds;
|
||||
// Work around Mono/GDI+ bug, which causes incorrect
|
||||
// text wraping when block.Bounds == SizeF.Empty.
|
||||
if (block.Bounds.Size == SizeF.Empty)
|
||||
rect.Size = MaximumGraphicsClipSize;
|
||||
|
||||
SetTextRenderingOptions(graphics, block.Font, quality);
|
||||
|
||||
IntPtr native_graphics = GdiPlus.GetNativeGraphics(graphics);
|
||||
IntPtr native_font = GdiPlus.GetNativeFont(block.Font);
|
||||
IntPtr native_string_format = GdiPlus.GetNativeStringFormat(format);
|
||||
|
||||
float max_width = 0, max_height = 0;
|
||||
|
||||
// It seems that the mere presence of \n and \r characters
|
||||
// is enough for Mono to botch the layout (even if these
|
||||
// characters are not processed.) We'll need to find a
|
||||
// different way to perform layout on Mono, probably
|
||||
// through Pango.
|
||||
// Todo: This workaround allocates memory.
|
||||
//if (Configuration.RunningOnMono)
|
||||
{
|
||||
string[] lines = block.Text.Replace("\r", String.Empty).Split('\n');
|
||||
foreach (string s in lines)
|
||||
{
|
||||
float width, height;
|
||||
|
||||
extents.AddRange(MeasureGlyphExtents(
|
||||
ref block, s,
|
||||
native_graphics, native_font, native_string_format,
|
||||
ref rect, out width, out height));
|
||||
|
||||
if ((block.Direction & TextDirection.Vertical) == 0)
|
||||
rect.Y += block.Font.Height;
|
||||
else
|
||||
rect.X += block.Font.Height;
|
||||
|
||||
if (width > max_width)
|
||||
max_width = width;
|
||||
if (height > max_height)
|
||||
max_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
if (extents.Count > 0)
|
||||
extents.BoundingBox = new RectangleF(extents[0].X, extents[0].Y, max_width, max_height);
|
||||
else
|
||||
extents.BoundingBox = RectangleF.Empty;
|
||||
|
||||
return extents;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MeasureGlyphExtents
|
||||
|
||||
// Gets the bounds of each character in a line of text.
|
||||
// Each line is processed in blocks of 32 characters (GdiPlus.MaxMeasurableCharacterRanges).
|
||||
IEnumerable<RectangleF> MeasureGlyphExtents(
|
||||
ref TextBlock block, string text,
|
||||
IntPtr native_graphics, IntPtr native_font, IntPtr native_string_format,
|
||||
ref RectangleF layoutRect, out float max_width, out float max_height)
|
||||
{
|
||||
measured_glyphs.Clear();
|
||||
max_width = layoutRect.Left;
|
||||
max_height = layoutRect.Top;
|
||||
float last_line_width = 0, last_line_height = 0;
|
||||
|
||||
int current = 0;
|
||||
while (current < text.Length)
|
||||
{
|
||||
int num_characters = (text.Length - current) > GdiPlus.MaxMeasurableCharacterRanges ?
|
||||
GdiPlus.MaxMeasurableCharacterRanges :
|
||||
text.Length - current;
|
||||
int status = 0;
|
||||
|
||||
// Prepare the character ranges and region structs for the measurement.
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
if (text[current + i] == '\n' || text[current + i] == '\r')
|
||||
throw new NotSupportedException();
|
||||
|
||||
characterRanges[i] = new CharacterRange(current + i, 1);
|
||||
|
||||
IntPtr region;
|
||||
status = GdiPlus.CreateRegion(out region);
|
||||
regions[i] = region;
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
}
|
||||
|
||||
status = GdiPlus.SetStringFormatMeasurableCharacterRanges(native_string_format, num_characters, characterRanges);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
status = GdiPlus.MeasureCharacterRanges(native_graphics, text, text.Length,
|
||||
native_font, ref layoutRect, native_string_format, num_characters, regions);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
// Read back the results of the measurement.
|
||||
for (int i = 0; i < num_characters; i++)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
|
||||
GdiPlus.GetRegionBounds(regions[i], native_graphics, ref rect);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
GdiPlus.DeleteRegion(regions[i]);
|
||||
Debug.Assert(status == 0, String.Format("GDI+ error: {0}", status));
|
||||
|
||||
if (rect.Bottom > max_height)
|
||||
max_height = rect.Bottom;
|
||||
if (rect.Right > max_width)
|
||||
max_width = rect.Right;
|
||||
|
||||
if (rect.X > last_line_width)
|
||||
last_line_width = rect.X;
|
||||
if (rect.Y > last_line_height)
|
||||
last_line_height = rect.Y;
|
||||
|
||||
measured_glyphs.Add(rect);
|
||||
}
|
||||
|
||||
current += num_characters;
|
||||
}
|
||||
|
||||
// Make sure the current height is updated, if the the current line has wrapped due to word-wraping.
|
||||
// Otherwise, the next line will overlap with the current one.
|
||||
if (measured_glyphs.Count > 1)
|
||||
{
|
||||
if ((block.Direction & TextDirection.Vertical) == 0)
|
||||
{
|
||||
if (layoutRect.Y < last_line_height)
|
||||
layoutRect.Y = last_line_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (layoutRect.X < last_line_width)
|
||||
layoutRect.X = last_line_width;
|
||||
}
|
||||
}
|
||||
|
||||
// Mono's GDI+ implementation suffers from an issue where the specified layoutRect is not taken into
|
||||
// account. We will try to improve the situation by moving text to the correct location on this
|
||||
// error condition. This will not help word wrapping, but it is better than nothing.
|
||||
// Todo: Mono 2.8 is supposed to ship with a Pango-based GDI+ text renderer, which should not
|
||||
// suffer from this bug. Verify that this is the case and remove the hack.
|
||||
if (Configuration.RunningOnMono && (layoutRect.X != 0 || layoutRect.Y != 0) && measured_glyphs.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < measured_glyphs.Count; i++)
|
||||
{
|
||||
RectangleF rect = measured_glyphs[i];
|
||||
rect.X += layoutRect.X;
|
||||
rect.Y += layoutRect.Y;
|
||||
measured_glyphs[i] = rect;
|
||||
}
|
||||
}
|
||||
|
||||
return measured_glyphs;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region FindEdges
|
||||
|
||||
#pragma warning disable 0649
|
||||
|
||||
struct Pixel { public byte B, G, R, A; }
|
||||
|
||||
#pragma warning restore 0649
|
||||
|
||||
// Note: The bool parameter is not used at this point.
|
||||
// We might need it if we ever load true rightToLeft glyphs.
|
||||
Rectangle FindEdges(Bitmap bmp, bool rightToLeft)
|
||||
{
|
||||
BitmapData data = bmp.LockBits(
|
||||
new Rectangle(0, 0, bmp.Width, bmp.Height),
|
||||
ImageLockMode.ReadOnly,
|
||||
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
|
||||
//Rectangle rect = rightToLeft ?
|
||||
// Rectangle.FromLTRB(FindLeftEdge(bmp, data.Scan0), 0, bmp.Width - 1, FindBottomEdge(bmp, data.Scan0)) :
|
||||
// Rectangle.FromLTRB(0, 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
||||
|
||||
Rectangle rect =
|
||||
Rectangle.FromLTRB(0, 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
||||
//Rectangle.FromLTRB(FindLeftEdge(bmp, data.Scan0), 0, FindRightEdge(bmp, data.Scan0), FindBottomEdge(bmp, data.Scan0));
|
||||
|
||||
bmp.UnlockBits(data);
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Find[Left|Right|Top|Bottom]Edge
|
||||
|
||||
// Iterates through the bmp, and returns the first row or line that contains a non-transparent pixels.
|
||||
|
||||
int FindLeftEdge(Bitmap bmp, IntPtr ptr)
|
||||
{
|
||||
for (int x = 0; x < bmp.Width; x++)
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
unsafe
|
||||
{
|
||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
||||
return x;
|
||||
}
|
||||
|
||||
return bmp.Width - 1;
|
||||
}
|
||||
|
||||
int FindRightEdge(Bitmap bmp, IntPtr ptr)
|
||||
{
|
||||
for (int x = bmp.Width - 1; x >= 0; x--)
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
unsafe
|
||||
{
|
||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FindTopEdge(Bitmap bmp, IntPtr ptr)
|
||||
{
|
||||
for (int y = 0; y < bmp.Height; y++)
|
||||
for (int x = 0; x < bmp.Width; x++)
|
||||
unsafe
|
||||
{
|
||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
||||
return y;
|
||||
}
|
||||
|
||||
return bmp.Height - 1;
|
||||
}
|
||||
|
||||
int FindBottomEdge(Bitmap bmp, IntPtr ptr)
|
||||
{
|
||||
for (int y = bmp.Height - 1; y >= 0; y--)
|
||||
for (int x = 0; x < bmp.Width; x++)
|
||||
unsafe
|
||||
{
|
||||
if (((Pixel*)(ptr) + y * bmp.Width + x)->A != 0)
|
||||
return y + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
struct Glyph : IEquatable<Glyph>
|
||||
{
|
||||
char character;
|
||||
Font font;
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new Glyph that represents the given character and Font.
|
||||
/// </summary>
|
||||
/// <param name="c">The character to represent.</param>
|
||||
/// <param name="font">The Font of the character.</param>
|
||||
public Glyph(char c, Font font)
|
||||
{
|
||||
if (font == null)
|
||||
throw new ArgumentNullException("font");
|
||||
character = c;
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#region public char Character
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character represented by this Glyph.
|
||||
/// </summary>
|
||||
public char Character
|
||||
{
|
||||
get { return character; }
|
||||
private set { character = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Font Font
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Font of this Glyph.
|
||||
/// </summary>
|
||||
public Font Font
|
||||
{
|
||||
get { return font; }
|
||||
private set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("Font", "Glyph font cannot be null");
|
||||
|
||||
font = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public bool IsWhiteSpace
|
||||
|
||||
public bool IsWhiteSpace
|
||||
{
|
||||
get { return Char.IsWhiteSpace(Character); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override bool Equals(object obj)
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given object is equal (memberwise) to the current Glyph.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj to check.</param>
|
||||
/// <returns>True, if the object is identical to the current Glyph.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Glyph)
|
||||
return this.Equals((Glyph)obj);
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override string ToString()
|
||||
|
||||
/// <summary>
|
||||
/// Describes this Glyph object.
|
||||
/// </summary>
|
||||
/// <returns>Returns a System.String describing this Glyph.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("'{0}', {1} {2}, {3} {4}", Character, Font.Name, font.Style, font.Size, font.Unit);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override int GetHashCode()
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the hashcode for this Glyph.
|
||||
/// </summary>
|
||||
/// <returns>A System.Int32 containing a hashcode that uniquely identifies this Glyph.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return character.GetHashCode() ^ font.GetHashCode();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Glyph> Members
|
||||
|
||||
public bool Equals(Glyph other)
|
||||
{
|
||||
return Character == other.Character && Font == other.Font;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
abstract class GlyphCache : IGlyphCache
|
||||
{
|
||||
#region IGlyphCache Members
|
||||
|
||||
public abstract void Add(Glyph glyph, IGlyphRasterizer rasterizer, TextQuality quality);
|
||||
|
||||
public abstract bool Contains(Glyph glyph);
|
||||
|
||||
public abstract CachedGlyphInfo this[Glyph glyph] { get; }
|
||||
|
||||
public abstract void Clear();
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
sealed class GlyphCache<T> : GlyphCache where T : Texture2D
|
||||
{
|
||||
#region Fields
|
||||
|
||||
List<GlyphSheet<T>> sheets = new List<GlyphSheet<T>>();
|
||||
|
||||
Dictionary<Glyph, CachedGlyphInfo> cached_glyphs = new Dictionary<Glyph, CachedGlyphInfo>();
|
||||
|
||||
bool disposed;
|
||||
|
||||
const int SheetWidth = 512, SheetHeight = 512;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GlyphCache()
|
||||
{
|
||||
sheets.Add(new GlyphSheet<T>(SheetWidth, SheetHeight));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGlyphCache Members
|
||||
|
||||
public override void Add(Glyph glyph, IGlyphRasterizer rasterizer, TextQuality quality)
|
||||
{
|
||||
if (rasterizer == null)
|
||||
throw new ArgumentNullException("rasterizer");
|
||||
|
||||
bool inserted = false;
|
||||
|
||||
using (Bitmap bmp = rasterizer.Rasterize(glyph, quality))
|
||||
{
|
||||
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
||||
foreach (GlyphSheet<T> sheet in sheets)
|
||||
{
|
||||
inserted = InsertGlyph(glyph, bmp, rect, sheet);
|
||||
if (inserted)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!inserted)
|
||||
{
|
||||
GlyphSheet<T> sheet = new GlyphSheet<T>(SheetWidth, SheetHeight);
|
||||
sheets.Add(sheet);
|
||||
InsertGlyph(glyph, bmp, rect, sheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Contains(Glyph glyph)
|
||||
{
|
||||
return cached_glyphs.ContainsKey(glyph);
|
||||
}
|
||||
|
||||
public override CachedGlyphInfo this[Glyph glyph]
|
||||
{
|
||||
get
|
||||
{
|
||||
return cached_glyphs[glyph];
|
||||
}
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
for (int i = 0; i < sheets.Count; i++)
|
||||
sheets[i].Dispose();
|
||||
|
||||
sheets.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
// Asks the packer for an empty space and writes the glyph there.
|
||||
bool InsertGlyph(Glyph glyph, Bitmap bmp, Rectangle source, GlyphSheet<T> sheet)
|
||||
{
|
||||
Rectangle target = new Rectangle();
|
||||
if (!sheet.Packer.TryAdd(source, out target))
|
||||
return false;
|
||||
|
||||
sheet.Texture.WriteRegion(source, target, 0, bmp);
|
||||
cached_glyphs.Add(glyph, new CachedGlyphInfo(sheet.Texture, target));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
Clear();
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
class GlyphEnumerator : IEnumerator<Glyph>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
string text;
|
||||
Font font;
|
||||
|
||||
IEnumerator<char> implementation;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GlyphEnumerator(string text, Font font)
|
||||
{
|
||||
if (text == null)
|
||||
throw new ArgumentNullException("text");
|
||||
|
||||
if (font == null)
|
||||
throw new ArgumentNullException("font");
|
||||
|
||||
this.text = text;
|
||||
this.font = font;
|
||||
|
||||
implementation = text.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerator<Glyph> Members
|
||||
|
||||
public Glyph Current
|
||||
{
|
||||
get { return new Glyph(implementation.Current, font); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
implementation.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerator Members
|
||||
|
||||
object System.Collections.IEnumerator.Current
|
||||
{
|
||||
get { return new Glyph(implementation.Current, font); }
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
bool status;
|
||||
do
|
||||
{
|
||||
status = implementation.MoveNext();
|
||||
} while (status && (implementation.Current == '\n' || implementation.Current == '\r'));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
implementation.Reset();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,270 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
class GlyphPacker
|
||||
{
|
||||
Node root;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
public GlyphPacker(int width, int height)
|
||||
{
|
||||
if (width <= 0)
|
||||
throw new ArgumentOutOfRangeException("width", width, "Must be greater than zero.");
|
||||
if (height <= 0)
|
||||
throw new ArgumentOutOfRangeException("height", height, "Must be greater than zero.");
|
||||
|
||||
root = new Node();
|
||||
root.Rectangle = new Rectangle(0, 0, width, width);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public bool TryAdd(Rectangle boundingBox)
|
||||
|
||||
/// <summary>
|
||||
/// Adds boundingBox to the GlyphPacker.
|
||||
/// </summary>
|
||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
||||
/// <param name="packedRectangle">The System.Drawing.Rectangle that contains the position of the packed item.</param>
|
||||
/// <returns>True, if the item was successfully packed; false if the item is too big for this packer..</returns>
|
||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
||||
/// <exception cref="TexturePackerFullException">Occurs if the item cannot fit in the remaining packer space.</exception>
|
||||
public bool TryAdd(Rectangle boundingBox, out Rectangle packedRectangle)
|
||||
{
|
||||
if (!root.Rectangle.Contains(boundingBox))
|
||||
{
|
||||
packedRectangle = new Rectangle();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Increase size so that the glyphs do not touch each other (to avoid rendering artifacts).
|
||||
boundingBox.Width += 2;
|
||||
boundingBox.Height += 2;
|
||||
|
||||
Node node = root.Insert(boundingBox);
|
||||
|
||||
// Tree is full and insertion failed:
|
||||
if (node == null)
|
||||
{
|
||||
packedRectangle = new Rectangle();
|
||||
return false;
|
||||
}
|
||||
|
||||
packedRectangle = new Rectangle(node.Rectangle.X, node.Rectangle.Y, node.Rectangle.Width - 2, node.Rectangle.Height - 2);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Rectangle TryAdd(RectangleF boundingBox)
|
||||
|
||||
/// <summary>
|
||||
/// Adds boundingBox to the GlyphPacker.
|
||||
/// </summary>
|
||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
||||
/// <param name="packedRectangle">The System.Drawing.RectangleF that contains the position of the packed item.</param>
|
||||
/// <returns>True, if the item was successfully packed; false if the item is too big for this packer..</returns>
|
||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
||||
/// <exception cref="TexturePackerFullException">Occurs if the item cannot fit in the remaining packer space.</exception>
|
||||
public bool TryAdd(RectangleF boundingBox, out RectangleF packedRectangle)
|
||||
{
|
||||
Rectangle bbox = new Rectangle(
|
||||
(int)boundingBox.X, (int)boundingBox.Y,
|
||||
(int)(boundingBox.Width + 0.5f), (int)(boundingBox.Height + 0.5f));
|
||||
|
||||
return TryAdd(bbox, out packedRectangle);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Rectangle Add(Rectangle boundingBox)
|
||||
|
||||
/// <summary>
|
||||
/// Adds boundingBox to the GlyphPacker.
|
||||
/// </summary>
|
||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
||||
/// <returns>A System.Drawing.Rectangle containing the coordinates of the packed item.</returns>
|
||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
||||
/// <exception cref="TexturePackerFullException">Occurs if the item cannot fit in the remaining packer space.</exception>
|
||||
public Rectangle Add(Rectangle boundingBox)
|
||||
{
|
||||
if (!TryAdd(boundingBox, out boundingBox))
|
||||
throw new TexturePackerFullException();
|
||||
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Rectangle Add(RectangleF boundingBox)
|
||||
|
||||
/// <summary>
|
||||
/// Rounds boundingBox to the largest integer and adds the resulting Rectangle to the GlyphPacker.
|
||||
/// </summary>
|
||||
/// <param name="boundingBox">The bounding box of the item to pack.</param>
|
||||
/// <returns>A System.Drawing.Rectangle containing the coordinates of the packed item.</returns>
|
||||
/// <exception cref="InvalidOperationException">Occurs if the item is larger than the available TexturePacker area</exception>
|
||||
/// <exception cref="ArgumentException">Occurs if the item already exists in the TexturePacker.</exception>
|
||||
public Rectangle Add(RectangleF boundingBox)
|
||||
{
|
||||
Rectangle bbox = new Rectangle(
|
||||
(int)boundingBox.X, (int)boundingBox.Y,
|
||||
(int)(boundingBox.Width + 0.5f), (int)(boundingBox.Height + 0.5f));
|
||||
|
||||
return Add(bbox);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Clear()
|
||||
|
||||
/// <summary>
|
||||
/// Discards all packed items.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
root.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Node
|
||||
|
||||
class Node
|
||||
{
|
||||
public Node()
|
||||
{
|
||||
}
|
||||
|
||||
Node left, right;
|
||||
Rectangle rect;
|
||||
bool occupied;
|
||||
|
||||
public Rectangle Rectangle { get { return rect; } set { rect = value; } }
|
||||
public Node Left { get { return left; } set { left = value; } }
|
||||
public Node Right { get { return right; } set { right = value; } }
|
||||
|
||||
#region --- Constructor ---
|
||||
|
||||
public bool Leaf
|
||||
{
|
||||
get { return left == null && right == null; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Node Insert(Rectangle bbox)
|
||||
|
||||
public Node Insert( Rectangle bbox)
|
||||
{
|
||||
if (!this.Leaf)
|
||||
{
|
||||
// Recurse towards left child, and if that fails, towards the right.
|
||||
Node new_node = left.Insert(bbox);
|
||||
return new_node ?? right.Insert(bbox);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have recursed to a leaf.
|
||||
|
||||
// If it is not empty go back.
|
||||
if (occupied)
|
||||
return null;
|
||||
|
||||
// If this leaf is too small go back.
|
||||
if (rect.Width < bbox.Width || rect.Height < bbox.Height)
|
||||
return null;
|
||||
|
||||
// If this leaf is the right size, insert here.
|
||||
if (rect.Width == bbox.Width && rect.Height == bbox.Height)
|
||||
{
|
||||
occupied = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
// This leaf is too large, split it up. We'll decide which way to split
|
||||
// by checking the width and height difference between this rectangle and
|
||||
// out item's bounding box. If the width difference is larger, we'll split
|
||||
// horizontaly, else verticaly.
|
||||
left = new Node();
|
||||
right = new Node();
|
||||
|
||||
int dw = this.rect.Width - bbox.Width + 1;
|
||||
int dh = this.rect.Height - bbox.Height + 1;
|
||||
|
||||
if (dw > dh)
|
||||
{
|
||||
left.rect = new Rectangle(rect.Left, rect.Top, bbox.Width, rect.Height);
|
||||
right.rect = new Rectangle(rect.Left + bbox.Width, rect.Top, rect.Width - bbox.Width, rect.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
left.rect = new Rectangle(rect.Left, rect.Top, rect.Width, bbox.Height);
|
||||
right.rect = new Rectangle(rect.Left, rect.Top + bbox.Height, rect.Width, rect.Height - bbox.Height);
|
||||
}
|
||||
|
||||
return left.Insert(bbox);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Clear()
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (left != null)
|
||||
left.Clear();
|
||||
if (right != null)
|
||||
right.Clear();
|
||||
|
||||
left = right = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
class TexturePackerFullException : Exception
|
||||
{
|
||||
public TexturePackerFullException() : base("There is not enough space to add this item. Consider calling the Clear() method.") { }
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
class GlyphSheet<T> : IDisposable where T : Texture2D
|
||||
{
|
||||
#region Fields
|
||||
|
||||
readonly T texture;
|
||||
readonly GlyphPacker packer;
|
||||
|
||||
bool disposed;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GlyphSheet(int width, int height)
|
||||
{
|
||||
texture = (T)typeof(T).GetConstructor(new Type[] { typeof(int), typeof(int) }).Invoke(new object[] { width, height });
|
||||
//texture.MagnificationFilter = TextureMagFilter.Nearest;
|
||||
//texture.MinificationFilter = TextureMinFilter.Nearest;
|
||||
packer = new GlyphPacker(width, height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
public T Texture
|
||||
{
|
||||
get { return texture; }
|
||||
}
|
||||
|
||||
public GlyphPacker Packer
|
||||
{
|
||||
get { return packer; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
texture.Dispose();
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
interface IGlyphCache : IDisposable
|
||||
{
|
||||
void Add(Glyph glyph, IGlyphRasterizer rasterizer, TextQuality quality);
|
||||
bool Contains(Glyph glyph);
|
||||
CachedGlyphInfo this[Glyph glyph] { get; }
|
||||
void Clear();
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
using OpenTK.Graphics.Text;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
interface IGlyphRasterizer
|
||||
{
|
||||
Bitmap Rasterize(Glyph glyph);
|
||||
Bitmap Rasterize(Glyph glyph, TextQuality quality);
|
||||
TextExtents MeasureText(ref TextBlock block);
|
||||
TextExtents MeasureText(ref TextBlock block, TextQuality quality);
|
||||
void Clear();
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
interface ITextOutputProvider : IDisposable
|
||||
{
|
||||
void Print(ref TextBlock block, Color color, IGlyphRasterizer rasterizer);
|
||||
void Clear();
|
||||
void Begin();
|
||||
void End();
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
class PoolableTextExtents : TextExtents, IPoolable<PoolableTextExtents>
|
||||
{
|
||||
ObjectPool<PoolableTextExtents> owner;
|
||||
|
||||
#region Constructors
|
||||
|
||||
public PoolableTextExtents()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPoolable<PoolableTextExtents> Members
|
||||
|
||||
ObjectPool<PoolableTextExtents> IPoolable<PoolableTextExtents>.Owner
|
||||
{
|
||||
get { return owner; }
|
||||
set { owner = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPoolable Members
|
||||
|
||||
void IPoolable.OnAcquire()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void IPoolable.OnRelease()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
// Uniquely identifies a block of text. This structure can be used to identify text blocks for caching.
|
||||
struct TextBlock : IEquatable<TextBlock>, IEnumerable<Glyph>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public readonly string Text;
|
||||
|
||||
public readonly Font Font;
|
||||
|
||||
public readonly RectangleF Bounds;
|
||||
|
||||
public readonly TextPrinterOptions Options;
|
||||
|
||||
public readonly TextAlignment Alignment;
|
||||
|
||||
public readonly TextDirection Direction;
|
||||
|
||||
public readonly int UsageCount;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public TextBlock(string text, Font font, RectangleF bounds, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
||||
{
|
||||
Text = text;
|
||||
Font = font;
|
||||
Bounds = bounds;
|
||||
Options = options;
|
||||
Alignment = alignment;
|
||||
Direction = direction;
|
||||
UsageCount = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is TextBlock))
|
||||
return false;
|
||||
|
||||
return Equals((TextBlock)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Text.GetHashCode() ^ Font.GetHashCode() ^ Bounds.GetHashCode() ^ Options.GetHashCode();
|
||||
}
|
||||
|
||||
public Glyph this[int i]
|
||||
{
|
||||
get { return new Glyph(Text[i], Font); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<TextBlock> Members
|
||||
|
||||
public bool Equals(TextBlock other)
|
||||
{
|
||||
return
|
||||
Text == other.Text &&
|
||||
Font == other.Font &&
|
||||
Bounds == other.Bounds &&
|
||||
Options == other.Options;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable<Glyph> Members
|
||||
|
||||
public IEnumerator<Glyph> GetEnumerator()
|
||||
{
|
||||
return new GlyphEnumerator(Text, Font);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Members
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new GlyphEnumerator(Text, Font);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
class TextBlockComparer : IComparer<TextBlock>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public TextBlockComparer() { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region IComparer<TextBlock> Members
|
||||
|
||||
public int Compare(TextBlock x, TextBlock y)
|
||||
{
|
||||
return x.UsageCount.CompareTo(y.UsageCount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines available alignments for text.
|
||||
/// </summary>
|
||||
public enum TextAlignment
|
||||
{
|
||||
/// <summary>The text is aligned to the near side (left for left-to-right text and right for right-to-left text).</summary>
|
||||
Near = 0,
|
||||
/// <summary>The text is aligned to the center.</summary>
|
||||
Center,
|
||||
/// <summary>The text is aligned to the far side (right for left-to-right text and left for right-to-left text).</summary>
|
||||
Far
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines available directions for text layout.
|
||||
/// </summary>
|
||||
public enum TextDirection
|
||||
{
|
||||
/// <summary>The text is layed out from left to right.</summary>
|
||||
LeftToRight,
|
||||
/// <summary>The text is layed out from right to left.</summary>
|
||||
RightToLeft,
|
||||
/// <summary>The text is layed out vertically.</summary>
|
||||
Vertical
|
||||
}
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the results of a text measurement.
|
||||
/// </summary>
|
||||
public class TextExtents : IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
protected RectangleF text_extents;
|
||||
protected List<RectangleF> glyph_extents = new List<RectangleF>();
|
||||
|
||||
public static readonly TextExtents Empty = new TextExtents();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal TextExtents()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bounding box of the measured text.
|
||||
/// </summary>
|
||||
public RectangleF BoundingBox
|
||||
{
|
||||
get { return text_extents; }
|
||||
internal set { text_extents = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the extents of each glyph in the measured text.
|
||||
/// </summary>
|
||||
/// <param name="i">The index of the glyph.</param>
|
||||
/// <returns>The extents of the specified glyph.</returns>
|
||||
public RectangleF this[int i]
|
||||
{
|
||||
get { return glyph_extents[i]; }
|
||||
internal set { glyph_extents[i] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the extents of each glyph in the measured text.
|
||||
/// </summary>
|
||||
public IEnumerable<RectangleF> GlyphExtents
|
||||
{
|
||||
get { return (IEnumerable<RectangleF>)glyph_extents; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of the measured glyphs.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return glyph_extents.Count; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Members
|
||||
|
||||
internal void Add(RectangleF glyphExtent)
|
||||
{
|
||||
glyph_extents.Add(glyphExtent);
|
||||
}
|
||||
|
||||
internal void AddRange(IEnumerable<RectangleF> glyphExtents)
|
||||
{
|
||||
glyph_extents.AddRange(glyphExtents);
|
||||
}
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
BoundingBox = RectangleF.Empty;
|
||||
glyph_extents.Clear();
|
||||
}
|
||||
|
||||
internal TextExtents Clone()
|
||||
{
|
||||
TextExtents extents = new TextExtents();
|
||||
extents.glyph_extents.AddRange(GlyphExtents);
|
||||
extents.BoundingBox = BoundingBox;
|
||||
return extents;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
||||
/// Frees the resources consumed by this TextExtents instance.
|
||||
/// </summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,338 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.Text;
|
||||
using OpenTK.Platform;
|
||||
|
||||
namespace OpenTK.Fonts { }
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides methods to perform layout and print hardware accelerated text.
|
||||
/// </summary>
|
||||
public sealed class TextPrinter : ITextPrinter
|
||||
{
|
||||
#region Fields
|
||||
|
||||
IGlyphRasterizer glyph_rasterizer;
|
||||
ITextOutputProvider text_output;
|
||||
TextQuality text_quality;
|
||||
|
||||
bool disposed;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new TextPrinter instance.
|
||||
/// </summary>
|
||||
public TextPrinter()
|
||||
: this(null, null, TextQuality.Default) { }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new TextPrinter instance with the specified TextQuality level.
|
||||
/// </summary>
|
||||
/// <param name="quality">The desired TextQuality of this TextPrinter.</param>
|
||||
public TextPrinter(TextQuality quality)
|
||||
: this(null, null, quality) { }
|
||||
|
||||
TextPrinter(IGlyphRasterizer rasterizer, ITextOutputProvider output, TextQuality quality)
|
||||
{
|
||||
glyph_rasterizer = rasterizer;
|
||||
text_output = output;
|
||||
text_quality = quality;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ITextPrinter Members
|
||||
|
||||
#region Print
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
public void Print(string text, Font font, Color color)
|
||||
{
|
||||
Print(text, font, color, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
public void Print(string text, Font font, Color color, RectangleF rect)
|
||||
{
|
||||
Print(text, font, color, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options)
|
||||
{
|
||||
Print(text, font, color, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
|
||||
{
|
||||
Print(text, font, color, rect, options, alignment, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints text using the specified color and layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to print.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to print text.</param>
|
||||
/// <param name="color">The System.Drawing.Color that will be used to print text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to print text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to print text.</param>
|
||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to print text.</param>
|
||||
public void Print(string text, Font font, Color color, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(this.GetType().ToString());
|
||||
|
||||
if (!ValidateParameters(text, font, rect))
|
||||
return;
|
||||
|
||||
TextBlock block = new TextBlock(text, font, rect, options, alignment, direction);
|
||||
TextOutput.Print(ref block, color, Rasterizer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Measure
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
public TextExtents Measure(string text, Font font)
|
||||
{
|
||||
return Measure(text, font, RectangleF.Empty, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect)
|
||||
{
|
||||
return Measure(text, font, rect, TextPrinterOptions.Default, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options)
|
||||
{
|
||||
return Measure(text, font, rect, options, TextAlignment.Near, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment)
|
||||
{
|
||||
return Measure(text, font, rect, options, alignment, TextDirection.LeftToRight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures text using the specified layout options.
|
||||
/// </summary>
|
||||
/// <param name="text">The System.String to measure.</param>
|
||||
/// <param name="font">The System.Drawing.Font that will be used to measure text.</param>
|
||||
/// <param name="rect">The System.Drawing.Rectangle that defines the bounds for text layout.</param>
|
||||
/// <param name="options">The OpenTK.Graphics.TextPrinterOptions that will be used to measure text.</param>
|
||||
/// <param name="alignment">The OpenTK.Graphics.TextAlignment that will be used to measure text.</param>
|
||||
/// <param name="direction">The OpenTK.Graphics.TextDirection that will be used to measure text.</param>
|
||||
/// <returns>An OpenTK.Graphics.TextExtents instance that contains the results of the measurement.</returns>
|
||||
public TextExtents Measure(string text, Font font, RectangleF rect, TextPrinterOptions options, TextAlignment alignment, TextDirection direction)
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(this.GetType().ToString());
|
||||
|
||||
if (!ValidateParameters(text, font, rect))
|
||||
return TextExtents.Empty;
|
||||
|
||||
TextBlock block = new TextBlock(text, font, rect, options, alignment, direction);
|
||||
return Rasterizer.MeasureText(ref block);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Clear
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException(this.GetType().ToString());
|
||||
|
||||
TextOutput.Clear();
|
||||
Rasterizer.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Begin
|
||||
|
||||
/// <summary>
|
||||
/// Sets up a resolution-dependent orthographic projection.
|
||||
/// </summary>
|
||||
public void Begin()
|
||||
{
|
||||
TextOutput.Begin();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Begin
|
||||
|
||||
/// <summary>
|
||||
/// Restores the projection and modelview matrices to their previous state.
|
||||
/// </summary>
|
||||
public void End()
|
||||
{
|
||||
TextOutput.End();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Obsolete
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
public void Draw(TextHandle handle)
|
||||
{
|
||||
Print(handle.Text, handle.GdiPFont, Color.White);
|
||||
}
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
public void Draw(string text, TextureFont font)
|
||||
{
|
||||
Print(text, font.font, Color.White);
|
||||
}
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
public void Prepare(string text, TextureFont font, out TextHandle handle)
|
||||
{
|
||||
handle = new TextHandle(text, font.font);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
IGlyphRasterizer Rasterizer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (glyph_rasterizer == null)
|
||||
glyph_rasterizer = new GdiPlusGlyphRasterizer();
|
||||
|
||||
return glyph_rasterizer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ITextOutputProvider TextOutput
|
||||
{
|
||||
get
|
||||
{
|
||||
if (text_output == null)
|
||||
text_output = GL1TextOutputProvider.Create(text_quality);
|
||||
|
||||
return text_output;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Members
|
||||
|
||||
static bool ValidateParameters(string text, Font font, RectangleF rect)
|
||||
{
|
||||
if (String.IsNullOrEmpty(text))
|
||||
return false;
|
||||
if (font == null)
|
||||
throw new ArgumentNullException("font");
|
||||
if (rect.Width < 0 || rect.Height < 0)
|
||||
throw new ArgumentOutOfRangeException("rect");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
||||
/// Frees the resources consumed by this TextPrinter object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
TextOutput.Dispose();
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines available options for the TextPrinter.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum TextPrinterOptions
|
||||
{
|
||||
/// <summary>The TextPrinter will use default printing options.</summary>
|
||||
Default = 0x0000,
|
||||
/// <summary>The TextPrinter will not cache text blocks as they are measured or printed.</summary>
|
||||
NoCache = 0x0001,
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines available quality levels for text printing.
|
||||
/// </summary>
|
||||
public enum TextQuality
|
||||
{
|
||||
/// <summary>Use the default quality, as specified by the operating system.</summary>
|
||||
Default = 0,
|
||||
/// <summary>Use fast, low quality text (typically non-antialiased) .</summary>
|
||||
Low,
|
||||
/// <summary>Use medium quality text (typically grayscale antialiased).</summary>
|
||||
Medium,
|
||||
/// <summary>Use slow, high quality text (typically subpixel antialiased).</summary>
|
||||
High
|
||||
}
|
||||
}
|
|
@ -1,320 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
abstract class Texture2D : IGraphicsResource, IEquatable<Texture2D>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
IGraphicsContext context;
|
||||
int id;
|
||||
int width, height;
|
||||
bool disposed;
|
||||
|
||||
TextureMagFilter mag_filter = TextureMagFilter.Linear;
|
||||
TextureMinFilter min_filter = TextureMinFilter.Linear;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public Texture2D(int width, int height)
|
||||
{
|
||||
if (width <= 0)
|
||||
throw new ArgumentOutOfRangeException("width");
|
||||
|
||||
if (height <= 0)
|
||||
throw new ArgumentOutOfRangeException("height");
|
||||
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#region public int Width
|
||||
|
||||
/// <summary>Gets the width of the texture.</summary>
|
||||
public int Width { get { return width; } private set { width = value; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region public int Height
|
||||
|
||||
/// <summary>Gets the height of the texture.</summary>
|
||||
public int Height { get { return height; } private set { height = value; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region MagnificationFilter
|
||||
|
||||
public TextureMagFilter MagnificationFilter
|
||||
{
|
||||
get { return mag_filter; }
|
||||
set { mag_filter = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MinificationFilter
|
||||
|
||||
public TextureMinFilter MinificationFilter
|
||||
{
|
||||
get { return min_filter; }
|
||||
set { min_filter = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bind
|
||||
|
||||
public void Bind()
|
||||
{
|
||||
GL.BindTexture(TextureTarget.Texture2D, (this as IGraphicsResource).Id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region WriteRegion
|
||||
|
||||
public void WriteRegion(Rectangle source, Rectangle target, int mipLevel, Bitmap bitmap)
|
||||
{
|
||||
if (bitmap == null)
|
||||
throw new ArgumentNullException("data");
|
||||
|
||||
GraphicsUnit unit = GraphicsUnit.Pixel;
|
||||
if (!bitmap.GetBounds(ref unit).Contains(source))
|
||||
throw new InvalidOperationException("The source Rectangle is larger than the Bitmap.");
|
||||
|
||||
if (mipLevel < 0)
|
||||
throw new ArgumentOutOfRangeException("mipLevel");
|
||||
|
||||
Bind();
|
||||
|
||||
BitmapData data = null;
|
||||
|
||||
GL.PushClientAttrib(ClientAttribMask.ClientPixelStoreBit);
|
||||
try
|
||||
{
|
||||
data = bitmap.LockBits(source, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
|
||||
GL.PixelStore(PixelStoreParameter.UnpackRowLength, bitmap.Width);
|
||||
GL.TexSubImage2D(TextureTarget.Texture2D, mipLevel,
|
||||
target.Left, target.Top,
|
||||
target.Width, target.Height,
|
||||
OpenTK.Graphics.PixelFormat.Bgra,
|
||||
PixelType.UnsignedByte, data.Scan0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GL.PopClientAttrib();
|
||||
if (data != null)
|
||||
bitmap.UnlockBits(data);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ReadRegion
|
||||
|
||||
public TextureRegion2D ReadRegion(Rectangle rect, int mipLevel)
|
||||
{
|
||||
if (mipLevel < 0)
|
||||
throw new ArgumentOutOfRangeException("miplevel");
|
||||
|
||||
TextureRegion2D<int> region = new TextureRegion2D<int>(rect);
|
||||
|
||||
GL.GetTexImage(TextureTarget.Texture2D, mipLevel, OpenTK.Graphics.PixelFormat.Bgra, PixelType.UnsignedByte, region.Data);
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Equals
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Texture2D)
|
||||
return this.Equals((Texture2D)obj);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public override int GetHashCode()
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (this as IGraphicsResource).Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public overrid string ToString()
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("Texture2D #{0} ({1}x{2}, {3})",
|
||||
(this as IGraphicsResource).Id.ToString(),
|
||||
Width.ToString(),
|
||||
Height.ToString(),
|
||||
InternalFormat.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Members
|
||||
|
||||
#region InternalFormat
|
||||
|
||||
protected abstract PixelInternalFormat InternalFormat { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
int CreateTexture(int width, int height)
|
||||
{
|
||||
int id = GL.GenTexture();
|
||||
if (id == 0)
|
||||
throw new GraphicsResourceException(String.Format("Texture creation failed, (Error: {0})", GL.GetError()));
|
||||
|
||||
SetDefaultTextureParameters(id);
|
||||
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0, InternalFormat, Width, Height, 0,
|
||||
OpenTK.Graphics.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void SetDefaultTextureParameters(int id)
|
||||
{
|
||||
// Ensure the texture is allocated.
|
||||
GL.BindTexture(TextureTarget.Texture2D, id);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
|
||||
if (GL.SupportsExtension("Version12"))
|
||||
{
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
|
||||
}
|
||||
else
|
||||
{
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Clamp);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Clamp);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGraphicsResource Members
|
||||
|
||||
#region IGraphicsResource.Context
|
||||
|
||||
IGraphicsContext IGraphicsResource.Context { get { return context; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region IGraphicsResource.Id
|
||||
|
||||
int IGraphicsResource.Id
|
||||
{
|
||||
get
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
GraphicsContext.Assert();
|
||||
context = GraphicsContext.CurrentContext;
|
||||
|
||||
id = CreateTexture(Width, Height);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEquatable<Texture2D> Members
|
||||
|
||||
public bool Equals(Texture2D other)
|
||||
{
|
||||
return (this as IGraphicsResource).Id == (other as IGraphicsResource).Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
void Dispose(bool manual)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (manual)
|
||||
{
|
||||
GL.DeleteTexture(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Print("[Warning] {0} leaked.", this);
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~Texture2D()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
#region License
|
||||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2008 the Open Toolkit library, except where noted.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
abstract class TextureRegion2D
|
||||
{
|
||||
Rectangle rectangle;
|
||||
|
||||
public Rectangle Rectangle { get { return rectangle; } protected set { rectangle = value; } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds part or the whole of a 2d OpenGL texture.
|
||||
/// </summary>
|
||||
class TextureRegion2D<T> : TextureRegion2D where T : struct
|
||||
{
|
||||
#region Fields
|
||||
|
||||
T[,] data;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal TextureRegion2D(Rectangle rect)
|
||||
{
|
||||
data = new T[rect.Width, rect.Height];
|
||||
Rectangle = rect;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
public T this[int x, int y]
|
||||
{
|
||||
get { return data[x, y]; }
|
||||
set { data[x, y] = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Members
|
||||
|
||||
internal T[,] Data { get { return data; } }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an item that can be packed with the TexturePacker.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the packable item.</typeparam>
|
||||
interface IPackable<T> : IEquatable<T>
|
||||
{
|
||||
int Width { get; }
|
||||
int Height { get; }
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
interface IPoolable : IDisposable
|
||||
{
|
||||
void OnAcquire();
|
||||
void OnRelease();
|
||||
}
|
||||
|
||||
interface IPoolable<T> : IPoolable where T : IPoolable<T>, new()
|
||||
{
|
||||
ObjectPool<T> Owner { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
class ObjectPool<T> where T : IPoolable<T>, new()
|
||||
{
|
||||
Queue<T> pool = new Queue<T>();
|
||||
|
||||
public ObjectPool()
|
||||
{ }
|
||||
|
||||
public T Acquire()
|
||||
{
|
||||
T item;
|
||||
|
||||
if (pool.Count > 0)
|
||||
{
|
||||
item = pool.Dequeue();
|
||||
item.OnAcquire();
|
||||
}
|
||||
else
|
||||
{
|
||||
item = new T();
|
||||
item.Owner = this;
|
||||
item.OnAcquire();
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public void Release(T item)
|
||||
{
|
||||
if (item == null)
|
||||
throw new ArgumentNullException("item");
|
||||
|
||||
item.OnRelease();
|
||||
pool.Enqueue(item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
<configuration>
|
||||
</configuration>
|
|
@ -1,33 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("The Open Toolkit Library Utilities")]
|
||||
[assembly: AssemblyDescription("Open source game development toolkit for .Net/Mono.")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("The Open Toolkit Library")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2006-2009 the Open Toolkit team")]
|
||||
[assembly: AssemblyTrademark("OpenTK")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("3e1a89c5-9405-4061-8cbe-7e5efe870731")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("0.9.9.2")]
|
||||
[assembly: AssemblyFileVersion("0.9.9.2")]
|
|
@ -1,195 +0,0 @@
|
|||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
class TexturePacker<T> where T : IPackable<T>
|
||||
{
|
||||
Node root;
|
||||
|
||||
#region --- Constructors ---
|
||||
|
||||
public TexturePacker(int width, int height)
|
||||
{
|
||||
if (width <= 0)
|
||||
throw new ArgumentOutOfRangeException("width", width, "Must be greater than zero.");
|
||||
if (height <= 0)
|
||||
throw new ArgumentOutOfRangeException("height", height, "Must be greater than zero.");
|
||||
|
||||
root = new Node();
|
||||
root.Rect = new Rectangle(0, 0, width, width);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- Public Methods ---
|
||||
|
||||
#region public Rectangle Add(T item)
|
||||
|
||||
// Packs the given item into the free space of the TexturePacker. Returns the Rectangle of the packed item.
|
||||
public void Add(T item, out Rectangle rect)
|
||||
{
|
||||
if (item.Width > root.Rect.Width || item.Height > root.Rect.Height)
|
||||
throw new InvalidOperationException("The item is too large for this TexturePacker");
|
||||
|
||||
Node node;
|
||||
//if (!items.ContainsKey(item))
|
||||
{
|
||||
node = root.Insert(item);
|
||||
|
||||
// Tree is full and insertion failed:
|
||||
if (node == null)
|
||||
throw new TexturePackerFullException();
|
||||
|
||||
//items.Add(item, node);
|
||||
rect = node.Rect;
|
||||
}
|
||||
//throw new ArgumentException("The item already exists in the TexturePacker.", "item");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Clear()
|
||||
|
||||
/// <summary>
|
||||
/// Discards all packed items.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
//items.Clear();
|
||||
root.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void ChangeSize(int new_width, int new_height)
|
||||
|
||||
/// <summary>
|
||||
/// Changes the dimensions of the TexturePacker surface.
|
||||
/// </summary>
|
||||
/// <param name="new_width">The new width of the TexturePacker surface.</param>
|
||||
/// <param name="new_height">The new height of the TexturePacker surface.</param>
|
||||
/// <remarks>Changing the size of the TexturePacker surface will implicitly call TexturePacker.Clear().</remarks>
|
||||
/// <seealso cref="Clear"/>
|
||||
public void ChangeSize(int new_width, int new_height)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Node
|
||||
|
||||
class Node
|
||||
{
|
||||
public Node()
|
||||
{
|
||||
}
|
||||
|
||||
Node left, right;
|
||||
Rectangle rect;
|
||||
int use_count;
|
||||
|
||||
public Rectangle Rect { get { return rect; } set { rect = value; } }
|
||||
public Node Left { get { return left; } set { left = value; } }
|
||||
public Node Right { get { return right; } set { right = value; } }
|
||||
|
||||
#region --- Constructor ---
|
||||
|
||||
public bool Leaf
|
||||
{
|
||||
get { return left == null && right == null; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Node Insert(T item)
|
||||
|
||||
public Node Insert(T item)
|
||||
{
|
||||
if (!this.Leaf)
|
||||
{
|
||||
// Recurse towards left child, and if that fails, towards the right.
|
||||
Node new_node = left.Insert(item);
|
||||
return new_node ?? right.Insert(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have recursed to a leaf.
|
||||
|
||||
// If it is not empty go back.
|
||||
if (use_count != 0)
|
||||
return null;
|
||||
|
||||
// If this leaf is too small go back.
|
||||
if (rect.Width < item.Width || rect.Height < item.Height)
|
||||
return null;
|
||||
|
||||
// If this leaf is the right size, insert here.
|
||||
if (rect.Width == item.Width && rect.Height == item.Height)
|
||||
{
|
||||
use_count = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
// This leaf is too large, split it up. We'll decide which way to split
|
||||
// by checking the width and height difference between this rectangle and
|
||||
// out item's bounding box. If the width difference is larger, we'll split
|
||||
// horizontaly, else verticaly.
|
||||
left = new Node();
|
||||
right = new Node();
|
||||
|
||||
int dw = this.rect.Width - item.Width + 1;
|
||||
int dh = this.rect.Height - item.Height + 1;
|
||||
|
||||
if (dw > dh)
|
||||
{
|
||||
left.rect = new Rectangle(rect.Left, rect.Top, item.Width, rect.Height);
|
||||
right.rect = new Rectangle(rect.Left + item.Width, rect.Top, rect.Width - item.Width, rect.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
left.rect = new Rectangle(rect.Left, rect.Top, rect.Width, item.Height);
|
||||
right.rect = new Rectangle(rect.Left, rect.Top + item.Height, rect.Width, rect.Height - item.Height);
|
||||
}
|
||||
|
||||
return left.Insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public void Clear()
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (left != null)
|
||||
left.Clear();
|
||||
if (right != null)
|
||||
right.Clear();
|
||||
|
||||
left = right = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
class TexturePackerFullException : Exception
|
||||
{
|
||||
public TexturePackerFullException() : base("There is not enough space to add this item. Consider calling the Clear() method.") { }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue