• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List

CEGUIIrrlichtEventPusher.h

00001 /***********************************************************************
00002     filename:   CEGUIIrrlichtEventPusher.h
00003     created:    12/22/2004
00004     author:     Thomas Suter
00005 *************************************************************************/
00006 /***************************************************************************
00007  *   Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
00008  *
00009  *   Permission is hereby granted, free of charge, to any person obtaining
00010  *   a copy of this software and associated documentation files (the
00011  *   "Software"), to deal in the Software without restriction, including
00012  *   without limitation the rights to use, copy, modify, merge, publish,
00013  *   distribute, sublicense, and/or sell copies of the Software, and to
00014  *   permit persons to whom the Software is furnished to do so, subject to
00015  *   the following conditions:
00016  *
00017  *   The above copyright notice and this permission notice shall be
00018  *   included in all copies or substantial portions of the Software.
00019  *
00020  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00021  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00022  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00023  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00024  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00025  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00026  *   OTHER DEALINGS IN THE SOFTWARE.
00027  ***************************************************************************/
00028 #ifndef CCEGUIEVENTPUSHER_H_INCLUDED
00029 #define CCEGUIEVENTPUSHER_H_INCLUDED
00030 
00031 #include "../../CEGUI.h"
00032 #include <irrlicht.h>
00033 
00034 namespace CEGUI
00035 {
00036 using namespace irr;
00037 
00038 class IrrlichtEventPusher
00039 {
00040     gui::ICursorControl* d_cursorctrl;
00041 
00042 public :
00043     IrrlichtEventPusher(irr::gui::ICursorControl* ctrl) :
00044         d_cursorctrl(ctrl)
00045     {
00046         initCodes();
00047     };
00048 
00049     virtual ~IrrlichtEventPusher(){};
00050 
00051     bool OnEvent(const SEvent& event)
00052     {
00053         switch (event.EventType)
00054         {
00055         case EET_KEY_INPUT_EVENT :
00056             if (event.KeyInput.PressedDown)
00057                 return OnKeyDown(event.KeyInput.Key, event.KeyInput.Char, event.KeyInput.Control, event.KeyInput.Shift);
00058             else
00059                 return OnKeyUp(event.KeyInput.Key, event.KeyInput.Char, event.KeyInput.Control, event.KeyInput.Shift);
00060             break;
00061 
00062         case EET_MOUSE_INPUT_EVENT :
00063             return OnMouse(event.MouseInput.X, event.MouseInput.Y, event.MouseInput.Wheel, event.MouseInput.Event);
00064             break;
00065 
00066         default:
00067             break;
00068         }
00069 
00070         return false;
00071     }
00072 
00073     bool OnKeyDown(EKEY_CODE key, wchar_t wch, bool /*ctrl*/, bool /*shift*/)
00074     {
00075         bool handled = false;
00076         CEGUI::System& cegui = CEGUI::System::getSingleton();
00077         handled = cegui.injectKeyDown(getKeyCode(key));
00078         handled = cegui.injectChar(wch) || handled;
00079         return handled;
00080     }
00081 
00082     bool OnKeyUp(EKEY_CODE key, wchar_t /*wch*/, bool /*ctrl*/, bool /*shift*/)
00083     {
00084         bool handled = false;
00085         CEGUI::System& cegui = CEGUI::System::getSingleton();
00086         handled = cegui.injectKeyUp(getKeyCode(key));
00087         return handled;
00088     }
00089 
00090     bool OnMouse(s32 x, s32 y, f32 w, EMOUSE_INPUT_EVENT e)
00091     {
00092         using namespace irr;
00093         bool handled = false;
00094 
00095         switch (e)
00096         {
00098         case EMIE_LMOUSE_PRESSED_DOWN:
00099             handled = CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
00100             break;
00102         case EMIE_RMOUSE_PRESSED_DOWN:
00103             handled = CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
00104             break;
00106         case EMIE_MMOUSE_PRESSED_DOWN:
00107             handled = CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
00108             break;
00110         case EMIE_LMOUSE_LEFT_UP:
00111             handled = CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
00112             break;
00114         case EMIE_RMOUSE_LEFT_UP:
00115             handled = CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
00116             break;
00118         case EMIE_MMOUSE_LEFT_UP:
00119             handled = CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
00120             break;
00122         case EMIE_MOUSE_MOVED:
00123             handled = CEGUI::System::getSingleton().injectMousePosition(
00124                         static_cast<float>(x), static_cast<float>(y));
00125             break;
00128         case EMIE_MOUSE_WHEEL:
00129             handled = CEGUI::System::getSingleton().injectMouseWheelChange(w);
00130             break;
00131         default:
00132             break;
00133         }
00134         return handled;
00135 
00136     }
00137 
00138 protected:
00139     unsigned char irr2ceCODE[irr::KEY_KEY_CODES_COUNT];
00140 
00141     void initCodes()
00142     {
00143         using namespace irr;
00144         memset(irr2ceCODE, 0, KEY_KEY_CODES_COUNT);
00145 
00146         irr2ceCODE[KEY_LBUTTON   ] = 0;  // Left mouse button
00147         irr2ceCODE[KEY_RBUTTON   ] = 0;  // Right mouse button
00148         irr2ceCODE[KEY_CANCEL    ] = 0;  // Control-break processing
00149         irr2ceCODE[KEY_MBUTTON   ] = 0;  // Middle mouse button (three-button mouse)
00150         irr2ceCODE[KEY_XBUTTON1  ] = 0;  // Windows 2000/XP: X1 mouse button
00151         irr2ceCODE[KEY_XBUTTON2  ] = 0;  // Windows 2000/XP: X2 mouse button
00152         irr2ceCODE[KEY_BACK      ] = Key::Backspace; //0x08;  // BACKSPACE key
00153         irr2ceCODE[KEY_TAB       ] = Key::Tab; //0x09;  // TAB key
00154         irr2ceCODE[KEY_CLEAR     ] = 0;  // CLEAR key
00155         irr2ceCODE[KEY_RETURN    ] = Key::Return; //0x0D;  // ENTER key
00156         irr2ceCODE[KEY_SHIFT     ] = Key::LeftShift;  // SHIFT key
00157         irr2ceCODE[KEY_CONTROL   ] = Key::LeftControl;   // CTRL key
00158         irr2ceCODE[KEY_MENU      ] = Key::LeftAlt;  // ALT key
00159         irr2ceCODE[KEY_PAUSE     ] = Key::Pause;   // PAUSE key
00160         irr2ceCODE[KEY_CAPITAL   ] = Key::Capital;  // CAPS LOCK key
00161         irr2ceCODE[KEY_KANA      ] = Key::Kana;  // IME Kana mode
00162         irr2ceCODE[KEY_HANGUEL   ] = KEY_HANGUEL;  // IME Hanguel mode
00163         irr2ceCODE[KEY_HANGUL    ] = KEY_HANGUL;  // IME Hangul mode
00164         irr2ceCODE[KEY_JUNJA     ] = 0;  // IME Junja mode
00165         irr2ceCODE[KEY_FINAL     ] = 0;  // IME final mode
00166         irr2ceCODE[KEY_HANJA     ] = 0;  // IME Hanja mode
00167         irr2ceCODE[KEY_KANJI     ] = 0;  // IME Kanji mode
00168         irr2ceCODE[KEY_ESCAPE    ] = Key::Escape;  // ESC key
00169         irr2ceCODE[KEY_CONVERT   ] = Key::Convert;  // IME convert
00170         irr2ceCODE[KEY_NONCONVERT] = Key::NoConvert;  // IME nonconvert
00171         irr2ceCODE[KEY_ACCEPT    ] = 0;  // IME accept
00172         irr2ceCODE[KEY_MODECHANGE] = 0;  // IME mode change request
00173         irr2ceCODE[KEY_SPACE     ] = Key::Space;  // SPACEBAR
00174         irr2ceCODE[KEY_PRIOR     ] = Key::PageUp;  // PAGE UP key
00175         irr2ceCODE[KEY_NEXT      ] = Key::PageDown;  // PAGE DOWN key
00176         irr2ceCODE[KEY_END       ] = Key::End;  // END key
00177         irr2ceCODE[KEY_HOME      ] = Key::Home;  // HOME key
00178         irr2ceCODE[KEY_LEFT      ] = Key::ArrowLeft;  // LEFT ARROW key
00179         irr2ceCODE[KEY_UP        ] = Key::ArrowUp;  // UP ARROW key
00180         irr2ceCODE[KEY_RIGHT     ] = Key::ArrowRight;  // RIGHT ARROW key
00181         irr2ceCODE[KEY_DOWN      ] = Key::ArrowDown;  // DOWN ARROW key
00182         irr2ceCODE[KEY_SELECT    ] = 0;  // SELECT key
00183         irr2ceCODE[KEY_PRINT     ] = Key::SysRq;  // PRINT key
00184         irr2ceCODE[KEY_EXECUT    ] = 0;  // EXECUTE key
00185         irr2ceCODE[KEY_SNAPSHOT  ] = 0;  // PRINT SCREEN key
00186         irr2ceCODE[KEY_INSERT    ] = Key::Insert;//0x2D;  // INS key
00187         irr2ceCODE[KEY_DELETE    ] = Key::Delete;//0x2E;  // DEL key
00188         irr2ceCODE[KEY_HELP      ] = 0;  // HELP key
00189         irr2ceCODE[KEY_KEY_0     ] = Key::Zero;   // 0 key
00190         irr2ceCODE[KEY_KEY_1     ] = Key::One;    // 1 key
00191         irr2ceCODE[KEY_KEY_2     ] = Key::Two;    // 2 key
00192         irr2ceCODE[KEY_KEY_3     ] = Key::Three;  // 3 key
00193         irr2ceCODE[KEY_KEY_4     ] = Key::Four;   // 4 key
00194         irr2ceCODE[KEY_KEY_5     ] = Key::Five;   // 5 key
00195         irr2ceCODE[KEY_KEY_6     ] = Key::Six;    // 6 key
00196         irr2ceCODE[KEY_KEY_7     ] = Key::Seven;  // 7 key
00197         irr2ceCODE[KEY_KEY_8     ] = Key::Eight;  // 8 key
00198         irr2ceCODE[KEY_KEY_9     ] = Key::Nine;   // 9 key
00199         irr2ceCODE[KEY_KEY_A     ] = Key::A;  // A key
00200         irr2ceCODE[KEY_KEY_B     ] = Key::B;  // B key
00201         irr2ceCODE[KEY_KEY_C     ] = Key::C;  // C key
00202         irr2ceCODE[KEY_KEY_D     ] = Key::D;  // D key
00203         irr2ceCODE[KEY_KEY_E     ] = Key::E;  // E key
00204         irr2ceCODE[KEY_KEY_F     ] = Key::F;  // F key
00205         irr2ceCODE[KEY_KEY_G     ] = Key::G;  // G key
00206         irr2ceCODE[KEY_KEY_H     ] = Key::H;  // H key
00207         irr2ceCODE[KEY_KEY_I     ] = Key::I;  // I key
00208         irr2ceCODE[KEY_KEY_J     ] = Key::J;  // J key
00209         irr2ceCODE[KEY_KEY_K     ] = Key::K;  // K key
00210         irr2ceCODE[KEY_KEY_L     ] = Key::L;  // L key
00211         irr2ceCODE[KEY_KEY_M     ] = Key::M;  // M key
00212         irr2ceCODE[KEY_KEY_N     ] = Key::N;  // N key
00213         irr2ceCODE[KEY_KEY_O     ] = Key::O;  // O key
00214         irr2ceCODE[KEY_KEY_P     ] = Key::P;  // P key
00215         irr2ceCODE[KEY_KEY_Q     ] = Key::Q;  // Q key
00216         irr2ceCODE[KEY_KEY_R     ] = Key::R;  // R key
00217         irr2ceCODE[KEY_KEY_S     ] = Key::S;  // S key
00218         irr2ceCODE[KEY_KEY_T     ] = Key::T;  // T key
00219         irr2ceCODE[KEY_KEY_U     ] = Key::U;  // U key
00220         irr2ceCODE[KEY_KEY_V     ] = Key::V;  // V key
00221         irr2ceCODE[KEY_KEY_W     ] = Key::W;  // W key
00222         irr2ceCODE[KEY_KEY_X     ] = Key::X;  // X key
00223         irr2ceCODE[KEY_KEY_Y     ] = Key::Y;  // Y key
00224         irr2ceCODE[KEY_KEY_Z     ] = Key::Z;  // Z key
00225         irr2ceCODE[KEY_LWIN      ] = Key::LeftWindows;  // Left Windows key (Microsoft� Natural� keyboard)
00226         irr2ceCODE[KEY_RWIN      ] = Key::RightWindows;  // Right Windows key (Natural keyboard)
00227         irr2ceCODE[KEY_APPS      ] = Key::AppMenu;  //Applications key (Natural keyboard)
00228         irr2ceCODE[KEY_SLEEP     ] = Key::Sleep;  // Computer Sleep key
00229         irr2ceCODE[KEY_NUMPAD0   ] = Key::Numpad0;  // Numeric keypad 0 key
00230         irr2ceCODE[KEY_NUMPAD1   ] = Key::Numpad1;  // Numeric keypad 1 key
00231         irr2ceCODE[KEY_NUMPAD2   ] = Key::Numpad2;  // Numeric keypad 2 key
00232         irr2ceCODE[KEY_NUMPAD3   ] = Key::Numpad3;  // Numeric keypad 3 key
00233         irr2ceCODE[KEY_NUMPAD4   ] = Key::Numpad4;  // Numeric keypad 4 key
00234         irr2ceCODE[KEY_NUMPAD5   ] = Key::Numpad5;  // Numeric keypad 5 key
00235         irr2ceCODE[KEY_NUMPAD6   ] = Key::Numpad6;  // Numeric keypad 6 key
00236         irr2ceCODE[KEY_NUMPAD7   ] = Key::Numpad7;  // Numeric keypad 7 key
00237         irr2ceCODE[KEY_NUMPAD8   ] = Key::Numpad8;  // Numeric keypad 8 key
00238         irr2ceCODE[KEY_NUMPAD9   ] = Key::Numpad9;  // Numeric keypad 9 key
00239         irr2ceCODE[KEY_MULTIPLY  ] = Key::Multiply;  // Multiply key
00240         irr2ceCODE[KEY_ADD       ] = Key::Add;  // Add key
00241         irr2ceCODE[KEY_SEPARATOR ] = 0;  // Separator key
00242         irr2ceCODE[KEY_SUBTRACT  ] = Key::Subtract;  // Subtract key
00243         irr2ceCODE[KEY_DECIMAL   ] = Key::Decimal;  // Decimal key
00244         irr2ceCODE[KEY_DIVIDE    ] = Key::Divide;  // Divide key
00245         irr2ceCODE[KEY_F1        ] = Key::F1;   // F1 key
00246         irr2ceCODE[KEY_F2        ] = Key::F2;   // F2 key
00247         irr2ceCODE[KEY_F3        ] = Key::F3;   // F3 key
00248         irr2ceCODE[KEY_F4        ] = Key::F4;   // F4 key
00249         irr2ceCODE[KEY_F5        ] = Key::F5;   // F5 key
00250         irr2ceCODE[KEY_F6        ] = Key::F6;   // F6 key
00251         irr2ceCODE[KEY_F7        ] = Key::F7;   // F7 key
00252         irr2ceCODE[KEY_F8        ] = Key::F8;   // F8 key
00253         irr2ceCODE[KEY_F9        ] = Key::F9;   // F9 key
00254         irr2ceCODE[KEY_F10       ] = Key::F10;  // F10 key
00255         irr2ceCODE[KEY_F11       ] = Key::F11;  // F11 key
00256         irr2ceCODE[KEY_F12       ] = Key::F12;  // F12 key
00257         irr2ceCODE[KEY_F13       ] = Key::F13;  // F13 key
00258         irr2ceCODE[KEY_F14       ] = Key::F14;  // F14 key
00259         irr2ceCODE[KEY_F15       ] = Key::F15;  // F15 key
00260         irr2ceCODE[KEY_F16       ] = 0;  // F16 key
00261         irr2ceCODE[KEY_F17       ] = 0;  // F17 key
00262         irr2ceCODE[KEY_F18       ] = 0;  // F18 key
00263         irr2ceCODE[KEY_F19       ] = 0;  // F19 key
00264         irr2ceCODE[KEY_F20       ] = 0;  // F20 key
00265         irr2ceCODE[KEY_F21       ] = 0;  // F21 key
00266         irr2ceCODE[KEY_F22       ] = 0;  // F22 key
00267         irr2ceCODE[KEY_F23       ] = 0;  // F23 key
00268         irr2ceCODE[KEY_F24       ] = 0;  // F24 key
00269         irr2ceCODE[KEY_NUMLOCK   ] = Key::NumLock;  // NUM LOCK key
00270         irr2ceCODE[KEY_SCROLL    ] = Key::ScrollLock;  // SCROLL LOCK key
00271         irr2ceCODE[KEY_LSHIFT    ] = Key::LeftShift;  // Left SHIFT key
00272         irr2ceCODE[KEY_RSHIFT    ] = Key::RightShift;  // Right SHIFT key
00273         irr2ceCODE[KEY_LCONTROL  ] = Key::LeftControl;  // Left CONTROL key
00274         irr2ceCODE[KEY_RCONTROL  ] = Key::RightControl;  // Right CONTROL key
00275         irr2ceCODE[KEY_LMENU     ] = Key::LeftAlt;  // Left MENU key
00276         irr2ceCODE[KEY_RMENU     ] = Key::RightAlt;  // Right MENU key
00277         irr2ceCODE[KEY_COMMA     ] = Key::Comma;//0xBC;  // Comma Key  (;)
00278         irr2ceCODE[KEY_PLUS      ] = Key::Add;  // Plus Key   (+)
00279         irr2ceCODE[KEY_MINUS     ] = Key::Minus;  // Minus Key  (-)
00280         irr2ceCODE[KEY_PERIOD    ] = Key::Period;//0xBE;  // Period Key (.)
00281         irr2ceCODE[KEY_ATTN      ] = 0;  // Attn key
00282         irr2ceCODE[KEY_CRSEL     ] = 0;  // CrSel key
00283         irr2ceCODE[KEY_EXSEL     ] = 0;  // ExSel key
00284         irr2ceCODE[KEY_EREOF     ] = 0;  // Erase EOF key
00285         irr2ceCODE[KEY_PLAY      ] = 0;  // Play key
00286         irr2ceCODE[KEY_ZOOM      ] = 0;  // Zoom key
00287         irr2ceCODE[KEY_PA1       ] = 0;  // PA1 key
00288         irr2ceCODE[KEY_OEM_CLEAR ] = 0;  // Clear key
00289     }
00290 
00298     uchar getKeyCode(irr::EKEY_CODE kc)
00299     {
00300         return irr2ceCODE[kc];
00301     }
00302 };
00303 
00304 }
00305 
00306 #endif

Generated on Fri Nov 19 2010 12:01:19 for Crazy Eddies GUI System by  doxygen 1.7.2