|
csinput.h00001 /* 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 00029 #include "csutil/scf.h" 00030 #include "csutil/bitset.h" 00031 #include "iutil/csinput.h" 00032 #include "iutil/eventh.h" 00033 #include "iutil/comp.h" 00034 struct iEvent; 00035 struct iEventQueue; 00036 struct iObjectRegistry; 00037 00041 class csInputDriver 00042 { 00043 private: 00044 bool Registered; 00045 protected: 00046 iObjectRegistry* Registry; 00047 iEventHandler* Listener; 00048 csInputDriver(iObjectRegistry*); 00049 virtual ~csInputDriver(); 00050 iEventQueue* GetEventQueue(); 00051 virtual void LostFocus() = 0; 00052 virtual void Post(iEvent*); 00053 virtual bool HandleEvent(iEvent&); 00054 friend struct FocusListener; 00055 void StartListening(); 00056 void StopListening(); 00057 }; 00058 00064 class csKeyboardDriver : public csInputDriver, public iKeyboardDriver 00065 { 00066 protected: 00068 csBitSet KeyState; 00069 00074 virtual void SetKeyState (int iKey, bool iDown); 00075 00076 public: 00077 SCF_DECLARE_IBASE; 00078 00080 csKeyboardDriver (iObjectRegistry*); 00082 virtual ~csKeyboardDriver (); 00083 00085 virtual void Reset (); 00086 00088 virtual void DoKey (int iKey, int iChar, bool iDown); 00089 00095 virtual bool GetKeyState (int iKey); 00096 00098 virtual void LostFocus() { Reset(); } 00099 00100 struct eiEventHandler : public iEventHandler 00101 { 00102 SCF_DECLARE_EMBEDDED_IBASE(csKeyboardDriver); 00103 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00104 } scfiEventHandler; 00105 friend struct eiEventHandler; 00106 }; 00107 00113 class csMouseDriver : public csInputDriver, public iMouseDriver 00114 { 00115 private: 00116 // Generic keyboard driver (for checking modifier key states). 00117 iKeyboardDriver* Keyboard; 00118 00119 protected: 00121 csTicks LastClickTime; 00123 int LastClickButton; 00125 int LastClickX, LastClickY; 00127 int LastX, LastY; 00129 bool Button [CS_MAX_MOUSE_BUTTONS]; 00131 csTicks DoubleClickTime; 00133 size_t DoubleClickDist; 00135 iKeyboardDriver* GetKeyboardDriver(); 00136 00137 public: 00138 SCF_DECLARE_IBASE; 00139 00141 csMouseDriver (iObjectRegistry*); 00143 virtual ~csMouseDriver (); 00144 00146 virtual void SetDoubleClickTime (int iTime, size_t iDist); 00147 00149 virtual void Reset (); 00150 00152 virtual int GetLastX () { return LastX; } 00154 virtual int GetLastY () { return LastY; } 00156 virtual bool GetLastButton (int button) 00157 { 00158 return (button > 0 && button <= CS_MAX_MOUSE_BUTTONS) ? 00159 Button [button - 1] : false; 00160 } 00161 00163 virtual void DoButton (int button, bool down, int x, int y); 00165 virtual void DoMotion (int x, int y); 00166 00168 virtual void LostFocus() { Reset(); } 00169 00170 struct eiEventHandler : public iEventHandler 00171 { 00172 SCF_DECLARE_EMBEDDED_IBASE(csMouseDriver); 00173 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00174 } scfiEventHandler; 00175 friend struct eiEventHandler; 00176 }; 00177 00183 class csJoystickDriver : public csInputDriver, public iJoystickDriver 00184 { 00185 private: 00186 // Generic keyboard driver (for checking modifier key states). 00187 iKeyboardDriver* Keyboard; 00188 protected: 00190 bool Button [CS_MAX_JOYSTICK_COUNT][CS_MAX_JOYSTICK_BUTTONS]; 00192 int LastX [CS_MAX_JOYSTICK_COUNT], LastY [CS_MAX_JOYSTICK_COUNT]; 00194 iKeyboardDriver* GetKeyboardDriver(); 00195 00196 public: 00197 SCF_DECLARE_IBASE; 00198 00200 csJoystickDriver (iObjectRegistry*); 00202 virtual ~csJoystickDriver (); 00203 00205 virtual void Reset (); 00206 00208 virtual int GetLastX (int number) { return LastX [number]; } 00210 virtual int GetLastY (int number) { return LastY [number]; } 00212 virtual bool GetLastButton (int number, int button) 00213 { 00214 return (number > 0 && number <= CS_MAX_JOYSTICK_COUNT 00215 && button > 0 && button <= CS_MAX_JOYSTICK_BUTTONS) ? 00216 Button [number - 1] [button - 1] : false; 00217 } 00218 00220 virtual void DoButton (int number, int button, bool down, int x, int y); 00222 virtual void DoMotion (int number, int x, int y); 00223 00225 virtual void LostFocus() { Reset(); } 00226 00227 struct eiEventHandler : public iEventHandler 00228 { 00229 SCF_DECLARE_EMBEDDED_IBASE (csJoystickDriver); 00230 virtual bool HandleEvent(iEvent& e) { return scfParent->HandleEvent(e); } 00231 } scfiEventHandler; 00232 friend struct eiEventHandler; 00233 }; 00234 00235 #endif // __CS_CSINPUT_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |