using System.Collections.Generic; using Microsoft.Xna.Framework; namespace StardustCore.StardustMath { /// A Class that helps represents 32 bit hex. class Hex32 : Hex { /// A default constructor. public Hex32() { this.hexValue = "0x00000000"; } /// Construct an instance. /// A string in hex representation. Ex) 0x00000000 public Hex32(string hexValue) { this.hexValue = hexValue; if (!this.verifyHexLength()) this.hexValue = "0x00000000"; } /// Construct an instance. /// An int to be converted into Hex. public Hex32(int value) { this.hexValue = value.ToString("X"); if (!this.verifyHexLength()) this.hexValue = "0x00000000"; } /// Makes sure the hex value is the appropriate length. public override bool verifyHexLength() { if (this.hexValue.Length != 10) return false; else return true; } /// Converts a hex value to a string. public Color toColor() { var bytes = this.getBytes(); int red = this.convertHexByteTo255Int(bytes[0]); int green = this.convertHexByteTo255Int(bytes[1]); int blue = this.convertHexByteTo255Int(bytes[2]); int alpha = this.convertHexByteTo255Int(bytes[3]); return new Color(red, green, blue, alpha); } /// Get the individual byte strings associated with this hex value. public override List getBytes() { List bytes = new List(); bytes.Add(this.getByte(0)); bytes.Add(this.getByte(1)); bytes.Add(this.getByte(2)); bytes.Add(this.getByte(3)); return bytes; } } }