Files
dusk/src/dusksdl2/input/inputsdl2.h
T
2026-06-21 10:00:30 -05:00

85 lines
2.0 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef struct inputbutton_s inputbutton_t;
#ifdef DUSK_INPUT_KEYBOARD
typedef SDL_Scancode inputscancodesdl2_t;
#endif
#ifdef DUSK_INPUT_GAMEPAD
typedef SDL_GameControllerButton inputgamepadbuttonsdl2_t;
typedef SDL_GameControllerAxis inputgamepadaxissdl2_t;
#endif
#ifdef DUSK_INPUT_POINTER
typedef enum {
INPUT_POINTER_AXIS_X,
INPUT_POINTER_AXIS_Y,
INPUT_POINTER_AXIS_Z,
INPUT_POINTER_AXIS_WHEEL_X,
INPUT_POINTER_AXIS_WHEEL_Y,
} inputpointeraxissdl2_t;
#endif
typedef struct {
#ifdef DUSK_INPUT_GAMEPAD
SDL_GameController *controller;
#endif
#ifdef DUSK_INPUT_KEYBOARD
const uint8_t *keyboardState;
#endif
#ifdef DUSK_INPUT_POINTER
int16_t mouseX, mouseY;
int16_t scrollX, scrollY;
#endif
} inputsdl2_t;
// Setup platform variables for input.
#ifdef DUSK_INPUT_KEYBOARD
typedef inputscancodesdl2_t inputscancodeplatform_t;
#endif
#ifdef DUSK_INPUT_GAMEPAD
typedef inputgamepadbuttonsdl2_t inputgamepadbuttonplatform_t;
typedef inputgamepadaxissdl2_t inputgamepadaxissplatform_t;
#endif
#ifdef DUSK_INPUT_POINTER
typedef inputpointeraxissdl2_t inputpointeraxisplatform_t;
#endif
#define inputUpdatePlatform inputUpdateSDL2
#define inputButtonGetValuePlatform inputButtonGetValueSDL2
typedef inputsdl2_t inputplatform_t;
/**
* Updates the input state for SDL2.
*/
void inputUpdateSDL2(void);
/**
* Returns the deadzone for the given gamepad axis (0 to INT16_MAX).
*
* @param button The button to get the deadzone of.
* @return The deadzone threshold (0 to INT16_MAX).
*/
int16_t inputGetDeadzoneSDL2(const inputbutton_t button);
/**
* Returns the input value of the given button (0 to INT16_MAX).
*
* @param button The button to get the value of.
* @return The value of the button (0 to INT16_MAX).
*/
int16_t inputButtonGetValueSDL2(const inputbutton_t button);