glfw: add glfw.Window.getMouseButton

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-23 13:06:18 -07:00 committed by Stephen Gutekanst
parent 9aaa8702a8
commit 77e9396888

View file

@ -1414,28 +1414,27 @@ pub inline fn setContentScaleCallback(self: Window, callback: ?fn (window: Windo
// /// see also: input_key // /// see also: input_key
// GLFWAPI int glfwGetKey(GLFWwindow* window, int key); // GLFWAPI int glfwGetKey(GLFWwindow* window, int key);
// TODO(mouse button) /// Returns the last reported state of a mouse button for the specified window.
// /// Returns the last reported state of a mouse button for the specified ///
// /// window. /// This function returns whether the specified mouse button is pressed or not.
// /// ///
// /// This function returns the last state reported for the specified mouse button /// If the glfw.sticky_mouse_buttons input mode is enabled, this function returns `true` the first
// /// to the specified window. The returned state is one of `glfw.press` or /// time you call it for a mouse button that was pressed, even if that mouse button has already been
// /// `glfw.release`. /// released.
// /// ///
// /// If the @ref GLFW_STICKY_MOUSE_BUTTONS input mode is enabled, this function /// @param[in] button The desired mouse button.
// /// returns `glfw.press` the first time you call it for a mouse button that was /// @return One of `true` (if pressed) or `false` (if released)
// /// pressed, even if that mouse button has already been released. ///
// /// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidEnum.
// /// @param[in] window The desired window. ///
// /// @param[in] button The desired mouse button. /// @thread_safety This function must only be called from the main thread.
// /// @return One of `glfw.press` or `glfw.release`. ///
// /// /// see also: input_mouse_button
// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidEnum. pub inline fn getMouseButton(self: Window, button: isize) Error!bool {
// /// const state = c.glfwGetMouseButton(self.handle, @intCast(c_int, button));
// /// @thread_safety This function must only be called from the main thread. try getError();
// /// return state == c.GLFW_PRESS;
// /// see also: input_mouse_button }
// GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button);
const CursorPos = struct { const CursorPos = struct {
xpos: f64, xpos: f64,
@ -2563,6 +2562,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 "getMouseButton" {
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.getMouseButton(glfw.mouse_button.left) catch |err| std.debug.print("failed to get mouse button, not supported? error={}\n", .{err});
}
test "getCursorPos" { test "getCursorPos" {
const glfw = @import("main.zig"); const glfw = @import("main.zig");
try glfw.init(); try glfw.init();