jtmm2/include/input.h

50 lines
982 B
C

#ifndef _DEF_INPUT
#define _DEF_INPUT
#include <gint/defs/types.h>
#include <stdbool.h>
#include "input_macro.h"
#define KEYS_COUNT 6
enum {
K_LEFT,
K_RIGHT,
K_UP,
K_DOWN,
K_JUMP,
K_EXIT
};
enum {
S_PRESSED, /* 0 */
S_DOWN, /* 1 */
S_RELEASED, /* 2 */
S_UP /* 3 */
};
typedef struct Input {
uint8_t keys[KEYS_COUNT];
uint8_t states[KEYS_COUNT];
uint last_press[KEYS_COUNT];
} Input;
/* will check for new key inputs and update states[] */
void input_step(Input *input, uint step);
/* initialize values */
void input_init(Input *input);
/* display all keys states and information */
void input_draw_debug(Input *input);
bool input_is_pressed(Input *input, uint8_t key);
/* Return duration since the last time key was pressed. */
uint input_last_press(Input *input, uint8_t key, uint step);
bool input_is_down(Input *input, uint8_t key);
bool input_is_released(Input *input, uint8_t key);
bool input_is_up(Input *input, uint8_t key);
#endif /* _DEF_INPUT */