summaryrefslogtreecommitdiff
path: root/editor/animation_bezier_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/animation_bezier_editor.cpp')
-rw-r--r--editor/animation_bezier_editor.cpp92
1 files changed, 48 insertions, 44 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index 9682fb07d2..3678642521 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,6 +32,7 @@
#include "editor/editor_node.h"
#include "editor_scale.h"
+#include "scene/gui/view_panner.h"
#include "scene/resources/text_line.h"
float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) {
@@ -216,6 +217,9 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V
}
void AnimationBezierTrackEdit::_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) {
close_button->set_icon(get_theme_icon(SNAME("Close"), SNAME("EditorIcons")));
@@ -610,6 +614,11 @@ void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int
void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
+ if (panner->gui_input(p_event)) {
+ accept_event();
+ return;
+ }
+
if (p_event->is_pressed()) {
if (ED_GET_SHORTCUT("animation_editor/duplicate_selection")->matches_event(p_event)) {
duplicate_selection();
@@ -623,40 +632,24 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
}
Ref<InputEventMouseButton> mb = p_event;
- if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::WHEEL_DOWN) {
- const float v_zoom_orig = v_zoom;
- if (mb->is_command_pressed()) {
- timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05);
- } else {
+ if (mb.is_valid() && mb->is_pressed() && mb->is_alt_pressed()) {
+ // Alternate zoom (doesn't affect timeline).
+ if (mb->get_button_index() == MouseButton::WHEEL_DOWN) {
+ const float v_zoom_orig = v_zoom;
if (v_zoom < 100000) {
v_zoom *= 1.2;
}
+ v_scroll = v_scroll + (mb->get_position().y - get_size().y / 2) * (v_zoom - v_zoom_orig);
+ update();
}
- v_scroll = v_scroll + (mb->get_position().y - get_size().y / 2) * (v_zoom - v_zoom_orig);
- update();
- }
- if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::WHEEL_UP) {
- const float v_zoom_orig = v_zoom;
- if (mb->is_command_pressed()) {
- timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05);
- } else {
+ if (mb->get_button_index() == MouseButton::WHEEL_UP) {
+ const float v_zoom_orig = v_zoom;
if (v_zoom > 0.000001) {
v_zoom /= 1.2;
}
- }
- v_scroll = v_scroll + (mb->get_position().y - get_size().y / 2) * (v_zoom - v_zoom_orig);
- update();
- }
-
- if (mb.is_valid() && mb->get_button_index() == MouseButton::MIDDLE) {
- if (mb->is_pressed()) {
- int x = mb->get_position().x - timeline->get_name_limit();
- panning_timeline_from = x / timeline->get_zoom_scale();
- panning_timeline = true;
- panning_timeline_at = timeline->get_value();
- } else {
- panning_timeline = false;
+ v_scroll = v_scroll + (mb->get_position().y - get_size().y / 2) * (v_zoom - v_zoom_orig);
+ update();
}
}
@@ -934,22 +927,6 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
}
Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && (mm->get_button_mask() & MouseButton::MASK_MIDDLE) != MouseButton::NONE) {
- v_scroll += mm->get_relative().y * v_zoom;
- if (v_scroll > 100000) {
- v_scroll = 100000;
- }
- if (v_scroll < -100000) {
- v_scroll = -100000;
- }
-
- int x = mm->get_position().x - timeline->get_name_limit();
- float ofs = x / timeline->get_zoom_scale();
- float diff = ofs - panning_timeline_from;
- timeline->set_value(panning_timeline_at - diff);
-
- update();
- }
if (moving_selection_attempt && mm.is_valid()) {
if (!moving_selection) {
moving_selection = true;
@@ -1038,6 +1015,28 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
}
}
+void AnimationBezierTrackEdit::_scroll_callback(Vector2 p_scroll_vec) {
+ _pan_callback(-p_scroll_vec * 32);
+}
+
+void AnimationBezierTrackEdit::_pan_callback(Vector2 p_scroll_vec) {
+ v_scroll += p_scroll_vec.y * v_zoom;
+ v_scroll = CLAMP(v_scroll, -100000, 100000);
+ timeline->set_value(timeline->get_value() - p_scroll_vec.x / timeline->get_zoom_scale());
+ update();
+}
+
+void AnimationBezierTrackEdit::_zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin) {
+ const float v_zoom_orig = v_zoom;
+ 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);
+ }
+ v_scroll = v_scroll + (p_origin.y - get_size().y / 2) * (v_zoom - v_zoom_orig);
+ update();
+}
+
void AnimationBezierTrackEdit::_menu_selected(int p_index) {
switch (p_index) {
case MENU_KEY_INSERT: {
@@ -1171,6 +1170,11 @@ void AnimationBezierTrackEdit::_bind_methods() {
}
AnimationBezierTrackEdit::AnimationBezierTrackEdit() {
+ panner.instantiate();
+ panner->set_callbacks(callable_mp(this, &AnimationBezierTrackEdit::_scroll_callback), callable_mp(this, &AnimationBezierTrackEdit::_pan_callback), callable_mp(this, &AnimationBezierTrackEdit::_zoom_callback));
+ panner->set_disable_rmb(true);
+ panner->set_control_scheme(ViewPanner::SCROLL_PANS);
+
play_position = memnew(Control);
play_position->set_mouse_filter(MOUSE_FILTER_PASS);
add_child(play_position);