HEventListener.h
Go to the documentation of this file.
1 // Copyright (c) Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
14 #ifndef _HEVENTLISTENER_H
15 #define _HEVENTLISTENER_H
16 
17 #ifdef H_PACK_8
18 #pragma pack(push)
19 #pragma pack(8)
20 #endif
21 
22 #include "HTools.h"
23 #include "HEventInfo.h"
24 
25 #include "HDB.h"
26 
27 class HBhvAnimation;
28 class HBhvTargetObject;
29 class HEventListener;
30 class HBhvSensor;
31 
32 #define HLISTENER_PASS_EVENT 0
33 #define HLISTENER_CONSUME_EVENT 999
34 
36 #define HLISTENER_PRIORITY_NORMAL 5
37 
38 #define HLISTENER_PRIORITY_HIGH 10
39 
40 #define HLISTENER_PRIORITY_LOW 0
41 
54 };
55 
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57 
58 #define HLISTENER_EVENT(ListenerType, manager, callback) \
59  { \
60  ListenerType * listener = (ListenerType *)manager->GetEventListenerManager(ListenerType::GetType()); \
61  if (listener) \
62  (listener->callback); \
63  }
64 
65 #define HLISTENER_EVENT_STRING(ListenerType, manager, callback) \
66  { \
67  ListenerType * listener = (ListenerType *)manager->GetEventListenerManager(ListenerType::GetStringType()); \
68  if (listener) \
69  (listener->callback); \
70  }
71 
72 #define HLISTENER_FUNCTION_0(Class, Method) \
73  virtual int Method() { \
74  if (!m_pEventListenerManager) \
75  return 0; \
76  m_pEventListenerManager->StartQuery(); \
77  Class * listener; \
78  while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \
79  if (listener->Method() == HLISTENER_CONSUME_EVENT) \
80  break; \
81  return 1; \
82  }
83 
84 #define HLISTENER_FUNCTION_1(Class, Method, ParamType_1, param1) \
85  virtual int Method(ParamType_1 param_1) { \
86  if (!m_pEventListenerManager) \
87  return 0; \
88  m_pEventListenerManager->StartQuery(); \
89  Class * listener; \
90  while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \
91  if (listener->Method(param_1) == HLISTENER_CONSUME_EVENT) \
92  break; \
93  return 1; \
94  }
95 
96 #define HLISTENER_FUNCTION_2(Class, Method, ParamType_1, param_1, ParamType_2, param_2) \
97  virtual int Method(ParamType_1 param_1, ParamType_2 param_2) { \
98  if (!m_pEventListenerManager) \
99  return 0; \
100  m_pEventListenerManager->StartQuery(); \
101  Class * listener; \
102  while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \
103  if (listener->Method(param_1, param_2) == HLISTENER_CONSUME_EVENT) \
104  break; \
105  return 1; \
106  }
107 
108 #define HLISTENER_FUNCTION_3(Class, Method, ParamType_1, param_1, ParamType_2, param_2, ParamType_3, param_3) \
109  virtual int Method(ParamType_1 param_1, ParamType_2 param_2, ParamType_3 param_3) { \
110  if (!m_pEventListenerManager) \
111  return 0; \
112  m_pEventListenerManager->StartQuery(); \
113  Class * listener; \
114  while ((listener = (Class *)m_pEventListenerManager->GetEventListener()) != 0) \
115  if (listener->Method(param_1, param_2, param_3) == HLISTENER_CONSUME_EVENT) \
116  break; \
117  return 1; \
118  }
119 
120 #define HLISTENER_SETUP_FUNCTIONS(ListenerType) \
121  static HEventListenerType GetType() \
122  { \
123  return ListenerType##Type; \
124  } \
125  virtual HEventListener * CreateListenerManager() \
126  { \
127  HEventListener * listener = (HEventListener *)new ListenerType(); \
128  listener->ConvertToManager(); \
129  return listener; \
130  }
131 
132 #define HLISTENER_SETUP_FUNCTIONS_STRING(ListenerType, string_type) \
133  static HEventListenerType GetType() { return HUserdefinerListenerType; } \
134  static const char * GetStringType() { return string_type; } \
135  virtual HEventListener * CreateListenerManager() \
136  { \
137  HEventListener * temp = (HEventListener *)new ListenerType(); \
138  temp->ConvertToManager(); \
139  return temp; \
140  }
141 
142 #endif //DOXYGEN_SHOULD_SKIP_THIS
143 
144 
145 
146 class HMouseListenerManager;
147 class HUpdateListenerManager;
148 
149 
150 
153 {
154 public:
159  virtual ~HEventListenerManager();
160 
161 
168  void AddEventListener(HEventListener * eventlistener, int priority);
169 
174  void Reset();
175 
179  void StartQuery();
180 
187  HEventListener * GetEventListener();
188 
194  bool RemoveEventListener(HEventListener *eventlistener);
195 
196 protected:
197  struct vlist_s * m_pEventListenerList;
199 };
200 
201 
202 
203 
204 
206 
210 class MVO_API HEventListener
211 {
212 public:
216  HEventListener() { m_pEventListenerManager = 0; m_RequestedPriority = -1; }
217 
218  virtual ~HEventListener() {
219  if (m_pEventListenerManager)
220  delete m_pEventListenerManager;
221  }
222 
227  if (m_pEventListenerManager == 0)
228  m_pEventListenerManager = new HEventListenerManager();
229  }
230 
235  virtual HEventListener * CreateListenerManager() { return 0; }
236 
240  HEventListenerManager * GetEventListenerManager() { return m_pEventListenerManager; }
241 
246  void SetRequestedPriority(int v) { m_RequestedPriority = v; }
247 
251  int GetRequestedPriority() { return m_RequestedPriority; }
252 
253 protected:
256 };
257 
258 
259 
260 #ifndef DOXYGEN_SHOULD_SKIP_THIS
261 
262 
264 class MVO_API HUpdateListener : public HEventListener
265 {
266 public:
270  HLISTENER_SETUP_FUNCTIONS(HUpdateListener);
271  HLISTENER_FUNCTION_1(HUpdateListener, CameraChangedEvent, HBaseView *, view);
272  HLISTENER_FUNCTION_2(HUpdateListener, UpdateEvent, bool, antialias, bool, forceUpdate);
273  HLISTENER_FUNCTION_1(HUpdateListener, ViewDestroyedEvent, HBaseView *, view);
274  HLISTENER_FUNCTION_1(HUpdateListener, SmoothTransitionFinishedEvent, HBaseView *, view);
275 };
276 
278 class MVO_API HFitWorldListener : public HEventListener
279 {
280 public:
284  HLISTENER_SETUP_FUNCTIONS(HFitWorldListener);
285  HLISTENER_FUNCTION_1(HFitWorldListener, PreFitWorldEvent, HBaseView *, view);
286  HLISTENER_FUNCTION_1(HFitWorldListener, PostFitWorldEvent, HBaseView *, view);
287 };
288 
290 class MVO_API HObjectManipulationListener : public HEventListener
291 {
292 public:
296  HLISTENER_SETUP_FUNCTIONS(HObjectManipulationListener);
297  HLISTENER_FUNCTION_3(HObjectManipulationListener, SetupHandlesEvent, HBaseView *, view, HC_KEY, key, bool, complex);
298  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectBeforeMoveEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);
299  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectMovedEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);
300  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectScaledEvent, HBaseView *, view, HC_KEY, key, HPoint &, p);
301 };
302 
303 
305 class MVO_API HAnimationListener : public HEventListener
306 {
307 public:
311  HLISTENER_SETUP_FUNCTIONS(HAnimationListener);
312 
313  HLISTENER_FUNCTION_1(HAnimationListener, AnimationFinishedEvent, HBhvAnimation *, ainst);
314  HLISTENER_FUNCTION_1(HAnimationListener, KeyframeEditorExistsQuery, bool &, res);
315  HLISTENER_FUNCTION_0(HAnimationListener, KeyframeAddedEvent);
316  HLISTENER_FUNCTION_1(HAnimationListener, ObjectCollisionEvent, HBhvTargetObject *, tob);
317  HLISTENER_FUNCTION_1(HAnimationListener, ObjectNoCollisionEvent, HBhvTargetObject *, tob);
318 };
319 
320 
322 class MVO_API HSensorListener : public HEventListener
323 {
324 public:
328  HLISTENER_SETUP_FUNCTIONS(HSensorListener);
329  HLISTENER_FUNCTION_1(HSensorListener, SensorActivatedEvent, HBhvSensor *, sensor);
330  HLISTENER_FUNCTION_1(HSensorListener, SensorActionEvent, const char *, action);
331 };
332 
333 
334 
336 class MVO_API HMouseListener : public HEventListener
337 {
338 public:
342  HLISTENER_SETUP_FUNCTIONS(HMouseListener);
343 
344  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDown, HEventInfo &, hevent);
345  HLISTENER_FUNCTION_1(HMouseListener, OnMouseMove, HEventInfo &, hevent);
346  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonUp, HEventInfo &, hevent);
347  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDblClk, HEventInfo &, hevent);
348  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDown, HEventInfo &, hevent);
349  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonUp, HEventInfo &, hevent);
350  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDblClk, HEventInfo &, hevent);
351  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDown, HEventInfo &, hevent);
352  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonUp, HEventInfo &, hevent);
353  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDblClk, HEventInfo &, hevent);
354  HLISTENER_FUNCTION_1(HMouseListener, OnMouseWheel, HEventInfo &, hevent);
355  HLISTENER_FUNCTION_1(HMouseListener, OnKeyDown, HEventInfo &, hevent);
356  HLISTENER_FUNCTION_1(HMouseListener, OnKeyUp, HEventInfo &, hevent);
357  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesDown, HEventInfo &, hevent);
358  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesMove, HEventInfo &, hevent);
359  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesUp, HEventInfo &, hevent);
360 };
361 
363 class MVO_API HJoyStickListener : public HEventListener
364 {
365 public:
369  HLISTENER_SETUP_FUNCTIONS(HJoyStickListener);
370 
371  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickRotation, HEventInfo &, hevent);
372  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickTranslation, HEventInfo &, hevent);
373  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickButton, HEventInfo &, hevent);
374 };
375 
376 #endif //DOXYGEN_SHOULD_SKIP_THIS
377 
378 
379 #ifdef H_PACK_8
380 #pragma pack(pop)
381 #endif
382 
383 #endif
384 
385 
386 
387 
void ConvertToManager()
Definition: HEventListener.h:226
self-explanatory
Definition: HEventListener.h:46
bool m_bQueryInProgress
Definition: HEventListener.h:198
virtual HEventListener * CreateListenerManager()
Definition: HEventListener.h:235
int m_RequestedPriority
Definition: HEventListener.h:255
HEventListenerManager * m_pEventListenerManager
Definition: HEventListener.h:254
HEventListener()
Definition: HEventListener.h:216
The HEventListener class is the base class for all event types.
Definition: HEventListener.h:210
The HBhvTargetObject class encapsulates various target types for animations and sensors.
Definition: HBhvBehaviorManager.h:82
Listens for mouse events like mouse moves and double clicks.
Definition: HEventListener.h:48
The HBhvSensor class encapsulates an animation sensor.
Definition: HBhvSensor.h:33
Listens when sensors are activated.
Definition: HEventListener.h:50
The HPoint class is the data type of a three-dimensional point.
Definition: HGlobals.h:121
The HBaseView class defines and manages a view of model information.
Definition: HBaseView.h:332
int GetRequestedPriority()
Definition: HEventListener.h:251
Listens for animation events like when key frames are added or when objects collide.
Definition: HEventListener.h:49
HEventListenerType
Definition: HEventListener.h:45
The HBhvAnimation class defines an animation.
Definition: HBhvAnimation.h:43
void SetRequestedPriority(int v)
Definition: HEventListener.h:246
HEventListenerManager * GetEventListenerManager()
Definition: HEventListener.h:240
The HEventInfo class stores and manages event information.
Definition: HEventInfo.h:207
Listens for 3DMouse/Joystick translation and rotation events.
Definition: HEventListener.h:53
The HEventListenerManager class is used to dispatch event for a specific type.
Definition: HEventListener.h:152
Listens for when fit world event will happen.
Definition: HEventListener.h:51
Listens for object manipulation events like when objects are moved or scaled.
Definition: HEventListener.h:52
Listens for update events like camera changed or view destroyed.
Definition: HEventListener.h:47
Interface of the HEventInfo class.
struct vlist_s * m_pEventListenerList
Definition: HEventListener.h:197