csutil/eventnames.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

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

- 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 #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   csEventID GetID (const char* name);
    00079
    00080   const char * GetString (const csEventID id);
    00081   static const char * GetString (iObjectRegistry *object_reg,
    00082                                                  csEventID id);
    00083   csEventID GetParentID (const csEventID id);
    00084   bool IsImmediateChildOf (const csEventID child,
    00085                                            const csEventID parent);
    00086   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
    00162 #define csevAllEvents(reg)            \
    00163   (csEventNameRegistry::GetID((reg), ""))
    00164
    00170 #define csevFrame(reg)                \
    00171   (csEventNameRegistry::GetID((reg), "crystalspace.frame"))
    00172
    00177 #define csevInput(reg)                \
    00178   (csEventNameRegistry::GetID((reg), "crystalspace.input"))
    00179
    00185 #define csevKeyboardEvent(reg)        \
    00186   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard"))
    00187
    00189 #define csevKeyboardDown(reg)         \
    00190   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard.down"))
    00191
    00193 #define csevKeyboardUp(reg)           \
    00194   (csEventNameRegistry::GetID((reg), "crystalspace.input.keyboard.up"))
    00195
    00200 #define csevMouseEvent(reg)           \
    00201   (csEventNameRegistry::GetID((reg), "crystalspace.input.mouse"))
    00202
    00203 static inline csEventID csevMouse (
    00204   iEventNameRegistry *name_reg, uint x)
    00205 {
    00206   csString name ("crystalspace.input.mouse.");
    00207   name.Append (x);
    00208   return name_reg->GetID(name);
    00209 }
    00210
    00211 static inline csEventID csevMouse(
    00212   iObjectRegistry *object_reg, uint x)
    00213 {
    00214   return csevMouse(csEventNameRegistry::GetRegistry(object_reg), x);
    00215 }
    00216
    00217 static inline csEventID csevMouseOp(
    00218   iEventNameRegistry *name_reg, uint x, const csString &y)
    00219 {
    00220   csString name ("crystalspace.input.mouse.");
    00221   name.Append (x);
    00222   name.Append (".");
    00223   name.Append (y);
    00224   return name_reg->GetID(name);
    00225 }
    00226
    00227 static inline csEventID csevMouseOp(
    00228   iObjectRegistry *object_reg, uint x, const csString &y)
    00229 {
    00230   return csevMouseOp(csEventNameRegistry::GetRegistry(object_reg), x, y);
    00231 }
    00232
    00238 #define csevMouseButton(reg,x)        \
    00239   csevMouseOp ((reg), (x), "button")
    00240
    00244 #define csevMouseDown(reg,x)          \
    00245   csevMouseOp ((reg), (x), "button.down")
    00246
    00250 #define csevMouseUp(reg,x)            \
    00251   csevMouseOp ((reg), (x), "button.up")
    00252
    00256 #define csevMouseClick(reg,x)         \
    00257   csevMouseOp ((reg), (x), "button.click")
    00258
    00262 #define csevMouseDoubleClick(reg,x)   \
    00263   csevMouseOp((reg), (x), "button.doubleclick")
    00264
    00268 #define csevMouseMove(reg,x)          \
    00269   csevMouseOp((reg), (x), "move")
    00270
    00276 #define csevJoystickEvent(reg)        \
    00277   (csEventNameRegistry::GetID((reg), "crystalspace.input.joystick"))
    00278
    00279 static inline csEventID csevJoystick (
    00280   iEventNameRegistry *name_reg, uint x)
    00281 {
    00282   char buffer[64];
    00283   cs_snprintf(buffer, sizeof (buffer) - 1, "crystalspace.input.joystick.%d",
    00284     x);
    00285   return name_reg->GetID(buffer);
    00286 }
    00287
    00288 static inline csEventID csevJoystick (
    00289   iObjectRegistry *object_reg, uint x)
    00290 {
    00291   return csevJoystick(csEventNameRegistry::GetRegistry(object_reg), x);
    00292 }
    00293
    00294 static inline csEventID csevJoystickOp (
    00295   iEventNameRegistry *name_reg, uint x, const csString &y)
    00296 {
    00297   csString name ("crystalspace.input.joystick.");
    00298   name.Append (x);
    00299   name.Append (".");
    00300   name.Append (y);
    00301   return name_reg->GetID(name);
    00302 }
    00303
    00304 static inline csEventID csevJoystickOp (
    00305   iObjectRegistry *object_reg, uint x, const csString &y)
    00306 {
    00307   return csevJoystickOp (csEventNameRegistry::GetRegistry(object_reg), x, y);
    00308 }
    00309
    00316 #define csevJoystickButton(reg,x)     \
    00317   csevJoystickOp((reg),(x),"button")
    00318
    00320 #define csevJoystickDown(reg,x)       \
    00321   csevJoystickOp((reg),(x),"button.down")
    00322
    00324 #define csevJoystickUp(reg,x)         \
    00325   csevJoystickOp((reg),(x),"button.up")
    00326
    00328 #define csevJoystickMove(reg,x)       \
    00329   csevJoystickOp((reg),(x),"move")
    00330
    00332 #define CS_IS_KEYBOARD_EVENT(reg,e)   \
    00333   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevKeyboardEvent(reg))
    00334
    00336 #define CS_IS_MOUSE_EVENT(reg,e)      \
    00337   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseEvent(reg))
    00338
    00340 #define CS_IS_MOUSE_BUTTON_EVENT(reg,e,n) \
    00341   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseButton((reg),n))
    00342
    00344 #define CS_IS_MOUSE_MOVE_EVENT(reg,e,n) \
    00345   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevMouseMove((reg),n))
    00346
    00348 #define CS_IS_JOYSTICK_EVENT(reg,e)   \
    00349   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickEvent(reg))
    00350
    00352 #define CS_IS_JOYSTICK_BUTTON_EVENT(reg,e,n) \
    00353   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickButton((reg),n))
    00354
    00356 #define CS_IS_JOYSTICK_MOVE_EVENT(reg,e,n) \
    00357   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevJoystickMove((reg),n))
    00358
    00360 #define CS_IS_INPUT_EVENT(reg,e)      \
    00361   csEventNameRegistry::IsKindOf((reg), ((e).Name), csevInput(reg))
    00362
    00371 #define csevQuit(reg)                 \
    00372   (csEventNameRegistry::GetID((reg), "crystalspace.application.quit"))
    00373
    00379 #define csevFocusChanged(reg)         \
    00380   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus"))
    00381
    00387 #define csevFocusGained(reg)          \
    00388   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus.gained"))
    00389
    00395 #define csevFocusLost(reg)            \
    00396   (csEventNameRegistry::GetID((reg), "crystalspace.application.focus.lost"))
    00397
    00408 #define csevSystemOpen(reg)           \
    00409   (csEventNameRegistry::GetID((reg), "crystalspace.application.open"))
    00410
    00415 #define csevSystemClose(reg)          \
    00416   (csEventNameRegistry::GetID((reg), "crystalspace.application.close"))
    00417
    00418 struct iGraphics2D;
    00419
    00420 CS_CRYSTALSPACE_EXPORT
    00421 csEventID csevCanvasOp (csRef<iEventNameRegistry>& reg,
    00422                                         const iGraphics2D* g2d,
    00423                                         const csString &y);
    00424 static inline csEventID csevCanvasOp (
    00425   iObjectRegistry *object_reg, const iGraphics2D* g2d, const csString &y)
    00426 {
    00427   csRef<iEventNameRegistry> name_reg = csEventNameRegistry::GetRegistry (object_reg);
    00428   return csevCanvasOp(name_reg, g2d, y);
    00429 }
    00430
    00431
    00439 #define csevCanvasResize(reg, g2d)      \
    00440   csevCanvasOp((reg), (g2d), "resize")
    00441
    00452 #define csevCanvasClose(reg, g2d)             \
    00453   csevCanvasOp((reg), (g2d), "close")
    00454
    00460 #define csevCanvasHidden(reg, g2d)      \
    00461   csevCanvasOp((reg), (g2d), "hidden")
    00462
    00467 #define csevCanvasExposed(reg, g2d)     \
    00468   csevCanvasOp((reg), (g2d), "exposed")
    00469
    00479 #define csevCommandLineHelp(reg)      \
    00480   (csEventNameRegistry::GetID((reg), "crystalspace.application.commandlinehelp"))
    00481
    00484 #define CS_DECLARE_SYSTEM_EVENT_SHORTCUTS                       \
    00485   csEventID SystemOpen;                                         \
    00486   csEventID SystemClose
    00487
    00488 #define CS_DECLARE_FRAME_EVENT_SHORTCUTS                        \
    00489   csEventID Frame
    00490
    00491 #define CS_DECLARE_INPUT_EVENT_SHORTCUTS                        \
    00492   csEventID KeyboardEvent;                                      \
    00493   csEventID MouseEvent;                                         \
    00494   csEventID JoystickEvent
    00495
    00501 #define CS_DECLARE_EVENT_SHORTCUTS                              \
    00502   CS_DECLARE_SYSTEM_EVENT_SHORTCUTS;                            \
    00503   CS_DECLARE_FRAME_EVENT_SHORTCUTS;                             \
    00504   CS_DECLARE_INPUT_EVENT_SHORTCUTS
    00505
    00506 #define CS_INITIALIZE_SYSTEM_EVENT_SHORTCUTS(object_reg) do {   \
    00507     SystemOpen = csevSystemOpen ((object_reg));                 \
    00508     SystemClose = csevSystemClose ((object_reg));               \
    00509   } while (0)
    00510
    00511 #define CS_INITIALIZE_FRAME_EVENT_SHORTCUTS(object_reg) do {    \
    00512     Frame = csevFrame ((object_reg));                           \
    00513   } while (0)
    00514
    00515 #define CS_INITIALIZE_INPUT_EVENT_SHORTCUTS(object_reg) do {    \
    00516     KeyboardEvent = csevKeyboardEvent ((object_reg));           \
    00517     MouseEvent = csevMouseEvent ((object_reg));                 \
    00518     JoystickEvent = csevJoystickEvent ((object_reg));           \
    00519   } while (0)
    00520
    00526 #define CS_INITIALIZE_EVENT_SHORTCUTS(object_reg) do {  \
    00527     CS_INITIALIZE_SYSTEM_EVENT_SHORTCUTS (object_reg);  \
    00528     CS_INITIALIZE_FRAME_EVENT_SHORTCUTS (object_reg);   \
    00529     CS_INITIALIZE_INPUT_EVENT_SHORTCUTS (object_reg);   \
    00530   } while (0)
    00531
    00534 #endif // __CS_CSUTIL_EVENTNAMES_H__