fix cursor visibility in OSX
This commit is contained in:
@@ -45,6 +45,14 @@ std::mutex task_mutex;
|
||||
{
|
||||
[[NSApplication sharedApplication] terminate:nil];
|
||||
}
|
||||
- (void)show_cursor:(bool)visible
|
||||
{
|
||||
if (cursor_visible == visible)
|
||||
return;
|
||||
cursor_visible = visible;
|
||||
if (cursor_inside)
|
||||
visible ? [NSCursor unhide] : [NSCursor hide];
|
||||
}
|
||||
- (std::string)pick_file:(NSArray<NSString*>*)types
|
||||
{
|
||||
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
||||
@@ -107,6 +115,8 @@ std::mutex task_mutex;
|
||||
airdrop_service = [NSSharingService sharingServiceNamed:NSSharingServiceNameSendViaAirDrop];
|
||||
airdrop_service.delegate = self;
|
||||
gl_ready = false;
|
||||
cursor_visible = CGCursorIsVisible();
|
||||
cursor_inside = false;
|
||||
NSOpenGLPixelFormatAttribute attrs[] =
|
||||
{
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
@@ -125,7 +135,7 @@ std::mutex task_mutex;
|
||||
[self setPixelFormat:pf];
|
||||
[self setOpenGLContext:context];
|
||||
|
||||
self->trackingArea = [[NSTrackingArea alloc] initWithRect:frameRect
|
||||
trackingArea = [[NSTrackingArea alloc] initWithRect:frameRect
|
||||
options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow )
|
||||
owner:self userInfo:nil];
|
||||
[self addTrackingArea:trackingArea];
|
||||
@@ -268,9 +278,9 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
}
|
||||
- (void)updateTrackingAreas
|
||||
{
|
||||
if(self->trackingArea != nil)
|
||||
[self removeTrackingArea:self->trackingArea];
|
||||
self->trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
||||
if(trackingArea != nil)
|
||||
[self removeTrackingArea:trackingArea];
|
||||
trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
||||
options: (NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow)
|
||||
owner:self userInfo:nil];
|
||||
[self addTrackingArea:trackingArea];
|
||||
@@ -389,14 +399,15 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
}
|
||||
-(void)mouseExited:(NSEvent *)event
|
||||
{
|
||||
self->cursor_visible = CGCursorIsVisible();
|
||||
if (!self->cursor_visible)
|
||||
if (!cursor_visible)
|
||||
[NSCursor unhide];
|
||||
cursor_inside = false;
|
||||
}
|
||||
-(void)mouseEntered:(NSEvent *)event
|
||||
{
|
||||
if (!self->cursor_visible)
|
||||
if (!cursor_visible)
|
||||
[NSCursor hide];
|
||||
cursor_inside = true;
|
||||
}
|
||||
- (void)scrollWheel:(NSEvent *)theEvent
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
_CGLContextObject* cgl;
|
||||
bool gl_ready;
|
||||
bool cursor_visible;
|
||||
bool cursor_inside;
|
||||
NSTrackingArea* trackingArea;
|
||||
@public NSString* file2open;
|
||||
}
|
||||
@@ -29,4 +30,5 @@
|
||||
- (std::string)pick_dir;
|
||||
- (void)share_file:(NSString*)file_path;
|
||||
- (void)hockeyapp_crash;
|
||||
- (void)show_cursor:(bool)visible;
|
||||
@end
|
||||
|
||||
@@ -43,8 +43,7 @@ void App::show_cursor()
|
||||
#ifdef _WIN32
|
||||
win32_show_cursor(true);
|
||||
#elif __OSX__
|
||||
if (!CGCursorIsVisible())
|
||||
[NSCursor unhide];
|
||||
[osx_view show_cursor:true];
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -53,8 +52,7 @@ void App::hide_cursor()
|
||||
#ifdef _WIN32
|
||||
win32_show_cursor(false);
|
||||
#elif __OSX__
|
||||
if (CGCursorIsVisible())
|
||||
[NSCursor hide];
|
||||
[osx_view show_cursor:false];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -115,9 +115,12 @@ std::wstring BinaryStreamReader::rwstring(size_t len)
|
||||
// std::swap(ptr[i * 2], ptr[i * 2 + 1]);
|
||||
|
||||
// right trim trailing zeroes
|
||||
if (len > 0)
|
||||
{
|
||||
auto wptr = (uint16_t*)ptr;
|
||||
for (int i = len - 1; i >= 0; i--)
|
||||
for (size_t i = len - 1; i >= 0 && len > 0; i--)
|
||||
if (wptr[i] == 0) len--;
|
||||
}
|
||||
|
||||
// wide to UTF-16le
|
||||
std::wstring_convert<std::codecvt_utf16<wchar_t, 0x10ffff>> converter;
|
||||
@@ -257,7 +260,7 @@ void BinaryStreamWriter::wdbl(double v)
|
||||
|
||||
void BinaryStreamWriter::wstring(std::string s)
|
||||
{
|
||||
wu32(s.size());
|
||||
wu32((int)s.size());
|
||||
write(s.data(), s.size());
|
||||
}
|
||||
|
||||
@@ -268,7 +271,7 @@ void BinaryStreamWriter::wstring_raw(std::string s)
|
||||
|
||||
void BinaryStreamWriter::wwstring(std::wstring s)
|
||||
{
|
||||
wu32(s.size());
|
||||
wu32((int)s.size());
|
||||
std::wstring_convert<std::codecvt_utf16<wchar_t, 0x10ffff>> converter;
|
||||
wstring_raw(converter.to_bytes(s));
|
||||
}
|
||||
@@ -287,13 +290,13 @@ void BinaryStreamWriter::wpascal(std::string s)
|
||||
|
||||
void BinaryStreamWriter::wraw(std::vector<uint8_t> raw)
|
||||
{
|
||||
wu32(raw.size());
|
||||
wu32((int)raw.size());
|
||||
write(raw.data(), raw.size());
|
||||
}
|
||||
|
||||
void BinaryStreamWriter::wrle(std::vector<uint8_t> data)
|
||||
{
|
||||
int idx = 0;
|
||||
size_t idx = 0;
|
||||
auto ptr = data.data();
|
||||
|
||||
// find the next sequence and return the position
|
||||
|
||||
@@ -104,11 +104,13 @@ kEventResult Node::on_event(Event* e)
|
||||
MouseEvent e2 = *me;
|
||||
e2.m_type = kEventType::MouseUnfocus;
|
||||
child_mouse_focus->handle_event(&e2);
|
||||
child_mouse_focus->m_mouse_focus = false;
|
||||
}
|
||||
MouseEvent e2 = *me;
|
||||
e2.m_type = kEventType::MouseFocus;
|
||||
current_mouse_capture->handle_event(&e2);
|
||||
child_mouse_focus = current_mouse_capture;
|
||||
child_mouse_focus->m_mouse_focus = true;
|
||||
}
|
||||
return current_mouse_capture->on_event(e);
|
||||
}
|
||||
@@ -140,11 +142,13 @@ kEventResult Node::on_event(Event* e)
|
||||
MouseEvent e2 = *me;
|
||||
e2.m_type = kEventType::MouseUnfocus;
|
||||
child_mouse_focus->handle_event(&e2);
|
||||
child_mouse_focus->m_mouse_focus = false;
|
||||
}
|
||||
MouseEvent e2 = *me;
|
||||
e2.m_type = kEventType::MouseFocus;
|
||||
(*it)->handle_event(&e2);
|
||||
child_mouse_focus = it->get();
|
||||
child_mouse_focus->m_mouse_focus = true;
|
||||
}
|
||||
ret = kEventResult::Consumed;
|
||||
break;
|
||||
|
||||
@@ -110,6 +110,7 @@ public:
|
||||
|
||||
glm::mat4 m_proj;
|
||||
glm::mat4 m_mvp;
|
||||
bool m_mouse_focus = false;
|
||||
bool m_mouse_inside = false;
|
||||
bool m_flood_events = false;
|
||||
bool m_force_mouse_capture = false;
|
||||
|
||||
@@ -466,8 +466,9 @@ kEventResult NodeCanvas::handle_event(Event* e)
|
||||
App::I.show_cursor();
|
||||
break;
|
||||
case kEventType::MouseFocus:
|
||||
m_canvas->m_current_mode == kCanvasMode::Draw ||
|
||||
m_canvas->m_current_mode == kCanvasMode::Erase ?
|
||||
(m_canvas->m_current_mode == kCanvasMode::Draw ||
|
||||
m_canvas->m_current_mode == kCanvasMode::Erase) &&
|
||||
!App::I.keys[(int)kKey::KeyAlt] ?
|
||||
App::I.hide_cursor() : App::I.show_cursor();
|
||||
break;
|
||||
case kEventType::KeyDown:
|
||||
@@ -476,11 +477,11 @@ kEventResult NodeCanvas::handle_event(Event* e)
|
||||
if (ke->m_key == kKey::AndroidBack)
|
||||
if (!ActionManager::empty())
|
||||
ActionManager::undo();
|
||||
if (ke->m_key == kKey::KeyAlt)
|
||||
if (ke->m_key == kKey::KeyAlt && m_mouse_focus)
|
||||
App::I.show_cursor();
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
if (ke->m_key == kKey::KeyAlt)
|
||||
if (ke->m_key == kKey::KeyAlt && m_mouse_focus)
|
||||
m_canvas->m_current_mode == kCanvasMode::Draw ||
|
||||
m_canvas->m_current_mode == kCanvasMode::Erase ?
|
||||
App::I.hide_cursor() : App::I.show_cursor();
|
||||
|
||||
Reference in New Issue
Block a user