mirror of
https://github.com/glfw/glfw.git
synced 2025-10-03 21:30:57 +00:00
joystickcallback : Add new callback, add overload.
This commit is contained in:
parent
7105ff2dfd
commit
8b2b1d7eda
2
.gitignore
vendored
2
.gitignore
vendored
@ -82,4 +82,4 @@ tests/timeout
|
|||||||
tests/title
|
tests/title
|
||||||
tests/triangle-vulkan
|
tests/triangle-vulkan
|
||||||
tests/windows
|
tests/windows
|
||||||
|
/[Bb]uild*/
|
||||||
|
@ -1613,6 +1613,32 @@ typedef void (* GLFWmonitorfun)(GLFWmonitor*,int);
|
|||||||
*/
|
*/
|
||||||
typedef void (* GLFWjoystickfun)(int,int);
|
typedef void (* GLFWjoystickfun)(int,int);
|
||||||
|
|
||||||
|
/*! @brief The function pointer type for window joystick configuration callbacks.
|
||||||
|
*
|
||||||
|
* This is the function pointer type for window joystick configuration callbacks.
|
||||||
|
* Even though joystick configuration callbacks are global events, you may
|
||||||
|
* use this version of the callback to recieve valid window pointers in
|
||||||
|
* your callback. Must be used with appropriate glfwSetJoystickCallback overload.
|
||||||
|
*
|
||||||
|
* A joystick configuration callback function has the following signature:
|
||||||
|
* @code
|
||||||
|
* void function_name(GLFWwindow* window, int jid, int event)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param[in] window A valid window associated to the event.
|
||||||
|
* @param[in] jid The joystick that was connected or disconnected.
|
||||||
|
* @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. Future
|
||||||
|
* releases may add more events.
|
||||||
|
*
|
||||||
|
* @sa @ref joystick_event
|
||||||
|
* @sa @ref glfwSetJoystickCallback
|
||||||
|
*
|
||||||
|
* @since Added in version 3.4.
|
||||||
|
*
|
||||||
|
* @ingroup input
|
||||||
|
*/
|
||||||
|
typedef void (* GLFWjoystickwindowfun)(GLFWwindow*,int,int);
|
||||||
|
|
||||||
/*! @brief Video mode type.
|
/*! @brief Video mode type.
|
||||||
*
|
*
|
||||||
* This describes a single video mode.
|
* This describes a single video mode.
|
||||||
@ -5139,6 +5165,44 @@ GLFWAPI int glfwJoystickIsGamepad(int jid);
|
|||||||
*/
|
*/
|
||||||
GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback);
|
GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback);
|
||||||
|
|
||||||
|
/*! @brief Sets the window joystick configuration callback.
|
||||||
|
*
|
||||||
|
* This function sets the window joystick configuration callback, or removes the
|
||||||
|
* currently set callback. This is called when a joystick is connected to or
|
||||||
|
* disconnected from the system. Windows which have registered to recieve
|
||||||
|
* this callback will be notified, and provided with their window pointer.
|
||||||
|
*
|
||||||
|
* For joystick connection and disconnection events to be delivered on all
|
||||||
|
* platforms, you need to call one of the [event processing](@ref events)
|
||||||
|
* functions. Joystick disconnection may also be detected and the callback
|
||||||
|
* called by joystick functions. The function will then return whatever it
|
||||||
|
* returns if the joystick is not present.
|
||||||
|
*
|
||||||
|
* @param[in] window The window whose callback to set.
|
||||||
|
* @param[in] callback The new callback, or `NULL` to remove the currently set
|
||||||
|
* callback.
|
||||||
|
* @return The previously set callback, or `NULL` if no callback was set or the
|
||||||
|
* library had not been [initialized](@ref intro_init).
|
||||||
|
*
|
||||||
|
* @callback_signature
|
||||||
|
* @code
|
||||||
|
* void function_name(GLFWwindow* window, int jid, int event)
|
||||||
|
* @endcode
|
||||||
|
* For more information about the callback parameters, see the
|
||||||
|
* [function pointer type](@ref GLFWjoystickwindowfun).
|
||||||
|
*
|
||||||
|
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||||
|
*
|
||||||
|
* @thread_safety This function must only be called from the main thread.
|
||||||
|
*
|
||||||
|
* @sa @ref joystick_event
|
||||||
|
*
|
||||||
|
* @since Added in version 3.4.
|
||||||
|
*
|
||||||
|
* @ingroup input
|
||||||
|
*/
|
||||||
|
GLFWAPI GLFWjoystickwindowfun glfwSetJoystickCallback(GLFWwindow* window, GLFWjoystickwindowfun callback);
|
||||||
|
|
||||||
/*! @brief Adds the specified SDL_GameControllerDB gamepad mappings.
|
/*! @brief Adds the specified SDL_GameControllerDB gamepad mappings.
|
||||||
*
|
*
|
||||||
* This function parses the specified ASCII encoded string and updates the
|
* This function parses the specified ASCII encoded string and updates the
|
||||||
|
22
src/input.c
22
src/input.c
@ -373,6 +373,18 @@ void _glfwInputJoystick(_GLFWjoystick* js, int event)
|
|||||||
|
|
||||||
if (_glfw.callbacks.joystick)
|
if (_glfw.callbacks.joystick)
|
||||||
_glfw.callbacks.joystick(jid, event);
|
_glfw.callbacks.joystick(jid, event);
|
||||||
|
|
||||||
|
// Send event to windows that want the notification.
|
||||||
|
{
|
||||||
|
_GLFWwindow* window;
|
||||||
|
|
||||||
|
for (window = _glfw.windowListHead; window; window = window->next) {
|
||||||
|
GLFWjoystickwindowfun fun = window->callbacks.joystickConnect;
|
||||||
|
if (fun) {
|
||||||
|
fun((GLFWwindow*) window, jid, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notifies shared code of the new value of a joystick axis
|
// Notifies shared code of the new value of a joystick axis
|
||||||
@ -1112,6 +1124,16 @@ GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun)
|
|||||||
return cbfun;
|
return cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLFWAPI GLFWjoystickwindowfun glfwSetJoystickCallback(GLFWwindow* handle, GLFWjoystickwindowfun cbfun)
|
||||||
|
{
|
||||||
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
assert(window != NULL);
|
||||||
|
|
||||||
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.joystickConnect, cbfun);
|
||||||
|
return cbfun;
|
||||||
|
}
|
||||||
|
|
||||||
GLFWAPI int glfwUpdateGamepadMappings(const char* string)
|
GLFWAPI int glfwUpdateGamepadMappings(const char* string)
|
||||||
{
|
{
|
||||||
int jid;
|
int jid;
|
||||||
|
@ -412,6 +412,7 @@ struct _GLFWwindow
|
|||||||
GLFWcharfun character;
|
GLFWcharfun character;
|
||||||
GLFWcharmodsfun charmods;
|
GLFWcharmodsfun charmods;
|
||||||
GLFWdropfun drop;
|
GLFWdropfun drop;
|
||||||
|
GLFWjoystickwindowfun joystickConnect;
|
||||||
} callbacks;
|
} callbacks;
|
||||||
|
|
||||||
// This is defined in the window API's platform.h
|
// This is defined in the window API's platform.h
|
||||||
|
Loading…
Reference in New Issue
Block a user