view LightClone/Source/GuiFunctor.h @ 51:efd2b1ca5b77

Clean up gui
author koryspansel <koryspansel@bendbroadband.com>
date Tue, 27 Sep 2011 09:42:01 -0700
parents b4dc5d674e22
children
line wrap: on
line source

/*
 * GuiFunctor
 */

#ifndef __GUIFUNCTOR_H__
#define __GUIFUNCTOR_H__

#include "Types.h"
#include "ArrayList.h"

/*
 * GuiEventArguments
 */
struct GuiEventArguments;

/*
 * GuiFunctor
 */
class GuiFunctor
{
public:

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

public:

	/*
	 * ~GuiFunctor
	 */
	virtual ~GuiFunctor()
	{
	}

	/*
	 * operator ()
	 */
	virtual void operator()(GuiEventArguments&) = 0;
};

/*
 * GuiFunction
 */
class GuiFunction : public GuiFunctor
{
	/*
	 * FunctorType
	 */
	typedef void (*FunctorType)(GuiEventArguments&);

	/*
	 * pFunctor
	 */
	FunctorType pFunctor;

public:

	/*
	 * GuiFunction
	 */
	GuiFunction(FunctorType pFunction) : pFunctor(pFunction)
	{
	}

	/*
	 * operator ()
	 */
	virtual void operator()(GuiEventArguments& kArguments)
	{
		(*pFunctor)(kArguments);
	}
};

/*
 * GuiMethod
 */
template <typename Object>
class GuiMethod : public GuiFunctor
{
	/*
	 * FunctorType
	 */
	typedef void (Object::*FunctorType)(GuiEventArguments&);

	/*
	 * pFunctor
	 */
	FunctorType pFunctor;

	/*
	 * pObject
	 */
	Object* pObject;

public:

	/*
	 * GuiMethod
	 */
	GuiMethod(FunctorType pMethod, Object* pInstance) : pFunctor(pMethod), pObject(pInstance)
	{
	}

	/*
	 * operator()
	 */
	void operator()(GuiEventArguments& kArguments)
	{
		(pObject->*pFunctor)(kArguments);
	}
};

#endif //__GUIFUNCTOR_H__