summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/Window.zig64
-rw-r--r--src/gfz.zig12
2 files changed, 71 insertions, 5 deletions
diff --git a/src/Window.zig b/src/Window.zig
index 4f22fa9..506225a 100644
--- a/src/Window.zig
+++ b/src/Window.zig
@@ -166,9 +166,19 @@ pub fn create(width: c_int, height: c_int, title: [:0]const u8,
         getError();
 }
 
+/// Return the window whose context is current on the calling thread.
+pub fn getCurrent() Error!?Window {
+    const result = if (glfwGetCurrentContext()) |pimpl|
+        Window{ .pimpl = pimpl }
+    else
+        null;
+    try checkError();
+    return result;
+}
+
 /// Make the context current for the calling thread.
-pub fn makeCurrent(self: Window) Error!void {
-    glfwMakeContextCurrent(self.pimpl);
+pub fn makeCurrent(self: ?Window) Error!void {
+    glfwMakeContextCurrent(if (self) |window| window.pimpl else null);
     try checkError();
 }
 
@@ -231,10 +241,42 @@ pub fn setCursorMode(self: Window, value: CursorMode) Error!void {
     try checkError();
 }
 
-/// Set the size callback.
-pub fn setSizeCallback(self: Window, callback: GLFWwindowsizefun) Error!void {
-    _ = glfwSetWindowSizeCallback(self.pimpl, callback);
+const Pos = struct {
+    x: f64,
+    y: f64,
+};
+
+/// Retrieve the position of the cursor relative to the window's content area.
+pub fn getCursorPos(self: Window) Error!Pos {
+    var pos: Pos = undefined;
+    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: Window, xpos: f64, ypos: f64) Error!void {
+    glfwSetCursorPos(self.pimpl, xpos, ypos);
+    try checkError();
+}
+
+const State = enum(c_int) {
+    press = GLFW_PRESS,
+    release = GLFW_RELEASE,
+};
+
+/// Return the last reported state of a mouse button.
+pub fn getMouseButton(self: Window, button: c_int) Error!State {
+    const state = glfwGetMouseButton(self.pimpl, button);
+    try checkError();
+    return @intToEnum(State, state);
+}
+
+/// Return the last reported state of a keyboard key.
+pub fn getKey(self: Window, key: c_int) Error!State {
+    const state = glfwGetKey(self.pimpl, key);
     try checkError();
+    return @intToEnum(State, state);
 }
 
 /// Set the key callback.
@@ -242,3 +284,15 @@ pub fn setKeyCallback(self: Window, callback: GLFWkeyfun) Error!void {
     _ = glfwSetKeyCallback(self.pimpl, callback);
     try checkError();
 }
+
+/// Set the size of the content area.
+pub fn setSize(self: Window, width: c_int, height: c_int) Error!void {
+    glfwSetWindowSize(self.pimpl, width, height);
+    try checkError();
+}
+
+/// Set the size callback.
+pub fn setSizeCallback(self: Window, callback: GLFWwindowsizefun) Error!void {
+    _ = glfwSetWindowSizeCallback(self.pimpl, callback);
+    try checkError();
+}
diff --git a/src/gfz.zig b/src/gfz.zig
index d96f197..2374ae6 100644
--- a/src/gfz.zig
+++ b/src/gfz.zig
@@ -110,6 +110,18 @@ pub fn pollEvents() Error!void {
     try checkError();
 }
 
+/// Return the GLFW time, in seconds.
+pub fn getTime() Error!f64 {
+    const time = glfwGetTime();
+    return if (time == 0) getError() else time;
+}
+
+/// Set the GLFW time, in seconds.
+pub fn setTime(time: f64) Error!void {
+    glfwSetTime(time);
+    try checkError();
+}
+
 /// Return whether raw mouse motion is supported.
 pub fn rawMouseMotionSupported() Error!bool {
     const result = glfwRawMouseMotionSupported();