1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
*
* This software is open source and may be redistributed and/or modified under
* the terms of the GNU General Public License (GPL) version 2.0.
* The full license is in LICENSE.txt file included with this distribution,.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* include LICENSE.txt for more details.
*/
#ifndef SDLINTEGRATION
#define SDLINTEGRATION
#include <SDL.h>
#include <SDL_events.h>
#include <SDL_joystick.h>
#include <vector>
#include <map>
class SDLIntegration
{
public:
SDLIntegration();
~SDLIntegration();
typedef std::vector<int> ValueList;
typedef std::map<int, int> ButtonMap;
void update(osgViewer::Viewer& viewer);
void addMouseButtonMapping(int joystickButton, int mouseButton)
{
_mouseButtonMap[joystickButton] = mouseButton;
}
int getMouseButtonMapping(int joystickButton)
{
ButtonMap::const_iterator itr = _mouseButtonMap.find(joystickButton);
if (itr != _mouseButtonMap.end()) return itr->second;
else return -1;
}
void addKeyMapping(int joystickButton, int key)
{
_keyMap[joystickButton] = key;
}
int getKeyMapping(int joystickButton)
{
ButtonMap::const_iterator itr = _keyMap.find(joystickButton);
if (itr != _keyMap.end()) return itr->second;
else return -1;
}
protected:
void capture(ValueList& axisValues, ValueList& buttonValues) const;
SDL_Joystick* _joystick;
int _numAxes;
int _numBalls;
int _numHats;
int _numButtons;
bool _verbose;
ValueList _axisValues;
ValueList _buttonValues;
ButtonMap _mouseButtonMap;
ButtonMap _keyMap;
};
#endif
|