OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sdlinputwrapper.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_SDLUTIL_SDLINPUTWRAPPER_H
2 #define OPENMW_COMPONENTS_SDLUTIL_SDLINPUTWRAPPER_H
3 
4 #include <map>
5 
6 #include <osg/ref_ptr>
7 
8 #include <SDL_events.h>
9 #include <SDL_version.h>
10 
11 #include "OISCompat.hpp"
12 #include "events.hpp"
13 
14 namespace osgViewer
15 {
16  class Viewer;
17 }
18 
19 namespace SDLUtil
20 {
23  {
24  public:
25  InputWrapper(SDL_Window *window, osg::ref_ptr<osgViewer::Viewer> viewer, bool grab);
26  ~InputWrapper();
27 
32 
33  void capture(bool windowEventsOnly);
34  bool isModifierHeld(SDL_Keymod mod);
35  bool isKeyDown(SDL_Scancode key);
36 
37  void setMouseVisible (bool visible);
38  void setMouseRelative(bool relative);
39  bool getMouseRelative() { return mMouseRelative; }
40  void setGrabPointer(bool grab);
41 
42  OIS::KeyCode sdl2OISKeyCode(SDL_Keycode code);
43 
44  void warpMouse(int x, int y);
45 
46  void updateMouseSettings();
47 
48  private:
49  void handleWindowEvent(const SDL_Event& evt);
50 
51  bool _handleWarpMotion(const SDL_MouseMotionEvent& evt);
52  void _wrapMousePointer(const SDL_MouseMotionEvent &evt);
53  MouseMotionEvent _packageMouseMotion(const SDL_Event& evt);
54 
55  void _setupOISKeys();
56 
57  SDL_Window* mSDLWindow;
58  osg::ref_ptr<osgViewer::Viewer> mViewer;
59 
64 
65  typedef std::map<SDL_Keycode, OIS::KeyCode> KeyMap;
67 
68  Uint16 mWarpX;
69  Uint16 mWarpY;
72 
73  bool mAllowGrab;
75  bool mWantGrab;
79 
81 
82  Sint32 mMouseZ;
83  Sint32 mMouseX;
84  Sint32 mMouseY;
85 
88  };
89 
90 }
91 
92 #endif
void setMouseEventCallback(MouseListener *listen)
Definition: sdlinputwrapper.hpp:28
MouseListener * mMouseListener
Definition: sdlinputwrapper.hpp:60
bool isKeyDown(SDL_Scancode key)
Definition: sdlinputwrapper.cpp:235
void setKeyboardEventCallback(KeyListener *listen)
Definition: sdlinputwrapper.hpp:29
A wrapper around SDL's event queue, mostly used for handling input-related events.
Definition: sdlinputwrapper.hpp:22
Sint32 mMouseX
Definition: sdlinputwrapper.hpp:83
Definition: events.hpp:65
bool mWantGrab
Definition: sdlinputwrapper.hpp:75
void setControllerEventCallback(ControllerListener *listen)
Definition: sdlinputwrapper.hpp:31
void setGrabPointer(bool grab)
Locks the pointer to the window.
Definition: sdlinputwrapper.cpp:250
Definition: events.hpp:15
void updateMouseSettings()
Definition: sdlinputwrapper.cpp:270
ControllerListener * mConListener
Definition: sdlinputwrapper.hpp:63
void setWindowEventCallback(WindowListener *listen)
Definition: sdlinputwrapper.hpp:30
Sint32 mMouseZ
Definition: sdlinputwrapper.hpp:82
Uint16 mWarpY
Definition: sdlinputwrapper.hpp:69
KeyMap mKeyMap
Definition: sdlinputwrapper.hpp:66
WindowListener * mWindowListener
Definition: sdlinputwrapper.hpp:62
bool mAllowGrab
Definition: sdlinputwrapper.hpp:73
MouseMotionEvent _packageMouseMotion(const SDL_Event &evt)
Package mouse and mousewheel motions into a single event.
Definition: sdlinputwrapper.cpp:340
bool _handleWarpMotion(const SDL_MouseMotionEvent &evt)
Internal method for ignoring relative motions as a side effect of warpMouse()
Definition: sdlinputwrapper.cpp:300
bool mMouseInWindow
Definition: sdlinputwrapper.hpp:87
Definition: events.hpp:26
InputWrapper(SDL_Window *window, osg::ref_ptr< osgViewer::Viewer > viewer, bool grab)
Definition: sdlinputwrapper.cpp:11
Definition: events.hpp:44
bool mMouseRelative
Definition: sdlinputwrapper.hpp:78
void setMouseRelative(bool relative)
Set the mouse to relative positioning. Doesn't move the cursor and disables mouse acceleration...
Definition: sdlinputwrapper.cpp:258
SDL_Window * mSDLWindow
Definition: sdlinputwrapper.hpp:57
bool mWarpCompensate
Definition: sdlinputwrapper.hpp:70
void _setupOISKeys()
Definition: sdlinputwrapper.cpp:389
void handleWindowEvent(const SDL_Event &evt)
Definition: sdlinputwrapper.cpp:171
std::map< SDL_Keycode, OIS::KeyCode > KeyMap
Definition: sdlinputwrapper.hpp:65
bool mGrabPointer
Definition: sdlinputwrapper.hpp:77
KeyListener * mKeyboardListener
Definition: sdlinputwrapper.hpp:61
void warpMouse(int x, int y)
Moves the mouse to the specified point within the viewport.
Definition: sdlinputwrapper.cpp:241
bool mWantRelative
Definition: sdlinputwrapper.hpp:76
Definition: events.hpp:35
bool mFirstMouseMove
Definition: sdlinputwrapper.hpp:80
bool mWindowHasFocus
Definition: sdlinputwrapper.hpp:86
int code
Definition: crashcatcher.cpp:70
bool isModifierHeld(SDL_Keymod mod)
Definition: sdlinputwrapper.cpp:230
void _wrapMousePointer(const SDL_MouseMotionEvent &evt)
Wrap the mouse to the viewport.
Definition: sdlinputwrapper.cpp:316
Uint16 mWarpX
Definition: sdlinputwrapper.hpp:68
Sint32 mMouseY
Definition: sdlinputwrapper.hpp:84
void setMouseVisible(bool visible)
Definition: sdlinputwrapper.cpp:264
bool mWrapPointer
Definition: sdlinputwrapper.hpp:71
~InputWrapper()
Definition: sdlinputwrapper.cpp:42
void capture(bool windowEventsOnly)
Definition: sdlinputwrapper.cpp:46
OIS::KeyCode sdl2OISKeyCode(SDL_Keycode code)
Definition: sdlinputwrapper.cpp:377
KeyCode
Keyboard scan codes.
Definition: OISCompat.hpp:10
bool getMouseRelative()
Definition: sdlinputwrapper.hpp:39
osg::ref_ptr< osgViewer::Viewer > mViewer
Definition: sdlinputwrapper.hpp:58
bool mWantMouseVisible
Definition: sdlinputwrapper.hpp:74