Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreSDLInput.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025
    00026 #include "OgreSDLInput.h"
    00027 #include "OgreLogManager.h"
    00028 #include "OgreMouseEvent.h"
    00029 #include "OgreCursor.h"
    00030
    00031 namespace Ogre {
    00032
    00033     SDLInput::SDLInput()
    00034         : InputReader(), mMouseX(0), mMouseY(0), mMouseRelativeX(0),
    00035           mMouseRelativeY(0), mMouseRelativeZ(0), mScale(0.002), _visible(true)
    00036     {
    00037         mMouseGrabbed = false;
    00038         mGrabMouse = false;
    00039         mMouseLeft = false;
    00040         mGrabMode = GRAB_NONE;
    00041         mEventQueue = 0;
    00042
    00043         _key_map.insert(InputKeyMap::value_type(SDLK_ESCAPE,KC_ESCAPE));
    00044         _key_map.insert(InputKeyMap::value_type(SDLK_1, KC_1));
    00045         _key_map.insert(InputKeyMap::value_type(SDLK_2, KC_2));
    00046         _key_map.insert(InputKeyMap::value_type(SDLK_3, KC_3));
    00047         _key_map.insert(InputKeyMap::value_type(SDLK_4, KC_4));
    00048         _key_map.insert(InputKeyMap::value_type(SDLK_5, KC_5));
    00049         _key_map.insert(InputKeyMap::value_type(SDLK_6, KC_6));
    00050         _key_map.insert(InputKeyMap::value_type(SDLK_7, KC_7));
    00051         _key_map.insert(InputKeyMap::value_type(SDLK_8, KC_8));
    00052         _key_map.insert(InputKeyMap::value_type(SDLK_9, KC_9));
    00053         _key_map.insert(InputKeyMap::value_type(SDLK_0, KC_0));
    00054         _key_map.insert(InputKeyMap::value_type(SDLK_MINUS, KC_MINUS));
    00055         _key_map.insert(InputKeyMap::value_type(SDLK_EQUALS, KC_EQUALS));
    00056         _key_map.insert(InputKeyMap::value_type(SDLK_BACKSPACE, KC_BACK));
    00057         _key_map.insert(InputKeyMap::value_type(SDLK_TAB, KC_TAB));
    00058         _key_map.insert(InputKeyMap::value_type(SDLK_q, KC_Q));
    00059         _key_map.insert(InputKeyMap::value_type(SDLK_w, KC_W));
    00060         _key_map.insert(InputKeyMap::value_type(SDLK_e, KC_E));
    00061         _key_map.insert(InputKeyMap::value_type(SDLK_r, KC_R));
    00062         _key_map.insert(InputKeyMap::value_type(SDLK_t, KC_T));
    00063         _key_map.insert(InputKeyMap::value_type(SDLK_y, KC_Y));
    00064         _key_map.insert(InputKeyMap::value_type(SDLK_u, KC_U));
    00065         _key_map.insert(InputKeyMap::value_type(SDLK_i, KC_I));
    00066         _key_map.insert(InputKeyMap::value_type(SDLK_o, KC_O));
    00067         _key_map.insert(InputKeyMap::value_type(SDLK_p, KC_P));
    00068         _key_map.insert(InputKeyMap::value_type(SDLK_RETURN, KC_RETURN));
    00069         _key_map.insert(InputKeyMap::value_type(SDLK_LCTRL, KC_LCONTROL));
    00070         _key_map.insert(InputKeyMap::value_type(SDLK_a, KC_A));
    00071         _key_map.insert(InputKeyMap::value_type(SDLK_s, KC_S));
    00072         _key_map.insert(InputKeyMap::value_type(SDLK_d, KC_D));
    00073         _key_map.insert(InputKeyMap::value_type(SDLK_f, KC_F));
    00074         _key_map.insert(InputKeyMap::value_type(SDLK_g, KC_G));
    00075         _key_map.insert(InputKeyMap::value_type(SDLK_h, KC_H));
    00076         _key_map.insert(InputKeyMap::value_type(SDLK_j, KC_J));
    00077         _key_map.insert(InputKeyMap::value_type(SDLK_k, KC_K));
    00078         _key_map.insert(InputKeyMap::value_type(SDLK_l, KC_L));
    00079         _key_map.insert(InputKeyMap::value_type(SDLK_SEMICOLON, KC_SEMICOLON));
    00080         _key_map.insert(InputKeyMap::value_type(SDLK_COLON, KC_COLON));
    00081         _key_map.insert(InputKeyMap::value_type(SDLK_QUOTE, KC_APOSTROPHE));
    00082         _key_map.insert(InputKeyMap::value_type(SDLK_BACKQUOTE, KC_GRAVE));
    00083         _key_map.insert(InputKeyMap::value_type(SDLK_LSHIFT, KC_LSHIFT));
    00084         _key_map.insert(InputKeyMap::value_type(SDLK_BACKSLASH, KC_BACKSLASH));
    00085         _key_map.insert(InputKeyMap::value_type(SDLK_z, KC_Z));
    00086         _key_map.insert(InputKeyMap::value_type(SDLK_x, KC_X));
    00087         _key_map.insert(InputKeyMap::value_type(SDLK_c, KC_C));
    00088         _key_map.insert(InputKeyMap::value_type(SDLK_v, KC_V));
    00089         _key_map.insert(InputKeyMap::value_type(SDLK_b, KC_B));
    00090         _key_map.insert(InputKeyMap::value_type(SDLK_n, KC_N));
    00091         _key_map.insert(InputKeyMap::value_type(SDLK_m, KC_M));
    00092         _key_map.insert(InputKeyMap::value_type(SDLK_COMMA, KC_COMMA));
    00093         _key_map.insert(InputKeyMap::value_type(SDLK_PERIOD, KC_PERIOD));
    00094         _key_map.insert(InputKeyMap::value_type(SDLK_RSHIFT, KC_RSHIFT));
    00095         _key_map.insert(InputKeyMap::value_type(SDLK_KP_MULTIPLY, KC_MULTIPLY));
    00096         _key_map.insert(InputKeyMap::value_type(SDLK_LALT, KC_LMENU));
    00097         _key_map.insert(InputKeyMap::value_type(SDLK_SPACE, KC_SPACE));
    00098         _key_map.insert(InputKeyMap::value_type(SDLK_CAPSLOCK, KC_CAPITAL));
    00099         _key_map.insert(InputKeyMap::value_type(SDLK_F1, KC_F1));
    00100         _key_map.insert(InputKeyMap::value_type(SDLK_F2, KC_F2));
    00101         _key_map.insert(InputKeyMap::value_type(SDLK_F3, KC_F3));
    00102         _key_map.insert(InputKeyMap::value_type(SDLK_F4, KC_F4));
    00103         _key_map.insert(InputKeyMap::value_type(SDLK_F5, KC_F5));
    00104         _key_map.insert(InputKeyMap::value_type(SDLK_F6, KC_F6));
    00105         _key_map.insert(InputKeyMap::value_type(SDLK_F7, KC_F7));
    00106         _key_map.insert(InputKeyMap::value_type(SDLK_F8, KC_F8));
    00107         _key_map.insert(InputKeyMap::value_type(SDLK_F9, KC_F9));
    00108         _key_map.insert(InputKeyMap::value_type(SDLK_F10, KC_F10));
    00109         _key_map.insert(InputKeyMap::value_type(SDLK_NUMLOCK, KC_NUMLOCK));
    00110         _key_map.insert(InputKeyMap::value_type(SDLK_SCROLLOCK, KC_SCROLL));
    00111         _key_map.insert(InputKeyMap::value_type(SDLK_KP7, KC_NUMPAD7));
    00112         _key_map.insert(InputKeyMap::value_type(SDLK_KP8, KC_NUMPAD8));
    00113         _key_map.insert(InputKeyMap::value_type(SDLK_KP9, KC_NUMPAD9));
    00114         _key_map.insert(InputKeyMap::value_type(SDLK_KP_MINUS, KC_SUBTRACT));
    00115         _key_map.insert(InputKeyMap::value_type(SDLK_KP4, KC_NUMPAD4));
    00116         _key_map.insert(InputKeyMap::value_type(SDLK_KP5, KC_NUMPAD5));
    00117         _key_map.insert(InputKeyMap::value_type(SDLK_KP6, KC_NUMPAD6));
    00118         _key_map.insert(InputKeyMap::value_type(SDLK_KP_PLUS, KC_ADD));
    00119         _key_map.insert(InputKeyMap::value_type(SDLK_KP1, KC_NUMPAD1));
    00120         _key_map.insert(InputKeyMap::value_type(SDLK_KP2, KC_NUMPAD2));
    00121         _key_map.insert(InputKeyMap::value_type(SDLK_KP3, KC_NUMPAD3));
    00122         _key_map.insert(InputKeyMap::value_type(SDLK_KP0, KC_NUMPAD0));
    00123         _key_map.insert(InputKeyMap::value_type(SDLK_KP_PERIOD, KC_DECIMAL));
    00124         _key_map.insert(InputKeyMap::value_type(SDLK_F11, KC_F11));
    00125         _key_map.insert(InputKeyMap::value_type(SDLK_F12, KC_F12));
    00126         _key_map.insert(InputKeyMap::value_type(SDLK_F13, KC_F13));
    00127         _key_map.insert(InputKeyMap::value_type(SDLK_F14, KC_F14));
    00128         _key_map.insert(InputKeyMap::value_type(SDLK_F15, KC_F15));
    00129         _key_map.insert(InputKeyMap::value_type(SDLK_KP_EQUALS, KC_NUMPADEQUALS));
    00130         _key_map.insert(InputKeyMap::value_type(SDLK_KP_DIVIDE, KC_DIVIDE));
    00131         _key_map.insert(InputKeyMap::value_type(SDLK_SYSREQ, KC_SYSRQ));
    00132         _key_map.insert(InputKeyMap::value_type(SDLK_RALT, KC_RMENU));
    00133         _key_map.insert(InputKeyMap::value_type(SDLK_HOME, KC_HOME));
    00134         _key_map.insert(InputKeyMap::value_type(SDLK_UP, KC_UP));
    00135         _key_map.insert(InputKeyMap::value_type(SDLK_PAGEUP, KC_PGUP));
    00136         _key_map.insert(InputKeyMap::value_type(SDLK_LEFT, KC_LEFT));
    00137         _key_map.insert(InputKeyMap::value_type(SDLK_RIGHT, KC_RIGHT));
    00138         _key_map.insert(InputKeyMap::value_type(SDLK_END, KC_END));
    00139         _key_map.insert(InputKeyMap::value_type(SDLK_DOWN, KC_DOWN));
    00140         _key_map.insert(InputKeyMap::value_type(SDLK_PAGEDOWN, KC_PGDOWN));
    00141         _key_map.insert(InputKeyMap::value_type(SDLK_INSERT, KC_INSERT));
    00142         _key_map.insert(InputKeyMap::value_type(SDLK_DELETE, KC_DELETE));
    00143         _key_map.insert(InputKeyMap::value_type(SDLK_LSUPER, KC_LWIN));
    00144         _key_map.insert(InputKeyMap::value_type(SDLK_RSUPER, KC_RWIN));
    00145     }
    00146
    00147     SDLInput::~SDLInput()
    00148     {
    00149         if ( mUseMouse )
    00150         {
    00151             SDL_WM_GrabInput(SDL_GRAB_OFF);
    00152             SDL_ShowCursor(1);
    00153         }
    00154     }
    00155
    00156     void SDLInput::initialise(RenderWindow* pWindow, bool useKeyboard, bool useMouse, bool useGameController)
    00157     {
    00158         mUseMouse = useMouse;
    00159         if ( useMouse )
    00160         {
    00161             mGrabMode = GRAB_MOUSE_CLICK;
    00162
    00163             // is the mouse pointer over the app window?
    00164             if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS )
    00165             {
    00166                 _grabMouse();
    00167             }
    00168             else
    00169             {
    00170                 // no, so we have to wait until the app gets
    00171                 // the mouse focus
    00172                 mGrabMouse = true;
    00173                 mMouseLeft = true;
    00174             }
    00175             // Get the center and put the mouse there
    00176             unsigned int width, height, depth;
    00177             int left, top;
    00178             pWindow->getMetrics(width, height, depth, left, top);
    00179
    00180             mMouseX = width / 2;
    00181             mMouseY = height / 2;
    00182         }
    00183         else
    00184         {
    00185             mGrabMode = GRAB_NONE;
    00186         }
    00187     }
    00188
    00189     void SDLInput::_releaseMouse()
    00190     {
    00191         SDL_WM_GrabInput(SDL_GRAB_OFF);
    00192         SDL_ShowCursor(1);
    00193         mMouseGrabbed = false;
    00194         mMouseLeft = false;
    00195         mGrabMouse = true;
    00196     }
    00197
    00198     void SDLInput::_grabMouse()
    00199     {
    00200         SDL_ShowCursor(0);
    00201         SDL_WM_GrabInput(SDL_GRAB_ON);
    00202         mMouseGrabbed = true;
    00203         mGrabMouse = false;
    00204     }
    00205
    00206     void SDLInput::capture()
    00207     {
    00208          SDL_Event event[16];
    00209
    00210         // Wait until we're visible again
    00211         // and throw away all SDL_Events
    00212         if (!_visible)
    00213         {
    00214             SDL_Event event;
    00215             while (SDL_WaitEvent(&event))
    00216             {
    00217                 if (event.type == SDL_ACTIVEEVENT && event.active.gain == 1)
    00218                 {
    00219                     break;
    00220                 }
    00221             }
    00222         }
    00223
    00224         SDL_PumpEvents();
    00225
    00226         // look for SDL "system" events
    00227         int count = SDL_PeepEvents( event, 16 , SDL_GETEVENT
    00228                             , SDL_EVENTMASK(SDL_ACTIVEEVENT)
    00229                             | SDL_EVENTMASK(SDL_VIDEORESIZE)
    00230                             | SDL_EVENTMASK(SDL_VIDEOEXPOSE)
    00231                             | SDL_EVENTMASK(SDL_SYSWMEVENT)
    00232                         );
    00233         if ( count )
    00234         {
    00235             for (int i = 0; i < count; i++)
    00236             {
    00237                 switch (event[i].type)
    00238                 {
    00239                 case SDL_ACTIVEEVENT:
    00240                     if ( mGrabMouse && (mGrabMode == GRAB_MOUSE_OVER ) )
    00241                     {
    00242                         if ( event[i].active.gain )
    00243                         {
    00244                             if ( mMouseLeft )
    00245                             {
    00246                                 // mouse is over the application window
    00247                                 _grabMouse();
    00248                             }
    00249                         }
    00250                         else
    00251                         {
    00252                             mMouseLeft = true;
    00253                         }
    00254                     }
    00255                     break;
    00256                 case SDL_VIDEORESIZE:
    00257                 case SDL_VIDEOEXPOSE:
    00258                 case SDL_SYSWMEVENT:
    00259                     break;
    00260                 }
    00261             }
    00262         }
    00263
    00264         // Keyboard input
    00265         if (mUseBufferedKeys)
    00266         {
    00267             processBufferedKeyboard();
    00268         }
    00269         // check for ALT + TAB to mimic windoze behaviour (useful to get the mouse
    00270         // pointer back ;-)
    00271
    00272         // we have to call GetKeyState() even if buffered keyboard input is selected
    00273         mKeyboardBuffer = SDL_GetKeyState(NULL);
    00274         if ( mKeyboardBuffer[SDLK_LALT] && mKeyboardBuffer[SDLK_TAB] )
    00275         {
    00276             _releaseMouse();
    00277         }
    00278
    00279
    00280         if (mUseBufferedMouse)
    00281         {
    00282             processBufferedMouse();
    00283         }
    00284         else
    00285         {
    00286             mMouseKeys = 0;
    00287             mMouseRelativeX = 0; mMouseRelativeY = 0; mMouseRelativeZ = 0;
    00288
    00289             // Get mouse info
    00290             if( 1 ) // SDL_GetAppState() & SDL_APPMOUSEFOCUS )
    00291             {
    00292                 mMouseKeys = SDL_GetMouseState( &mMouseX, &mMouseY );
    00293                 SDL_GetRelativeMouseState( &mMouseRelativeX, &mMouseRelativeY );
    00294
    00295
    00296                 // get mouse wheel movement
    00297                 // fetch all mouse wheel related events
    00298                 int count = SDL_PeepEvents( event, 16 , SDL_GETEVENT
    00299                         ,(SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)
    00300                         | SDL_EVENTMASK(SDL_MOUSEBUTTONUP)
    00301                         | SDL_EVENTMASK(SDL_MOUSEMOTION)
    00302                        ));
    00303                 if ( count )
    00304                 {
    00305                     for (int i = 0; i < count; i++)
    00306                     {
    00307                         switch (event[i].type)
    00308                         {
    00309                         case SDL_MOUSEBUTTONDOWN:
    00310                         case SDL_MOUSEBUTTONUP:
    00311                             // grab the mouse if the user presses a mouse button
    00312                             if ( !mMouseGrabbed && mGrabMouse && ( mGrabMode == GRAB_MOUSE_CLICK ) )
    00313                             {
    00314                                 _grabMouse();
    00315                             }
    00316                             switch(event[i].button.button)
    00317                             {
    00318                             case SDL_BUTTON_WHEELUP:
    00319                                 mMouseRelativeZ += mWheelStep;
    00320                                 break;
    00321                             case SDL_BUTTON_WHEELDOWN:
    00322                                 mMouseRelativeZ -= mWheelStep;
    00323                                 break;
    00324                             }
    00325                             break;
    00326                         }
    00327                     }
    00328                 }
    00329             }
    00330
    00331             mMouseState.Xabs = mMouseX;
    00332             mMouseState.Yabs = mMouseY;
    00333             mMouseState.Zabs = 0;
    00334
    00335             mMouseState.Xrel = mMouseRelativeX;
    00336             mMouseState.Yrel = mMouseRelativeY;
    00337             mMouseState.Zrel = mMouseRelativeZ;
    00338
    00339             mMouseState.Buttons =  (mMouseKeys & SDL_BUTTON_LMASK) ? 1 : 0; // left
    00340             mMouseState.Buttons |= (mMouseKeys & SDL_BUTTON_RMASK) ? 2 : 0; // right
    00341             mMouseState.Buttons |= (mMouseKeys & SDL_BUTTON_MMASK) ? 4 : 0; // middle
    00342
    00343         }
    00344
    00345         // XXX Fix me up
    00346         // Game controller state
    00347     }
    00348
    00349     bool SDLInput::isKeyDownImmediate(KeyCode kc) const
    00350     {
    00351         switch(kc)
    00352         {
    00353         case KC_ESCAPE:
    00354             return mKeyboardBuffer[SDLK_ESCAPE];
    00355         case KC_1:
    00356             return mKeyboardBuffer[SDLK_1];
    00357         case KC_2:
    00358             return mKeyboardBuffer[SDLK_2];
    00359         case KC_3:
    00360             return mKeyboardBuffer[SDLK_3];
    00361         case KC_4:
    00362             return mKeyboardBuffer[SDLK_4];
    00363         case KC_5:
    00364             return mKeyboardBuffer[SDLK_5];
    00365         case KC_6:
    00366             return mKeyboardBuffer[SDLK_6];
    00367         case KC_7:
    00368             return mKeyboardBuffer[SDLK_7];
    00369         case KC_8:
    00370             return mKeyboardBuffer[SDLK_8];
    00371         case KC_9:
    00372             return mKeyboardBuffer[SDLK_9];
    00373         case KC_0:
    00374             return mKeyboardBuffer[SDLK_0];
    00375         case KC_MINUS:  /* - on main keyboard */
    00376             return mKeyboardBuffer[SDLK_MINUS];
    00377         case KC_EQUALS:
    00378             return mKeyboardBuffer[SDLK_EQUALS];
    00379         case KC_BACK:  /* backspace */
    00380             return mKeyboardBuffer[SDLK_BACKSPACE];
    00381         case KC_TAB:
    00382             return mKeyboardBuffer[SDLK_TAB];
    00383         case KC_Q:
    00384             return mKeyboardBuffer[SDLK_q];
    00385         case KC_W:
    00386             return mKeyboardBuffer[SDLK_w];
    00387         case KC_E:
    00388             return mKeyboardBuffer[SDLK_e];
    00389         case KC_R:
    00390             return mKeyboardBuffer[SDLK_r];
    00391         case KC_T:
    00392             return mKeyboardBuffer[SDLK_t];
    00393         case KC_Y:
    00394             return mKeyboardBuffer[SDLK_y];
    00395         case KC_U:
    00396             return mKeyboardBuffer[SDLK_u];
    00397         case KC_I:
    00398             return mKeyboardBuffer[SDLK_i];
    00399         case KC_O:
    00400             return mKeyboardBuffer[SDLK_o];
    00401         case KC_P:
    00402             return mKeyboardBuffer[SDLK_p];
    00403         case KC_LBRACKET:
    00404         case KC_RBRACKET:
    00405             break;
    00406         case KC_RETURN: /* Enter on main keyboard */
    00407             return mKeyboardBuffer[SDLK_RETURN];
    00408         case KC_LCONTROL:
    00409             return mKeyboardBuffer[SDLK_LCTRL];
    00410         case KC_A:
    00411             return mKeyboardBuffer[SDLK_a];
    00412         case KC_S:
    00413             return mKeyboardBuffer[SDLK_s];
    00414         case KC_D:
    00415             return mKeyboardBuffer[SDLK_d];
    00416         case KC_F:
    00417             return mKeyboardBuffer[SDLK_f];
    00418         case KC_G:
    00419             return mKeyboardBuffer[SDLK_g];
    00420         case KC_H:
    00421             return mKeyboardBuffer[SDLK_h];
    00422         case KC_J:
    00423             return mKeyboardBuffer[SDLK_j];
    00424         case KC_K:
    00425             return mKeyboardBuffer[SDLK_k];
    00426         case KC_L:
    00427             return mKeyboardBuffer[SDLK_l];
    00428         case KC_SEMICOLON:
    00429             return mKeyboardBuffer[SDLK_SEMICOLON];
    00430         case KC_APOSTROPHE:
    00431             return mKeyboardBuffer[SDLK_QUOTE];
    00432         case KC_GRAVE:  /* accent grave */
    00433             return mKeyboardBuffer[SDLK_BACKQUOTE];
    00434         case KC_LSHIFT:
    00435             return mKeyboardBuffer[SDLK_LSHIFT];
    00436         case KC_BACKSLASH:
    00437             return mKeyboardBuffer[SDLK_BACKSLASH];
    00438         case KC_Z:
    00439             return mKeyboardBuffer[SDLK_z];
    00440         case KC_X:
    00441             return mKeyboardBuffer[SDLK_x];
    00442         case KC_C:
    00443             return mKeyboardBuffer[SDLK_c];
    00444         case KC_V:
    00445             return mKeyboardBuffer[SDLK_v];
    00446         case KC_B:
    00447             return mKeyboardBuffer[SDLK_b];
    00448         case KC_N:
    00449             return mKeyboardBuffer[SDLK_n];
    00450         case KC_M:
    00451             return mKeyboardBuffer[SDLK_m];
    00452         case KC_COMMA:
    00453             return mKeyboardBuffer[SDLK_COMMA];
    00454         case KC_PERIOD: /* . on main keyboard */
    00455             return mKeyboardBuffer[SDLK_PERIOD];
    00456         case KC_SLASH: /* '/' on main keyboard */
    00457             break;
    00458         case KC_RSHIFT:
    00459             return mKeyboardBuffer[SDLK_RSHIFT];
    00460         case KC_MULTIPLY: /* * on numeric keypad */
    00461             return mKeyboardBuffer[SDLK_KP_MULTIPLY];
    00462         case KC_LMENU: /* left Alt */
    00463             return mKeyboardBuffer[SDLK_LALT];
    00464         case KC_SPACE:
    00465             return mKeyboardBuffer[SDLK_SPACE];
    00466         case KC_CAPITAL:
    00467             return mKeyboardBuffer[SDLK_CAPSLOCK];
    00468         case KC_F1:
    00469             return mKeyboardBuffer[SDLK_F1];
    00470         case KC_F2:
    00471             return mKeyboardBuffer[SDLK_F2];
    00472         case KC_F3:
    00473             return mKeyboardBuffer[SDLK_F3];
    00474         case KC_F4:
    00475             return mKeyboardBuffer[SDLK_F4];
    00476         case KC_F5:
    00477             return mKeyboardBuffer[SDLK_F5];
    00478         case KC_F6:
    00479             return mKeyboardBuffer[SDLK_F6];
    00480         case KC_F7:
    00481             return mKeyboardBuffer[SDLK_F7];
    00482         case KC_F8:
    00483             return mKeyboardBuffer[SDLK_F8];
    00484         case KC_F9:
    00485             return mKeyboardBuffer[SDLK_F9];
    00486         case KC_F10:
    00487             return mKeyboardBuffer[SDLK_F10];
    00488         case KC_NUMLOCK:
    00489             return mKeyboardBuffer[SDLK_NUMLOCK];
    00490         case KC_SCROLL: /* Scroll Lock */
    00491             return mKeyboardBuffer[SDLK_SCROLLOCK];
    00492         case KC_NUMPAD7:
    00493             return mKeyboardBuffer[SDLK_KP7];
    00494         case KC_NUMPAD8:
    00495             return mKeyboardBuffer[SDLK_KP8];
    00496         case KC_NUMPAD9:
    00497             return mKeyboardBuffer[SDLK_KP9];
    00498         case KC_SUBTRACT: /* - on numeric keypad */
    00499             return mKeyboardBuffer[SDLK_KP_MINUS];
    00500         case KC_NUMPAD4:
    00501             return mKeyboardBuffer[SDLK_KP4];
    00502         case KC_NUMPAD5:
    00503             return mKeyboardBuffer[SDLK_KP5];
    00504         case KC_NUMPAD6:
    00505             return mKeyboardBuffer[SDLK_KP6];
    00506         case KC_ADD: /* + on numeric keypad */
    00507             return mKeyboardBuffer[SDLK_KP_PLUS];
    00508         case KC_NUMPAD1:
    00509             return mKeyboardBuffer[SDLK_KP1];
    00510         case KC_NUMPAD2:
    00511             return mKeyboardBuffer[SDLK_KP2];
    00512         case KC_NUMPAD3:
    00513             return mKeyboardBuffer[SDLK_KP3];
    00514         case KC_NUMPAD0:
    00515             return mKeyboardBuffer[SDLK_KP0];
    00516         case KC_DECIMAL:  /* . on numeric keypad */
    00517             return mKeyboardBuffer[SDLK_KP_PERIOD];
    00518         case KC_OEM_102:  /* < > | on UK/Germany keyboards */
    00519             break;
    00520         case KC_F11:
    00521             return mKeyboardBuffer[SDLK_F11];
    00522         case KC_F12:
    00523             return mKeyboardBuffer[SDLK_F12];
    00524         case KC_F13: /* (NEC PC98) */
    00525             return mKeyboardBuffer[SDLK_F13];
    00526         case KC_F14: /* (NEC PC98) */
    00527             return mKeyboardBuffer[SDLK_F14];
    00528         case KC_F15: /* (NEC PC98) */
    00529             return mKeyboardBuffer[SDLK_F15];
    00530         case KC_KANA: /* (Japanese keyboard) */
    00531         case KC_ABNT_C1: /* / ? on Portugese (Brazilian) keyboards */
    00532         case KC_CONVERT: /* (Japanese keyboard) */
    00533         case KC_NOCONVERT: /* (Japanese keyboard) */
    00534         case KC_YEN: /* (Japanese keyboard) */
    00535         case KC_ABNT_C2: /* Numpad . on Portugese (Brazilian) keyboards */
    00536             break;
    00537         case KC_NUMPADEQUALS: /* = on numeric keypad (NEC PC98) */
    00538             return mKeyboardBuffer[SDLK_KP_EQUALS];
    00539         case KC_PREVTRACK: /* Previous Track (KC_CIRCUMFLEX on Japanese keyboard) */
    00540         case KC_AT: /* (NEC PC98) */
    00541         case KC_COLON: /* (NEC PC98) */
    00542             return mKeyboardBuffer[SDLK_COLON];
    00543         case KC_UNDERLINE: /* (NEC PC98) */
    00544         case KC_KANJI: /* (Japanese keyboard)            */
    00545         case KC_STOP: /* (NEC PC98) */
    00546         case KC_AX:  /*  (Japan AX) */
    00547         case KC_UNLABELED:  /* (J3100) */
    00548         case KC_NEXTTRACK:  /* Next Track */
    00549         case KC_NUMPADENTER:  /* Enter on numeric keypad */
    00550         case KC_RCONTROL:
    00551         case KC_MUTE:  /* Mute */
    00552         case KC_CALCULATOR:  /* Calculator */
    00553         case KC_PLAYPAUSE:  /* Play / Pause */
    00554         case KC_MEDIASTOP:  /* Media Stop */
    00555         case KC_VOLUMEDOWN:  /* Volume - */
    00556         case KC_VOLUMEUP:  /* Volume + */
    00557         case KC_WEBHOME:  /* Web home */
    00558         case KC_NUMPADCOMMA:  /* , on numeric keypad (NEC PC98) */
    00559             break;
    00560         case KC_DIVIDE:  /* / on numeric keypad */
    00561             return mKeyboardBuffer[SDLK_KP_DIVIDE];
    00562         case KC_SYSRQ:
    00563             return mKeyboardBuffer[SDLK_SYSREQ] | mKeyboardBuffer[SDLK_PRINT];
    00564         case KC_RMENU:  /* right Alt */
    00565             return mKeyboardBuffer[SDLK_RALT];
    00566         case KC_PAUSE:  /* Pause */
    00567             break;
    00568         case KC_HOME:  /* Home on arrow keypad */
    00569             return mKeyboardBuffer[SDLK_HOME];
    00570         case KC_UP:  /* UpArrow on arrow keypad */
    00571             return mKeyboardBuffer[SDLK_UP];
    00572         case KC_PGUP:  /* PgUp on arrow keypad */
    00573             return mKeyboardBuffer[SDLK_PAGEUP];
    00574         case KC_LEFT:  /* LeftArrow on arrow keypad */
    00575             return mKeyboardBuffer[SDLK_LEFT];
    00576         case KC_RIGHT:  /* RightArrow on arrow keypad */
    00577             return mKeyboardBuffer[SDLK_RIGHT];
    00578         case KC_END:  /* End on arrow keypad */
    00579             return mKeyboardBuffer[SDLK_END];
    00580         case KC_DOWN:  /* DownArrow on arrow keypad */
    00581             return mKeyboardBuffer[SDLK_DOWN];
    00582         case KC_PGDOWN:  /* PgDn on arrow keypad */
    00583             return mKeyboardBuffer[SDLK_PAGEDOWN];
    00584         case KC_INSERT:  /* Insert on arrow keypad */
    00585             return mKeyboardBuffer[SDLK_INSERT];
    00586         case KC_DELETE:  /* Delete on arrow keypad */
    00587             return mKeyboardBuffer[SDLK_DELETE];
    00588         case KC_LWIN:  /* Left Windows key */
    00589             return mKeyboardBuffer[SDLK_LSUPER];
    00590         case KC_RWIN:  /* Right Windows key */
    00591             return mKeyboardBuffer[SDLK_RSUPER];
    00592         case KC_APPS:  /* AppMenu key */
    00593         case KC_POWER:  /* System Power */
    00594         case KC_SLEEP:  /* System Sleep */
    00595         case KC_WAKE:  /* System Wake */
    00596         case KC_WEBSEARCH:  /* Web Search */
    00597         case KC_WEBFAVORITES:  /* Web Favorites */
    00598         case KC_WEBREFRESH:  /* Web Refresh */
    00599         case KC_WEBSTOP:  /* Web Stop */
    00600         case KC_WEBFORWARD:  /* Web Forward */
    00601         case KC_WEBBACK:  /* Web Back */
    00602         case KC_MYCOMPUTER:  /* My Computer */
    00603         case KC_MAIL:  /* Mail */
    00604         case KC_MEDIASELECT:  /* Media Select */
    00605             break;
    00606         default:
    00607             break;
    00608         };
    00609
    00610         return 0;
    00611     }
    00612
    00613     long SDLInput::getMouseRelX() const
    00614     {
    00615         return mMouseState.Xrel;
    00616     }
    00617
    00618     long SDLInput::getMouseRelY() const
    00619     {
    00620         return mMouseState.Yrel;
    00621     }
    00622
    00623     long SDLInput::getMouseRelZ() const
    00624     {
    00625         return mMouseState.Zrel;
    00626     }
    00627
    00628     long SDLInput::getMouseAbsX() const
    00629     {
    00630         return mMouseX;
    00631     }
    00632
    00633     long SDLInput::getMouseAbsY() const
    00634     {
    00635         return mMouseY;
    00636     }
    00637
    00638     long SDLInput::getMouseAbsZ() const
    00639     {
    00640         return 0;
    00641     }
    00642
    00643     bool SDLInput::getMouseButton( uchar button ) const
    00644     {
    00645         return mMouseState.isButtonDown( button );
    00646     }
    00647
    00648     void SDLInput::processBufferedKeyboard()
    00649     {
    00650         // XXX Arbitrarily picked 16
    00651         SDL_Event events[16];
    00652
    00653         int count = SDL_PeepEvents(events, 16, SDL_GETEVENT,
    00654                 (SDL_KEYDOWNMASK | SDL_KEYUPMASK));
    00655         if (!count)
    00656         {
    00657             return;
    00658         }
    00659
    00660         for (int i = 0; i < count; i++)
    00661         {
    00662             bool down = false;
    00663             if (events[i].type == SDL_KEYDOWN)
    00664                 down = true;
    00665             keyChanged(_key_map[events[i].key.keysym.sym], down);
    00666         }
    00667     }
    00668
    00669     void SDLInput::processBufferedMouse()
    00670     {
    00671         // XXX Arbitrarily picked 16
    00672         SDL_Event events[16];
    00673
    00674         int count = SDL_PeepEvents(events, 16, SDL_GETEVENT,
    00675                 (SDL_MOUSEMOTIONMASK | SDL_MOUSEBUTTONDOWNMASK |
    00676                  SDL_MOUSEBUTTONUPMASK | SDL_ACTIVEEVENTMASK));
    00677         if (!count)
    00678         {
    00679             return;
    00680         }
    00681
    00682         bool Xset, Yset, Zset;
    00683         Xset = Yset = Zset = false;
    00684         for (int i = 0; i < count; i++)
    00685         {
    00686             int button_mask = -1;
    00687             bool button_down = false;
    00688             switch (events[i].type)
    00689             {
    00690             case SDL_ACTIVEEVENT:
    00691                 _visible = events[i].active.gain ? true : false;
    00692                 break;
    00693             case SDL_MOUSEMOTION:
    00694                 if (events[i].motion.xrel)
    00695                 {
    00696                     if (Xset)
    00697                     {
    00698                         mouseMoved();
    00699                     }
    00700                     mCursor->addToX(events[i].motion.xrel * mScale);
    00701                     Xset = true;
    00702                 }
    00703                 if (events[i].motion.yrel)
    00704                 {
    00705                     if (Yset)
    00706                     {
    00707                         mouseMoved();
    00708                     }
    00709                     mCursor->addToY(events[i].motion.yrel * mScale);
    00710                     Yset = true;
    00711                 }
    00712                 break;
    00713             case SDL_MOUSEBUTTONDOWN:
    00714                 button_down = true;
    00715             case SDL_MOUSEBUTTONUP:
    00716                 // grab the mouse if the user presses a mouse button
    00717                 if ( !mMouseGrabbed && mGrabMouse && ( mGrabMode == GRAB_MOUSE_CLICK ) )
    00718                 {
    00719                     _grabMouse();
    00720                 }
    00721                 switch(events[i].button.button)
    00722                 {
    00723                 case SDL_BUTTON_LEFT:
    00724                     button_mask = InputEvent::BUTTON0_MASK;
    00725                     break;
    00726                 case SDL_BUTTON_RIGHT:
    00727                     button_mask = InputEvent::BUTTON1_MASK;
    00728                     break;
    00729                 case SDL_BUTTON_MIDDLE:
    00730                     button_mask = InputEvent::BUTTON2_MASK;
    00731                     break;
    00732                 };
    00733                 triggerMouseButton(button_mask, button_down);
    00734                 break;
    00735             };
    00736
    00737             if (Xset && Yset)
    00738             {
    00739                 mouseMoved();
    00740                 Xset = Yset = false;
    00741             }
    00742         }
    00743
    00744         if (Xset || Yset)
    00745         {
    00746             mouseMoved();
    00747         }
    00748
    00749     }
    00750
    00751     void SDLInput::getMouseState( MouseState& state ) const
    00752     {
    00753         memcpy( &state, &mMouseState, sizeof( MouseState ) );
    00754     }
    00755
    00756 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:46 2004