//------------------------------------------------------------------------------
// 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 KEYBOARD_STATE_H_
#define KEYBOARD_STATE_H_

#include <Input/Keyboard/KeyboardKey.h>

namespace Lamp{

class BinaryWriter;
class BinaryReader;

//------------------------------------------------------------------------------
/**
 * キーボードステート
 */
class KeyboardState : public KeyboardKey{
public:
	/**
	 * コンストラクタ
	 */
	KeyboardState(){ clear(); }

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

	/**
	 * クリア
	 */
	virtual void clear(){
		for(int i = 0; i < maxKeyCount; i++){ keys_[i] = false; }
	}

	//--------------------------------------------------------------------------
	/**
	 * キーの設定
	 * @param key 対象キー
	 * @param pressed trueなら押されている
	 */
	virtual void setKeyPressed(Key key, bool pressed){
		Assert((key >= 0) && (key < maxKeyCount));
		keys_[key] = pressed;
	}

	/**
	 * キーが押されているか
	 * @param key 対象キー
	 * @return キーが押されていればtrue
	 */
	virtual bool keyPressed(Key key) const{
		Assert((key >= 0) && (key < maxKeyCount));
		return keys_[key];
	}

	//--------------------------------------------------------------------------
	/**
	 * 文字列への変換
	 * @return 文字列
	 */
	virtual String toString() const{
		String result = "Press ";
		for(int i = 0; i < maxKeyCount; i++){
			Key key = (Key)i;
			if(keyPressed(key)){ result += keyToString(key) + " "; }
		}
		result += "\n";
		return result;
	}

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

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

	//--------------------------------------------------------------------------
private:
	// キーデータ
	bool keys_[maxKeyCount];

};
//------------------------------------------------------------------------------
} // End of namespace Lamp
#endif // End of KEYBOARD_STATE_H_
//------------------------------------------------------------------------------

