Blame | Last modification | View Log | RSS feed
// TextureFile.h: interface for the CTextureFile class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TEXTUREFILE_H__07FEFD54_9847_4F3E_9BF1_20F80C6B5EA4__INCLUDED_)
#define AFX_TEXTUREFILE_H__07FEFD54_9847_4F3E_9BF1_20F80C6B5EA4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define TEXTUREFILE_VERSION 1.20
#define DIRECT3D
enum {TEXTURELOAD_OK, TEXTURELOAD_NOFILE, TEXTURELOAD_INVALIDFORMAT, TEXTURELOAD_SIZEMISMATCH};
#include <Utils/String.h>
typedef struct {
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char alpha;
} STextureData;
typedef struct {
int width;
int height;
int num;
} STextureSize;
typedef struct {
unsigned int cols;
unsigned int rows;
unsigned int x;
unsigned int y;
} STextureFrames;
typedef struct {
unsigned int minx;
unsigned int maxx;
unsigned int miny;
unsigned int maxy;
} SFrameBounds;
typedef struct {
char *name;
int delay;
int amt;
int *frames;
bool cont;
bool remove;
} SAnimation;
typedef struct {
SAnimation *anim;
int curframe;
int delay;
bool reverse;
} SPlayAnimation;
//#include "Visualisation.h"
#include <d3dx9.h>
class CTextureFile
{
public:
static std::string GetErrorText ( int error );
public:
bool CheckAlpha ( int x, int y, int frame, bool inccollisionmap = true );
int GetFrameHeight();
int GetFrameWidth();
void SetEditor();
SAnimation * GetAnimation ( int num );
SAnimation * FindAnimation ( const char *search );
int GetAnimationNum();
SAnimation * AddNewAnimation ( const char *name );
bool GetAlphaMap ( int *red, int *green, int *blue );
void SetAlphaMap ( int red, int green, int blue );
bool GetAlphaMap();
void EnableAlphamap ( bool enable = true );
void SetFrames ( int rows, int cols );
const STextureFrames * GetFrames();
void SetFrameSize ( int width, int height );
bool Load ( const char *filename );
bool Save ( const char *filename );
bool SaveTGA ( const char *filename );
int GetWidth() { return m_width; }
int GetHeight() { return m_height; }
int GetMinAlphaX ( int frame ) { return m_framebounds[frame].minx; }
int GetMaxAlphaX ( int frame ) { return m_framebounds[frame].maxx; }
int GetMinAlphaY ( int frame ) { return m_framebounds[frame].miny; }
int GetMaxAlphaY ( int frame ) { return m_framebounds[frame].maxy; }
#ifdef DIRECT3D
LPDIRECT3DTEXTURE9 CreateTexture ( LPDIRECT3DDEVICE9 device );
LPDIRECT3DTEXTURE9 CreateCollisionTexture(LPDIRECT3DDEVICE9 device, DWORD nRed, DWORD nGreen, DWORD nBlue);
#endif //DIRECT3D
int LoadTextureTGA(const char *filename );
int LoadCollisionTGA(const char *filename );
bool CollisionMap () { return m_collisionMap; }
void WipeCollisionMap () { if ( m_collisionData ) delete [] m_collisionData; m_collisionMap = false; m_collisionData = NULL; }
CTextureFile ( bool editor = false );
virtual ~CTextureFile();
private:
int ComputeMinAlphaX ( int frame );
int ComputeMaxAlphaX ( int frame );
int ComputeMinAlphaY ( int frame );
int ComputeMaxAlphaY ( int frame );
typedef struct {
bool alpha;
int alphamap[3];
bool frames;
int height;
int width;
} SFileHeader;
STextureData *m_data;
STextureFrames m_frames;
int m_numData; // number of entries in array (width * height)
int m_width; // width of texture file
int m_height; // height of texture file
bool m_alpha;
int m_alphamap[3];
int m_numframes;
SFrameBounds *m_framebounds;
void ClearHeader ( SFileHeader *header );
STextureData *LoadTGA(const char *filename, STextureSize *tsize, int *error );
STextureData *CreateData(int width, int height, STextureSize *size );
SAnimation *m_anim;
int m_animNum;
bool m_editor;
bool m_collisionMap;
bool *m_collisionData;
};
void IncAnimationFrame ( SPlayAnimation *anim, int *times = NULL );
void IncAnimationFrame ( SPlayAnimation *anim, bool endstop, int *times = NULL );
void DecAnimationFrame ( SPlayAnimation *anim, int *times = NULL );
void DecAnimationFrame ( SPlayAnimation *anim, bool endstop, int *times = NULL );
void DoAnimation ( SPlayAnimation *anim, bool endstopinc, bool endstopdec, int *times = NULL );
void ResetAnimation ( SPlayAnimation *anim );
#endif // !defined(AFX_TEXTUREFILE_H__07FEFD54_9847_4F3E_9BF1_20F80C6B5EA4__INCLUDED_)