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_H_ 00026 #define KEYBOARD_H_ 00027 00028 #include <Input/Keyboard/KeyboardKey.h> 00029 #include <Input/Keyboard/KeyboardState.h> 00030 #include <Input/Keyboard/KeyboardDevice.h> 00031 00032 namespace Lamp{ 00033 00034 //------------------------------------------------------------------------------ 00035 /** 00036 * キーボード 00037 */ 00038 class Keyboard : public KeyboardKey{ 00039 friend class LampInput; 00040 friend class BufferedInput; 00041 public: 00042 //-------------------------------------------------------------------------- 00043 /** 00044 * キー数の取得 00045 * @return キー数 00046 */ 00047 virtual int getKeyCount() const{ return device_->getButtonCount(); } 00048 00049 /** 00050 * キーが押されているか 00051 * @param key 対象キー 00052 * @return キーが押されていればtrue 00053 */ 00054 virtual bool pressed(Key key) const{ return state_.keyPressed(key); } 00055 00056 /** 00057 * キーが下がった 00058 * @param key キー 00059 * @return キーが下がったならばtrue 00060 */ 00061 virtual bool down(Key key) const{ 00062 return (state_.keyPressed(key) && (!preState_.keyPressed(key))); 00063 } 00064 00065 /** 00066 * キーが上がった 00067 * @param key キー 00068 * @return キーが上がったならばtrue 00069 */ 00070 virtual bool up(Key key) const{ 00071 return ((!state_.keyPressed(key)) && preState_.keyPressed(key)); 00072 } 00073 00074 //-------------------------------------------------------------------------- 00075 /** 00076 * 名前の取得 00077 * @return 名前 00078 */ 00079 virtual String getName() const{ return device_->getProductName(); } 00080 00081 /** 00082 * アタッチされているか 00083 * @return アタッチされていればtrue 00084 */ 00085 virtual bool isAttached() const{ return device_->isAttached(); } 00086 00087 /** 00088 * ポーリングが必要か 00089 * @return ポーリングが必要ならtrue 00090 */ 00091 virtual bool isPolled() const{ return device_->isPolled(); } 00092 00093 /** 00094 * 文字列への変換 00095 * @return 文字列 00096 */ 00097 virtual String toString() const; 00098 00099 /** 00100 * クリア 00101 */ 00102 virtual void clear(){ 00103 state_.clear(); 00104 preState_.clear(); 00105 } 00106 00107 /** 00108 * 協調レベルの設定 00109 * @param exclusive 排他モードならtrue 00110 * @param foreground フォアグラウンドモードならtrue 00111 * @return 成功すればtrue 00112 */ 00113 virtual bool setCooperativeLevel(bool exclusive, bool foreground){ 00114 return device_->setCooperativeLevel(exclusive, foreground); 00115 } 00116 00117 /** 00118 * 排他モードか 00119 * @return 排他モードならtrue 00120 */ 00121 virtual bool isExclusive() const{ return device_->isExclusive(); } 00122 00123 /** 00124 * フォアグラウンドモードか 00125 * @return フォアグラウンドモードならtrue、バックグラウンドモードならfalse 00126 */ 00127 virtual bool isForeground() const{ return device_->isForeground(); } 00128 00129 protected: 00130 //-------------------------------------------------------------------------- 00131 /** 00132 * コンストラクタ 00133 */ 00134 Keyboard(KeyboardDevice* device); 00135 00136 /** 00137 * デストラクタ 00138 */ 00139 virtual ~Keyboard(); 00140 00141 /** 00142 * 次のステート設定 00143 * @param state 次のステート 00144 */ 00145 virtual void setNextState(const KeyboardState& state); 00146 00147 /** 00148 * ステートの取得 00149 * @return ステート 00150 */ 00151 virtual const KeyboardState& getState(){ return state_; } 00152 00153 private: 00154 //-------------------------------------------------------------------------- 00155 // デバイス 00156 KeyboardDevice* device_; 00157 // ステート 00158 KeyboardState state_; 00159 // 前回のステート 00160 KeyboardState preState_; 00161 }; 00162 00163 //------------------------------------------------------------------------------ 00164 } // End of namespace Lamp 00165 #endif // End of KEYBOARD_H_ 00166 //------------------------------------------------------------------------------