CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

binder.h

00001 /*
00002     Copyright (C) 2003, 04 by Mathew Sutcliffe <oktal@gmx.co.uk>
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 
00022 #include "csextern.h"
00023 #include "iutil/binder.h"
00024 #include "iutil/event.h"
00025 #include "iutil/eventh.h"
00026 #include "iutil/evdefs.h"
00027 #include "csutil/inputdef.h"
00028 #include "csutil/array.h"
00029 #include "csutil/hash.h"
00030 
00035 class CS_CSUTIL_EXPORT csInputBinder : public iInputBinder
00036 {
00037   struct AxisCmd
00038   {
00039     unsigned cmd;
00040     int val, sens;
00041     bool wrap;
00042     AxisCmd (unsigned cmd0, int sens0)
00043     : cmd (cmd0), val (0), sens (sens0) {}
00044   };
00045   typedef csHash<AxisCmd *, csInputDefinition, csInputDefinition> AxisHash;
00046   AxisHash axisHash;
00047   csArray<AxisCmd *> axisArray;
00048 
00049   struct BtnCmd
00050   {
00051     unsigned cmd;
00052     bool down, toggle;
00053     BtnCmd (unsigned cmd0, bool toggle0)
00054     : cmd (cmd0), down (false), toggle (toggle0) {}
00055   };
00056   typedef csHash<BtnCmd *, csInputDefinition, csInputDefinition> BtnHash;
00057   BtnHash btnHash;
00058   csArray<BtnCmd *> btnArray;
00059 
00060 protected:
00061   bool HandleEvent (iEvent&);
00062 
00063 public:
00064   SCF_DECLARE_IBASE;
00065 
00070   csInputBinder (iBase *parent = 0, int btnSize = 127, int axisSize = 13);
00071   virtual ~csInputBinder ();
00072 
00073   struct CS_CSUTIL_EXPORT eiEventHandler : public iEventHandler
00074   {
00075     SCF_DECLARE_EMBEDDED_IBASE (csInputBinder);
00076     bool HandleEvent (iEvent &ev) { return scfParent->HandleEvent (ev); }
00077   } scfiEventHandler;
00078   friend struct eiEventHandler;
00079 
00080   virtual iEventHandler* QueryHandler () { return &scfiEventHandler; }
00081 
00082   virtual int Axis (unsigned cmd);
00083   virtual bool Button (unsigned cmd);
00084 
00085   virtual void BindAxis (const csInputDefinition &, unsigned cmd, int sens);
00086   virtual void BindButton (const csInputDefinition &, unsigned cmd, bool tgl);
00087 
00088   virtual bool UnbindAxis (unsigned cmd);
00089   virtual bool UnbindButton (unsigned cmd);
00090   virtual void UnbindAll ();
00091 
00092   virtual void LoadConfig (iConfigFile *, const char *subsection);
00093   virtual void SaveConfig (iConfigFile *, const char *subsection);
00094 };
00095 
00096 #endif // __CS_UTIL_BINDER_H__

Generated for Crystal Space by doxygen 1.3.9.1