#pragma once #include /*! \file gamepad.h \brief Provides gamepad-support. */ #ifdef __cplusplus extern "C" { #endif /// /// Sets the gamepad-axis-callback which is called with data about changing gamepad-sticks. /// /// The callback KINC_FUNC void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/)); /// /// Sets the gamepad-button-callback which is called with data about changing gamepad-buttons. /// /// The callback KINC_FUNC void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/)); /// /// Returns a vendor-name for a gamepad. /// /// The index of the gamepad for which to receive the vendor-name /// The vendor-name KINC_FUNC const char *kinc_gamepad_vendor(int gamepad); /// /// Returns a name for a gamepad. /// /// The index of the gamepad for which to receive the name /// The gamepad's name KINC_FUNC const char *kinc_gamepad_product_name(int gamepad); /// /// Checks whether a gamepad is connected. /// /// The index of the gamepad which's connection will be checked /// Whether a gamepad is connected for the gamepad-index KINC_FUNC bool kinc_gamepad_connected(int gamepad); /// /// Rumbles a gamepad. Careful here because it might just fall off your table. /// /// The index of the gamepad to rumble /// Rumble-strength for the left motor between 0 and 1 /// Rumble-strength for the right motor between 0 and 1 KINC_FUNC void kinc_gamepad_rumble(int gamepad, float left, float right); void kinc_internal_gamepad_trigger_axis(int gamepad, int axis, float value); void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value); #ifdef KINC_IMPLEMENTATION_INPUT #define KINC_IMPLEMENTATION #endif #ifdef KINC_IMPLEMENTATION #include static void (*gamepad_axis_callback)(int /*gamepad*/, int /*axis*/, float /*value*/) = NULL; static void (*gamepad_button_callback)(int /*gamepad*/, int /*button*/, float /*value*/) = NULL; void kinc_gamepad_set_axis_callback(void (*value)(int /*gamepad*/, int /*axis*/, float /*value*/)) { gamepad_axis_callback = value; } void kinc_gamepad_set_button_callback(void (*value)(int /*gamepad*/, int /*button*/, float /*value*/)) { gamepad_button_callback = value; } void kinc_internal_gamepad_trigger_axis(int gamepad, int axis, float value) { if (gamepad_axis_callback != NULL) { gamepad_axis_callback(gamepad, axis, value); } } void kinc_internal_gamepad_trigger_button(int gamepad, int button, float value) { if (gamepad_button_callback != NULL) { gamepad_button_callback(gamepad, button, value); } } #endif #ifdef __cplusplus } #endif