glfw: add glfw.Window.getInputMode
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
79a2784093
commit
d23cd8e400
1 changed files with 36 additions and 19 deletions
|
|
@ -1303,25 +1303,26 @@ pub inline fn setContentScaleCallback(self: Window, callback: ?fn (window: Windo
|
||||||
getError() catch {};
|
getError() catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mouinput options)
|
/// Returns the value of an input option for the specified window.
|
||||||
// /// Returns the value of an input option for the specified window.
|
///
|
||||||
// ///
|
/// This function returns the value of an input option for the specified window. The mode must be
|
||||||
// /// This function returns the value of an input option for the specified window.
|
/// one of `glfw.cursor`, `glfw.sticky_keys`, `glfw.sticky_mouse_buttons`, `glfw.lock_key_mods`, or
|
||||||
// /// The mode must be one of @ref GLFW_CURSOR, @ref GLFW_STICKY_KEYS,
|
/// `glfw.raw_mouse_motion`.
|
||||||
// /// @ref GLFW_STICKY_MOUSE_BUTTONS, @ref GLFW_LOCK_KEY_MODS or
|
///
|
||||||
// /// @ref GLFW_RAW_MOUSE_MOTION.
|
/// Boolean values, such as for `glfw.raw_mouse_motion`, are returned as integers. You may convert
|
||||||
// ///
|
/// to a boolean using `== 1`.
|
||||||
// /// @param[in] window The window to query.
|
///
|
||||||
// /// @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS`,
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
// /// `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or
|
///
|
||||||
// /// `GLFW_RAW_MOUSE_MOTION`.
|
/// see also: glfw.setInputMode
|
||||||
// ///
|
pub inline fn getInputMode(self: Window, mode: isize) isize {
|
||||||
// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidEnum.
|
const value = c.glfwGetInputMode(self.handle, @intCast(c_int, mode));
|
||||||
// ///
|
|
||||||
// /// @thread_safety This function must only be called from the main thread.
|
// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidEnum.
|
||||||
// ///
|
getError() catch @panic("unexpected error getting input mode, invalid enum?");
|
||||||
// /// see also: glfw.setInputMode
|
|
||||||
// GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
|
return @intCast(isize, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets an input option for the specified window.
|
/// Sets an input option for the specified window.
|
||||||
///
|
///
|
||||||
|
|
@ -2558,6 +2559,22 @@ test "setDropCallback" {
|
||||||
}).callback) catch |err| std.debug.print("can't set window drop callback, not supported by OS maybe? error={}\n", .{err});
|
}).callback) catch |err| std.debug.print("can't set window drop callback, not supported by OS maybe? error={}\n", .{err});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getInputMode" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null) catch |err| {
|
||||||
|
// return without fail, because most of our CI environments are headless / we cannot open
|
||||||
|
// windows on them.
|
||||||
|
std.debug.print("note: failed to create window: {}\n", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
defer window.destroy();
|
||||||
|
|
||||||
|
_ = window.getInputMode(glfw.raw_mouse_motion) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
test "setInputMode" {
|
test "setInputMode" {
|
||||||
const glfw = @import("main.zig");
|
const glfw = @import("main.zig");
|
||||||
try glfw.init();
|
try glfw.init();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue