Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
EventPusher.h
1 /***********************************************************************
2  filename: CEGUIIrrlichtEventPusher.h
3  created: 12/22/2004
4  author: Thomas Suter
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef CCEGUIEVENTPUSHER_H_INCLUDED
29 #define CCEGUIEVENTPUSHER_H_INCLUDED
30 
31 #include "../../CEGUI.h"
32 #include <irrlicht.h>
33 
34 namespace CEGUI
35 {
36 using namespace irr;
37 
39 {
40  gui::ICursorControl* d_cursorctrl;
41 
42 public :
43  IrrlichtEventPusher(irr::gui::ICursorControl* ctrl) :
44  d_cursorctrl(ctrl)
45  {
46  initCodes();
47  };
48 
49  virtual ~IrrlichtEventPusher(){};
50 
51  bool OnEvent(const SEvent& event)
52  {
53  switch (event.EventType)
54  {
55  case EET_KEY_INPUT_EVENT :
56  if (event.KeyInput.PressedDown)
57  return OnKeyDown(event.KeyInput.Key, event.KeyInput.Char, event.KeyInput.Control, event.KeyInput.Shift);
58  else
59  return OnKeyUp(event.KeyInput.Key, event.KeyInput.Char, event.KeyInput.Control, event.KeyInput.Shift);
60  break;
61 
62  case EET_MOUSE_INPUT_EVENT :
63  return OnMouse(event.MouseInput.X, event.MouseInput.Y, event.MouseInput.Wheel, event.MouseInput.Event);
64  break;
65 
66  default:
67  break;
68  }
69 
70  return false;
71  }
72 
73  bool OnKeyDown(EKEY_CODE key, wchar_t wch, bool /*ctrl*/, bool /*shift*/)
74  {
75  bool handled = false;
76  CEGUI::GUIContext& cegui = CEGUI::System::getSingleton().getDefaultGUIContext();
77  handled = cegui.injectKeyDown(getKeyCode(key));
78  handled = cegui.injectChar(wch) || handled;
79  return handled;
80  }
81 
82  bool OnKeyUp(EKEY_CODE key, wchar_t /*wch*/, bool /*ctrl*/, bool /*shift*/)
83  {
84  bool handled = false;
85  CEGUI::GUIContext& cegui = CEGUI::System::getSingleton().getDefaultGUIContext();
86  handled = cegui.injectKeyUp(getKeyCode(key));
87  return handled;
88  }
89 
90  bool OnMouse(s32 x, s32 y, f32 w, EMOUSE_INPUT_EVENT e)
91  {
92  using namespace irr;
93  bool handled = false;
94 
95  switch (e)
96  {
98  case EMIE_LMOUSE_PRESSED_DOWN:
99  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(CEGUI::LeftButton);
100  break;
102  case EMIE_RMOUSE_PRESSED_DOWN:
103  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(CEGUI::RightButton);
104  break;
106  case EMIE_MMOUSE_PRESSED_DOWN:
107  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(CEGUI::MiddleButton);
108  break;
110  case EMIE_LMOUSE_LEFT_UP:
111  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(CEGUI::LeftButton);
112  break;
114  case EMIE_RMOUSE_LEFT_UP:
115  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(CEGUI::RightButton);
116  break;
118  case EMIE_MMOUSE_LEFT_UP:
119  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(CEGUI::MiddleButton);
120  break;
122  case EMIE_MOUSE_MOVED:
123  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(
124  static_cast<float>(x), static_cast<float>(y));
125  break;
128  case EMIE_MOUSE_WHEEL:
129  handled = CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseWheelChange(w);
130  break;
131  default:
132  break;
133  }
134  return handled;
135 
136  }
137 
145  CEGUI::Key::Scan getKeyCode(irr::EKEY_CODE kc) const
146  {
147  return irr2ceCODE[kc];
148  }
149 
150 protected:
151  CEGUI::Key::Scan irr2ceCODE[irr::KEY_KEY_CODES_COUNT];
152 
153  void initCodes()
154  {
155  using namespace irr;
156  memset(irr2ceCODE, Key::Unknown, KEY_KEY_CODES_COUNT);
157 
158  irr2ceCODE[KEY_LBUTTON ] = Key::Unknown; // Left mouse button
159  irr2ceCODE[KEY_RBUTTON ] = Key::Unknown; // Right mouse button
160  irr2ceCODE[KEY_CANCEL ] = Key::Unknown; // Control-break processing
161  irr2ceCODE[KEY_MBUTTON ] = Key::Unknown; // Middle mouse button (three-button mouse)
162  irr2ceCODE[KEY_XBUTTON1 ] = Key::Unknown; // Windows 2000/XP: X1 mouse button
163  irr2ceCODE[KEY_XBUTTON2 ] = Key::Unknown; // Windows 2000/XP: X2 mouse button
164  irr2ceCODE[KEY_BACK ] = Key::Backspace; //0x08; // BACKSPACE key
165  irr2ceCODE[KEY_TAB ] = Key::Tab; //0x09; // TAB key
166  irr2ceCODE[KEY_CLEAR ] = Key::Unknown; // CLEAR key
167  irr2ceCODE[KEY_RETURN ] = Key::Return; //0x0D; // ENTER key
168  irr2ceCODE[KEY_SHIFT ] = Key::LeftShift; // SHIFT key
169  irr2ceCODE[KEY_CONTROL ] = Key::LeftControl; // CTRL key
170  irr2ceCODE[KEY_MENU ] = Key::LeftAlt; // ALT key
171  irr2ceCODE[KEY_PAUSE ] = Key::Pause; // PAUSE key
172  irr2ceCODE[KEY_CAPITAL ] = Key::Capital; // CAPS LOCK key
173  irr2ceCODE[KEY_KANA ] = Key::Kana; // IME Kana mode
174  irr2ceCODE[KEY_HANGUEL ] = Key::Unknown; // IME Hanguel mode
175  irr2ceCODE[KEY_HANGUL ] = Key::Unknown; // IME Hangul mode
176  irr2ceCODE[KEY_JUNJA ] = Key::Unknown; // IME Junja mode
177  irr2ceCODE[KEY_FINAL ] = Key::Unknown; // IME final mode
178  irr2ceCODE[KEY_HANJA ] = Key::Unknown; // IME Hanja mode
179  irr2ceCODE[KEY_KANJI ] = Key::Unknown; // IME Kanji mode
180  irr2ceCODE[KEY_ESCAPE ] = Key::Escape; // ESC key
181  irr2ceCODE[KEY_CONVERT ] = Key::Convert; // IME convert
182  irr2ceCODE[KEY_NONCONVERT] = Key::NoConvert; // IME nonconvert
183  irr2ceCODE[KEY_ACCEPT ] = Key::Unknown; // IME accept
184  irr2ceCODE[KEY_MODECHANGE] = Key::Unknown; // IME mode change request
185  irr2ceCODE[KEY_SPACE ] = Key::Space; // SPACEBAR
186  irr2ceCODE[KEY_PRIOR ] = Key::PageUp; // PAGE UP key
187  irr2ceCODE[KEY_NEXT ] = Key::PageDown; // PAGE DOWN key
188  irr2ceCODE[KEY_END ] = Key::End; // END key
189  irr2ceCODE[KEY_HOME ] = Key::Home; // HOME key
190  irr2ceCODE[KEY_LEFT ] = Key::ArrowLeft; // LEFT ARROW key
191  irr2ceCODE[KEY_UP ] = Key::ArrowUp; // UP ARROW key
192  irr2ceCODE[KEY_RIGHT ] = Key::ArrowRight; // RIGHT ARROW key
193  irr2ceCODE[KEY_DOWN ] = Key::ArrowDown; // DOWN ARROW key
194  irr2ceCODE[KEY_SELECT ] = Key::Unknown; // SELECT key
195  irr2ceCODE[KEY_PRINT ] = Key::SysRq; // PRINT key
196  irr2ceCODE[KEY_EXECUT ] = Key::Unknown; // EXECUTE key
197  irr2ceCODE[KEY_SNAPSHOT ] = Key::Unknown; // PRINT SCREEN key
198  irr2ceCODE[KEY_INSERT ] = Key::Insert;//0x2D; // INS key
199  irr2ceCODE[KEY_DELETE ] = Key::Delete;//0x2E; // DEL key
200  irr2ceCODE[KEY_HELP ] = Key::Unknown; // HELP key
201  irr2ceCODE[KEY_KEY_0 ] = Key::Zero; // 0 key
202  irr2ceCODE[KEY_KEY_1 ] = Key::One; // 1 key
203  irr2ceCODE[KEY_KEY_2 ] = Key::Two; // 2 key
204  irr2ceCODE[KEY_KEY_3 ] = Key::Three; // 3 key
205  irr2ceCODE[KEY_KEY_4 ] = Key::Four; // 4 key
206  irr2ceCODE[KEY_KEY_5 ] = Key::Five; // 5 key
207  irr2ceCODE[KEY_KEY_6 ] = Key::Six; // 6 key
208  irr2ceCODE[KEY_KEY_7 ] = Key::Seven; // 7 key
209  irr2ceCODE[KEY_KEY_8 ] = Key::Eight; // 8 key
210  irr2ceCODE[KEY_KEY_9 ] = Key::Nine; // 9 key
211  irr2ceCODE[KEY_KEY_A ] = Key::A; // A key
212  irr2ceCODE[KEY_KEY_B ] = Key::B; // B key
213  irr2ceCODE[KEY_KEY_C ] = Key::C; // C key
214  irr2ceCODE[KEY_KEY_D ] = Key::D; // D key
215  irr2ceCODE[KEY_KEY_E ] = Key::E; // E key
216  irr2ceCODE[KEY_KEY_F ] = Key::F; // F key
217  irr2ceCODE[KEY_KEY_G ] = Key::G; // G key
218  irr2ceCODE[KEY_KEY_H ] = Key::H; // H key
219  irr2ceCODE[KEY_KEY_I ] = Key::I; // I key
220  irr2ceCODE[KEY_KEY_J ] = Key::J; // J key
221  irr2ceCODE[KEY_KEY_K ] = Key::K; // K key
222  irr2ceCODE[KEY_KEY_L ] = Key::L; // L key
223  irr2ceCODE[KEY_KEY_M ] = Key::M; // M key
224  irr2ceCODE[KEY_KEY_N ] = Key::N; // N key
225  irr2ceCODE[KEY_KEY_O ] = Key::O; // O key
226  irr2ceCODE[KEY_KEY_P ] = Key::P; // P key
227  irr2ceCODE[KEY_KEY_Q ] = Key::Q; // Q key
228  irr2ceCODE[KEY_KEY_R ] = Key::R; // R key
229  irr2ceCODE[KEY_KEY_S ] = Key::S; // S key
230  irr2ceCODE[KEY_KEY_T ] = Key::T; // T key
231  irr2ceCODE[KEY_KEY_U ] = Key::U; // U key
232  irr2ceCODE[KEY_KEY_V ] = Key::V; // V key
233  irr2ceCODE[KEY_KEY_W ] = Key::W; // W key
234  irr2ceCODE[KEY_KEY_X ] = Key::X; // X key
235  irr2ceCODE[KEY_KEY_Y ] = Key::Y; // Y key
236  irr2ceCODE[KEY_KEY_Z ] = Key::Z; // Z key
237  irr2ceCODE[KEY_LWIN ] = Key::LeftWindows; // Left Windows key (Microsoft� Natural� keyboard)
238  irr2ceCODE[KEY_RWIN ] = Key::RightWindows; // Right Windows key (Natural keyboard)
239  irr2ceCODE[KEY_APPS ] = Key::AppMenu; //Applications key (Natural keyboard)
240  irr2ceCODE[KEY_SLEEP ] = Key::Sleep; // Computer Sleep key
241  irr2ceCODE[KEY_NUMPAD0 ] = Key::Numpad0; // Numeric keypad 0 key
242  irr2ceCODE[KEY_NUMPAD1 ] = Key::Numpad1; // Numeric keypad 1 key
243  irr2ceCODE[KEY_NUMPAD2 ] = Key::Numpad2; // Numeric keypad 2 key
244  irr2ceCODE[KEY_NUMPAD3 ] = Key::Numpad3; // Numeric keypad 3 key
245  irr2ceCODE[KEY_NUMPAD4 ] = Key::Numpad4; // Numeric keypad 4 key
246  irr2ceCODE[KEY_NUMPAD5 ] = Key::Numpad5; // Numeric keypad 5 key
247  irr2ceCODE[KEY_NUMPAD6 ] = Key::Numpad6; // Numeric keypad 6 key
248  irr2ceCODE[KEY_NUMPAD7 ] = Key::Numpad7; // Numeric keypad 7 key
249  irr2ceCODE[KEY_NUMPAD8 ] = Key::Numpad8; // Numeric keypad 8 key
250  irr2ceCODE[KEY_NUMPAD9 ] = Key::Numpad9; // Numeric keypad 9 key
251  irr2ceCODE[KEY_MULTIPLY ] = Key::Multiply; // Multiply key
252  irr2ceCODE[KEY_ADD ] = Key::Add; // Add key
253  irr2ceCODE[KEY_SEPARATOR ] = Key::Unknown; // Separator key
254  irr2ceCODE[KEY_SUBTRACT ] = Key::Subtract; // Subtract key
255  irr2ceCODE[KEY_DECIMAL ] = Key::Decimal; // Decimal key
256  irr2ceCODE[KEY_DIVIDE ] = Key::Divide; // Divide key
257  irr2ceCODE[KEY_F1 ] = Key::F1; // F1 key
258  irr2ceCODE[KEY_F2 ] = Key::F2; // F2 key
259  irr2ceCODE[KEY_F3 ] = Key::F3; // F3 key
260  irr2ceCODE[KEY_F4 ] = Key::F4; // F4 key
261  irr2ceCODE[KEY_F5 ] = Key::F5; // F5 key
262  irr2ceCODE[KEY_F6 ] = Key::F6; // F6 key
263  irr2ceCODE[KEY_F7 ] = Key::F7; // F7 key
264  irr2ceCODE[KEY_F8 ] = Key::F8; // F8 key
265  irr2ceCODE[KEY_F9 ] = Key::F9; // F9 key
266  irr2ceCODE[KEY_F10 ] = Key::F10; // F10 key
267  irr2ceCODE[KEY_F11 ] = Key::F11; // F11 key
268  irr2ceCODE[KEY_F12 ] = Key::F12; // F12 key
269  irr2ceCODE[KEY_F13 ] = Key::F13; // F13 key
270  irr2ceCODE[KEY_F14 ] = Key::F14; // F14 key
271  irr2ceCODE[KEY_F15 ] = Key::F15; // F15 key
272  irr2ceCODE[KEY_F16 ] = Key::Unknown; // F16 key
273  irr2ceCODE[KEY_F17 ] = Key::Unknown; // F17 key
274  irr2ceCODE[KEY_F18 ] = Key::Unknown; // F18 key
275  irr2ceCODE[KEY_F19 ] = Key::Unknown; // F19 key
276  irr2ceCODE[KEY_F20 ] = Key::Unknown; // F20 key
277  irr2ceCODE[KEY_F21 ] = Key::Unknown; // F21 key
278  irr2ceCODE[KEY_F22 ] = Key::Unknown; // F22 key
279  irr2ceCODE[KEY_F23 ] = Key::Unknown; // F23 key
280  irr2ceCODE[KEY_F24 ] = Key::Unknown; // F24 key
281  irr2ceCODE[KEY_NUMLOCK ] = Key::NumLock; // NUM LOCK key
282  irr2ceCODE[KEY_SCROLL ] = Key::ScrollLock; // SCROLL LOCK key
283  irr2ceCODE[KEY_LSHIFT ] = Key::LeftShift; // Left SHIFT key
284  irr2ceCODE[KEY_RSHIFT ] = Key::RightShift; // Right SHIFT key
285  irr2ceCODE[KEY_LCONTROL ] = Key::LeftControl; // Left CONTROL key
286  irr2ceCODE[KEY_RCONTROL ] = Key::RightControl; // Right CONTROL key
287  irr2ceCODE[KEY_LMENU ] = Key::LeftAlt; // Left MENU key
288  irr2ceCODE[KEY_RMENU ] = Key::RightAlt; // Right MENU key
289  irr2ceCODE[KEY_COMMA ] = Key::Comma;//0xBC; // Comma Key (;)
290  irr2ceCODE[KEY_PLUS ] = Key::Add; // Plus Key (+)
291  irr2ceCODE[KEY_MINUS ] = Key::Minus; // Minus Key (-)
292  irr2ceCODE[KEY_PERIOD ] = Key::Period;//0xBE; // Period Key (.)
293  irr2ceCODE[KEY_ATTN ] = Key::Unknown; // Attn key
294  irr2ceCODE[KEY_CRSEL ] = Key::Unknown; // CrSel key
295  irr2ceCODE[KEY_EXSEL ] = Key::Unknown; // ExSel key
296  irr2ceCODE[KEY_EREOF ] = Key::Unknown; // Erase EOF key
297  irr2ceCODE[KEY_PLAY ] = Key::Unknown; // Play key
298  irr2ceCODE[KEY_ZOOM ] = Key::Unknown; // Zoom key
299  irr2ceCODE[KEY_PA1 ] = Key::Unknown; // PA1 key
300  irr2ceCODE[KEY_OEM_CLEAR ] = Key::Unknown; // Clear key
301  }
302 
303 };
304 
305 }
306 
307 #endif