Kore
Loading...
Searching...
No Matches
gamepad.h
Go to the documentation of this file.
1#pragma once
2
3#include <kinc/global.h>
4
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define KINC_GAMEPAD_MAX_COUNT 12
14
20KINC_FUNC void kinc_gamepad_set_connect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata);
21
27KINC_FUNC void kinc_gamepad_set_disconnect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata);
28
34KINC_FUNC void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/), void *userdata);
35
41KINC_FUNC void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/), void *userdata);
42
48KINC_FUNC const char *kinc_gamepad_vendor(int gamepad);
49
55KINC_FUNC const char *kinc_gamepad_product_name(int gamepad);
56
62KINC_FUNC bool kinc_gamepad_connected(int gamepad);
63
70KINC_FUNC void kinc_gamepad_rumble(int gamepad, float left, float right);
71
72void kinc_internal_gamepad_trigger_connect(int gamepad);
73void kinc_internal_gamepad_trigger_disconnect(int gamepad);
74void kinc_internal_gamepad_trigger_axis(int gamepad, int axis, float value);
75void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value);
76
77#ifdef KINC_IMPLEMENTATION_INPUT
78#define KINC_IMPLEMENTATION
79#endif
80
81#ifdef KINC_IMPLEMENTATION
82
83#include <memory.h>
84#include <stddef.h>
85
86static void (*gamepad_connect_callback)(int /*gamepad*/, void * /*userdata*/) = NULL;
87static void *gamepad_connect_callback_userdata = NULL;
88static void (*gamepad_disconnect_callback)(int /*gamepad*/, void * /*userdata*/) = NULL;
89static void *gamepad_disconnect_callback_userdata = NULL;
90static void (*gamepad_axis_callback)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/) = NULL;
91static void *gamepad_axis_callback_userdata = NULL;
92static void (*gamepad_button_callback)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/) = NULL;
93static void *gamepad_button_callback_userdata = NULL;
94
95void kinc_gamepad_set_connect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata) {
96 gamepad_connect_callback = value;
97 gamepad_connect_callback_userdata = userdata;
98}
99
100void kinc_gamepad_set_disconnect_callback(void (*value)(int /*gamepad*/, void * /*userdata*/), void *userdata) {
101 gamepad_disconnect_callback = value;
102 gamepad_disconnect_callback_userdata = userdata;
103}
104
105void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/, void * /*userdata*/), void *userdata) {
106 gamepad_axis_callback = value;
107 gamepad_axis_callback_userdata = userdata;
108}
109
110void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/, void * /*userdata*/), void *userdata) {
111 gamepad_button_callback = value;
112 gamepad_button_callback_userdata = userdata;
113}
114
115void kinc_internal_gamepad_trigger_connect(int gamepad) {
116 if (gamepad_connect_callback != NULL) {
117 gamepad_connect_callback(gamepad, gamepad_connect_callback_userdata);
118 }
119}
120
121void kinc_internal_gamepad_trigger_disconnect(int gamepad) {
122 if (gamepad_disconnect_callback != NULL) {
123 gamepad_disconnect_callback(gamepad, gamepad_disconnect_callback_userdata);
124 }
125}
126
127void kinc_internal_gamepad_trigger_axis(int gamepad, int axis, float value) {
128 if (gamepad_axis_callback != NULL) {
129 gamepad_axis_callback(gamepad, axis, value, gamepad_axis_callback_userdata);
130 }
131}
132
133void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value) {
134 if (gamepad_button_callback != NULL) {
135 gamepad_button_callback(gamepad, button, value, gamepad_button_callback_userdata);
136 }
137}
138
139#endif
140
141#ifdef __cplusplus
142}
143#endif
KINC_FUNC const char * kinc_gamepad_product_name(int gamepad)
Returns a name for a gamepad.
KINC_FUNC bool kinc_gamepad_connected(int gamepad)
Checks whether a gamepad is connected.
KINC_FUNC void kinc_gamepad_rumble(int gamepad, float left, float right)
Rumbles a gamepad. Careful here because it might just fall off your table.
KINC_FUNC void kinc_gamepad_set_connect_callback(void(*value)(int, void *), void *userdata)
Sets the gamepad-connect-callback which is called when a gamepad is connected.
KINC_FUNC void kinc_gamepad_set_axis_callback(void(*value)(int, int, float, void *), void *userdata)
Sets the gamepad-axis-callback which is called with data about changing gamepad-sticks.
KINC_FUNC void kinc_gamepad_set_disconnect_callback(void(*value)(int, void *), void *userdata)
Sets the gamepad-disconnect-callback which is called when a gamepad is disconnected.
KINC_FUNC void kinc_gamepad_set_button_callback(void(*value)(int, int, float, void *), void *userdata)
Sets the gamepad-button-callback which is called with data about changing gamepad-buttons.
KINC_FUNC const char * kinc_gamepad_vendor(int gamepad)
Returns a vendor-name for a gamepad.
Provides basic functionality that's used all over the place. There's usually no need to manually incl...