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-2006 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 { 00044 00045 enum GrabMode 00046 { 00047 GRAB_NONE, 00048 GRAB_MOUSE_OVER, 00049 GRAB_MOUSE_CLICK // this is the default 00050 }; 00051 00052 class SDLInput : public InputReader 00053 { 00054 public: 00055 SDLInput(); 00056 virtual ~SDLInput(); 00057 00058 void initialise( RenderWindow* pWindow, bool useKeyboard = true, bool useMouse = true, 00059 bool useGameController = false ); 00060 void capture(); 00061 00068 void setGrabMode( GrabMode mode ) { mGrabMode = mode; } 00069 00070 /* 00071 * Mouse getters 00072 */ 00073 virtual long getMouseRelX() const; 00074 virtual long getMouseRelY() const; 00075 virtual long getMouseRelZ() const; 00076 00077 virtual long getMouseAbsX() const; 00078 virtual long getMouseAbsY() const; 00079 virtual long getMouseAbsZ() const; 00080 00081 virtual void getMouseState( MouseState& state ) const; 00082 00083 virtual bool getMouseButton( uchar button ) const; 00084 00085 private: 00086 RenderWindow *mRenderWindow; 00087 // State at last 'capture' call 00088 Uint8* mKeyboardBuffer; 00089 int mMaxKey; 00090 int mMouseX, mMouseY; 00091 int mMouseRelativeX, mMouseRelativeY, mMouseRelativeZ; 00092 Uint8 mMouseKeys; 00093 bool _visible; 00094 00095 bool mMouseGrabbed; // true if Ogre has control over the mouse input 00096 bool mUseMouse; // true if initialise() is called with useMouse == true 00097 bool mGrabMouse; // grab the mouse input if the situation specified by mGrabMode arises 00098 bool mMouseLeft; // true if the mouse pointer has left the window after calling releaseMouse(). Needed for 00099 // mGrabMode == GRAB_MOUSE_BUTTON. 00100 int mGrabMode; // when/how to grab the mouse 00101 00102 00103 typedef std::map<SDLKey, KeyCode> InputKeyMap; 00104 InputKeyMap _key_map; 00105 bool warpMouse; 00106 00107 // the value that is added to mMouseRelativeZ when the wheel 00108 // is moved one step (this value is actually added 00109 // twice per movement since a wheel movement triggers a 00110 // MOUSEBUTTONUP and a MOUSEBUTTONDOWN event). 00111 // The value is chosen according to the windoze value. 00112 static const unsigned int mWheelStep = 60; 00113 00114 void processBufferedKeyboard(); 00115 void processBufferedMouse(); 00116 00117 void _grabMouse(); 00118 void _releaseMouse(); 00119 bool isKeyDownImmediate( KeyCode kc ) const; 00120 }; 00121 } 00122 #endif 00123
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jun 11 10:46:41 2006