//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * マウスステートヘッダ
 * @author Junpee
 */

#ifndef MOUSE_STATE_H_
#define MOUSE_STATE_H_

namespace Lamp{

class BinaryWriter;
class BinaryReader;

//------------------------------------------------------------------------------
/**
 * マウスステート
 */
class MouseState{
friend class MouseDevice;
public:
	/// 最大ボタン数
	static const int maxButtonCount = 8;

	//--------------------------------------------------------------------------
	/**
	 * コンストラクタ
	 */
	MouseState(){ clear(); }

	/**
	 * デストラクタ
	 */
	virtual ~MouseState(){}

	/**
	 * クリア
	 */
	virtual void clear(){
		xAxis_ = yAxis_ = zAxis_ = 0;
		for(int i = 0; i < maxButtonCount; i++){ buttons_[i] = false; }
	}

	//--------------------------------------------------------------------------
	/**
	 * X軸の設定
	 * @param xAxis X軸
	 */
	virtual void setXAxis(int xAxis){ xAxis_ = xAxis; }

	/**
	 * X軸の取得
	 * @return X軸
	 */
	virtual int getXAxis() const{ return xAxis_; }

	/**
	 * Y軸の設定
	 * @param yAxis Y軸
	 */
	virtual void setYAxis(int yAxis){ yAxis_ = yAxis; }

	/**
	 * Y軸の取得
	 * @return Y軸
	 */
	virtual int getYAxis() const{ return yAxis_; }

	/**
	 * Z軸の設定
	 * @param zAxis Z軸
	 */
	virtual void setZAxis(int zAxis){ zAxis_ = zAxis; }

	/**
	 * Z軸の取得
	 * @return Z軸
	 */
	virtual int getZAxis() const{ return zAxis_; }

	//--------------------------------------------------------------------------
	/**
	 * ボタンの設定
	 * @param id 対象ボタンID
	 * @param pressed trueなら押されている
	 */
	virtual void setButtonPressed(int id, bool pressed){
		Assert((id >= 0) && (id < maxButtonCount));
		buttons_[id] = pressed;
	}

	/**
	 * ボタンが押されているか
	 * @param id 対象ボタンID
	 * @return ボタンが押されていればtrue
	 */
	virtual bool buttonPressed(int id) const{
		Assert((id >= 0) && (id < maxButtonCount));
		return buttons_[id];
	}

	//--------------------------------------------------------------------------
	/**
	 * 文字列への変換
	 * @return 文字列
	 */
	virtual String toString() const{
		String result;
		result.format("( X = %4d , Y = %4d , Z = %4d )\n"
			"Press       %d %d %d %d %d %d %d %d\n",
			getXAxis(), getYAxis(), getZAxis(),
			buttonPressed(0), buttonPressed(1), buttonPressed(2),
			buttonPressed(3), buttonPressed(4), buttonPressed(5), 
			buttonPressed(6), buttonPressed(7));
		return result;
	}

	//--------------------------------------------------------------------------
	/**
	 * バイナリ書き出し
	 * @param binaryWriter バイナリライタ
	 */
	virtual void writeBinary(BinaryWriter* binaryWriter) const;

	/**
	 * バイナリ読み込み
	 * @param binaryReader バイナリリーダ
	 */
	virtual void readBinary(BinaryReader* binaryReader);

	//--------------------------------------------------------------------------
private:
	// X軸
	int xAxis_;
	// Y軸
	int yAxis_;
	// Z軸
	int zAxis_;
	// ボタンデータ
	bool buttons_[maxButtonCount];
};

//------------------------------------------------------------------------------
} // End of namespace Lamp
#endif // End of _H_
//------------------------------------------------------------------------------

