Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HEventListener.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2000 by Tech Soft 3D, LLC.
00003 // The information contained herein is confidential and proprietary to
00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under
00005 // civil and criminal statutes.  Tech Soft 3D shall pursue its civil
00006 // and criminal remedies in the event of unauthorized use or misappropriation
00007 // of its trade secrets.  Use of this information by anyone other than
00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a
00009 // written non-disclosure agreement, expressly prescribing the scope and
00010 // manner of such use.
00011 //
00012 // $Id: d51fd687f079b7258239d3ac133a406009e4286f $
00013 //
00014 
00019 #ifndef _HEVENTLISTENER_H
00020 #define _HEVENTLISTENER_H
00021 
00022 #ifdef H_PACK_8
00023 #pragma pack(push)
00024 #pragma pack(8)
00025 #endif
00026 
00027 #include "HTools.h"
00028 #include "HEventInfo.h"
00029  
00030 #include "HDB.h"
00031 
00032 class HBhvAnimation;
00033 class HBhvTargetObject;
00034 class HEventListener;
00035 class HBhvSensor;
00036 
00037 #define HLISTENER_PASS_EVENT 0
00038 #define HLISTENER_CONSUME_EVENT 999
00039 
00041 #define HLISTENER_PRIORITY_NORMAL  5
00042 
00043 #define HLISTENER_PRIORITY_HIGH  10
00044 
00045 #define HLISTENER_PRIORITY_LOW  0
00046 
00050 enum HEventListenerType {
00051     HUserdefinerListenerType, 
00052     HUpdateListenerType, 
00053     HMouseListenerType, 
00054     HAnimationListenerType, 
00055     HSensorListenerType, 
00056     HFitWorldListenerType, 
00057     HObjectManipulationListenerType, 
00058     HJoyStickListenerType 
00059 };
00060 
00061 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00062 
00063 #define HLISTENER_EVENT(listenertype, manager, function)     { listenertype *el = (listenertype *)manager->GetEventListenerManager(listenertype::GetType()); \
00064                                                 if (el) \
00065                                                     el->function; }
00066 #define HLISTENER_EVENT_STRING(listenertype, manager, function)  { listenertype *el = (listenertype *)manager->GetEventListenerManager(listenertype::GetStringType()); \
00067                                                 if (el) \
00068                                                     el->function; }
00069 
00070 #define HLISTENER_FUNCTION_0(classname, method) \
00071     virtual int method() { \
00072                 if (!m_pEventListenerManager)    \
00073                     return 0;  \
00074                 m_pEventListenerManager->StartQuery(); \
00075                 classname* listener; \
00076                 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
00077                     if (listener->method() == HLISTENER_CONSUME_EVENT) \
00078                         break; \
00079                 return 1; }     
00080 
00081 
00082 #define HLISTENER_FUNCTION_1(classname, method, param_type_1, param_1) \
00083     virtual int method( param_type_1 param_1 ) { \
00084                 if (!m_pEventListenerManager)    \
00085                     return 0;  \
00086                 m_pEventListenerManager->StartQuery(); \
00087                 classname* listener; \
00088                 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
00089                     if (listener->method( param_1 ) == HLISTENER_CONSUME_EVENT) \
00090                         break; \
00091                 return 1; }     
00092 
00093 #define HLISTENER_FUNCTION_2(classname, method, param_type_1, param_1, param_type_2, param_2) \
00094     virtual int method( param_type_1 param_1 , param_type_2 param_2) { \
00095                 if (!m_pEventListenerManager)    \
00096                     return 0;  \
00097                 m_pEventListenerManager->StartQuery(); \
00098                 classname* listener; \
00099                 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
00100                     if (listener->method( param_1, param_2) == HLISTENER_CONSUME_EVENT) \
00101                         break; \
00102                 return 1; }     
00103 
00104 #define HLISTENER_FUNCTION_3(classname, method, param_type_1, param_1, param_type_2, param_2, param_type_3, param_3) \
00105     virtual int method( param_type_1 param_1 , param_type_2 param_2, param_type_3 param_3) { \
00106                 if (!m_pEventListenerManager)    \
00107                     return 0;  \
00108                 m_pEventListenerManager->StartQuery(); \
00109                 classname* listener; \
00110                 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
00111                     if (listener->method( param_1, param_2, param_3) == HLISTENER_CONSUME_EVENT) \
00112                         break; \
00113                 return 1; }     
00114  
00115 #define HLISTENER_SETUP_FUNCTIONS(listenertype)                             \
00116     static  HEventListenerType GetType() { return listenertype##Type; }         \
00117     virtual HEventListener *CreateListenerManager()                         \
00118             { HEventListener *temp = (HEventListener *)new listenertype();  \
00119               temp->ConvertToManager();                                     \
00120               return temp;                                                  \
00121             }
00122                                                     
00123 #define HLISTENER_SETUP_FUNCTIONS_STRING(listenertype, stringtype)                      \
00124 static  HEventListenerType GetType() { return HUserdefinerListenerType; }   \
00125     static  const char * GetStringType() { return stringtype; } \
00126     virtual HEventListener *CreateListenerManager()                         \
00127             { HEventListener *temp = (HEventListener *)new listenertype();  \
00128               temp->ConvertToManager();                                     \
00129               return temp;                                                  \
00130             }
00131 
00132 #endif //DOXYGEN_SHOULD_SKIP_THIS
00133 
00134 class HMouseListenerManager;
00135 class HUpdateListenerManager;
00136 
00137 
00138  
00139 
00140 
00142 class MVO_API HEventListenerManager
00143 {
00144 public:
00148     HEventListenerManager();
00149     virtual ~HEventListenerManager();
00150 
00151 
00158     void AddEventListener(HEventListener *eventlistener, int priority);
00159 
00164     void Reset();
00168     void StartQuery();
00169 
00176     HEventListener * GetEventListener();
00177 
00183     bool RemoveEventListener(HEventListener *eventlistener);
00184 
00185 protected:
00186     struct vlist_s * m_pEventListenerList;      
00187     bool m_bQueryInProgress;                    
00188 };
00189 
00190  
00191 
00192 
00193 
00195 
00199 class MVO_API HEventListener 
00200 {
00201 public:
00205     HEventListener() { m_pEventListenerManager = 0; m_RequestedPriority = -1; }
00206     virtual ~HEventListener() { 
00207         if (m_pEventListenerManager)
00208             delete m_pEventListenerManager;
00209     };
00213     void    ConvertToManager() {
00214         if (m_pEventListenerManager == 0)
00215                 m_pEventListenerManager = new HEventListenerManager;
00216  
00217     }
00222     virtual HEventListener *CreateListenerManager() { return 0;}
00226     HEventListenerManager * GetEventListenerManager() {return m_pEventListenerManager; }
00231     void SetRequestedPriority(int v) { m_RequestedPriority = v; }
00232 
00236     int GetRequestedPriority() { return m_RequestedPriority; }
00237 protected:
00238     HEventListenerManager *m_pEventListenerManager; 
00239     int m_RequestedPriority; 
00240 };
00241 
00242 
00243 
00244 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00245 
00246 
00248 class MVO_API HUpdateListener : public HEventListener
00249 {
00250 public:
00254     HLISTENER_SETUP_FUNCTIONS(HUpdateListener);
00255     HLISTENER_FUNCTION_1(HUpdateListener, CameraChangedEvent, HBaseView *, view);
00256     HLISTENER_FUNCTION_2(HUpdateListener, UpdateEvent, bool, antialias, bool, forceUpdate); 
00257     HLISTENER_FUNCTION_1(HUpdateListener, ViewDestroyedEvent, HBaseView *, view);
00258     HLISTENER_FUNCTION_1(HUpdateListener, SmoothTransitionFinishedEvent, HBaseView *, view);
00259 
00260    
00261 };
00262 
00264 class MVO_API HFitWorldListener : public HEventListener
00265 {
00266 public:
00270     HLISTENER_SETUP_FUNCTIONS(HFitWorldListener);
00271     HLISTENER_FUNCTION_1(HFitWorldListener, PreFitWorldEvent, HBaseView *, view);
00272     HLISTENER_FUNCTION_1(HFitWorldListener, PostFitWorldEvent, HBaseView *, view);
00273    
00274 };
00275 
00277 class MVO_API HObjectManipulationListener : public HEventListener
00278 {
00279 public:
00283     HLISTENER_SETUP_FUNCTIONS(HObjectManipulationListener);
00284     HLISTENER_FUNCTION_3(HObjectManipulationListener, SetupHandlesEvent, HBaseView *, view, HC_KEY, key, bool, complex);
00285     HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectBeforeMoveEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);  
00286     HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectMovedEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);
00287     HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectScaledEvent, HBaseView *, view, HC_KEY, key, HPoint &, p);
00288     
00289 };
00290 
00291 
00293 class MVO_API HAnimationListener : public HEventListener
00294 {
00295 public:
00299     HLISTENER_SETUP_FUNCTIONS(HAnimationListener)
00300 
00301     HLISTENER_FUNCTION_1(HAnimationListener, AnimationFinishedEvent, HBhvAnimation *, ainst)
00302     HLISTENER_FUNCTION_1(HAnimationListener, KeyframeEditorExistsQuery, bool &, res)
00303     HLISTENER_FUNCTION_0(HAnimationListener, KeyframeAddedEvent)
00304     HLISTENER_FUNCTION_1(HAnimationListener, ObjectCollisionEvent, HBhvTargetObject *, tob)
00305     HLISTENER_FUNCTION_1(HAnimationListener, ObjectNoCollisionEvent, HBhvTargetObject *, tob)
00306 
00307   
00308 };
00309  
00311 class MVO_API HSensorListener : public HEventListener
00312 {
00313 public:
00317     HLISTENER_SETUP_FUNCTIONS(HSensorListener)
00318     HLISTENER_FUNCTION_1(HSensorListener, SensorActivatedEvent, HBhvSensor *, sensor)
00319     HLISTENER_FUNCTION_1(HSensorListener, SensorActionEvent, const char *, action)
00320   
00321 };
00322 
00323 
00324 
00326 class MVO_API HMouseListener : public HEventListener
00327 {
00328 public:
00332     HLISTENER_SETUP_FUNCTIONS(HMouseListener)
00333 
00334     HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDown, HEventInfo &, hevent)
00335     HLISTENER_FUNCTION_1(HMouseListener, OnMouseMove, HEventInfo &, hevent)
00336     HLISTENER_FUNCTION_1(HMouseListener, OnLButtonUp, HEventInfo &, hevent)
00337     HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDblClk, HEventInfo &, hevent)
00338     HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDown, HEventInfo &, hevent)
00339     HLISTENER_FUNCTION_1(HMouseListener, OnMButtonUp, HEventInfo &, hevent)
00340     HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDblClk, HEventInfo &, hevent)
00341     HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDown, HEventInfo &, hevent)
00342     HLISTENER_FUNCTION_1(HMouseListener, OnRButtonUp, HEventInfo &, hevent)
00343     HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDblClk, HEventInfo &, hevent)
00344     HLISTENER_FUNCTION_1(HMouseListener, OnMouseWheel, HEventInfo &, hevent)
00345     HLISTENER_FUNCTION_1(HMouseListener, OnKeyDown, HEventInfo &, hevent)
00346     HLISTENER_FUNCTION_1(HMouseListener, OnKeyUp, HEventInfo &, hevent)
00347     HLISTENER_FUNCTION_1(HMouseListener, OnTouchesDown, HEventInfo &, hevent)
00348     HLISTENER_FUNCTION_1(HMouseListener, OnTouchesMove, HEventInfo &, hevent)
00349     HLISTENER_FUNCTION_1(HMouseListener, OnTouchesUp, HEventInfo &, hevent)
00350    
00351 };
00352 
00354 class MVO_API HJoyStickListener : public HEventListener
00355 {
00356 public:
00360     HLISTENER_SETUP_FUNCTIONS(HJoyStickListener)
00361 
00362     HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickRotation, HEventInfo &, hevent)
00363     HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickTranslation, HEventInfo &, hevent)  
00364     HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickButton, HEventInfo &, hevent)
00365 };
00366 
00367 #endif  //DOXYGEN_SHOULD_SKIP_THIS
00368 
00369 
00370 #ifdef H_PACK_8
00371 #pragma pack(pop)
00372 #endif
00373 
00374 #endif
00375 
00376 
00377 
00378