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, callback) \ 00059 { \ 00060 ListenerType * listener = (ListenerType *)manager->GetEventListenerManager(ListenerType::GetType()); \ 00061 if (listener) \ 00062 (listener->callback); \ 00063 } 00064 00065 #define HLISTENER_EVENT_STRING(ListenerType, manager, callback) \ 00066 { \ 00067 ListenerType * listener = (ListenerType *)manager->GetEventListenerManager(ListenerType::GetStringType()); \ 00068 if (listener) \ 00069 (listener->callback); \ 00070 } 00071 00072 #define HLISTENER_FUNCTION_0(Class, Method) \ 00073 virtual int Method() { \ 00074 if (!m_pEventListenerManager) \ 00075 return 0; \ 00076 m_pEventListenerManager->StartQuery(); \ 00077 Class * listener; \ 00078 while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \ 00079 if (listener->Method() == HLISTENER_CONSUME_EVENT) \ 00080 break; \ 00081 return 1; \ 00082 } 00083 00084 #define HLISTENER_FUNCTION_1(Class, Method, ParamType_1, param1) \ 00085 virtual int Method(ParamType_1 param_1) { \ 00086 if (!m_pEventListenerManager) \ 00087 return 0; \ 00088 m_pEventListenerManager->StartQuery(); \ 00089 Class * listener; \ 00090 while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \ 00091 if (listener->Method(param_1) == HLISTENER_CONSUME_EVENT) \ 00092 break; \ 00093 return 1; \ 00094 } 00095 00096 #define HLISTENER_FUNCTION_2(Class, Method, ParamType_1, param_1, ParamType_2, param_2) \ 00097 virtual int Method(ParamType_1 param_1, ParamType_2 param_2) { \ 00098 if (!m_pEventListenerManager) \ 00099 return 0; \ 00100 m_pEventListenerManager->StartQuery(); \ 00101 Class * listener; \ 00102 while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \ 00103 if (listener->Method(param_1, param_2) == HLISTENER_CONSUME_EVENT) \ 00104 break; \ 00105 return 1; \ 00106 } 00107 00108 #define HLISTENER_FUNCTION_3(Class, Method, ParamType_1, param_1, ParamType_2, param_2, ParamType_3, param_3) \ 00109 virtual int Method(ParamType_1 param_1, ParamType_2 param_2, ParamType_3 param_3) { \ 00110 if (!m_pEventListenerManager) \ 00111 return 0; \ 00112 m_pEventListenerManager->StartQuery(); \ 00113 Class * listener; \ 00114 while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \ 00115 if (listener->Method(param_1, param_2, param_3) == HLISTENER_CONSUME_EVENT) \ 00116 break; \ 00117 return 1; \ 00118 } 00119 00120 #define HLISTENER_SETUP_FUNCTIONS(ListenerType) \ 00121 static HEventListenerType GetType() \ 00122 { \ 00123 return ListenerType##Type; \ 00124 } \ 00125 virtual HEventListener * CreateListenerManager() \ 00126 { \ 00127 HEventListener * listener = (HEventListener *)new ListenerType(); \ 00128 listener->ConvertToManager(); \ 00129 return listener; \ 00130 } 00131 00132 #define HLISTENER_SETUP_FUNCTIONS_STRING(ListenerType, string_type) \ 00133 HLISTENER_SETUP_FUNCTIONS(HUserdefinerListener); \ 00134 static const char * GetStringType() \ 00135 { \ 00136 return string_type; \ 00137 } 00138 00139 #endif //DOXYGEN_SHOULD_SKIP_THIS 00140 00141 00142 00143 class HMouseListenerManager; 00144 class HUpdateListenerManager; 00145 00146 00147 00149 class MVO_API HEventListenerManager 00150 { 00151 public: 00155 HEventListenerManager(); 00156 virtual ~HEventListenerManager(); 00157 00158 00165 void AddEventListener(HEventListener * eventlistener, int priority); 00166 00171 void Reset(); 00172 00176 void StartQuery(); 00177 00184 HEventListener * GetEventListener(); 00185 00191 bool RemoveEventListener(HEventListener *eventlistener); 00192 00193 protected: 00194 struct vlist_s * m_pEventListenerList; 00195 bool m_bQueryInProgress; 00196 }; 00197 00198 00199 00200 00201 00203 00207 class MVO_API HEventListener 00208 { 00209 public: 00213 HEventListener() { m_pEventListenerManager = 0; m_RequestedPriority = -1; } 00214 00215 virtual ~HEventListener() { 00216 if (m_pEventListenerManager) 00217 delete m_pEventListenerManager; 00218 } 00219 00223 void ConvertToManager() { 00224 if (m_pEventListenerManager == 0) 00225 m_pEventListenerManager = new HEventListenerManager(); 00226 } 00227 00232 virtual HEventListener * CreateListenerManager() { return 0; } 00233 00237 HEventListenerManager * GetEventListenerManager() { return m_pEventListenerManager; } 00238 00243 void SetRequestedPriority(int v) { m_RequestedPriority = v; } 00244 00248 int GetRequestedPriority() { return m_RequestedPriority; } 00249 00250 protected: 00251 HEventListenerManager * m_pEventListenerManager; 00252 int m_RequestedPriority; 00253 }; 00254 00255 00256 00257 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00258 00259 00261 class MVO_API HUpdateListener : public HEventListener 00262 { 00263 public: 00267 HLISTENER_SETUP_FUNCTIONS(HUpdateListener); 00268 HLISTENER_FUNCTION_1(HUpdateListener, CameraChangedEvent, HBaseView *, view); 00269 HLISTENER_FUNCTION_2(HUpdateListener, UpdateEvent, bool, antialias, bool, forceUpdate); 00270 HLISTENER_FUNCTION_1(HUpdateListener, ViewDestroyedEvent, HBaseView *, view); 00271 HLISTENER_FUNCTION_1(HUpdateListener, SmoothTransitionFinishedEvent, HBaseView *, view); 00272 }; 00273 00275 class MVO_API HFitWorldListener : public HEventListener 00276 { 00277 public: 00281 HLISTENER_SETUP_FUNCTIONS(HFitWorldListener); 00282 HLISTENER_FUNCTION_1(HFitWorldListener, PreFitWorldEvent, HBaseView *, view); 00283 HLISTENER_FUNCTION_1(HFitWorldListener, PostFitWorldEvent, HBaseView *, view); 00284 }; 00285 00287 class MVO_API HObjectManipulationListener : public HEventListener 00288 { 00289 public: 00293 HLISTENER_SETUP_FUNCTIONS(HObjectManipulationListener); 00294 HLISTENER_FUNCTION_3(HObjectManipulationListener, SetupHandlesEvent, HBaseView *, view, HC_KEY, key, bool, complex); 00295 HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectBeforeMoveEvent, HBaseView *, view, HC_KEY, key, HPoint *, p); 00296 HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectMovedEvent, HBaseView *, view, HC_KEY, key, HPoint *, p); 00297 HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectScaledEvent, HBaseView *, view, HC_KEY, key, HPoint &, p); 00298 }; 00299 00300 00302 class MVO_API HAnimationListener : public HEventListener 00303 { 00304 public: 00308 HLISTENER_SETUP_FUNCTIONS(HAnimationListener); 00309 00310 HLISTENER_FUNCTION_1(HAnimationListener, AnimationFinishedEvent, HBhvAnimation *, ainst); 00311 HLISTENER_FUNCTION_1(HAnimationListener, KeyframeEditorExistsQuery, bool &, res); 00312 HLISTENER_FUNCTION_0(HAnimationListener, KeyframeAddedEvent); 00313 HLISTENER_FUNCTION_1(HAnimationListener, ObjectCollisionEvent, HBhvTargetObject *, tob); 00314 HLISTENER_FUNCTION_1(HAnimationListener, ObjectNoCollisionEvent, HBhvTargetObject *, tob); 00315 }; 00316 00317 00319 class MVO_API HSensorListener : public HEventListener 00320 { 00321 public: 00325 HLISTENER_SETUP_FUNCTIONS(HSensorListener); 00326 HLISTENER_FUNCTION_1(HSensorListener, SensorActivatedEvent, HBhvSensor *, sensor); 00327 HLISTENER_FUNCTION_1(HSensorListener, SensorActionEvent, const char *, action); 00328 }; 00329 00330 00331 00333 class MVO_API HMouseListener : public HEventListener 00334 { 00335 public: 00339 HLISTENER_SETUP_FUNCTIONS(HMouseListener); 00340 00341 HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDown, HEventInfo &, hevent); 00342 HLISTENER_FUNCTION_1(HMouseListener, OnMouseMove, HEventInfo &, hevent); 00343 HLISTENER_FUNCTION_1(HMouseListener, OnLButtonUp, HEventInfo &, hevent); 00344 HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDblClk, HEventInfo &, hevent); 00345 HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDown, HEventInfo &, hevent); 00346 HLISTENER_FUNCTION_1(HMouseListener, OnMButtonUp, HEventInfo &, hevent); 00347 HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDblClk, HEventInfo &, hevent); 00348 HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDown, HEventInfo &, hevent); 00349 HLISTENER_FUNCTION_1(HMouseListener, OnRButtonUp, HEventInfo &, hevent); 00350 HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDblClk, HEventInfo &, hevent); 00351 HLISTENER_FUNCTION_1(HMouseListener, OnMouseWheel, HEventInfo &, hevent); 00352 HLISTENER_FUNCTION_1(HMouseListener, OnKeyDown, HEventInfo &, hevent); 00353 HLISTENER_FUNCTION_1(HMouseListener, OnKeyUp, HEventInfo &, hevent); 00354 HLISTENER_FUNCTION_1(HMouseListener, OnTouchesDown, HEventInfo &, hevent); 00355 HLISTENER_FUNCTION_1(HMouseListener, OnTouchesMove, HEventInfo &, hevent); 00356 HLISTENER_FUNCTION_1(HMouseListener, OnTouchesUp, HEventInfo &, hevent); 00357 }; 00358 00360 class MVO_API HJoyStickListener : public HEventListener 00361 { 00362 public: 00366 HLISTENER_SETUP_FUNCTIONS(HJoyStickListener); 00367 00368 HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickRotation, HEventInfo &, hevent); 00369 HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickTranslation, HEventInfo &, hevent); 00370 HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickButton, HEventInfo &, hevent); 00371 }; 00372 00373 #endif //DOXYGEN_SHOULD_SKIP_THIS 00374 00375 00376 #ifdef H_PACK_8 00377 #pragma pack(pop) 00378 #endif 00379 00380 #endif 00381 00382 00383 00384