glfw: add glfw.Window.setInputMode
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
53519d94af
commit
79a2784093
1 changed files with 73 additions and 56 deletions
|
|
@ -1323,62 +1323,59 @@ pub inline fn setContentScaleCallback(self: Window, callback: ?fn (window: Windo
|
||||||
// /// see also: glfw.setInputMode
|
// /// see also: glfw.setInputMode
|
||||||
// GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
|
// GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
|
||||||
|
|
||||||
// TODO(mouinput options)
|
/// Sets an input option for the specified window.
|
||||||
// /// Sets an input option for the specified window.
|
///
|
||||||
// ///
|
/// This function sets an input mode option for the specified window. The mode must be one of
|
||||||
// /// This function sets an input mode option for the specified window. The mode
|
/// `glfw.cursor`, `glfw.sticky_keys`, `glfw.sticky_mouse_buttons`, `glfw.lock_key_mods`, or
|
||||||
// /// 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.
|
/// If the mode is `glfw.cursor`, the value must be one of the following cursor
|
||||||
// ///
|
/// modes:
|
||||||
// /// If the mode is `GLFW_CURSOR`, the value must be one of the following cursor
|
/// - `glfw.cursor_normal` makes the cursor visible and behaving normally.
|
||||||
// /// modes:
|
/// - `glfw.cursor_hidden` makes the cursor invisible when it is over the content area of the window
|
||||||
// /// - `GLFW_CURSOR_NORMAL` makes the cursor visible and behaving normally.
|
/// but does not restrict the cursor from leaving.
|
||||||
// /// - `GLFW_CURSOR_HIDDEN` makes the cursor invisible when it is over the
|
/// - `glfw.cursor_disabled` hides and grabs the cursor, providing virtual and unlimited cursor
|
||||||
// /// content area of the window but does not restrict the cursor from leaving.
|
/// movement. This is useful for implementing for example 3D camera controls.
|
||||||
// /// - `GLFW_CURSOR_DISABLED` hides and grabs the cursor, providing virtual
|
///
|
||||||
// /// and unlimited cursor movement. This is useful for implementing for
|
/// If the mode is `glfw.sticky_keys`, the value must be either `true` to enable sticky keys, or
|
||||||
// /// example 3D camera controls.
|
/// `false` to disable it. If sticky keys are enabled, a key press will ensure that `glfw.Window.getKey`
|
||||||
// ///
|
/// `true` (pressed) the next time it is called even if the key had been released before the call.
|
||||||
// /// If the mode is `GLFW_STICKY_KEYS`, the value must be either `true` to
|
/// This is useful when you are only interested in whether keys have been pressed but not when or in
|
||||||
// /// enable sticky keys, or `false` to disable it. If sticky keys are
|
/// which order.
|
||||||
// /// enabled, a key press will ensure that @ref glfwGetKey returns `glfw.press`
|
///
|
||||||
// /// the next time it is called even if the key had been released before the
|
/// If the mode is `glfw.sticky_mouse_buttons`, the value must be either `true` to enable sticky
|
||||||
// /// call. This is useful when you are only interested in whether keys have been
|
/// mouse buttons, or `false` to disable it. If sticky mouse buttons are enabled, a mouse button
|
||||||
// /// pressed but not when or in which order.
|
/// press will ensure that glfw.Window.getMouseButton returns `glfw.press` the next time it is
|
||||||
// ///
|
/// called even if the mouse button had been released before the call. This is useful when you are
|
||||||
// /// If the mode is `GLFW_STICKY_MOUSE_BUTTONS`, the value must be either
|
/// only interested in whether mouse buttons have been pressed but not when or in which order.
|
||||||
// /// `true` to enable sticky mouse buttons, or `false` to disable it.
|
///
|
||||||
// /// If sticky mouse buttons are enabled, a mouse button press will ensure that
|
/// If the mode is `glfw.lock_key_mods`, the value must be either `true` to enable lock key modifier
|
||||||
// /// @ref glfwGetMouseButton returns `glfw.press` the next time it is called even
|
/// bits, or `false` to disable them. If enabled, callbacks that receive modifier bits will also
|
||||||
// /// if the mouse button had been released before the call. This is useful when
|
/// have the glfw.mod.caps_lock bit set when the event was generated with Caps Lock on, and the
|
||||||
// /// you are only interested in whether mouse buttons have been pressed but not
|
/// glfw.mod.num_lock bit when Num Lock was on.
|
||||||
// /// when or in which order.
|
///
|
||||||
// ///
|
/// If the mode is `glfw.raw_mouse_motion`, the value must be either `true` to enable raw (unscaled
|
||||||
// /// If the mode is `GLFW_LOCK_KEY_MODS`, the value must be either `true` to
|
/// and unaccelerated) mouse motion when the cursor is disabled, or `false` to disable it. If raw
|
||||||
// /// enable lock key modifier bits, or `false` to disable them. If enabled,
|
/// motion is not supported, attempting to set this will emit glfw.Error.PlatformError. Call
|
||||||
// /// callbacks that receive modifier bits will also have the @ref
|
/// glfw.rawMouseMotionSupported to check for support.
|
||||||
// /// GLFW_MOD_CAPS_LOCK bit set when the event was generated with Caps Lock on,
|
///
|
||||||
// /// and the @ref GLFW_MOD_NUM_LOCK bit when Num Lock was on.
|
/// @param[in] mode One of `glfw.cursor`, `glfw.sticky_keys`, `glfw.sticky_mouse_buttons`,
|
||||||
// ///
|
/// `glfw.lock_key_mods` or `glfw.raw_mouse_motion`.
|
||||||
// /// If the mode is `GLFW_RAW_MOUSE_MOTION`, the value must be either `true`
|
/// @param[in] value The new value of the specified input mode.
|
||||||
// /// to enable raw (unscaled and unaccelerated) mouse motion when the cursor is
|
///
|
||||||
// /// disabled, or `false` to disable it. If raw motion is not supported,
|
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
||||||
// /// attempting to set this will emit glfw.Error.PlatformError. Call @ref
|
///
|
||||||
// /// glfwRawMouseMotionSupported to check for support.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
// ///
|
///
|
||||||
// /// @param[in] window The window whose input mode to set.
|
/// see also: glfw.getInputMode
|
||||||
// /// @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS`,
|
pub inline fn setInputMode(self: Window, mode: isize, value: anytype) Error!void {
|
||||||
// /// `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or
|
switch (@typeInfo(@TypeOf(value))) {
|
||||||
// /// `GLFW_RAW_MOUSE_MOTION`.
|
.Int, .ComptimeInt => c.glfwSetInputMode(self.handle, @intCast(c_int, mode), @intCast(c_int, value)),
|
||||||
// /// @param[in] value The new value of the specified input mode.
|
.Bool => c.glfwSetInputMode(self.handle, @intCast(c_int, mode), @intCast(c_int, @boolToInt(value))),
|
||||||
// ///
|
else => @compileError("expected a int or bool, got " ++ @typeName(@TypeOf(value))),
|
||||||
// /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
}
|
||||||
// ///
|
try getError();
|
||||||
// /// @thread_safety This function must only be called from the main thread.
|
}
|
||||||
// ///
|
|
||||||
// /// see also: glfw.getInputMode
|
|
||||||
// GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value);
|
|
||||||
|
|
||||||
/// Returns the last reported press state of a keyboard key for the specified window.
|
/// Returns the last reported press state of a keyboard key for the specified window.
|
||||||
///
|
///
|
||||||
|
|
@ -2561,6 +2558,26 @@ 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 "setInputMode" {
|
||||||
|
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();
|
||||||
|
|
||||||
|
// Boolean values.
|
||||||
|
window.setInputMode(glfw.raw_mouse_motion, true) catch |err| std.debug.print("failed to set input mode, not supported? error={}\n", .{err});
|
||||||
|
|
||||||
|
// Integer values.
|
||||||
|
window.setInputMode(glfw.cursor, glfw.cursor_hidden) catch |err| std.debug.print("failed to set input mode, not supported? error={}\n", .{err});
|
||||||
|
}
|
||||||
|
|
||||||
test "getKey" {
|
test "getKey" {
|
||||||
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