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

/*! \file */

#ifndef REVEAL_CHECK_BOX_CONTROL_H
#define REVEAL_CHECK_BOX_CONTROL_H

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

#include "reveal/callback/callback_0.h"
#include "reveal/callback/callback_1.h"

#if defined _MSC_VER
	// We disable this for clients. This file is actually okay. It's 
	// just handier for clients if they are able to use non-bools as checkboxes too;
	#pragma warning( disable : 4800 ) // forcing value to bool 'true' or 'false' (performance warning)
#endif

namespace Reveal {
	namespace Impl {

// -------------------------------------------------------------------------------
/*!
	\brief Simple checkbox control, allows control over boolean (or integer in
		   old-scool C code) values;

*/
// -------------------------------------------------------------------------------
class CheckBoxControl : public Widget
{
	//! Type of the callback that is called when the checkbox value changes;
    typedef Callback::Callback1< void, bool  > CallbackToGame;
	typedef Callback::Callback0< bool >		   CallbackFromGame;

public:

	/*!
		\brief Constructor, does nothing special;
		\param name	Name of the widget;
		\param callbackToGame Callback that takes a boolean and returns void, it is called when the checkbox value changes;
		\param callbackFromGame Callback that returns the current boolean status.
	*/	
    CheckBoxControl( const char* name, Tree& tree, const CallbackToGame& callbackToGame, const CallbackFromGame& callbackFromGame ) 
	: Widget( name, tree )
	, mCallbackToGame( callbackToGame )
	, mCallbackFromGame( callbackFromGame )
	, mValue( false )
	{
		SetHelp( "Confirm or left mouse button:\n"
				"Toggle check" );
	}

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

	//Update value from game.
	virtual void	Update( );
		  
private:

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

	//! 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;
	
	CallbackToGame	 mCallbackToGame;
	CallbackFromGame mCallbackFromGame;
	
	bool	 mValue;		//!< Current checkbox value;
};






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

#endif
