Fix issues with camera movement with controller when mouse tracking is also enabled (#3409)

Fixes #3408
This commit is contained in:
Tyler Wilding
2024-03-07 23:35:38 -05:00
committed by GitHub
parent a80f4e7cca
commit 0626862a8c
4 changed files with 18 additions and 2 deletions
+10 -2
View File
@@ -39,11 +39,13 @@ void MouseDevice::poll_state(std::shared_ptr<PadData> data) {
int curr_mouse_relx;
int curr_mouse_rely;
const auto mouse_state_rel = SDL_GetRelativeMouseState(&curr_mouse_relx, &curr_mouse_rely);
if (m_last_xcoord == curr_mouse_x && curr_mouse_relx == 0) {
if (m_mouse_moved_x && m_last_xcoord == curr_mouse_x && curr_mouse_relx == 0) {
data->analog_data.at(2) = 127;
m_mouse_moved_x = false;
}
if (m_last_ycoord == curr_mouse_y && curr_mouse_rely == 0) {
if (m_mouse_moved_y && m_last_ycoord == curr_mouse_y && curr_mouse_rely == 0) {
data->analog_data.at(3) = 127;
m_mouse_moved_y = false;
}
m_last_xcoord = curr_mouse_x;
m_last_ycoord = curr_mouse_y;
@@ -139,9 +141,15 @@ void MouseDevice::process_event(const SDL_Event& event,
if (m_control_camera) {
const auto xrel_amount = float(event.motion.xrel);
const auto xadjust = std::clamp(127 + int(xrel_amount * m_xsens), 0, 255);
if (xadjust > 0) {
m_mouse_moved_x = true;
}
data->analog_data.at(2) = xadjust;
const auto yrel_amount = float(event.motion.yrel);
const auto yadjust = std::clamp(127 + int(yrel_amount * m_ysens), 0, 255);
if (yadjust > 0) {
m_mouse_moved_y = true;
}
data->analog_data.at(3) = yadjust;
}
} else if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) {
+2
View File
@@ -59,6 +59,8 @@ class MouseDevice : public InputDevice {
// Tracking motion
int m_last_xcoord = 0;
int m_last_ycoord = 0;
bool m_mouse_moved_x = false;
bool m_mouse_moved_y = false;
int m_frame_counter = 0;
bool is_action_already_active(const u32 sdl_keycode, const bool player_movement);
+5
View File
@@ -202,6 +202,7 @@ void DisplayManager::set_window_display_mode(WindowDisplayMode mode) {
case WindowDisplayMode::Windowed:
result = SDL_SetWindowFullscreen(m_window, 0);
if (result == 0) {
lg::info("windowed mode - resizing window to {}x{}", m_window_width, m_window_height);
SDL_SetWindowSize(m_window, m_window_width, m_window_height);
} else {
sdl_util::log_error("unable to change window to windowed mode");
@@ -219,6 +220,8 @@ void DisplayManager::set_window_display_mode(WindowDisplayMode mode) {
m_selected_fullscreen_display_id));
} else {
// 2. move it to the right monitor
lg::info("preparing fullscreen - moving window to {},{} on display id {}",
display_bounds.x + 50, display_bounds.y + 50, m_selected_fullscreen_display_id);
SDL_SetWindowPosition(m_window, display_bounds.x + 50, display_bounds.y + 50);
if (mode == WindowDisplayMode::Fullscreen) {
update_video_modes();
@@ -227,6 +230,8 @@ void DisplayManager::set_window_display_mode(WindowDisplayMode mode) {
// Some people are weird and don't use the monitor's maximum supported resolution
// in which case, we use what the user actually has selected.
const auto& display_res = m_current_display_modes.at(m_selected_fullscreen_display_id);
lg::info("preparing fullscreen - setting window resolution to {}x{}",
display_res.screen_width, display_res.screen_height);
set_window_size(display_res.screen_width, display_res.screen_height);
}
// 3. fullscreen it!
@@ -194,6 +194,7 @@ This gives us more freedom to write code how we want.
:get-value-fn (lambda () (-> *pc-settings* mouse-enabled?))
:on-confirm (lambda ((val symbol))
(set! (-> *pc-settings* mouse-enabled?) val)
(update-mouse-controls! *pc-settings*)
(pc-settings-save)))
(progress-new-generic-link-to-scrolling-page (text-id progress-menu-mouse-options) :should-disable? (lambda () (not (-> *pc-settings* mouse-enabled?)))
(new 'static 'menu-generic-boolean-option