Input bind complete.
This commit is contained in:
@@ -6,65 +6,19 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
#include <SDL2/SDL.h>
|
||||
#else
|
||||
#error "No input backend defined"
|
||||
#endif
|
||||
|
||||
// Keyboard defs
|
||||
#if INPUT_KEYBOARD == 1
|
||||
#define INPUT_BIND_KEYBOARD_BUTTONS_MAX 32
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
typedef SDL_Scancode inputscancode_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Gamepad defs
|
||||
#if INPUT_GAMEPAD == 1
|
||||
#define INPUT_GAMEPAD_BUTTON_NAME_MAX 8
|
||||
#define INPUT_BIND_GAMEPAD_BUTTONS_MAX 8
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
typedef SDL_GameControllerButton inputgamepadbutton_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
INPUT_BIND_UP,
|
||||
INPUT_BIND_DOWN,
|
||||
INPUT_BIND_LEFT,
|
||||
INPUT_BIND_RIGHT,
|
||||
INPUT_BIND_ACCEPT,
|
||||
INPUT_BIND_CANCEL,
|
||||
INPUT_BIND_CONSOLE,
|
||||
|
||||
INPUT_BIND_COUNT
|
||||
} inputbind_t;
|
||||
|
||||
typedef struct {
|
||||
inputbind_t bind;
|
||||
float_t lastValue;
|
||||
float_t currentValue;
|
||||
|
||||
#if INPUT_GAMEPAD == 1
|
||||
inputgamepadbutton_t gamepad[INPUT_BIND_GAMEPAD_BUTTONS_MAX];
|
||||
uint8_t gamepadButtonCount;
|
||||
#endif
|
||||
|
||||
#if INPUT_KEYBOARD == 1
|
||||
inputscancode_t keyboard[INPUT_BIND_KEYBOARD_BUTTONS_MAX];
|
||||
#endif
|
||||
} inputbinddata_t;
|
||||
#include "inputbutton.h"
|
||||
#include "inputbind.h"
|
||||
|
||||
typedef struct {
|
||||
inputbinddata_t binds[INPUT_BIND_COUNT];
|
||||
|
||||
#if INPUT_SDL2 == 1
|
||||
#if INPUT_KEYBOARD == 1
|
||||
const uint8_t *keyboardState;
|
||||
#endif
|
||||
#endif
|
||||
} input_t;
|
||||
|
||||
extern char_t INPUT_BIND_NAMES[INPUT_BIND_COUNT][16];
|
||||
extern input_t INPUT;
|
||||
|
||||
/**
|
||||
@@ -127,9 +81,36 @@ bool_t inputPressed(const inputbind_t bind);
|
||||
bool_t inputReleased(const inputbind_t bind);
|
||||
|
||||
/**
|
||||
* Gets an input bind by its name.
|
||||
* Binds an input button to a specific input bind.
|
||||
*
|
||||
* @param name The name of the input bind.
|
||||
* @return The input bind, or INPUT_BIND_COUNT if not found.
|
||||
* @param bind The input bind to bind the button to.
|
||||
* @param button The input button to bind.
|
||||
*/
|
||||
inputbind_t inputBindGetByName(const char_t *name);
|
||||
void inputBind(const inputbind_t bind, const inputbutton_t button);
|
||||
|
||||
/**
|
||||
* Unbinds an input button from a specific input bind.
|
||||
*
|
||||
* @param bind The input bind to unbind the button from.
|
||||
* @param button The input button to unbind.
|
||||
*/
|
||||
void inputUnbind(const inputbind_t bind, const inputbutton_t button);
|
||||
|
||||
/**
|
||||
* Unbinds all input buttons from all input binds.
|
||||
*/
|
||||
void inputUnbindAll();
|
||||
|
||||
/**
|
||||
* Unbinds an input button from all input binds.
|
||||
*
|
||||
* @param button The input button to unbind.
|
||||
*/
|
||||
void inputUnbindButton(const inputbutton_t button);
|
||||
|
||||
/**
|
||||
* Unbinds all input buttons from a specific input bind.
|
||||
*
|
||||
* @param bind The input bind to unbind all buttons from.
|
||||
*/
|
||||
void inputUnbindBind(const inputbind_t bind);
|
Reference in New Issue
Block a user