My Project
EventBinding.h
1 #pragma once
2 #include "Events_def.h"
3 #include <string>
4 #include <bitset>
5 #include <set>
6 #include <map>
7 #include <boost/array.hpp>
8 #include "util/cow_ptr.hpp"
9 
10 #define EventCount 512
11 using namespace std;
12 
13 #ifndef IS_KEYDOWN
14 #define IS_KEYDOWN(x) ((0x80&(x))!=0)
15 #endif
16 
17 #ifndef IS_KEYUP
18 #define IS_KEYUP(x) ((0x80&(x))==0)
19 #endif
20 
21 #ifndef WIN32
22 typedef struct tagMSG {
23  HWND hwnd;
24  UINT message;
25  WPARAM wParam;
26  LPARAM lParam;
27  DWORD time;
28  POINT pt;
29 
30 } MSG;
31 #endif
32 namespace ParaEngine
33 {
35  int data;
38  next=NULL;data=EM_NONE;
39  }
40  };
41 
42  class SimpleScript{
43  public:
44  string szFile;
45  string szCode;
46  };
51  class CEventBinding:public IObject
52  {
53  public:
54  CEventBinding();
55  ~CEventBinding();
57 // CEventBinding(const &)
58  static void StaticInit();
59  //initialize the event mapping table, the old mappings are erased.
60  void InitEventMappingTable(bool bDisable=false);
61 
62  //enable/disable an event
63  void EnableEvent(int eEvent);
64  void DisableEvent(int eEvent);
68  void MapEvent(int eSrcEvent, int eDestEvent);
72  void UnmapEvent(int eSrcEvent, int eDestEvent);
76  bool IsMapTo(int eSrcEvent, int eDestEvent)const;
77 
78  //maps the default relation between the visible characters.
79  void DefaultMap_Text();
80 
81  //maps the default relation between the control keys
82  void DefaultMap_Control();
83 
84  //maps the default relation between mouse events
85  void DefaultMap_Mouse();
86 
87  //disable all the keyboard events
88  void DisableKeyboard();
89  //enable all the keyboard events
90  void EnableKeyboard();
91 
92  //disable all the mouse events
93  void DisableMouse();
94  //enable all the mouse events
95  void EnableMouse();
96 
97  //create an event's script, if it already has a script, the old one will be replace by the new one
98  void MapEventToScript(int eEvent,const SimpleScript *script);
99 
100  //delete an event's script, if any
101  void UnmapEventToScript(int eEvent);
102 
103  //return the script of a given event, null if not exists
104  const SimpleScript *GetEventScript(int eEvent)const;
105 
106  //if an event has script,
107  bool HasEventScript(int eEvent)const ;
108 
109  CEventBinding & operator =(CEventBinding &input);
110 
111 
112  //inherits from IObject
113  virtual void Clone(IObject* pobj)const;
114  virtual IObject* Clone()const;
115  virtual int Release();
116  virtual bool Equals(const IObject *obj)const;
117 
118  //two helper functions for translating between string and the event value.
119  static int StringToEventValue(const string &str);
120  static string& EventValueToString(int value);
121 
122  //helper function for initializing a message
123  static void InitMsg(MSG *event,DWORD time,DWORD message,POINT& pt);
124 
126  static DWORD TranslateVKToDIK(DWORD dwVKey);
127 
128  static DWORD ScancodeToKeyTable[256];
129 
131  static DWORD WinVirtualKeyToDIK[256];
132 
134  static DWORD DIKToWinVirtualKey[256];
135  protected:
136  typedef std::bitset<EventCount> EventEnabledArray_type;
137  typedef std::map<int,SimpleScript> EventScriptMap_type;
138  typedef boost::array< set<int>, EventCount > EventMapping_type;
139  typedef cow_ptr< boost::array< set<int>, EventCount > > EventMapping_cow_type; // copy on write
140 
141  EventEnabledArray_type m_pEventEnable;
142  EventScriptMap_type m_pEventToScript;
143 
144  EventMapping_cow_type m_pEventMappingTable;
145  static map<string,int> StringToEventTable;
146  static map<int,string> EventToStringTable;
147  };
148 
149  // since most event binding is stored as copy on write pointer.
151 }
Definition: EventBinding.h:22
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: PEtypes.h:116
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
Definition: EventBinding.h:42
Definition: EventBinding.h:34
Definition: enum_maker.hpp:46
This class is for maintaining the event binding table and script binding table.
Definition: EventBinding.h:51
cow_ptr is a Copy On Write smart pointer. It does not require the pointee to have clone function logi...
Definition: cow_ptr.hpp:56