mlx_mouse.m
 1  #include	<stdio.h>
 2  
 3  #import <Cocoa/Cocoa.h>
 4  #import <OpenGL/gl3.h>
 5  
 6  #include	"mlx_int.h"
 7  #include	"mlx_new_window.h"
 8  
 9  int	mlx_mouse_hide()
10  {
11    //  CGDisplayHideCursor(kCGDirectMainDisplay);
12    [NSCursor hide];
13    return (0);
14  }
15  
16  int	mlx_mouse_show()
17  {
18    //  CGDisplayShowCursor(kCGDirectMainDisplay);
19    [NSCursor unhide];
20    return (0);
21  }
22  
23  int	mlx_mouse_move(mlx_win_list_t *win, int x, int y)
24  {
25    CGPoint	point;
26    NSRect	pos;
27    id	thewin;
28  
29    thewin = [(id)(win->winid) win];
30    pos = [thewin frame];
31    //  printf("got win pos %f %f\n", pos.origin.x, pos.origin.y);
32    point.x = pos.origin.x + x;
33    point.y = NSHeight([[thewin screen] frame]) - NSHeight([(id)(win->winid) frame]) - pos.origin.y + 1 + y;
34    CGWarpMouseCursorPosition(point);
35    CGAssociateMouseAndMouseCursorPosition(true);
36    return (0);
37  }
38  
39  
40  int	mlx_mouse_get_pos(mlx_win_list_t *win, int *x, int *y)
41  {
42    CGPoint	point;
43    id		thewin;
44    NSRect	pos;
45  
46    thewin = [(id)(win->winid) win];
47    pos = [(id)(win->winid) frame];
48    point = [thewin mouseLocationOutsideOfEventStream];
49    *x = point.x;
50    *y = NSHeight(pos) - 1 - point.y;
51    return (0);
52  }