CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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 #include "iutil/evdefs.h"
00030 #include "iutil/event.h"
00031 #include "csstring.h"
00032 
00033 struct iEvent;
00034 class csInputBinder;
00035 
00040 class CS_CSUTIL_EXPORT csInputDefinition
00041 {
00042 protected:
00043   int containedType;
00044 
00045   uint32 modifiersHonored;
00046   csKeyModifiers modifiers;
00047 
00048   union
00049   {
00050     struct
00051     {
00052       utf32_char code;
00053       bool isCooked;
00054     } keyboard;
00055     int mouseButton;
00056     int mouseAxis;
00057     int joystickButton;
00058     int joystickAxis;
00059   };
00060 
00061   void Initialize (uint32 honorModifiers, bool useCookedCode);
00062   void InitializeFromEvent (iEvent *ev);
00063 
00064   friend class csInputBinder;
00065 
00066 public:
00072   csInputDefinition (uint32 honorModifiers = 0, bool useCookedCode = false);
00073 
00075   csInputDefinition (const csInputDefinition &other);
00076 
00083   csInputDefinition (iEvent *event,
00084                      uint32 honorModifiers = 0, bool useCookedCode = false);
00085 
00091   csInputDefinition (iEvent *event, int axis);
00092 
00099   csInputDefinition (const char *string,
00100                      uint32 honorModifiers = 0, bool useCookedCode = false);
00101 
00109   csString ToString (bool distinguishModifiers = true) const;
00110 
00112   bool IsValid () const;
00113 
00115   int GetType () const { return containedType; }
00116 
00118   void SetType (int t) { containedType = t; }
00119 
00126   bool GetKeyCode (utf32_char &code, bool &isCooked) const
00127     { code = keyboard.code;
00128       isCooked = keyboard.isCooked;
00129       return containedType == csevKeyboard; }
00130 
00132   bool SetKeyCode (utf32_char code)
00133     { if (containedType != csevKeyboard) return false;
00134       keyboard.code = code;
00135       return true; }
00136 
00142   int GetNumber () const { return mouseButton; }
00143 
00149   void SetNumber (int n) { mouseButton = n; }
00150 
00152   const csKeyModifiers& GetModifiers () const { return modifiers; }
00153 
00155   void SetModifiers (const csKeyModifiers &mods) { modifiers = mods; }
00156 
00158   uint32 ComputeHash () const;
00159 
00161   bool Compare (csInputDefinition const &) const;
00162 
00174   static bool ParseKey (const char *iStr, utf32_char *oKeyCode,
00175     utf32_char *oCookedCode, csKeyModifiers *oModifiers);
00176 
00190   static bool ParseOther (const char *iStr, int *oType, int *oNumeric,
00191     csKeyModifiers *oModifiers);
00192 
00203   static csString GetKeyString (utf32_char code, const csKeyModifiers *mods,
00204     bool distinguishModifiers = true);
00205 
00217   static csString GetOtherString (int type, int num, const csKeyModifiers *mods,
00218     bool distinguishModifiers = true);
00219 
00221   static unsigned int ComputeHash (const csInputDefinition &key)
00222   { return key.ComputeHash (); }
00223 
00225   static bool CompareKeys (const csInputDefinition &key1,
00226                            const csInputDefinition &key2)
00227   { return key1.Compare (key2); }
00228 };
00229 
00230 #endif // __CS_UTIL_INPUTDEF_H__

Generated for Crystal Space by doxygen 1.3.9.1