/// <summary> /// Cleans up all of the loaded textures. /// </summary> public void ShutdownManagedTextureManager() { for (int i = 0; i < textures.Count; i++) { // Dispose of the textures TEXTURE t = (TEXTURE)textures[i]; t.texture.Dispose(); t.fileName = ""; t.width = -1; t.height = -1; } // Clear the list of all loaded textures. textures.Clear(); }
void DragLoad(string[] files) { string file = files[0]; if (animation != null) { Content.Dispose(animation.Key); } try { animation = Content.Load <TEXTURE>("TEXTURE", file); rects.Clear(); ResetViewport(); } catch (Exception) { } }
/// <summary> /// Releases the memory of a texture. /// </summary> /// <param name="id">Id of the texture to release.</param> public void ReleaseTexture(int id) { // Make sure the id is in range. Debug.Assert((id > -1 && id < textures.Count), "id is out of range"); // Do a lazy delete and leave this spot empty. TEXTURE t = (TEXTURE)textures[id]; t.texture.Dispose(); t.texture = null; t.fileName = ""; t.width = -1; t.height = -1; // Put it back in textures array changed. textures[id] = t; if (!textures[id].Equals(t)) { MessageBox.Show("theys not equal!!"); } }
private IEnumerable <ICoroutine> MyLoading() { area = PATCH.GetNinePatch(new COLOR(255, 0, 0, 64), new COLOR(255, 0, 0, 222), 1); ResetViewport(); return(null); }
/// <summary> /// Loads a texture into the texture manager. /// </summary> /// <param name="fileName">File name of the texture to load.</param> /// <param name="colorkey">Transparent color (0 for no color key). Use Color.FromArgb() then do Color.ToArgb() (Example: Color.FromArgb(255, 255, 0, 255).ToArgb() for magenta)</param> /// <returns>The id for the loaded texture, -1 on failure.</returns> public int LoadTexture(string fileName, int colorkey) { // See if we have loaded the texture before and return its id for (int i = 0; i < textures.Count; i++) { TEXTURE t = (TEXTURE)textures[i]; if (t.fileName == fileName) { return(i); } } // we haven't loaded it before so... // look for an open spot int id = -1; for (int i = 0; i < textures.Count; i++) { TEXTURE t = (TEXTURE)textures[i]; if (t.texture == null) { id = i; break; } } // if we didn't find an open spot, load it into a new one if (id == -1) { // A temp texture object. TEXTURE loaded; // Copy the filename of the loaded texture. loaded.fileName = fileName; loaded.texture = null; loaded.width = -1; loaded.height = -1; try { loaded.texture = TextureLoader.FromFile(device, fileName, 0, 0, 1, Usage.None, Format.Unknown, Pool.Managed, Filter.None, Filter.None, colorkey); } catch (Exception) { MessageBox.Show("Failed to load texture: " + fileName, "ManagedTextureManager::Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(-1); } // Get Width/Height of the texture. loaded.width = loaded.texture.GetSurfaceLevel(0).Description.Width; loaded.height = loaded.texture.GetSurfaceLevel(0).Description.Height; // Put the texture into the list. textures.Add(loaded); // Return the id of the texture. return(textures.Count - 1); } // we found an open spot else { TEXTURE t = (TEXTURE)textures[id]; // Make sure the texture has been released. if (t.texture != null) { t.texture.Dispose(); t.texture = null; } // Copy the filename of the loaded texture. t.fileName = fileName; // Load the texture from the given file. try { t.texture = TextureLoader.FromFile(device, fileName, 0, 0, 1, Usage.None, Format.Unknown, Pool.Managed, Filter.None, Filter.None, colorkey); } catch (Exception) { MessageBox.Show("Failed to load texture: " + fileName, "ManagedTextureManager::Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(-1); } // Get Width/Height of the texture. t.width = t.texture.GetSurfaceLevel(0).Description.Width; t.height = t.texture.GetSurfaceLevel(0).Description.Height; textures[id] = t; if (!textures[id].Equals(t)) { MessageBox.Show("theys not equal!!"); } // Return the id of the texture. return(id); } }