hide cursor on OSX
This commit is contained in:
@@ -124,6 +124,11 @@ std::mutex task_mutex;
|
|||||||
self = [super initWithFrame:frameRect pixelFormat:pf];
|
self = [super initWithFrame:frameRect pixelFormat:pf];
|
||||||
[self setPixelFormat:pf];
|
[self setPixelFormat:pf];
|
||||||
[self setOpenGLContext:context];
|
[self setOpenGLContext:context];
|
||||||
|
|
||||||
|
NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:frameRect
|
||||||
|
options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow )
|
||||||
|
owner:self userInfo:nil];
|
||||||
|
[self addTrackingArea:trackingArea];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
- (void)prepareOpenGL
|
- (void)prepareOpenGL
|
||||||
@@ -374,6 +379,17 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|||||||
App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1, p, kEventSource::Mouse, 0);
|
App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1, p, kEventSource::Mouse, 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
-(void)mouseExited:(NSEvent *)event
|
||||||
|
{
|
||||||
|
self->cursor_visible = CGCursorIsVisible();
|
||||||
|
if (!self->cursor_visible)
|
||||||
|
[NSCursor unhide];
|
||||||
|
}
|
||||||
|
-(void)mouseEntered:(NSEvent *)event
|
||||||
|
{
|
||||||
|
if (!self->cursor_visible)
|
||||||
|
[NSCursor hide];
|
||||||
|
}
|
||||||
- (void)scrollWheel:(NSEvent *)theEvent
|
- (void)scrollWheel:(NSEvent *)theEvent
|
||||||
{
|
{
|
||||||
auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
NSOpenGLContext* glctx;
|
NSOpenGLContext* glctx;
|
||||||
_CGLContextObject* cgl;
|
_CGLContextObject* cgl;
|
||||||
bool gl_ready;
|
bool gl_ready;
|
||||||
|
bool cursor_visible;
|
||||||
@public NSString* file2open;
|
@public NSString* file2open;
|
||||||
}
|
}
|
||||||
- (void)close;
|
- (void)close;
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ void App::show_cursor()
|
|||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
win32_show_cursor(true);
|
win32_show_cursor(true);
|
||||||
|
#elif __OSX__
|
||||||
|
if (!CGCursorIsVisible())
|
||||||
|
[NSCursor unhide];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +52,9 @@ void App::hide_cursor()
|
|||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
win32_show_cursor(false);
|
win32_show_cursor(false);
|
||||||
|
#elif __OSX__
|
||||||
|
if (CGCursorIsVisible())
|
||||||
|
[NSCursor hide];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user