libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1/**
2 * @file input.hpp
3 * @brief High-level game controller input abstraction built on Controller.
4 *
5 * Input extends Controller to offer a named-button query API using the
6 * Input_Button enum, mapping logical buttons to SDL_GameControllerButton values.
7 */
8#ifndef __INPUT__H__
9#define __INPUT__H__
10
11#include "joystick.hpp"
12
13namespace mx {
14
15/**
16 * @enum Input_Button
17 * @brief Logical button identifiers for a standard gamepad.
18 */
19 enum class Input_Button {
20 BTN_A = 0, ///< A / Cross button.
21 BTN_B, ///< B / Circle button.
22 BTN_X, ///< X / Square button.
23 BTN_Y, ///< Y / Triangle button.
24 BTNL_L, ///< Left shoulder button.
25 BTN_R, ///< Right shoulder button.
26 BTN_D_UP, ///< D-pad up.
27 BTN_D_DOWN, ///< D-pad down.
28 BTN_D_LEFT, ///< D-pad left.
29 BTN_D_RIGHT, ///< D-pad right.
30 BTN_START, ///< Start / Menu button.
31 BTN_BACK, ///< Back / Select button.
32 };
33
34/**
35 * @class Input
36 * @brief Convenience wrapper that queries controller buttons by logical name.
37 *
38 * Inherits Controller, adding getButton(Input_Button) to allow polling
39 * gamepad input without knowing the underlying SDL button codes.
40 */
41 class Input : public Controller {
42 public:
43 /** @brief Default constructor. */
44 Input() = default;
45 ~Input() = default;
46
47 Input(const Input&) = delete;
48 Input& operator=(const Input&) = delete;
49 Input(Input&&) = delete;
50 Input& operator=(Input&&) = delete;
51
52 /**
53 * @brief Query whether a logical gamepad button is currently pressed.
54 * @param b Logical button identifier.
55 * @return @c true if the button is held down.
56 */
57 bool getButton(Input_Button b);
58 };
59
60}
61
62
63#endif
64
65
Controller()
Default constructor — device not yet opened.
Definition joystick.cpp:101
Input(Input &&)=delete
Input & operator=(Input &&)=delete
Input()=default
Default constructor.
~Input()=default
Input & operator=(const Input &)=delete
Input(const Input &)=delete
bool getButton(Input_Button b)
Query whether a logical gamepad button is currently pressed.
Definition input.cpp:22
SDL joystick and game controller RAII wrappers.
Definition cfg.cpp:11
Input_Button
Logical button identifiers for a standard gamepad.
Definition input.hpp:19
@ BTN_B
B / Circle button.
Definition input.hpp:21
@ BTN_BACK
Back / Select button.
Definition input.hpp:31
@ BTN_Y
Y / Triangle button.
Definition input.hpp:23
@ BTN_D_LEFT
D-pad left.
Definition input.hpp:28
@ BTN_D_DOWN
D-pad down.
Definition input.hpp:27
@ BTN_D_UP
D-pad up.
Definition input.hpp:26
@ BTN_D_RIGHT
D-pad right.
Definition input.hpp:29
@ BTN_A
A / Cross button.
Definition input.hpp:20
@ BTN_X
X / Square button.
Definition input.hpp:22
@ BTN_R
Right shoulder button.
Definition input.hpp:25
@ BTN_START
Start / Menu button.
Definition input.hpp:30
@ BTNL_L
Left shoulder button.
Definition input.hpp:24