fix cursor visibility in OSX

This commit is contained in:
2019-03-11 18:39:11 +01:00
parent c111495cae
commit 5bef9c7286
7 changed files with 43 additions and 23 deletions

View File

@@ -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
}

View File

@@ -115,10 +115,13 @@ std::wstring BinaryStreamReader::rwstring(size_t len)
// std::swap(ptr[i * 2], ptr[i * 2 + 1]);
// right trim trailing zeroes
auto wptr = (uint16_t*)ptr;
for (int i = len - 1; i >= 0; i--)
if (wptr[i] == 0) len--;
if (len > 0)
{
auto wptr = (uint16_t*)ptr;
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;
return converter.from_bytes(ptr, ptr + len * 2);
@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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();