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

OgreSDLInput.h

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 (c) 2000-2005 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 
00027 #ifndef __SDLInputReader_H__
00028 #define __SDLInputReader_H__
00029 
00030 #include "OgreInput.h"
00031 #include "OgreInputEvent.h"
00032 #include "OgreRenderWindow.h"
00033 
00034 #include <map>
00035 
00036 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
00037 #   include <SDL/sdl.h>
00038 #else
00039 #   include <SDL.h>
00040 #endif
00041 
00042 namespace Ogre {
00043     enum GrabMode
00044     {
00045         GRAB_NONE,
00046         GRAB_MOUSE_OVER,
00047         GRAB_MOUSE_CLICK   // this is the default
00048     };
00049 
00050     class SDLInput : public InputReader
00051     {
00052     public:
00053         SDLInput();
00054         virtual ~SDLInput();
00055 
00056         void initialise( RenderWindow* pWindow, bool useKeyboard = true, bool useMouse = true, bool useGameController = false );
00057         void capture();
00058 
00064         void setGrabMode( GrabMode mode ) { mGrabMode = mode; }
00065 
00066         /*
00067          * Mouse getters
00068          */
00069         virtual long getMouseRelX() const;
00070         virtual long getMouseRelY() const;
00071         virtual long getMouseRelZ() const;
00072 
00073         virtual long getMouseAbsX() const;
00074         virtual long getMouseAbsY() const;
00075         virtual long getMouseAbsZ() const;
00076 
00077         virtual void getMouseState( MouseState& state ) const;
00078 
00079         virtual bool getMouseButton( uchar button ) const;
00080 
00081     private:
00082         // State at last 'capture' call
00083         Uint8* mKeyboardBuffer;
00084         int mMaxKey;
00085         int mMouseX, mMouseY;
00086         int mMouseRelativeX, mMouseRelativeY, mMouseRelativeZ;
00087         Uint8 mMouseKeys;
00088         bool _visible;
00089         
00090         bool mMouseGrabbed;  // true if Ogre has control over the mouse input
00091         bool mUseMouse;   // true if initialise() is called with useMouse == true
00092         bool mGrabMouse;  // grab the mouse input if the situation specified by mGrabMode arises
00093         bool mMouseLeft;  // true if the mouse pointer has left the window after calling releaseMouse(). Needed for
00094                           // mGrabMode == GRAB_MOUSE_BUTTON.
00095         int mGrabMode;    // when/how to grab the mouse
00096 
00097         typedef std::map<SDLKey, KeyCode> InputKeyMap;
00098         InputKeyMap _key_map;
00099         bool warpMouse;
00100 
00101         // the value that is added to mMouseRelativeZ when the wheel
00102         // is moved one step (this value is actually added
00103         // twice per movement since a wheel movement triggers a
00104         // MOUSEBUTTONUP and a MOUSEBUTTONDOWN event).
00105         // The value is chosen according to the windoze value.
00106         static const unsigned int mWheelStep = 60;
00107 
00108         void processBufferedKeyboard();
00109         void processBufferedMouse();
00110 
00111         void _grabMouse();
00112         void _releaseMouse();
00113         bool isKeyDownImmediate( KeyCode kc ) const;
00114     };
00115 }
00116 
00117 #endif
00118 

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:49 2006