/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/sgx/graphics/sgxtexture.hpp

*/

#ifndef SGX_GRAPHICS_TEXTURE_HPP
#define SGX_GRAPHICS_TEXTURE_HPP	1

class CSGXDrawSurface;

class sgxRegion : public sgxUV {
public:
	sgxRegion();
	//sgxRegion(const sgxUV &uv);
	
	sgxRegion(const tUINT32 tw, const tUINT32 th, const sgxUV &uv);
	sgxRegion(const tUINT32 tw, const tUINT32 th, const tUINT32 x, const tUINT32 y, const tUINT32 x2, const tUINT32 y2);

	tUINT16 width, height;	// in pixels. both are set to 0 if unknown. 
	// In which case, use the floating versions and multiple by width.
	// This should only occur in bad cases, when the default ctor has been used
};

class CSGXTexture : public CGameHandler {
public:
	typedef CImageData::tFormat			tFormat;
	typedef CSGXSurface::tReason		tReason;
	typedef CSGXSurface::tWrapped		tWrapped;
	typedef CSGXSurface::tBlendMode		tBlendMode;

	typedef enum {
		eWood,
		eMetal,
		ePlastic,
		eCardboard,
	} tSurfaceType;

	static CSGXTexture	Null;

	CSGXSurface *			m_pSurface;
	sgxVector<sgxRegion>	m_Region;
	tBOOL					m_Transparent;
	tBOOL					m_Translucent;

	virtual tBOOL	isTranslucent() const { return m_Translucent; }
	virtual tBOOL	isTransparent() const { return m_Transparent; }
	
	CSGXTexture();
	virtual ~CSGXTexture();
	virtual	void	set() const;
	// TODO: How can these 'set's be const?
	virtual void	setRegion(const tUINT32 region);
	virtual void	setRegion(const sgxUV &uv);
	virtual void	setWrapped(const tWrapped wrapped);
	virtual void	setBlendMode(const tBlendMode mode);
	virtual tBOOL	setTextureProperty(const sgxString &property, const sgxTexturePropertyParams *pParams=NULL);
	virtual void	rebuild(void *pBitmap=NULL);
	
	virtual void	clearRegions();
	virtual tUINT32	addRegion(const sgxUV &region);
	virtual tUINT32	addPixelRegion(const tUINT32 x, const tUINT32 y, const tUINT32 x2, const tUINT32 y2);
	virtual tUINT32	addStd4Regions();
	virtual tUINT32	addStandardRegions(const tUINT32 w, const tUINT32 h);
	virtual tUINT32	addRegionSizes(const tUINT32 w, const tUINT32 h);


	virtual tUINT32	getRegionWidth(const tUINT32 region) const;
	virtual tUINT32	getRegionWidth(const sgxUV &uv) const;
	virtual tUINT32	getRegionHeight(const tUINT32 region) const;
	virtual tUINT32	getRegionHeight(const sgxUV &uv) const;
	virtual void 	getRegionSize(const tUINT32 region, sgxDimension2i &size) const;
	virtual void	getRegionSize(const sgxUV &uv, sgxDimension2i &size) const;
	virtual void	getRegionArea(const tUINT32 region, sgxRect2i &rc) const;

	virtual tUINT32	getWidth() const;
	virtual tUINT32	getHeight() const;
	virtual tUINT32	getNumRegions() const;
	virtual void	getRegion(const tUINT32 region, sgxUV &uv) const;
	virtual void	*getDynamicBitmap();
	virtual tBOOL	getDynamicImageData(CImageData &data) const;

private:
};

class CSGXTextureBank {
public:
	tUINT32 		add(CSGXTexture *pTexture);
	CSGXTexture *	get(tUINT32 id);
 
	tUINT32 		loadTextures(const sgxString &filename);
 
protected:
	sgxVector<CSGXTexture *> m_TextureList;
};
 
#endif /* SGX_GRAPHICS_TEXTURE_HPP */
