/*!
 *	\file
 *	\brief	ＧＵＩパーツ スライダクラス
 *
 */
#ifndef CGUISlider_h
#define CGUISlider_h

#include"CGUIParts.h"

namespace Maid
{

	class IGUISlider : public IGUIParts
	{
	public:
		class Listener
		{
			friend IGUISlider;
		public:
			virtual ~Listener(){}
			virtual bool IsCollisionBar( const POINT2DI& pos )const=0;		//!<	スライダバーの範囲内にカーソルがあるか
			virtual bool IsCollisionButton( const POINT2DI& pos )const=0;	//!<	スライダボタンの範囲内にカーソルがあるか
			virtual void OnMove(){}
			virtual void OnDraw( const POINT2DI& BarPos, const POINT2DI& ButtonPos, CGraphic& Render ){}
			virtual void OnFocusIn(){}
			virtual void OnFocusOut(){}

			virtual void OnButtonDown(){}
			virtual void OnButtonUp(){}
			virtual void OnMouseIn(){}
			virtual void OnMouseOut(){}

			virtual int GetBarBegin()  const=0;
			virtual int GetBarLength() const=0;
		protected:
			int GetMeter() const { return m_pOwner->GetMeter(); }

		private:
			IGUISlider*	m_pOwner;
		};

	public:
		IGUISlider();

		void	SetListener(const boost::shared_ptr<Listener>& pListener );
		const boost::shared_ptr<Listener>&	GetSliderListener() const;

		void	SetMeterRange( int begin, int len );
		void	SetMeter( int pos );
		void	SetMeterCallMessage( int pos );
		int		GetMeter() const;

	protected:

		virtual void OnLocalCharCode( const mstring& CharCode ){};
		virtual void OnLocalChangeState( bool NewStateEnable, bool NewStateVisible ){};
		virtual void OnLocalFocusIn();
		virtual void OnLocalFocusOut();

	protected:
		int	GetButtonPos() const;
		int	CalcMeter( int pos ) const;

	protected:
		boost::shared_ptr<Listener>	m_pListener;


		int		m_MeterBegin;	//!<	メモリの開始の値
		int		m_MeterLength;	//!<	メモリの長さ
		int		m_NowMeter;		//!<	現在の位置

		int		m_BarBegin;		//!<	バーの配置座標
		int		m_BarLength;	//!<	バーの長さ


		enum STATE
		{
			STATE_NORMAL,	//!<	通常状態
			STATE_MOVE,		//!<	マウスでスライダを動かせる状態
		};

		STATE	m_State;
	};
	typedef boost::shared_ptr<IGUISlider::Listener> SPGUISLIDERLISTENER;


	//	縦横スライダのインタフェース
	class CGUISliderVH : public IGUISlider
	{
	public:
		enum TYPE
		{
			TYPE_V,	//	縦スライダ
			TYPE_H,	//	横スライダ
		};

		void SetSliderType( TYPE type );

	protected:
		virtual bool IsLocalCollision( const POINT2DI& pos ) const;
		virtual void OnLocalMove();
		virtual void OnLocalDraw( const POINT2DI& pos, CGraphic& Render );
		virtual void OnLocalMouseIn  ( const POINT2DI& pos );
		virtual void OnLocalMouseOut ( const POINT2DI& pos );
		virtual void OnLocalMouseDown( const POINT2DI& pos );
		virtual void OnLocalMouseUp  ( const POINT2DI& pos );
		virtual void OnLocalMouseMove( const POINT2DI& pos );
		virtual void OnLocalKeyDown( unt08 KeyCode );
		virtual void OnLocalKeyUp( unt08 KeyCode ){}

	private:
		VECTOR2DI GetButtonOffset() const;
		int		 CalcMeter( const POINT2DI& pos )const;
	private:
		TYPE	m_Type;
	};



}

#endif