diff --git a/PanoPainter-OSX/main.cpp b/PanoPainter-OSX/main.cpp index 5765a25..0a05e89 100644 --- a/PanoPainter-OSX/main.cpp +++ b/PanoPainter-OSX/main.cpp @@ -124,6 +124,11 @@ std::mutex task_mutex; self = [super initWithFrame:frameRect pixelFormat:pf]; [self setPixelFormat:pf]; [self setOpenGLContext:context]; + + NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:frameRect + options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow ) + owner:self userInfo:nil]; + [self addTrackingArea:trackingArea]; return self; } - (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); }); } +-(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 { auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; diff --git a/PanoPainter-OSX/main.h b/PanoPainter-OSX/main.h index 5e778a6..a44d03f 100644 --- a/PanoPainter-OSX/main.h +++ b/PanoPainter-OSX/main.h @@ -16,6 +16,7 @@ NSOpenGLContext* glctx; _CGLContextObject* cgl; bool gl_ready; + bool cursor_visible; @public NSString* file2open; } - (void)close; diff --git a/src/app_events.cpp b/src/app_events.cpp index 7c894d7..01c6a18 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -42,6 +42,9 @@ void App::show_cursor() { #ifdef _WIN32 win32_show_cursor(true); +#elif __OSX__ + if (!CGCursorIsVisible()) + [NSCursor unhide]; #endif } @@ -49,6 +52,9 @@ void App::hide_cursor() { #ifdef _WIN32 win32_show_cursor(false); +#elif __OSX__ + if (CGCursorIsVisible()) + [NSCursor hide]; #endif }