Skip to content

Commit 0a56752

Browse files
committed
Add shortcut (default ESC) to cancel transform.
Pressing the `spatial_editor/cancel_transform` shortcut key during a transform operation will cancel the transform and reset the objects back to their original transforms. This functionality was already accessible by pressing RMB during a transform, however: - ESC is more familiar to blender users, and a more common "cancel" key in general. - Given you must hold LMB during a transform, pressing RMB as well is clumsy if not impossible (on a laptop trackpad). See godotengine/godot-proposals#1215.
1 parent 4bb6738 commit 0a56752

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

editor/plugins/spatial_editor_plugin.cpp

+26-19
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,27 @@ int SpatialEditorViewport::get_selected_count() const {
399399
return count;
400400
}
401401

402+
void SpatialEditorViewport::cancel_transform() {
403+
_edit.mode = TRANSFORM_NONE;
404+
405+
List<Node *> &selection = editor_selection->get_selected_node_list();
406+
407+
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
408+
409+
Spatial *sp = Object::cast_to<Spatial>(E->get());
410+
if (!sp)
411+
continue;
412+
413+
SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
414+
if (!se)
415+
continue;
416+
417+
sp->set_global_transform(se->original);
418+
}
419+
surface->update();
420+
set_message(TTR("Transform Aborted."), 3);
421+
}
422+
402423
float SpatialEditorViewport::get_znear() const {
403424

404425
return CLAMP(spatial_editor->get_znear(), MIN_Z, MAX_Z);
@@ -1143,25 +1164,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
11431164
}
11441165

11451166
if (_edit.mode != TRANSFORM_NONE && b->is_pressed()) {
1146-
//cancel motion
1147-
_edit.mode = TRANSFORM_NONE;
1148-
1149-
List<Node *> &selection = editor_selection->get_selected_node_list();
1150-
1151-
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
1152-
1153-
Spatial *sp = Object::cast_to<Spatial>(E->get());
1154-
if (!sp)
1155-
continue;
1156-
1157-
SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
1158-
if (!se)
1159-
continue;
1160-
1161-
sp->set_global_transform(se->original);
1162-
}
1163-
surface->update();
1164-
set_message(TTR("Transform Aborted."), 3);
1167+
cancel_transform();
11651168
}
11661169

11671170
if (b->is_pressed()) {
@@ -2084,6 +2087,9 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
20842087

20852088
set_message(TTR("Animation Key Inserted."));
20862089
}
2090+
if (ED_IS_SHORTCUT("spatial_editor/cancel_transform", p_event) && _edit.mode != TRANSFORM_NONE) {
2091+
cancel_transform();
2092+
}
20872093

20882094
// Freelook doesn't work in orthogonal mode.
20892095
if (!orthogonal && ED_IS_SHORTCUT("spatial_editor/freelook_toggle", p_event)) {
@@ -3967,6 +3973,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
39673973
ED_SHORTCUT("spatial_editor/lock_transform_yz", TTR("Lock Transformation to YZ plane"), KEY_MASK_SHIFT | KEY_X);
39683974
ED_SHORTCUT("spatial_editor/lock_transform_xz", TTR("Lock Transformation to XZ plane"), KEY_MASK_SHIFT | KEY_Y);
39693975
ED_SHORTCUT("spatial_editor/lock_transform_xy", TTR("Lock Transformation to XY plane"), KEY_MASK_SHIFT | KEY_Z);
3976+
ED_SHORTCUT("spatial_editor/cancel_transform", TTR("Cancel Transformation"), KEY_ESCAPE);
39703977

39713978
preview_camera = memnew(CheckBox);
39723979
preview_camera->set_text(TTR("Preview"));

editor/plugins/spatial_editor_plugin.h

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ class SpatialEditorViewport : public Control {
296296
Point2 _point_to_screen(const Vector3 &p_point);
297297
Transform _get_camera_transform() const;
298298
int get_selected_count() const;
299+
void cancel_transform();
299300

300301
Vector3 _get_camera_position() const;
301302
Vector3 _get_camera_normal() const;

0 commit comments

Comments
 (0)