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 "scf.h" 00030 #include "array.h" 00031 #include "hash.h" 00032 #include "iutil/csinput.h" 00033 #include "iutil/eventh.h" 00034 #include "iutil/comp.h" 00035 00036 struct iEvent; 00037 struct iEventQueue; 00038 struct iObjectRegistry; 00039 00043 class csInputDriver 00044 { 00045 private: 00046 bool Registered; 00047 protected: 00048 iObjectRegistry* Registry; 00049 iEventHandler* Listener; 00050 csInputDriver(iObjectRegistry*); 00051 virtual ~csInputDriver(); 00052 csPtr<iEventQueue> GetEventQueue(); 00053 virtual void LostFocus() = 0; 00054 virtual void Post(iEvent*); 00055 virtual bool HandleEvent(iEvent&); 00056 friend struct FocusListener; 00057 void StartListening(); 00058 void StopListening(); 00059 }; 00060 00061 class csKeyComposer : public iKeyComposer 00062 { 00063 protected: 00064 utf32_char lastDead; 00065 00066 public: 00067 SCF_DECLARE_IBASE; 00068 00069 csKeyComposer (); 00070 virtual ~csKeyComposer (); 00071 00072 virtual csKeyComposeResult HandleKey (const csKeyEventData& keyEventData, 00073 utf32_char* buf, size_t bufChars, int* resultChars = 0); 00074 virtual void ResetState (); 00075 }; 00076 00082 class csKeyboardDriver : public csInputDriver, public iKeyboardDriver 00083 { 00084 protected: 00086 csHash<bool, utf32_char> keyStates; 00087 csKeyModifiers modifiersState; 00088 00093 virtual void SetKeyState (utf32_char codeRaw, bool iDown, 00094 bool autoRepeat); 00099 virtual void SynthesizeCooked (utf32_char codeRaw, 00100 const csKeyModifiers& modifiers, utf32_char& codeCooked); 00101 public: 00102 SCF_DECLARE_IBASE; 00103 00105 csKeyboardDriver (iObjectRegistry*); 00107 virtual ~csKeyboardDriver (); 00108 00110 virtual void Reset (); 00111 00122 virtual void DoKey (utf32_char codeRaw, utf32_char codeCooked, bool iDown, 00123 bool autoRepeat = false, csKeyCharType charType = csKeyCharTypeNormal); 00124 00130 virtual bool GetKeyState (utf32_char codeRaw); 00131 00150 virtual uint32 GetModifierState (utf32_char codeRaw); 00151 00152 virtual csPtr<iKeyComposer> CreateKeyComposer (); 00153 00155 virtual void LostFocus() { Reset(); } 00156 00158 struct eiEventHandler : public iEventHandler 00159 { 00160 SCF_DECLARE_EMBEDDED_IBASE(csKeyboardDriver); 00161 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00162 } scfiEventHandler; 00163 friend struct eiEventHandler; 00164 }; 00165 00171 class csMouseDriver : public csInputDriver, public iMouseDriver 00172 { 00173 private: 00174 // Generic keyboard driver (for checking modifier key states). 00175 csRef<iKeyboardDriver> Keyboard; 00176 00177 protected: 00179 csTicks LastClickTime; 00181 int LastClickButton; 00183 int LastClickX, LastClickY; 00185 int LastX, LastY; 00187 bool Button [CS_MAX_MOUSE_BUTTONS]; 00189 csTicks DoubleClickTime; 00191 size_t DoubleClickDist; 00193 iKeyboardDriver* GetKeyboardDriver(); 00194 00195 public: 00196 SCF_DECLARE_IBASE; 00197 00199 csMouseDriver (iObjectRegistry*); 00201 virtual ~csMouseDriver (); 00202 00204 virtual void SetDoubleClickTime (int iTime, size_t iDist); 00205 00207 virtual void Reset (); 00208 00210 virtual int GetLastX () { return LastX; } 00212 virtual int GetLastY () { return LastY; } 00214 virtual bool GetLastButton (int button) 00215 { 00216 return (button > 0 && button <= CS_MAX_MOUSE_BUTTONS) ? 00217 Button [button - 1] : false; 00218 } 00219 00221 virtual void DoButton (int button, bool down, int x, int y); 00223 virtual void DoMotion (int x, int y); 00224 00226 virtual void LostFocus() { Reset(); } 00227 00229 struct eiEventHandler : public iEventHandler 00230 { 00231 SCF_DECLARE_EMBEDDED_IBASE(csMouseDriver); 00232 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00233 } scfiEventHandler; 00234 friend struct eiEventHandler; 00235 }; 00236 00242 class csJoystickDriver : public csInputDriver, public iJoystickDriver 00243 { 00244 private: 00245 // Generic keyboard driver (for checking modifier key states). 00246 csRef<iKeyboardDriver> Keyboard; 00247 protected: 00249 bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS]; 00251 int LastX [CS_MAX_JOYSTICK_COUNT], LastY [CS_MAX_JOYSTICK_COUNT]; 00253 iKeyboardDriver* GetKeyboardDriver(); 00254 00255 public: 00256 SCF_DECLARE_IBASE; 00257 00259 csJoystickDriver (iObjectRegistry*); 00261 virtual ~csJoystickDriver (); 00262 00264 virtual void Reset (); 00265 00267 virtual int GetLastX (int number) { return LastX [number]; } 00269 virtual int GetLastY (int number) { return LastY [number]; } 00271 virtual bool GetLastButton (int number, int button) 00272 { 00273 return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT 00274 && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ? 00275 Button [number - 1] [button - 1] : false; 00276 } 00277 00279 virtual void DoButton (int number, int button, bool down, int x, int y); 00281 virtual void DoMotion (int number, int x, int y); 00282 00284 virtual void LostFocus() { Reset(); } 00285 00287 struct eiEventHandler : public iEventHandler 00288 { 00289 SCF_DECLARE_EMBEDDED_IBASE (csJoystickDriver); 00290 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00291 } scfiEventHandler; 00292 friend struct eiEventHandler; 00293 }; 00294 00295 #endif // __CS_CSINPUT_H__
Generated for Crystal Space by doxygen 1.2.18