UltimateZoneBuilder/Source/Core/Data/SimpleTextureImage.cs
MaxED 99f3ba2844 Changed long texture names handling. Texture names conversion is no longer required.
Texture browser form: added "Long texture names" check-box. It can be used to toggle between displaying long and short texture names.
Texture browser form: added "Show image size" check-box.
Texture browser form: image size is now shown differently.
Image Selector: added a button to toggle between long and short texture name.
Linedef info panel: long texture names are now displayed properly.
Sector info panel: long texture names are now displayed properly.
Fixed: "Save Screenshot" and "Save Edit Area Screenshot" actions were triggered multiple times when a child window was open.
Fixed: used textures should be always updated after using "Change map in current WAD" action.
Fixed, "Change map in current WAD": fixed a crash when trying to switch from a map with missing game configuration path.
Updated ZDoom_ACS.cfg.
2014-12-03 09:06:05 +00:00

121 lines
3.1 KiB
C#

#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using CodeImp.DoomBuilder.IO;
using System.IO;
#endregion
namespace CodeImp.DoomBuilder.Data
{
internal class SimpleTextureImage : ImageData
{
#region ================== Constants
#endregion
#region ================== Variables
private string lumpname;
#endregion
#region ================== Constructor / Disposer
// Constructor
public SimpleTextureImage(string name, string lumpname, float scalex, float scaley)
{
// Initialize
this.scale.x = scalex;
this.scale.y = scaley;
this.lumpname = lumpname;
SetName(name);
// We have no destructor
GC.SuppressFinalize(this);
}
#endregion
#region ================== Methods
// This loads the image
protected override void LocalLoadImage()
{
// Checks
if(this.IsImageLoaded) return;
lock(this)
{
// Get the patch data stream
if(bitmap != null) bitmap.Dispose(); bitmap = null;
Stream patchdata = General.Map.Data.GetTextureData(lumpname, hasLongName);
if(patchdata != null)
{
// Copy patch data to memory
patchdata.Seek(0, SeekOrigin.Begin);
byte[] membytes = new byte[(int)patchdata.Length];
patchdata.Read(membytes, 0, (int)patchdata.Length);
MemoryStream mem = new MemoryStream(membytes);
mem.Seek(0, SeekOrigin.Begin);
// Get a reader for the data
IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
if(!(reader is UnknownImageReader))
{
// Load the image
mem.Seek(0, SeekOrigin.Begin);
try { bitmap = reader.ReadAsBitmap(mem); }
catch(InvalidDataException)
{
// Data cannot be read!
bitmap = null;
}
}
// Not loaded?
if(bitmap == null)
{
General.ErrorLogger.Add(ErrorType.Error, "Image lump '" + lumpname + "' data format could not be read, while loading texture '" + this.Name + "'. Does this lump contain valid picture data at all?");
loadfailed = true;
}
else
{
// Get width and height from image
width = bitmap.Size.Width;
height = bitmap.Size.Height;
}
// Done
mem.Dispose();
}
else
{
General.ErrorLogger.Add(ErrorType.Error, "Image lump '" + lumpname + "' could not be found, while loading texture '" + this.Name + "'. Did you forget to include required resources?");
loadfailed = true;
}
// Pass on to base
base.LocalLoadImage();
}
}
#endregion
}
}