My Project
GUIEvent.h
1 #pragma once
2 using namespace std;
3 
4 #include "EventBinding.h"
5 // decide how far is the control dragged away from the mouse pressed location when the dragging operation starts, in pixels
6 #define EVENT_DRAG_DISTANCE 2
7 
8 // the maximum between two successive clicks that can be interpreted as double click, in milliseconds
9 #define EVENT_DOUBLECLICK_TIME 300
10 
11 // this should be equal to the one in guidirectinput.h
12 #define SAMPLE_BUFFER_SIZE 1024
13 
14 
16 #define ShiftPressed (((CGUIEvent::KeyStates[EM_KEY_LSHIFT]&0x80)!=0)||((CGUIEvent::KeyStates[EM_KEY_RSHIFT]&0x80)!=0))
17 #define ControlPressed (((CGUIEvent::KeyStates[EM_KEY_LCONTROL]&0x80)!=0)||((CGUIEvent::KeyStates[EM_KEY_RCONTROL]&0x80)!=0))
18 #define AltPressed (((CGUIEvent::KeyStates[EM_KEY_LALT]&0x80)!=0)||((CGUIEvent::KeyStates[EM_KEY_RALT]&0x80)!=0))
19 #define CapsLockPressed ((CGUIEvent::KeyStates[EM_KEY_CAPSLOCK]&0x01)!=0)
20 #define NumLockPressed ((CGUIEvent::KeyStates[EM_KEY_NUMLOCK]&0x01)!=0)
21 
22 #include <map>
23 #include <list>
24 #include <vector>
25 #include <bitset>
26 using namespace std;
27 #define RetainLeftState(x) ((x)&0x7)
28 #define RetainRightState(x) (((x)&0x38)>>3)
29 #define RetainMiddleState(x) (((x)&0x1c0)>>6)
30 #define RetainDragState(x) (((x)&0xe00)>>9)
31 #define RetainKeyState(x) (((x)&0x3000)>>12)
32 namespace ParaEngine
33 {
34  class CEventBinding;
35  class CDirectKeyboard;
36  class CDirectMouse;
37  class CGUIBase;
38  class IObjectDrag;
39 
43  class CGUIEvent:public IObject
44  {
45  public:
46  enum GUI_EVENT_TYPE{
47  NONE=0,
48  SIMULATE=1,//if the event is use to simulate user input such as moving the mouse or type something
49  MOUSE=2,//any kind of mouse event
50  KEYBOARD=4,//any kind of keyboard event
51 /* MOVE_RESIZE=8,//move or resize a control, the parameter is its new rectangle.
52  CREATE=16,//creates a new control
53  SET_RESOURCE=32,//set or change a resource
54  PROCEDURE_CALL=64,//calls member function of a control, something like remote
55  //procedure call, not implemented in current version
56  RESERVED1=128,//three reserved input event type for future development
57  RESERVED2=256,
58  RESERVED3=512,*/
59  WINDOWS=1048576//other windows event
60  };
69  GUIESNone=0,
70  GUIESLeftNone=1,
71  GUIESLeftDown=2,
72  GUIESLeftClick=3,
73  GUIESLeftDBClick=4,
74  GUIESLeftMask=7,//00000000000111
75  GUIESRightNone=8,
76  GUIESRightDown=16,
77  GUIESRightClick=24,
78  GUIESRightDBClick=32,
79  GUIESRightMask=56,//00000000111000
80  GUIESMiddleNone=64,
81  GUIESMiddleDown=128,
82  GUIESMiddleClick=192,
83  GUIESMiddleDBClick=256,
84  GUIESMiddleMask=448,//00000111000000
85  GUIESDragBegin=512,
86  GUIESDragOver=1024,
87  GUIESDragEnd=1536,
88  GUIESDragMask=3584
89  };
90  enum GUI_KEY_OPTION{
91  DEFAULT=0,
92  REPEAT_PRESSED_KEYS=1,
93  IGNORE_UP_EVENTS=2,
94  IGNORE_DOWN_EVENTS=4
95  };
96  //this struct can be memcpy
98  public:
99  short x,y;
100  DWORD nTime;
101  void init(short x, short y, DWORD time)
102  {
103  this->x=x;this->y=y;this->nTime=time;
104  }
105  void init()
106  {
107  memset(this,0,sizeof(GUI_SIMPLE_EVENT_MOUSE));
108  }
109  };
110  //can be memcpy
112  public:
113  short x,y;
114  short WheelDelta;//if the mouse wheel scrolls, it is the the number of detents the mouse wheel has rotated.
115  int HoverDuration;//how long the mouse is on the control, set by InterpretEvent()
116  GUI_SIMPLE_EVENT_MOUSE LastLDown,LastRDown,LastMDown;//store the last click
117  void init()
118  {
119  x=y=0;
120  HoverDuration=0;
121  WheelDelta=0;
122  LastMDown.init();
123  LastRDown.init();
124  LastLDown.init();
125  }
126  };
127  //can be memcpy
129  DWORD key;
130  DWORD state;
131  DWORD lasttime;
132  };
133  //can not be memcpy
135  public:
136  DIDEVICEOBJECTDATA KeyEvents[SAMPLE_BUFFER_SIZE];
137 
138  DWORD Size;//size of KeyEvents
139  //the alternative key for the current trigger event.
140  //This is the translation of the original key code with the control keys.
141  //For example, NUMPAD0, if NUMLOCK is off, the nAlterKey will be INSERT key.
142  int nAlterKey;
143  std::vector <GUI_KEYBOARD_HOLDKEY> HoldKey;
144  void init()
145  {
146  //memset(KeyStates,0,sizeof(KeyStates));
147  memset(KeyEvents,0,sizeof(KeyEvents[0])*SAMPLE_BUFFER_SIZE);
148  Size=0;
149  HoldKey.clear();
150  }
151  };//keyboard event represents the current state of the keyboard,
152 
153  GUI_EVENT_MOUSE m_mouse;
154 
155  GUI_EVENT_KEYBOARD m_keyboard;
156 
158  int m_nTime;
159 
160 // bool m_bLeftdown,m_bRightdown,m_bMiddledown;
161  CGUIEvent();
162  ~CGUIEvent();
163 
164  //new
165  bool IsMapTo(int eSrcEvent, int eDestEvent);
172 // void SetEventBinding(const Policy::CopyOnWriteHolder<CEventBinding> *eventbinding);
173  int GetTriggerEvent()const{return m_nTriggerEvent;}
174  bool InterpretMessage(MSG *msg,int option=0);
175  CEventBinding *GetEventBindingObj(){return m_eventbinding.get_ptr();}
176  const CEventBinding *GetConstEventBindingObj(){return m_eventbinding.c_ptr();}
177 
178  bool IsMousePressed(int mouse);
179 
183  string GetCharSequence();
184 
190  static CHAR GetChar(DWORD key);
191 
192 
194  bool IsKeyPressed(int key);
195 
196  void SetBinding(IObjectDrag *obj);
197 
201  void AddHoldKey(DWORD key,DWORD nTime);
202 
203  void Initialize();
204 
205  void UpdateKey(int option);
206 
207  virtual int Release();
208  virtual void Clone(IObject* obj)const;
209  virtual IObject* Clone()const;
210  virtual bool Equals(const IObject *obj)const;
211 
212  void ResetState(){m_eState=GUIESNone;/*m_bLeftdown=false;m_bRightdown=false;m_bMiddledown=false;*/}
213  MSG GenerateMessage();
214 
215  EventBinding_cow_type m_eventbinding;
216  protected:
217  int m_nTriggerEvent;
218  short m_eState;//GUI_EVENT_STATE
219  IObjectDrag *m_binding;
220  //static members
221  public:
222  //this is a static member to temporarily store the keyboard state,
223  //all mapping are in the EM_XX index
224  static byte KeyStates[EventCount];
225  static void StaticInit();
226  protected:
227  static int m_nDragBeginDistance;
228  static int m_nDBClickInterval;
229 
230  };
231 }
Definition: RenderCoreOpenGL.h:38
Definition: GLType.h:217
int m_nTime
the time when the event happen, get using GetTickCount()
Definition: GUIEvent.h:158
Definition: EventBinding.h:22
different physics engine has different winding order.
Definition: EventBinding.h:32
Place of the.
Definition: GUIEvent.h:43
int GetTriggerEvent() const
Set the CEventBinding object of this event.
Definition: GUIEvent.h:173
Definition: IObjectDrag.h:66
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
GUI_EVENT_STATE
new 00000000000xxx: Left 00000000xxx000: Right 00000xxx000000: Middle 00xxx000000000: Drag xx00000000...
Definition: GUIEvent.h:68
This class is for maintaining the event binding table and script binding table.
Definition: EventBinding.h:51
Definition: GUIEvent.h:111