Added new font rendering sample.

This commit is contained in:
the_fiddler 2008-11-25 19:00:06 +00:00
parent 27c3f3b0ce
commit 2bffcbbfcf
3 changed files with 332 additions and 0 deletions

View file

@ -0,0 +1,94 @@
namespace Examples.WinForms
{
partial class FontRendering
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.glControl1 = new OpenTK.GLControl();
this.changeFont = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.fontDialog = new System.Windows.Forms.FontDialog();
this.SuspendLayout();
//
// glControl1
//
this.glControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.glControl1.BackColor = System.Drawing.Color.Black;
this.glControl1.Location = new System.Drawing.Point(0, 40);
this.glControl1.Name = "glControl1";
this.glControl1.Size = new System.Drawing.Size(700, 521);
this.glControl1.TabIndex = 0;
this.glControl1.VSync = false;
this.glControl1.Load += new System.EventHandler(this.glControl1_Load);
this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
this.glControl1.Resize += new System.EventHandler(this.glControl1_Resize);
//
// changeFont
//
this.changeFont.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.changeFont.Location = new System.Drawing.Point(568, 10);
this.changeFont.Name = "changeFont";
this.changeFont.Size = new System.Drawing.Size(120, 23);
this.changeFont.TabIndex = 1;
this.changeFont.Text = "Change Font";
this.changeFont.UseVisualStyleBackColor = true;
this.changeFont.Click += new System.EventHandler(this.changeFont_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 11);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(550, 22);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "The quick fox jumped over the lazy dogs. 0123456789";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// FontRendering
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 561);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.changeFont);
this.Controls.Add(this.glControl1);
this.Name = "FontRendering";
this.Text = "FontRendering";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private OpenTK.GLControl glControl1;
private System.Windows.Forms.Button changeFont;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.FontDialog fontDialog;
}
}

View file

@ -0,0 +1,115 @@
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 sample", ExampleCategory.WinForms)]
public partial class FontRendering : Form
{
#region Fields
float[] sizes = new float[] { 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 48 };
List<Font> fonts = new List<Font>();
TextPrinter text = new TextPrinter();
#endregion
#region Constructors
public FontRendering()
{
InitializeComponent();
UpdateFontList(fontDialog.Font);
glControl1_Resize(this, EventArgs.Empty);
}
#endregion
#region Private Members
void UpdateFontList(Font base_font)
{
foreach (Font font in fonts)
font.Dispose();
fonts.Clear();
foreach (float size in sizes)
fonts.Add(new Font(base_font.Name, size, base_font.Style));
}
#endregion
#region Events
private void glControl1_Load(object sender, EventArgs e)
{
GL.ClearColor(Color.SteelBlue);
}
private void changeFont_Click(object sender, EventArgs e)
{
if (fontDialog.ShowDialog() == DialogResult.OK)
{
UpdateFontList(fontDialog.Font);
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
glControl1.Invalidate();
}
private void glControl1_Paint(object sender, PaintEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Color3(Color.White);
text.Begin();
foreach (Font font in fonts)
{
text.Print(textBox1.Text, font);
GL.Translate(0, font.Height, 0);
}
text.End();
glControl1.SwapBuffers();
}
private void glControl1_Resize(object sender, EventArgs e)
{
if (glControl1.ClientSize.Height == 0)
glControl1.ClientSize = new System.Drawing.Size(glControl1.ClientSize.Width, 1);
GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
}
#endregion
#region public static void Main()
/// <summary>
/// Entry point of this example.
/// </summary>
[STAThread]
public static void Main()
{
using (FontRendering example = new FontRendering())
{
Utilities.SetWindowTitle(example);
example.ShowDialog();
}
}
#endregion
}
}

View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="fontDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>