summaryrefslogtreecommitdiff
path: root/editor/animation_track_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/animation_track_editor.cpp')
-rw-r--r--editor/animation_track_editor.cpp112
1 files changed, 69 insertions, 43 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index f4e719f552..973f74d6cc 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -32,12 +32,12 @@
#include "animation_track_editor_plugins.h"
#include "core/input/input.h"
-#include "core/os/keyboard.h"
#include "editor/animation_bezier_editor.h"
#include "editor/plugins/animation_player_editor_plugin.h"
#include "editor_node.h"
#include "editor_scale.h"
#include "scene/animation/animation_player.h"
+#include "scene/gui/view_panner.h"
#include "scene/main/window.h"
#include "scene/scene_string_names.h"
#include "servers/audio/audio_stream.h"
@@ -1458,6 +1458,10 @@ int AnimationTimelineEdit::get_name_limit() const {
}
void AnimationTimelineEdit::_notification(int p_what) {
+ if (p_what == NOTIFICATION_ENTER_TREE || p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
+ panner->set_control_scheme((ViewPanner::ControlScheme)EDITOR_GET("interface/editors/animation_editors_panning_scheme").operator int());
+ }
+
if (p_what == NOTIFICATION_ENTER_TREE) {
add_track->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
loop->set_icon(get_theme_icon(SNAME("Loop"), SNAME("EditorIcons")));
@@ -1760,17 +1764,12 @@ void AnimationTimelineEdit::_play_position_draw() {
void AnimationTimelineEdit::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
- const Ref<InputEventMouseButton> mb = p_event;
-
- if (mb.is_valid() && mb->is_pressed() && mb->is_command_pressed() && mb->get_button_index() == MouseButton::WHEEL_UP) {
- get_zoom()->set_value(get_zoom()->get_value() * 1.05);
+ if (panner->gui_input(p_event)) {
accept_event();
+ return;
}
- if (mb.is_valid() && mb->is_pressed() && mb->is_command_pressed() && mb->get_button_index() == MouseButton::WHEEL_DOWN) {
- get_zoom()->set_value(get_zoom()->get_value() / 1.05);
- accept_event();
- }
+ const Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->is_alt_pressed() && mb->get_button_index() == MouseButton::WHEEL_UP) {
if (track_edit) {
@@ -1796,29 +1795,19 @@ void AnimationTimelineEdit::gui_input(const Ref<InputEvent> &p_event) {
dragging_hsize = false;
}
if (mb.is_valid() && mb->get_position().x > get_name_limit() && mb->get_position().x < (get_size().width - get_buttons_width())) {
- if (!panning_timeline && mb->get_button_index() == MouseButton::LEFT) {
+ if (!panner->is_panning() && mb->get_button_index() == MouseButton::LEFT) {
int x = mb->get_position().x - get_name_limit();
float ofs = x / get_zoom_scale() + get_value();
emit_signal(SNAME("timeline_changed"), ofs, false, Input::get_singleton()->is_key_pressed(Key::ALT));
dragging_timeline = true;
}
- if (!dragging_timeline && mb->get_button_index() == MouseButton::MIDDLE) {
- int x = mb->get_position().x - get_name_limit();
- panning_timeline_from = x / get_zoom_scale();
- panning_timeline = true;
- panning_timeline_at = get_value();
- }
}
if (dragging_timeline && mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && !mb->is_pressed()) {
dragging_timeline = false;
}
- if (panning_timeline && mb.is_valid() && mb->get_button_index() == MouseButton::MIDDLE && !mb->is_pressed()) {
- panning_timeline = false;
- }
-
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
@@ -1839,17 +1828,29 @@ void AnimationTimelineEdit::gui_input(const Ref<InputEvent> &p_event) {
if (dragging_timeline) {
int x = mm->get_position().x - get_name_limit();
float ofs = x / get_zoom_scale() + get_value();
- emit_signal(SNAME("timeline_changed"), ofs, false, Input::get_singleton()->is_key_pressed(Key::ALT));
- }
- if (panning_timeline) {
- int x = mm->get_position().x - get_name_limit();
- float ofs = x / get_zoom_scale();
- float diff = ofs - panning_timeline_from;
- set_value(panning_timeline_at - diff);
+ emit_signal(SNAME("timeline_changed"), ofs, false, mm->is_alt_pressed());
}
}
}
+void AnimationTimelineEdit::_scroll_callback(Vector2 p_scroll_vec) {
+ // Timeline has no vertical scroll, so we change it to horizontal.
+ p_scroll_vec.x += p_scroll_vec.y;
+ _pan_callback(-p_scroll_vec * 32);
+}
+
+void AnimationTimelineEdit::_pan_callback(Vector2 p_scroll_vec) {
+ set_value(get_value() - p_scroll_vec.x / get_zoom_scale());
+}
+
+void AnimationTimelineEdit::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin) {
+ if (p_scroll_vec.y < 0) {
+ get_zoom()->set_value(get_zoom()->get_value() * 1.05);
+ } else {
+ get_zoom()->set_value(get_zoom()->get_value() / 1.05);
+ }
+}
+
void AnimationTimelineEdit::set_use_fps(bool p_use_fps) {
use_fps = p_use_fps;
update_values();
@@ -1926,10 +1927,14 @@ AnimationTimelineEdit::AnimationTimelineEdit() {
add_track->get_popup()->connect("index_pressed", callable_mp(this, &AnimationTimelineEdit::_track_added));
len_hb->hide();
- panning_timeline = false;
dragging_timeline = false;
dragging_hsize = false;
+ panner.instantiate();
+ panner->set_callbacks(callable_mp(this, &AnimationTimelineEdit::_scroll_callback), callable_mp(this, &AnimationTimelineEdit::_pan_callback), callable_mp(this, &AnimationTimelineEdit::_zoom_callback));
+ panner->set_disable_rmb(true);
+ panner->set_control_scheme(ViewPanner::SCROLL_PANS);
+
set_layout_direction(Control::LAYOUT_DIRECTION_LTR);
}
@@ -3370,7 +3375,13 @@ Node *AnimationTrackEditor::get_root() const {
}
void AnimationTrackEditor::update_keying() {
- bool keying_enabled = is_visible_in_tree() && animation.is_valid();
+ bool keying_enabled = false;
+
+ EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
+ if (is_visible_in_tree() && animation.is_valid() && editor_history->get_path_size() > 0) {
+ Object *obj = ObjectDB::get_instance(editor_history->get_path_object(0));
+ keying_enabled = Object::cast_to<Node>(obj) != nullptr;
+ }
if (keying_enabled == keying) {
return;
@@ -4500,6 +4511,10 @@ MenuButton *AnimationTrackEditor::get_edit_menu() {
}
void AnimationTrackEditor::_notification(int p_what) {
+ if (p_what == NOTIFICATION_ENTER_TREE || p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
+ panner->set_control_scheme((ViewPanner::ControlScheme)EDITOR_GET("interface/editors/animation_editors_panning_scheme").operator int());
+ }
+
if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) {
zoom_icon->set_texture(get_theme_icon(SNAME("Zoom"), SNAME("EditorIcons")));
snap->set_icon(get_theme_icon(SNAME("Snap"), SNAME("EditorIcons")));
@@ -4516,8 +4531,6 @@ void AnimationTrackEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
update_keying();
- EditorNode::get_singleton()->update_keying();
- emit_signal(SNAME("keying_changed"));
}
}
@@ -5212,17 +5225,12 @@ void AnimationTrackEditor::_box_selection_draw() {
}
void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) {
- Ref<InputEventMouseButton> mb = p_event;
-
- if (mb.is_valid() && mb->is_pressed() && mb->is_command_pressed() && mb->get_button_index() == MouseButton::WHEEL_UP) {
- timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05);
+ if (panner->gui_input(p_event)) {
scroll->accept_event();
+ return;
}
- if (mb.is_valid() && mb->is_pressed() && mb->is_command_pressed() && mb->get_button_index() == MouseButton::WHEEL_DOWN) {
- timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05);
- scroll->accept_event();
- }
+ Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->is_alt_pressed() && mb->get_button_index() == MouseButton::WHEEL_UP) {
goto_prev_step(true);
@@ -5262,10 +5270,6 @@ void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_MIDDLE) != MouseButton::NONE) {
- timeline->set_value(timeline->get_value() - mm->get_relative().x / timeline->get_zoom_scale());
- }
-
if (mm.is_valid() && box_selecting) {
if ((mm->get_button_mask() & MouseButton::MASK_LEFT) == MouseButton::NONE) {
// No longer.
@@ -5302,6 +5306,23 @@ void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) {
}
}
+void AnimationTrackEditor::_scroll_callback(Vector2 p_scroll_vec) {
+ _pan_callback(-p_scroll_vec * 32);
+}
+
+void AnimationTrackEditor::_pan_callback(Vector2 p_scroll_vec) {
+ timeline->set_value(timeline->get_value() - p_scroll_vec.x / timeline->get_zoom_scale());
+ scroll->set_v_scroll(scroll->get_v_scroll() - p_scroll_vec.y);
+}
+
+void AnimationTrackEditor::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin) {
+ if (p_scroll_vec.y < 0) {
+ timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05);
+ } else {
+ timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05);
+ }
+}
+
void AnimationTrackEditor::_cancel_bezier_edit() {
bezier_edit->hide();
scroll->show();
@@ -6088,6 +6109,11 @@ AnimationTrackEditor::AnimationTrackEditor() {
timeline->connect("value_changed", callable_mp(this, &AnimationTrackEditor::_timeline_value_changed));
timeline->connect("length_changed", callable_mp(this, &AnimationTrackEditor::_update_length));
+ panner.instantiate();
+ panner->set_callbacks(callable_mp(this, &AnimationTrackEditor::_scroll_callback), callable_mp(this, &AnimationTrackEditor::_pan_callback), callable_mp(this, &AnimationTrackEditor::_zoom_callback));
+ panner->set_disable_rmb(true);
+ panner->set_control_scheme(ViewPanner::SCROLL_PANS);
+
scroll = memnew(ScrollContainer);
timeline_vbox->add_child(scroll);
scroll->set_v_size_flags(SIZE_EXPAND_FILL);