glfw: force init in Cursor.zig
This commit is contained in:
parent
fba8bb1cb2
commit
de1e6391c6
1 changed files with 21 additions and 5 deletions
|
|
@ -8,6 +8,8 @@ const Error = @import("errors.zig").Error;
|
|||
const getError = @import("errors.zig").getError;
|
||||
const Image = @import("Image.zig");
|
||||
|
||||
const internal_debug = @import("internal_debug.zig");
|
||||
|
||||
const Cursor = @This();
|
||||
|
||||
ptr: *c.GLFWcursor,
|
||||
|
|
@ -58,10 +60,14 @@ pub const Shape = enum(isize) {
|
|||
/// @thread_safety This function must only be called from the main thread.
|
||||
///
|
||||
/// see also: cursor_object, glfw.Cursor.destroy, glfw.Cursor.createStandard
|
||||
pub inline fn create(image: Image, xhot: isize, yhot: isize) Error!Cursor {
|
||||
pub inline fn create(image: Image, xhot: isize, yhot: isize) error{ PlatformError }!Cursor {
|
||||
internal_debug.assertInitialized();
|
||||
const img = image.toC();
|
||||
const cursor = c.glfwCreateCursor(&img, @intCast(c_int, xhot), @intCast(c_int, yhot));
|
||||
try getError();
|
||||
getError() catch |err| return switch (err) {
|
||||
Error.PlatformError => err,
|
||||
else => unreachable,
|
||||
};
|
||||
return Cursor{ .ptr = cursor.? };
|
||||
}
|
||||
|
||||
|
|
@ -74,9 +80,15 @@ pub inline fn create(image: Image, xhot: isize, yhot: isize) Error!Cursor {
|
|||
/// @thread_safety This function must only be called from the main thread.
|
||||
///
|
||||
/// see also: cursor_object, glfwCreateCursor
|
||||
pub inline fn createStandard(shape: Shape) Error!Cursor {
|
||||
pub inline fn createStandard(shape: Shape) error{ InvalidEnum, PlatformError }!Cursor {
|
||||
internal_debug.assertInitialized();
|
||||
const cursor = c.glfwCreateStandardCursor(@intCast(c_int, @enumToInt(shape)));
|
||||
try getError();
|
||||
getError() catch |err| return switch (err) {
|
||||
// TODO: should be impossible given that only the values in 'Shape' are available, unless the user explicitly gives us a bad value via casting
|
||||
Error.InvalidEnum => unreachable,
|
||||
Error.PlatformError => err,
|
||||
else => unreachable,
|
||||
};
|
||||
return Cursor{ .ptr = cursor.? };
|
||||
}
|
||||
|
||||
|
|
@ -96,8 +108,12 @@ pub inline fn createStandard(shape: Shape) Error!Cursor {
|
|||
///
|
||||
/// see also: cursor_object, glfw.createCursor
|
||||
pub inline fn destroy(self: Cursor) void {
|
||||
internal_debug.assertInitialized();
|
||||
c.glfwDestroyCursor(self.ptr);
|
||||
getError() catch {}; // what would anyone do with it anyway?
|
||||
getError() catch |err| return switch (err) {
|
||||
Error.PlatformError => {}, // TODO: See 'todo' in 'internal_debug.zig' concerning 'PlatformError'
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
|
||||
test "create" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue