My Project
EventClasses.h
1 #pragma once
2 #include "IEvent.h"
3 namespace ParaEngine
4 {
5  class TouchEventSession;
6 
8  struct Event : public IEvent
9  {
10  int m_nEventType;
11  int m_nEventID;
12  string m_sCode;
13 
15  virtual int GetEventType() const { return m_nEventType; }
17  virtual string ToScriptCode() const;
18 
20  virtual int GetEventID() const { return m_nEventID; }
21  public:
22  Event(int nEventType, const char* sCode);
23  Event(int nEventType, int nID, const char* sCode);
24  };
25 
27  struct MouseEvent : public IEvent
28  {
29  DWORD m_MouseState;
30  int m_x;
31  int m_y;
34 
35  public:
36  MouseEvent(DWORD MouseState, int x, int y);
37  MouseEvent(DWORD MouseState, int x, int y, int nEventType);
39  virtual int GetEventType() const { return m_nEventType; }
40  string ToScriptCode()const;
41  };
42 
44  struct KeyEvent : public IEvent
45  {
46  DWORD m_KeyState;
47  int m_nKey;
48  int m_nEventType;
49 
50  public:
51  KeyEvent(DWORD KeyState, int nKey, int nEventType = EVENT_KEY) :m_KeyState(KeyState), m_nKey(nKey), m_nEventType(nEventType) {};
53  virtual int GetEventType() const { return m_nEventType; }
54  string ToScriptCode()const;
55  };
56 
58  struct SystemEvent : public IEvent
59  {
60  // value of SystemEventType
61  int m_nType;
62  // the string code
63  string m_sCode;
64  bool m_bIsAsyncMode;
65  enum SystemEventType
66  {
67  // this is fired when the same application receives a message from the command line.
68  // event_type=0 and msg=command line
69  SYS_COMMANDLINE = 0,
70  // the user requests to close the application, such as clicking the x or alt-f4
71  SYS_WM_CLOSE = 1,
72  // a file drop event whenever user drags from windows explorer to this window.
73  SYS_WM_DROPFILES = 2,
74  // window is being destroyed, do final clean up and save states.
75  SYS_WM_DESTROY = 3,
76  // when system settings changed. such as the slate mode is changed, mostly for intel 2in1 pad.
77  SYS_WM_SETTINGCHANGE = 4,
78  };
79  public:
80  SystemEvent(int nType, const string& sCode) :m_nType(nType), m_sCode(sCode), m_bIsAsyncMode(true){};
82  virtual int GetEventType() const { return EVENT_SYSTEM; }
83  string ToScriptCode()const;
85  virtual bool IsAsyncMode() { return m_bIsAsyncMode; }
89  void SetAsyncMode(bool bAsync){ m_bIsAsyncMode = bAsync; }
90  };
91 
93  struct EditorEvent : public IEvent
94  {
95  public:
96  int m_nType;
97  EditorEvent(int nType) :m_nType(nType){};
99  virtual int GetEventType() const { return EVENT_EDITOR; }
100  string ToScriptCode()const;
101  };
102 
104  struct NetworkEvent : public IEvent
105  {
106  public:
107  // see NPLGlobals::NPL_PACKET_TYPE
108  int m_nType;
109  string m_sCode;
110  NetworkEvent(int nType, const string& sCode) :m_nType(nType), m_sCode(sCode){};
111 
113  virtual int GetEventType() const { return EVENT_NETWORK; }
114  string ToScriptCode()const;
115  };
116 
118  struct TouchEvent : public IEvent
119  {
120  public:
121  enum TouchEventMsgType{
122  TouchEvent_POINTER_ENTER = 0,
123  TouchEvent_POINTER_DOWN,
124  TouchEvent_POINTER_UPDATE,
125  TouchEvent_POINTER_UP,
126  TouchEvent_POINTER_LEAVE,
127  TouchEvent_POINTER_INVALID,
128  };
129  // see NPLGlobals::NPL_PACKET_TYPE
130  int m_nType;
131  std::string m_sCode;
132  TouchEventMsgType m_nTouchType;
133 
134  int m_touch_id;
135  float m_x;
136  float m_y;
137  // in ms seconds ticks
138  int m_nTime;
139 
140  TouchEvent(int nType, const string& sCode);
141  TouchEvent(int nType = EH_TOUCH, TouchEventMsgType nTouchType = TouchEvent_POINTER_INVALID, int touch_id = 0, float x = 0.f, float y = 0.f, int nTimeTick = 0);
142 
143  int GetClientPosX() const;
144  int GetClientPosY() const;
145  int GetTouchId() const;
146  int GetTime() const;
147  TouchEventMsgType GetTouchType() const;
148 
149  bool operator==(const TouchEvent& r);
150 
151  static const char* GetTouchTypeAsString(TouchEventMsgType nTouchType);
153  virtual int GetEventType() const { return EVENT_TOUCH; }
154  std::string ToScriptCode() const;
155  };
156 
162  struct AccelerometerEvent : public IEvent
163  {
164  public:
165  // see NPLGlobals::NPL_PACKET_TYPE
166  int m_nType;
167  std::string m_sCode;
168 
169  AccelerometerEvent(double x = 0, double y = 0, double z = 0, double timestamp = 0);
170 
172  virtual int GetEventType() const { return EVENT_ACCELEROMETER; }
173 
174  std::string ToScriptCode() const;
175 
176  public:
177  double m_x;
178  double m_y;
179  double m_z;
180  // current time in nano seconds when the event is received.
181  double m_timestamp;
182  };
183 }
different physics engine has different winding order.
Definition: EventBinding.h:32
simple mouse event struct
Definition: EventClasses.h:27
virtual int GetEventType() const
get event type
Definition: EventClasses.h:153
virtual int GetEventType() const
get event type
Definition: EventClasses.h:113
world editor events, such as scene selection, etc.
Definition: EventClasses.h:93
touch event
Definition: EventClasses.h:118
virtual int GetEventID() const
get event id
Definition: EventClasses.h:20
virtual int GetEventType() const
get event type
Definition: EventClasses.h:99
virtual int GetEventType() const
get event type
Definition: EventClasses.h:172
virtual int GetEventType() const
get event type
Definition: EventClasses.h:15
network event
Definition: EventClasses.h:104
virtual bool IsAsyncMode()
return true, if firing event does not immediately invoke the handler.
Definition: EventClasses.h:85
system events struct
Definition: EventClasses.h:58
simple key events struct
Definition: EventClasses.h:44
the event interface
Definition: IEvent.h:8
void SetAsyncMode(bool bAsync)
set whether firing event does not immediately invoke the handler.
Definition: EventClasses.h:89
the total 3d vector of force that is currently on the device, including gravity.
Definition: EventClasses.h:162
int m_nEventType
EM_MOUSE_MOVE or EM_MOUSE_CLICK, EM_MOUSE_DOWN, EM_MOUSE_UP, etc.
Definition: EventClasses.h:33
virtual string ToScriptCode() const
build script code and return.
Definition: EventClasses.cpp:22
a general event
Definition: EventClasses.h:8
virtual int GetEventType() const
get event type
Definition: EventClasses.h:39
virtual int GetEventType() const
get event type
Definition: EventClasses.h:82
virtual int GetEventType() const
get event type
Definition: EventClasses.h:53