glfw: add enum for standard cursor shapes
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
b50cbba83f
commit
0f6efa4bc0
1 changed files with 17 additions and 20 deletions
|
|
@ -12,26 +12,26 @@ const Cursor = @This();
|
||||||
|
|
||||||
ptr: *c.GLFWcursor,
|
ptr: *c.GLFWcursor,
|
||||||
|
|
||||||
// TODO(enum)
|
|
||||||
|
|
||||||
// Standard system cursor shapes.
|
// Standard system cursor shapes.
|
||||||
/// The regular arrow cursor shape.
|
const Shape = enum(isize) {
|
||||||
pub const arrow_cursor = c.GLFW_ARROW_CURSOR;
|
/// The regular arrow cursor shape.
|
||||||
|
arrow = c.GLFW_ARROW_CURSOR,
|
||||||
|
|
||||||
/// The text input I-beam cursor shape.
|
/// The text input I-beam cursor shape.
|
||||||
pub const ibeam_cursor = c.GLFW_IBEAM_CURSOR;
|
ibeam = c.GLFW_IBEAM_CURSOR,
|
||||||
|
|
||||||
/// The crosshair shape.
|
/// The crosshair shape.
|
||||||
pub const crosshair_cursor = c.GLFW_CROSSHAIR_CURSOR;
|
crosshair = c.GLFW_CROSSHAIR_CURSOR,
|
||||||
|
|
||||||
/// The hand shape.
|
/// The hand shape.
|
||||||
pub const hand_cursor = c.GLFW_HAND_CURSOR;
|
hand = c.GLFW_HAND_CURSOR,
|
||||||
|
|
||||||
/// The horizontal resize arrow shape.
|
/// The horizontal resize arrow shape.
|
||||||
pub const hresize_cursor = c.GLFW_HRESIZE_CURSOR;
|
hresize = c.GLFW_HRESIZE_CURSOR,
|
||||||
|
|
||||||
/// The vertical resize arrow shape.
|
/// The vertical resize arrow shape.
|
||||||
pub const vresize_cursor = c.GLFW_VRESIZE_CURSOR;
|
vresize = c.GLFW_VRESIZE_CURSOR,
|
||||||
|
};
|
||||||
|
|
||||||
/// Creates a custom cursor.
|
/// Creates a custom cursor.
|
||||||
///
|
///
|
||||||
|
|
@ -69,16 +69,13 @@ pub inline fn create(image: Image, xhot: isize, yhot: isize) Error!Cursor {
|
||||||
///
|
///
|
||||||
/// Returns a cursor with a standard shape (see shapes), that can be set for a window with glfw.Window.setCursor.
|
/// Returns a cursor with a standard shape (see shapes), that can be set for a window with glfw.Window.setCursor.
|
||||||
///
|
///
|
||||||
/// @param[in] shape One of the standard shapes (see shapes).
|
|
||||||
/// @return A new cursor ready to use.
|
|
||||||
///
|
|
||||||
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
/// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError.
|
||||||
///
|
///
|
||||||
/// @thread_safety This function must only be called from the main thread.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
///
|
///
|
||||||
/// see also: cursor_object, glfwCreateCursor
|
/// see also: cursor_object, glfwCreateCursor
|
||||||
pub inline fn createStandard(shape: isize) Error!Cursor {
|
pub inline fn createStandard(shape: Shape) Error!Cursor {
|
||||||
const cursor = c.glfwCreateStandardCursor(@intCast(c_int, shape));
|
const cursor = c.glfwCreateStandardCursor(@intCast(c_int, @enumToInt(shape)));
|
||||||
try getError();
|
try getError();
|
||||||
return Cursor{ .ptr = cursor.? };
|
return Cursor{ .ptr = cursor.? };
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +122,7 @@ test "createStandard" {
|
||||||
try glfw.init();
|
try glfw.init();
|
||||||
defer glfw.terminate();
|
defer glfw.terminate();
|
||||||
|
|
||||||
const cursor = glfw.Cursor.createStandard(glfw.Cursor.ibeam_cursor) catch |err| {
|
const cursor = glfw.Cursor.createStandard(.ibeam) catch |err| {
|
||||||
std.debug.print("failed to create cursor, custom cursors not supported? error={}\n", .{err});
|
std.debug.print("failed to create cursor, custom cursors not supported? error={}\n", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue