CrystalSpace

Public API Reference

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

csutil/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 #include "scf.h"
00031 #include "array.h"
00032 #include "hash.h"
00033 #include "iutil/csinput.h"
00034 #include "iutil/eventh.h"
00035 #include "iutil/comp.h"
00036 
00037 struct iEvent;
00038 struct iEventQueue;
00039 struct iObjectRegistry;
00040 
00044 class CS_CSUTIL_EXPORT csInputDriver
00045 {
00046 private:
00047   bool Registered;
00048 protected:
00049   iObjectRegistry* Registry;
00050   iEventHandler* Listener;
00051   csInputDriver(iObjectRegistry*);
00052   virtual ~csInputDriver();
00053   csPtr<iEventQueue> GetEventQueue();
00054   virtual void GainFocus() = 0;
00055   virtual void LostFocus() = 0;
00056   virtual void Post(iEvent*);
00057   virtual bool HandleEvent(iEvent&);
00058   friend struct FocusListener;
00059   void StartListening();
00060   void StopListening();
00061 };
00062 
00063 class CS_CSUTIL_EXPORT csKeyComposer : public iKeyComposer
00064 {
00065 protected:
00066   utf32_char lastDead;
00067 
00068 public:
00069   SCF_DECLARE_IBASE;
00070 
00071   csKeyComposer ();
00072   virtual ~csKeyComposer ();
00073 
00074   virtual csKeyComposeResult HandleKey (const csKeyEventData& keyEventData,
00075     utf32_char* buf, size_t bufChars, int* resultChars = 0);
00076   virtual void ResetState ();
00077 };
00078 
00084 class CS_CSUTIL_EXPORT csKeyboardDriver : public csInputDriver,
00085   public iKeyboardDriver
00086 {
00087 protected:
00089   csHash<bool, utf32_char> keyStates;
00090   csKeyModifiers modifiersState;
00091 
00096   virtual void SetKeyState (utf32_char codeRaw, bool iDown,
00097     bool autoRepeat);
00102   virtual void SynthesizeCooked (utf32_char codeRaw,
00103     const csKeyModifiers& modifiers, utf32_char& codeCooked);
00104 public:
00105   SCF_DECLARE_IBASE;
00106 
00108   csKeyboardDriver (iObjectRegistry*);
00110   virtual ~csKeyboardDriver ();
00111 
00113   virtual void Reset ();
00115   virtual void RestoreKeys ();
00116 
00127   virtual void DoKey (utf32_char codeRaw, utf32_char codeCooked, bool iDown,
00128     bool autoRepeat = false, csKeyCharType charType = csKeyCharTypeNormal);
00129 
00135   virtual bool GetKeyState (utf32_char codeRaw);
00136 
00155   virtual uint32 GetModifierState (utf32_char codeRaw);
00156 
00157   virtual csPtr<iKeyComposer> CreateKeyComposer ();
00158 
00160   virtual void LostFocus() { Reset(); }
00161   virtual void GainFocus() { RestoreKeys(); }
00162 
00164   struct CS_CSUTIL_EXPORT eiEventHandler : public iEventHandler
00165   {
00166     SCF_DECLARE_EMBEDDED_IBASE(csKeyboardDriver);
00167     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00168   } scfiEventHandler;
00169   friend struct eiEventHandler;
00170 };
00171 
00177 class CS_CSUTIL_EXPORT csMouseDriver : public csInputDriver, public iMouseDriver
00178 {
00179 private:
00180   // Generic keyboard driver (for checking modifier key states).
00181   csRef<iKeyboardDriver> Keyboard;
00182 
00183 protected:
00185   csTicks LastClickTime;
00187   int LastClickButton;
00189   int LastClickX, LastClickY;
00191   int LastX, LastY;
00193   bool Button [CS_MAX_MOUSE_BUTTONS];
00195   csTicks DoubleClickTime;
00197   size_t DoubleClickDist;
00199   iKeyboardDriver* GetKeyboardDriver();
00200 
00201 public:
00202   SCF_DECLARE_IBASE;
00203 
00205   csMouseDriver (iObjectRegistry*);
00207   virtual ~csMouseDriver ();
00208 
00210   virtual void SetDoubleClickTime (int iTime, size_t iDist);
00211 
00213   virtual void Reset ();
00214 
00216   virtual int GetLastX () { return LastX; }
00218   virtual int GetLastY () { return LastY; }
00220   virtual bool GetLastButton (int button)
00221   {
00222     return (button > 0 && button <= CS_MAX_MOUSE_BUTTONS) ?
00223       Button [button - 1] : false;
00224   }
00225 
00227   virtual void DoButton (int button, bool down, int x, int y);
00229   virtual void DoMotion (int x, int y);
00230 
00232   virtual void LostFocus() { Reset(); }
00233   virtual void GainFocus() { }
00234 
00236   struct CS_CSUTIL_EXPORT eiEventHandler : public iEventHandler
00237   {
00238     SCF_DECLARE_EMBEDDED_IBASE(csMouseDriver);
00239     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00240   } scfiEventHandler;
00241   friend struct eiEventHandler;
00242 };
00243 
00249 class CS_CSUTIL_EXPORT csJoystickDriver : public csInputDriver,
00250   public iJoystickDriver
00251 {
00252 private:
00253   // Generic keyboard driver (for checking modifier key states).
00254   csRef<iKeyboardDriver> Keyboard;
00255 protected:
00257   bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS];
00259   int LastX [CS_MAX_JOYSTICK_COUNT], LastY [CS_MAX_JOYSTICK_COUNT];
00261   iKeyboardDriver* GetKeyboardDriver();
00262 
00263 public:
00264   SCF_DECLARE_IBASE;
00265 
00267   csJoystickDriver (iObjectRegistry*);
00269   virtual ~csJoystickDriver ();
00270 
00272   virtual void Reset ();
00273 
00275   virtual int GetLastX (int number) { return LastX [number]; }
00277   virtual int GetLastY (int number) { return LastY [number]; }
00279   virtual bool GetLastButton (int number, int button)
00280   {
00281     return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT
00282          && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ?
00283             Button [number - 1] [button - 1] : false;
00284   }
00285 
00287   virtual void DoButton (int number, int button, bool down, int x, int y);
00289   virtual void DoMotion (int number, int x, int y);
00290 
00292   virtual void LostFocus() { Reset(); }
00293   virtual void GainFocus() { }
00294 
00296   struct CS_CSUTIL_EXPORT eiEventHandler : public iEventHandler
00297   {
00298     SCF_DECLARE_EMBEDDED_IBASE (csJoystickDriver);
00299     virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); }
00300   } scfiEventHandler;
00301   friend struct eiEventHandler;
00302 };
00303 
00304 #endif // __CS_CSINPUT_H__

Generated for Crystal Space by doxygen 1.2.18