Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

KeyboardState.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * キーボードステートヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef KEYBOARD_STATE_H_
00026 #define KEYBOARD_STATE_H_
00027 
00028 #include <Input/Keyboard/KeyboardKey.h>
00029 
00030 namespace Lamp{
00031 
00032 class BinaryWriter;
00033 class BinaryReader;
00034 
00035 //------------------------------------------------------------------------------
00036 /**
00037  * キーボードステート
00038  */
00039 class KeyboardState : public KeyboardKey{
00040 public:
00041     /**
00042      * コンストラクタ
00043      */
00044     KeyboardState(){ clear(); }
00045 
00046     /**
00047      * デストラクタ
00048      */
00049     virtual ~KeyboardState(){}
00050 
00051     /**
00052      * クリア
00053      */
00054     virtual void clear(){
00055         for(int i = 0; i < maxKeyCount; i++){ keys_[i] = false; }
00056     }
00057 
00058     //--------------------------------------------------------------------------
00059     /**
00060      * キーの設定
00061      * @param key 対象キー
00062      * @param pressed trueなら押されている
00063      */
00064     virtual void setKeyPressed(Key key, bool pressed){
00065         Assert((key >= 0) && (key < maxKeyCount));
00066         keys_[key] = pressed;
00067     }
00068 
00069     /**
00070      * キーが押されているか
00071      * @param key 対象キー
00072      * @return キーが押されていればtrue
00073      */
00074     virtual bool keyPressed(Key key) const{
00075         Assert((key >= 0) && (key < maxKeyCount));
00076         return keys_[key];
00077     }
00078 
00079     //--------------------------------------------------------------------------
00080     /**
00081      * 文字列への変換
00082      * @return 文字列
00083      */
00084     virtual String toString() const{
00085         String result = "Press ";
00086         for(int i = 0; i < maxKeyCount; i++){
00087             Key key = (Key)i;
00088             if(keyPressed(key)){ result += keyToString(key) + " "; }
00089         }
00090         result += "\n";
00091         return result;
00092     }
00093 
00094     //--------------------------------------------------------------------------
00095     /**
00096      * バイナリ書き出し
00097      * @param binaryWriter バイナリライタ
00098      */
00099     virtual void writeBinary(BinaryWriter* binaryWriter) const;
00100 
00101     /**
00102      * バイナリ読み込み
00103      * @param binaryReader バイナリリーダ
00104      */
00105     virtual void readBinary(BinaryReader* binaryReader);
00106 
00107     //--------------------------------------------------------------------------
00108 private:
00109     // キーデータ
00110     bool keys_[maxKeyCount];
00111 
00112 };
00113 //------------------------------------------------------------------------------
00114 } // End of namespace Lamp
00115 #endif // End of KEYBOARD_STATE_H_
00116 //------------------------------------------------------------------------------
00117 

Generated on Wed Mar 16 10:29:31 2005 for Lamp by doxygen 1.3.2