csutil/binder.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003, 04 by Mathew Sutcliffe <[email protected]> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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__
Generated for Crystal Space by doxygen 1.4.7