csutil/inputdef.h
Go to the documentation of this file.00001 /* 00002 Crystal Space input library 00003 Copyright (C) 2000 by Andrew Zabolotny <[email protected]> 00004 Copyright (C) 2002, 04 by Mathew Sutcliffe <[email protected]> 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 00045 class CS_CRYSTALSPACE_EXPORT csInputDefinition 00046 { 00047 public: 00048 csRef<iEventNameRegistry> name_reg; 00049 00050 protected: 00051 csEventID containedName; 00052 00053 uint32 modifiersHonored; 00054 csKeyModifiers modifiers; 00055 // The (basis-0) identifier for the device from which this event came 00056 uint deviceNumber; 00057 union 00058 { 00059 struct 00060 { 00061 utf32_char code; 00062 bool isCooked; 00063 } keyboard; 00064 int mouseButton; 00065 int mouseAxis; 00066 int joystickButton; 00067 int joystickAxis; 00068 }; 00069 00070 void Initialize (uint32 honorModifiers, bool useCookedCode); 00071 void InitializeFromEvent (iEvent *ev); 00072 00073 friend class csInputBinder; 00074 00075 public: 00082 csInputDefinition (iEventNameRegistry* name_reg, 00083 uint32 honorModifiers = 0, bool useCookedCode = false); 00084 00086 csInputDefinition (const csInputDefinition &other); 00087 00095 csInputDefinition (iEventNameRegistry* name_reg, iEvent *event, 00096 uint32 honorModifiers = 0, bool useCookedCode = false); 00097 00104 csInputDefinition (iEventNameRegistry* name_reg, iEvent *event, uint8 axis); 00105 00121 csInputDefinition (iEventNameRegistry* name_reg, const char *string, 00122 uint32 honorModifiers = 0, bool useCookedCode = false); 00123 00131 csString ToString (bool distinguishModifiers = true) const; 00132 00134 bool IsValid () const; 00135 00137 csEventID GetName () const { return containedName; } 00138 00140 void SetName (csEventID n) { containedName = n; } 00141 00148 bool GetKeyCode (utf32_char &code, bool &isCooked) const 00149 { code = keyboard.code; 00150 isCooked = keyboard.isCooked; 00151 return (containedName == csevKeyboardEvent(name_reg)); } 00152 00154 bool SetKeyCode (utf32_char code) 00155 { if (containedName != csevKeyboardEvent(name_reg)) return false; 00156 keyboard.code = code; 00157 return true; } 00158 00164 int GetNumber () const { return mouseButton; } 00165 00171 void SetNumber (int n) { mouseButton = n; } 00172 00174 const csKeyModifiers& GetModifiers () const { return modifiers; } 00175 00177 const uint GetDeviceNumber () const { return deviceNumber; } 00178 00180 void SetModifiers (const csKeyModifiers &mods) { modifiers = mods; } 00181 00183 uint32 ComputeHash () const; 00184 00186 int Compare (csInputDefinition const &) const; 00187 00200 static bool ParseKey (iEventNameRegistry* reg, 00201 const char *iStr, utf32_char *oKeyCode, 00202 utf32_char *oCookedCode, csKeyModifiers *oModifiers); 00203 00220 static bool ParseOther (iEventNameRegistry* reg, 00221 const char *iStr, csEventID *oType, uint *oDevice, 00222 int *oNumeric, csKeyModifiers *oModifiers); 00223 00235 static csString GetKeyString (iEventNameRegistry* reg, 00236 utf32_char code, const csKeyModifiers *mods, 00237 bool distinguishModifiers = true); 00238 00253 static csString GetOtherString (iEventNameRegistry* reg, 00254 csEventID type, uint device, int num, 00255 const csKeyModifiers *mods, 00256 bool distinguishModifiers = true); 00257 }; 00258 00263 template<> 00264 class csComparator<csInputDefinition, csInputDefinition> 00265 { 00266 public: 00267 static int Compare (csInputDefinition const& r1, csInputDefinition const& r2) 00268 { 00269 return r1.Compare (r2); 00270 } 00271 }; 00272 00277 template<> 00278 class csHashComputer<csInputDefinition> 00279 { 00280 public: 00281 static uint ComputeHash (csInputDefinition const& key) 00282 { 00283 return key.ComputeHash (); 00284 } 00285 }; 00286 00287 #endif // __CS_UTIL_INPUTDEF_H__
Generated for Crystal Space by doxygen 1.4.7