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

*/

#ifndef SGX_CORE_GUI_WIDGET_HPP
#define SGX_CORE_GUI_WIDGET_HPP	1

class sgxWidget : public CGameHandler {
public:

	typedef enum {
		eInFrontOf,
		eBehind,
	} tDepthPosition;

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

	sgxWidget(const tINT32 x=0, const tINT32 y=0, const CGUIDesignScreen::tWidgetType type=CGUIDesignScreen::widgetUnknown);

	virtual CGUIDesignScreen::tWidgetType	getType();

	virtual tBOOL			enable();
	virtual tBOOL			disable();
	virtual tBOOL			show();
	virtual tBOOL			hide();
	virtual void			setCallback(CSGXCallback *pCallback);
	virtual CSGXCallback *	getCallback() const;
	virtual void 			setText(const sgxString &s);
	virtual void			getPosition(sgxPoint2i &pt);
	virtual void 			setPosition(const sgxPoint2i &pt);
	virtual void 			setPosition(const tINT32 x, const tINT32 y);
	virtual void 			setSize(const tINT32 w, const tINT32 h);

	virtual void			update(const tREAL32 telaps);
	virtual void			draw() const { draw(0,0); }	// explicitly done, because draw(x,y) would hide parent class method
	virtual tBOOL			draw(const tINT32 offsetX, const tINT32 offsetY) const;

	virtual tBOOL			onPressed(const sgxVector2 &position);
	virtual tBOOL			onRelease(const sgxVector2 &position);
	virtual tBOOL			onLeaveArea(const sgxVector2 &position);
	virtual tBOOL			onReenterArea(const sgxVector2 &position);
	virtual tBOOL			onKeyDown(const tUINT32 key);
	virtual tBOOL			onKeyUp(const tUINT32 key);
	virtual tBOOL			onHoverEnter(const sgxVector2 &position);
	virtual tBOOL			onHoverLeave(const sgxVector2 &position);
	virtual tBOOL			onFocusGain();
	virtual tBOOL			onFocusLose();
	virtual tBOOL			onActiveGain();
	virtual tBOOL			onActiveLose();

	virtual tBOOL			onSelect(const sgxVector2 &position);

	virtual tBOOL			isFocused() const;
	virtual tBOOL			isActive() const;
	virtual tBOOL			isEnabled() const;
	virtual tBOOL			isVisible() const;
	
	virtual tBOOL			isPointInside(const sgxPoint2i &position) const;
	virtual void			getArea(sgxRect2i &rc) const;

	virtual tBOOL 			reorderWidget(sgxWidget *pTargetWidget, const tDepthPosition pos, sgxWidget *pMarkerWidget);

	virtual sgxWidget *		getWidget(const tUINT32 idx);
	virtual const sgxWidget*getWidgetAt(const sgxPoint2i &position) const;
	virtual sgxWidget *		getWidgetAt(const sgxPoint2i &position, const tSelectionSet fromSet=eAll);
	virtual tUINT32			getWidgetListWithin(const sgxRect2i &rc, sgxVector<sgxWidget *> &widgetList);
	
	virtual sgxWidget *		addChildWidget(sgxWidget *pWidget);
	virtual sgxWidget *		getChildWidget(const tUINT32 idx);
	virtual sgxWidget *		getChildWidget(const tUINT32 idx, CGUIDesignScreen::tWidgetType type);
	virtual void 			clearChildWidgets();
	virtual void 			releaseChildWidgets();

	virtual tUINT32			getUserData() const { return m_UserData; }
	virtual tUINT32 		setUserData(const tUINT32 id) {tUINT32 old = m_UserData; m_UserData=id; return old; }


protected:

	CGUIDesignScreen::tWidgetType	m_Type;

	sgxVector<sgxWidget *>			m_Children;
	sgxWidget *						m_pParent;

	tINT32							m_X, m_Y;
	tBOOL							m_bEnabled;
	tBOOL							m_bVisible;
	CSGXCallback *					m_pSelectCallback;

	tBOOL							m_State;
	tBOOL							m_DirectedState;	// true means the mouse has clicked onto it, and is currently hovering over it
	tBOOL							m_isOver;			// for when the cursor hovers over the buttons, whether the button is pressed or not
	sgxWidgetGroup *				m_pGroup;
	tUINT32							m_KeyboardShortcut;		// the key itself
	tUINT32							m_KeyboardShortcutExt;	// the extensions, e.g. alt, necessary
	//
	tMEM_SIZE						m_UserData;
};

#endif /* SGX_CORE_GUI_WIDGET_HPP */

