glfw: add Joystick.setUserPointer, Joystick.getUserPointer

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-21 22:45:10 -07:00 committed by Stephen Gutekanst
parent 23f0eaa1df
commit fb98715d9e

View file

@ -14,7 +14,7 @@ jid: c_int,
/// Joystick IDs. /// Joystick IDs.
/// ///
/// See glfw.setJoystickCallback for how these are used. /// See glfw.Joystick.setCallback for how these are used.
pub const one = c.GLFW_JOYSTICK_1; pub const one = c.GLFW_JOYSTICK_1;
pub const two = c.GLFW_JOYSTICK_2; pub const two = c.GLFW_JOYSTICK_2;
pub const three = c.GLFW_JOYSTICK_3; pub const three = c.GLFW_JOYSTICK_3;
@ -280,51 +280,37 @@ const GamepadState = extern struct {
// /// @ingroup input // /// @ingroup input
// GLFWAPI const char* glfwGetJoystickGUID(int jid); // GLFWAPI const char* glfwGetJoystickGUID(int jid);
// TODO(joystick) /// Sets the user pointer of the specified joystick.
// /// Sets the user pointer of the specified joystick. ///
// /// /// This function sets the user-defined pointer of the specified joystick. The current value is
// /// This function sets the user-defined pointer of the specified joystick. The /// retained until the joystick is disconnected. The initial value is null.
// /// current value is retained until the joystick is disconnected. The initial ///
// /// value is null. /// This function may be called from the joystick callback, even for a joystick that is being disconnected.
// /// ///
// /// This function may be called from the joystick callback, even for a joystick /// @thread_safety This function may be called from any thread. Access is not synchronized.
// /// that is being disconnected. ///
// /// /// see also: joystick_userptr, glfw.Joystick.getUserPointer
// /// @param[in] jid The joystick whose pointer to set. pub inline fn setUserPointer(self: Joystick, Type: anytype, pointer: Type) void {
// /// @param[in] pointer The new value. c.glfwSetJoystickUserPointer(self.jid, @ptrCast(*c_void, pointer));
// /// getError() catch {};
// /// Possible errors include glfw.Error.NotInitialized. }
// ///
// /// @thread_safety This function may be called from any thread. Access is not
// /// synchronized.
// ///
// /// see also: joystick_userptr, glfwGetJoystickUserPointer
// ///
// ///
// /// @ingroup input
// GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer);
// TODO(joystick) /// Returns the user pointer of the specified joystick.
// /// Returns the user pointer of the specified joystick. ///
// /// /// This function returns the current value of the user-defined pointer of the specified joystick.
// /// This function returns the current value of the user-defined pointer of the /// The initial value is null.
// /// specified joystick. The initial value is null. ///
// /// /// This function may be called from the joystick callback, even for a joystick that is being
// /// This function may be called from the joystick callback, even for a joystick /// disconnected.
// /// that is being disconnected. ///
// /// /// @thread_safety This function may be called from any thread. Access is not synchronized.
// /// @param[in] jid The joystick whose pointer to return. ///
// /// /// see also: joystick_userptr, glfw.Joystick.setUserPointer
// /// Possible errors include glfw.Error.NotInitialized. pub inline fn getUserPointer(self: Joystick, Type: anytype) ?Type {
// /// const ptr = c.glfwGetJoystickUserPointer(self.jid);
// /// @thread_safety This function may be called from any thread. Access is not if (ptr) |p| return @ptrCast(Type, @alignCast(@alignOf(Type), p));
// /// synchronized. return null;
// /// }
// /// see also: joystick_userptr, glfwSetJoystickUserPointer
// ///
// ///
// /// @ingroup input
// GLFWAPI void* glfwGetJoystickUserPointer(int jid);
// TODO(joystick) // TODO(joystick)
// /// Sets the joystick configuration callback. // /// Sets the joystick configuration callback.
@ -471,6 +457,28 @@ pub inline fn getGamepadState(self: Joystick) Error!?GamepadState {
return if (success == c.GLFW_TRUE) state else null; return if (success == c.GLFW_TRUE) state else null;
} }
test "setUserPointer_syntax" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const joystick = glfw.Joystick{ .jid = glfw.Joystick.one };
// Must be called from joystick callback, we cannot test it.
_ = joystick.setUserPointer;
}
test "getUserPointer_syntax" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const joystick = glfw.Joystick{ .jid = glfw.Joystick.one };
// Must be called from joystick callback, we cannot test it.
_ = joystick.getUserPointer;
}
test "updateGamepadMappings_syntax" { test "updateGamepadMappings_syntax" {
// We don't have a gamepad mapping to test with, just confirm the syntax is good. // We don't have a gamepad mapping to test with, just confirm the syntax is good.
_ = updateGamepadMappings; _ = updateGamepadMappings;