Main Page   Class Hierarchy   Compound List   File List   Compound 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 
00031 #include "csutil/scf.h"
00032 #include "csutil/bitset.h"
00033 #include "iutil/csinput.h"
00034 #include "iutil/eventh.h"
00035 #include "iutil/comp.h"
00036 struct iEvent;
00037 struct iEventQueue;
00038 struct iObjectRegistry;
00039 
00043 class csInputDriver
00044 {
00045 protected:
00046   iObjectRegistry* Registry;
00047   csInputDriver(iObjectRegistry*);
00048   virtual ~csInputDriver();
00049   iEventQueue* GetEventQueue();
00050   virtual void LostFocus() = 0;
00051   virtual void Post(iEvent*);
00052 protected:
00053   struct FocusListener : public iEventHandler
00054   {
00055     csInputDriver* Parent;
00056     SCF_DECLARE_IBASE;
00057     FocusListener() {}
00058     void SetSCFParent(iBase* p) { SCF_CONSTRUCT_IBASE(p); }
00059     virtual bool HandleEvent(iEvent&);
00060   };
00061   friend struct FocusListener;
00062   FocusListener Listener;
00063   iEventQueue* Queue;
00064   void SetSCFParent(iBase*);
00065   void StartListening();
00066   void StopListening();
00067 };
00068 
00074 class csKeyboardDriver : public csInputDriver, public iKeyboardDriver
00075 {
00076 protected:
00078   csBitSet KeyState;
00079 
00084   virtual void SetKeyState (int iKey, bool iDown);
00085 
00086 public:
00087   SCF_DECLARE_IBASE;
00088 
00090   csKeyboardDriver (iObjectRegistry*);
00091 
00093   virtual void Reset ();
00094 
00096   virtual void DoKey (int iKey, int iChar, bool iDown);
00097 
00103   virtual bool GetKeyState (int iKey);
00104 
00105 private:
00107   virtual void LostFocus() { Reset(); }
00108 };
00109 
00115 class csMouseDriver : public csInputDriver, public iMouseDriver
00116 {
00117 private:
00118   // Generic keyboard driver (for checking modifier key states).
00119   iKeyboardDriver* Keyboard;
00120 
00121 protected:
00123   csTicks LastClickTime;
00125   int LastClickButton;
00127   int LastClickX, LastClickY;
00129   int LastX, LastY;
00131   bool Button [CS_MAX_MOUSE_BUTTONS];
00133   csTicks DoubleClickTime;
00135   size_t DoubleClickDist;
00137   iKeyboardDriver* GetKeyboardDriver();
00138 
00139 public:
00140   SCF_DECLARE_IBASE;
00141 
00143   csMouseDriver (iObjectRegistry*);
00144 
00145   virtual ~csMouseDriver ();
00146 
00148   virtual void SetDoubleClickTime (int iTime, size_t iDist);
00149 
00151   virtual void Reset ();
00152 
00154   virtual int GetLastX () { return LastX; }
00156   virtual int GetLastY () { return LastY; }
00158   virtual bool GetLastButton (int button)
00159   {
00160     return (button > 0 && button <= CS_MAX_MOUSE_BUTTONS) ?
00161       Button [button - 1] : false;
00162   }
00163 
00165   virtual void DoButton (int button, bool down, int x, int y);
00167   virtual void DoMotion (int x, int y);
00168 
00169 private:
00171   virtual void LostFocus() { Reset(); }
00172 };
00173 
00179 class csJoystickDriver : public csInputDriver, public iJoystickDriver
00180 {
00181 private:
00182   // Generic keyboard driver (for checking modifier key states).
00183   iKeyboardDriver* Keyboard;
00184 protected:
00186   bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS];
00188   int LastX [CS_MAX_JOYSTICK_COUNT], LastY [CS_MAX_JOYSTICK_COUNT];
00190   iKeyboardDriver* GetKeyboardDriver();
00191 
00192 public:
00193   SCF_DECLARE_IBASE;
00194 
00196   csJoystickDriver (iObjectRegistry*);
00197 
00199   virtual void Reset ();
00200 
00202   virtual int GetLastX (int number) { return LastX [number]; }
00204   virtual int GetLastY (int number) { return LastY [number]; }
00206   virtual bool GetLastButton (int number, int button)
00207   {
00208     return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT
00209          && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ?
00210             Button [number - 1] [button - 1] : false;
00211   }
00212 
00214   virtual void DoButton (int number, int button, bool down, int x, int y);
00216   virtual void DoMotion (int number, int x, int y);
00217 
00218 private:
00220   virtual void LostFocus() { Reset(); }
00221 };
00222 
00223 #endif // __CS_CSINPUT_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000