Merge pull request #9415 from Filoppi/patch-8

Fix cursor going to +infinite if the window size was 0
This commit is contained in:
LC 2021-01-03 11:26:11 -05:00 committed by GitHub
commit 4b9259d691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -126,9 +126,9 @@ void KeyboardMouse::UpdateCursorInput()
RECT rect;
GetClientRect(m_hwnd, &rect);
// Width and height are the size of the rendering window.
const auto win_width = rect.right - rect.left;
const auto win_height = rect.bottom - rect.top;
// Width and height are the size of the rendering window. They could be 0
const auto win_width = std::max(rect.right - rect.left, 1l);
const auto win_height = std::max(rect.bottom - rect.top, 1l);
const auto window_scale = g_controller_interface.GetWindowInputScale();

View File

@ -188,8 +188,8 @@ void KeyboardAndMouse::UpdateInput()
loc.x -= bounds.origin.x;
loc.y -= bounds.origin.y;
m_cursor.x = (loc.x / bounds.size.width * 2 - 1.0) * window_scale.x;
m_cursor.y = (loc.y / bounds.size.height * 2 - 1.0) * window_scale.y;
m_cursor.x = (loc.x / std::max(bounds.size.width, 1.0) * 2 - 1.0) * window_scale.x;
m_cursor.y = (loc.y / std::max(bounds.size.height, 1.0) * 2 - 1.0) * window_scale.y;
}
std::string KeyboardAndMouse::GetName() const

View File

@ -227,8 +227,8 @@ void KeyboardMouse::UpdateCursor()
const auto window_scale = g_controller_interface.GetWindowInputScale();
// the mouse position as a range from -1 to 1
m_state.cursor.x = (win_x / win_attribs.width * 2 - 1) * window_scale.x;
m_state.cursor.y = (win_y / win_attribs.height * 2 - 1) * window_scale.y;
m_state.cursor.x = (win_x / std::max(win_attribs.width, 1) * 2 - 1) * window_scale.x;
m_state.cursor.y = (win_y / std::max(win_attribs.height, 1) * 2 - 1) * window_scale.y;
}
void KeyboardMouse::UpdateInput()