do not pass mouse position to imgui when mouse is captured by scene or game view

This commit is contained in:
Mikulas Florek 2021-04-13 21:30:48 +02:00
parent 27361937e9
commit 828c5e57ad
2 changed files with 11 additions and 8 deletions

View file

@ -727,14 +727,16 @@ struct StudioAppImpl final : StudioApp
io.KeyAlt = os::isKeyDown(os::Keycode::MENU);
const os::Point cp = os::getMouseScreenPos();
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
io.MousePos.x = (float)cp.x;
io.MousePos.y = (float)cp.y;
}
else {
const os::Rect screen_rect = os::getWindowScreenRect(m_main_window);
io.MousePos.x = (float)cp.x - screen_rect.left;
io.MousePos.y = (float)cp.y - screen_rect.top;
if (!m_cursor_captured) {
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
io.MousePos.x = (float)cp.x;
io.MousePos.y = (float)cp.y;
}
else {
const os::Rect screen_rect = os::getWindowScreenRect(m_main_window);
io.MousePos.x = (float)cp.x - screen_rect.left;
io.MousePos.y = (float)cp.y - screen_rect.top;
}
}
const ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();

View file

@ -1047,6 +1047,7 @@ void SceneView::captureMouse(bool capture)
{
if(m_is_mouse_captured == capture) return;
m_is_mouse_captured = capture;
m_app.setCursorCaptured(capture);
os::showCursor(!m_is_mouse_captured);
if (capture) {
os::grabMouse(ImGui::GetWindowViewport()->PlatformHandle);