Skip to content

Commit 88cd7ab

Browse files
committed
Merge pull request #105791 from ryevdokimov/cancel-navigation
Add the ability to cancel pan/zoom/orbit navigation
2 parents 01af009 + 05c9155 commit 88cd7ab

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

editor/scene/3d/node_3d_editor_plugin.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ void ViewportRotationControl::_process_drag(Ref<InputEventWithModifiers> p_event
464464
if (Input::get_singleton()->get_mouse_mode() == Input::MouseMode::MOUSE_MODE_VISIBLE) {
465465
Input::get_singleton()->set_mouse_mode(Input::MouseMode::MOUSE_MODE_CAPTURED);
466466
orbiting_mouse_start = p_position;
467-
viewport->previous_cursor = viewport->view_3d_controller->cursor;
467+
saved_cursor = viewport->view_3d_controller->cursor;
468468
}
469469
viewport->view_3d_controller->cursor_orbit(p_event, p_relative_position);
470470
focused_axis = -1;
@@ -483,7 +483,7 @@ void ViewportRotationControl::gui_input(const Ref<InputEvent> &p_event) {
483483
if (Input::get_singleton()->get_mouse_mode() == Input::MouseMode::MOUSE_MODE_CAPTURED) {
484484
Input::get_singleton()->set_mouse_mode(Input::MouseMode::MOUSE_MODE_VISIBLE);
485485
Input::get_singleton()->warp_mouse(orbiting_mouse_start);
486-
viewport->view_3d_controller->cursor = viewport->previous_cursor;
486+
viewport->view_3d_controller->cursor = saved_cursor;
487487
gizmo_activated = false;
488488
}
489489
}
@@ -502,7 +502,7 @@ void ViewportRotationControl::gui_input(const Ref<InputEvent> &p_event) {
502502
if (Input::get_singleton()->get_mouse_mode() == Input::MouseMode::MOUSE_MODE_CAPTURED) {
503503
Input::get_singleton()->set_mouse_mode(Input::MouseMode::MOUSE_MODE_VISIBLE);
504504
Input::get_singleton()->warp_mouse(orbiting_mouse_start);
505-
viewport->view_3d_controller->cursor = viewport->previous_cursor;
505+
viewport->view_3d_controller->cursor = saved_cursor;
506506
gizmo_activated = false;
507507
}
508508
}
@@ -1740,7 +1740,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
17401740
}
17411741

17421742
// Several parts of the 3D navigation are handled here.
1743+
bool was_navigating = view_3d_controller->is_navigating();
17431744
view_3d_controller->gui_input(p_event, surface->get_global_rect());
1745+
if (was_navigating && !view_3d_controller->is_navigating()) {
1746+
return;
1747+
}
17441748

17451749
Ref<InputEventMouseButton> b = p_event;
17461750

