From 6a2d132873ce7b40405a3dc000a12539fffd969b Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Wed, 1 Sep 2021 12:59:50 -0400 Subject: Init --- src/sfml/window/mouse.zig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/sfml/window/mouse.zig (limited to 'src/sfml/window/mouse.zig') 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); +} -- cgit v1.3.1