using System; using System.Diagnostics; namespace SpaceInvaders { public class Glyph : DLink { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- public enum GlyphName { Consolas20pt, Consolas36pt, InvaderFont, NullObject, Uninitialized } public GlyphName name; //public int index; // just for search public struct Key { public int key; public Azul.Rect rect; } private Key[] pKeys = new Key[127]; private Texture pTexture; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public Glyph() : base() { this.name = GlyphName.Uninitialized; this.pTexture = null; } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public void SetGlyph(Glyph.GlyphName name, Texture.TextureName texName) { this.name = name; this.pTexture = TextureMan.FindTexture(texName); Debug.Assert(this.pTexture != null); } public void SetKey(int key, int x, int y, int w, int h) { this.pKeys[key-1].key = key; this.pKeys[key-1].rect = new Azul.Rect(x, y, w, h); } public Azul.Rect GetKey(int key) { return this.pKeys[key-1].rect; } public Azul.Texture GetAzulTexture() { Debug.Assert(this.pTexture != null); return this.pTexture.GetAzulTexture(); } public override bool Compare(Node pNode) { Debug.Assert(pNode != null); Glyph pGlyphB = (Glyph)pNode; if(this.name == pGlyphB.name) { return true; } return false; } public override object GetName() { return this.name; } public override void Reset() { this.Clear(); } public override void PrintStats() { Debug.WriteLine("name: {0} ({1})", this.name, this.GetHashCode()); if (this.pTexture != null) { Debug.WriteLine("pTexture: {0}", this.pTexture.GetName()); } else { Debug.WriteLine("pTexture: null"); } base.PrintStats(); } //------------------------------------------------------------------- // PRIVATE METHODS //------------------------------------------------------------------- private void Clear() { this.name = GlyphName.Uninitialized; this.pTexture = null; } } // end class } // end namespace