summaryrefslogtreecommitdiff
path: root/vendors/input.h
blob: f7f0239c39b17f258e8a5d152380df66c8c331e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "TZR.h"
#include <stdbool.h>

#define INPUT_TAG_LEN 32

typedef enum InputBindType {
	IBT_SCANCODE,
	IBT_CONBUTTON,
	IBT_MOUSEBUTTON
} InputBindType;

typedef struct InputBind InputBind;
struct InputBind {
	InputBindType type;
	union {
		SDL_Scancode sc;
		uint8_t cb;
		uint8_t mb;
	};
	InputBind *next;
};

typedef struct InputAction InputAction;
struct InputAction {
	char tag[INPUT_TAG_LEN];
	InputBind binds;
	InputAction *next;
};

typedef enum InputPairType {
	IPT_ACTION,
	IPT_STICK
} InputPairType;

typedef struct InputPair InputPair;
struct InputPair {
	InputPairType type;
	union {
		struct {
			char left[INPUT_TAG_LEN];
			char right[INPUT_TAG_LEN];
		};
		float (*stick)(void);
	};
	InputPair *next;
};

typedef struct InputAxis InputAxis;
struct InputAxis {
	char tag[INPUT_TAG_LEN];
	InputPair pairs;
	InputAxis *next;
};

void input_deinit(void);
void input_new_action(const char *tag);
void input_new_axis(const char *tag);
void input_bind_action_sc(const char *tag, SDL_Scancode sc);
void input_bind_action_cb(const char *tag, uint8_t cb);
void input_bind_action_mb(const char *tag, uint8_t mb);
void input_bind_axis_gc(const char *tag, SDL_GameControllerAxis ax);
void input_bind_axis_act(const char *tag, const char *l, const char *r);

bool input_down(const char *tag);
bool input_up(const char *tag);
bool input_pressed(const char *tag);
bool input_released(const char *tag);
int input_axis(const char *tag);
float input_axisf(const char *tag);