Alphabetical Class Index  Class Hierarchy   File Members   Compound Members   File List  

HEventListener.h
Go to the documentation of this file.
1 // Copyright (c) 1998-2014 by 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, function) { listenertype *el = (listenertype *)manager->GetEventListenerManager(listenertype::GetType()); \
59  if (el) \
60  el->function; }
61 #define HLISTENER_EVENT_STRING(listenertype, manager, function) { listenertype *el = (listenertype *)manager->GetEventListenerManager(listenertype::GetStringType()); \
62  if (el) \
63  el->function; }
64 
65 #define HLISTENER_FUNCTION_0(classname, method) \
66  virtual int method() { \
67  if (!m_pEventListenerManager) \
68  return 0; \
69  m_pEventListenerManager->StartQuery(); \
70  classname* listener; \
71  while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
72  if (listener->method() == HLISTENER_CONSUME_EVENT) \
73  break; \
74  return 1; }
75 
76 
77 #define HLISTENER_FUNCTION_1(classname, method, param_type_1, param_1) \
78  virtual int method( param_type_1 param_1 ) { \
79  if (!m_pEventListenerManager) \
80  return 0; \
81  m_pEventListenerManager->StartQuery(); \
82  classname* listener; \
83  while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
84  if (listener->method( param_1 ) == HLISTENER_CONSUME_EVENT) \
85  break; \
86  return 1; }
87 
88 #define HLISTENER_FUNCTION_2(classname, method, param_type_1, param_1, param_type_2, param_2) \
89  virtual int method( param_type_1 param_1 , param_type_2 param_2) { \
90  if (!m_pEventListenerManager) \
91  return 0; \
92  m_pEventListenerManager->StartQuery(); \
93  classname* listener; \
94  while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
95  if (listener->method( param_1, param_2) == HLISTENER_CONSUME_EVENT) \
96  break; \
97  return 1; }
98 
99 #define HLISTENER_FUNCTION_3(classname, method, param_type_1, param_1, param_type_2, param_2, param_type_3, param_3) \
100  virtual int method( param_type_1 param_1 , param_type_2 param_2, param_type_3 param_3) { \
101  if (!m_pEventListenerManager) \
102  return 0; \
103  m_pEventListenerManager->StartQuery(); \
104  classname* listener; \
105  while ((listener = (classname*)m_pEventListenerManager->GetEventListener()) != 0) \
106  if (listener->method( param_1, param_2, param_3) == HLISTENER_CONSUME_EVENT) \
107  break; \
108  return 1; }
109 
110 #define HLISTENER_SETUP_FUNCTIONS(listenertype) \
111  static HEventListenerType GetType() { return listenertype##Type; } \
112  virtual HEventListener *CreateListenerManager() \
113  { HEventListener *temp = (HEventListener *)new listenertype(); \
114  temp->ConvertToManager(); \
115  return temp; \
116  }
117 
118 #define HLISTENER_SETUP_FUNCTIONS_STRING(listenertype, stringtype) \
119 static HEventListenerType GetType() { return HUserdefinerListenerType; } \
120  static const char * GetStringType() { return stringtype; } \
121  virtual HEventListener *CreateListenerManager() \
122  { HEventListener *temp = (HEventListener *)new listenertype(); \
123  temp->ConvertToManager(); \
124  return temp; \
125  }
126 
127 #endif //DOXYGEN_SHOULD_SKIP_THIS
128 
129 class HMouseListenerManager;
130 class HUpdateListenerManager;
131 
132 
133 
134 
135 
138 {
139 public:
144  virtual ~HEventListenerManager();
145 
146 
153  void AddEventListener(HEventListener *eventlistener, int priority);
154 
159  void Reset();
163  void StartQuery();
164 
171  HEventListener * GetEventListener();
172 
178  bool RemoveEventListener(HEventListener *eventlistener);
179 
180 protected:
181  struct vlist_s * m_pEventListenerList;
183 };
184 
185 
186 
187 
188 
190 
194 class MVO_API HEventListener
195 {
196 public:
200  HEventListener() { m_pEventListenerManager = 0; m_RequestedPriority = -1; }
201  virtual ~HEventListener() {
202  if (m_pEventListenerManager)
203  delete m_pEventListenerManager;
204  };
209  if (m_pEventListenerManager == 0)
210  m_pEventListenerManager = new HEventListenerManager;
211 
212  }
217  virtual HEventListener *CreateListenerManager() { return 0;}
221  HEventListenerManager * GetEventListenerManager() {return m_pEventListenerManager; }
226  void SetRequestedPriority(int v) { m_RequestedPriority = v; }
227 
231  int GetRequestedPriority() { return m_RequestedPriority; }
232 protected:
235 };
236 
237 
238 
239 #ifndef DOXYGEN_SHOULD_SKIP_THIS
240 
241 
243 class MVO_API HUpdateListener : public HEventListener
244 {
245 public:
249  HLISTENER_SETUP_FUNCTIONS(HUpdateListener);
250  HLISTENER_FUNCTION_1(HUpdateListener, CameraChangedEvent, HBaseView *, view);
251  HLISTENER_FUNCTION_2(HUpdateListener, UpdateEvent, bool, antialias, bool, forceUpdate);
252  HLISTENER_FUNCTION_1(HUpdateListener, ViewDestroyedEvent, HBaseView *, view);
253  HLISTENER_FUNCTION_1(HUpdateListener, SmoothTransitionFinishedEvent, HBaseView *, view);
254 
255 
256 };
257 
259 class MVO_API HFitWorldListener : public HEventListener
260 {
261 public:
265  HLISTENER_SETUP_FUNCTIONS(HFitWorldListener);
266  HLISTENER_FUNCTION_1(HFitWorldListener, PreFitWorldEvent, HBaseView *, view);
267  HLISTENER_FUNCTION_1(HFitWorldListener, PostFitWorldEvent, HBaseView *, view);
268 
269 };
270 
272 class MVO_API HObjectManipulationListener : public HEventListener
273 {
274 public:
278  HLISTENER_SETUP_FUNCTIONS(HObjectManipulationListener);
279  HLISTENER_FUNCTION_3(HObjectManipulationListener, SetupHandlesEvent, HBaseView *, view, HC_KEY, key, bool, complex);
280  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectBeforeMoveEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);
281  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectMovedEvent, HBaseView *, view, HC_KEY, key, HPoint *, p);
282  HLISTENER_FUNCTION_3(HObjectManipulationListener, ObjectScaledEvent, HBaseView *, view, HC_KEY, key, HPoint &, p);
283 
284 };
285 
286 
288 class MVO_API HAnimationListener : public HEventListener
289 {
290 public:
294  HLISTENER_SETUP_FUNCTIONS(HAnimationListener)
295 
296  HLISTENER_FUNCTION_1(HAnimationListener, AnimationFinishedEvent, HBhvAnimation *, ainst)
297  HLISTENER_FUNCTION_1(HAnimationListener, KeyframeEditorExistsQuery, bool &, res)
298  HLISTENER_FUNCTION_0(HAnimationListener, KeyframeAddedEvent)
299  HLISTENER_FUNCTION_1(HAnimationListener, ObjectCollisionEvent, HBhvTargetObject *, tob)
300  HLISTENER_FUNCTION_1(HAnimationListener, ObjectNoCollisionEvent, HBhvTargetObject *, tob)
301 
302 
303 };
304 
306 class MVO_API HSensorListener : public HEventListener
307 {
308 public:
312  HLISTENER_SETUP_FUNCTIONS(HSensorListener)
313  HLISTENER_FUNCTION_1(HSensorListener, SensorActivatedEvent, HBhvSensor *, sensor)
314  HLISTENER_FUNCTION_1(HSensorListener, SensorActionEvent, const char *, action)
315 
316 };
317 
318 
319 
321 class MVO_API HMouseListener : public HEventListener
322 {
323 public:
327  HLISTENER_SETUP_FUNCTIONS(HMouseListener)
328 
329  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDown, HEventInfo &, hevent)
330  HLISTENER_FUNCTION_1(HMouseListener, OnMouseMove, HEventInfo &, hevent)
331  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonUp, HEventInfo &, hevent)
332  HLISTENER_FUNCTION_1(HMouseListener, OnLButtonDblClk, HEventInfo &, hevent)
333  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDown, HEventInfo &, hevent)
334  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonUp, HEventInfo &, hevent)
335  HLISTENER_FUNCTION_1(HMouseListener, OnMButtonDblClk, HEventInfo &, hevent)
336  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDown, HEventInfo &, hevent)
337  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonUp, HEventInfo &, hevent)
338  HLISTENER_FUNCTION_1(HMouseListener, OnRButtonDblClk, HEventInfo &, hevent)
339  HLISTENER_FUNCTION_1(HMouseListener, OnMouseWheel, HEventInfo &, hevent)
340  HLISTENER_FUNCTION_1(HMouseListener, OnKeyDown, HEventInfo &, hevent)
341  HLISTENER_FUNCTION_1(HMouseListener, OnKeyUp, HEventInfo &, hevent)
342  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesDown, HEventInfo &, hevent)
343  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesMove, HEventInfo &, hevent)
344  HLISTENER_FUNCTION_1(HMouseListener, OnTouchesUp, HEventInfo &, hevent)
345 
346 };
347 
349 class MVO_API HJoyStickListener : public HEventListener
350 {
351 public:
355  HLISTENER_SETUP_FUNCTIONS(HJoyStickListener)
356 
357  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickRotation, HEventInfo &, hevent)
358  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickTranslation, HEventInfo &, hevent)
359  HLISTENER_FUNCTION_1(HJoyStickListener, OnJoyStickButton, HEventInfo &, hevent)
360 };
361 
362 #endif //DOXYGEN_SHOULD_SKIP_THIS
363 
364 
365 #ifdef H_PACK_8
366 #pragma pack(pop)
367 #endif
368 
369 #endif
370 
371 
372 
373 
void ConvertToManager()
Definition: HEventListener.h:208
self-explanatory
Definition: HEventListener.h:46
bool m_bQueryInProgress
Definition: HEventListener.h:182
virtual HEventListener * CreateListenerManager()
Definition: HEventListener.h:217
int m_RequestedPriority
Definition: HEventListener.h:234
HEventListenerManager * m_pEventListenerManager
Definition: HEventListener.h:233
HEventListener()
Definition: HEventListener.h:200
The HEventListener class is the base class for all event types.
Definition: HEventListener.h:194
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:231
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:226
HEventListenerManager * GetEventListenerManager()
Definition: HEventListener.h:221
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:137
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:181