From 4fa8a129e6ecfa168604568673cfbdaa2c8e34b0 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Sun, 9 Feb 2020 14:31:57 +0100 Subject: Renamed minilibx --- minilibx/mlx_mouse.m | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 minilibx/mlx_mouse.m (limited to 'minilibx/mlx_mouse.m') diff --git a/minilibx/mlx_mouse.m b/minilibx/mlx_mouse.m new file mode 100644 index 0000000..94ce0a9 --- /dev/null +++ b/minilibx/mlx_mouse.m @@ -0,0 +1,52 @@ +#include + +#import +#import + +#include "mlx_int.h" +#include "mlx_new_window.h" + +int mlx_mouse_hide() +{ + // CGDisplayHideCursor(kCGDirectMainDisplay); + [NSCursor hide]; + return (0); +} + +int mlx_mouse_show() +{ + // CGDisplayShowCursor(kCGDirectMainDisplay); + [NSCursor unhide]; + return (0); +} + +int mlx_mouse_move(mlx_win_list_t *win, int x, int y) +{ + CGPoint point; + NSRect pos; + id thewin; + + thewin = [(id)(win->winid) win]; + pos = [thewin frame]; + // printf("got win pos %f %f\n", pos.origin.x, pos.origin.y); + point.x = pos.origin.x + x; + point.y = NSHeight([[thewin screen] frame]) - NSHeight([(id)(win->winid) frame]) - pos.origin.y + 1 + y; + CGWarpMouseCursorPosition(point); + CGAssociateMouseAndMouseCursorPosition(true); + return (0); +} + + +int mlx_mouse_get_pos(mlx_win_list_t *win, int *x, int *y) +{ + CGPoint point; + id thewin; + NSRect pos; + + thewin = [(id)(win->winid) win]; + pos = [(id)(win->winid) frame]; + point = [thewin mouseLocationOutsideOfEventStream]; + *x = point.x; + *y = NSHeight(pos) - 1 - point.y; + return (0); +} -- cgit v1.2.3