diff options
Diffstat (limited to 'src/Window.zig')
-rw-r--r-- | src/Window.zig | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/Window.zig b/src/Window.zig index 82ae8c3..5ff2de9 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -19,8 +19,10 @@ 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 checkError = gfz.checkError; const getError = gfz.getError; const gfz = @import("gfz.zig"); @@ -29,9 +31,9 @@ const input = @import("input.zig"); const Self = @This(); const CursorPosFun = fn (window: Self, xpos: f64, ypos: f64) void; const KeyFun = fn (window: Self, key: Key, scancode: c_int, - action: c_int, mods: Mods) void; -const MouseButtonFun = fn (window: Self, button: c_int, - action: c_int, mods: Mods) void; + action: KeyAction, mods: Mods) void; +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; pimpl: *Impl, @@ -49,14 +51,16 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { 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.?).*, - @intToEnum(Key, key), scancode, action, Mods.fromInt(mods)); + @intToEnum(Key, key), scancode, + @intToEnum(KeyAction, action), Mods.fromInt(mods)); } }, GLFWmousebuttonfun => struct { pub fn callback(window: ?*Impl, button: c_int, action: c_int, mods: c_int) callconv(.C) void { fun(@fieldParentPtr(Self, "pimpl", &window.?).*, - button, action, Mods.fromInt(mods)); + @intToEnum(MouseButton, button), + @intToEnum(MouseButton.Action, action), Mods.fromInt(mods)); } }, GLFWwindowsizefun => struct { @@ -243,7 +247,7 @@ pub fn swapBuffers(self: Self) Error!void { try checkError(); } -pub const InputMode = enum(c_int) { +const InputMode = enum(c_int) { sticky_keys = GLFW_STICKY_KEYS, sticky_mouse_buttons = GLFW_STICKY_MOUSE_BUTTONS, lock_key_mods = GLFW_LOCK_KEY_MODS, @@ -264,7 +268,7 @@ pub fn setInputMode(self: Self, mode: InputMode, flag: bool) Error!void { try checkError(); } -pub const CursorMode = enum(c_int) { +const CursorMode = enum(c_int) { normal = GLFW_CURSOR_NORMAL, hidden = GLFW_CURSOR_HIDDEN, disabled = GLFW_CURSOR_DISABLED, @@ -314,8 +318,8 @@ const State = enum(c_int) { }; /// Return the last reported state of a mouse button. -pub fn getMouseButton(self: Self, button: c_int) Error!State { - const state = glfwGetMouseButton(self.pimpl, button); +pub fn getMouseButton(self: Self, button: MouseButton) Error!State { + const state = glfwGetMouseButton(self.pimpl, @enumToInt(button)); try checkError(); return @intToEnum(State, state); } |