diff options
-rw-r--r-- | build.zig | 13 | ||||
-rw-r--r-- | src/Monitor.zig | 4 | ||||
-rw-r--r-- | src/Window.zig | 186 | ||||
-rw-r--r-- | src/gfz.zig | 42 | ||||
-rw-r--r-- | src/input.zig | 38 |
5 files changed, 146 insertions, 137 deletions
diff --git a/build.zig b/build.zig index 42a8031..f701451 100644 --- a/build.zig +++ b/build.zig @@ -16,7 +16,15 @@ // You should have received a copy of the GNU Lesser General Public License // along with gfz. If not, see <https://www.gnu.org/licenses/>. -const Builder = @import("std").build.Builder; +const std = @import("std"); +const Builder = std.build.Builder; +const LibExeObjStep = std.build.LibExeObjStep; + +/// Link given library, executable, or object with shared libraries. +pub fn link(lib_exe_obj: *LibExeObjStep) void { + lib_exe_obj.linkSystemLibrary("glfw"); + lib_exe_obj.linkSystemLibrary("c"); +} pub fn build(b: *Builder) void { // Standard release options allow the person running `zig build` to select @@ -24,8 +32,7 @@ pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const lib = b.addStaticLibrary("gfz", "src/gfz.zig"); - lib.linkSystemLibrary("glfw"); - lib.linkSystemLibrary("c"); + link(lib); lib.setBuildMode(mode); lib.install(); diff --git a/src/Monitor.zig b/src/Monitor.zig index d3b2db7..e515a3b 100644 --- a/src/Monitor.zig +++ b/src/Monitor.zig @@ -1,3 +1,3 @@ -usingnamespace @import("cimport.zig"); +const c = @import("cimport.zig"); -pimpl: *GLFWmonitor, +pimpl: *c.GLFWmonitor, diff --git a/src/Window.zig b/src/Window.zig index 5ff2de9..787fd84 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -16,13 +16,13 @@ // You should have received a copy of the GNU Lesser General Public License // along with gfz. If not, see <https://www.gnu.org/licenses/>. -usingnamespace @import("cimport.zig"); const Error = gfz.Error; const Key = input.Key; const KeyAction = input.KeyAction; const Mods = input.Mods; const Monitor = @import("Monitor.zig"); const MouseButton = input.MouseButton; +const c = @import("cimport.zig"); const checkError = gfz.checkError; const getError = gfz.getError; const gfz = @import("gfz.zig"); @@ -35,19 +35,19 @@ const KeyFun = fn (window: Self, key: Key, scancode: c_int, const MouseButtonFun = fn (window: Self, button: MouseButton, action: MouseButton.Action, mods: Mods) void; const SizeFun = fn (window: Self, width: c_int, height: c_int) void; -const Impl = GLFWwindow; +const Impl = c.GLFWwindow; pimpl: *Impl, /// Convert given function to GLFW callback. fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { return switch (DestType) { - GLFWcursorposfun => struct { + c.GLFWcursorposfun => struct { pub fn callback(window: ?*Impl, xpos: f64, ypos: f64) callconv(.C) void { fun(@fieldParentPtr(Self, "pimpl", &window.?).*, xpos, ypos); } }, - GLFWkeyfun => struct { + c.GLFWkeyfun => struct { pub fn callback(window: ?*Impl, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void { fun(@fieldParentPtr(Self, "pimpl", &window.?).*, @@ -55,7 +55,7 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { @intToEnum(KeyAction, action), Mods.fromInt(mods)); } }, - GLFWmousebuttonfun => struct { + c.GLFWmousebuttonfun => struct { pub fn callback(window: ?*Impl, button: c_int, action: c_int, mods: c_int) callconv(.C) void { fun(@fieldParentPtr(Self, "pimpl", &window.?).*, @@ -63,7 +63,7 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { @intToEnum(MouseButton.Action, action), Mods.fromInt(mods)); } }, - GLFWwindowsizefun => struct { + c.GLFWwindowsizefun => struct { pub fn callback(window: ?*Impl, width: c_int, height: c_int) callconv(.C) void { fun(@fieldParentPtr(Self, "pimpl", &window.?).*, width, height); @@ -74,7 +74,7 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { } pub const Hints = struct { - pub const dont_care = GLFW_DONT_CARE; + pub const dont_care = c.GLFW_DONT_CARE; resizable: bool = true, visible: bool = true, @@ -111,29 +111,29 @@ pub const Hints = struct { doublebuffer: bool = true, client_api: enum(c_int) { - opengl = GLFW_OPENGL_API, - opengl_es = GLFW_OPENGL_ES_API, - no = GLFW_NO_API, + opengl = c.GLFW_OPENGL_API, + opengl_es = c.GLFW_OPENGL_ES_API, + no = c.GLFW_NO_API, } = .opengl, context: struct { creation_api: enum(c_int) { - native = GLFW_NATIVE_CONTEXT_API, - egl = GLFW_EGL_CONTEXT_API, - osmesa = GLFW_OSMESA_CONTEXT_API, + native = c.GLFW_NATIVE_CONTEXT_API, + egl = c.GLFW_EGL_CONTEXT_API, + osmesa = c.GLFW_OSMESA_CONTEXT_API, } = .native, version: struct { major: c_int = 1, minor: c_int = 0, } = .{}, robustness: enum(c_int) { - no_robustness = GLFW_NO_ROBUSTNESS, - no_reset_notification = GLFW_NO_RESET_NOTIFICATION, - lose_context_on_reset = GLFW_LOSE_CONTEXT_ON_RESET, + no_robustness = c.GLFW_NO_ROBUSTNESS, + no_reset_notification = c.GLFW_NO_RESET_NOTIFICATION, + lose_context_on_reset = c.GLFW_LOSE_CONTEXT_ON_RESET, } = .no_robustness, release_behavior: enum(c_int) { - any = GLFW_ANY_RELEASE_BEHAVIOR, - flush = GLFW_RELEASE_BEHAVIOR_FLUSH, - none = GLFW_RELEASE_BEHAVIOR_NONE, + any = c.GLFW_ANY_RELEASE_BEHAVIOR, + flush = c.GLFW_RELEASE_BEHAVIOR_FLUSH, + none = c.GLFW_RELEASE_BEHAVIOR_NONE, } = .any, } = .{}, @@ -141,18 +141,18 @@ pub const Hints = struct { forward_compat: bool = false, debug_context: bool = false, profile: enum(c_int) { - any = GLFW_OPENGL_ANY_PROFILE, - compat = GLFW_OPENGL_COMPAT_PROFILE, - core = GLFW_OPENGL_CORE_PROFILE, + any = c.GLFW_OPENGL_ANY_PROFILE, + compat = c.GLFW_OPENGL_COMPAT_PROFILE, + core = c.GLFW_OPENGL_CORE_PROFILE, } = .any, } = .{}, }; /// Set the specified window hint to the desired value. fn setHint(hint: c_int, value: anytype) Error!void { - glfwWindowHint(hint, switch (@TypeOf(value)) { + c.glfwWindowHint(hint, switch (@TypeOf(value)) { c_int, comptime_int => value, - bool => if (value) GLFW_TRUE else GLFW_FALSE, + bool => if (value) c.GLFW_TRUE else c.GLFW_FALSE, else => @enumToInt(value), }); try checkError(); @@ -166,46 +166,47 @@ const Options = struct { /// Create a window and its associated context. pub fn create(width: c_int, height: c_int, title: [:0]const u8, options: Options, hints: Hints) Error!Self { - try setHint(GLFW_RESIZABLE, hints.resizable); - try setHint(GLFW_VISIBLE, hints.visible); - try setHint(GLFW_DECORATED, hints.decorated); - try setHint(GLFW_FOCUSED, hints.focused); - try setHint(GLFW_AUTO_ICONIFY, hints.auto_iconify); - try setHint(GLFW_FLOATING, hints.floating); - try setHint(GLFW_MAXIMIZED, hints.maximized); - try setHint(GLFW_CENTER_CURSOR, hints.center_cursor); - try setHint(GLFW_TRANSPARENT_FRAMEBUFFER, hints.transparent_framebuffer); - try setHint(GLFW_FOCUS_ON_SHOW, hints.focus_on_show); - try setHint(GLFW_SCALE_TO_MONITOR, hints.scale_to_monitor); - try setHint(GLFW_RED_BITS, hints.bits.red); - try setHint(GLFW_GREEN_BITS, hints.bits.green); - try setHint(GLFW_BLUE_BITS, hints.bits.blue); - try setHint(GLFW_ALPHA_BITS, hints.bits.alpha); - try setHint(GLFW_DEPTH_BITS, hints.bits.depth); - try setHint(GLFW_STENCIL_BITS, hints.bits.stencil); - try setHint(GLFW_ACCUM_RED_BITS, hints.accum_bits.red); - try setHint(GLFW_ACCUM_GREEN_BITS, hints.accum_bits.green); - try setHint(GLFW_ACCUM_BLUE_BITS, hints.accum_bits.blue); - try setHint(GLFW_ACCUM_ALPHA_BITS, hints.accum_bits.alpha); - try setHint(GLFW_AUX_BUFFERS, hints.aux_buffers); - try setHint(GLFW_SAMPLES, hints.samples); - try setHint(GLFW_REFRESH_RATE, hints.refresh_rate); - try setHint(GLFW_STEREO, hints.stereo); - try setHint(GLFW_SRGB_CAPABLE, hints.srgb_capable); - try setHint(GLFW_DOUBLEBUFFER, hints.doublebuffer); - try setHint(GLFW_CLIENT_API, hints.client_api); - try setHint(GLFW_CONTEXT_CREATION_API, hints.context.creation_api); - try setHint(GLFW_CONTEXT_VERSION_MAJOR, hints.context.version.major); - try setHint(GLFW_CONTEXT_VERSION_MINOR, hints.context.version.minor); - try setHint(GLFW_CONTEXT_ROBUSTNESS, hints.context.robustness); - try setHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, hints.context.release_behavior); - try setHint(GLFW_OPENGL_FORWARD_COMPAT, hints.opengl.forward_compat); - try setHint(GLFW_OPENGL_DEBUG_CONTEXT, hints.opengl.debug_context); - try setHint(GLFW_OPENGL_PROFILE, hints.opengl.profile); + try setHint(c.GLFW_RESIZABLE, hints.resizable); + try setHint(c.GLFW_VISIBLE, hints.visible); + try setHint(c.GLFW_DECORATED, hints.decorated); + try setHint(c.GLFW_FOCUSED, hints.focused); + try setHint(c.GLFW_AUTO_ICONIFY, hints.auto_iconify); + try setHint(c.GLFW_FLOATING, hints.floating); + try setHint(c.GLFW_MAXIMIZED, hints.maximized); + try setHint(c.GLFW_CENTER_CURSOR, hints.center_cursor); + try setHint(c.GLFW_TRANSPARENT_FRAMEBUFFER, hints.transparent_framebuffer); + try setHint(c.GLFW_FOCUS_ON_SHOW, hints.focus_on_show); + try setHint(c.GLFW_SCALE_TO_MONITOR, hints.scale_to_monitor); + try setHint(c.GLFW_RED_BITS, hints.bits.red); + try setHint(c.GLFW_GREEN_BITS, hints.bits.green); + try setHint(c.GLFW_BLUE_BITS, hints.bits.blue); + try setHint(c.GLFW_ALPHA_BITS, hints.bits.alpha); + try setHint(c.GLFW_DEPTH_BITS, hints.bits.depth); + try setHint(c.GLFW_STENCIL_BITS, hints.bits.stencil); + try setHint(c.GLFW_ACCUM_RED_BITS, hints.accum_bits.red); + try setHint(c.GLFW_ACCUM_GREEN_BITS, hints.accum_bits.green); + try setHint(c.GLFW_ACCUM_BLUE_BITS, hints.accum_bits.blue); + try setHint(c.GLFW_ACCUM_ALPHA_BITS, hints.accum_bits.alpha); + try setHint(c.GLFW_AUX_BUFFERS, hints.aux_buffers); + try setHint(c.GLFW_SAMPLES, hints.samples); + try setHint(c.GLFW_REFRESH_RATE, hints.refresh_rate); + try setHint(c.GLFW_STEREO, hints.stereo); + try setHint(c.GLFW_SRGB_CAPABLE, hints.srgb_capable); + try setHint(c.GLFW_DOUBLEBUFFER, hints.doublebuffer); + try setHint(c.GLFW_CLIENT_API, hints.client_api); + try setHint(c.GLFW_CONTEXT_CREATION_API, hints.context.creation_api); + try setHint(c.GLFW_CONTEXT_VERSION_MAJOR, hints.context.version.major); + try setHint(c.GLFW_CONTEXT_VERSION_MINOR, hints.context.version.minor); + try setHint(c.GLFW_CONTEXT_ROBUSTNESS, hints.context.robustness); + try setHint(c.GLFW_CONTEXT_RELEASE_BEHAVIOR, + hints.context.release_behavior); + try setHint(c.GLFW_OPENGL_FORWARD_COMPAT, hints.opengl.forward_compat); + try setHint(c.GLFW_OPENGL_DEBUG_CONTEXT, hints.opengl.debug_context); + try setHint(c.GLFW_OPENGL_PROFILE, hints.opengl.profile); const monitor = if (options.fullscreen) |box| box.pimpl else null; const share = if (options.share) |box| box.pimpl else null; - const ptr = glfwCreateWindow(width, height, title.ptr, monitor, share); + const ptr = c.glfwCreateWindow(width, height, title.ptr, monitor, share); return if (ptr) |pimpl| Self{ .pimpl = pimpl } else @@ -214,7 +215,7 @@ pub fn create(width: c_int, height: c_int, title: [:0]const u8, /// Return the window whose context is current on the calling thread. pub fn getCurrent() Error!?Self { - const result = if (glfwGetCurrentContext()) |pimpl| + const result = if (c.glfwGetCurrentContext()) |pimpl| Self{ .pimpl = pimpl } else null; @@ -224,66 +225,67 @@ pub fn getCurrent() Error!?Self { /// Make the context current for the calling thread. pub fn makeCurrent(self: ?Self) Error!void { - glfwMakeContextCurrent(if (self) |window| window.pimpl else null); + c.glfwMakeContextCurrent(if (self) |window| window.pimpl else null); try checkError(); } /// Check the close flag. pub fn shouldClose(self: Self) Error!bool { - const flag = glfwWindowShouldClose(self.pimpl); + const flag = c.glfwWindowShouldClose(self.pimpl); try checkError(); - return flag == GLFW_TRUE; + return flag == c.GLFW_TRUE; } /// Set the close flag. pub fn setShouldClose(self: Self, value: bool) Error!void { - glfwSetWindowShouldClose(self.pimpl, if (value) GLFW_TRUE else GLFW_FALSE); + c.glfwSetWindowShouldClose(self.pimpl, + if (value) c.GLFW_TRUE else c.GLFW_FALSE); try checkError(); } /// Swap the front and back buffers. pub fn swapBuffers(self: Self) Error!void { - glfwSwapBuffers(self.pimpl); + c.glfwSwapBuffers(self.pimpl); try checkError(); } const InputMode = enum(c_int) { - sticky_keys = GLFW_STICKY_KEYS, - sticky_mouse_buttons = GLFW_STICKY_MOUSE_BUTTONS, - lock_key_mods = GLFW_LOCK_KEY_MODS, - raw_mouse_motion = GLFW_RAW_MOUSE_MOTION, + sticky_keys = c.GLFW_STICKY_KEYS, + sticky_mouse_buttons = c.GLFW_STICKY_MOUSE_BUTTONS, + lock_key_mods = c.GLFW_LOCK_KEY_MODS, + raw_mouse_motion = c.GLFW_RAW_MOUSE_MOTION, }; /// Return the value of an input option. pub fn getInputMode(self: Self, mode: InputMode) Error!bool { - const value = glfwGetInputMode(self.pimpl, @enumToInt(mode)); + const value = c.glfwGetInputMode(self.pimpl, @enumToInt(mode)); try checkError(); - return value == GLFW_TRUE; + return value == c.GLFW_TRUE; } /// Set an input option. pub fn setInputMode(self: Self, mode: InputMode, flag: bool) Error!void { - const value = if (flag) GLFW_TRUE else GLFW_FALSE; - glfwSetInputMode(self.pimpl, @enumToInt(mode), value); + const value = if (flag) c.GLFW_TRUE else c.GLFW_FALSE; + c.glfwSetInputMode(self.pimpl, @enumToInt(mode), value); try checkError(); } const CursorMode = enum(c_int) { - normal = GLFW_CURSOR_NORMAL, - hidden = GLFW_CURSOR_HIDDEN, - disabled = GLFW_CURSOR_DISABLED, + normal = c.GLFW_CURSOR_NORMAL, + hidden = c.GLFW_CURSOR_HIDDEN, + disabled = c.GLFW_CURSOR_DISABLED, }; /// Return the cursor mode. pub fn getCursorMode(self: Self) Error!CursorMode { - const value = glfwGetInputMode(self.pimpl, GLFW_CURSOR); + const value = c.glfwGetInputMode(self.pimpl, c.GLFW_CURSOR); try checkError(); return @intToEnum(CursorMode, value); } /// Set the cursor mode. pub fn setCursorMode(self: Self, value: CursorMode) Error!void { - glfwSetInputMode(self.pimpl, GLFW_CURSOR, @enumToInt(value)); + c.glfwSetInputMode(self.pimpl, c.GLFW_CURSOR, @enumToInt(value)); try checkError(); } @@ -295,31 +297,31 @@ const Pos = struct { /// Retrieve the position of the cursor relative to the window's content area. pub fn getCursorPos(self: Self) Error!Pos { var pos: Pos = undefined; - glfwGetCursorPos(self.pimpl, &pos.x, &pos.y); + c.glfwGetCursorPos(self.pimpl, &pos.x, &pos.y); try checkError(); return pos; } /// Set the position of the cursor, relative to the window's content area. pub fn setCursorPos(self: Self, xpos: f64, ypos: f64) Error!void { - glfwSetCursorPos(self.pimpl, xpos, ypos); + c.glfwSetCursorPos(self.pimpl, xpos, ypos); try checkError(); } /// Set the cursor position callback. pub fn setCursorPosCallback(self: Self, comptime fun: CursorPosFun) Error!void { - _ = glfwSetCursorPosCallback(self.pimpl, fnCast(GLFWcursorposfun, fun)); + _ = c.glfwSetCursorPosCallback(self.pimpl, fnCast(c.GLFWcursorposfun, fun)); try checkError(); } const State = enum(c_int) { - press = GLFW_PRESS, - release = GLFW_RELEASE, + press = c.GLFW_PRESS, + release = c.GLFW_RELEASE, }; /// Return the last reported state of a mouse button. pub fn getMouseButton(self: Self, button: MouseButton) Error!State { - const state = glfwGetMouseButton(self.pimpl, @enumToInt(button)); + const state = c.glfwGetMouseButton(self.pimpl, @enumToInt(button)); try checkError(); return @intToEnum(State, state); } @@ -327,31 +329,33 @@ pub fn getMouseButton(self: Self, button: MouseButton) Error!State { /// Set the mouse button callback. pub fn setMouseButtonCallback(self: Self, comptime fun: MouseButtonFun) Error!void { - _ = glfwSetMouseButtonCallback(self.pimpl, fnCast(GLFWmousebuttonfun, fun)); + _ = c.glfwSetMouseButtonCallback(self.pimpl, + fnCast(c.GLFWmousebuttonfun, fun)); try checkError(); } /// Return the last reported state of a keyboard key. pub fn getKey(self: Self, key: Key) Error!State { - const state = glfwGetKey(self.pimpl, @enumToInt(key)); + const state = c.glfwGetKey(self.pimpl, @enumToInt(key)); try checkError(); return @intToEnum(State, state); } /// Set the key callback. pub fn setKeyCallback(self: Self, comptime fun: KeyFun) Error!void { - _ = glfwSetKeyCallback(self.pimpl, fnCast(GLFWkeyfun, fun)); + _ = c.glfwSetKeyCallback(self.pimpl, fnCast(c.GLFWkeyfun, fun)); try checkError(); } /// Set the size of the content area. pub fn setSize(self: Self, width: c_int, height: c_int) Error!void { - glfwSetWindowSize(self.pimpl, width, height); + c.glfwSetWindowSize(self.pimpl, width, height); try checkError(); } /// Set the size callback. pub fn setSizeCallback(self: Self, comptime fun: SizeFun) Error!void { - _ = glfwSetWindowSizeCallback(self.pimpl, fnCast(GLFWwindowsizefun, fun)); + _ = c.glfwSetWindowSizeCallback(self.pimpl, + fnCast(c.GLFWwindowsizefun, fun)); try checkError(); } diff --git a/src/gfz.zig b/src/gfz.zig index 83c89aa..56d60f0 100644 --- a/src/gfz.zig +++ b/src/gfz.zig @@ -16,7 +16,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with gfz. If not, see <https://www.gnu.org/licenses/>. -usingnamespace @import("cimport.zig"); +const c = @import("cimport.zig"); const input = @import("input.zig"); pub const Error = error { @@ -46,18 +46,18 @@ pub const Error = error { /// Return and clear the error code of the last error /// that occurred on the calling thread if any. pub fn checkError() Error!void { - return switch (glfwGetError(null)) { - GLFW_NO_ERROR => {}, - GLFW_NOT_INITIALIZED => Error.NotInitialized, - GLFW_NO_CURRENT_CONTEXT => Error.NoCurrentContext, - GLFW_INVALID_ENUM => Error.InvalidEnum, - GLFW_INVALID_VALUE => Error.InvalidValue, - GLFW_OUT_OF_MEMORY => Error.OutOfMemory, - GLFW_API_UNAVAILABLE => Error.ApiUnavailable, - GLFW_VERSION_UNAVAILABLE => Error.VersionUnavailable, - GLFW_PLATFORM_ERROR => Error.PlatformError, - GLFW_FORMAT_UNAVAILABLE => Error.FormatUnavailable, - GLFW_NO_WINDOW_CONTEXT => Error.NoWindowContext, + return switch (c.glfwGetError(null)) { + c.GLFW_NO_ERROR => {}, + c.GLFW_NOT_INITIALIZED => Error.NotInitialized, + c.GLFW_NO_CURRENT_CONTEXT => Error.NoCurrentContext, + c.GLFW_INVALID_ENUM => Error.InvalidEnum, + c.GLFW_INVALID_VALUE => Error.InvalidValue, + c.GLFW_OUT_OF_MEMORY => Error.OutOfMemory, + c.GLFW_API_UNAVAILABLE => Error.ApiUnavailable, + c.GLFW_VERSION_UNAVAILABLE => Error.VersionUnavailable, + c.GLFW_PLATFORM_ERROR => Error.PlatformError, + c.GLFW_FORMAT_UNAVAILABLE => Error.FormatUnavailable, + c.GLFW_NO_WINDOW_CONTEXT => Error.NoWindowContext, else => unreachable, }; } @@ -79,7 +79,7 @@ pub fn getError() Error { /// Additional calls to this function after successful initialization /// but before termination will return immediately. pub fn init() Error!void { - if (glfwInit() != GLFW_TRUE) + if (c.glfwInit() != c.GLFW_TRUE) return getError(); } @@ -95,39 +95,39 @@ pub fn init() Error!void { /// /// This function has no effect if GLFW is not initialized. pub fn deinit() Error!void { - glfwTerminate(); + c.glfwTerminate(); try checkError(); } /// Set the swap interval for the current context. pub fn swapInterval(interval: c_int) Error!void { - glfwSwapInterval(interval); + c.glfwSwapInterval(interval); try checkError(); } /// Process all pending events. pub fn pollEvents() Error!void { - glfwPollEvents(); + c.glfwPollEvents(); try checkError(); } /// Return the GLFW time, in seconds. pub fn getTime() Error!f64 { - const time = glfwGetTime(); + const time = c.glfwGetTime(); return if (time == 0) getError() else time; } /// Set the GLFW time, in seconds. pub fn setTime(time: f64) Error!void { - glfwSetTime(time); + c.glfwSetTime(time); try checkError(); } /// Return whether raw mouse motion is supported. pub fn rawMouseMotionSupported() Error!bool { - const result = glfwRawMouseMotionSupported(); + const result = c.glfwRawMouseMotionSupported(); try checkError(); - return result == GLFW_TRUE; + return result == c.GLFW_TRUE; } pub const Window = @import("Window.zig"); diff --git a/src/input.zig b/src/input.zig index 97ad9b3..873265f 100644 --- a/src/input.zig +++ b/src/input.zig @@ -19,7 +19,7 @@ const Int = std.meta.Int; const EnumField = std.builtin.TypeInfo.EnumField; const endian = @import("builtin").target.cpu.arch.endian(); -const glfw = @import("cimport.zig"); +const c = @import("cimport.zig"); const std = @import("std"); const keys = [_][]const u8{ @@ -54,7 +54,7 @@ pub const Key = @Type(.{ for (keys) |name, i| fields[i] = .{ .name = name, - .value = @field(glfw, "GLFW_KEY_" ++ name), + .value = @field(c, "GLFW_KEY_" ++ name), }; break :blk fields[0..]; }, @@ -104,35 +104,33 @@ pub const Mods = packed struct { } }; -usingnamespace glfw; - /// Key action: https://www.glfw.org/docs/latest/input_guide.html#input_key // TODO: move inside Key: https://github.com/ziglang/zig/issues/6709 pub const KeyAction = enum(c_int) { - press = GLFW_PRESS, - release = GLFW_RELEASE, - repeat = GLFW_REPEAT, + press = c.GLFW_PRESS, + release = c.GLFW_RELEASE, + repeat = c.GLFW_REPEAT, }; /// Mouse buttons: https://www.glfw.org/docs/latest/group__buttons.html pub const MouseButton = enum(c_int) { - @"1" = GLFW_MOUSE_BUTTON_1, - @"2" = GLFW_MOUSE_BUTTON_2, - @"3" = GLFW_MOUSE_BUTTON_3, - @"4" = GLFW_MOUSE_BUTTON_4, - @"5" = GLFW_MOUSE_BUTTON_5, - @"6" = GLFW_MOUSE_BUTTON_6, - @"7" = GLFW_MOUSE_BUTTON_7, - @"8" = GLFW_MOUSE_BUTTON_8, + @"1" = c.GLFW_MOUSE_BUTTON_1, + @"2" = c.GLFW_MOUSE_BUTTON_2, + @"3" = c.GLFW_MOUSE_BUTTON_3, + @"4" = c.GLFW_MOUSE_BUTTON_4, + @"5" = c.GLFW_MOUSE_BUTTON_5, + @"6" = c.GLFW_MOUSE_BUTTON_6, + @"7" = c.GLFW_MOUSE_BUTTON_7, + @"8" = c.GLFW_MOUSE_BUTTON_8, - pub const left = @intToEnum(MouseButton, GLFW_MOUSE_BUTTON_LEFT); - pub const right = @intToEnum(MouseButton, GLFW_MOUSE_BUTTON_RIGHT); - pub const middle = @intToEnum(MouseButton, GLFW_MOUSE_BUTTON_MIDDLE); + pub const left = @intToEnum(MouseButton, c.GLFW_MOUSE_BUTTON_LEFT); + pub const right = @intToEnum(MouseButton, c.GLFW_MOUSE_BUTTON_RIGHT); + pub const middle = @intToEnum(MouseButton, c.GLFW_MOUSE_BUTTON_MIDDLE); /// Mouse button input action: /// https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button pub const Action = enum(c_int) { - press = GLFW_PRESS, - release = GLFW_RELEASE, + press = c.GLFW_PRESS, + release = c.GLFW_RELEASE, }; }; |