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 <[email protected]> 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 CS_PURE_METHOD virtual bool GetKeyState (utf32_char codeRaw) const; 00167 00186 CS_PURE_METHOD virtual uint32 GetModifierState (utf32_char codeRaw) const; 00187 00188 virtual csPtr<iKeyComposer> CreateKeyComposer (); 00189 00191 virtual csEventError SynthesizeCooked (iEvent *); 00192 00193 }; 00194 00203 class CS_CRYSTALSPACE_EXPORT csMouseDriver : public csInputDriver, 00204 public scfImplementation2<csMouseDriver, iMouseDriver, iEventHandler> 00205 { 00206 private: 00207 // Generic keyboard driver (for checking modifier key states). 00208 csRef<iKeyboardDriver> Keyboard; 00209 00210 virtual bool HandleEvent (iEvent& e) 00211 { 00212 return csInputDriver::HandleEvent (e); 00213 } 00214 protected: 00216 csTicks LastClickTime[CS_MAX_MOUSE_COUNT]; 00218 int LastClickButton[CS_MAX_MOUSE_COUNT]; 00220 int LastClick [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES]; 00222 int32 Last [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES]; 00223 uint Axes [CS_MAX_MOUSE_COUNT]; 00228 bool Button [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_BUTTONS]; 00230 csTicks DoubleClickTime; 00232 size_t DoubleClickDist; 00234 iKeyboardDriver* GetKeyboardDriver(); 00235 00236 public: 00238 csMouseDriver (iObjectRegistry*); 00240 virtual ~csMouseDriver (); 00241 00242 CS_EVENTHANDLER_NAMES("crystalspace.inputdriver.mouse") 00243 CS_EVENTHANDLER_NIL_CONSTRAINTS 00244 00246 virtual void SetDoubleClickTime (int iTime, size_t iDist); 00247 00249 virtual void Reset (); 00250 00252 CS_PURE_METHOD virtual int GetLastX (uint n) const { return Last[n][0]; } 00254 CS_PURE_METHOD virtual int GetLastY (uint n) const { return Last[n][1]; } 00256 CS_PURE_METHOD virtual int GetLast (uint n, uint axis) const 00257 { return Last[n][axis]; } 00259 CS_PURE_METHOD virtual const int32 *GetLast (uint n) const 00260 { return Last [n]; } 00262 CS_PURE_METHOD virtual bool GetLastButton (int button) const 00263 { return GetLastButton(0, button); } 00265 CS_PURE_METHOD virtual bool GetLastButton (uint number, int button) const 00266 { 00267 return (number < CS_MAX_MOUSE_COUNT 00268 && button >= 0 && button < CS_MAX_MOUSE_BUTTONS) ? 00269 Button [number][button] : false; 00270 } 00271 00273 virtual void DoButton (uint number, int button, bool down, 00274 const int32 *axes, uint numAxes); 00275 virtual void DoButton (int button, bool down, const int32 *axes, 00276 uint numAxes) 00277 { DoButton (0, button, down, axes, numAxes); } 00278 virtual void DoButton (int button, bool down, int x, int y) 00279 { int32 axes[2] = {x, y}; DoButton (0, button, down, axes, 2); } 00281 virtual void DoMotion (uint number, const int32 *axes, uint numAxes); 00282 virtual void DoMotion (const int32 *axes, uint numAxes) 00283 { DoMotion (0, axes, numAxes); } 00284 virtual void DoMotion (int x, int y) 00285 { int32 axes[2] = {x, y}; DoMotion (0, axes, 2); } 00287 virtual void LostFocus() { Reset(); } 00288 virtual void GainFocus() { } 00289 00290 }; 00291 00292 #include "csutil/win32/msvc_deprecated_warn_off.h" 00293 00300 class CS_CRYSTALSPACE_EXPORT csJoystickDriver : public csInputDriver, 00301 public scfImplementation2<csJoystickDriver, iJoystickDriver, iEventHandler> 00302 { 00303 private: 00304 // Generic keyboard driver (for checking modifier key states). 00305 csRef<iKeyboardDriver> Keyboard; 00306 00307 protected: 00312 bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS]; 00314 int32 Last [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_AXES]; 00315 uint Axes [CS_MAX_JOYSTICK_COUNT]; 00317 iKeyboardDriver* GetKeyboardDriver(); 00318 virtual bool HandleEvent (iEvent& e) 00319 { 00320 return csInputDriver::HandleEvent (e); 00321 } 00322 public: 00323 00325 csJoystickDriver (iObjectRegistry*); 00327 virtual ~csJoystickDriver (); 00328 00329 CS_EVENTHANDLER_NAMES("crystalspace.inputdriver.joystick") 00330 CS_EVENTHANDLER_NIL_CONSTRAINTS 00331 00333 virtual void Reset (); 00334 00336 CS_DEPRECATED_METHOD CS_PURE_METHOD virtual int GetLastX (uint number) const 00337 { return Last [number][0]; } 00339 CS_DEPRECATED_METHOD CS_PURE_METHOD virtual int GetLastY (uint number) const 00340 { return Last [number][0]; } 00341 CS_PURE_METHOD virtual const int32 *GetLast (uint number) const 00342 { return Last [number]; } 00343 CS_PURE_METHOD virtual int GetLast (uint number, uint axis) const 00344 { return Last [number][axis]; } 00346 CS_PURE_METHOD virtual bool GetLastButton (uint number, int button) const 00347 { 00348 return (number < CS_MAX_JOYSTICK_COUNT 00349 && button >= 0 && button < CS_MAX_JOYSTICK_BUTTONS) ? 00350 Button [number][button] : false; 00351 } 00352 00354 virtual void DoButton (uint number, int button, bool down, 00355 const int32 *axes, uint numAxes); 00357 virtual void DoMotion (uint number, const int32 *axes, uint numAxes); 00358 00360 virtual void LostFocus() { Reset(); } 00361 virtual void GainFocus() { } 00362 00363 }; 00364 00365 #include "csutil/win32/msvc_deprecated_warn_on.h" 00366 00367 #endif // __CS_CSINPUT_H__
Generated for Crystal Space by doxygen 1.4.7