#ifndef ICON_HPP
#define ICON_HPP

#include "sprite.h"

class cSpriteIcon : public cSprite
{
DECLARE_SERIAL(cSpriteIcon)
public:
	static BOOL ENABLEDISPLAYLIST;	/* ENABLEDISPLAYLIST specifies whetehr or not you want to
		try and use a display list to show this kind of sprite. By default this is TRUE.  We 
		have it because the cSpriteIcon actually runs slower with displaylists, so we
		want to be able turn of display lists for them. So we have a cSpriteIcon::ENABLEDISPLAY
		list that is FALSE to shadow (hide) the cSprite::ENABLEDISPLAYLIST. */ 
protected:
	BOOL _transparent; /*Usually _transparent is TRUE, but if we use a cSpriteIcon for, say,
		a backgroudn bitmap, we might want _transparent to be FALSE. */
	int _resourceID;
	Real _aspect; /* The ratio of the width to the height.  Gets set when you first
		set up the image to match the _resourceID in the cGraphics object. */
	Real _sizex, _sizey; //These are helpers kept in synch with _aspect and _radius.
	BOOL _imageloaded; /* The first time we draw the icon and actually load its image,
		we set the _aspect to match the image unless presetaspect is TRUE. */
	BOOL _presetaspect; /* If _presetaspect holds, then the first time we load the image,
		we crop the image so that its size matches the _aspect. */
	Real _visualradius; /* Maintain a _visualradius smaller than _radius
		which is the radius of the rectangle out to the corners.  A typical
		bitmap might not go out to the corners of the rect its in, but rather out
		to its sides.  Let's try the average of the distance to the sides. */
public:
	cSpriteIcon();
	cSpriteIcon(int resourceID, BOOL transparent = TRUE, BOOL presetaspect = FALSE);
	cSpriteIcon(cSpriteIcon *picon);
	cSpriteIcon(cSpriteIcon &picon);
	~cSpriteIcon(){} /* Either we have the owner critter tell all the views to
		tell their pgraphics to get rid	of the images matching _resourceID, or we
		will eventually let the pgraphics have a garbage collection routine to winnow
		out scaled icons that are no longer in use.  In any case, the pgraphics will
		free up all the resourceImage and scaledImage objects in its destructor. */
//Accessors
	Real aspect()const{return _aspect;}
	BOOL transparent()const{return _transparent;}
	int resourceID(){return _resourceID;}
	Real sizex(){return _sizex;}
	Real sizey(){return _sizey;}
	virtual Real radius() const; /* Overload to returns something based on
		_visualradius. */ 
	cVector locorner(){return center() - cVector(_sizex/2.0, _sizey/2.0);}
	cVector hicorner(){return center() + cVector(_sizex/2.0, _sizey/2.0);}
	BOOL imageloaded(){return _imageloaded;}
	BOOL presetaspect(){return _presetaspect;}
	virtual BOOL enabledisplaylist()const{return cSpriteIcon::ENABLEDISPLAYLIST;}
//Mutator
	void setResourceID(int resourceid){_resourceID = resourceid;} /* We'll count
		on the cGraphics to free the old resource bitmap memory and allocate the
		new resrouce bitmap memory as part of this sprite's next call to draw. */
	void setAspect(Real aspect);
	void setImageloaded(BOOL imageloaded){_imageloaded = imageloaded;}
//cSprite overloads
	virtual void setRadius(Real radius);
	virtual void copy(cSprite *psprite);
	virtual void Serialize(CArchive &ar);
//The imagedraw function
	virtual void imagedraw(cGraphics *pgraphics, int drawflags = 0);
};

class cSpriteIconBackground : public cSpriteIcon
{
DECLARE_SERIAL(cSpriteIconBackground)
public:
	cSpriteIconBackground(){}
	cSpriteIconBackground(int resourceID, const cRealBox2 &worldborder);
};


#endif //ICON_HPP