Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_UTIL_BINDER_H__
00020 #define __CS_UTIL_BINDER_H__
00021
00026 #include "csextern.h"
00027 #include "csutil/array.h"
00028 #include "csutil/hash.h"
00029 #include "csutil/inputdef.h"
00030 #include "csutil/scf_implementation.h"
00031 #include "iutil/binder.h"
00032 #include "iutil/evdefs.h"
00033 #include "iutil/event.h"
00034 #include "iutil/eventh.h"
00035
00057 class CS_CRYSTALSPACE_EXPORT csInputBinder :
00058 public scfImplementation2<csInputBinder, iInputBinder, iEventHandler>
00059 {
00060 CS_EVENTHANDLER_NAMES("crystalspace.inputbinder")
00061 CS_EVENTHANDLER_NIL_CONSTRAINTS
00062
00063 iObjectRegistry *object_reg;
00064 csRef<iEventNameRegistry> name_reg;
00065 struct AxisCmd
00066 {
00067 unsigned cmd;
00068 int val, sens;
00069 bool wrap;
00070 AxisCmd (unsigned cmd0, int sens0)
00071 : cmd (cmd0), val (0), sens (sens0) {}
00072 };
00073 typedef csHash<AxisCmd *, csInputDefinition> AxisHash;
00074 AxisHash axisHash;
00075 csArray<AxisCmd *> axisArray;
00076
00077 struct BtnCmd
00078 {
00079 unsigned cmd;
00080 bool down, toggle;
00081 BtnCmd (unsigned cmd0, bool toggle0)
00082 : cmd (cmd0), down (false), toggle (toggle0) {}
00083 };
00084 typedef csHash<BtnCmd *, csInputDefinition> BtnHash;
00085 BtnHash btnHash;
00086 csArray<BtnCmd *> btnArray;
00087
00088 protected:
00089 bool HandleEvent (iEvent&);
00090
00091 public:
00092
00097 csInputBinder (iObjectRegistry *, iBase *parent = 0, int btnSize = 127, int axisSize = 13);
00098 virtual ~csInputBinder ();
00099
00100 virtual iEventHandler* QueryHandler () { return this; }
00101
00102 virtual int Axis (unsigned cmd);
00103 virtual bool Button (unsigned cmd);
00104
00105 virtual void BindButton (csInputDefinition const& def, unsigned int cmd,
00106 bool toggle = false);
00107 virtual void BindAxis (csInputDefinition const& def, unsigned int cmd,
00108 int sensitivity = 1);
00109
00110 virtual bool UnbindAxis (unsigned cmd);
00111 virtual bool UnbindButton (unsigned cmd);
00112 virtual void UnbindAll ();
00113
00114 virtual void LoadConfig (iConfigFile *, const char *subsection);
00115 virtual void SaveConfig (iConfigFile *, const char *subsection);
00116 };
00117
00118 #endif // __CS_UTIL_BINDER_H__