CrystalSpace

Public API Reference

csutil/eventnames.h

Go to the documentation of this file.
00001 /*
00002   Crystal Space 3D engine: Event and module naming interface
00003   (C) 2005 by Adam D. Bradley <[email protected]>
00004   
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014   
00015   You should have received a copy of the GNU Library General Public
00016   License along with this library; if not, write to the Free
00017   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_CSUTIL_EVENTNAMES_H__
00021 #define __CS_CSUTIL_EVENTNAMES_H__
00022 
00023 #include "cssysdef.h"
00024 #include "csextern.h"
00025 #include "csutil/scf_implementation.h"
00026 #include "iutil/eventnames.h"
00027 #include "iutil/objreg.h"
00028 #include "csutil/hash.h"
00029 #include "csutil/strset.h"
00030 #include "csutil/csstring.h"
00031 
00039 #ifndef CSHASHCOMPUTER_EVENTENGINE_IDS
00040 #define CSHASHCOMPUTER_EVENTENGINE_IDS
00041 template<>
00042 class csHashComputer<const csEventID>
00043 {
00044 public:
00045   static uint ComputeHash (const csEventID eid) 
00046   {
00047     return (uint) eid;
00048   }
00049 };
00050 #endif // CSHASHCOMPUTER_EVENTENGINE_IDS
00051 
00052 
00063 class CS_CRYSTALSPACE_EXPORT csEventNameRegistry :
00064   public scfImplementation1<csEventNameRegistry, iEventNameRegistry>
00065 {
00066  private:
00072   csEventNameRegistry (iObjectRegistry *);
00073  public:
00074   ~csEventNameRegistry ();
00075 
00078   CS_CONST_METHOD csEventID GetID (const char* name);
00079 
00080   CS_CONST_METHOD const char * GetString (const csEventID id);
00081   static CS_CONST_METHOD const char * GetString (iObjectRegistry *object_reg, 
00082                                                  csEventID id);
00083   CS_CONST_METHOD csEventID GetParentID (const csEventID id);
00084   CS_CONST_METHOD bool IsImmediateChildOf (const csEventID child, 
00085                                            const csEventID parent);
00086   CS_CONST_METHOD bool IsKindOf (const csEventID child, 
00087                                  const csEventID parent);
00094   static csRef<iEventNameRegistry> GetRegistry(iObjectRegistry *object_reg);
00095 
00096   static inline csEventID GetID (iEventNameRegistry *name_reg,
00097                                  const char* name) 
00098   {
00099     if (name_reg != 0)
00100       return name_reg->GetID (name);
00101     else
00102       return CS_EVENT_INVALID;
00103   }
00104   static inline csEventID GetID (iObjectRegistry *object_reg, 
00105                                  const char* name)
00106   {
00107     csRef<iEventNameRegistry> nameRegistry = 
00108       csQueryRegistry<iEventNameRegistry> (object_reg);
00109     CS_ASSERT (nameRegistry);
00110     return nameRegistry->GetID (name);
00111   };
00112 
00113   static inline bool IsKindOf (iEventNameRegistry *name_reg,
00114                                csEventID name1, csEventID name2) 
00115   {
00116     if (name_reg != 0)
00117       return name_reg->IsKindOf(name1, name2);
00118     else
00119       return false;
00120   }
00121   static inline bool IsKindOf (iObjectRegistry *object_reg, 
00122                                csEventID name1, csEventID name2)
00123   {
00124     csRef<iEventNameRegistry> nameRegistry =
00125       csQueryRegistry<iEventNameRegistry> (object_reg);
00126     CS_ASSERT(nameRegistry);
00127     return nameRegistry->IsKindOf (name1, name2);
00128   };
00129 
00130  private:
00131   iObjectRegistry *object_reg;
00132   csHash<csEventID,csEventID> parentage;
00133   csStringSet names;
00134 };
00135 
00136 
00153 #define csevAllEvents(reg)            \
00154   (csEventNameRegistry::GetID((reg), ""))
00155 
00161 #define csevFrame(reg)                \
00162   (csEventNameRegistry::GetID((reg), "crystalspace.frame"))
00163 
00167 #define csevInput(reg)                \
00168   (csEventNameRegistry::GetID((reg), "crystalspace.input"))
00169 
00174 #define csevKeyboardEvent(reg)        \
00175   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard"))
00176 
00178 #define csevKeyboardDown(reg)         \
00179   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard.down"))
00180 
00182 #define csevKeyboardUp(reg)           \
00183   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard.up"))
00184 
00186 #define csevMouseEvent(reg)           \
00187   (csEventNameRegistry::GetID((reg), "crystalspace.input.mouse"))
00188 
00189 static inline CS_CONST_METHOD csEventID csevMouse (
00190   iEventNameRegistry *name_reg, uint x)
00191 {
00192   csString name ("crystalspace.input.mouse.");
00193   name.Append (x);
00194   return name_reg->GetID(name);
00195 }
00196 
00197 static inline CS_CONST_METHOD csEventID csevMouse(
00198   iObjectRegistry *object_reg, uint x) 
00199 {
00200   return csevMouse(csEventNameRegistry::GetRegistry(object_reg), x);
00201 }
00202 
00203 static inline CS_CONST_METHOD csEventID csevMouseOp(
00204   iEventNameRegistry *name_reg, uint x, const csString &y)
00205 {
00206   csString name ("crystalspace.input.mouse.");
00207   name.Append (x);
00208   name.Append (".");
00209   name.Append (y);
00210   return name_reg->GetID(name);
00211 }
00212 
00213 static inline CS_CONST_METHOD csEventID csevMouseOp(
00214   iObjectRegistry *object_reg, uint x, const csString &y) 
00215 {
00216   return csevMouseOp(csEventNameRegistry::GetRegistry(object_reg), x, y);
00217 }
00218 
00223 #define csevMouseButton(reg,x)        \
00224   csevMouseOp ((reg), (x), "button")
00225 
00229 #define csevMouseDown(reg,x)          \
00230   csevMouseOp ((reg), (x), "button.down")
00231 
00235 #define csevMouseUp(reg,x)            \
00236   csevMouseOp ((reg), (x), "button.up")
00237 
00241 #define csevMouseClick(reg,x)         \
00242   csevMouseOp ((reg), (x), "button.click")
00243 
00247 #define csevMouseDoubleClick(reg,x)   \
00248   csevMouseOp((reg), (x), "button.doubleclick")
00249 
00253 #define csevMouseMove(reg,x)          \
00254   csevMouseOp((reg), (x), "move")
00255 
00260 #define csevJoystickEvent(reg)        \
00261   (csEventNameRegistry::GetID((reg), "crystalspace.input.joystick"))
00262 
00263 static inline CS_CONST_METHOD csEventID csevJoystick (
00264   iEventNameRegistry *name_reg, uint x) 
00265 {
00266   char buffer[64];
00267   cs_snprintf(buffer, sizeof (buffer) - 1, "crystalspace.input.joystick.%d", 
00268     x);
00269   return name_reg->GetID(buffer);
00270 }
00271 
00272 static inline CS_CONST_METHOD csEventID csevJoystick (
00273   iObjectRegistry *object_reg, uint x)
00274 {
00275   return csevJoystick(csEventNameRegistry::GetRegistry(object_reg), x);
00276 }
00277 
00278 static inline CS_CONST_METHOD csEventID csevJoystickOp (
00279   iEventNameRegistry *name_reg, uint x, const csString &y) 
00280 {
00281   csString name ("crystalspace.input.joystick.");
00282   name.Append (x);
00283   name.Append (".");
00284   name.Append (y);
00285   return name_reg->GetID(name);
00286 }
00287 
00288 static inline CS_CONST_METHOD csEventID csevJoystickOp (
00289   iObjectRegistry *object_reg, uint x, const csString &y)
00290 {
00291   return csevJoystickOp (csEventNameRegistry::GetRegistry(object_reg), x, y);
00292 }
00293 
00299 #define csevJoystickButton(reg,x)     \
00300   csevJoystickOp((reg),(x),"button")
00301 
00303 #define csevJoystickDown(reg,x)       \
00304   csevJoystickOp((reg),(x),"button.down")
00305 
00307 #define csevJoystickUp(reg,x)         \
00308   csevJoystickOp((reg),(x),"button.up")
00309 
00311 #define csevJoystickMove(reg,x)       \
00312   csevJoystickOp((reg),(x),"move")
00313 
00315 #define CS_IS_KEYBOARD_EVENT(reg,e)   \
00316   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevKeyboardEvent(reg))
00317 
00319 #define CS_IS_MOUSE_EVENT(reg,e)      \
00320   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseEvent(reg))
00321 
00323 #define CS_IS_MOUSE_BUTTON_EVENT(reg,e,n) \
00324   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseButton((reg),n))
00325 
00327 #define CS_IS_MOUSE_MOVE_EVENT(reg,e,n) \
00328   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseMove((reg),n))
00329 
00331 #define CS_IS_JOYSTICK_EVENT(reg,e)   \
00332   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickEvent(reg))
00333 
00335 #define CS_IS_JOYSTICK_BUTTON_EVENT(reg,e,n) \
00336   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickButton((reg),n))
00337 
00339 #define CS_IS_JOYSTICK_MOVE_EVENT(reg,e,n) \
00340   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickMove((reg),n))
00341 
00343 #define CS_IS_INPUT_EVENT(reg,e)      \
00344   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevInput(reg))
00345 
00354 #define csevQuit(reg)                 \
00355   (csEventNameRegistry::GetID((reg), "crystalspace.application.quit"))
00356 
00361 #define csevFocusChanged(reg)         \
00362   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus"))
00363 
00369 #define csevFocusGained(reg)          \
00370   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus.gained"))
00371 
00377 #define csevFocusLost(reg)            \
00378   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus.lost"))
00379 
00390 #define csevSystemOpen(reg)           \
00391   (csEventNameRegistry::GetID((reg), "crystalspace.application.open"))
00392 
00397 #define csevSystemClose(reg)          \
00398   (csEventNameRegistry::GetID((reg), "crystalspace.application.close"))
00399 
00400 struct iGraphics2D;
00401 
00402 CS_CRYSTALSPACE_EXPORT
00403 CS_CONST_METHOD csEventID csevCanvasOp (csRef<iEventNameRegistry>& reg, 
00404                                         const iGraphics2D* g2d, 
00405                                         const csString &y);
00406 static inline CS_CONST_METHOD csEventID csevCanvasOp (
00407   iObjectRegistry *object_reg, const iGraphics2D* g2d, const csString &y)
00408 {
00409   csRef<iEventNameRegistry> name_reg = csEventNameRegistry::GetRegistry (object_reg);
00410   return csevCanvasOp(name_reg, g2d, y);
00411 }
00412 
00413 
00421 #define csevCanvasResize(reg, g2d)      \
00422   csevCanvasOp((reg), (g2d), "resize")
00423 
00434 #define csevCanvasClose(reg, g2d)             \
00435   csevCanvasOp((reg), (g2d), "close")
00436 
00442 #define csevCanvasHidden(reg, g2d)      \
00443   csevCanvasOp((reg), (g2d), "hidden")
00444 
00449 #define csevCanvasExposed(reg, g2d)     \
00450   csevCanvasOp((reg), (g2d), "exposed")
00451 
00461 #define csevCommandLineHelp(reg)      \
00462   (csEventNameRegistry::GetID((reg), "crystalspace.application.commandlinehelp"))
00463 
00471 CS_CRYSTALSPACE_EXPORT csEventID csevPreProcess(iObjectRegistry *reg);
00472 CS_CRYSTALSPACE_EXPORT csEventID csevPreProcess(iEventNameRegistry *reg);
00473 
00478 CS_CRYSTALSPACE_EXPORT csEventID csevProcess(iObjectRegistry *reg);
00479 CS_CRYSTALSPACE_EXPORT csEventID csevProcess(iEventNameRegistry *reg);
00480 
00488 CS_CRYSTALSPACE_EXPORT csEventID csevPostProcess(iObjectRegistry *reg);
00489 CS_CRYSTALSPACE_EXPORT csEventID csevPostProcess(iEventNameRegistry *reg);
00490 
00498 CS_CRYSTALSPACE_EXPORT csEventID csevFinalProcess(iObjectRegistry *reg);
00499 CS_CRYSTALSPACE_EXPORT csEventID csevFinalProcess(iEventNameRegistry *reg);
00500 
00503 #define CS_DECLARE_SYSTEM_EVENT_SHORTCUTS                       \
00504   csEventID SystemOpen;                                         \
00505   csEventID SystemClose
00506 
00507 #define CS_DECLARE_FRAME_EVENT_SHORTCUTS                        \
00508   csEventID Frame;                                              \
00509   csEventID PreProcess;                                         \
00510   csEventID Process;                                            \
00511   csEventID PostProcess;                                        \
00512   csEventID FinalProcess
00513 
00514 #define CS_DECLARE_INPUT_EVENT_SHORTCUTS                        \
00515   csEventID KeyboardEvent;                                      \
00516   csEventID MouseEvent;                                         \
00517   csEventID JoystickEvent
00518 
00524 #define CS_DECLARE_EVENT_SHORTCUTS                              \
00525   CS_DECLARE_SYSTEM_EVENT_SHORTCUTS;                            \
00526   CS_DECLARE_FRAME_EVENT_SHORTCUTS;                             \
00527   CS_DECLARE_INPUT_EVENT_SHORTCUTS
00528 
00529 #define CS_INITIALIZE_SYSTEM_EVENT_SHORTCUTS(object_reg) do {   \
00530     SystemOpen = csevSystemOpen ((object_reg));                 \
00531     SystemClose = csevSystemClose ((object_reg));               \
00532   } while (0)
00533 
00534 #define CS_INITIALIZE_FRAME_EVENT_SHORTCUTS(object_reg) do {    \
00535     Frame = csevFrame ((object_reg));                           \
00536     PreProcess = csevPreProcess ((object_reg));                 \
00537     Process = csevProcess ((object_reg));                       \
00538     PostProcess = csevPostProcess ((object_reg));               \
00539     FinalProcess = csevFinalProcess ((object_reg));             \
00540   } while (0)
00541 
00542 #define CS_INITIALIZE_INPUT_EVENT_SHORTCUTS(object_reg) do {    \
00543     KeyboardEvent = csevKeyboardEvent ((object_reg));           \
00544     MouseEvent = csevMouseEvent ((object_reg));                 \
00545     JoystickEvent = csevJoystickEvent ((object_reg));           \
00546   } while (0)
00547 
00553 #define CS_INITIALIZE_EVENT_SHORTCUTS(object_reg) do {  \
00554     CS_INITIALIZE_SYSTEM_EVENT_SHORTCUTS (object_reg);  \
00555     CS_INITIALIZE_FRAME_EVENT_SHORTCUTS (object_reg);   \
00556     CS_INITIALIZE_INPUT_EVENT_SHORTCUTS (object_reg);   \
00557   } while (0)
00558 
00561 #endif // __CS_CSUTIL_EVENTNAMES_H__

Generated for Crystal Space by doxygen 1.4.7