Crazy Eddies GUI System: IrrlichtEventPusher.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# IrrlichtEventPusher.h

    00001 /************************************************************************
    00002 filename:       IrrlichtEventPusher.h
    00003 created:        12/22/2004
    00004 author:         Thomas Suter
    00005 *************************************************************************/
    00006 /*************************************************************************
    00007 Crazy Eddie's GUI System (http://www.cegui.org.uk)
    00008 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
    00009
    00010 This library is free software; you can redistribute it and/or
    00011 modify it under the terms of the GNU Lesser General Public
    00012 License as published by the Free Software Foundation; either
    00013 version 2.1 of the License, or (at your option) any later version.
    00014
    00015 This library is distributed in the hope that it will be useful,
    00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018 Lesser General Public License for more details.
    00019
    00020 You should have received a copy of the GNU Lesser General Public
    00021 License along with this library; if not, write to the Free Software
    00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00023 *************************************************************************/
    00024 #ifndef CCEGUIEVENTPUSHER_H_INCLUDED
    00025 #define CCEGUIEVENTPUSHER_H_INCLUDED
    00026
    00027 #include <CEGUI.h>
    00028 #include <irrlicht.h>
    00029
    00030 namespace CEGUI
    00031 {
    00032         using namespace irr;
    00033
    00034         class EventPusher
    00035         {
    00036                 gui::ICursorControl* cursorctrl;
    00037
    00038                 core::position2d<s32> pos;
    00039                 core::position2d<s32> dpos;
    00040
    00041         public :
    00042
    00043                 EventPusher(irr::gui::ICursorControl* ctrl)
    00044                         :cursorctrl(ctrl)
    00045                 {
    00046                         cursorctrl->setPosition(0.5f,0.5f);
    00047                         pos=cursorctrl->getPosition();
    00048                         dpos.X=0;
    00049                         dpos.Y=0;
    00050                         initCodes();
    00051                 };
    00052
    00053                 virtual ~EventPusher(){};
    00054
    00055                 bool OnEvent(SEvent& event)
    00056                 {
    00057                         switch(event.EventType)
    00058                         {
    00059                         case EET_KEY_INPUT_EVENT :
    00060                                 if(event.KeyInput.PressedDown)
    00061                                         return OnKeyDown(event.KeyInput.Key,event.KeyInput.Char,event.KeyInput.Control,event.KeyInput.Shift);
    00062                                 else
    00063                                         return OnKeyUp(event.KeyInput.Key,event.KeyInput.Char,event.KeyInput.Control,event.KeyInput.Shift);
    00064                                 break;
    00065
    00066                         case EET_MOUSE_INPUT_EVENT :
    00067                                 return OnMouse(event.MouseInput.X,event.MouseInput.Y,event.MouseInput.Wheel,event.MouseInput.Event);
    00068                                 break;
    00069
    00070                         default:
    00071                                 break;
    00072                         }
    00073                         return false;
    00074                 }
    00075
    00076                 bool OnKeyDown(EKEY_CODE key, wchar_t wch, bool ctrl, bool shift)
    00077                 {
    00078                         bool handled=false;
    00079                         CEGUI::System& cegui = CEGUI::System::getSingleton();
    00080                         handled = cegui.injectKeyDown(getKeyCode(key));
    00081                         handled = cegui.injectChar(wch) || handled;
    00082                         return handled;
    00083                 }
    00084
    00085                 bool OnKeyUp(EKEY_CODE key, wchar_t wch, bool ctrl, bool shift)
    00086                 {
    00087                         bool handled=false;
    00088                         CEGUI::System& cegui = CEGUI::System::getSingleton();
    00089                         handled=cegui.injectKeyUp(getKeyCode(key));
    00090                         return handled;
    00091                 }
    00092
    00093                 bool OnMouse(s32 x, s32 y, f32 w, EMOUSE_INPUT_EVENT e)
    00094                 {
    00095                         using namespace irr;
    00096                         bool handled=false;
    00097
    00098                         switch(e)
    00099                         {
    00101                         case EMIE_LMOUSE_PRESSED_DOWN:
    00102                                 handled=CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
    00104                         case EMIE_RMOUSE_PRESSED_DOWN:
    00105                                 handled=CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
    00106                                 break;
    00108                         case EMIE_MMOUSE_PRESSED_DOWN:
    00109                                 handled=CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
    00110                                 break;
    00112                         case EMIE_LMOUSE_LEFT_UP:
    00113                                 handled=CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
    00114                                 break;
    00116                         case EMIE_RMOUSE_LEFT_UP:
    00117                                 handled=CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
    00118                                 break;
    00120                         case EMIE_MMOUSE_LEFT_UP:
    00121                                 handled=CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
    00122                                 break;
    00124                         case EMIE_MOUSE_MOVED:
    00125                                 dpos.X=x-pos.X;
    00126                                 dpos.Y=y-pos.Y;
    00127                                 pos.X=x;
    00128                                 pos.Y=y;
    00129                                 CEGUI::MouseCursor::getSingleton().setPosition(CEGUI::Point(float(pos.X),float(pos.Y)));
    00130                                 handled=CEGUI::System::getSingleton().injectMouseMove(0.0f, 0.0f);
    00131                                 //handled=CEGUI::System::getSingleton().injectMouseMove(float(dpos.X), float(dpos.Y));
    00132                                 break;
    00135                         case EMIE_MOUSE_WHEEL:
    00136                                 handled=CEGUI::System::getSingleton().injectMouseWheelChange(w);
    00137                                 break;
    00138                         default:
    00139                                 break;
    00140
    00141                         }
    00142                         return handled;
    00143
    00144                 }
    00145
    00146                 protected:
    00147
    00148                         unsigned char irr2ceCODE[irr::KEY_KEY_CODES_COUNT];
    00149
    00150                         void initCodes()
    00151                         {
    00152                                 using namespace irr;
    00153                                 memset(irr2ceCODE,0,KEY_KEY_CODES_COUNT);
    00154
    00155                                 irr2ceCODE[KEY_LBUTTON          ] = 0;  // Left mouse button
    00156                                 irr2ceCODE[KEY_RBUTTON          ] = 0;  // Right mouse button
    00157                                 irr2ceCODE[KEY_CANCEL           ] = 0;  // Control-break processing
    00158                                 irr2ceCODE[KEY_MBUTTON          ] = 0;  // Middle mouse button (three-button mouse)
    00159                                 irr2ceCODE[KEY_XBUTTON1         ] = 0;  // Windows 2000/XP: X1 mouse button
    00160                                 irr2ceCODE[KEY_XBUTTON2         ] = 0;  // Windows 2000/XP: X2 mouse button
    00161                                 irr2ceCODE[KEY_BACK             ] = Key::Backspace; //0x08;  // BACKSPACE key
    00162                                 irr2ceCODE[KEY_TAB              ] = Key::Tab; //0x09;  // TAB key
    00163                                 irr2ceCODE[KEY_CLEAR            ] = 0;  // CLEAR key
    00164                                 irr2ceCODE[KEY_RETURN           ] = Key::Return; //0x0D;  // ENTER key
    00165                                 irr2ceCODE[KEY_SHIFT            ] = Key::LeftShift;  // SHIFT key
    00166                                 irr2ceCODE[KEY_CONTROL          ] = Key::LeftControl;   // CTRL key
    00167                                 irr2ceCODE[KEY_MENU             ] = Key::LeftAlt;  // ALT key
    00168                                 irr2ceCODE[KEY_PAUSE            ] = Key::Pause;   // PAUSE key
    00169                                 irr2ceCODE[KEY_CAPITAL          ] = Key::Capital;  // CAPS LOCK key
    00170                                 irr2ceCODE[KEY_KANA             ] = Key::Kana;  // IME Kana mode
    00171                                 irr2ceCODE[KEY_HANGUEL          ] = KEY_HANGUEL;  // IME Hanguel mode
    00172                                 irr2ceCODE[KEY_HANGUL           ] = KEY_HANGUL;  // IME Hangul mode
    00173                                 irr2ceCODE[KEY_JUNJA            ] = 0;  // IME Junja mode
    00174                                 irr2ceCODE[KEY_FINAL            ] = 0;  // IME final mode
    00175                                 irr2ceCODE[KEY_HANJA            ] = 0;  // IME Hanja mode
    00176                                 irr2ceCODE[KEY_KANJI            ] = 0;  // IME Kanji mode
    00177                                 irr2ceCODE[KEY_ESCAPE           ] = Key::Escape;  // ESC key
    00178                                 irr2ceCODE[KEY_CONVERT          ] = Key::Convert;  // IME convert
    00179                                 irr2ceCODE[KEY_NONCONVERT       ] = Key::NoConvert;  // IME nonconvert
    00180                                 irr2ceCODE[KEY_ACCEPT           ] = 0;  // IME accept
    00181                                 irr2ceCODE[KEY_MODECHANGE       ] = 0;  // IME mode change request
    00182                                 irr2ceCODE[KEY_SPACE            ] = Key::Space;  // SPACEBAR
    00183                                 irr2ceCODE[KEY_PRIOR            ] = Key::PageUp;  // PAGE UP key
    00184                                 irr2ceCODE[KEY_NEXT             ] = Key::PageDown;  // PAGE DOWN key
    00185                                 irr2ceCODE[KEY_END              ] = Key::End;  // END key
    00186                                 irr2ceCODE[KEY_HOME             ] = Key::Home;  // HOME key
    00187                                 irr2ceCODE[KEY_LEFT             ] = Key::ArrowLeft;  // LEFT ARROW key
    00188                                 irr2ceCODE[KEY_UP               ] = Key::ArrowUp;  // UP ARROW key
    00189                                 irr2ceCODE[KEY_RIGHT            ] = Key::ArrowRight;  // RIGHT ARROW key
    00190                                 irr2ceCODE[KEY_DOWN             ] = Key::ArrowDown;  // DOWN ARROW key
    00191                                 irr2ceCODE[KEY_SELECT           ] = 0;  // SELECT key
    00192                                 irr2ceCODE[KEY_PRINT            ] = Key::SysRq;  // PRINT key
    00193                                 irr2ceCODE[KEY_EXECUT           ] = 0;  // EXECUTE key
    00194                                 irr2ceCODE[KEY_SNAPSHOT         ] = 0;  // PRINT SCREEN key
    00195                                 irr2ceCODE[KEY_INSERT           ] = Key::Insert;//0x2D;  // INS key
    00196                                 irr2ceCODE[KEY_DELETE           ] = Key::Delete;//0x2E;  // DEL key
    00197                                 irr2ceCODE[KEY_HELP             ] = 0;  // HELP key
    00198                                 irr2ceCODE[KEY_KEY_0            ] = Key::Zero;   // 0 key
    00199                                 irr2ceCODE[KEY_KEY_1            ] = Key::One;    // 1 key
    00200                                 irr2ceCODE[KEY_KEY_2            ] = Key::Two;    // 2 key
    00201                                 irr2ceCODE[KEY_KEY_3            ] = Key::Three;  // 3 key
    00202                                 irr2ceCODE[KEY_KEY_4            ] = Key::Four;   // 4 key
    00203                                 irr2ceCODE[KEY_KEY_5            ] = Key::Five;   // 5 key
    00204                                 irr2ceCODE[KEY_KEY_6            ] = Key::Six;    // 6 key
    00205                                 irr2ceCODE[KEY_KEY_7            ] = Key::Seven;  // 7 key
    00206                                 irr2ceCODE[KEY_KEY_8            ] = Key::Eight;  // 8 key
    00207                                 irr2ceCODE[KEY_KEY_9            ] = Key::Nine;   // 9 key
    00208                                 irr2ceCODE[KEY_KEY_A            ] = Key::A;  // A key
    00209                                 irr2ceCODE[KEY_KEY_B            ] = Key::B;  // B key
    00210                                 irr2ceCODE[KEY_KEY_C            ] = Key::C;  // C key
    00211                                 irr2ceCODE[KEY_KEY_D            ] = Key::D;  // D key
    00212                                 irr2ceCODE[KEY_KEY_E            ] = Key::E;  // E key
    00213                                 irr2ceCODE[KEY_KEY_F            ] = Key::F;  // F key
    00214                                 irr2ceCODE[KEY_KEY_G            ] = Key::G;  // G key
    00215                                 irr2ceCODE[KEY_KEY_H            ] = Key::H;  // H key
    00216                                 irr2ceCODE[KEY_KEY_I            ] = Key::I;  // I key
    00217                                 irr2ceCODE[KEY_KEY_J            ] = Key::J;  // J key
    00218                                 irr2ceCODE[KEY_KEY_K            ] = Key::K;  // K key
    00219                                 irr2ceCODE[KEY_KEY_L            ] = Key::L;  // L key
    00220                                 irr2ceCODE[KEY_KEY_M            ] = Key::M;  // M key
    00221                                 irr2ceCODE[KEY_KEY_N            ] = Key::N;  // N key
    00222                                 irr2ceCODE[KEY_KEY_O            ] = Key::O;  // O key
    00223                                 irr2ceCODE[KEY_KEY_P            ] = Key::P;  // P key
    00224                                 irr2ceCODE[KEY_KEY_Q            ] = Key::Q;  // Q key
    00225                                 irr2ceCODE[KEY_KEY_R            ] = Key::R;  // R key
    00226                                 irr2ceCODE[KEY_KEY_S            ] = Key::S;  // S key
    00227                                 irr2ceCODE[KEY_KEY_T            ] = Key::T;  // T key
    00228                                 irr2ceCODE[KEY_KEY_U            ] = Key::U;  // U key
    00229                                 irr2ceCODE[KEY_KEY_V            ] = Key::V;  // V key
    00230                                 irr2ceCODE[KEY_KEY_W            ] = Key::W;  // W key
    00231                                 irr2ceCODE[KEY_KEY_X            ] = Key::X;  // X key
    00232                                 irr2ceCODE[KEY_KEY_Y            ] = Key::Y;  // Y key
    00233                                 irr2ceCODE[KEY_KEY_Z            ] = Key::Z;  // Z key
    00234                                 irr2ceCODE[KEY_LWIN             ] = Key::LeftWindows;  // Left Windows key (Microsoft® Natural® keyboard)
    00235                                 irr2ceCODE[KEY_RWIN             ] = Key::RightWindow;  // Right Windows key (Natural keyboard)
    00236                                 irr2ceCODE[KEY_APPS             ] = Key::AppMenu;  //Applications key (Natural keyboard)
    00237                                 irr2ceCODE[KEY_SLEEP            ] = Key::Sleep;  // Computer Sleep key
    00238                                 irr2ceCODE[KEY_NUMPAD0          ] = Key::Numpad0;  // Numeric keypad 0 key
    00239                                 irr2ceCODE[KEY_NUMPAD1          ] = Key::Numpad1;  // Numeric keypad 1 key
    00240                                 irr2ceCODE[KEY_NUMPAD2          ] = Key::Numpad2;  // Numeric keypad 2 key
    00241                                 irr2ceCODE[KEY_NUMPAD3          ] = Key::Numpad3;  // Numeric keypad 3 key
    00242                                 irr2ceCODE[KEY_NUMPAD4          ] = Key::Numpad4;  // Numeric keypad 4 key
    00243                                 irr2ceCODE[KEY_NUMPAD5          ] = Key::Numpad5;  // Numeric keypad 5 key
    00244                                 irr2ceCODE[KEY_NUMPAD6          ] = Key::Numpad6;  // Numeric keypad 6 key
    00245                                 irr2ceCODE[KEY_NUMPAD7          ] = Key::Numpad7;  // Numeric keypad 7 key
    00246                                 irr2ceCODE[KEY_NUMPAD8          ] = Key::Numpad8;  // Numeric keypad 8 key
    00247                                 irr2ceCODE[KEY_NUMPAD9          ] = Key::Numpad9;  // Numeric keypad 9 key
    00248                                 irr2ceCODE[KEY_MULTIPLY         ] = Key::Multiply;  // Multiply key
    00249                                 irr2ceCODE[KEY_ADD              ] = Key::Add;  // Add key
    00250                                 irr2ceCODE[KEY_SEPARATOR        ] = 0;  // Separator key
    00251                                 irr2ceCODE[KEY_SUBTRACT         ] = Key::Subtract;  // Subtract key
    00252                                 irr2ceCODE[KEY_DECIMAL          ] = Key::Decimal;  // Decimal key
    00253                                 irr2ceCODE[KEY_DIVIDE           ] = Key::Divide;  // Divide key
    00254                                 irr2ceCODE[KEY_F1               ] = Key::F1;   // F1 key
    00255                                 irr2ceCODE[KEY_F2               ] = Key::F2;   // F2 key
    00256                                 irr2ceCODE[KEY_F3               ] = Key::F3;   // F3 key
    00257                                 irr2ceCODE[KEY_F4               ] = Key::F4;   // F4 key
    00258                                 irr2ceCODE[KEY_F5               ] = Key::F5;   // F5 key
    00259                                 irr2ceCODE[KEY_F6               ] = Key::F6;   // F6 key
    00260                                 irr2ceCODE[KEY_F7               ] = Key::F7;   // F7 key
    00261                                 irr2ceCODE[KEY_F8               ] = Key::F8;   // F8 key
    00262                                 irr2ceCODE[KEY_F9               ] = Key::F9;   // F9 key
    00263                                 irr2ceCODE[KEY_F10              ] = Key::F10;  // F10 key
    00264                                 irr2ceCODE[KEY_F11              ] = Key::F11;  // F11 key
    00265                                 irr2ceCODE[KEY_F12              ] = Key::F12;  // F12 key
    00266                                 irr2ceCODE[KEY_F13              ] = Key::F13;  // F13 key
    00267                                 irr2ceCODE[KEY_F14              ] = Key::F14;  // F14 key
    00268                                 irr2ceCODE[KEY_F15              ] = Key::F15;  // F15 key
    00269                                 irr2ceCODE[KEY_F16              ] = 0;  // F16 key
    00270                                 irr2ceCODE[KEY_F17              ] = 0;  // F17 key
    00271                                 irr2ceCODE[KEY_F18              ] = 0;  // F18 key
    00272                                 irr2ceCODE[KEY_F19              ] = 0;  // F19 key
    00273                                 irr2ceCODE[KEY_F20              ] = 0;  // F20 key
    00274                                 irr2ceCODE[KEY_F21              ] = 0;  // F21 key
    00275                                 irr2ceCODE[KEY_F22              ] = 0;  // F22 key
    00276                                 irr2ceCODE[KEY_F23              ] = 0;  // F23 key
    00277                                 irr2ceCODE[KEY_F24              ] = 0;  // F24 key
    00278                                 irr2ceCODE[KEY_NUMLOCK          ] = Key::NumLock;  // NUM LOCK key
    00279                                 irr2ceCODE[KEY_SCROLL           ] = Key::ScrollLock;  // SCROLL LOCK key
    00280                                 irr2ceCODE[KEY_LSHIFT           ] = Key::LeftShift;  // Left SHIFT key
    00281                                 irr2ceCODE[KEY_RSHIFT           ] = Key::RightShift;  // Right SHIFT key
    00282                                 irr2ceCODE[KEY_LCONTROL         ] = Key::LeftControl;  // Left CONTROL key
    00283                                 irr2ceCODE[KEY_RCONTROL         ] = Key::RightControl;  // Right CONTROL key
    00284                                 irr2ceCODE[KEY_LMENU            ] = Key::LeftAlt;  // Left MENU key
    00285                                 irr2ceCODE[KEY_RMENU            ] = Key::RightAlt;  // Right MENU key
    00286                                 irr2ceCODE[KEY_COMMA            ] = Key::Comma;//0xBC;  // Comma Key  (;)
    00287                                 irr2ceCODE[KEY_PLUS             ] = Key::Add;  // Plus Key   (+)
    00288                                 irr2ceCODE[KEY_MINUS            ] = Key::Minus;  // Minus Key  (-)
    00289                                 irr2ceCODE[KEY_PERIOD           ] = Key::Period;//0xBE;  // Period Key (.)
    00290                                 irr2ceCODE[KEY_ATTN             ] = 0;  // Attn key
    00291                                 irr2ceCODE[KEY_CRSEL            ] = 0;  // CrSel key
    00292                                 irr2ceCODE[KEY_EXSEL            ] = 0;  // ExSel key
    00293                                 irr2ceCODE[KEY_EREOF            ] = 0;  // Erase EOF key
    00294                                 irr2ceCODE[KEY_PLAY             ] = 0;  // Play key
    00295                                 irr2ceCODE[KEY_ZOOM             ] = 0;  // Zoom key
    00296                                 irr2ceCODE[KEY_PA1              ] = 0;  // PA1 key
    00297                                 irr2ceCODE[KEY_OEM_CLEAR        ] = 0;  // Clear key
    00298                         }
    00299
    00307                         uchar getKeyCode(irr::EKEY_CODE kc)
    00308                         {
    00309                                 return irr2ceCODE[kc];
    00310                         }
    00311
    00312
    00313         };
    00314
    00315 }
    00316
    00317
    00318 #endif