/** 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/gui/guidesign.hpp

*/

#ifndef SGX_CORE_GUI_GUIDESIGN_HPP
#define SGX_CORE_GUI_GUIDESIGN_HPP	1

class sgxWidget;

class CGUIDesignScreen {
public:
	typedef enum {
		widgetUnknown,
		//
		widgetFrame,
		widgetImage,
		widgetText,
		widgetButton,
		widgetImageButton,
		widgetHotspot,
		widgetAnimatedImage,
		//
		widgetRadioButton,
		widgetCheckBox,
	} tWidgetType;

	CGUIDesignScreen(const tUINT32 id=0);
	~CGUIDesignScreen();

	sgxWidget *	addWidget(sgxWidget *pWidget);
	void		releaseScreenWidgets();
	sgxWidget * applyScreen();

protected:
	tUINT32							m_ID;
	sgxWidget *						m_pFrame;
	sgxVector<const sgxWidget *>	m_WidgetList;
};

// Do not place members into the CGUIDesignAssetData class, or its derivatives.
// These are intended to be used for pointer casting, somewhat akin to
// interfaces in Java.
class CGUIDesignAssetData {
};

class CGUIDesignAsset  {
public:
	tUINT32					m_ID;
	CGUIDesignAssetData *	m_pData;
};

class CGUIDesignAssetTextureData : public CSGXTexture, public CGUIDesignAssetData {
public:
	static CGUIDesignAsset *load(const sgxString &str, const tUINT32 id);
};

class CGUIDesignAssetAnimationData : public CSGXTextureAnimationData, public CGUIDesignAssetData {
public:
	static CGUIDesignAsset *load(const sgxString &str, const tUINT32 id);
};

class CGUIDesign {
public:
	typedef enum {
		// Horizontal formatting
		fmtLeftJustify,
		fmtCentreJustify,
		fmtRightJustify,
		// Vertical formatting
		fmtTopAlignment,
		fmtMiddleAlignment,
		fmtBottomAlignment,
	} tJustify;
	
	typedef enum {
		assetTexture,
		assetAnimation,
	} tAssetType;

	CGUIDesign();
	~CGUIDesign();

	CGUIDesignAsset **	m_pAssetList;
	CGUIDesignScreen **	m_pScreenList;
	tUINT32				m_iNumTextures;
	tUINT32				m_iNumScreens;
	//
	CGUIDesign(const tUINT32 numAssets);

	CGUIDesignAssetData *getAssetData(const tUINT32 idx) {
		if (idx >= m_iNumTextures) {
			return NULL;
		}
		return m_pAssetList[idx]->m_pData;
	}

	CGUIDesignAssetData *getAssetData(const sgxString &name) {
		tUINT32 id = sgxGetCRC32(name);
		for(tUINT32 i=0;i<m_iNumTextures;++i) {
			if (m_pAssetList[i]->m_ID == id) {
				return m_pAssetList[i]->m_pData;
			}
		}
		return NULL;
	}

	CGUIDesignScreen *getScreen(const tUINT32 idx) {
		if (idx >= m_iNumScreens) {
			return NULL;
		}
		return m_pScreenList[idx];
	}

	void releaseScreenWidgets(const tUINT32 idx) {
		if (idx < m_iNumScreens) {
			m_pScreenList[idx]->releaseScreenWidgets();
		}
	}

	void releaseScreenWidgets() {
		for(tUINT32 i=0;i<m_iNumScreens;++i) {
			releaseScreenWidgets(i);
		}
	}

	static void adjustPosition(tINT32 &x, tINT32 &y, const tUINT32 w, const tUINT32 h, const tJustify fx, const tJustify fy);
};


#endif /* SGX_CORE_GUI_GUIDESIGN_HPP */
