/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     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: include/sgx/gui/guimanager.hpp

*/

#ifndef SGX_CORE_GUI_GUIMANAGER_HPP
#define SGX_CORE_GUI_GUIMANAGER_HPP	1

class CSGXGUI : public CSGXEngine {
public:

	typedef  enum {
		eAll=0,
		eFunctioningWidgets,
	} tSelectionSet;

	static CSGXGUI *ms_pSingleton;
	static CSGXGUI *get();

	virtual ~CSGXGUI();
	virtual void unregisterObjects();

	virtual CSGXGUISkin * getCurrentSkin();
	virtual const CSGXGUISkin * const getCurrentSkin() const;
	virtual CSGXGUISkin *	setCurrentSkin(CSGXGUISkin *pSkin);
	virtual const CSGXFont *setDefaultFont(const CSGXFont *pFont);

	virtual void			applyPointerPosition(const sgxPoint2i &pos);
	virtual	void			applyPointerUp();
	virtual void			applyPointerDown();
	
	virtual sgxWidgetGroup *createGroup(const tUINT32 userData);
	virtual sgxWidget *		createFrame(const tINT32 x=0, const tINT32 y=0, const sgxGUIFrameParams &params=sgxGUIFrameParams());
	virtual sgxWidget *		createButton(const tINT32 x=0, const tINT32 y=0, const sgxGUIButtonParams &params=sgxGUIButtonParams(), CSGXCallback *pCallback=NULL, const tUINT32 userdata=0);
	virtual sgxWidget *		createImageButton(const tINT32 x=0, const tINT32 y=0, const sgxGUIImageButtonParams &params=sgxGUIImageButtonParams(), CSGXCallback *pCallback=NULL, const tUINT32 userdata=0);
	virtual sgxWidget *		createCheckBox(const tINT32 x=0, const tINT32 y=0, const sgxGUICheckBoxParams &params=sgxGUICheckBoxParams(), CSGXCallback *pCallback=NULL, const tUINT32 userdata=0);
	virtual sgxWidget *		createRadioButton(const tINT32 x=0, const tINT32 y=0, const sgxGUIRadioButtonParams &params=sgxGUIRadioButtonParams(), CSGXCallback *pCallback=NULL, const tUINT32 userdata=0);
	virtual sgxWidget *		createHotSpot(const tINT32 x=0, const tINT32 y=0, const sgxGUIHotSpotParams &params=sgxGUIHotSpotParams(), CSGXCallback *pCallback=NULL, const tUINT32 userdata=0);
	virtual sgxWidget *		createStaticText(const tINT32 x=0, const tINT32 y=0, const sgxGUIStaticTextParams &params=sgxGUIStaticTextParams());
	virtual sgxWidget *		createStaticImage(const tINT32 x=0, const tINT32 y=0, const sgxGUIStaticImageParams &params=sgxGUIStaticImageParams());

	virtual tBOOL 			registerWidget(sgxWidget *pWidget);

	virtual sgxWidget *		getWidgetAt(const sgxWidget::tSelectionSet fromSet);
	virtual sgxWidget *		getWidgetAt(const sgxPoint2i &position, const sgxWidget::tSelectionSet fromSet);
		
	virtual sgxWidget *		getFocusWidget() const;
	virtual sgxWidget *		getActiveWidget() const;

	virtual void 			setPointerImage();	// use default according to skin
	virtual void			setPointerImage(CSGXTexture *pTexture, tUINT32 regionIn=0, tUINT32 regionOut=0, tUINT32 size=32);
	virtual void 			setPointerHotspot(const sgxPoint2i &vHotspot);
	virtual void			showPointer(tBOOL visible=TRUE);
	virtual void			hidePointer();

	virtual void			setRootWidget(sgxWidget *pWidget);
	virtual void			clearFocus();
	virtual void			clearActive();

	virtual void			update(const tREAL32 telaps);
	virtual void			update(sgxWidget *pRoot, const tREAL32 telaps);
	virtual void			draw() const;
	virtual void			draw(const sgxWidget *pFrame) const;

	virtual	CGUIDesign *	loadDesign(const sgxString &filename);
	virtual CGUIDesign *	loadDesign(CSGXFile &file);

protected:
	virtual void			setFocus(sgxWidget *pWidget);
	virtual void			setActive(sgxWidget *pWidget);


private:
	CSGXGUI();

	CSGXGUISkin *	m_pDefaultSkin;
	CSGXGUISkin *	m_pCurrentSkin;
	const CSGXFont *m_pDefaultFont;
	sgxPoint2i		m_vPosition;
	tBOOL			m_PointerIsDown;
	sgxPoint2i		m_vLastPosition;
	tBOOL			m_WasPointerDown;
		
	tUINT32			m_iPointerImageSize;
	tBOOL			m_bPointerVisible;
	CSGXTexture *	m_pPointerTexture;
	tUINT32			m_iPointerRegionIn;
	tUINT32			m_iPointerRegionOut;
	sgxPoint2i		m_vPointerHotspot;

	sgxWidget *		m_pRootWidget;
	
	sgxWidget *		m_pActive;
	sgxWidget *		m_pFocus;
};


#endif /* SGX_CORE_GUI_GUIMANAGER_HPP */
