| 
									
										
										
										
											2018-08-29 22:38:13 +02:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  animation_track_editor_plugins.cpp                                   */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                      https://godotengine.org                          */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2018-08-29 22:38:13 +02:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | #include "animation_track_editor_plugins.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-12 21:10:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | #include "editor/audio_stream_preview.h"
 | 
					
						
							|  |  |  | #include "editor_resource_preview.h"
 | 
					
						
							|  |  |  | #include "editor_scale.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | #include "scene/2d/animated_sprite_2d.h"
 | 
					
						
							|  |  |  | #include "scene/2d/sprite_2d.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | #include "scene/3d/sprite_3d.h"
 | 
					
						
							|  |  |  | #include "scene/animation/animation_player.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | #include "scene/resources/text_line.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | #include "servers/audio/audio_stream.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-12 21:10:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | /// BOOL ///
 | 
					
						
							|  |  |  | int AnimationTrackEditBool::get_key_height() const { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Texture2D> checked = get_theme_icon(SNAME("checked"), SNAME("CheckBox")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	return checked->get_height(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | Rect2 AnimationTrackEditBool::get_key_rect(int p_index, float p_pixels_sec) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Texture2D> checked = get_theme_icon(SNAME("checked"), SNAME("CheckBox")); | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 	return Rect2(-checked->get_width() / 2, 0, checked->get_width(), get_size().height); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditBool::is_key_selectable_by_distance() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { | 
					
						
							|  |  |  | 	bool checked = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							| 
									
										
										
										
											2020-03-12 09:37:40 -03:00
										 |  |  | 	Ref<Texture2D> icon = get_theme_icon(checked ? "checked" : "unchecked", "CheckBox"); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 	Vector2 ofs(p_x - icon->get_width() / 2, int(get_size().height - icon->get_height()) / 2); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (ofs.x + icon->get_width() / 2 < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (ofs.x + icon->get_width() / 2 > p_clip_right) { | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 	draw_texture(icon, ofs); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color color = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		draw_rect_clipped(Rect2(ofs, icon->get_size()), color, false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// COLOR ///
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int AnimationTrackEditColor::get_key_height() const { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	return font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | Rect2 AnimationTrackEditColor::get_key_rect(int p_index, float p_pixels_sec) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 	return Rect2(-fh / 2, 0, fh, get_size().height); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditColor::is_key_selectable_by_distance() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	int fh = (font->get_height(font_size) * 0.8); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 	fh /= 3; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 	int x_from = p_x + fh / 2 - 1; | 
					
						
							|  |  |  | 	int x_to = p_next_x - fh / 2 + 1; | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 	x_from = MAX(x_from, p_clip_left); | 
					
						
							|  |  |  | 	x_to = MIN(x_to, p_clip_right); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int y_from = (get_size().height - fh) / 2; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (x_from > p_clip_right || x_to < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 	Vector<Color> color_samples; | 
					
						
							|  |  |  | 	color_samples.append(get_animation()->track_get_key_value(get_track(), p_index)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (get_animation()->track_get_type(get_track()) == Animation::TYPE_VALUE) { | 
					
						
							|  |  |  | 		if (get_animation()->track_get_interpolation_type(get_track()) != Animation::INTERPOLATION_NEAREST && | 
					
						
							|  |  |  | 				(get_animation()->value_track_get_update_mode(get_track()) == Animation::UPDATE_CONTINUOUS || | 
					
						
							|  |  |  | 						get_animation()->value_track_get_update_mode(get_track()) == Animation::UPDATE_CAPTURE) && | 
					
						
							|  |  |  | 				!Math::is_zero_approx(get_animation()->track_get_key_transition(get_track(), p_index))) { | 
					
						
							|  |  |  | 			float start_time = get_animation()->track_get_key_time(get_track(), p_index); | 
					
						
							|  |  |  | 			float end_time = get_animation()->track_get_key_time(get_track(), p_index + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Color color_next = get_animation()->value_track_interpolate(get_track(), end_time); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!color_samples[0].is_equal_approx(color_next)) { | 
					
						
							|  |  |  | 				color_samples.resize(1 + (x_to - x_from) / 64); // Make a color sample every 64 px.
 | 
					
						
							|  |  |  | 				for (int i = 1; i < color_samples.size(); i++) { | 
					
						
							|  |  |  | 					float j = i; | 
					
						
							|  |  |  | 					color_samples.write[i] = get_animation()->value_track_interpolate( | 
					
						
							|  |  |  | 							get_track(), | 
					
						
							|  |  |  | 							Math::lerp(start_time, end_time, j / color_samples.size())); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			color_samples.append(color_next); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			color_samples.append(color_samples[0]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		color_samples.append(get_animation()->track_get_key_value(get_track(), p_index + 1)); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 	for (int i = 0; i < color_samples.size() - 1; i++) { | 
					
						
							|  |  |  | 		Vector<Vector2> points; | 
					
						
							|  |  |  | 		Vector<Color> colors; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 		points.push_back(Vector2(Math::lerp(x_from, x_to, float(i) / (color_samples.size() - 1)), y_from)); | 
					
						
							|  |  |  | 		colors.push_back(color_samples[i]); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 		points.push_back(Vector2(Math::lerp(x_from, x_to, float(i + 1) / (color_samples.size() - 1)), y_from)); | 
					
						
							|  |  |  | 		colors.push_back(color_samples[i + 1]); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 		points.push_back(Vector2(Math::lerp(x_from, x_to, float(i + 1) / (color_samples.size() - 1)), y_from + fh)); | 
					
						
							|  |  |  | 		colors.push_back(color_samples[i + 1]); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 		points.push_back(Vector2(Math::lerp(x_from, x_to, float(i) / (color_samples.size() - 1)), y_from + fh)); | 
					
						
							|  |  |  | 		colors.push_back(color_samples[i]); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 15:23:54 +01:00
										 |  |  | 		draw_primitive(points, colors, Vector<Vector2>()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { | 
					
						
							|  |  |  | 	Color color = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 23:59:18 +02:00
										 |  |  | 	Rect2 rect(Vector2(p_x - fh / 2, int(get_size().height - fh) / 2), Size2(fh, fh)); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	draw_rect_clipped(Rect2(rect.position, rect.size / 2), Color(0.4, 0.4, 0.4)); | 
					
						
							|  |  |  | 	draw_rect_clipped(Rect2(rect.position + rect.size / 2, rect.size / 2), Color(0.4, 0.4, 0.4)); | 
					
						
							|  |  |  | 	draw_rect_clipped(Rect2(rect.position + Vector2(rect.size.x / 2, 0), rect.size / 2), Color(0.6, 0.6, 0.6)); | 
					
						
							|  |  |  | 	draw_rect_clipped(Rect2(rect.position + Vector2(0, rect.size.y / 2), rect.size / 2), Color(0.6, 0.6, 0.6)); | 
					
						
							|  |  |  | 	draw_rect_clipped(rect, color); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		draw_rect_clipped(rect, accent, false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// AUDIO ///
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditAudio::_preview_changed(ObjectID p_which) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!object) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Ref<AudioStream> stream = object->call("get_stream"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (stream.is_valid() && stream->get_instance_id() == p_which) { | 
					
						
							|  |  |  | 		update(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int AnimationTrackEditAudio::get_key_height() const { | 
					
						
							|  |  |  | 	if (!ObjectDB::get_instance(id)) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_height(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	return int(font->get_height(font_size) * 1.5); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<AudioStream> stream = object->call("get_stream"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!stream.is_valid()) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool play = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 	if (play) { | 
					
						
							|  |  |  | 		float len = stream->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (len == 0) { | 
					
						
							|  |  |  | 			Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); | 
					
						
							|  |  |  | 			len = preview->get_length(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 			len = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return Rect2(0, 0, len * p_pixels_sec, get_size().height); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return Rect2(0, 0, fh, get_size().height); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditAudio::is_key_selectable_by_distance() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<AudioStream> stream = object->call("get_stream"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!stream.is_valid()) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool play = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 	if (play) { | 
					
						
							|  |  |  | 		float len = stream->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float preview_len = preview->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (len == 0) { | 
					
						
							|  |  |  | 			len = preview_len; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int pixel_len = len * p_pixels_sec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int pixel_begin = p_x; | 
					
						
							|  |  |  | 		int pixel_end = p_x + pixel_len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (pixel_end < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (pixel_begin > p_clip_right) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		int from_x = MAX(pixel_begin, p_clip_left); | 
					
						
							|  |  |  | 		int to_x = MIN(pixel_end, p_clip_right); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 			float limit = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 			int limit_x = pixel_begin + limit * p_pixels_sec; | 
					
						
							|  |  |  | 			to_x = MIN(limit_x, to_x); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (to_x <= from_x) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		float fh = int(font->get_height(font_size) * 1.5); | 
					
						
							| 
									
										
										
										
											2019-02-12 21:10:08 +01:00
										 |  |  | 		Rect2 rect = Rect2(from_x, (get_size().height - fh) / 2, to_x - from_x, fh); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		draw_rect(rect, Color(0.25, 0.25, 0.25)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Vector2> lines; | 
					
						
							|  |  |  | 		lines.resize((to_x - from_x + 1) * 2); | 
					
						
							|  |  |  | 		preview_len = preview->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = from_x; i < to_x; i++) { | 
					
						
							|  |  |  | 			float ofs = (i - pixel_begin) * preview_len / pixel_len; | 
					
						
							|  |  |  | 			float ofs_n = ((i + 1) - pixel_begin) * preview_len / pixel_len; | 
					
						
							|  |  |  | 			float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5; | 
					
						
							|  |  |  | 			float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			int idx = i - from_x; | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 			lines.write[idx * 2 + 0] = Vector2(i, rect.position.y + min * rect.size.y); | 
					
						
							|  |  |  | 			lines.write[idx * 2 + 1] = Vector2(i, rect.position.y + max * rect.size.y); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Color> color; | 
					
						
							|  |  |  | 		color.push_back(Color(0.75, 0.75, 0.75)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, color); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			draw_rect(rect, accent, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color color = get_theme_color(SNAME("font_color"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		draw_rect(rect, color); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			draw_rect(rect, accent, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditAudio::set_node(Object *p_object) { | 
					
						
							|  |  |  | 	id = p_object->get_instance_id(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditAudio::_bind_methods() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimationTrackEditAudio::AnimationTrackEditAudio() { | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	AudioStreamPreviewGenerator::get_singleton()->connect("preview_updated", callable_mp(this, &AnimationTrackEditAudio::_preview_changed)); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 02:46:50 +02:00
										 |  |  | /// SPRITE FRAME / FRAME_COORDS ///
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | int AnimationTrackEditSpriteFrame::get_key_height() const { | 
					
						
							|  |  |  | 	if (!ObjectDB::get_instance(id)) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_height(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	return int(font->get_height(font_size) * 2); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_sec) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Size2 size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	if (Object::cast_to<Sprite2D>(object) || Object::cast_to<Sprite3D>(object)) { | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 		Ref<Texture2D> texture = object->call("get_texture"); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		if (!texture.is_valid()) { | 
					
						
							|  |  |  | 			return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		size = texture->get_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (bool(object->call("is_region"))) { | 
					
						
							|  |  |  | 			size = Rect2(object->call("get_region_rect")).size; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int hframes = object->call("get_hframes"); | 
					
						
							|  |  |  | 		int vframes = object->call("get_vframes"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (hframes > 1) { | 
					
						
							|  |  |  | 			size.x /= hframes; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (vframes > 1) { | 
					
						
							|  |  |  | 			size.y /= vframes; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	} else if (Object::cast_to<AnimatedSprite2D>(object) || Object::cast_to<AnimatedSprite3D>(object)) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		Ref<SpriteFrames> sf = object->call("get_sprite_frames"); | 
					
						
							|  |  |  | 		if (sf.is_null()) { | 
					
						
							|  |  |  | 			return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-14 17:47:44 -03:00
										 |  |  | 		List<StringName> animations; | 
					
						
							|  |  |  | 		sf->get_animation_list(&animations); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int frame = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 		String animation; | 
					
						
							|  |  |  | 		if (animations.size() == 1) { | 
					
						
							|  |  |  | 			animation = animations.front()->get(); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// Go through other track to find if animation is set
 | 
					
						
							|  |  |  | 			String animation_path = get_animation()->track_get_path(get_track()); | 
					
						
							|  |  |  | 			animation_path = animation_path.replace(":frame", ":animation"); | 
					
						
							| 
									
										
										
										
											2021-10-16 10:04:09 +09:00
										 |  |  | 			int animation_track = get_animation()->find_track(animation_path, get_animation()->track_get_type(get_track())); | 
					
						
							| 
									
										
										
										
											2018-06-14 17:47:44 -03:00
										 |  |  | 			float track_time = get_animation()->track_get_key_time(get_track(), p_index); | 
					
						
							|  |  |  | 			int animaiton_index = get_animation()->track_find_key(animation_track, track_time); | 
					
						
							|  |  |  | 			animation = get_animation()->track_get_key_value(animation_track, animaiton_index); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 		Ref<Texture2D> texture = sf->get_frame(animation, frame); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		if (!texture.is_valid()) { | 
					
						
							|  |  |  | 			return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		size = texture->get_size(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	size = size.floor(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	int height = int(font->get_height(font_size) * 2); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	int width = height * size.width / size.height; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Rect2(0, 0, width, get_size().height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditSpriteFrame::is_key_selectable_by_distance() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	Ref<Texture2D> texture; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	Rect2 region; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	if (Object::cast_to<Sprite2D>(object) || Object::cast_to<Sprite3D>(object)) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		texture = object->call("get_texture"); | 
					
						
							|  |  |  | 		if (!texture.is_valid()) { | 
					
						
							|  |  |  | 			AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 02:46:50 +02:00
										 |  |  | 		int hframes = object->call("get_hframes"); | 
					
						
							|  |  |  | 		int vframes = object->call("get_vframes"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector2 coords; | 
					
						
							|  |  |  | 		if (is_coords) { | 
					
						
							|  |  |  | 			coords = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			int frame = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 			coords.x = frame % hframes; | 
					
						
							|  |  |  | 			coords.y = frame / hframes; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		region.size = texture->get_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (bool(object->call("is_region"))) { | 
					
						
							|  |  |  | 			region = Rect2(object->call("get_region_rect")); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (hframes > 1) { | 
					
						
							|  |  |  | 			region.size.x /= hframes; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (vframes > 1) { | 
					
						
							|  |  |  | 			region.size.y /= vframes; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 02:46:50 +02:00
										 |  |  | 		region.position.x += region.size.x * coords.x; | 
					
						
							|  |  |  | 		region.position.y += region.size.y * coords.y; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	} else if (Object::cast_to<AnimatedSprite2D>(object) || Object::cast_to<AnimatedSprite3D>(object)) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		Ref<SpriteFrames> sf = object->call("get_sprite_frames"); | 
					
						
							|  |  |  | 		if (sf.is_null()) { | 
					
						
							|  |  |  | 			AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-14 17:47:44 -03:00
										 |  |  | 		List<StringName> animations; | 
					
						
							|  |  |  | 		sf->get_animation_list(&animations); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int frame = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 		String animation; | 
					
						
							|  |  |  | 		if (animations.size() == 1) { | 
					
						
							|  |  |  | 			animation = animations.front()->get(); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// Go through other track to find if animation is set
 | 
					
						
							|  |  |  | 			String animation_path = get_animation()->track_get_path(get_track()); | 
					
						
							|  |  |  | 			animation_path = animation_path.replace(":frame", ":animation"); | 
					
						
							| 
									
										
										
										
											2021-10-16 10:04:09 +09:00
										 |  |  | 			int animation_track = get_animation()->find_track(animation_path, get_animation()->track_get_type(get_track())); | 
					
						
							| 
									
										
										
										
											2018-06-14 17:47:44 -03:00
										 |  |  | 			float track_time = get_animation()->track_get_key_time(get_track(), p_index); | 
					
						
							|  |  |  | 			int animaiton_index = get_animation()->track_find_key(animation_track, track_time); | 
					
						
							|  |  |  | 			animation = get_animation()->track_get_key_value(animation_track, animaiton_index); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		texture = sf->get_frame(animation, frame); | 
					
						
							|  |  |  | 		if (!texture.is_valid()) { | 
					
						
							|  |  |  | 			AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		region.size = texture->get_size(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	int height = int(font->get_height(font_size) * 2); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int width = height * region.size.width / region.size.height; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Rect2 rect(p_x, int(get_size().height - height) / 2, width, height); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (rect.position.x + rect.size.x < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (rect.position.x > p_clip_right) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	Color bg = accent; | 
					
						
							|  |  |  | 	bg.a = 0.15; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	draw_rect_clipped(rect, bg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	draw_texture_region_clipped(texture, rect, region); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_selected) { | 
					
						
							|  |  |  | 		draw_rect_clipped(rect, accent, false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditSpriteFrame::set_node(Object *p_object) { | 
					
						
							|  |  |  | 	id = p_object->get_instance_id(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 02:46:50 +02:00
										 |  |  | void AnimationTrackEditSpriteFrame::set_as_coords() { | 
					
						
							|  |  |  | 	is_coords = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | /// SUB ANIMATION ///
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int AnimationTrackEditSubAnim::get_key_height() const { | 
					
						
							|  |  |  | 	if (!ObjectDB::get_instance(id)) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_height(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	return int(font->get_height(font_size) * 1.5); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ap) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String anim = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (anim != "[stop]" && ap->has_animation(anim)) { | 
					
						
							|  |  |  | 		float len = ap->get_animation(anim)->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 			len = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return Rect2(0, 0, len * p_pixels_sec, get_size().height); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return Rect2(0, 0, fh, get_size().height); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditSubAnim::is_key_selectable_by_distance() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ap) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String anim = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (anim != "[stop]" && ap->has_animation(anim)) { | 
					
						
							|  |  |  | 		float len = ap->get_animation(anim)->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 			len = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int pixel_len = len * p_pixels_sec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int pixel_begin = p_x; | 
					
						
							|  |  |  | 		int pixel_end = p_x + pixel_len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (pixel_end < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (pixel_begin > p_clip_right) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		int from_x = MAX(pixel_begin, p_clip_left); | 
					
						
							|  |  |  | 		int to_x = MIN(pixel_end, p_clip_right); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (to_x <= from_x) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 1.5; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color color = get_theme_color(SNAME("font_color"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		Color bg = color; | 
					
						
							|  |  |  | 		bg.r = 1 - color.r; | 
					
						
							|  |  |  | 		bg.g = 1 - color.g; | 
					
						
							|  |  |  | 		bg.b = 1 - color.b; | 
					
						
							|  |  |  | 		draw_rect(rect, bg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Vector2> lines; | 
					
						
							|  |  |  | 		Vector<Color> colorv; | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			Ref<Animation> animation = ap->get_animation(anim); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (int i = 0; i < animation->get_track_count(); i++) { | 
					
						
							|  |  |  | 				float h = (rect.size.height - 2) / animation->get_track_count(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				int y = 2 + h * i + h / 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				for (int j = 0; j < animation->track_get_key_count(i); j++) { | 
					
						
							|  |  |  | 					float ofs = animation->track_get_key_time(i, j); | 
					
						
							|  |  |  | 					int x = p_x + ofs * p_pixels_sec + 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					if (x < from_x || x >= (to_x - 4)) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 						continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					lines.push_back(Point2(x, y)); | 
					
						
							|  |  |  | 					lines.push_back(Point2(x + 1, y)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			colorv.push_back(color); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (lines.size() > 2) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 			RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, colorv); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int limit = to_x - from_x - 4; | 
					
						
							|  |  |  | 		if (limit > 0) { | 
					
						
							| 
									
										
										
										
											2021-11-24 20:58:47 -06:00
										 |  |  | 			draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), anim, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			draw_rect(rect, accent, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color color = get_theme_color(SNAME("font_color"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		draw_rect(rect, color); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			draw_rect(rect, accent, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditSubAnim::set_node(Object *p_object) { | 
					
						
							|  |  |  | 	id = p_object->get_instance_id(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //// VOLUME DB ////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int AnimationTrackEditVolumeDB::get_key_height() const { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	return volume_texture->get_height() * 1.2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditVolumeDB::draw_bg(int p_clip_left, int p_clip_right) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	int tex_h = volume_texture->get_height(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int y_from = (get_size().height - tex_h) / 2; | 
					
						
							|  |  |  | 	int y_size = tex_h; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Color color(1, 1, 1, 0.3); | 
					
						
							|  |  |  | 	draw_texture_rect(volume_texture, Rect2(p_clip_left, y_from, p_clip_right - p_clip_left, y_from + y_size), false, color); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditVolumeDB::draw_fg(int p_clip_left, int p_clip_right) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	int tex_h = volume_texture->get_height(); | 
					
						
							|  |  |  | 	int y_from = (get_size().height - tex_h) / 2; | 
					
						
							|  |  |  | 	int db0 = y_from + (24 / 80.0) * tex_h; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	draw_line(Vector2(p_clip_left, db0), Vector2(p_clip_right, db0), Color(1, 1, 1, 0.3)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditVolumeDB::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (p_x > p_clip_right || p_next_x < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	float db = get_animation()->track_get_key_value(get_track(), p_index); | 
					
						
							|  |  |  | 	float db_n = get_animation()->track_get_key_value(get_track(), p_index + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	db = CLAMP(db, -60, 24); | 
					
						
							|  |  |  | 	db_n = CLAMP(db_n, -60, 24); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float h = 1.0 - ((db + 60) / 84.0); | 
					
						
							|  |  |  | 	float h_n = 1.0 - ((db_n + 60) / 84.0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int from_x = p_x; | 
					
						
							|  |  |  | 	int to_x = p_next_x; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (from_x < p_clip_left) { | 
					
						
							|  |  |  | 		h = Math::lerp(h, h_n, float(p_clip_left - from_x) / float(to_x - from_x)); | 
					
						
							|  |  |  | 		from_x = p_clip_left; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (to_x > p_clip_right) { | 
					
						
							|  |  |  | 		h_n = Math::lerp(h, h_n, float(p_clip_right - from_x) / float(to_x - from_x)); | 
					
						
							|  |  |  | 		to_x = p_clip_right; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Texture2D> volume_texture = get_theme_icon(SNAME("ColorTrackVu"), SNAME("EditorIcons")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	int tex_h = volume_texture->get_height(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int y_from = (get_size().height - tex_h) / 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Color color = get_theme_color(SNAME("font_color"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	color.a *= 0.7; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	draw_line(Point2(from_x, y_from + h * tex_h), Point2(to_x, y_from + h_n * tex_h), color, 2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// AUDIO ///
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditTypeAudio::_preview_changed(ObjectID p_which) { | 
					
						
							|  |  |  | 	for (int i = 0; i < get_animation()->track_get_key_count(get_track()); i++) { | 
					
						
							|  |  |  | 		Ref<AudioStream> stream = get_animation()->audio_track_get_key_stream(get_track(), i); | 
					
						
							|  |  |  | 		if (stream.is_valid() && stream->get_instance_id() == p_which) { | 
					
						
							|  |  |  | 			update(); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int AnimationTrackEditTypeAudio::get_key_height() const { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	return int(font->get_height(font_size) * 1.5); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | Rect2 AnimationTrackEditTypeAudio::get_key_rect(int p_index, float p_pixels_sec) { | 
					
						
							|  |  |  | 	Ref<AudioStream> stream = get_animation()->audio_track_get_key_stream(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!stream.is_valid()) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float start_ofs = get_animation()->audio_track_get_key_start_offset(get_track(), p_index); | 
					
						
							|  |  |  | 	float end_ofs = get_animation()->audio_track_get_key_end_offset(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float len = stream->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (len == 0) { | 
					
						
							|  |  |  | 		Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); | 
					
						
							|  |  |  | 		len = preview->get_length(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len -= end_ofs; | 
					
						
							|  |  |  | 	len -= start_ofs; | 
					
						
							|  |  |  | 	if (len <= 0.001) { | 
					
						
							|  |  |  | 		len = 0.001; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 		len = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Rect2(0, 0, len * p_pixels_sec, get_size().height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditTypeAudio::is_key_selectable_by_distance() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { | 
					
						
							|  |  |  | 	Ref<AudioStream> stream = get_animation()->audio_track_get_key_stream(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!stream.is_valid()) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float start_ofs = get_animation()->audio_track_get_key_start_offset(get_track(), p_index); | 
					
						
							|  |  |  | 	float end_ofs = get_animation()->audio_track_get_key_end_offset(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (len_resizing && p_index == len_resizing_index) { | 
					
						
							|  |  |  | 		float ofs_local = -len_resizing_rel / get_timeline()->get_zoom_scale(); | 
					
						
							|  |  |  | 		if (len_resizing_start) { | 
					
						
							|  |  |  | 			start_ofs += ofs_local; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (start_ofs < 0) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 				start_ofs = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			end_ofs += ofs_local; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (end_ofs < 0) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 				end_ofs = 0; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	float fh = int(font->get_height(font_size) * 1.5); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	float len = stream->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float preview_len = preview->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (len == 0) { | 
					
						
							|  |  |  | 		len = preview_len; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int pixel_total_len = len * p_pixels_sec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len -= end_ofs; | 
					
						
							|  |  |  | 	len -= start_ofs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (len <= 0.001) { | 
					
						
							|  |  |  | 		len = 0.001; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int pixel_len = len * p_pixels_sec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int pixel_begin = p_x; | 
					
						
							|  |  |  | 	int pixel_end = p_x + pixel_len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (pixel_end < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (pixel_begin > p_clip_right) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int from_x = MAX(pixel_begin, p_clip_left); | 
					
						
							|  |  |  | 	int to_x = MIN(pixel_end, p_clip_right); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 		float limit = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 		int limit_x = pixel_begin + limit * p_pixels_sec; | 
					
						
							|  |  |  | 		to_x = MIN(limit_x, to_x); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (to_x <= from_x) { | 
					
						
							|  |  |  | 		to_x = from_x + 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int h = get_size().height; | 
					
						
							|  |  |  | 	Rect2 rect = Rect2(from_x, (h - fh) / 2, to_x - from_x, fh); | 
					
						
							|  |  |  | 	draw_rect(rect, Color(0.25, 0.25, 0.25)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Vector2> lines; | 
					
						
							|  |  |  | 	lines.resize((to_x - from_x + 1) * 2); | 
					
						
							|  |  |  | 	preview_len = preview->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = from_x; i < to_x; i++) { | 
					
						
							|  |  |  | 		float ofs = (i - pixel_begin) * preview_len / pixel_total_len; | 
					
						
							|  |  |  | 		float ofs_n = ((i + 1) - pixel_begin) * preview_len / pixel_total_len; | 
					
						
							|  |  |  | 		ofs += start_ofs; | 
					
						
							|  |  |  | 		ofs_n += start_ofs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5; | 
					
						
							|  |  |  | 		float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int idx = i - from_x; | 
					
						
							| 
									
										
										
										
											2018-07-25 03:11:03 +02:00
										 |  |  | 		lines.write[idx * 2 + 0] = Vector2(i, rect.position.y + min * rect.size.y); | 
					
						
							|  |  |  | 		lines.write[idx * 2 + 1] = Vector2(i, rect.position.y + max * rect.size.y); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Color> color; | 
					
						
							|  |  |  | 	color.push_back(Color(0.75, 0.75, 0.75)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, color); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Color cut_color = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	cut_color.a = 0.7; | 
					
						
							|  |  |  | 	if (start_ofs > 0 && pixel_begin > p_clip_left) { | 
					
						
							|  |  |  | 		draw_rect(Rect2(pixel_begin, rect.position.y, 1, rect.size.y), cut_color); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (end_ofs > 0 && pixel_end < p_clip_right) { | 
					
						
							|  |  |  | 		draw_rect(Rect2(pixel_end, rect.position.y, 1, rect.size.y), cut_color); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		draw_rect(rect, accent, false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditTypeAudio::_bind_methods() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimationTrackEditTypeAudio::AnimationTrackEditTypeAudio() { | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	AudioStreamPreviewGenerator::get_singleton()->connect("preview_updated", callable_mp(this, &AnimationTrackEditTypeAudio::_preview_changed)); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	len_resizing = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditTypeAudio::can_drop_data(const Point2 &p_point, const Variant &p_data) const { | 
					
						
							|  |  |  | 	if (p_point.x > get_timeline()->get_name_limit() && p_point.x < get_size().width - get_timeline()->get_buttons_width()) { | 
					
						
							|  |  |  | 		Dictionary drag_data = p_data; | 
					
						
							|  |  |  | 		if (drag_data.has("type") && String(drag_data["type"]) == "resource") { | 
					
						
							|  |  |  | 			Ref<AudioStream> res = drag_data["resource"]; | 
					
						
							|  |  |  | 			if (res.is_valid()) { | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (drag_data.has("type") && String(drag_data["type"]) == "files") { | 
					
						
							|  |  |  | 			Vector<String> files = drag_data["files"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (files.size() == 1) { | 
					
						
							|  |  |  | 				String file = files[0]; | 
					
						
							|  |  |  | 				Ref<AudioStream> res = ResourceLoader::load(file); | 
					
						
							|  |  |  | 				if (res.is_valid()) { | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return AnimationTrackEdit::can_drop_data(p_point, p_data); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | void AnimationTrackEditTypeAudio::drop_data(const Point2 &p_point, const Variant &p_data) { | 
					
						
							|  |  |  | 	if (p_point.x > get_timeline()->get_name_limit() && p_point.x < get_size().width - get_timeline()->get_buttons_width()) { | 
					
						
							|  |  |  | 		Ref<AudioStream> stream; | 
					
						
							|  |  |  | 		Dictionary drag_data = p_data; | 
					
						
							|  |  |  | 		if (drag_data.has("type") && String(drag_data["type"]) == "resource") { | 
					
						
							|  |  |  | 			stream = drag_data["resource"]; | 
					
						
							|  |  |  | 		} else if (drag_data.has("type") && String(drag_data["type"]) == "files") { | 
					
						
							|  |  |  | 			Vector<String> files = drag_data["files"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (files.size() == 1) { | 
					
						
							|  |  |  | 				String file = files[0]; | 
					
						
							|  |  |  | 				stream = ResourceLoader::load(file); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (stream.is_valid()) { | 
					
						
							|  |  |  | 			int x = p_point.x - get_timeline()->get_name_limit(); | 
					
						
							|  |  |  | 			float ofs = x / get_timeline()->get_zoom_scale(); | 
					
						
							|  |  |  | 			ofs += get_timeline()->get_value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			ofs = get_editor()->snap_time(ofs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			while (get_animation()->track_find_key(get_track(), ofs, true) != -1) { //make sure insertion point is valid
 | 
					
						
							|  |  |  | 				ofs += 0.001; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-21 16:41:01 -03:00
										 |  |  | 			get_undo_redo()->create_action(TTR("Add Audio Track Clip")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			get_undo_redo()->add_do_method(get_animation().ptr(), "audio_track_insert_key", get_track(), ofs, stream); | 
					
						
							| 
									
										
										
										
											2021-05-05 13:34:39 +09:00
										 |  |  | 			get_undo_redo()->add_undo_method(get_animation().ptr(), "track_remove_key_at_time", get_track(), ofs); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			get_undo_redo()->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			update(); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-01 12:59:42 +02:00
										 |  |  | 	AnimationTrackEdit::drop_data(p_point, p_data); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-22 12:37:22 -03:00
										 |  |  | void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) { | 
					
						
							| 
									
										
										
										
											2021-04-05 08:52:21 +02:00
										 |  |  | 	ERR_FAIL_COND(p_event.is_null()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	Ref<InputEventMouseMotion> mm = p_event; | 
					
						
							|  |  |  | 	if (!len_resizing && mm.is_valid()) { | 
					
						
							|  |  |  | 		bool use_hsize_cursor = false; | 
					
						
							|  |  |  | 		for (int i = 0; i < get_animation()->track_get_key_count(get_track()); i++) { | 
					
						
							|  |  |  | 			Ref<AudioStream> stream = get_animation()->audio_track_get_key_stream(get_track(), i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!stream.is_valid()) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			float start_ofs = get_animation()->audio_track_get_key_start_offset(get_track(), i); | 
					
						
							|  |  |  | 			float end_ofs = get_animation()->audio_track_get_key_end_offset(get_track(), i); | 
					
						
							|  |  |  | 			float len = stream->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (len == 0) { | 
					
						
							|  |  |  | 				Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); | 
					
						
							|  |  |  | 				float preview_len = preview->get_length(); | 
					
						
							|  |  |  | 				len = preview_len; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			len -= end_ofs; | 
					
						
							|  |  |  | 			len -= start_ofs; | 
					
						
							|  |  |  | 			if (len <= 0.001) { | 
					
						
							|  |  |  | 				len = 0.001; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (get_animation()->track_get_key_count(get_track()) > i + 1) { | 
					
						
							|  |  |  | 				len = MIN(len, get_animation()->track_get_key_time(get_track(), i + 1) - get_animation()->track_get_key_time(get_track(), i)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			float ofs = get_animation()->track_get_key_time(get_track(), i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			ofs -= get_timeline()->get_value(); | 
					
						
							|  |  |  | 			ofs *= get_timeline()->get_zoom_scale(); | 
					
						
							|  |  |  | 			ofs += get_timeline()->get_name_limit(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			int end = ofs + len * get_timeline()->get_zoom_scale(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (end >= get_timeline()->get_name_limit() && end <= get_size().width - get_timeline()->get_buttons_width() && ABS(mm->get_position().x - end) < 5 * EDSCALE) { | 
					
						
							|  |  |  | 				use_hsize_cursor = true; | 
					
						
							|  |  |  | 				len_resizing_index = i; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (use_hsize_cursor) { | 
					
						
							|  |  |  | 			set_default_cursor_shape(CURSOR_HSIZE); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			set_default_cursor_shape(CURSOR_ARROW); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (len_resizing && mm.is_valid()) { | 
					
						
							|  |  |  | 		len_resizing_rel += mm->get_relative().x; | 
					
						
							| 
									
										
										
										
											2021-04-24 14:33:50 -06:00
										 |  |  | 		len_resizing_start = mm->is_shift_pressed(); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		update(); | 
					
						
							|  |  |  | 		accept_event(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Ref<InputEventMouseButton> mb = p_event; | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT && get_default_cursor_shape() == CURSOR_HSIZE) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		len_resizing = true; | 
					
						
							| 
									
										
										
										
											2021-04-24 14:33:50 -06:00
										 |  |  | 		len_resizing_start = mb->is_shift_pressed(); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		len_resizing_from_px = mb->get_position().x; | 
					
						
							|  |  |  | 		len_resizing_rel = 0; | 
					
						
							|  |  |  | 		update(); | 
					
						
							|  |  |  | 		accept_event(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	if (len_resizing && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		float ofs_local = -len_resizing_rel / get_timeline()->get_zoom_scale(); | 
					
						
							|  |  |  | 		if (len_resizing_start) { | 
					
						
							|  |  |  | 			float prev_ofs = get_animation()->audio_track_get_key_start_offset(get_track(), len_resizing_index); | 
					
						
							| 
									
										
										
										
											2019-02-21 16:41:01 -03:00
										 |  |  | 			get_undo_redo()->create_action(TTR("Change Audio Track Clip Start Offset")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			get_undo_redo()->add_do_method(get_animation().ptr(), "audio_track_set_key_start_offset", get_track(), len_resizing_index, prev_ofs + ofs_local); | 
					
						
							|  |  |  | 			get_undo_redo()->add_undo_method(get_animation().ptr(), "audio_track_set_key_start_offset", get_track(), len_resizing_index, prev_ofs); | 
					
						
							|  |  |  | 			get_undo_redo()->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			float prev_ofs = get_animation()->audio_track_get_key_end_offset(get_track(), len_resizing_index); | 
					
						
							| 
									
										
										
										
											2019-02-21 16:41:01 -03:00
										 |  |  | 			get_undo_redo()->create_action(TTR("Change Audio Track Clip End Offset")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			get_undo_redo()->add_do_method(get_animation().ptr(), "audio_track_set_key_end_offset", get_track(), len_resizing_index, prev_ofs + ofs_local); | 
					
						
							|  |  |  | 			get_undo_redo()->add_undo_method(get_animation().ptr(), "audio_track_set_key_end_offset", get_track(), len_resizing_index, prev_ofs); | 
					
						
							|  |  |  | 			get_undo_redo()->commit_action(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		len_resizing = false; | 
					
						
							|  |  |  | 		len_resizing_index = -1; | 
					
						
							|  |  |  | 		update(); | 
					
						
							|  |  |  | 		accept_event(); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-22 12:37:22 -03:00
										 |  |  | 	AnimationTrackEdit::gui_input(p_event); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ////////////////////
 | 
					
						
							|  |  |  | /// SUB ANIMATION ///
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int AnimationTrackEditTypeAnimation::get_key_height() const { | 
					
						
							|  |  |  | 	if (!ObjectDB::get_instance(id)) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_height(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 	int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	return int(font->get_height(font_size) * 1.5); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_sec) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ap) { | 
					
						
							|  |  |  | 		return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String anim = get_animation()->animation_track_get_key_animation(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (anim != "[stop]" && ap->has_animation(anim)) { | 
					
						
							|  |  |  | 		float len = ap->get_animation(anim)->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 			len = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return Rect2(0, 0, len * p_pixels_sec, get_size().height); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		return Rect2(0, 0, fh, get_size().height); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool AnimationTrackEditTypeAnimation::is_key_selectable_by_distance() const { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { | 
					
						
							|  |  |  | 	Object *object = ObjectDB::get_instance(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!object) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!ap) { | 
					
						
							|  |  |  | 		AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	String anim = get_animation()->animation_track_get_key_animation(get_track(), p_index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (anim != "[stop]" && ap->has_animation(anim)) { | 
					
						
							|  |  |  | 		float len = ap->get_animation(anim)->get_length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (get_animation()->track_get_key_count(get_track()) > p_index + 1) { | 
					
						
							|  |  |  | 			len = MIN(len, get_animation()->track_get_key_time(get_track(), p_index + 1) - get_animation()->track_get_key_time(get_track(), p_index)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int pixel_len = len * p_pixels_sec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int pixel_begin = p_x; | 
					
						
							|  |  |  | 		int pixel_end = p_x + pixel_len; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (pixel_end < p_clip_left) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (pixel_begin > p_clip_right) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		int from_x = MAX(pixel_begin, p_clip_left); | 
					
						
							|  |  |  | 		int to_x = MIN(pixel_end, p_clip_right); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (to_x <= from_x) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 1.5; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		Rect2 rect(from_x, int(get_size().height - fh) / 2, to_x - from_x, fh); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color color = get_theme_color(SNAME("font_color"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		Color bg = color; | 
					
						
							|  |  |  | 		bg.r = 1 - color.r; | 
					
						
							|  |  |  | 		bg.g = 1 - color.g; | 
					
						
							|  |  |  | 		bg.b = 1 - color.b; | 
					
						
							|  |  |  | 		draw_rect(rect, bg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Vector2> lines; | 
					
						
							|  |  |  | 		Vector<Color> colorv; | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			Ref<Animation> animation = ap->get_animation(anim); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (int i = 0; i < animation->get_track_count(); i++) { | 
					
						
							|  |  |  | 				float h = (rect.size.height - 2) / animation->get_track_count(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				int y = 2 + h * i + h / 2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				for (int j = 0; j < animation->track_get_key_count(i); j++) { | 
					
						
							|  |  |  | 					float ofs = animation->track_get_key_time(i, j); | 
					
						
							|  |  |  | 					int x = p_x + ofs * p_pixels_sec + 2; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					if (x < from_x || x >= (to_x - 4)) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 						continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					lines.push_back(Point2(x, y)); | 
					
						
							|  |  |  | 					lines.push_back(Point2(x + 1, y)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			colorv.push_back(color); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (lines.size() > 2) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 			RS::get_singleton()->canvas_item_add_multiline(get_canvas_item(), lines, colorv); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		int limit = to_x - from_x - 4; | 
					
						
							|  |  |  | 		if (limit > 0) { | 
					
						
							| 
									
										
										
										
											2021-11-24 20:58:47 -06:00
										 |  |  | 			draw_string(font, Point2(from_x + 2, int(get_size().height - font->get_height(font_size)) / 2 + font->get_ascent(font_size)), anim, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			draw_rect(rect, accent, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); | 
					
						
							|  |  |  | 		int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		int fh = font->get_height(font_size) * 0.8; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		Rect2 rect(Vector2(p_x, int(get_size().height - fh) / 2), Size2(fh, fh)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Color color = get_theme_color(SNAME("font_color"), SNAME("Label")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		draw_rect(rect, color); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (p_selected) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 			draw_rect(rect, accent, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationTrackEditTypeAnimation::set_node(Object *p_object) { | 
					
						
							|  |  |  | 	id = p_object->get_instance_id(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimationTrackEditTypeAnimation::AnimationTrackEditTypeAnimation() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /////////
 | 
					
						
							|  |  |  | AnimationTrackEdit *AnimationTrackEditDefaultPlugin::create_value_track_edit(Object *p_object, Variant::Type p_type, const String &p_property, PropertyHint p_hint, const String &p_hint_string, int p_usage) { | 
					
						
							|  |  |  | 	if (p_property == "playing" && (p_object->is_class("AudioStreamPlayer") || p_object->is_class("AudioStreamPlayer2D") || p_object->is_class("AudioStreamPlayer3D"))) { | 
					
						
							|  |  |  | 		AnimationTrackEditAudio *audio = memnew(AnimationTrackEditAudio); | 
					
						
							|  |  |  | 		audio->set_node(p_object); | 
					
						
							|  |  |  | 		return audio; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	if (p_property == "frame" && (p_object->is_class("Sprite2D") || p_object->is_class("Sprite3D") || p_object->is_class("AnimatedSprite2D") || p_object->is_class("AnimatedSprite3D"))) { | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 		AnimationTrackEditSpriteFrame *sprite = memnew(AnimationTrackEditSpriteFrame); | 
					
						
							|  |  |  | 		sprite->set_node(p_object); | 
					
						
							|  |  |  | 		return sprite; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	if (p_property == "frame_coords" && (p_object->is_class("Sprite2D") || p_object->is_class("Sprite3D"))) { | 
					
						
							| 
									
										
										
										
											2019-10-22 02:46:50 +02:00
										 |  |  | 		AnimationTrackEditSpriteFrame *sprite = memnew(AnimationTrackEditSpriteFrame); | 
					
						
							|  |  |  | 		sprite->set_as_coords(); | 
					
						
							|  |  |  | 		sprite->set_node(p_object); | 
					
						
							|  |  |  | 		return sprite; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | 	if (p_property == "current_animation" && (p_object->is_class("AnimationPlayer"))) { | 
					
						
							|  |  |  | 		AnimationTrackEditSubAnim *player = memnew(AnimationTrackEditSubAnim); | 
					
						
							|  |  |  | 		player->set_node(p_object); | 
					
						
							|  |  |  | 		return player; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_property == "volume_db") { | 
					
						
							|  |  |  | 		AnimationTrackEditVolumeDB *vu = memnew(AnimationTrackEditVolumeDB); | 
					
						
							|  |  |  | 		return vu; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_type == Variant::BOOL) { | 
					
						
							|  |  |  | 		return memnew(AnimationTrackEditBool); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (p_type == Variant::COLOR) { | 
					
						
							|  |  |  | 		return memnew(AnimationTrackEditColor); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	return nullptr; | 
					
						
							| 
									
										
										
										
											2018-06-07 12:46:14 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimationTrackEdit *AnimationTrackEditDefaultPlugin::create_audio_track_edit() { | 
					
						
							|  |  |  | 	return memnew(AnimationTrackEditTypeAudio); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimationTrackEdit *AnimationTrackEditDefaultPlugin::create_animation_track_edit(Object *p_object) { | 
					
						
							|  |  |  | 	AnimationTrackEditTypeAnimation *an = memnew(AnimationTrackEditTypeAnimation); | 
					
						
							|  |  |  | 	an->set_node(p_object); | 
					
						
							|  |  |  | 	return an; | 
					
						
							|  |  |  | } |