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 MOUSE_H_ 00026 #define MOUSE_H_ 00027 00028 #include <Input/Mouse/MouseState.h> 00029 #include <Input/Mouse/MouseDevice.h> 00030 00031 namespace Lamp{ 00032 00033 //------------------------------------------------------------------------------ 00034 /** 00035 * マウス 00036 */ 00037 class Mouse{ 00038 friend class LampInput; 00039 friend class BufferedInput; 00040 public: 00041 //-------------------------------------------------------------------------- 00042 // 定数 00043 //-------------------------------------------------------------------------- 00044 /// 最大ボタン数 00045 static const int maxButtonCount = 8; 00046 00047 //-------------------------------------------------------------------------- 00048 // 軸 00049 //-------------------------------------------------------------------------- 00050 /** 00051 * X軸の取得 00052 * @return X軸 00053 */ 00054 virtual int getXAxis() const{ return state_.getXAxis(); } 00055 00056 /** 00057 * Y軸の取得 00058 * @return Y軸 00059 */ 00060 virtual int getYAxis() const{ return state_.getYAxis(); } 00061 00062 /** 00063 * Z軸の取得 00064 * @return Z軸 00065 */ 00066 virtual int getZAxis() const{ return state_.getZAxis(); } 00067 00068 /** 00069 * Z解像度の取得 00070 * @return Z解像度 00071 */ 00072 int getZResolution() const{ return device_->getZResolution(); } 00073 00074 /** 00075 * 補正済みZ軸の取得 00076 * @return 補正済みZ軸 00077 */ 00078 virtual float getCorrectedZAxis() const{ 00079 return (float)getZAxis() / (float)getZResolution(); 00080 } 00081 00082 //-------------------------------------------------------------------------- 00083 // ボタン 00084 //-------------------------------------------------------------------------- 00085 /** 00086 * ボタン数の取得 00087 * @return ボタン数 00088 */ 00089 virtual int getButtonCount() const{ return device_->getButtonCount(); } 00090 00091 /** 00092 * ボタンが押されているか 00093 * @param id 対象ボタンID 00094 * @return ボタンが押されていればtrue 00095 */ 00096 virtual bool buttonPressed(int id) const{ 00097 return state_.buttonPressed(id); 00098 } 00099 00100 /** 00101 * ボタンが下がった 00102 * @param id ボタンID 00103 * @return ボタンが下がったならばtrue 00104 */ 00105 virtual bool buttonDown(int id) const{ 00106 return (state_.buttonPressed(id) && (!preState_.buttonPressed(id))); 00107 } 00108 00109 /** 00110 * ボタンが上がった 00111 * @param id ボタンID 00112 * @return ボタンが上がったならばtrue 00113 */ 00114 virtual bool buttonUp(int id) const{ 00115 return ((!state_.buttonPressed(id)) && preState_.buttonPressed(id)); 00116 } 00117 00118 //-------------------------------------------------------------------------- 00119 // クリック 00120 //-------------------------------------------------------------------------- 00121 /** 00122 * クリック位置範囲の設定 00123 * @param clickPositionRange クリック位置範囲 00124 */ 00125 virtual void setClickPositionRange(int clickPositionRange){ 00126 clickPositionRange_ = clickPositionRange; 00127 } 00128 00129 /** 00130 * クリック位置範囲の取得 00131 * @return クリック位置範囲 00132 */ 00133 virtual int getClickPositionRange() const{ return clickPositionRange_; } 00134 00135 //-------------------------------------------------------------------------- 00136 /** 00137 * ダブルクリック時間範囲の設定 00138 * @param doubleClickTimeRange ダブルクリック時間範囲 00139 */ 00140 virtual void setDoubleClickTimeRange(int doubleClickTimeRange){ 00141 doubleClickTimeRange_ = doubleClickTimeRange; 00142 } 00143 00144 /** 00145 * ダブルクリック時間範囲の取得 00146 * @return ダブルクリック時間範囲 00147 */ 00148 virtual int getDoubleClickTimeRange() const{ return doubleClickTimeRange_; } 00149 00150 //-------------------------------------------------------------------------- 00151 /** 00152 * クリックされたか 00153 * @param id 対象ボタンID 00154 * @return ボタンがクリックされていればtrue 00155 */ 00156 virtual bool clicked(int id) const{ 00157 Assert(id >= 0); 00158 Assert(id < maxButtonCount); 00159 return clicked_[id]; 00160 } 00161 00162 /** 00163 * ダブルクリックされたか 00164 * @param id 対象ボタンID 00165 * @return ボタンがダブルクリックされていればtrue 00166 */ 00167 virtual bool doubleClicked(int id) const{ 00168 Assert(id >= 0); 00169 Assert(id < maxButtonCount); 00170 return doubleClicked_[id]; 00171 } 00172 00173 /** 00174 * ダブルダウンされたか 00175 * @param id 対象ボタンID 00176 * @return ボタンがダブルダウンされていればtrue 00177 */ 00178 virtual bool doubleDown(int id) const{ 00179 Assert(id >= 0); 00180 Assert(id < maxButtonCount); 00181 return doubleDown_[id]; 00182 } 00183 00184 //-------------------------------------------------------------------------- 00185 /** 00186 * 名前の取得 00187 * @return 名前 00188 */ 00189 virtual String getName() const{ return device_->getProductName(); } 00190 00191 /** 00192 * アタッチされているか 00193 * @return アタッチされていればtrue 00194 */ 00195 virtual bool isAttached() const{ return device_->isAttached(); } 00196 00197 /** 00198 * ポーリングが必要か 00199 * @return ポーリングが必要ならtrue 00200 */ 00201 virtual bool isPolled() const{ return device_->isPolled(); } 00202 00203 /** 00204 * 文字列への変換 00205 * @return 文字列 00206 */ 00207 virtual String toString() const; 00208 00209 /** 00210 * クリア 00211 */ 00212 virtual void clear(){ 00213 state_.clear(); 00214 preState_.clear(); 00215 } 00216 00217 /** 00218 * 協調レベルの設定 00219 * @param exclusive 排他モードならtrue 00220 * @param foreground フォアグラウンドモードならtrue 00221 * @return 成功すればtrue 00222 */ 00223 virtual bool setCooperativeLevel(bool exclusive, bool foreground){ 00224 return device_->setCooperativeLevel(exclusive, foreground); 00225 } 00226 00227 /** 00228 * 排他モードか 00229 * @return 排他モードならtrue 00230 */ 00231 virtual bool isExclusive() const{ return device_->isExclusive(); } 00232 00233 /** 00234 * フォアグラウンドモードか 00235 * @return フォアグラウンドモードならtrue、バックグラウンドモードならfalse 00236 */ 00237 virtual bool isForeground() const{ return device_->isForeground(); } 00238 00239 protected: 00240 //-------------------------------------------------------------------------- 00241 /** 00242 * コンストラクタ 00243 * @param device デバイス 00244 */ 00245 Mouse(MouseDevice* device); 00246 00247 /** 00248 * デストラクタ 00249 */ 00250 virtual ~Mouse(); 00251 00252 /** 00253 * 次のステート設定 00254 * @param state 次のステート 00255 */ 00256 virtual void setNextState(const MouseState& state); 00257 00258 /** 00259 * ステートの取得 00260 * @return ステート 00261 */ 00262 virtual const MouseState& getState(){ return state_; } 00263 00264 /** 00265 * クリックステートクリア 00266 */ 00267 virtual void clickStateClear(); 00268 00269 private: 00270 //-------------------------------------------------------------------------- 00271 // デバイス 00272 MouseDevice* device_; 00273 // ステート 00274 MouseState state_; 00275 // 前回のステート 00276 MouseState preState_; 00277 // 押し下げオフセット 00278 Point2i downOffset_[maxButtonCount]; 00279 // 押し下げ時間 00280 int downTime_[maxButtonCount]; 00281 // 前回の押し下げオフセット 00282 Point2i preDownOffset_[maxButtonCount]; 00283 // 前回の押し下げ時間 00284 int preDownTime_[maxButtonCount]; 00285 // クリック位置範囲 00286 int clickPositionRange_; 00287 // ダブルクリック時間範囲 00288 int doubleClickTimeRange_; 00289 // クリック 00290 bool clicked_[maxButtonCount]; 00291 // ダブルクリック 00292 bool doubleClicked_[maxButtonCount]; 00293 // ダブルダウン 00294 bool doubleDown_[maxButtonCount]; 00295 }; 00296 00297 //------------------------------------------------------------------------------ 00298 } // End of namespace Lamp 00299 #endif // End of MOUSE_H_ 00300 //------------------------------------------------------------------------------