Browse Source

Merge pull request #105715 from Arnklit/animation-player-scale-from-cursor-fix

Fix scaling from cursor in AnimationPlayer
Rémi Verschelde 1 month ago
parent
commit
88c47c663d
2 changed files with 9 additions and 7 deletions
  1. 8 6
      editor/animation_track_editor.cpp
  2. 1 1
      editor/animation_track_editor.h

+ 8 - 6
editor/animation_track_editor.cpp

@@ -6681,7 +6681,6 @@ void AnimationTrackEditor::goto_next_step(bool p_from_mouse_event, bool p_timeli
 }
 }
 
 
 void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
 void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
-	last_menu_track_opt = p_option;
 	switch (p_option) {
 	switch (p_option) {
 		case EDIT_COPY_TRACKS: {
 		case EDIT_COPY_TRACKS: {
 			track_copy_select->clear();
 			track_copy_select->clear();
@@ -6841,11 +6840,15 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
 
 
 			undo_redo->commit_action();
 			undo_redo->commit_action();
 		} break;
 		} break;
-
-		case EDIT_SCALE_SELECTION:
+		case EDIT_SCALE_SELECTION: {
+			scale_dialog->popup_centered(Size2(200, 100) * EDSCALE);
+			scale->get_line_edit()->grab_focus();
+			scale_from_cursor = false;
+		} break;
 		case EDIT_SCALE_FROM_CURSOR: {
 		case EDIT_SCALE_FROM_CURSOR: {
 			scale_dialog->popup_centered(Size2(200, 100) * EDSCALE);
 			scale_dialog->popup_centered(Size2(200, 100) * EDSCALE);
 			scale->get_line_edit()->grab_focus();
 			scale->get_line_edit()->grab_focus();
+			scale_from_cursor = true;
 		} break;
 		} break;
 		case EDIT_SCALE_CONFIRM: {
 		case EDIT_SCALE_CONFIRM: {
 			if (selection.is_empty()) {
 			if (selection.is_empty()) {
@@ -6868,9 +6871,8 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
 			}
 			}
 
 
 			len = to_t - from_t;
 			len = to_t - from_t;
-			if (last_menu_track_opt == EDIT_SCALE_FROM_CURSOR) {
+			if (scale_from_cursor) {
 				pivot = timeline->get_play_position();
 				pivot = timeline->get_play_position();
-
 			} else {
 			} else {
 				pivot = from_t;
 				pivot = from_t;
 			}
 			}
@@ -6912,7 +6914,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
 				to_restore.push_back(amr);
 				to_restore.push_back(amr);
 			}
 			}
 
 
-#define NEW_POS(m_ofs) (((s > 0) ? m_ofs : from_t + (len - (m_ofs - from_t))) - pivot) * Math::abs(s) + from_t
+#define NEW_POS(m_ofs) (((s > 0) ? m_ofs : from_t + (len - (m_ofs - from_t))) - pivot) * Math::abs(s) + pivot
 			// 3 - Move the keys (re insert them).
 			// 3 - Move the keys (re insert them).
 			for (RBMap<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
 			for (RBMap<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
 				float newpos = NEW_POS(E->get().pos);
 				float newpos = NEW_POS(E->get().pos);

+ 1 - 1
editor/animation_track_editor.h

@@ -802,7 +802,7 @@ class AnimationTrackEditor : public VBoxContainer {
 
 
 	void _edit_menu_about_to_popup();
 	void _edit_menu_about_to_popup();
 	void _edit_menu_pressed(int p_option);
 	void _edit_menu_pressed(int p_option);
-	int last_menu_track_opt = 0;
+	bool scale_from_cursor = false;
 
 
 	void _cleanup_animation(Ref<Animation> p_animation);
 	void _cleanup_animation(Ref<Animation> p_animation);