From bd47e4f1ba5a0d8623944582eaf9b21a1fa68c3a Mon Sep 17 00:00:00 2001 From: Matt Enad Date: Tue, 8 Oct 2024 13:09:13 -0400 Subject: [PATCH] Add `Tablet/Trackpad` nav preset This commit adds a new navigation preset called `Tablet/Trackpad` which enables "Emulate 3 Button Mouse" to more quickly set up good default keys for tablet users. It also adds support for mouse buttons 4 and 5 in the navigation settings which will be helpful if users want to customize 3D navigation further for specific pens/mice. --- doc/classes/EditorSettings.xml | 5 +++-- editor/editor_settings.cpp | 8 ++++---- editor/editor_settings_dialog.cpp | 25 ++++++++++++++++++++++-- editor/plugins/node_3d_editor_plugin.cpp | 12 ++++++++++++ editor/plugins/node_3d_editor_plugin.h | 11 +++++++---- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 550933ce64..25e2e959f3 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -360,12 +360,13 @@ If [code]true[/code], invert the vertical mouse axis when panning, orbiting, or using freelook mode in the 3D editor. - The navigation scheme preset to use in the 3D editor. Changing this setting will affect the mouse button and modifier controls used to navigate the 3D editor viewport. + The navigation scheme preset to use in the 3D editor. Changing this setting will affect the mouse button and modifier keys used to navigate the 3D editor viewport. All schemes can use [kbd]Mouse wheel[/kbd] to zoom. - [b]Godot:[/b] [kbd]Middle mouse button[/kbd] to orbit. [kbd]Shift + Middle mouse button[/kbd] to pan. [kbd]Ctrl + Middle mouse button[/kbd] to zoom. - [b]Maya:[/b] [kbd]Alt + Left mouse button[/kbd] to orbit. [kbd]Middle mouse button[/kbd] to pan, [kbd]Shift + Middle mouse button[/kbd] to pan 10 times faster. [kbd]Alt + Right mouse button[/kbd] to zoom. - [b]Modo:[/b] [kbd]Alt + Left mouse button[/kbd] to orbit. [kbd]Alt + Shift + Left mouse button[/kbd] to pan. [kbd]Ctrl + Alt + Left mouse button[/kbd] to zoom. - See also [member editors/3d/navigation/orbit_mouse_button], [member editors/3d/navigation/pan_mouse_button], [member editors/3d/navigation/zoom_mouse_button], and [member editors/3d/freelook/freelook_navigation_scheme]. + - [b]Tablet/Trackpad:[/b] [kbd]Alt[/kbd] to orbit. [kbd]Shift[/kbd] to pan. [kbd]Ctrl[/kbd] to zoom. Enables 3-button mouse emulation mode. + See also [member editors/3d/navigation/orbit_mouse_button], [member editors/3d/navigation/pan_mouse_button], [member editors/3d/navigation/zoom_mouse_button], [member editors/3d/freelook/freelook_navigation_scheme], and [member editors/3d/navigation/emulate_3_button_mouse]. [b]Note:[/b] On certain window managers on Linux, the [kbd]Alt[/kbd] key will be intercepted by the window manager when clicking a mouse button at the same time. This means Godot will not see the modifier key as being pressed. diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 153cb74b74..ea0d5804e1 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -816,10 +816,10 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { // 3D: Navigation _initial_set("editors/3d/navigation/invert_x_axis", false, true); _initial_set("editors/3d/navigation/invert_y_axis", false, true); - EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot,Maya,Modo,Custom") - EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse") - EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse") - EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse") + EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/navigation_scheme", 0, "Godot:0,Maya:1,Modo:2,Tablet/Trackpad:4,Custom:3") + EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/orbit_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse,Mouse Button 4,Mouse Button 5") + EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/pan_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse,Mouse Button 4,Mouse Button 5") + EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_mouse_button", 1, "Left Mouse,Middle Mouse,Right Mouse,Mouse Button 4,Mouse Button 5") EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "editors/3d/navigation/zoom_style", 0, "Vertical,Horizontal") _initial_set("editors/3d/navigation/emulate_numpad", false, true); diff --git a/editor/editor_settings_dialog.cpp b/editor/editor_settings_dialog.cpp index 8989b9cf9b..877b18697b 100644 --- a/editor/editor_settings_dialog.cpp +++ b/editor/editor_settings_dialog.cpp @@ -77,7 +77,7 @@ void EditorSettingsDialog::_settings_property_edited(const String &p_name) { EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom"); } else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) { EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom"); - } else if (full_name == "editors/3d/navigation/orbit_mouse_button" || full_name == "editors/3d/navigation/pan_mouse_button" || full_name == "editors/3d/navigation/zoom_mouse_button") { + } else if (full_name == "editors/3d/navigation/orbit_mouse_button" || full_name == "editors/3d/navigation/pan_mouse_button" || full_name == "editors/3d/navigation/zoom_mouse_button" || full_name == "editors/3d/navigation/emulate_3_button_mouse") { EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM); } else if (full_name == "editors/3d/navigation/navigation_scheme") { update_navigation_preset(); @@ -89,6 +89,7 @@ void EditorSettingsDialog::update_navigation_preset() { Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE; Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE; Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE; + bool set_3_button_mouse = false; Ref orbit_mod_key_1; Ref orbit_mod_key_2; Ref pan_mod_key_1; @@ -102,6 +103,7 @@ void EditorSettingsDialog::update_navigation_preset() { set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE; set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE; set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE; + set_3_button_mouse = false; orbit_mod_key_1 = InputEventKey::create_reference(Key::NONE); orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE); pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT); @@ -113,6 +115,7 @@ void EditorSettingsDialog::update_navigation_preset() { set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE; set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE; set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_RIGHT_MOUSE; + set_3_button_mouse = false; orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT); orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE); pan_mod_key_1 = InputEventKey::create_reference(Key::NONE); @@ -124,18 +127,32 @@ void EditorSettingsDialog::update_navigation_preset() { set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE; set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE; set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE; + set_3_button_mouse = false; orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT); orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE); pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT); pan_mod_key_2 = InputEventKey::create_reference(Key::ALT); zoom_mod_key_1 = InputEventKey::create_reference(Key::ALT); zoom_mod_key_2 = InputEventKey::create_reference(Key::CTRL); + } else if (nav_scheme == Node3DEditorViewport::NAVIGATION_TABLET) { + set_preset = true; + set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE; + set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE; + set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_MIDDLE_MOUSE; + set_3_button_mouse = true; + orbit_mod_key_1 = InputEventKey::create_reference(Key::ALT); + orbit_mod_key_2 = InputEventKey::create_reference(Key::NONE); + pan_mod_key_1 = InputEventKey::create_reference(Key::SHIFT); + pan_mod_key_2 = InputEventKey::create_reference(Key::NONE); + zoom_mod_key_1 = InputEventKey::create_reference(Key::CTRL); + zoom_mod_key_2 = InputEventKey::create_reference(Key::NONE); } // Set settings to the desired preset values. if (set_preset) { EditorSettings::get_singleton()->set_manually("editors/3d/navigation/orbit_mouse_button", (int)set_orbit_mouse_button); EditorSettings::get_singleton()->set_manually("editors/3d/navigation/pan_mouse_button", (int)set_pan_mouse_button); EditorSettings::get_singleton()->set_manually("editors/3d/navigation/zoom_mouse_button", (int)set_zoom_mouse_button); + EditorSettings::get_singleton()->set_manually("editors/3d/navigation/emulate_3_button_mouse", set_3_button_mouse); _set_shortcut_input("spatial_editor/viewport_orbit_modifier_1", orbit_mod_key_1); _set_shortcut_input("spatial_editor/viewport_orbit_modifier_2", orbit_mod_key_2); _set_shortcut_input("spatial_editor/viewport_pan_modifier_1", pan_mod_key_1); @@ -775,7 +792,11 @@ PropertyInfo EditorSettingsDialog::_create_mouse_shortcut_property_info(const St hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name); hint_string += "Middle Mouse,"; hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name); - hint_string += "Right Mouse"; + hint_string += "Right Mouse,"; + hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name); + hint_string += "Mouse Button 4,"; + hint_string += _get_shortcut_button_string(p_shortcut_1_name) + _get_shortcut_button_string(p_shortcut_2_name); + hint_string += "Mouse Button 5"; return PropertyInfo(Variant::INT, p_property_name, PROPERTY_HINT_ENUM, hint_string); } diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 5d11cc7bc5..1ac83408b9 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -2125,6 +2125,18 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { nav_mode = change_nav_from_shortcut; } + } else if (m->get_button_mask().has_flag(MouseButtonMask::MB_XBUTTON1)) { + NavigationMode change_nav_from_shortcut = _get_nav_mode_from_shortcut_check(NAVIGATION_MOUSE_4, shortcut_check_sets, false); + if (change_nav_from_shortcut != NAVIGATION_NONE) { + nav_mode = change_nav_from_shortcut; + } + + } else if (m->get_button_mask().has_flag(MouseButtonMask::MB_XBUTTON2)) { + NavigationMode change_nav_from_shortcut = _get_nav_mode_from_shortcut_check(NAVIGATION_MOUSE_5, shortcut_check_sets, false); + if (change_nav_from_shortcut != NAVIGATION_NONE) { + nav_mode = change_nav_from_shortcut; + } + } else if (EDITOR_GET("editors/3d/navigation/emulate_3_button_mouse")) { // Handle trackpad (no external mouse) use case NavigationMode change_nav_from_shortcut = _get_nav_mode_from_shortcut_check(NAVIGATION_LEFT_MOUSE, shortcut_check_sets, true); diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index 243a712c3a..0b5ed554b1 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -190,10 +190,11 @@ public: }; enum NavigationScheme { - NAVIGATION_GODOT, - NAVIGATION_MAYA, - NAVIGATION_MODO, - NAVIGATION_CUSTOM, + NAVIGATION_GODOT = 0, + NAVIGATION_MAYA = 1, + NAVIGATION_MODO = 2, + NAVIGATION_CUSTOM = 3, + NAVIGATION_TABLET = 4, }; enum FreelookNavigationScheme { @@ -206,6 +207,8 @@ public: NAVIGATION_LEFT_MOUSE, NAVIGATION_MIDDLE_MOUSE, NAVIGATION_RIGHT_MOUSE, + NAVIGATION_MOUSE_4, + NAVIGATION_MOUSE_5, }; private: