// Window manipulation // Copyright (C) 2021 Nguyễn Gia Phong // // This file is part of gfz. // // gfz is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published // by the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // gfz is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with gfz. If not, see . usingnamespace @import("cimport.zig"); const Error = gfz.Error; const Monitor = @import("Monitor.zig"); const checkError = gfz.checkError; const getError = gfz.getError; const gfz = @import("gfz.zig"); const Window = @This(); pimpl: *GLFWwindow, /// Create a window and its associated context. pub fn create(width: c_int, height: c_int, title: []const u8, monitor: ?Monitor, share: ?Window) Error!Window { const pmonitor = if (monitor) |box| box.pimpl else null; const pshare = if (share) |box| box.pimpl else null; const ptr = glfwCreateWindow(width, height, title.ptr, pmonitor, pshare); return if (ptr) |pimpl| Window{ .pimpl = pimpl } else getError(); } /// Make the context current for the calling thread. pub fn makeCurrent(self: Window) Error!void { glfwMakeContextCurrent(self.pimpl); try checkError(); } /// Check the close flag. pub fn shouldClose(self: Window) Error!bool { const flag = glfwWindowShouldClose(self.pimpl); try checkError(); return flag == GLFW_TRUE; } pub fn swapBuffers(self: Window) Error!void { glfwSwapBuffers(self.pimpl); try checkError(); }