Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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 #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 00079 #ifdef CS_DEBUG 00080 #ifndef CS_KEY_DEBUG_ENABLE 00081 00085 #define CS_KEY_DEBUG_ENABLE 00086 #endif 00087 #endif 00088 00094 class CS_CSUTIL_EXPORT csKeyboardDriver : public csInputDriver, 00095 public iKeyboardDriver 00096 { 00097 protected: 00099 csHash<bool, utf32_char> keyStates; 00100 csKeyModifiers modifiersState; 00101 bool keyDebug; 00102 bool keyDebugChecked; 00103 00108 virtual void SetKeyState (utf32_char codeRaw, bool iDown, 00109 bool autoRepeat); 00114 virtual void SynthesizeCooked (utf32_char codeRaw, 00115 const csKeyModifiers& modifiers, utf32_char& codeCooked); 00116 00117 const char* GetKeycodeString (utf32_char code); 00118 bool IsKeyboardDebugging (); 00119 public: 00120 SCF_DECLARE_IBASE; 00121 00123 csKeyboardDriver (iObjectRegistry*); 00125 virtual ~csKeyboardDriver (); 00126 00128 virtual void Reset (); 00130 virtual void RestoreKeys (); 00131 00142 virtual void DoKey (utf32_char codeRaw, utf32_char codeCooked, bool iDown, 00143 bool autoRepeat = false, csKeyCharType charType = csKeyCharTypeNormal); 00144 00150 virtual bool GetKeyState (utf32_char codeRaw); 00151 00170 virtual uint32 GetModifierState (utf32_char codeRaw); 00171 00172 virtual csPtr<iKeyComposer> CreateKeyComposer (); 00173 00175 virtual void LostFocus() { Reset(); } 00176 virtual void GainFocus() { RestoreKeys(); } 00177 00179 virtual csEventError SynthesizeCooked (iEvent *); 00180 00182 struct CS_CSUTIL_EXPORT eiEventHandler : public iEventHandler 00183 { 00184 SCF_DECLARE_EMBEDDED_IBASE(csKeyboardDriver); 00185 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00186 } scfiEventHandler; 00187 friend struct eiEventHandler; 00188 }; 00189 00196 class CS_CSUTIL_EXPORT csMouseDriver : 00197 public csInputDriver, public iMouseDriver 00198 { 00199 private: 00200 // Generic keyboard driver (for checking modifier key states). 00201 csRef<iKeyboardDriver> Keyboard; 00202 00203 protected: 00205 csTicks LastClickTime; 00207 int LastClickButton; 00209 int LastClickX, LastClickY; 00211 int LastX, LastY; 00213 bool Button [CS_MAX_MOUSE_BUTTONS]; 00215 csTicks DoubleClickTime; 00217 size_t DoubleClickDist; 00219 iKeyboardDriver* GetKeyboardDriver(); 00220 00221 public: 00222 SCF_DECLARE_IBASE; 00223 00225 csMouseDriver (iObjectRegistry*); 00227 virtual ~csMouseDriver (); 00228 00230 virtual void SetDoubleClickTime (int iTime, size_t iDist); 00231 00233 virtual void Reset (); 00234 00236 virtual int GetLastX () { return LastX; } 00238 virtual int GetLastY () { return LastY; } 00240 virtual bool GetLastButton (int button) 00241 { 00242 return (button > 0 && button <= CS_MAX_MOUSE_BUTTONS) ? 00243 Button [button - 1] : false; 00244 } 00245 00247 virtual void DoButton (int button, bool down, int x, int y); 00249 virtual void DoMotion (int x, int y); 00250 00252 virtual void LostFocus() { Reset(); } 00253 virtual void GainFocus() { } 00254 00256 struct CS_CSUTIL_EXPORT eiEventHandler : public iEventHandler 00257 { 00258 SCF_DECLARE_EMBEDDED_IBASE(csMouseDriver); 00259 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00260 } scfiEventHandler; 00261 friend struct eiEventHandler; 00262 }; 00263 00270 class CS_CSUTIL_EXPORT csJoystickDriver : public csInputDriver, 00271 public iJoystickDriver 00272 { 00273 private: 00274 // Generic keyboard driver (for checking modifier key states). 00275 csRef<iKeyboardDriver> Keyboard; 00276 protected: 00278 bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS]; 00280 int LastX [CS_MAX_JOYSTICK_COUNT], LastY [CS_MAX_JOYSTICK_COUNT]; 00282 iKeyboardDriver* GetKeyboardDriver(); 00283 00284 public: 00285 SCF_DECLARE_IBASE; 00286 00288 csJoystickDriver (iObjectRegistry*); 00290 virtual ~csJoystickDriver (); 00291 00293 virtual void Reset (); 00294 00296 virtual int GetLastX (int number) { return LastX [number - 1]; } 00298 virtual int GetLastY (int number) { return LastY [number - 1]; } 00300 virtual bool GetLastButton (int number, int button) 00301 { 00302 return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT 00303 && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ? 00304 Button [number - 1][button - 1] : false; 00305 } 00306 00308 virtual void DoButton (int number, int button, bool down, int x, int y); 00310 virtual void DoMotion (int number, int x, int y); 00311 00313 virtual void LostFocus() { Reset(); } 00314 virtual void GainFocus() { } 00315 00317 struct CS_CSUTIL_EXPORT eiEventHandler : public iEventHandler 00318 { 00319 SCF_DECLARE_EMBEDDED_IBASE (csJoystickDriver); 00320 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00321 } scfiEventHandler; 00322 friend struct eiEventHandler; 00323 }; 00324 00325 #endif // __CS_CSINPUT_H__
Generated for Crystal Space by doxygen 1.3.9.1