Bubba-3D  0.9.0
Awesome game engine!
JoystickTranslation.h
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 #pragma once
18 
19 #include <SFML/Window.hpp>
20 #include <map>
21 #include <functional>
22 #include <IJoystickTranslation.h>
23 
25 
26 public:
27  typedef std::function<float (unsigned int)> valueRetriever;
28 
29  JoystickTranslation(unsigned int joystickID, bool defaultMapping);
30  unsigned int getJoystickID();
31  float getAxisValue(Axis axis);
32  float getButtonValue(Button button);
33  bool isDefaultMapping();
34 
35  static valueRetriever buttonValueRetriever( unsigned int button);
36  static valueRetriever axisValueRetriever( sf::Joystick::Axis axis, bool inverted);
37  static valueRetriever axisFromButtonsRetriever(unsigned int buttonPos,unsigned int buttonNeg);
38  static valueRetriever axisFromButtonRetriever(unsigned int button);
39  static valueRetriever buttonFromAxisRetriever(sf::Joystick::Axis axis);
40  static valueRetriever buttonFromHalfAxisRetriever(sf::Joystick::Axis axis, bool positiveElseNegative);
41  static valueRetriever valRetriever(float retrieve);
42 
43  void addButton(Button,valueRetriever);
44  void addAxis(Axis,valueRetriever);
45 
46 private:
47  unsigned int joystickID;
48  bool defaultMapping;
49 
50  std::map<Button,valueRetriever> xboxToGenericButton;
51  //The boolean says if the axes have their negative value to the same direction as the xbox controller
52  std::map<Axis,valueRetriever> xboxToGenericAxis;
53 
54 };