Update docs, readme, news, and contributors

This commit is contained in:
NarrikSynthfox 2024-04-10 13:08:34 -04:00
parent a06c00215a
commit 094db02c39
4 changed files with 98 additions and 1 deletions

View File

@ -294,6 +294,9 @@ video tutorials.
- Jonas Ådahl - Jonas Ådahl
- Lasse Öörni - Lasse Öörni
- Leonard König - Leonard König
- Beoran
- Enthuin
- Narrik Synthfox
- All the unmentioned and anonymous contributors in the GLFW community, for bug - All the unmentioned and anonymous contributors in the GLFW community, for bug
reports, patches, feedback, testing and encouragement reports, patches, feedback, testing and encouragement

View File

@ -129,7 +129,7 @@ information on what to include when reporting a bug.
- [Null] Added EGL context creation on Mesa via `EGL_MESA_platform_surfaceless` - [Null] Added EGL context creation on Mesa via `EGL_MESA_platform_surfaceless`
- [EGL] Allowed native access on Wayland with `GLFW_CONTEXT_CREATION_API` set to - [EGL] Allowed native access on Wayland with `GLFW_CONTEXT_CREATION_API` set to
`GLFW_NATIVE_CONTEXT_API` (#2518) `GLFW_NATIVE_CONTEXT_API` (#2518)
- Added `GLFWgamepadstatefun`, `glfwSetGamepadStateCallback`, `GLFWjoystickbuttonfun`,`glfwSetJoystickButtonCallback`, `GLFWjoystickaxisfun`, `glfwSetJoystickAxisCallback`, `GLFWjoystickhatfun`, and `glfwSetJoystickHatCallback` for event-based joystick/gamepad input.
## Contact ## Contact

View File

@ -911,6 +911,85 @@ righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,
were recently added to SDL. The input modifiers `+`, `-` and `~` are supported were recently added to SDL. The input modifiers `+`, `-` and `~` are supported
and described above. and described above.
### Event-based joystick and gamepad input {#joystick_input_event}
If you wish to be notified when a button on a joystick is pressed or released, set a joystick button callback.
```c
glfwSetJoystickButtonCallback(joystick_button_callback);
```
The callback function receives the joystick id, the [joystick button](@ref joystick_button) that was pressed or released, and action.
```c
void joystick_button_callback(int jid, int button, int action)
{
if (button == 0 && action == GLFW_PRESS)
jump();
}
```
The action is one of `GLFW_PRESS` or `GLFW_RELEASE`
If you wish to be notified when an axis on a joystick is moved, set a joystick axis callback.
```c
glfwSetJoystickAxisCallback(joystick_axis_callback);
```
The callback function receives the joystick id, [joystick axis](@ref joystick_axis) that was moved, and float value from -1.0 to 1.0 for the axis.
```c
void joystick_axis_callback(int jid, int axis, float value)
{
if (axis == 0){
if(value == -1.0f)
move_left();
else if(value == 1.0f)
move_right();
}
}
```
If you wish to be notified when a hat on a joystick is moved, set a joystick hat callback.
```c
glfwSetJoystickHatCallback(joystick_hat_callback);
```
The callback function receives the joystick id, hat, and the [hat states](@ref hat_state).
```c
void joystick_hat_callback(int jid, int hat, int position)
{
if(hat == 0 && position == GLFW_HAT_UP)
move_up();
}
```
If you wish to be notified when the state of a gamepad is updated, set a gamepad state callback. This callback will occur every time any button, axis, or hat updates, so with this, you will have to handle checks for if a value is changed.
```c
glfwSetGamepadStateCallback(gamepad_state_callback);
```
The callback function recieves the joystick id and the gamepad state.
```c
bool jumpButtonHeld = false;
gamepad_state_callback(int jid, GLFWgamepadstate state){
if (state.buttons[GLFW_GAMEPAD_BUTTON_A] && !jumpButtonHeld)
{
input_jump();
jumpButtonHeld = true;
}
else if (!state.buttons[GLFW_GAMEPAD_BUTTON_A] && jumpButtonHeld)
{
jumpButtonHeld = false;
}
}
```
## Time input {#time} ## Time input {#time}

View File

@ -14,6 +14,11 @@ values over 8. For compatibility with older versions, the
@ref GLFW_UNLIMITED_MOUSE_BUTTONS input mode needs to be set to make use of @ref GLFW_UNLIMITED_MOUSE_BUTTONS input mode needs to be set to make use of
this. this.
### Callback functions for gamepad state, joystick buttons, joystick axes, and joystick hat inputs {#joystick_input_callbacks}
GLFW now has callback functions for [gamepad state](@ref glfwSetGamepadStateCallback), [joystick buttons](@ref glfwSetJoystickButtonCallback), [joystick axes](@ref glfwSetJoystickAxisCallback), and [joystick hats](@ref glfwSetJoystickHatCallback), allowing for
event-based inputs for joysticks and gamepads.
## Caveats {#caveats} ## Caveats {#caveats}
## Deprecations {#deprecations} ## Deprecations {#deprecations}
@ -24,8 +29,18 @@ this.
### New functions {#new_functions} ### New functions {#new_functions}
- @ref glfwSetJoystickButtonCallback
- @ref glfwSetJoystickAxisCallback
- @ref glfwSetJoystickHatCallback
- @ref glfwSetGamepadStateCallback
### New types {#new_types} ### New types {#new_types}
- @ref GLFWjoystickbuttonfun
- @ref GLFWjoystickaxisfun
- @ref GLFWjoystickhatfun
- @ref GLFWgamepadstatefun
### New constants {#new_constants} ### New constants {#new_constants}
- @ref GLFW_UNLIMITED_MOUSE_BUTTONS - @ref GLFW_UNLIMITED_MOUSE_BUTTONS