CrystalSpace

Public API Reference

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/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 public:
00047   csRef<iEventNameRegistry> name_reg;
00048 
00049 protected:
00050   csEventID containedName;
00051 
00052   uint32 modifiersHonored;
00053   csKeyModifiers modifiers;
00054   // The (basis-0) identifier for the device from which this event came
00055   uint deviceNumber;
00056   union
00057   {
00058     struct
00059     {
00060       utf32_char code;
00061       bool isCooked;
00062     } keyboard;
00063     int mouseButton;
00064     int mouseAxis;
00065     int joystickButton;
00066     int joystickAxis;
00067   };
00068 
00069   void Initialize (uint32 honorModifiers, bool useCookedCode);
00070   void InitializeFromEvent (iEvent *ev);
00071 
00072   friend class csInputBinder;
00073 
00074 public:
00081   csInputDefinition (iEventNameRegistry* name_reg, 
00082                      uint32 honorModifiers = 0, bool useCookedCode = false);
00083 
00085   csInputDefinition (const csInputDefinition &other);
00086 
00094   csInputDefinition (iEventNameRegistry* name_reg, iEvent *event,
00095                      uint32 honorModifiers = 0, bool useCookedCode = false);
00096 
00103   csInputDefinition (iEventNameRegistry* name_reg, iEvent *event, uint8 axis);
00104 
00120   csInputDefinition (iEventNameRegistry* name_reg, const char *string,
00121                      uint32 honorModifiers = 0, bool useCookedCode = false);
00122 
00130   csString ToString (bool distinguishModifiers = true) const;
00131 
00133   bool IsValid () const;
00134 
00136   csEventID GetName () const { return containedName; }
00137 
00139   void SetName (csEventID n) { containedName = n; }
00140 
00147   bool GetKeyCode (utf32_char &code, bool &isCooked) const
00148   { code = keyboard.code;
00149     isCooked = keyboard.isCooked;
00150     return (containedName == csevKeyboardEvent(name_reg)); }
00151 
00153   bool SetKeyCode (utf32_char code)
00154   { if (containedName != csevKeyboardEvent(name_reg)) return false;
00155     keyboard.code = code;
00156     return true; }
00157 
00163   int GetNumber () const { return mouseButton; }
00164 
00170   void SetNumber (int n) { mouseButton = n; }
00171 
00173   const csKeyModifiers& GetModifiers () const { return modifiers; }
00174 
00176   const uint GetDeviceNumber () const { return deviceNumber; }
00177 
00179   void SetModifiers (const csKeyModifiers &mods) { modifiers = mods; }
00180 
00182   uint32 ComputeHash () const;
00183 
00185   int Compare (csInputDefinition const &) const;
00186 
00199   static bool ParseKey (iEventNameRegistry* reg, 
00200                         const char *iStr, utf32_char *oKeyCode,
00201                         utf32_char *oCookedCode, csKeyModifiers *oModifiers);
00202 
00219   static bool ParseOther (iEventNameRegistry* reg, 
00220                           const char *iStr, csEventID *oType, uint *oDevice,
00221                           int *oNumeric, csKeyModifiers *oModifiers);
00222 
00234   static csString GetKeyString (iEventNameRegistry* reg,
00235                                 utf32_char code, const csKeyModifiers *mods,
00236                                 bool distinguishModifiers = true);
00237 
00252   static csString GetOtherString (iEventNameRegistry* reg,
00253                                   csEventID type, uint device, int num, 
00254                                   const csKeyModifiers *mods,
00255                                   bool distinguishModifiers = true);
00256 };
00257 
00262 CS_SPECIALIZE_TEMPLATE
00263 class csComparator<csInputDefinition, csInputDefinition>
00264 {
00265 public:
00266   static int Compare (csInputDefinition const& r1, csInputDefinition const& r2)
00267   {
00268     return r1.Compare (r2);
00269   }
00270 };
00271 
00276 CS_SPECIALIZE_TEMPLATE
00277 class csHashComputer<csInputDefinition>
00278 {
00279 public:
00280   static uint ComputeHash (csInputDefinition const& key)
00281   {
00282     return key.ComputeHash (); 
00283   }
00284 };
00285 
00286 #endif // __CS_UTIL_INPUTDEF_H__

Generated for Crystal Space by doxygen 1.4.6