CrystalSpace

Public API Reference

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

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 
00024 /*
00025  * These are the low-level implementations of generic classes of input devices
00026  * like keyboard, mouse, and joystick.
00027  */
00028 
00029 #include "csutil/scf.h"
00030 #include "csutil/array.h"
00031 #include "iutil/csinput.h"
00032 #include "iutil/eventh.h"
00033 #include "iutil/comp.h"
00034 
00035 struct iEvent;
00036 struct iEventQueue;
00037 struct iObjectRegistry;
00038 
00042 class csInputDriver
00043 {
00044 private:
00045   bool Registered;
00046 protected:
00047   iObjectRegistry* Registry;
00048   iEventHandler* Listener;
00049   csInputDriver(iObjectRegistry*);
00050   virtual ~csInputDriver();
00051   csPtr<iEventQueue> GetEventQueue();
00052   virtual void LostFocus() = 0;
00053   virtual void Post(iEvent*);
00054   virtual bool HandleEvent(iEvent&);
00055   friend struct FocusListener;
00056   void StartListening();
00057   void StopListening();
00058 };
00059 
00065 class csKeyboardDriver : public csInputDriver, public iKeyboardDriver
00066 {
00067 protected:
00069   csArray<bool> KeyState;
00070 
00075   virtual void SetKeyState (int iKey, bool iDown);
00076 
00077 public:
00078   SCF_DECLARE_IBASE;
00079 
00081   csKeyboardDriver (iObjectRegistry*);
00083   virtual ~csKeyboardDriver ();
00084 
00086   virtual void Reset ();
00087 
00089   virtual void DoKey (int iKey, int iChar, bool iDown);
00090 
00096   virtual bool GetKeyState (int iKey);
00097 
00099   virtual void LostFocus() { Reset(); }
00100 
00102   struct eiEventHandler : public iEventHandler
00103   {
00104     SCF_DECLARE_EMBEDDED_IBASE(csKeyboardDriver);
00105     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00106   } scfiEventHandler;
00107   friend struct eiEventHandler;
00108 };
00109 
00115 class csMouseDriver : public csInputDriver, public iMouseDriver
00116 {
00117 private:
00118   // Generic keyboard driver (for checking modifier key states).
00119   csRef<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*);
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 
00170   virtual void LostFocus() { Reset(); }
00171 
00173   struct eiEventHandler : public iEventHandler
00174   {
00175     SCF_DECLARE_EMBEDDED_IBASE(csMouseDriver);
00176     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00177   } scfiEventHandler;
00178   friend struct eiEventHandler;
00179 };
00180 
00186 class csJoystickDriver : public csInputDriver, public iJoystickDriver
00187 {
00188 private:
00189   // Generic keyboard driver (for checking modifier key states).
00190   csRef<iKeyboardDriver> Keyboard;
00191 protected:
00193   bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS];
00195   int LastX [CS_MAX_JOYSTICK_COUNT], LastY [CS_MAX_JOYSTICK_COUNT];
00197   iKeyboardDriver* GetKeyboardDriver();
00198 
00199 public:
00200   SCF_DECLARE_IBASE;
00201 
00203   csJoystickDriver (iObjectRegistry*);
00205   virtual ~csJoystickDriver ();
00206 
00208   virtual void Reset ();
00209 
00211   virtual int GetLastX (int number) { return LastX [number]; }
00213   virtual int GetLastY (int number) { return LastY [number]; }
00215   virtual bool GetLastButton (int number, int button)
00216   {
00217     return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT
00218          && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ?
00219             Button [number - 1] [button - 1] : false;
00220   }
00221 
00223   virtual void DoButton (int number, int button, bool down, int x, int y);
00225   virtual void DoMotion (int number, int x, int y);
00226 
00228   virtual void LostFocus() { Reset(); }
00229 
00231   struct eiEventHandler : public iEventHandler
00232   {
00233     SCF_DECLARE_EMBEDDED_IBASE (csJoystickDriver);
00234     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00235   } scfiEventHandler;
00236   friend struct eiEventHandler;
00237 };
00238 
00239 #endif // __CS_CSINPUT_H__

Generated for Crystal Space by doxygen 1.2.14