glfw: ziggify gamepad action enumerations
Helps hexops/mach#37 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
8a14d56fc3
commit
2154ee5aea
4 changed files with 23 additions and 15 deletions
|
|
@ -9,6 +9,7 @@ const c = @import("c.zig").c;
|
|||
const Window = @import("Window.zig");
|
||||
const Error = @import("errors.zig").Error;
|
||||
const getError = @import("errors.zig").getError;
|
||||
const GamepadAxis = @import("gamepad_axis.zig").GamepadAxis;
|
||||
|
||||
const Joystick = @This();
|
||||
|
||||
|
|
@ -46,7 +47,14 @@ const GamepadState = extern struct {
|
|||
buttons: [15]u8,
|
||||
|
||||
/// The states of each gamepad axis (see gamepad_axes), in the range -1.0 to 1.0 inclusive.
|
||||
///
|
||||
/// Use the enumeration helper e.g. `.getAxis(.left_x)` to access these indices.
|
||||
axes: [6]f32,
|
||||
|
||||
/// Returns the status of the specified gamepad axis, in the range -1.0 to 1.0 inclusive.
|
||||
pub fn getAxis(self: @This(), which: GamepadAxis) f32 {
|
||||
return self.axis[which];
|
||||
}
|
||||
};
|
||||
|
||||
/// Returns whether the specified joystick is present.
|
||||
|
|
@ -540,4 +548,5 @@ test "getGamepadState" {
|
|||
|
||||
const joystick = glfw.Joystick{ .jid = glfw.Joystick.one };
|
||||
_ = joystick.getGamepadState() catch |err| std.debug.print("failed to get gamepad state, joysticks not supported? error={}\n", .{err});
|
||||
_ = (GamepadState{}).getAxis(.left_x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
//! Key and button actions
|
||||
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
/// Holds all GLFW C action enumerations in their raw form.
|
||||
/// Key and button actions
|
||||
pub const Action = enum(c_int) {
|
||||
/// The key or mouse button was released.
|
||||
release = c.GLFW_RELEASE,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
//! Gamepad axes.
|
||||
//!
|
||||
//! See glfw.getGamepadState for how these are used.
|
||||
|
||||
const c = @import("c.zig").c;
|
||||
|
||||
pub const left_x = c.GLFW_GAMEPAD_AXIS_LEFT_X;
|
||||
pub const left_y = c.GLFW_GAMEPAD_AXIS_LEFT_Y;
|
||||
pub const right_x = c.GLFW_GAMEPAD_AXIS_RIGHT_X;
|
||||
pub const right_y = c.GLFW_GAMEPAD_AXIS_RIGHT_Y;
|
||||
pub const left_trigger = c.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER;
|
||||
pub const right_trigger = c.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER;
|
||||
pub const left = right_trigger;
|
||||
/// Gamepad axes.
|
||||
///
|
||||
/// See glfw.getGamepadState for how these are used.
|
||||
pub const GamepadAxis = enum(c_int) {
|
||||
left_x = c.GLFW_GAMEPAD_AXIS_LEFT_X,
|
||||
left_y = c.GLFW_GAMEPAD_AXIS_LEFT_Y,
|
||||
right_x = c.GLFW_GAMEPAD_AXIS_RIGHT_X,
|
||||
right_y = c.GLFW_GAMEPAD_AXIS_RIGHT_Y,
|
||||
left_trigger = c.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER,
|
||||
right_trigger = c.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER,
|
||||
last = .right_trigger,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub const Error = @import("errors.zig").Error;
|
|||
const getError = @import("errors.zig").getError;
|
||||
|
||||
pub const Action = @import("action.zig").Action;
|
||||
pub const gamepad_axis = @import("gamepad_axis.zig");
|
||||
pub const GamepadAxis = @import("gamepad_axis.zig").GamepadAxis;
|
||||
pub const gamepad_button = @import("gamepad_button.zig");
|
||||
pub const GammaRamp = @import("GammaRamp.zig");
|
||||
pub const hat = @import("hat.zig");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue