view LightClone/Source/GuiElement.h @ 37:58a16d529d95

Refactoring code and adding events for drag and drop
author koryspansel <koryspansel@bendbroadband.com>
date Wed, 21 Sep 2011 20:30:29 -0700
parents 06b151afc8d0
children 7ff46a00bcd3
line wrap: on
line source

/*
 * GuiElement
 */

#ifndef __GUIELEMENT_H__
#define __GUIELEMENT_H__

#include "Core.h"
#include "ResourceManager.h"
#include "RenderContext.h"
#include "Camera.h"
#include "ArrayList.h"
#include "GuiEventMap.h"

/*
 * GuiElementFlag
 */
enum
{
	GuiElementFlag_Visible	= 1 << 0,
	GuiElementFlag_Pickable	= 1 << 1,
};

/*
 * GuiElement
 */
class GuiElement : private GuiEventMap
{
	/*
	 * GuiInterface
	 */
	friend class GuiInterface;

public:

	/*
	 * EventDrop
	 */
	static const char* EventDrop;

	/*
	 * List
	 */
	typedef ArrayList<GuiElement*> List;

protected:

	/*
	 * pInterface
	 */
	GuiInterface* pInterface;

	/*
	 * pContainer
	 */
	GuiElement* pContainer;

	/*
	 * kPosition
	 */
	D3DXVECTOR2 kPosition;

	/*
	 * kDimensions
	 */
	D3DXVECTOR2 kDimensions;

	/*
	 * kColor
	 */
	D3DCOLOR kColor;

	/*
	 * nFlags
	 */
	uint32 nFlags;

	/*
	 * kChildren
	 */
	List kChildren;

public:

	/*
	 * GuiElement
	 */
	GuiElement();

	/*
	 * ~GuiElement
	 */
	virtual ~GuiElement();

	/*
	 * Initialize
	 */
	virtual ErrorCode Initialize(ResourceManager* pResourceManager);

	/*
	 * Terminate
	 */
	virtual void Terminate();

	/*
	 * Update
	 */
	virtual void Update(float fElapsed);

	/*
	 * Render
	 */
	virtual void Render(RenderContext& kContext, Camera& kCamera);

	/*
	 * SetInterface
	 */
	void SetInterface(GuiInterface* pInstance);

	/*
	 * GetInterface
	 */
	GuiInterface* GetInterface();

	/*
	 * SetParent
	 */
	void SetParent(GuiElement* pInstance);

	/* 
	 * GetParent
	 */
	GuiElement* GetParent();

	/*
	 * SetPosition
	 */
	void SetPosition(float fX, float fY);

	/*
	 * SetPosition
	 */
	void SetPosition(const D3DXVECTOR2& kValue);

	/*
	 * GetPosition
	 */
	const D3DXVECTOR2 GetPosition() const;

	/*
	 * SetDimensions
	 */
	void SetDimensions(float fWidth, float fHeight);

	/*
	 * SetDimensions
	 */
	void SetDimensions(const D3DXVECTOR2& kValue);

	/*
	 * GetDimensions
	 */
	const D3DXVECTOR2 GetDimensions() const;

	/*
	 * GetWidth
	 */
	float GetWidth() const;

	/*
	 * GetHeight
	 */
	float GetHeight() const;

	/*
	 * SetFlag
	 */
	void SetFlag(uint32 nValue);

	/*
	 * ClearFlag
	 */
	void ClearFlag(uint32 nValue);

	/*
	 * HasFlag
	 */
	bool HasFlag(uint32 nValue) const;

	/*
	 * IsVisible
	 */
	bool IsVisible() const;

	/*
	 * SetColor
	 */
	void SetColor(D3DCOLOR nColor);

	/*
	 * Pick
	 */
	virtual GuiElement* Pick(float fX, float fY);

	/*
	 * Add
	 */
	ErrorCode Add(GuiElement* pElement);

	/*
	 * Remove
	 */
	ErrorCode Remove(GuiElement* pElement);

	/*
	 * Contains
	 */
	bool Contains(float fX, float fY);

	/*
	 * Subscribe
	 */
	using GuiEventMap::Subscribe;

	/*
	 * Fire
	 */
	using GuiEventMap::Fire;

protected:

	/*
	 * OnMouseEnter
	 */
	virtual void OnMouseEnter();

	/*
	 * OnMouseLeave
	 */
	virtual void OnMouseLeave();

	/*
	 * OnMouseDown
	 */
	virtual void OnMouseDown(uint32 nButton, float fX, float fY);

	/*
	 * OnMouseUp
	 */
	virtual void OnMouseUp(uint32 nButton, float fX, float fY);

	/*
	 * OnMouseMove
	 */
	virtual void OnMouseMove(float fX, float fY);

	/*
	 * OnDrop
	 */
	virtual void OnDrop(GuiElement* pSource, float fX, float fY);
};

#endif //__GUIELEMENT_H__