CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class 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 "csextern.h"
00030 
00031 #include "csutil/array.h"
00032 #include "csutil/hash.h"
00033 #include "csutil/scf.h"
00034 
00035 #include "iutil/csinput.h"
00036 #include "iutil/eventh.h"
00037 #include "iutil/comp.h"
00038 
00039 struct iEvent;
00040 struct iEventQueue;
00041 struct iObjectRegistry;
00042 
00046 class CS_CRYSTALSPACE_EXPORT csInputDriver
00047 {
00048 private:
00049   bool Registered;
00050 protected:
00051   iObjectRegistry* Registry;
00052   iEventHandler* Listener;
00053   csInputDriver(iObjectRegistry*);
00054   virtual ~csInputDriver();
00055   csPtr<iEventQueue> GetEventQueue();
00056   virtual void GainFocus() = 0;
00057   virtual void LostFocus() = 0;
00058   virtual void Post(iEvent*);
00059   virtual bool HandleEvent(iEvent&);
00060   friend struct FocusListener;
00061   void StartListening();
00062   void StopListening();
00063 };
00064 
00065 class CS_CRYSTALSPACE_EXPORT csKeyComposer : public iKeyComposer
00066 {
00067 protected:
00068   utf32_char lastDead;
00069 
00070 public:
00071   SCF_DECLARE_IBASE;
00072 
00073   csKeyComposer ();
00074   virtual ~csKeyComposer ();
00075 
00076   virtual csKeyComposeResult HandleKey (const csKeyEventData& keyEventData,
00077     utf32_char* buf, size_t bufChars, int* resultChars = 0);
00078   virtual void ResetState ();
00079 };
00080 
00081 #ifdef CS_DEBUG
00082   #ifndef CS_KEY_DEBUG_ENABLE
00083 
00087     #define CS_KEY_DEBUG_ENABLE
00088   #endif
00089 #endif
00090 
00096 class CS_CRYSTALSPACE_EXPORT csKeyboardDriver : public csInputDriver,
00097   public iKeyboardDriver
00098 {
00099 protected:
00101   csHash<bool, utf32_char> keyStates;
00102   csKeyModifiers modifiersState;
00103   bool keyDebug;
00104   bool keyDebugChecked;
00105 
00110   virtual void SetKeyState (utf32_char codeRaw, bool iDown,
00111     bool autoRepeat);
00116   virtual void SynthesizeCooked (utf32_char codeRaw,
00117     const csKeyModifiers& modifiers, utf32_char& codeCooked);
00118 
00119   const char* GetKeycodeString (utf32_char code);
00120   bool IsKeyboardDebugging ();
00121 
00123   virtual void LostFocus() { Reset(); }
00124   virtual void GainFocus() { RestoreKeys(); }
00125 
00127   struct CS_CRYSTALSPACE_EXPORT eiEventHandler : public iEventHandler
00128   {
00129     SCF_DECLARE_EMBEDDED_IBASE(csKeyboardDriver);
00130     virtual bool HandleEvent(iEvent& e) 
00131     { return scfParent->HandleEvent(e); }
00132   } scfiEventHandler;
00133   friend struct eiEventHandler;
00134 public:
00135   SCF_DECLARE_IBASE;
00136 
00138   csKeyboardDriver (iObjectRegistry*);
00140   virtual ~csKeyboardDriver ();
00141 
00143   virtual void Reset ();
00145   virtual void RestoreKeys ();
00146 
00157   virtual void DoKey (utf32_char codeRaw, utf32_char codeCooked, bool iDown,
00158     bool autoRepeat = false, csKeyCharType charType = csKeyCharTypeNormal);
00159 
00164   CS_PURE_METHOD virtual bool GetKeyState (utf32_char codeRaw) const;
00165 
00184   CS_PURE_METHOD virtual uint32 GetModifierState (utf32_char codeRaw) const;
00185 
00186   virtual csPtr<iKeyComposer> CreateKeyComposer ();
00187 
00189   virtual csEventError SynthesizeCooked (iEvent *);
00190 };
00191 
00198 class CS_CRYSTALSPACE_EXPORT csMouseDriver :
00199   public csInputDriver, public iMouseDriver
00200 {
00201 private:
00202   // Generic keyboard driver (for checking modifier key states).
00203   csRef<iKeyboardDriver> Keyboard;
00204 
00205 protected:
00207   csTicks LastClickTime[CS_MAX_MOUSE_COUNT];
00209   uint LastClickButton[CS_MAX_MOUSE_COUNT];
00211   int LastClick [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES];
00213   int32 Last [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES];
00214   uint Axes [CS_MAX_MOUSE_COUNT];
00216   bool Button [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_BUTTONS];
00218   csTicks DoubleClickTime;
00220   size_t DoubleClickDist;
00222   iKeyboardDriver* GetKeyboardDriver();
00223 
00224 public:
00225   SCF_DECLARE_IBASE;
00226 
00228   csMouseDriver (iObjectRegistry*);
00230   virtual ~csMouseDriver ();
00231 
00233   virtual void SetDoubleClickTime (int iTime, size_t iDist);
00234 
00236   virtual void Reset ();
00237 
00239   CS_PURE_METHOD virtual int GetLastX (uint n) const { return Last[n - 1][0]; }
00241   CS_PURE_METHOD virtual int GetLastY (uint n) const { return Last[n - 1][1]; }
00243   CS_PURE_METHOD virtual int GetLast (uint n, uint axis) const { return Last[n - 1][axis - 1]; }
00245   CS_PURE_METHOD virtual const int32 *GetLast (uint n) const { return Last [n - 1]; }
00247   CS_PURE_METHOD virtual bool GetLastButton (uint button) const { return GetLastButton(1, button); }
00249   CS_PURE_METHOD virtual bool GetLastButton (uint number, uint button) const
00250   {
00251     return (number > 0 && number <= CS_MAX_MOUSE_COUNT
00252             && button > 0 && button <= CS_MAX_MOUSE_BUTTONS) ?
00253             Button [number - 1][button - 1] : false;
00254   }
00255 
00257   virtual void DoButton (uint number, uint button, bool down, const int32 *axes, uint numAxes);
00258   virtual void DoButton (uint button, bool down, const int32 *axes, uint numAxes) 
00259   { DoButton (1, button, down, axes, numAxes); }
00260   virtual void DoButton (uint button, bool down, int x, int y)
00261   { int32 axes[2] = {x, y}; DoButton (1, button, down, axes, 2); }
00263   virtual void DoMotion (uint number, const int32 *axes, uint numAxes);
00264   virtual void DoMotion (const int32 *axes, uint numAxes) 
00265   { DoMotion (1, axes, numAxes); }
00266   virtual void DoMotion (int x, int y)
00267   { int32 axes[2] = {x, y}; DoMotion (1, axes, 2); }
00269   virtual void LostFocus() { Reset(); }
00270   virtual void GainFocus() { }
00271 
00273   struct CS_CRYSTALSPACE_EXPORT eiEventHandler : public iEventHandler
00274   {
00275     SCF_DECLARE_EMBEDDED_IBASE(csMouseDriver);
00276     virtual bool HandleEvent(iEvent& e) 
00277     { return scfParent->HandleEvent(e); }
00278   } scfiEventHandler;
00279   friend struct eiEventHandler;
00280 };
00281 
00288 class CS_CRYSTALSPACE_EXPORT csJoystickDriver : public csInputDriver,
00289   public iJoystickDriver
00290 {
00291 private:
00292   // Generic keyboard driver (for checking modifier key states).
00293   csRef<iKeyboardDriver> Keyboard;
00294 protected:
00296   bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS];
00298   int32 Last [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_AXES];
00299   uint Axes [CS_MAX_JOYSTICK_COUNT];
00301   iKeyboardDriver* GetKeyboardDriver();
00302 
00303 public:
00304   SCF_DECLARE_IBASE;
00305 
00307   csJoystickDriver (iObjectRegistry*);
00309   virtual ~csJoystickDriver ();
00310 
00312   virtual void Reset ();
00313 
00315   CS_DEPRECATED_METHOD CS_PURE_METHOD virtual int GetLastX (uint number) const 
00316   { return Last [number - 1][0]; }
00318   CS_DEPRECATED_METHOD CS_PURE_METHOD virtual int GetLastY (uint number) const 
00319   { return Last [number - 1][1]; }
00320   CS_PURE_METHOD virtual const int32 *GetLast (uint number) const 
00321   { return Last [number - 1]; }
00322   CS_PURE_METHOD virtual int GetLast (uint number, uint axis) const 
00323   { return Last [number - 1][axis - 1]; }
00325   CS_PURE_METHOD virtual bool GetLastButton (uint number, uint button) const
00326   {
00327     return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT
00328          && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ?
00329             Button [number - 1][button - 1] : false;
00330   }
00331 
00333   virtual void DoButton (uint number, uint button, bool down, 
00334     const int32 *axes, uint numAxes);
00336   virtual void DoMotion (uint number, const int32 *axes, uint numAxes);
00337 
00339   virtual void LostFocus() { Reset(); }
00340   virtual void GainFocus() { }
00341 
00343   struct CS_CRYSTALSPACE_EXPORT eiEventHandler : public iEventHandler
00344   {
00345     SCF_DECLARE_EMBEDDED_IBASE (csJoystickDriver);
00346     virtual bool HandleEvent(iEvent& e) 
00347     { return scfParent->HandleEvent(e); }
00348   } scfiEventHandler;
00349   friend struct eiEventHandler;
00350 };
00351 
00352 #endif // __CS_CSINPUT_H__

Generated for Crystal Space by doxygen 1.4.4