csutil/event.h
Go to the documentation of this file.00001 /* 00002 Event system related helpers 00003 Copyright (C) 2003 by Jorrit Tyberghein 00004 (C) 2003 by Frank Richter 00005 (C) 2005 by Adam D. Bradley <artdodge@cs.bu.edu> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public 00018 License along with this library; if not, write to the Free 00019 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 00022 #ifndef __CS_CSUTIL_EVENT_H__ 00023 #define __CS_CSUTIL_EVENT_H__ 00024 00025 #include "csextern.h" 00026 #include "iutil/event.h" 00027 #include "iutil/eventhandlers.h" 00028 00041 class CS_CRYSTALSPACE_EXPORT csKeyEventHelper 00042 { 00043 public: 00045 static utf32_char GetRawCode (const iEvent* event); 00047 static utf32_char GetCookedCode (const iEvent* event); 00049 static void GetModifiers (const iEvent* event, csKeyModifiers& modifiers); 00051 static csKeyEventType GetEventType (const iEvent* event); 00056 static bool GetAutoRepeat (const iEvent* event); 00058 static csKeyCharType GetCharacterType (const iEvent* event); 00060 static bool GetEventData (const iEvent* event, csKeyEventData& data); 00066 static uint32 GetModifiersBits ( 00067 const csKeyModifiers& modifiers); 00072 static uint32 GetModifiersBits (const iEvent* event); 00077 static void GetModifiers (uint32 mask, csKeyModifiers& modifiers); 00078 }; 00081 /* forward declaration */ 00082 class csEvent; 00083 00089 class CS_CRYSTALSPACE_EXPORT csMouseEventHelper 00090 { 00091 public: 00093 00094 static csEvent *NewEvent (csRef<iEventNameRegistry> ®, 00095 csTicks, csEventID name, csMouseEventType etype, int x, int y, 00096 uint32 AxesChanged, uint button, bool buttonstate, uint32 buttonMask, 00097 const csKeyModifiers& modifiers); 00098 static csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks, 00099 csEventID name, uint8 n, csMouseEventType etype, int x, int y, 00100 uint32 axesChanged, uint button, bool buttonstate, uint32 buttonMask, 00101 const csKeyModifiers& modifiers); 00102 static csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks, 00103 csEventID name, uint8 n, csMouseEventType etype, const int32 *axes, 00104 uint8 numAxes, uint32 axesChanged, uint button, bool buttonstate, 00105 uint32 buttonMask, const csKeyModifiers& modifiers); 00107 00108 // Deprecated in 1.3. 00109 static CS_DEPRECATED_METHOD_MSG("Use the variant with csKeyModifiers modifiers") 00110 csEvent *NewEvent (csRef<iEventNameRegistry> ®, 00111 csTicks t, csEventID name, csMouseEventType etype, int x, int y, 00112 uint32 AxesChanged, uint button, bool buttonstate, uint32 buttonMask, 00113 uint32 modifiers) 00114 { 00115 csKeyModifiers m; 00116 csKeyEventHelper::GetModifiers (modifiers, m); 00117 return NewEvent (reg, t, name, etype, x, y, AxesChanged, button, 00118 buttonstate, buttonMask, m); 00119 } 00120 // Deprecated in 1.3. 00121 static CS_DEPRECATED_METHOD_MSG("Use the variant with csKeyModifiers modifiers") 00122 csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks t, 00123 csEventID name, uint8 n, csMouseEventType etype, int x, int y, 00124 uint32 axesChanged, uint button, bool buttonstate, uint32 buttonMask, 00125 uint32 modifiers) 00126 { 00127 csKeyModifiers m; 00128 csKeyEventHelper::GetModifiers (modifiers, m); 00129 return NewEvent (reg, t, name, n, etype, x, y, axesChanged, button, 00130 buttonstate, buttonMask, m); 00131 } 00132 // Deprecated in 1.3. 00133 static CS_DEPRECATED_METHOD_MSG("Use the variant with csKeyModifiers modifiers") 00134 csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks t, 00135 csEventID name, uint8 n, csMouseEventType etype, const int32 *axes, 00136 uint8 numAxes, uint32 axesChanged, uint button, bool buttonstate, 00137 uint32 buttonMask, uint32 modifiers) 00138 { 00139 csKeyModifiers m; 00140 csKeyEventHelper::GetModifiers (modifiers, m); 00141 return NewEvent (reg, t, name, n, etype, axes, numAxes, axesChanged, 00142 button, buttonstate, buttonMask, m); 00143 } 00144 00146 static csMouseEventType GetEventType (const iEvent* event); 00148 static uint GetNumber(const iEvent *event); 00150 static int GetX(const iEvent *event) 00151 { return csMouseEventHelper::GetAxis(event, 0); } 00153 static int GetY(const iEvent *event) 00154 { return csMouseEventHelper::GetAxis(event, 1); } 00156 static int GetAxis(const iEvent *event, uint axis); 00158 static uint GetNumAxes(const iEvent *event); 00160 static uint GetButton(const iEvent *event); 00162 static bool GetButtonState(const iEvent *event); 00164 static uint32 GetButtonMask(const iEvent *event); 00166 static void GetModifiers(const iEvent *event, 00167 csKeyModifiers& modifiers) 00168 { csKeyEventHelper::GetModifiers(event, modifiers); } 00170 static uint32 GetModifiers(const iEvent *event) 00171 { 00172 csKeyModifiers modifiers; 00173 csKeyEventHelper::GetModifiers(event, modifiers); 00174 return csKeyEventHelper::GetModifiersBits(modifiers); 00175 } 00177 static bool GetEventData (const iEvent* event, 00178 csMouseEventData& data); 00179 }; 00180 00188 class CS_CRYSTALSPACE_EXPORT csJoystickEventHelper 00189 { 00190 public: 00192 00193 static csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks, 00194 csEventID name, int n, int x, int y, uint32 axesChanged, uint button, 00195 bool buttonState, uint32 buttonMask, const csKeyModifiers& modifiers); 00196 static csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks, 00197 csEventID name, int n, const int32* axes, uint8 numAxes, uint32 axesChanged, 00198 uint button, bool buttonState, uint32 buttonMask, const csKeyModifiers& modifiers); 00200 00201 // Deprecated in 1.3. 00202 static CS_DEPRECATED_METHOD_MSG("Use the variant with csKeyModifiers modifiers") 00203 csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks t, 00204 csEventID name, int n, int x, int y, uint32 axesChanged, uint button, 00205 bool buttonState, uint32 buttonMask, uint32 modifiers) 00206 { 00207 csKeyModifiers m; 00208 csKeyEventHelper::GetModifiers (modifiers, m); 00209 return NewEvent (reg, t, name, n, x, y, axesChanged, button, 00210 buttonState, buttonMask, m); 00211 } 00212 // Deprecated in 1.3. 00213 static CS_DEPRECATED_METHOD_MSG("Use the variant with csKeyModifiers modifiers") 00214 csEvent *NewEvent (csRef<iEventNameRegistry> ®, csTicks t, 00215 csEventID name, int n, const int32* axes, uint8 numAxes, uint32 axesChanged, 00216 uint button, bool buttonState, uint32 buttonMask, uint32 modifiers) 00217 { 00218 csKeyModifiers m; 00219 csKeyEventHelper::GetModifiers (modifiers, m); 00220 return NewEvent (reg, t, name, n, axes, numAxes, axesChanged, button, 00221 buttonState, buttonMask, m); 00222 } 00223 00225 static uint GetNumber(const iEvent *event); 00227 static int GetAxis(const iEvent *event, uint); 00229 static uint GetNumAxes(const iEvent *); 00231 static uint GetButton(const iEvent *event); 00233 static bool GetButtonState(const iEvent *event); 00235 static uint32 GetButtonMask(const iEvent *event); 00237 static void GetModifiers(const iEvent *event, csKeyModifiers& modifiers) 00238 { csKeyEventHelper::GetModifiers(event, modifiers); } 00240 static uint32 GetModifiers(const iEvent *event) 00241 { 00242 csKeyModifiers modifiers; 00243 csKeyEventHelper::GetModifiers(event, modifiers); 00244 return csKeyEventHelper::GetModifiersBits(modifiers); 00245 } 00247 static bool GetEventData (const iEvent* event, csJoystickEventData& data); 00248 }; 00249 00257 class CS_CRYSTALSPACE_EXPORT csInputEventHelper 00258 { 00259 public: 00261 static uint GetButton (iEventNameRegistry *, 00262 const iEvent *event); 00264 static bool GetButtonState (iEventNameRegistry *, 00265 const iEvent *event); 00266 }; 00267 00275 class CS_CRYSTALSPACE_EXPORT csCommandEventHelper 00276 { 00277 public: 00279 static csEvent *NewEvent (csTicks, csEventID name, bool Broadcast, 00280 intptr_t info = 0); 00281 00283 static uint GetCode(const iEvent *event); 00285 static intptr_t GetInfo(const iEvent *event); 00287 static bool GetEventData (const iEvent* event, csCommandEventData& data); 00288 }; 00289 00292 struct iEventQueue; 00293 struct iObjectRegistry; 00294 00295 namespace CS 00296 { 00297 00303 csHandlerID CS_CRYSTALSPACE_EXPORT RegisterWeakListener (iEventQueue *q, 00304 iEventHandler *listener, csRef<iEventHandler> &handler); 00305 csHandlerID CS_CRYSTALSPACE_EXPORT RegisterWeakListener (iEventQueue *q, 00306 iEventHandler *listener, const csEventID &ename, csRef<iEventHandler> &handler); 00307 csHandlerID CS_CRYSTALSPACE_EXPORT RegisterWeakListener (iEventQueue *q, 00308 iEventHandler *listener, const csEventID ename[], csRef<iEventHandler> &handler); 00309 00314 void CS_CRYSTALSPACE_EXPORT RemoveWeakListener (iEventQueue *q, 00315 csRef<iEventHandler> &handler); 00316 00317 } // namespace CS 00318 00321 #endif // __CS_CSUTIL_EVENT_H__
Generated for Crystal Space 1.4.0 by doxygen 1.5.8