editor/scene/3d/node_3d_editor_plugin.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ViewportRotationControl : public Control {
8989
Vector<int> axis_menu_options;
9090
Vector2i orbiting_mouse_start;
9191
Point2 original_mouse_pos;
92+
View3DController::Cursor saved_cursor;
9293
int orbiting_index = -1;
9394
int focused_axis = -2;
9495
bool gizmo_activated = false;
@@ -368,8 +369,6 @@ class Node3DEditorViewport : public Control {
368369
void _freelook_changed();
369370
void _freelook_speed_scaled();
370371

371-
View3DController::Cursor previous_cursor; // Storing previous cursor state for canceling purposes.
372-
373372
real_t zoom_indicator_delay;
374373
int zoom_failed_attempts_count = 0;
375374

scene/debugger/runtime_node_select.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,12 +1424,6 @@ void RuntimeNodeSelect::_cursor_interpolated() {
14241424
}
14251425

14261426
bool RuntimeNodeSelect::_handle_3d_input(const Ref<InputEvent> &p_event) {
1427-
Ref<InputEventMouseButton> b = p_event;
1428-
if (b.is_valid() && b->get_button_index() == MouseButton::RIGHT) {
1429-
view_3d_controller->set_freelook_enabled(b->is_pressed());
1430-
return true;
1431-
}
1432-
14331427
Window *root = SceneTree::get_singleton()->get_root();
14341428
ERR_FAIL_COND_V(!root->is_camera_3d_override_enabled(), true);
14351429

@@ -1451,6 +1445,12 @@ bool RuntimeNodeSelect::_handle_3d_input(const Ref<InputEvent> &p_event) {
14511445
return true;
14521446
}
14531447

1448+
Ref<InputEventMouseButton> b = p_event;
1449+
if (b.is_valid() && b->get_button_index() == MouseButton::RIGHT) {
1450+
view_3d_controller->set_freelook_enabled(b->is_pressed());
1451+
return true;
1452+
}
1453+
14541454
Ref<InputEventKey> k = p_event;
14551455
if (k.is_valid() && k->get_physical_keycode() == Key::ESCAPE) {
14561456
view_3d_controller->set_freelook_enabled(false);

scene/debugger/view_3d_controller.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ View3DController::NavigationMode View3DController::_get_nav_mode_from_shortcuts(
120120
bool View3DController::gui_input(const Ref<InputEvent> &p_event, const Rect2 &p_surface_rect) {
121121
Ref<InputEventMouseButton> b = p_event;
122122
if (b.is_valid()) {
123+
if (b->get_button_index() == MouseButton::RIGHT && b->is_pressed() && navigating) {
124+
cancel_navigation();
125+
return true;
126+
}
127+
123128
const real_t zoom_factor = 1 + (ZOOM_FREELOOK_MULTIPLIER - 1) * b->get_factor();
124129
switch (b->get_button_index()) {
125130
case MouseButton::WHEEL_UP: {
@@ -168,6 +173,18 @@ bool View3DController::gui_input(const Ref<InputEvent> &p_event, const Rect2 &p_
168173

169174
Ref<InputEventMouseMotion> m = p_event;
170175
if (m.is_valid()) {
176+
if (m->get_button_mask() == MouseButtonMask::NONE) {
177+
navigation_cancelled = false;
178+
}
179+
180+
if (navigation_cancelled) {
181+
return false;
182+
}
183+
184+
if (!navigating) {
185+
previous_cursor = cursor;
186+
}
187+
171188
NavigationMode nav_mode = NAV_MODE_NONE;
172189

173190
if (m->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
@@ -229,10 +246,14 @@ bool View3DController::gui_input(const Ref<InputEvent> &p_event, const Rect2 &p_
229246
} break;
230247

231248
default: {
249+
navigating = false;
232250
return false;
233251
}
234252
}
235253

254+
if (!freelook) {
255+
navigating = true;
256+
}
236257
return true;
237258
}
238259

@@ -283,6 +304,12 @@ bool View3DController::gui_input(const Ref<InputEvent> &p_event, const Rect2 &p_
283304
return true;
284305
}
285306

307+
Ref<InputEventKey> k = p_event;
308+
if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == Key::ESCAPE && navigating) {
309+
cancel_navigation();
310+
return true;
311+
}
312+
286313
bool pressed = false;
287314
float old_fov_scale = cursor.fov_scale;
288315

@@ -306,6 +333,12 @@ bool View3DController::gui_input(const Ref<InputEvent> &p_event, const Rect2 &p_
306333
return pressed;
307334
}
308335

336+
void View3DController::cancel_navigation() {
337+
navigating = false;
338+
navigation_cancelled = true;
339+
cursor = previous_cursor;
340+
}
341+
309342
void View3DController::cursor_pan(const Ref<InputEventWithModifiers> &p_event, const Vector2 &p_relative) {
310343
float pan_speed = translation_sensitivity / 150.0;
311344
if (p_event.is_valid() && navigation_scheme == NAV_SCHEME_MAYA && p_event->is_shift_pressed()) {

scene/debugger/view_3d_controller.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ class View3DController : public RefCounted {
171171

172172
private:
173173
Cursor cursor_interp; // That one may be interpolated (don't modify this one except for smoothing purposes).
174+
Cursor previous_cursor; // Storing previous cursor state for canceling purposes.
175+
bool navigating = false;
176+
bool navigation_cancelled = false;
177+
void cancel_navigation();
174178

175179
protected:
176180
static void _bind_methods();
@@ -249,6 +253,7 @@ class View3DController : public RefCounted {
249253

250254
public:
251255
bool gui_input(const Ref<InputEvent> &p_event, const Rect2 &p_surface_rect);
256+
bool is_navigating() const { return navigating; }
252257

253258
void cursor_pan(const Ref<InputEventWithModifiers> &p_event, const Vector2 &p_relative);
254259
void cursor_look(const Ref<InputEventWithModifiers> &p_event, const Vector2 &p_relative);

0 commit comments

Comments
 (0)