Joystick.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2016 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_JOYSTICK_HPP
30 #define THOR_JOYSTICK_HPP
31 
32 #include <Thor/Config.hpp>
33 
34 #include <SFML/Window/Joystick.hpp>
35 
36 
37 namespace thor
38 {
39 
42 
45 struct THOR_API JoystickButton
46 {
53  JoystickButton(unsigned int joystickId, unsigned int button);
54 
55  unsigned int joystickId;
56  unsigned int button;
57 };
58 
61 struct THOR_API JoystickAxis
62 {
70  JoystickAxis(unsigned int joystickId, sf::Joystick::Axis axis, float threshold, bool above);
71 
72  unsigned int joystickId;
73  sf::Joystick::Axis axis;
74  float threshold;
75  bool above;
76 };
77 
79 
80 // ---------------------------------------------------------------------------------------------------------------------------
81 
82 
83 namespace detail
84 {
85 
86  // Proxy class that allows the joy(id) named parameter syntax
87  struct THOR_API JoystickBuilder
88  {
89  struct THOR_API Axis
90  {
91  JoystickAxis above(float threshold);
92  JoystickAxis below(float threshold);
93 
94  sf::Joystick::Axis axis;
95  unsigned int joystickId;
96  };
97 
98  explicit JoystickBuilder(unsigned int joystickId);
99  JoystickButton button(unsigned int button);
100  Axis axis(sf::Joystick::Axis axis);
101 
102  unsigned int joystickId;
103  };
104 
105 } // namespace detail
106 
107 detail::JoystickBuilder THOR_API joystick(unsigned int joystickId);
108 
109 } // namespace thor
110 
111 #endif // THOR_JOYSTICK_HPP
Contains information about a joystick number, an axis and its threshold.
Definition: Joystick.hpp:61
unsigned int joystickId
The joystick number.
Definition: Joystick.hpp:72
Definition: AnimationMap.hpp:42
sf::Joystick::Axis axis
The joystick axis.
Definition: Joystick.hpp:73
Configuration header of the library.
float threshold
Position threshold above/below which an action is triggered.
Definition: Joystick.hpp:74
unsigned int button
The joystick button number.
Definition: Joystick.hpp:56
bool above
True if position must be above threshold, false if below.
Definition: Joystick.hpp:75
Contains information about a joystick number and button number.
Definition: Joystick.hpp:45
unsigned int joystickId
The joystick number.
Definition: Joystick.hpp:55