Loading...
Searching...
No Matches
Joystick.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
31
33
38namespace sf::Joystick
39{
44// NOLINTBEGIN(readability-identifier-naming)
45static constexpr unsigned int Count{8};
46static constexpr unsigned int ButtonCount{32};
47static constexpr unsigned int AxisCount{8};
48// NOLINTEND(readability-identifier-naming)
49
54enum class Axis
55{
56 X,
57 Y,
58 Z,
59 R,
60 U,
61 V,
62 PovX,
63 PovY
64};
65
71{
72 String name{"No Joystick"};
73 unsigned int vendorId{};
74 unsigned int productId{};
75};
76
85[[nodiscard]] SFML_WINDOW_API bool isConnected(unsigned int joystick);
86
97[[nodiscard]] SFML_WINDOW_API unsigned int getButtonCount(unsigned int joystick);
98
110[[nodiscard]] SFML_WINDOW_API bool hasAxis(unsigned int joystick, Axis axis);
111
123[[nodiscard]] SFML_WINDOW_API bool isButtonPressed(unsigned int joystick, unsigned int button);
124
136[[nodiscard]] SFML_WINDOW_API float getAxisPosition(unsigned int joystick, Axis axis);
137
146[[nodiscard]] SFML_WINDOW_API Identification getIdentification(unsigned int joystick);
147
158} // namespace sf::Joystick
159
160
#define SFML_WINDOW_API
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:89
Give access to the real-time state of the joysticks.
Definition Joystick.hpp:39
Identification getIdentification(unsigned int joystick)
Get the joystick information.
static constexpr unsigned int AxisCount
Maximum number of supported axes.
Definition Joystick.hpp:47
unsigned int getButtonCount(unsigned int joystick)
Return the number of buttons supported by a joystick.
static constexpr unsigned int Count
Constants related to joysticks capabilities.
Definition Joystick.hpp:45
Axis
Axes supported by SFML joysticks.
Definition Joystick.hpp:55
@ X
The X axis.
@ Z
The Z axis.
@ U
The U axis.
@ V
The V axis.
@ Y
The Y axis.
@ PovX
The X axis of the point-of-view hat.
@ PovY
The Y axis of the point-of-view hat.
@ R
The R axis.
float getAxisPosition(unsigned int joystick, Axis axis)
Get the current position of a joystick axis.
static constexpr unsigned int ButtonCount
Maximum number of supported buttons.
Definition Joystick.hpp:46
bool isConnected(unsigned int joystick)
Check if a joystick is connected.
void update()
Update the states of all joysticks.
bool isButtonPressed(unsigned int joystick, unsigned int button)
Check if a joystick button is pressed.
bool hasAxis(unsigned int joystick, Axis axis)
Check if a joystick supports a given axis.
Structure holding a joystick's identification.
Definition Joystick.hpp:71