2009-04-19 18:07:22 +00:00
#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 ;
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
using System.Runtime.InteropServices ;
using CodeImp.DoomBuilder.Windows ;
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.Data
{
public sealed class SpriteImage : ImageData
{
#region = = = = = = = = = = = = = = = = = = Variables
2016-01-11 13:00:52 +00:00
private int offsetx ;
private int offsety ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
public int OffsetX { get { return offsetx ; } }
public int OffsetY { get { return offsety ; } }
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Disposer
// Constructor
internal SpriteImage ( string name )
{
// Initialize
SetName ( name ) ;
// We have no destructor
GC . SuppressFinalize ( this ) ;
}
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
Model rendering (all modes): UDMF scale, pitch and roll are now displayed.
Thing Edit Form, UDMF: added controls for setting pitch, roll, scale, render style, fill color, alpha, health and score.
Visual mode, UDMF: UDMF scale is now applied when rendering sprites.
Added Thing Statistics form (Edit -> View Thing Types...), which shows all loaded thing types with some additional info.
Visual mode: sprites with negative ScaleX and positive ScaleY were not rendered properly.
Classic modes: display was not updated after loading a sprite.
Current testing engine change was not saved on closing the program when no other game configuration settings were changed.
2014-04-30 10:01:22 +00:00
//mxd
override public void LoadImage ( )
{
// Do the loading
LocalLoadImage ( ) ;
// Notify the main thread about the change to redraw display
IntPtr strptr = Marshal . StringToCoTaskMemAuto ( this . Name ) ;
General . SendMessage ( General . MainWindow . Handle , ( int ) MainForm . ThreadMessages . SpriteDataLoaded , strptr . ToInt32 ( ) , 0 ) ;
}
2009-04-19 18:07:22 +00:00
// This loads the image
protected override void LocalLoadImage ( )
{
// Leave when already loaded
if ( this . IsImageLoaded ) return ;
lock ( this )
{
// Get the lump data stream
2016-03-14 21:53:53 +00:00
string spritelocation = string . Empty ; //mxd
Stream lumpdata = General . Map . Data . GetSpriteData ( Name , ref spritelocation ) ;
2009-04-19 18:07:22 +00:00
if ( lumpdata ! = null )
{
// Copy lump data to memory
lumpdata . Seek ( 0 , SeekOrigin . Begin ) ;
2015-12-28 15:01:53 +00:00
byte [ ] membytes = new byte [ ( int ) lumpdata . Length ] ;
2009-04-19 18:07:22 +00:00
lumpdata . Read ( membytes , 0 , ( int ) lumpdata . Length ) ;
2015-12-28 15:01:53 +00:00
MemoryStream mem = new MemoryStream ( membytes ) ;
2009-04-19 18:07:22 +00:00
mem . Seek ( 0 , SeekOrigin . Begin ) ;
// Get a reader for the data
2015-12-28 15:01:53 +00:00
IImageReader reader = ImageDataFormat . GetImageReader ( mem , ImageDataFormat . DOOMPICTURE , General . Map . Data . Palette ) ;
2009-04-19 18:07:22 +00:00
if ( reader is UnknownImageReader )
{
// Data is in an unknown format!
2016-03-14 21:53:53 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "Sprite lump \"" + Path . Combine ( spritelocation , Name ) + "\" data format could not be read. Does this lump contain valid picture data at all?" ) ;
2009-04-19 18:07:22 +00:00
bitmap = null ;
}
else
{
// Read data as bitmap
mem . Seek ( 0 , SeekOrigin . Begin ) ;
if ( bitmap ! = null ) bitmap . Dispose ( ) ;
bitmap = reader . ReadAsBitmap ( mem , out offsetx , out offsety ) ;
}
// Done
mem . Dispose ( ) ;
if ( bitmap ! = null )
{
// Get width and height from image
width = bitmap . Size . Width ;
height = bitmap . Size . Height ;
2010-01-02 20:22:05 +00:00
scale . x = 1.0f ;
scale . y = 1.0f ;
2009-04-19 18:07:22 +00:00
// Make offset corrections if the offset was not given
if ( ( offsetx = = int . MinValue ) | | ( offsety = = int . MinValue ) )
{
2010-01-02 20:22:05 +00:00
offsetx = ( int ) ( ( width * scale . x ) * 0.5f ) ;
offsety = ( int ) ( height * scale . y ) ;
2009-04-19 18:07:22 +00:00
}
}
else
{
loadfailed = true ;
}
}
else
{
// Missing a patch lump!
2016-02-22 08:04:06 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "Missing sprite lump \"" + Name + "\". Forgot to include required resources?" ) ;
2009-04-19 18:07:22 +00:00
}
// Pass on to base
base . LocalLoadImage ( ) ;
}
}
#endregion
}
}