// ------------------------------------------------------------------------
/*
	Copyright (C) Electronic Arts Canada Inc. 2004.  All rights reserved.	
*/
// ------------------------------------------------------------------------

/*! \file */

#ifndef REVEAL_WATCH_H
#define REVEAL_WATCH_H

#include <stddef.h>
#include "reveal/impl/window.h"
#include "reveal/impl/gui_metrics.h"
#include "reveal/type_traits/type_traits.h"
#include "reveal/impl/util.h"

namespace Reveal {

// ------------------------------------------------------------------------------
/*!
	\brief Todo
*/
// ------------------------------------------------------------------------------
template < class T >
class Watch : public Impl::Window
{
	typedef Callback::Callback0< T > CallbackFromGame;

public:

	Watch( const char* name, Impl::Tree& tree, const CallbackFromGame& callbackFromGame )
		: Impl::Window( name, tree ), mCallbackFromGame(callbackFromGame)
	{
	}

private:

	virtual Reveal::Impl::Widget* DoHandle( const InputState& inputState )
	{
		if ( mCallbackFromGame.Valid() ) {
			mValue = mCallbackFromGame();
		}

		return (Impl::Window::DoHandle(inputState));
	}

	virtual void DoRender( const Renderer& renderer, const GuiColors& guiColors ) const
	{
		renderer.Bar( X(), Y(), Width(), Height(), 0x66000000 );
		renderer.Bar( X() + Width() - 20, Y() + Height() - 20, 20, 20, 0xFF222222 );
		renderer.Bar( X(), Y(), Width(), Impl::GuiMetrics::GetRowHeight(), 0xFF888888 );
		renderer.String( X() + Impl::GuiMetrics::TEXT_BORDER_WIDTH, Y() + Impl::GuiMetrics::TEXT_BORDER_HEIGHT, Name(), guiColors.mTextColor );

		const int maxStringLength = 32;
		char valueRepr[ maxStringLength ];
		if ( TypeTraits::IsIntegral< T >::value )
		{
			Util::ToString( static_cast< int >( mValue ), valueRepr, maxStringLength );
		}
		else
		{
			Util::ToString( static_cast< float >( mValue ), valueRepr, maxStringLength );
		}
		renderer.String( X() + (Width() / 2), Y() + (Height() / 2), valueRepr, 0xFFFFFFFF );

		Window::DoRender( renderer, guiColors );
	}

	Watch( const Watch& ); // Not implemented, non-copyable;
	Watch& operator = ( const Watch& ); // Not implemented, non-assignable;

	virtual size_t  DoToString( const char* path, char* buffer, size_t size ) const
	{
		// Does nothing (can't save a graph);
		return 0;
	}

	T mValue;							//!< Current value in the range;
	CallbackFromGame mCallbackFromGame;
};

} // Namespace Reveal;

#endif	//REVEAL_WATCH_H

