root/OpenSceneGraph/trunk/src/osgPlugins/sdl/JoystickDevice.h @ 13429

Revision 13429, 2.2 kB (checked in by robert, 55 minutes ago)

From Mattias Helsing, "Seems I was only half right given what you asked for. CMP0017 only
says that modules that are found and ran from cmake modules dir should
prefer cmake-provided modules. find_package() and include() still look
in CMAKE_MODULE_PATH first.

After some investigating I've come up with a proposal examplified in
the attached FindGDAL.cmake script. It simply calls the cmake provided
FindGDAL.cmake if it exists and returns if it succeeds in finding GDAL
using that, otherwise continue with our local cmake code.
Pro: Wont clutter our root CMakeLists.txt
Con: If we begin to write more advanced Findxxx modules (using
COMPONENTS, REQUIRED etc.) we may have to revise this scheme.
"

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