Sirikata
|
00001 /* Sirikata libproxyobject -- Ogre Graphics Plugin 00002 * SDLInputManager.hpp 00003 * 00004 * Copyright (c) 2009, Daniel Reiter Horn 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are 00009 * met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the name of Sirikata nor the names of its contributors may 00017 * be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00021 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00022 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00023 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00024 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 extern "C" typedef struct SDL_Surface SDL_Surface; 00033 extern "C" typedef Sirikata::uint32 SDL_WindowID; 00034 extern "C" typedef void* SDL_GLContext; 00035 extern "C" typedef union SDL_Event SDL_Event; 00036 00037 #include <sirikata/ogre/input/InputManager.hpp> 00038 00039 namespace Sirikata { 00040 00041 namespace Graphics { 00042 class OgreRenderer; 00043 } 00044 00045 namespace Input { 00046 00047 class InputDevice; 00048 class SDLKeyboard; 00049 class SDLMouse; 00050 class SDLJoystick; 00051 typedef std::tr1::shared_ptr<InputDevice> InputDevicePtr; 00052 typedef std::tr1::weak_ptr<InputDevice> InputDeviceWPtr; 00053 typedef std::tr1::shared_ptr<SDLMouse> SDLMousePtr; 00054 typedef std::tr1::shared_ptr<SDLJoystick> SDLJoystickPtr; 00055 typedef std::tr1::shared_ptr<SDLKeyboard> SDLKeyboardPtr; 00056 00057 struct SIRIKATA_OGRE_EXPORT SDLKeyRepeatInfo { 00058 SDLKeyRepeatInfo(); 00059 ~SDLKeyRepeatInfo(); 00060 00061 bool isRepeating(uint32 key); 00062 void repeat(uint32 key, SDL_Event* evt); 00063 void unrepeat(uint32 key); 00064 00065 typedef std::tr1::unordered_map<uint32, SDL_Event*> RepeatMap; 00066 RepeatMap mRepeat; 00067 }; 00068 typedef std::tr1::shared_ptr<SDLKeyRepeatInfo> SDLKeyRepeatInfoPtr; 00069 00070 00071 class SIRIKATA_OGRE_EXPORT SDLInputManager : public InputManager { 00072 Graphics::OgreRenderer* mParent; 00073 bool mInitialized; 00074 SDL_WindowID mWindowID; 00075 SDL_GLContext mWindowContext; 00076 std::vector<SDLKeyboardPtr> mKeys; 00077 std::vector<SDLKeyRepeatInfoPtr> mLastKeys; 00078 std::vector<SDLMousePtr> mMice; 00079 std::vector<SDLJoystickPtr> mJoy; 00080 unsigned int mWidth, mHeight; 00081 bool mHasKeyboardFocus; 00082 static int modifiersFromSDL(int sdlMod); 00083 00084 OptionValue*mDragDeadband; 00085 OptionValue*mDragMultiplier; 00086 OptionValue*mWorldScale; 00087 OptionValue*mAxisToRadians; 00088 OptionValue*mRotateSnap; 00089 OptionValue*mWheelToAxis; 00090 OptionValue*mRelativeMouseToAxis; 00091 OptionValue*mJoyBallToAxis; 00092 public: 00093 class InitializationException : public std::exception { 00094 public: 00095 InitializationException(const String& msg); 00096 virtual ~InitializationException() throw(); 00097 virtual const char* what() const throw(); 00098 private: 00099 std::string _msg; 00100 }; 00101 00102 void windowFocusChange(); 00103 00104 float dragDeadBand() const; 00105 float relativeMouseToAxis() const; 00106 float wheelToAxis() const; 00107 float joyBallToAxis() const; 00108 00109 void getWindowSize(unsigned int &width, unsigned int &height) { 00110 width = this->mWidth; 00111 height = this->mHeight; 00112 } 00113 SDLInputManager(Graphics::OgreRenderer* parent, 00114 unsigned int width, 00115 unsigned int height, 00116 bool fullscreen, 00117 bool grabCursor, 00118 void *¤tWindowData); 00119 bool tick(Task::LocalTime currentTime, Duration frameTime); 00120 00121 void filesDropped(const std::vector<std::string> &files); 00122 00123 virtual bool isModifierDown(Modifier modifier) const; 00124 virtual bool isCapsLockDown() const; 00125 virtual bool isNumLockDown() const; 00126 virtual bool isScrollLockDown() const; 00127 00128 virtual ~SDLInputManager(); 00129 }; 00130 } }