using Nerfed.Runtime.Graphics; namespace Nerfed.Runtime.Gui; public class GuiTextureStorage { private readonly Dictionary> pointerToTexture = new Dictionary>(); public IntPtr Add(Texture texture) { if (!pointerToTexture.ContainsKey(texture.Handle)) { pointerToTexture.Add(texture.Handle, new WeakReference(texture)); } return texture.Handle; } public Texture GetTexture(IntPtr pointer) { if (!pointerToTexture.TryGetValue(pointer, out WeakReference value)) { return null; } WeakReference result = value; if (!result.TryGetTarget(out Texture texture)) { pointerToTexture.Remove(pointer); return null; } return texture; } }