Example #1
0
        public void AddAsset(int x, int y, SuperGumpAsset asset)
        {
            if (SuperGumpAsset.IsNullOrEmpty(asset))
            {
                return;
            }

            int   ax, ay;
            Color ac;

            for (ax = 0; ax < asset.Width; ax++)
            {
                for (ay = 0; ay < asset.Height; ay++)
                {
                    if ((ac = asset[ax, ay]).A > 0)
                    {
                        AddHtml(x + ax, y + ay, 1, 1, " ".WrapUOHtmlBG(ac), false, false);
                    }
                }
            }
        }
Example #2
0
        public static SuperGumpAsset CreateInstance(FileInfo file, bool cache, bool reload)
        {
            if (file == null || !file.Exists)
            {
                return(Empty);
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                var hash = CryptoGenerator.GenString(CryptoHashType.MD5, file.FullName);

                SuperGumpAsset a;

                lock (_CacheLock)
                {
                    a = AssetCache.FirstOrDefault(ca => ca.Hash == hash);
                }

                if (a == null || reload)
                {
                    using (var img = new Bitmap(file.FullName, true))
                    {
                        a = new SuperGumpAsset(file, img);

                        if (cache)
                        {
                            lock (_CacheLock)
                            {
                                AssetCache.AddOrReplace(a);
                            }
                        }
                    }
                }

                if (IsNullOrEmpty(a))
                {
                    return Empty;
                }

                if (!cache || a.Capacity > 0x1000)
                {
                    lock (_CacheLock)
                    {
                        AssetCache.Remove(a);
                        AssetCache.Free(false);
                    }
                }

                lock (_CacheLock)
                {
                    if (AssetCache.Count > 100)
                    {
                        AssetCache.RemoveAt(0);
                    }

                    AssetCache.Free(false);
                }

                return a;
            },
                       VitaNexCore.ToConsole));
        }
Example #3
0
 public static bool IsNullOrEmpty(SuperGumpAsset asset)
 {
     return(asset == null || asset == Empty || asset.Hash == Empty.Hash || asset.Capacity == 0 || asset.Count == 0);
 }
Example #4
0
 static SuperGumpAsset()
 {
     AssetCache = new List <SuperGumpAsset>();
     Empty      = new SuperGumpAsset();
 }
Example #5
0
 public void AddAsset(int x, int y, FileInfo file)
 {
     AddAsset(x, y, SuperGumpAsset.LoadAsset(file));
 }
Example #6
0
 public void AddAsset(int x, int y, Uri url)
 {
     AddAsset(x, y, SuperGumpAsset.LoadAsset(url));
 }
Example #7
0
 public void AddAsset(int x, int y, string path)
 {
     AddAsset(x, y, SuperGumpAsset.LoadAsset(path));
 }
Example #8
0
 protected SuperGumpAsset LoadAsset(string path)
 {
     return(SuperGumpAsset.LoadAsset(path));
 }
Example #9
0
 public bool Equals(SuperGumpAsset other)
 {
     return(!ReferenceEquals(other, null) && Hash.Equals(other.Hash));
 }