HEventListener.h
Go to the documentation of this file.
1 // Copyright (c) Tech Soft 3D
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  HLISTENER_SETUP_FUNCTIONS(HUserdefinerListener); \
134  static const char * GetStringType() \
135  { \
136  return string_type; \
137  }
138 
139 #endif //DOXYGEN_SHOULD_SKIP_THIS
140 
141 
142 
143 class HMouseListenerManager;
144 class HUpdateListenerManager;
145 
146 
147 
150 {
151 public:
156  virtual ~HEventListenerManager();
157 
158 
165  void AddEventListener(HEventListener * eventlistener, int priority);
166 
171  void Reset();
172 
176  void StartQuery();
177 
184  HEventListener * GetEventListener();
185 
191  bool RemoveEventListener(HEventListener *eventlistener);
192 
193 protected:
194  struct vlist_s * m_pEventListenerList;
196 };
197 
198 
199 
200 
201 
203 
207 class MVO_API HEventListener
208 {
209 public:
213  HEventListener() { m_pEventListenerManager = 0; m_RequestedPriority = -1; }
214 
215  virtual ~HEventListener() {
216  if (m_pEventListenerManager)
217  delete m_pEventListenerManager;
218  }
219 
224  if (m_pEventListenerManager == 0)
225  m_pEventListenerManager = new HEventListenerManager();
226  }
227 
232  virtual HEventListener * CreateListenerManager() { return 0; }
233 
237  HEventListenerManager * GetEventListenerManager() { return m_pEventListenerManager; }
238 
243  void SetRequestedPriority(int v) { m_RequestedPriority = v; }
244 
248  int GetRequestedPriority() { return m_RequestedPriority; }
249 
250 protected:
253 };
254 
255 
256 
257 #ifndef DOXYGEN_SHOULD_SKIP_THIS
258 
259 
261 class MVO_API HUpdateListener : public HEventListener
262 {
263 public:
267  HLISTENER_SETUP_FUNCTIONS(HUpdateListener);
268  HLISTENER_FUNCTION_1(HUpdateListener, CameraChangedEvent, HBaseView *, view);
269  HLISTENER_FUNCTION_2(HUpdateListener, UpdateEvent, bool, antialias, bool, forceUpdate);
270  HLISTENER_FUNCTION_1(HUpdateListener, ViewDestroyedEvent, HBaseView *, view);
271  HLISTENER_FUNCTION_1(HUpdateListener, SmoothTransitionFinishedEvent, HBaseView *, view);
272 };
273 
275 class MVO_API HFitWorldListener : public HEventListener
276 {
277 public:
281  HLISTENER_SETUP_FUNCTIONS(HFitWorldListener);
282  HLISTENER_FUNCTION_1(HFitWorldListener, PreFitWorldEvent, HBaseView *, view);
283  HLISTENER_FUNCTION_1(HFitWorldListener, PostFitWorldEvent, HBaseView *, view);
284 };
285 
287 class MVO_API HObjectManipulationListener : public HEventListener
288 {
289 public:
293  HLISTENER_SETUP_FUNCTIONS(HObjectManipulationListener);
294  HLISTENER_FUNCTION_3(HObjectManipulationListener, SetupHandlesEvent, HBaseView *, view, HC_KEY, key, bool, complex);
295  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectBeforeMoveEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);
296  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectMovedEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);
297  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectScaledEvent, HBaseView *, view, HC_KEY, key, HPoint &, p);
298 };
299 
300 
302 class MVO_API HAnimationListener : public HEventListener
303 {
304 public:
308  HLISTENER_SETUP_FUNCTIONS(HAnimationListener);
309 
310  HLISTENER_FUNCTION_1(HAnimationListener, AnimationFinishedEvent, HBhvAnimation *, ainst);
311  HLISTENER_FUNCTION_1(HAnimationListener, KeyframeEditorExistsQuery, bool &, res);
312  HLISTENER_FUNCTION_0(HAnimationListener, KeyframeAddedEvent);
313  HLISTENER_FUNCTION_1(HAnimationListener, ObjectCollisionEvent, HBhvTargetObject *, tob);
314  HLISTENER_FUNCTION_1(HAnimationListener, ObjectNoCollisionEvent, HBhvTargetObject *, tob);
315 };
316 
317 
319 class MVO_API HSensorListener : public HEventListener
320 {
321 public:
325  HLISTENER_SETUP_FUNCTIONS(HSensorListener);
326  HLISTENER_FUNCTION_1(HSensorListener, SensorActivatedEvent, HBhvSensor *, sensor);
327  HLISTENER_FUNCTION_1(HSensorListener, SensorActionEvent, const char *, action);
328 };
329 
330 
331 
333 class MVO_API HMouseListener : public HEventListener
334 {
335 public:
339  HLISTENER_SETUP_FUNCTIONS(HMouseListener);
340 
341  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDown, HEventInfo &, hevent);
342  HLISTENER_FUNCTION_1(HMouseListener, OnMouseMove, HEventInfo &, hevent);
343  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonUp, HEventInfo &, hevent);
344  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDblClk, HEventInfo &, hevent);
345  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDown, HEventInfo &, hevent);
346  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonUp, HEventInfo &, hevent);
347  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDblClk, HEventInfo &, hevent);
348  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDown, HEventInfo &, hevent);
349  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonUp, HEventInfo &, hevent);
350  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDblClk, HEventInfo &, hevent);
351  HLISTENER_FUNCTION_1(HMouseListener, OnMouseWheel, HEventInfo &, hevent);
352  HLISTENER_FUNCTION_1(HMouseListener, OnKeyDown, HEventInfo &, hevent);
353  HLISTENER_FUNCTION_1(HMouseListener, OnKeyUp, HEventInfo &, hevent);
354  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesDown, HEventInfo &, hevent);
355  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesMove, HEventInfo &, hevent);
356  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesUp, HEventInfo &, hevent);
357 };
358 
360 class MVO_API HJoyStickListener : public HEventListener
361 {
362 public:
366  HLISTENER_SETUP_FUNCTIONS(HJoyStickListener);
367 
368  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickRotation, HEventInfo &, hevent);
369  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickTranslation, HEventInfo &, hevent);
370  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickButton, HEventInfo &, hevent);
371 };
372 
373 #endif //DOXYGEN_SHOULD_SKIP_THIS
374 
375 
376 #ifdef H_PACK_8
377 #pragma pack(pop)
378 #endif
379 
380 #endif
381 
382 
383 
384 
void ConvertToManager()
Definition: HEventListener.h:223
self-explanatory
Definition: HEventListener.h:46
bool m_bQueryInProgress
Definition: HEventListener.h:195
virtual HEventListener * CreateListenerManager()
Definition: HEventListener.h:232
int m_RequestedPriority
Definition: HEventListener.h:252
HEventListenerManager * m_pEventListenerManager
Definition: HEventListener.h:251
HEventListener()
Definition: HEventListener.h:213
The HEventListener class is the base class for all event types.
Definition: HEventListener.h:207
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:248
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:243
HEventListenerManager * GetEventListenerManager()
Definition: HEventListener.h:237
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:149
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:194