csutil/inputdef.h
Go to the documentation of this file.00001 /* 00002 Crystal Space input library 00003 Copyright (C) 2000 by Andrew Zabolotny <bit@eltech.ru> 00004 Copyright (C) 2002, 04 by Mathew Sutcliffe <oktal@gmx.co.uk> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public 00017 License along with this library; if not, write to the Free 00018 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifndef __CS_UTIL_INPUTDEF_H__ 00022 #define __CS_UTIL_INPUTDEF_H__ 00023 00028 #include "csextern.h" 00029 00030 #include "csutil/csstring.h" 00031 #include "csutil/comparator.h" 00032 #include "csutil/eventnames.h" 00033 #include "csutil/hash.h" 00034 00035 #include "iutil/evdefs.h" 00036 #include "iutil/event.h" 00037 00038 struct iEvent; 00039 class csInputBinder; 00040 00232 class CS_CRYSTALSPACE_EXPORT csInputDefinition 00233 { 00234 public: 00235 csRef<iEventNameRegistry> name_reg; 00236 00237 protected: 00238 csEventID containedName; 00239 00240 uint32 modifiersHonored; 00241 csKeyModifiers modifiers; 00242 // The (basis-0) identifier for the device from which this event came 00243 uint deviceNumber; 00244 union 00245 { 00246 struct 00247 { 00248 utf32_char code; 00249 bool isCooked; 00250 } keyboard; 00251 int mouseButton; 00252 int mouseAxis; 00253 int joystickButton; 00254 int joystickAxis; 00255 }; 00256 00257 void Initialize (uint32 honorModifiers, bool useCookedCode); 00258 void InitializeFromEvent (iEvent *ev); 00259 00260 friend class csInputBinder; 00261 00262 public: 00269 csInputDefinition (iEventNameRegistry* name_reg, 00270 uint32 honorModifiers = 0, bool useCookedCode = false); 00271 00273 csInputDefinition (const csInputDefinition &other); 00274 00282 csInputDefinition (iEventNameRegistry* name_reg, iEvent *event, 00283 uint32 honorModifiers = 0, bool useCookedCode = false); 00284 00291 csInputDefinition (iEventNameRegistry* name_reg, iEvent *event, uint8 axis); 00292 00301 csInputDefinition (iEventNameRegistry* name_reg, const char *string, 00302 uint32 honorModifiers = 0, bool useCookedCode = false); 00303 00311 csString ToString (bool distinguishModifiers = true) const; 00312 00314 bool IsValid () const; 00315 00317 csEventID GetName () const { return containedName; } 00318 00320 void SetName (csEventID n) { containedName = n; } 00321 00328 bool GetKeyCode (utf32_char &code, bool &isCooked) const 00329 { code = keyboard.code; 00330 isCooked = keyboard.isCooked; 00331 return (containedName == csevKeyboardEvent(name_reg)); } 00332 00334 bool SetKeyCode (utf32_char code) 00335 { if (containedName != csevKeyboardEvent(name_reg)) return false; 00336 keyboard.code = code; 00337 return true; } 00338 00344 int GetNumber () const { return mouseButton; } 00345 00351 void SetNumber (int n) { mouseButton = n; } 00352 00354 const csKeyModifiers& GetModifiers () const { return modifiers; } 00355 00357 const uint GetDeviceNumber () const { return deviceNumber; } 00358 00360 void SetModifiers (const csKeyModifiers &mods) { modifiers = mods; } 00361 00363 uint32 ComputeHash () const; 00364 00366 int Compare (csInputDefinition const &) const; 00367 00380 static bool ParseKey (iEventNameRegistry* reg, 00381 const char *iStr, utf32_char *oKeyCode, 00382 utf32_char *oCookedCode, csKeyModifiers *oModifiers); 00383 00400 static bool ParseOther (iEventNameRegistry* reg, 00401 const char *iStr, csEventID *oType, uint *oDevice, 00402 int *oNumeric, csKeyModifiers *oModifiers); 00403 00415 static csString GetKeyString (iEventNameRegistry* reg, 00416 utf32_char code, const csKeyModifiers *mods, 00417 bool distinguishModifiers = true); 00418 00433 static csString GetOtherString (iEventNameRegistry* reg, 00434 csEventID type, uint device, int num, 00435 const csKeyModifiers *mods, 00436 bool distinguishModifiers = true); 00437 }; 00438 00443 template<> 00444 class csComparator<csInputDefinition, csInputDefinition> 00445 { 00446 public: 00447 static int Compare (csInputDefinition const& r1, csInputDefinition const& r2) 00448 { 00449 return r1.Compare (r2); 00450 } 00451 }; 00452 00457 template<> 00458 class csHashComputer<csInputDefinition> 00459 { 00460 public: 00461 static uint ComputeHash (csInputDefinition const& key) 00462 { 00463 return key.ComputeHash (); 00464 } 00465 }; 00466 00467 #endif // __CS_UTIL_INPUTDEF_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1