using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StardustCore.StardustMath { /// /// A Class that helps represents 32 bit hex. /// class Hex32 : Hex { /// /// A default constructor. /// public Hex32() { this.hexValue = "0x00000000"; } /// /// Constructor. /// /// A string in hex representation. Ex) 0x00000000 public Hex32(string hexValue) { this.hexValue = hexValue; if (verifyHexLength() == false) this.hexValue = "0x00000000"; } /// /// Constructor. /// /// An int to be converted into Hex. public Hex32(int value) { this.hexValue= value.ToString("X"); if (verifyHexLength() == false) 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; } /// /// Trims the hex to get rid of the leading 0x; /// /// public override string trimHex() { return base.trimHex(); } /// /// Converts a hex value to a string. /// /// public Color toColor() { var bytes = getBytes(); int red = convertHexByteTo255Int(bytes[0]); int green = convertHexByteTo255Int(bytes[1]); int blue = convertHexByteTo255Int(bytes[2]); int alpha = 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(getByte(0)); bytes.Add(getByte(1)); bytes.Add(getByte(2)); bytes.Add(getByte(3)); return bytes; } } }