00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc. 00002 // 00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., 00004 // and considered a trade secret as defined under civil and criminal statutes. 00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of 00006 // unauthorized use or misappropriation of its trade secrets. Use of this information 00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under 00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use. 00009 00014 #ifndef _HEVENTLISTENER_H 00015 #define _HEVENTLISTENER_H 00016 00017 #ifdef H_PACK_8 00018 #pragma pack(push) 00019 #pragma pack(8) 00020 #endif 00021 00022 #include "HTools.h" 00023 #include "HEventInfo.h" 00024 00025 #include "HDB.h" 00026 00027 class HBhvAnimation; 00028 class HBhvTargetObject; 00029 class HEventListener; 00030 class HBhvSensor; 00031 00032 #define HLISTENER_PASS_EVENT 0 00033 #define HLISTENER_CONSUME_EVENT 999 00034 00036 #define HLISTENER_PRIORITY_NORMAL 5 00037 00038 #define HLISTENER_PRIORITY_HIGH 10 00039 00040 #define HLISTENER_PRIORITY_LOW 0 00041 00045 enum HEventListenerType { 00046 HUserdefinerListenerType, 00047 HUpdateListenerType, 00048 HMouseListenerType, 00049 HAnimationListenerType, 00050 HSensorListenerType, 00051 HFitWorldListenerType, 00052 HObjectManipulationListenerType, 00053 HJoyStickListenerType 00054 }; 00055 00056 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00057 00058 #define HLISTENER_EVENT(listenertype, manager, function) { listenertype *el = (listenertype *)manager->GetEventListenerManager(listenertype::GetType()); \ 00059 if (el) \ 00060 el->function; } 00061 #define HLISTENER_EVENT_STRING(listenertype, manager, function) { listenertype *el = (listenertype *)manager->GetEventListenerManager(listenertype::GetStringType()); \ 00062 if (el) \ 00063 el->function; } 00064 00065 #define HLISTENER_FUNCTION_0(classname, method) \ 00066 virtual int method() { \ 00067 if (!m_pEventListenerManager) \ 00068 return 0; \ 00069 m_pEventListenerManager->StartQuery(); \ 00070 classname* listener; \ 00071 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \ 00072 if (listener->method() == HLISTENER_CONSUME_EVENT) \ 00073 break; \ 00074 return 1; } 00075 00076 00077 #define HLISTENER_FUNCTION_1(classname, method, param_type_1, param_1) \ 00078 virtual int method( param_type_1 param_1 ) { \ 00079 if (!m_pEventListenerManager) \ 00080 return 0; \ 00081 m_pEventListenerManager->StartQuery(); \ 00082 classname* listener; \ 00083 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \ 00084 if (listener->method( param_1 ) == HLISTENER_CONSUME_EVENT) \ 00085 break; \ 00086 return 1; } 00087 00088 #define HLISTENER_FUNCTION_2(classname, method, param_type_1, param_1, param_type_2, param_2) \ 00089 virtual int method( param_type_1 param_1 , param_type_2 param_2) { \ 00090 if (!m_pEventListenerManager) \ 00091 return 0; \ 00092 m_pEventListenerManager->StartQuery(); \ 00093 classname* listener; \ 00094 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \ 00095 if (listener->method( param_1, param_2) == HLISTENER_CONSUME_EVENT) \ 00096 break; \ 00097 return 1; } 00098 00099 #define HLISTENER_FUNCTION_3(classname, method, param_type_1, param_1, param_type_2, param_2, param_type_3, param_3) \ 00100 virtual int method( param_type_1 param_1 , param_type_2 param_2, param_type_3 param_3) { \ 00101 if (!m_pEventListenerManager) \ 00102 return 0; \ 00103 m_pEventListenerManager->StartQuery(); \ 00104 classname* listener; \ 00105 while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \ 00106 if (listener->method( param_1, param_2, param_3) == HLISTENER_CONSUME_EVENT) \ 00107 break; \ 00108 return 1; } 00109 00110 #define HLISTENER_SETUP_FUNCTIONS(listenertype) \ 00111 static HEventListenerType GetType() { return listenertype##Type; } \ 00112 virtual HEventListener *CreateListenerManager() \ 00113 { HEventListener *temp = (HEventListener *)new listenertype(); \ 00114 temp->ConvertToManager(); \ 00115 return temp; \ 00116 } 00117 00118 #define HLISTENER_SETUP_FUNCTIONS_STRING(listenertype, stringtype) \ 00119 static HEventListenerType GetType() { return HUserdefinerListenerType; } \ 00120 static const char * GetStringType() { return stringtype; } \ 00121 virtual HEventListener *CreateListenerManager() \ 00122 { HEventListener *temp = (HEventListener *)new listenertype(); \ 00123 temp->ConvertToManager(); \ 00124 return temp; \ 00125 } 00126 00127 #endif //DOXYGEN_SHOULD_SKIP_THIS 00128 00129 class HMouseListenerManager; 00130 class HUpdateListenerManager; 00131 00132 00133 00134 00135 00137 class MVO_API HEventListenerManager 00138 { 00139 public: 00143 HEventListenerManager(); 00144 virtual ~HEventListenerManager(); 00145 00146 00153 void AddEventListener(HEventListener *eventlistener, int priority); 00154 00159 void Reset(); 00163 void StartQuery(); 00164 00171 HEventListener * GetEventListener(); 00172 00178 bool RemoveEventListener(HEventListener *eventlistener); 00179 00180 protected: 00181 struct vlist_s * m_pEventListenerList; 00182 bool m_bQueryInProgress; 00183 }; 00184 00185 00186 00187 00188 00190 00194 class MVO_API HEventListener 00195 { 00196 public: 00200 HEventListener() { m_pEventListenerManager = 0; m_RequestedPriority = -1; } 00201 virtual ~HEventListener() { 00202 if (m_pEventListenerManager) 00203 delete m_pEventListenerManager; 00204 }; 00208 void ConvertToManager() { 00209 if (m_pEventListenerManager == 0) 00210 m_pEventListenerManager = new HEventListenerManager; 00211 00212 } 00217 virtual HEventListener *CreateListenerManager() { return 0;} 00221 HEventListenerManager * GetEventListenerManager() {return m_pEventListenerManager; } 00226 void SetRequestedPriority(int v) { m_RequestedPriority = v; } 00227 00231 int GetRequestedPriority() { return m_RequestedPriority; } 00232 protected: 00233 HEventListenerManager *m_pEventListenerManager; 00234 int m_RequestedPriority; 00235 }; 00236 00237 00238 00239 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00240 00241 00243 class MVO_API HUpdateListener : public HEventListener 00244 { 00245 public: 00249 HLISTENER_SETUP_FUNCTIONS(HUpdateListener); 00250 HLISTENER_FUNCTION_1(HUpdateListener, CameraChangedEvent, HBaseView *, view); 00251 HLISTENER_FUNCTION_2(HUpdateListener, UpdateEvent, bool, antialias, bool, forceUpdate); 00252 HLISTENER_FUNCTION_1(HUpdateListener, ViewDestroyedEvent, HBaseView *, view); 00253 HLISTENER_FUNCTION_1(HUpdateListener, SmoothTransitionFinishedEvent, HBaseView *, view); 00254 00255 00256 }; 00257 00259 class MVO_API HFitWorldListener : public HEventListener 00260 { 00261 public: 00265 HLISTENER_SETUP_FUNCTIONS(HFitWorldListener); 00266 HLISTENER_FUNCTION_1(HFitWorldListener, PreFitWorldEvent, HBaseView *, view); 00267 HLISTENER_FUNCTION_1(HFitWorldListener, PostFitWorldEvent, HBaseView *, view); 00268 00269 }; 00270 00272 class MVO_API HObjectManipulationListener : public HEventListener 00273 { 00274 public: 00278 HLISTENER_SETUP_FUNCTIONS(HObjectManipulationListener); 00279 HLISTENER_FUNCTION_3(HObjectManipulationListener, SetupHandlesEvent, HBaseView *, view, HC_KEY, key, bool, complex); 00280 HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectBeforeMoveEvent, HBaseView *, view, HC_KEY, key, HPoint *, p); 00281 HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectMovedEvent, HBaseView *, view, HC_KEY, key, HPoint *, p); 00282 HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectScaledEvent, HBaseView *, view, HC_KEY, key, HPoint &, p); 00283 00284 }; 00285 00286 00288 class MVO_API HAnimationListener : public HEventListener 00289 { 00290 public: 00294 HLISTENER_SETUP_FUNCTIONS(HAnimationListener) 00295 00296 HLISTENER_FUNCTION_1(HAnimationListener, AnimationFinishedEvent, HBhvAnimation *, ainst) 00297 HLISTENER_FUNCTION_1(HAnimationListener, KeyframeEditorExistsQuery, bool &, res) 00298 HLISTENER_FUNCTION_0(HAnimationListener, KeyframeAddedEvent) 00299 HLISTENER_FUNCTION_1(HAnimationListener, ObjectCollisionEvent, HBhvTargetObject *, tob) 00300 HLISTENER_FUNCTION_1(HAnimationListener, ObjectNoCollisionEvent, HBhvTargetObject *, tob) 00301 00302 00303 }; 00304 00306 class MVO_API HSensorListener : public HEventListener 00307 { 00308 public: 00312 HLISTENER_SETUP_FUNCTIONS(HSensorListener) 00313 HLISTENER_FUNCTION_1(HSensorListener, SensorActivatedEvent, HBhvSensor *, sensor) 00314 HLISTENER_FUNCTION_1(HSensorListener, SensorActionEvent, const char *, action) 00315 00316 }; 00317 00318 00319 00321 class MVO_API HMouseListener : public HEventListener 00322 { 00323 public: 00327 HLISTENER_SETUP_FUNCTIONS(HMouseListener) 00328 00329 HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDown, HEventInfo &, hevent) 00330 HLISTENER_FUNCTION_1(HMouseListener, OnMouseMove, HEventInfo &, hevent) 00331 HLISTENER_FUNCTION_1(HMouseListener, OnLButtonUp, HEventInfo &, hevent) 00332 HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDblClk, HEventInfo &, hevent) 00333 HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDown, HEventInfo &, hevent) 00334 HLISTENER_FUNCTION_1(HMouseListener, OnMButtonUp, HEventInfo &, hevent) 00335 HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDblClk, HEventInfo &, hevent) 00336 HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDown, HEventInfo &, hevent) 00337 HLISTENER_FUNCTION_1(HMouseListener, OnRButtonUp, HEventInfo &, hevent) 00338 HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDblClk, HEventInfo &, hevent) 00339 HLISTENER_FUNCTION_1(HMouseListener, OnMouseWheel, HEventInfo &, hevent) 00340 HLISTENER_FUNCTION_1(HMouseListener, OnKeyDown, HEventInfo &, hevent) 00341 HLISTENER_FUNCTION_1(HMouseListener, OnKeyUp, HEventInfo &, hevent) 00342 HLISTENER_FUNCTION_1(HMouseListener, OnTouchesDown, HEventInfo &, hevent) 00343 HLISTENER_FUNCTION_1(HMouseListener, OnTouchesMove, HEventInfo &, hevent) 00344 HLISTENER_FUNCTION_1(HMouseListener, OnTouchesUp, HEventInfo &, hevent) 00345 00346 }; 00347 00349 class MVO_API HJoyStickListener : public HEventListener 00350 { 00351 public: 00355 HLISTENER_SETUP_FUNCTIONS(HJoyStickListener) 00356 00357 HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickRotation, HEventInfo &, hevent) 00358 HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickTranslation, HEventInfo &, hevent) 00359 HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickButton, HEventInfo &, hevent) 00360 }; 00361 00362 #endif //DOXYGEN_SHOULD_SKIP_THIS 00363 00364 00365 #ifdef H_PACK_8 00366 #pragma pack(pop) 00367 #endif 00368 00369 #endif 00370 00371 00372 00373