glfw: add Joystick.getButtons
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
e31e9fe694
commit
d910349c7d
1 changed files with 41 additions and 38 deletions
|
@ -97,44 +97,37 @@ pub inline fn getAxes(self: Joystick) Error!?[]const f32 {
|
||||||
return axes[0..@intCast(usize, count)];
|
return axes[0..@intCast(usize, count)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(joystick)
|
/// Returns the state of all buttons of the specified joystick.
|
||||||
// /// Returns the state of all buttons of the specified joystick.
|
///
|
||||||
// ///
|
/// This function returns the state of all buttons of the specified joystick. Each element in the
|
||||||
// /// This function returns the state of all buttons of the specified joystick.
|
/// array is either `glfw.press` or `glfw.release`.
|
||||||
// /// Each element in the array is either `glfw.press` or `glfw.release`.
|
///
|
||||||
// ///
|
/// For backward compatibility with earlier versions that did not have glfw.Joystick.getHats, the
|
||||||
// /// For backward compatibility with earlier versions that did not have @ref
|
/// button array also includes all hats, each represented as four buttons. The hats are in the same
|
||||||
// /// glfwGetJoystickHats, the button array also includes all hats, each
|
/// order as returned by glfw.Joystick.getHats and are in the order _up_, _right_, _down_ and
|
||||||
// /// represented as four buttons. The hats are in the same order as returned by
|
/// _left_. To disable these extra buttons, set the glfw.joystick_hat_buttons init hint before
|
||||||
// /// __glfwGetJoystickHats__ and are in the order _up_, _right_, _down_ and
|
/// initialization.
|
||||||
// /// _left_. To disable these extra buttons, set the @ref
|
///
|
||||||
// /// GLFW_JOYSTICK_HAT_BUTTONS init hint before initialization.
|
/// If the specified joystick is not present this function will return null but will not generate an
|
||||||
// ///
|
/// error. This can be used instead of first calling glfw.Joystick.present.
|
||||||
// /// If the specified joystick is not present this function will return null
|
///
|
||||||
// /// but will not generate an error. This can be used instead of first calling
|
/// @return An array of button states, or null if the joystick is not present.
|
||||||
// /// @ref glfwJoystickPresent.
|
///
|
||||||
// ///
|
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
||||||
// /// @param[in] jid The [joystick](@ref joysticks) to query.
|
///
|
||||||
// /// @param[out] count Where to store the number of button states in the returned
|
/// @pointer_lifetime The returned array is allocated and freed by GLFW. You should not free it
|
||||||
// /// array. This is set to zero if the joystick is not present or an error
|
/// yourself. It is valid until the specified joystick is disconnected or the library is terminated.
|
||||||
// /// occurred.
|
///
|
||||||
// /// @return An array of button states, or null if the joystick is not present
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
// /// or an error occurred.
|
///
|
||||||
// ///
|
/// see also: joystick_button
|
||||||
// /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
pub inline fn getButtons(self: Joystick) Error!?[]const u8 {
|
||||||
// ///
|
var count: c_int = undefined;
|
||||||
// /// @pointer_lifetime The returned array is allocated and freed by GLFW. You
|
const buttons = c.glfwGetJoystickButtons(self.jid, &count);
|
||||||
// /// should not free it yourself. It is valid until the specified joystick is
|
try getError();
|
||||||
// /// disconnected or the library is terminated.
|
if (buttons == null) return null;
|
||||||
// ///
|
return buttons[0..@intCast(usize, count)];
|
||||||
// /// @thread_safety This function must only be called from the main thread.
|
}
|
||||||
// ///
|
|
||||||
// /// see also: joystick_button
|
|
||||||
// ///
|
|
||||||
// /// @glfw3 Changed to return a dynamic array.
|
|
||||||
// ///
|
|
||||||
// /// @ingroup input
|
|
||||||
// GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count);
|
|
||||||
|
|
||||||
// TODO(joystick)
|
// TODO(joystick)
|
||||||
// /// Returns the state of all hats of the specified joystick.
|
// /// Returns the state of all hats of the specified joystick.
|
||||||
|
@ -459,6 +452,16 @@ test "getAxes" {
|
||||||
_ = joystick.getAxes() catch |err| std.debug.print("failed to get joystick axes, joysticks not supported? error={}\n", .{err});
|
_ = joystick.getAxes() catch |err| std.debug.print("failed to get joystick axes, joysticks not supported? error={}\n", .{err});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getButtons" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const joystick = glfw.Joystick{ .jid = glfw.Joystick.one };
|
||||||
|
|
||||||
|
_ = joystick.getButtons() catch |err| std.debug.print("failed to get joystick buttons, joysticks not supported? error={}\n", .{err});
|
||||||
|
}
|
||||||
|
|
||||||
test "setUserPointer_syntax" {
|
test "setUserPointer_syntax" {
|
||||||
const glfw = @import("main.zig");
|
const glfw = @import("main.zig");
|
||||||
try glfw.init();
|
try glfw.init();
|
||||||
|
|
Loading…
Add table
Reference in a new issue