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/array.h" 00033 #include "csutil/hash.h" 00034 #include "csutil/scf.h" 00035 #include "csutil/scf_implementation.h" 00036 00037 #include "iutil/csinput.h" 00038 #include "iutil/eventh.h" 00039 #include "iutil/comp.h" 00040 00041 struct iEvent; 00042 struct iEventQueue; 00043 struct iObjectRegistry; 00044 00048 class CS_CRYSTALSPACE_EXPORT csInputDriver 00049 { 00050 private: 00051 bool Registered; 00052 protected: 00053 iObjectRegistry* Registry; 00054 csRef<iEventNameRegistry> NameRegistry; 00055 iEventHandler* Listener; 00056 csEventID FocusChanged; 00057 csEventID FocusGained; 00058 csEventID FocusLost; 00059 csInputDriver(iObjectRegistry*); 00060 virtual ~csInputDriver(); 00061 csPtr<iEventQueue> GetEventQueue(); 00062 virtual void GainFocus() = 0; 00063 virtual void LostFocus() = 0; 00064 virtual void Post(iEvent*); 00065 virtual bool HandleEvent(iEvent&); 00066 friend struct FocusListener; 00067 void StartListening(); 00068 void StopListening(); 00069 }; 00070 00071 class CS_CRYSTALSPACE_EXPORT csKeyComposer : 00072 public scfImplementation1<csKeyComposer, iKeyComposer> 00073 { 00074 protected: 00075 utf32_char lastDead; 00076 00077 public: 00078 csKeyComposer (); 00079 virtual ~csKeyComposer (); 00080 00081 virtual csKeyComposeResult HandleKey (const csKeyEventData& keyEventData, 00082 utf32_char* buf, size_t bufChars, int* resultChars = 0); 00083 virtual void ResetState (); 00084 }; 00085 00086 #ifdef CS_DEBUG 00087 #ifndef CS_KEY_DEBUG_ENABLE 00088 00092 #define CS_KEY_DEBUG_ENABLE 00093 #endif 00094 #endif 00095 00101 class CS_CRYSTALSPACE_EXPORT csKeyboardDriver : public csInputDriver, 00102 public scfImplementation2<csKeyboardDriver, iKeyboardDriver, iEventHandler> 00103 { 00104 protected: 00106 csHash<bool, utf32_char> keyStates; 00107 csKeyModifiers modifiersState; 00108 bool keyDebug; 00109 bool keyDebugChecked; 00110 csEventID KeyboardUp; 00111 csEventID KeyboardDown; 00112 00117 virtual void SetKeyState (utf32_char codeRaw, bool iDown, 00118 bool autoRepeat); 00123 virtual void SynthesizeCooked (utf32_char codeRaw, 00124 const csKeyModifiers& modifiers, utf32_char& codeCooked); 00125 00126 const char* GetKeycodeString (utf32_char code); 00127 bool IsKeyboardDebugging (); 00128 00130 virtual void LostFocus() { Reset(); } 00131 virtual void GainFocus() { RestoreKeys(); } 00132 00133 virtual bool HandleEvent (iEvent& e) 00134 { 00135 return csInputDriver::HandleEvent (e); 00136 } 00137 public: 00139 csKeyboardDriver (iObjectRegistry*); 00141 virtual ~csKeyboardDriver (); 00142 00143 CS_EVENTHANDLER_NAMES("crystalspace.inputdriver.keyboard") 00144 CS_EVENTHANDLER_NIL_CONSTRAINTS 00145 00147 virtual void Reset (); 00149 virtual void RestoreKeys (); 00150 00161 virtual void DoKey (utf32_char codeRaw, utf32_char codeCooked, bool iDown, 00162 bool autoRepeat = false, csKeyCharType charType = csKeyCharTypeNormal); 00163 00168 CS_PURE_METHOD virtual bool GetKeyState (utf32_char codeRaw) const; 00169 00188 CS_PURE_METHOD virtual uint32 GetModifierState (utf32_char codeRaw) const; 00189 00190 virtual csPtr<iKeyComposer> CreateKeyComposer (); 00191 00193 virtual csEventError SynthesizeCooked (iEvent *); 00194 00195 }; 00196 00205 class CS_CRYSTALSPACE_EXPORT csMouseDriver : public csInputDriver, 00206 public scfImplementation2<csMouseDriver, iMouseDriver, iEventHandler> 00207 { 00208 private: 00209 // Generic keyboard driver (for checking modifier key states). 00210 csRef<iKeyboardDriver> Keyboard; 00211 00212 virtual bool HandleEvent (iEvent& e) 00213 { 00214 return csInputDriver::HandleEvent (e); 00215 } 00216 protected: 00218 csTicks LastClickTime[CS_MAX_MOUSE_COUNT]; 00220 int LastClickButton[CS_MAX_MOUSE_COUNT]; 00222 int LastClick [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES]; 00224 int32 Last [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_AXES]; 00225 uint Axes [CS_MAX_MOUSE_COUNT]; 00230 bool Button [CS_MAX_MOUSE_COUNT][CS_MAX_MOUSE_BUTTONS]; 00232 csTicks DoubleClickTime; 00234 size_t DoubleClickDist; 00236 iKeyboardDriver* GetKeyboardDriver(); 00237 00238 public: 00240 csMouseDriver (iObjectRegistry*); 00242 virtual ~csMouseDriver (); 00243 00244 CS_EVENTHANDLER_NAMES("crystalspace.inputdriver.mouse") 00245 CS_EVENTHANDLER_NIL_CONSTRAINTS 00246 00248 virtual void SetDoubleClickTime (int iTime, size_t iDist); 00249 00251 virtual void Reset (); 00252 00254 CS_PURE_METHOD virtual int GetLastX (uint n) const { return Last[n][0]; } 00256 CS_PURE_METHOD virtual int GetLastY (uint n) const { return Last[n][1]; } 00258 CS_PURE_METHOD virtual int GetLast (uint n, uint axis) const 00259 { return Last[n][axis]; } 00261 CS_PURE_METHOD virtual const int32 *GetLast (uint n) const 00262 { return Last [n]; } 00264 CS_PURE_METHOD virtual bool GetLastButton (int button) const 00265 { return GetLastButton(0, button); } 00267 CS_PURE_METHOD virtual bool GetLastButton (uint number, int button) const 00268 { 00269 return (number < CS_MAX_MOUSE_COUNT 00270 && button >= 0 && button < CS_MAX_MOUSE_BUTTONS) ? 00271 Button [number][button] : false; 00272 } 00273 00275 virtual void DoButton (uint number, int button, bool down, 00276 const int32 *axes, uint numAxes); 00277 virtual void DoButton (int button, bool down, const int32 *axes, 00278 uint numAxes) 00279 { DoButton (0, button, down, axes, numAxes); } 00280 virtual void DoButton (int button, bool down, int x, int y) 00281 { int32 axes[2] = {x, y}; DoButton (0, button, down, axes, 2); } 00283 virtual void DoMotion (uint number, const int32 *axes, uint numAxes); 00284 virtual void DoMotion (const int32 *axes, uint numAxes) 00285 { DoMotion (0, axes, numAxes); } 00286 virtual void DoMotion (int x, int y) 00287 { int32 axes[2] = {x, y}; DoMotion (0, axes, 2); } 00289 virtual void LostFocus() { Reset(); } 00290 virtual void GainFocus() { } 00291 00292 }; 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 #endif // __CS_CSINPUT_H__
Generated for Crystal Space by doxygen 1.4.6