CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

csinput.h

00001 /*
00002     Crystal Space input library
00003     Copyright (C) 1998,2000 by Jorrit Tyberghein
00004     Written by Andrew Zabolotny <bit@eltech.ru>
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_CSINPUT_H__
00022 #define __CS_CSINPUT_H__
00023 
00029 #include "csutil/scf.h"
00030 #include "csutil/bitset.h"
00031 #include "iutil/csinput.h"
00032 #include "iutil/eventh.h"
00033 #include "iutil/comp.h"
00034 struct iEvent;
00035 struct iEventQueue;
00036 struct iObjectRegistry;
00037 
00041 class csInputDriver
00042 {
00043 private:
00044   bool Registered;
00045 protected:
00046   iObjectRegistry* Registry;
00047   iEventHandler* Listener;
00048   csInputDriver(iObjectRegistry*);
00049   virtual ~csInputDriver();
00050   csPtr<iEventQueue> GetEventQueue();
00051   virtual void LostFocus() = 0;
00052   virtual void Post(iEvent*);
00053   virtual bool HandleEvent(iEvent&);
00054   friend struct FocusListener;
00055   void StartListening();
00056   void StopListening();
00057 };
00058 
00064 class csKeyboardDriver : public csInputDriver, public iKeyboardDriver
00065 {
00066 protected:
00068   csBitSet KeyState;
00069 
00074   virtual void SetKeyState (int iKey, bool iDown);
00075 
00076 public:
00077   SCF_DECLARE_IBASE;
00078 
00080   csKeyboardDriver (iObjectRegistry*);
00082   virtual ~csKeyboardDriver ();
00083 
00085   virtual void Reset ();
00086 
00088   virtual void DoKey (int iKey, int iChar, bool iDown);
00089 
00095   virtual bool GetKeyState (int iKey);
00096 
00098   virtual void LostFocus() { Reset(); }
00099 
00101   struct eiEventHandler : public iEventHandler
00102   {
00103     SCF_DECLARE_EMBEDDED_IBASE(csKeyboardDriver);
00104     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00105   } scfiEventHandler;
00106   friend struct eiEventHandler;
00107 };
00108 
00114 class csMouseDriver : public csInputDriver, public iMouseDriver
00115 {
00116 private:
00117   // Generic keyboard driver (for checking modifier key states).
00118   csRef<iKeyboardDriver> Keyboard;
00119 
00120 protected:
00122   csTicks LastClickTime;
00124   int LastClickButton;
00126   int LastClickX, LastClickY;
00128   int LastX, LastY;
00130   bool Button [CS_MAX_MOUSE_BUTTONS];
00132   csTicks DoubleClickTime;
00134   size_t DoubleClickDist;
00136   iKeyboardDriver* GetKeyboardDriver();
00137 
00138 public:
00139   SCF_DECLARE_IBASE;
00140 
00142   csMouseDriver (iObjectRegistry*);
00144   virtual ~csMouseDriver ();
00145 
00147   virtual void SetDoubleClickTime (int iTime, size_t iDist);
00148 
00150   virtual void Reset ();
00151 
00153   virtual int GetLastX () { return LastX; }
00155   virtual int GetLastY () { return LastY; }
00157   virtual bool GetLastButton (int button)
00158   {
00159     return (button > 0 && button <= CS_MAX_MOUSE_BUTTONS) ?
00160       Button [button - 1] : false;
00161   }
00162 
00164   virtual void DoButton (int button, bool down, int x, int y);
00166   virtual void DoMotion (int x, int y);
00167 
00169   virtual void LostFocus() { Reset(); }
00170 
00172   struct eiEventHandler : public iEventHandler
00173   {
00174     SCF_DECLARE_EMBEDDED_IBASE(csMouseDriver);
00175     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00176   } scfiEventHandler;
00177   friend struct eiEventHandler;
00178 };
00179 
00185 class csJoystickDriver : public csInputDriver, public iJoystickDriver
00186 {
00187 private:
00188   // Generic keyboard driver (for checking modifier key states).
00189   csRef<iKeyboardDriver> Keyboard;
00190 protected:
00192   bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS];
00194   int LastX [CS_MAX_JOYSTICK_COUNT], LastY [CS_MAX_JOYSTICK_COUNT];
00196   iKeyboardDriver* GetKeyboardDriver();
00197 
00198 public:
00199   SCF_DECLARE_IBASE;
00200 
00202   csJoystickDriver (iObjectRegistry*);
00204   virtual ~csJoystickDriver ();
00205 
00207   virtual void Reset ();
00208 
00210   virtual int GetLastX (int number) { return LastX [number]; }
00212   virtual int GetLastY (int number) { return LastY [number]; }
00214   virtual bool GetLastButton (int number, int button)
00215   {
00216     return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT
00217          && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ?
00218             Button [number - 1] [button - 1] : false;
00219   }
00220 
00222   virtual void DoButton (int number, int button, bool down, int x, int y);
00224   virtual void DoMotion (int number, int x, int y);
00225 
00227   virtual void LostFocus() { Reset(); }
00228 
00230   struct eiEventHandler : public iEventHandler
00231   {
00232     SCF_DECLARE_EMBEDDED_IBASE (csJoystickDriver);
00233     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00234   } scfiEventHandler;
00235   friend struct eiEventHandler;
00236 };
00237 
00238 #endif // __CS_CSINPUT_H__

Generated for Crystal Space by doxygen 1.2.14