glfw: make setMouseButtonCallback use Mods bitmask directly

Helps hexops/mach#37

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-30 13:50:43 -07:00 committed by Stephen Gutekanst
parent 0beaedd263
commit f6f758859a

View file

@ -51,7 +51,7 @@ pub const InternalUserPointer = struct {
setContentScaleCallback: ?fn (window: Window, xscale: f32, yscale: f32) void,
setKeyCallback: ?fn (window: Window, key: isize, scancode: isize, action: Action, mods: Mods) void,
setCharCallback: ?fn (window: Window, codepoint: u21) void,
setMouseButtonCallback: ?fn (window: Window, button: isize, action: Action, mods: isize) void,
setMouseButtonCallback: ?fn (window: Window, button: isize, action: Action, mods: Mods) void,
setCursorPosCallback: ?fn (window: Window, xpos: f64, ypos: f64) void,
setCursorEnterCallback: ?fn (window: Window, entered: bool) void,
setScrollCallback: ?fn (window: Window, xoffset: f64, yoffset: f64) void,
@ -1617,7 +1617,7 @@ pub inline fn setCharCallback(self: Window, callback: ?fn (window: Window, codep
fn setMouseButtonCallbackWrapper(handle: ?*c.GLFWwindow, button: c_int, action: c_int, mods: c_int) callconv(.C) void {
const window = from(handle.?) catch unreachable;
const internal = window.getInternal();
internal.setMouseButtonCallback.?(window, @intCast(isize, button), @intToEnum(Action, action), @intCast(isize, mods));
internal.setMouseButtonCallback.?(window, @intCast(isize, button), @intToEnum(Action, action), Mods.fromInt(mods));
}
/// Sets the mouse button callback.
@ -1642,7 +1642,7 @@ fn setMouseButtonCallbackWrapper(handle: ?*c.GLFWwindow, button: c_int, action:
/// @thread_safety This function must only be called from the main thread.
///
/// see also: input_mouse_button
pub inline fn setMouseButtonCallback(self: Window, callback: ?fn (window: Window, button: isize, action: Action, mods: isize) void) void {
pub inline fn setMouseButtonCallback(self: Window, callback: ?fn (window: Window, button: isize, action: Action, mods: Mods) void) void {
var internal = self.getInternal();
internal.setMouseButtonCallback = callback;
_ = c.glfwSetMouseButtonCallback(self.handle, if (callback != null) setMouseButtonCallbackWrapper else null);
@ -2742,7 +2742,7 @@ test "setMouseButtonCallback" {
defer window.destroy();
window.setMouseButtonCallback((struct {
fn callback(_window: Window, button: isize, action: Action, mods: isize) void {
fn callback(_window: Window, button: isize, action: Action, mods: Mods) void {
_ = _window;
_ = button;
_ = action;