aboutsummaryrefslogtreecommitdiff
path: root/src/sfml/window/mouse.zig
diff options
context:
space:
mode:
authortslil clingman <>2021-09-01 12:59:50 -0400
committertslil clingman <>2021-09-01 12:59:50 -0400
commit6a2d132873ce7b40405a3dc000a12539fffd969b (patch)
tree3b730360b348900fbc937bd44b89c293c39ca00c /src/sfml/window/mouse.zig
Init
Diffstat (limited to 'src/sfml/window/mouse.zig')
-rw-r--r--src/sfml/window/mouse.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/sfml/window/mouse.zig b/src/sfml/window/mouse.zig
new file mode 100644
index 0000000..c788324
--- /dev/null
+++ b/src/sfml/window/mouse.zig
@@ -0,0 +1,26 @@
+//! Give access to the real-time state of the mouse.
+
+const sf = @import("../sfml.zig");
+
+/// Mouse buttons
+pub const Button = enum(c_uint) { Left, Right, Middle, XButton1, XButton2 };
+/// Mouse wheels
+pub const Wheel = enum(c_uint) { Vertical, Horizontal };
+
+/// Returns true if the specified mouse button is pressed
+pub fn isButtonPressed(button: Button) bool {
+ return sf.c.sfMouse_isButtonPressed(@intToEnum(sf.c.sfMouseButton, @enumToInt(button))) == 1;
+}
+
+/// Gets the position of the mouse cursor relative to the window passed or desktop
+pub fn getPosition(window: ?sf.graphics.RenderWindow) sf.system.Vector2i {
+ if (window) |w| {
+ return sf.system.Vector2i.fromCSFML(sf.c.sfMouse_getPosition(@ptrCast(*sf.c.sfWindow, w.ptr)));
+ } else return sf.system.Vector2i.fromCSFML(sf.c.sfMouse_getPosition(null));
+}
+/// Set the position of the mouse cursor relative to the window passed or desktop
+pub fn setPosition(position: sf.system.Vector2i, window: ?sf.graphics.RenderWindow) void {
+ if (window) |w| {
+ sf.c.sfMouse_setPosition(position.toCSFML(), @ptrCast(*sf.c.sfWindow, w.ptr));
+ } else sf.c.sfMouse_setPosition(position.toCSFML(), null);
+}