glfw: make init hints a proper enum
Helps hexops/mach#37 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
f1644d2e59
commit
7264741ede
2 changed files with 37 additions and 14 deletions
|
|
@ -29,15 +29,3 @@ pub const osmesa_context_api = c.GLFW_OSMESA_CONTEXT_API;
|
||||||
|
|
||||||
/// Possible value for various window hints, etc.
|
/// Possible value for various window hints, etc.
|
||||||
pub const dont_care = c.GLFW_DONT_CARE;
|
pub const dont_care = c.GLFW_DONT_CARE;
|
||||||
|
|
||||||
// TODO(enumify)
|
|
||||||
/// Joystick hat buttons init hint.
|
|
||||||
pub const joystick_hat_buttons = c.GLFW_JOYSTICK_HAT_BUTTONS;
|
|
||||||
|
|
||||||
// TODO(enumify)
|
|
||||||
/// macOS specific init hint.
|
|
||||||
pub const cocoa_chdir_resources = c.GLFW_COCOA_CHDIR_RESOURCES;
|
|
||||||
|
|
||||||
// TODO(enumify)
|
|
||||||
/// macOS specific init hint.
|
|
||||||
pub const cocoa_menubar = c.GLFW_COCOA_MENUBAR;
|
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,31 @@ pub inline fn terminate() void {
|
||||||
c.glfwTerminate();
|
c.glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initialization hints for passing into glfw.initHint
|
||||||
|
pub const InitHint = enum(c_int) {
|
||||||
|
/// Specifies whether to also expose joystick hats as buttons, for compatibility with earlier
|
||||||
|
/// versions of GLFW that did not have glfwGetJoystickHats.
|
||||||
|
///
|
||||||
|
/// Possible values are `true` and `false`.
|
||||||
|
joystick_hat_buttons = c.GLFW_JOYSTICK_HAT_BUTTONS,
|
||||||
|
|
||||||
|
/// macOS specific init hint. Ignored on other platforms.
|
||||||
|
///
|
||||||
|
/// Specifies whether to set the current directory to the application to the Contents/Resources
|
||||||
|
/// subdirectory of the application's bundle, if present.
|
||||||
|
///
|
||||||
|
/// Possible values are `true` and `false`.
|
||||||
|
cocoa_chdir_resources = c.GLFW_COCOA_CHDIR_RESOURCES,
|
||||||
|
|
||||||
|
/// macOS specific init hint. Ignored on other platforms.
|
||||||
|
///
|
||||||
|
/// specifies whether to create a basic menu bar, either from a nib or manually, when the first
|
||||||
|
/// window is created, which is when AppKit is initialized.
|
||||||
|
///
|
||||||
|
/// Possible values are `true` and `false`.
|
||||||
|
cocoa_menubar = c.GLFW_COCOA_MENUBAR,
|
||||||
|
};
|
||||||
|
|
||||||
/// Sets the specified init hint to the desired value.
|
/// Sets the specified init hint to the desired value.
|
||||||
///
|
///
|
||||||
/// This function sets hints for the next initialization of GLFW.
|
/// This function sets hints for the next initialization of GLFW.
|
||||||
|
|
@ -104,8 +129,12 @@ pub inline fn terminate() void {
|
||||||
/// @remarks This function may be called before glfw.init.
|
/// @remarks This function may be called before glfw.init.
|
||||||
///
|
///
|
||||||
/// @thread_safety This function must only be called from the main thread.
|
/// @thread_safety This function must only be called from the main thread.
|
||||||
pub inline fn initHint(hint: c_int, value: c_int) Error!void {
|
pub inline fn initHint(hint: InitHint, value: anytype) Error!void {
|
||||||
c.glfwInitHint(hint, value);
|
switch (@typeInfo(@TypeOf(value))) {
|
||||||
|
.Int, .ComptimeInt => c.glfwInitHint(@enumToInt(hint), @intCast(c_int, value)),
|
||||||
|
.Bool => c.glfwInitHint(@enumToInt(hint), @intCast(c_int, @boolToInt(value))),
|
||||||
|
else => @compileError("expected a int or bool, got " ++ @typeName(@TypeOf(value))),
|
||||||
|
}
|
||||||
try getError();
|
try getError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,6 +340,12 @@ test "getVersionString" {
|
||||||
std.debug.print("\nstring: {s}\n", .{getVersionString()});
|
std.debug.print("\nstring: {s}\n", .{getVersionString()});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "pollEvents" {
|
||||||
|
try initHint(.cocoa_chdir_resources, true);
|
||||||
|
try init();
|
||||||
|
defer terminate();
|
||||||
|
}
|
||||||
|
|
||||||
test "pollEvents" {
|
test "pollEvents" {
|
||||||
try init();
|
try init();
|
||||||
defer terminate();
|
defer terminate();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue