// ------------------------------------------------------------------------
/*
	author: Jaap Suter
   
	Copyright (C) Electronic Arts Canada Inc. 2002.  All rights reserved.	
*/
// ------------------------------------------------------------------------

/*! \file */

#ifndef REVEAL_BUTTON_CONTROL_H
#define REVEAL_BUTTON_CONTROL_H

#include "reveal/impl/widget.h"
#include "reveal/impl/gui_metrics.h"

#include "reveal/callback/callback_0.h"

namespace Reveal {
		
	namespace Impl {

		class Tree;

// -------------------------------------------------------------------------------
/*!
	\brief Simple button control, calling a given callback when the 
		   button is pressed;
*/
// -------------------------------------------------------------------------------
class ButtonControl : public Widget
{
	typedef Callback::Callback0< void > Callback;

public:

	/*!
		\brief Constructor, does nothing special;
		\param name	Name of the widget;
		\param tree Reference to the tree this widget belongs to;
		\param callback Callback that takes a void* and returns void, it is called when the button is pressed, 						
	*/
	ButtonControl ( const char* name, Tree& tree, const Callback& callback )  
	: Widget( name, tree )
	, mCallback( callback )
	, mDown( false )
	{
		SetHelp( "Confirm or left mouse button:\n"
				"Execute action" );
	}
		  
private:

	// Copy ctor and assignment operator are disabled;
	ButtonControl( const ButtonControl& );
	ButtonControl& operator = ( const ButtonControl& );

	//! Implementation of pure base virtual;
    void DoRender( const Renderer& renderer, const GuiColors& guiColors ) const;

	//! Implementation of pure base virtual;
    virtual Widget* DoHandle( const InputState& inputState );

	//! Implementation of pure base virtual;
	virtual size_t DoToString( const char* path, char* buffer, size_t size ) const { return 0; }

	//! Implementation of pure base virtual;
	virtual void DoFromString( const char* data ) { /* do nothing */; }

	//! Returns the width of the button control in GUI space;
	virtual int  Width() const { return Impl::GuiMetrics::GetWidgetWidth(); }

	//! Returns the height of the button control in GUI space;
	virtual int  Height() const { return Impl::GuiMetrics::GetRowHeight(); }

	Callback mCallback;
	bool     mDown;		//!< True if the button is down (the mouse is over it, and the mouse left button is down);
};

	} // Namespace Impl;
} // Namespace Reveal;

#endif
