csutil/csinput.h
Go to the documentation of this file.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 00030 #include "csextern.h" 00031 00032 #include "csutil/hash.h" 00033 #include "csutil/scf_implementation.h" 00034 #include "csutil/csstring.h" 00035 00036 #include "iutil/csinput.h" 00037 #include "iutil/eventh.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 csRef<iEventNameRegistry> NameRegistry; 00053 iEventHandler* Listener; 00054 csEventID FocusChanged; 00055 csEventID FocusGained; 00056 csEventID FocusLost; 00057 csInputDriver(iObjectRegistry*); 00058 virtual ~csInputDriver(); 00059 csPtr<iEventQueue> GetEventQueue(); 00060 virtual void GainFocus() = 0; 00061 virtual void LostFocus() = 0; 00062 virtual void Post(iEvent*); 00063 virtual bool HandleEvent(iEvent&); 00064 friend struct FocusListener; 00065 void StartListening(); 00066 void StopListening(); 00067 }; 00068 00069 class CS_CRYSTALSPACE_EXPORT csKeyComposer : 00070 public scfImplementation1<csKeyComposer, iKeyComposer> 00071 { 00072 protected: 00073 utf32_char lastDead; 00074 00075 public: 00076 csKeyComposer (); 00077 virtual ~csKeyComposer (); 00078 00079 virtual csKeyComposeResult HandleKey (const csKeyEventData& keyEventData, 00080 utf32_char* buf, size_t bufChars, int* resultChars = 0); 00081 virtual void ResetState (); 00082 }; 00083 00084 #ifdef CS_DEBUG 00085 #ifndef CS_KEY_DEBUG_ENABLE 00086 00090 #define CS_KEY_DEBUG_ENABLE 00091 #endif 00092 #endif 00093 00099 class CS_CRYSTALSPACE_EXPORT csKeyboardDriver : public csInputDriver, 00100 public scfImplementation2<csKeyboardDriver, iKeyboardDriver, iEventHandler> 00101 { 00102 protected: 00104 csHash<bool, utf32_char> keyStates; 00105 csKeyModifiers modifiersState; 00106 bool keyDebug; 00107 bool keyDebugChecked; 00108 csEventID KeyboardUp; 00109 csEventID KeyboardDown; 00110 00115 virtual void SetKeyState (utf32_char codeRaw, bool iDown, 00116 bool autoRepeat); 00121 virtual void SynthesizeCooked (utf32_char codeRaw, 00122 const csKeyModifiers& modifiers, utf32_char& codeCooked); 00123 00124 const char* GetKeycodeString (utf32_char code); 00125 bool IsKeyboardDebugging (); 00126 00128 virtual void LostFocus() { Reset(); } 00129 virtual void GainFocus() { RestoreKeys(); } 00130 00131 virtual bool HandleEvent (iEvent& e) 00132 { 00133 return csInputDriver::HandleEvent (e); 00134 } 00135 public: 00137 csKeyboardDriver (iObjectRegistry*); 00139 virtual ~csKeyboardDriver (); 00140 00141 CS_EVENTHANDLER_NAMES("crystalspace.inputdriver.keyboard") 00142 CS_EVENTHANDLER_NIL_CONSTRAINTS 00143 00145 virtual void Reset (); 00147 virtual void RestoreKeys (); 00148 00159 virtual void DoKey (utf32_char codeRaw, utf32_char codeCooked, bool iDown, 00160 bool autoRepeat = false, csKeyCharType charType = csKeyCharTypeNormal); 00161 00166 virtual bool GetKeyState (utf32_char codeRaw) const; 00167 00186 virtual uint32 GetModifierState (utf32_char codeRaw) const; 00187 00188 virtual csPtr<iKeyComposer> CreateKeyComposer (); 00189 00191 virtual csEventError SynthesizeCooked (iEvent *); 00192 00193 const csKeyModifiers& GetModifiersState () const { return modifiersState; } 00194 }; 00195 00204 class CS_CRYSTALSPACE_EXPORT csMouseDriver : public csInputDriver, 00205 public scfImplementation2<csMouseDriver, iMouseDriver, iEventHandler> 00206 { 00207 private: 00208 // Generic keyboard driver (for checking modifier key states). 00209 csRef<iKeyboardDriver> Keyboard; 00210 00211 virtual bool HandleEvent (iEvent& e) 00212 { 00213 return csInputDriver::HandleEvent (e); 00214 } 00215 protected: 00217 csTicks LastClickTime[CS_MAX_MOUSE_COUNT]; 00219 int LastClickButton[CS_MAX_MOUSE_COUNT]; 00221 int LastClick [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES]; 00223 int32 Last [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES]; 00224 uint Axes [CS_MAX_MOUSE_COUNT]; 00229 bool Button [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_BUTTONS]; 00231 csTicks DoubleClickTime; 00233 size_t DoubleClickDist; 00235 iKeyboardDriver* GetKeyboardDriver(); 00236 00237 public: 00239 csMouseDriver (iObjectRegistry*); 00241 virtual ~csMouseDriver (); 00242 00243 CS_EVENTHANDLER_NAMES("crystalspace.inputdriver.mouse") 00244 CS_EVENTHANDLER_NIL_CONSTRAINTS 00245 00247 virtual void SetDoubleClickTime (int iTime, size_t iDist); 00248 00250 virtual void Reset (); 00251 00253 virtual int GetLastX (uint n) const { return Last[n][0]; } 00255 virtual int GetLastY (uint n) const { return Last[n][1]; } 00257 virtual int GetLast (uint n, uint axis) const 00258 { return Last[n][axis]; } 00260 virtual const int32 *GetLast (uint n) const 00261 { return Last [n]; } 00263 virtual bool GetLastButton (int button) const 00264 { return GetLastButton(0, button); } 00266 virtual bool GetLastButton (uint number, int button) const 00267 { 00268 return (number < CS_MAX_MOUSE_COUNT 00269 && button >= 0 && button < CS_MAX_MOUSE_BUTTONS) ? 00270 Button [number][button] : false; 00271 } 00272 00274 virtual void DoButton (uint number, int button, bool down, 00275 const int32 *axes, uint numAxes); 00276 virtual void DoButton (int button, bool down, const int32 *axes, 00277 uint numAxes) 00278 { DoButton (0, button, down, axes, numAxes); } 00279 virtual void DoButton (int button, bool down, int x, int y) 00280 { int32 axes[2] = {x, y}; DoButton (0, button, down, axes, 2); } 00282 virtual void DoMotion (uint number, const int32 *axes, uint numAxes); 00283 virtual void DoMotion (const int32 *axes, uint numAxes) 00284 { DoMotion (0, axes, numAxes); } 00285 virtual void DoMotion (int x, int y) 00286 { int32 axes[2] = {x, y}; DoMotion (0, axes, 2); } 00288 virtual void LostFocus() { Reset(); } 00289 virtual void GainFocus() { } 00290 00291 }; 00292 00293 #include "csutil/deprecated_warn_off.h" 00294 00301 class CS_CRYSTALSPACE_EXPORT csJoystickDriver : public csInputDriver, 00302 public scfImplementation2<csJoystickDriver, iJoystickDriver, iEventHandler> 00303 { 00304 private: 00305 // Generic keyboard driver (for checking modifier key states). 00306 csRef<iKeyboardDriver> Keyboard; 00307 00308 protected: 00313 bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS]; 00315 int32 Last [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_AXES]; 00316 uint Axes [CS_MAX_JOYSTICK_COUNT]; 00318 iKeyboardDriver* GetKeyboardDriver(); 00319 virtual bool HandleEvent (iEvent& e) 00320 { 00321 return csInputDriver::HandleEvent (e); 00322 } 00323 public: 00324 00326 csJoystickDriver (iObjectRegistry*); 00328 virtual ~csJoystickDriver (); 00329 00330 CS_EVENTHANDLER_NAMES("crystalspace.inputdriver.joystick") 00331 CS_EVENTHANDLER_NIL_CONSTRAINTS 00332 00334 virtual void Reset (); 00335 00336 virtual const int32 *GetLast (uint number) const 00337 { return Last [number]; } 00338 virtual int GetLast (uint number, uint axis) const 00339 { return Last [number][axis]; } 00341 virtual bool GetLastButton (uint number, int button) const 00342 { 00343 return (number < CS_MAX_JOYSTICK_COUNT 00344 && button >= 0 && button < CS_MAX_JOYSTICK_BUTTONS) ? 00345 Button [number][button] : false; 00346 } 00347 00349 virtual void DoButton (uint number, int button, bool down, 00350 const int32 *axes, uint numAxes); 00352 virtual void DoMotion (uint number, const int32 *axes, uint numAxes); 00353 00355 virtual void LostFocus() { Reset(); } 00356 virtual void GainFocus() { } 00357 00358 }; 00359 00360 #include "csutil/deprecated_warn_on.h" 00361 00362 #endif // __CS_CSINPUT_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1