## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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 <artdodge@cs.bu.edu>
    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
    00038 #ifndef CSHASHCOMPUTER_EVENTENGINE_IDS
    00039 #define CSHASHCOMPUTER_EVENTENGINE_IDS
    00040 CS_SPECIALIZE_TEMPLATE
    00041 class csHashComputer<const csEventID>
    00042 {
    00043 public:
    00044   static uint ComputeHash (const csEventID eid)
    00045   {
    00046     return (uint) eid;
    00047   }
    00048 };
    00049 #endif // CSHASHCOMPUTER_EVENTENGINE_IDS
    00050
    00051
    00062 class CS_CRYSTALSPACE_EXPORT csEventNameRegistry :
    00063   public scfImplementation1<csEventNameRegistry, iEventNameRegistry>
    00064 {
    00065  private:
    00071   csEventNameRegistry (iObjectRegistry *);
    00072  public:
    00073   ~csEventNameRegistry ();
    00074
    00077   CS_CONST_METHOD csEventID GetID (const csString &name);
    00078   CS_CONST_METHOD const char * GetString (const csEventID id);
    00079   static CS_CONST_METHOD const char * GetString (iObjectRegistry *object_reg,
    00080                                                  csEventID id);
    00081   CS_CONST_METHOD csEventID GetParentID (const csEventID id);
    00082   CS_CONST_METHOD bool IsImmediateChildOf (const csEventID child,
    00083                                            const csEventID parent);
    00084   CS_CONST_METHOD bool IsKindOf (const csEventID child,
    00085                                  const csEventID parent);
    00092   static csRef<iEventNameRegistry> GetRegistry(iObjectRegistry *object_reg);
    00093
    00094   static inline csEventID GetID (iEventNameRegistry *name_reg,
    00095                                  const csString & name)
    00096   {
    00097     if (name_reg != 0)
    00098       return name_reg->GetID (name);
    00099     else
    00100       return CS_EVENT_INVALID;
    00101   }
    00102   static inline csEventID GetID (iObjectRegistry *object_reg,
    00103                                  const csString & name)
    00104   {
    00105     csRef<iEventNameRegistry> nameRegistry =
    00106       csQueryRegistry<iEventNameRegistry> (object_reg);
    00107     CS_ASSERT (nameRegistry);
    00108     return nameRegistry->GetID (name);
    00109   };
    00110
    00111   static inline bool IsKindOf (iEventNameRegistry *name_reg,
    00112                                csEventID name1, csEventID name2)
    00113   {
    00114     if (name_reg != 0)
    00115       return name_reg->IsKindOf(name1, name2);
    00116     else
    00117       return false;
    00118   }
    00119   static inline bool IsKindOf (iObjectRegistry *object_reg,
    00120                                csEventID name1, csEventID name2)
    00121   {
    00122     csRef<iEventNameRegistry> nameRegistry =
    00123       csQueryRegistry<iEventNameRegistry> (object_reg);
    00124     CS_ASSERT(nameRegistry);
    00125     return nameRegistry->IsKindOf (name1, name2);
    00126   };
    00127
    00128  private:
    00129   iObjectRegistry *object_reg;
    00130   csHash<csEventID,csEventID> parentage;
    00131   csStringSet names;
    00132 };
    00133
    00134
    00151 #define csevAllEvents(reg)            \
    00152   (csEventNameRegistry::GetID((reg), ""))
    00153
    00159 #define csevFrame(reg)                \
    00160   (csEventNameRegistry::GetID((reg), "crystalspace.frame"))
    00161
    00165 #define csevInput(reg)                \
    00166   (csEventNameRegistry::GetID((reg), "crystalspace.input"))
    00167
    00172 #define csevKeyboardEvent(reg)        \
    00173   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard"))
    00174
    00176 #define csevKeyboardDown(reg)         \
    00177   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard.down"))
    00178
    00180 #define csevKeyboardUp(reg)           \
    00181   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard.up"))
    00182
    00184 #define csevMouseEvent(reg)           \
    00185   (csEventNameRegistry::GetID((reg), "crystalspace.input.mouse"))
    00186
    00187 static inline CS_CONST_METHOD csEventID csevMouse (
    00188   iEventNameRegistry *name_reg, uint x)
    00189 {
    00190   csString name ("crystalspace.input.mouse.");
    00191   name.Append (x);
    00192   return name_reg->GetID(name);
    00193 }
    00194
    00195 static inline CS_CONST_METHOD csEventID csevMouse(
    00196   iObjectRegistry *object_reg, uint x)
    00197 {
    00198   return csevMouse(csEventNameRegistry::GetRegistry(object_reg), x);
    00199 }
    00200
    00201 static inline CS_CONST_METHOD csEventID csevMouseOp(
    00202   iEventNameRegistry *name_reg, uint x, const csString &y)
    00203 {
    00204   csString name ("crystalspace.input.mouse.");
    00205   name.Append (x);
    00206   name.Append (".");
    00207   name.Append (y);
    00208   return name_reg->GetID(name);
    00209 }
    00210
    00211 static inline CS_CONST_METHOD csEventID csevMouseOp(
    00212   iObjectRegistry *object_reg, uint x, const csString &y)
    00213 {
    00214   return csevMouseOp(csEventNameRegistry::GetRegistry(object_reg), x, y);
    00215 }
    00216
    00221 #define csevMouseButton(reg,x)        \
    00222   csevMouseOp ((reg), (x), "button")
    00223
    00227 #define csevMouseDown(reg,x)          \
    00228   csevMouseOp ((reg), (x), "button.down")
    00229
    00233 #define csevMouseUp(reg,x)            \
    00234   csevMouseOp ((reg), (x), "button.up")
    00235
    00239 #define csevMouseClick(reg,x)         \
    00240   csevMouseOp ((reg), (x), "button.click")
    00241
    00245 #define csevMouseDoubleClick(reg,x)   \
    00246   csevMouseOp((reg), (x), "button.doubleclick")
    00247
    00251 #define csevMouseMove(reg,x)          \
    00252   csevMouseOp((reg), (x), "move")
    00253
    00258 #define csevJoystickEvent(reg)        \
    00259   (csEventNameRegistry::GetID((reg), "crystalspace.input.joystick"))
    00260
    00261 static inline CS_CONST_METHOD csEventID csevJoystick (
    00262   iEventNameRegistry *name_reg, uint x)
    00263 {
    00264   char buffer[64];
    00265   cs_snprintf(buffer, sizeof (buffer) - 1, "crystalspace.input.joystick.%d",
    00266     x);
    00267   return name_reg->GetID(buffer);
    00268 }
    00269
    00270 static inline CS_CONST_METHOD csEventID csevJoystick (
    00271   iObjectRegistry *object_reg, uint x)
    00272 {
    00273   return csevJoystick(csEventNameRegistry::GetRegistry(object_reg), x);
    00274 }
    00275
    00276 static inline CS_CONST_METHOD csEventID csevJoystickOp (
    00277   iEventNameRegistry *name_reg, uint x, const csString &y)
    00278 {
    00279   csString name ("crystalspace.input.joystick.");
    00280   name.Append (x);
    00281   name.Append (".");
    00282   name.Append (y);
    00283   return name_reg->GetID(name);
    00284 }
    00285
    00286 static inline CS_CONST_METHOD csEventID csevJoystickOp (
    00287   iObjectRegistry *object_reg, uint x, const csString &y)
    00288 {
    00289   return csevJoystickOp (csEventNameRegistry::GetRegistry(object_reg), x, y);
    00290 }
    00291
    00297 #define csevJoystickButton(reg,x)     \
    00298   csevJoystickOp((reg),(x),"button")
    00299
    00301 #define csevJoystickDown(reg,x)       \
    00302   csevJoystickOp((reg),(x),"button.down")
    00303
    00305 #define csevJoystickUp(reg,x)         \
    00306   csevJoystickOp((reg),(x),"button.up")
    00307
    00309 #define csevJoystickMove(reg,x)       \
    00310   csevJoystickOp((reg),(x),"move")
    00311
    00313 #define CS_IS_KEYBOARD_EVENT(reg,e)   \
    00314   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevKeyboardEvent(reg))
    00315
    00317 #define CS_IS_MOUSE_EVENT(reg,e)      \
    00318   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseEvent(reg))
    00319
    00321 #define CS_IS_MOUSE_BUTTON_EVENT(reg,e,n) \
    00322   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseButton((reg),n))
    00323
    00325 #define CS_IS_MOUSE_MOVE_EVENT(reg,e,n) \
    00326   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseMove((reg),n))
    00327
    00329 #define CS_IS_JOYSTICK_EVENT(reg,e)   \
    00330   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickEvent(reg))
    00331
    00333 #define CS_IS_JOYSTICK_BUTTON_EVENT(reg,e,n) \
    00334   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickButton((reg),n))
    00335
    00337 #define CS_IS_JOYSTICK_MOVE_EVENT(reg,e,n) \
    00338   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickMove((reg),n))
    00339
    00341 #define CS_IS_INPUT_EVENT(reg,e)      \
    00342   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevInput(reg))
    00343
    00352 #define csevQuit(reg)                 \
    00353   (csEventNameRegistry::GetID((reg), "crystalspace.application.quit"))
    00354
    00359 #define csevFocusChanged(reg)         \
    00360   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus"))
    00361
    00367 #define csevFocusGained(reg)          \
    00368   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus.gained"))
    00369
    00375 #define csevFocusLost(reg)            \
    00376   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus.lost"))
    00377
    00388 #define csevSystemOpen(reg)           \
    00389   (csEventNameRegistry::GetID((reg), "crystalspace.application.open"))
    00390
    00395 #define csevSystemClose(reg)          \
    00396   (csEventNameRegistry::GetID((reg), "crystalspace.application.close"))
    00397
    00398 struct iGraphics2D;
    00399
    00400 CS_CONST_METHOD csEventID csevCanvasOp (csRef<iEventNameRegistry>& reg,
    00401                                         const iGraphics2D* g2d,
    00402                                         const csString &y);
    00403 static inline CS_CONST_METHOD csEventID csevCanvasOp (
    00404   iObjectRegistry *object_reg, const iGraphics2D* g2d, const csString &y)
    00405 {
    00406   csRef<iEventNameRegistry> name_reg = csEventNameRegistry::GetRegistry (object_reg);
    00407   return csevCanvasOp(name_reg, g2d, y);
    00408 }
    00409
    00410
    00418 #define csevCanvasResize(reg, g2d)      \
    00419   csevCanvasOp((reg), (g2d), "resize")
    00420
    00431 #define csevCanvasClose(reg, g2d)             \
    00432   csevCanvasOp((reg), (g2d), "close")
    00433
    00439 #define csevCanvasHidden(reg, g2d)      \
    00440   csevCanvasOp((reg), (g2d), "hidden")
    00441
    00446 #define csevCanvasExposed(reg, g2d)     \
    00447   csevCanvasOp((reg), (g2d), "exposed")
    00448
    00458 #define csevCommandLineHelp(reg)      \
    00459   (csEventNameRegistry::GetID((reg), "crystalspace.application.commandlinehelp"))
    00460
    00468 csEventID csevPreProcess(iObjectRegistry *reg);
    00469 csEventID csevPreProcess(iEventNameRegistry *reg);
    00470
    00475 csEventID csevProcess(iObjectRegistry *reg);
    00476 csEventID csevProcess(iEventNameRegistry *reg);
    00477
    00485 csEventID csevPostProcess(iObjectRegistry *reg);
    00486 csEventID csevPostProcess(iEventNameRegistry *reg);
    00487
    00495 csEventID csevFinalProcess(iObjectRegistry *reg);
    00496 csEventID csevFinalProcess(iEventNameRegistry *reg);
    00497
    00500 #define CS_DECLARE_SYSTEM_EVENT_SHORTCUTS                       \
    00501   csEventID SystemOpen;                                         \
    00502   csEventID SystemClose
    00503
    00504 #define CS_DECLARE_FRAME_EVENT_SHORTCUTS                        \
    00505   csEventID Frame;                                              \
    00506   csEventID PreProcess;                                         \
    00507   csEventID Process;                                            \
    00508   csEventID PostProcess;                                        \
    00509   csEventID FinalProcess
    00510
    00511 #define CS_DECLARE_INPUT_EVENT_SHORTCUTS                        \
    00512   csEventID KeyboardEvent;                                      \
    00513   csEventID MouseEvent;                                         \
    00514   csEventID JoystickEvent
    00515
    00521 #define CS_DECLARE_EVENT_SHORTCUTS                              \
    00522   CS_DECLARE_SYSTEM_EVENT_SHORTCUTS;                            \
    00523   CS_DECLARE_FRAME_EVENT_SHORTCUTS;                             \
    00524   CS_DECLARE_INPUT_EVENT_SHORTCUTS
    00525
    00526 #define CS_INITIALIZE_SYSTEM_EVENT_SHORTCUTS(object_reg) do {   \
    00527     SystemOpen = csevSystemOpen ((object_reg));                 \
    00528     SystemClose = csevSystemClose ((object_reg));               \
    00529   } while (0)
    00530
    00531 #define CS_INITIALIZE_FRAME_EVENT_SHORTCUTS(object_reg) do {    \
    00532     Frame = csevFrame ((object_reg));                           \
    00533     PreProcess = csevPreProcess ((object_reg));                 \
    00534     Process = csevProcess ((object_reg));                       \
    00535     PostProcess = csevPostProcess ((object_reg));               \
    00536     FinalProcess = csevFinalProcess ((object_reg));             \
    00537   } while (0)
    00538
    00539 #define CS_INITIALIZE_INPUT_EVENT_SHORTCUTS(object_reg) do {    \
    00540     KeyboardEvent = csevKeyboardEvent ((object_reg));           \
    00541     MouseEvent = csevMouseEvent ((object_reg));                 \
    00542     JoystickEvent = csevJoystickEvent ((object_reg));           \
    00543   } while (0)
    00544
    00550 #define CS_INITIALIZE_EVENT_SHORTCUTS(object_reg) do {  \
    00551     CS_INITIALIZE_SYSTEM_EVENT_SHORTCUTS (object_reg);  \
    00552     CS_INITIALIZE_FRAME_EVENT_SHORTCUTS (object_reg);   \
    00553     CS_INITIALIZE_INPUT_EVENT_SHORTCUTS (object_reg);   \
    00554   } while (0)
    00555
    00558 #endif // __CS_CSUTIL_EVENTNAMES_H__