Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
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/hash.h" 00033 00034 #include "iutil/evdefs.h" 00035 #include "iutil/event.h" 00036 00037 struct iEvent; 00038 class csInputBinder; 00039 00044 class CS_CRYSTALSPACE_EXPORT csInputDefinition 00045 { 00046 protected: 00047 int containedType; 00048 00049 uint32 modifiersHonored; 00050 csKeyModifiers modifiers; 00051 00052 union 00053 { 00054 struct 00055 { 00056 utf32_char code; 00057 bool isCooked; 00058 } keyboard; 00059 int mouseButton; 00060 int mouseAxis; 00061 int joystickButton; 00062 int joystickAxis; 00063 }; 00064 00065 void Initialize (uint32 honorModifiers, bool useCookedCode); 00066 void InitializeFromEvent (iEvent *ev); 00067 00068 friend class csInputBinder; 00069 00070 public: 00076 csInputDefinition (uint32 honorModifiers = 0, bool useCookedCode = false); 00077 00079 csInputDefinition (const csInputDefinition &other); 00080 00087 csInputDefinition (iEvent *event, 00088 uint32 honorModifiers = 0, bool useCookedCode = false); 00089 00095 csInputDefinition (iEvent *event, uint8 axis); 00096 00103 csInputDefinition (const char *string, 00104 uint32 honorModifiers = 0, bool useCookedCode = false); 00105 00113 csString ToString (bool distinguishModifiers = true) const; 00114 00116 bool IsValid () const; 00117 00119 int GetType () const { return containedType; } 00120 00122 void SetType (int t) { containedType = t; } 00123 00130 bool GetKeyCode (utf32_char &code, bool &isCooked) const 00131 { code = keyboard.code; 00132 isCooked = keyboard.isCooked; 00133 return containedType == csevKeyboard; } 00134 00136 bool SetKeyCode (utf32_char code) 00137 { if (containedType != csevKeyboard) return false; 00138 keyboard.code = code; 00139 return true; } 00140 00146 int GetNumber () const { return mouseButton; } 00147 00153 void SetNumber (int n) { mouseButton = n; } 00154 00156 const csKeyModifiers& GetModifiers () const { return modifiers; } 00157 00159 void SetModifiers (const csKeyModifiers &mods) { modifiers = mods; } 00160 00162 uint32 ComputeHash () const; 00163 00165 int Compare (csInputDefinition const &) const; 00166 00178 static bool ParseKey (const char *iStr, utf32_char *oKeyCode, 00179 utf32_char *oCookedCode, csKeyModifiers *oModifiers); 00180 00194 static bool ParseOther (const char *iStr, int *oType, int *oNumeric, 00195 csKeyModifiers *oModifiers); 00196 00207 static csString GetKeyString (utf32_char code, const csKeyModifiers *mods, 00208 bool distinguishModifiers = true); 00209 00221 static csString GetOtherString (int type, int num, const csKeyModifiers *mods, 00222 bool distinguishModifiers = true); 00223 }; 00224 00229 CS_SPECIALIZE_TEMPLATE 00230 class csComparator<csInputDefinition, csInputDefinition> 00231 { 00232 public: 00233 static int Compare (csInputDefinition const& r1, csInputDefinition const& r2) 00234 { 00235 return r1.Compare (r2); 00236 } 00237 }; 00238 00243 CS_SPECIALIZE_TEMPLATE 00244 class csHashComputer<csInputDefinition> 00245 { 00246 public: 00247 static uint ComputeHash (csInputDefinition const& key) 00248 { 00249 return key.ComputeHash (); 00250 } 00251 }; 00252 00253 #endif // __CS_UTIL_INPUTDEF_H__
Generated for Crystal Space by doxygen 1.4.4