summaryrefslogtreecommitdiff
path: root/editor/animation_track_editor_plugins.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/animation_track_editor_plugins.cpp')
-rw-r--r--editor/animation_track_editor_plugins.cpp76
1 files changed, 0 insertions, 76 deletions
diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp
index 0ce3ab292e..424c3db15f 100644
--- a/editor/animation_track_editor_plugins.cpp
+++ b/editor/animation_track_editor_plugins.cpp
@@ -41,22 +41,18 @@
/// BOOL ///
int AnimationTrackEditBool::get_key_height() const {
-
Ref<Texture2D> checked = get_theme_icon("checked", "CheckBox");
return checked->get_height();
}
Rect2 AnimationTrackEditBool::get_key_rect(int p_index, float p_pixels_sec) {
-
Ref<Texture2D> checked = get_theme_icon("checked", "CheckBox");
return Rect2(-checked->get_width() / 2, 0, checked->get_width(), get_size().height);
}
bool AnimationTrackEditBool::is_key_selectable_by_distance() const {
-
return false;
}
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);
Ref<Texture2D> icon = get_theme_icon(checked ? "checked" : "unchecked", "CheckBox");
@@ -79,24 +75,20 @@ void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x,
/// COLOR ///
int AnimationTrackEditColor::get_key_height() const {
-
Ref<Font> font = get_theme_font("font", "Label");
return font->get_height() * 0.8;
}
Rect2 AnimationTrackEditColor::get_key_rect(int p_index, float p_pixels_sec) {
-
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 0.8;
return Rect2(-fh / 2, 0, fh, get_size().height);
}
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) {
-
Ref<Font> font = get_theme_font("font", "Label");
int fh = (font->get_height() * 0.8);
@@ -143,7 +135,6 @@ void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int
}
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);
Ref<Font> font = get_theme_font("font", "Label");
@@ -166,7 +157,6 @@ void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x,
/// AUDIO ///
void AnimationTrackEditAudio::_preview_changed(ObjectID p_which) {
-
Object *object = ObjectDB::get_instance(id);
if (!object)
@@ -180,7 +170,6 @@ void AnimationTrackEditAudio::_preview_changed(ObjectID p_which) {
}
int AnimationTrackEditAudio::get_key_height() const {
-
if (!ObjectDB::get_instance(id)) {
return AnimationTrackEdit::get_key_height();
}
@@ -189,7 +178,6 @@ int AnimationTrackEditAudio::get_key_height() const {
return int(font->get_height() * 1.5);
}
Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) {
-
Object *object = ObjectDB::get_instance(id);
if (!object) {
@@ -207,7 +195,6 @@ Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) {
float len = stream->get_length();
if (len == 0) {
-
Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream);
len = preview->get_length();
}
@@ -225,11 +212,9 @@ Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) {
}
bool AnimationTrackEditAudio::is_key_selectable_by_distance() const {
-
return false;
}
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) {
@@ -289,7 +274,6 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
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;
@@ -325,7 +309,6 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
}
void AnimationTrackEditAudio::set_node(Object *p_object) {
-
id = p_object->get_instance_id();
}
@@ -339,7 +322,6 @@ AnimationTrackEditAudio::AnimationTrackEditAudio() {
/// SPRITE FRAME / FRAME_COORDS ///
int AnimationTrackEditSpriteFrame::get_key_height() const {
-
if (!ObjectDB::get_instance(id)) {
return AnimationTrackEdit::get_key_height();
}
@@ -348,7 +330,6 @@ int AnimationTrackEditSpriteFrame::get_key_height() const {
return int(font->get_height() * 2);
}
Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_sec) {
-
Object *object = ObjectDB::get_instance(id);
if (!object) {
@@ -358,7 +339,6 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
Size2 size;
if (Object::cast_to<Sprite2D>(object) || Object::cast_to<Sprite3D>(object)) {
-
Ref<Texture2D> texture = object->call("get_texture");
if (!texture.is_valid()) {
return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec);
@@ -380,7 +360,6 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
size.y /= vframes;
}
} else if (Object::cast_to<AnimatedSprite2D>(object) || Object::cast_to<AnimatedSprite3D>(object)) {
-
Ref<SpriteFrames> sf = object->call("get_sprite_frames");
if (sf.is_null()) {
return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec);
@@ -421,11 +400,9 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se
}
bool AnimationTrackEditSpriteFrame::is_key_selectable_by_distance() const {
-
return false;
}
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) {
@@ -437,7 +414,6 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
Rect2 region;
if (Object::cast_to<Sprite2D>(object) || Object::cast_to<Sprite3D>(object)) {
-
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);
@@ -459,7 +435,6 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
region.size = texture->get_size();
if (bool(object->call("is_region"))) {
-
region = Rect2(object->call("get_region_rect"));
}
@@ -474,7 +449,6 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
region.position.y += region.size.y * coords.y;
} else if (Object::cast_to<AnimatedSprite2D>(object) || Object::cast_to<AnimatedSprite3D>(object)) {
-
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);
@@ -534,19 +508,16 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
}
void AnimationTrackEditSpriteFrame::set_node(Object *p_object) {
-
id = p_object->get_instance_id();
}
void AnimationTrackEditSpriteFrame::set_as_coords() {
-
is_coords = true;
}
/// SUB ANIMATION ///
int AnimationTrackEditSubAnim::get_key_height() const {
-
if (!ObjectDB::get_instance(id)) {
return AnimationTrackEdit::get_key_height();
}
@@ -555,7 +526,6 @@ int AnimationTrackEditSubAnim::get_key_height() const {
return int(font->get_height() * 1.5);
}
Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) {
-
Object *object = ObjectDB::get_instance(id);
if (!object) {
@@ -571,7 +541,6 @@ Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float 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) {
@@ -587,11 +556,9 @@ Rect2 AnimationTrackEditSubAnim::get_key_rect(int p_index, float p_pixels_sec) {
}
bool AnimationTrackEditSubAnim::is_key_selectable_by_distance() const {
-
return false;
}
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) {
@@ -609,7 +576,6 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
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) {
@@ -651,13 +617,11 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
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;
@@ -701,20 +665,17 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
}
void AnimationTrackEditSubAnim::set_node(Object *p_object) {
-
id = p_object->get_instance_id();
}
//// VOLUME DB ////
int AnimationTrackEditVolumeDB::get_key_height() const {
-
Ref<Texture2D> volume_texture = get_theme_icon("ColorTrackVu", "EditorIcons");
return volume_texture->get_height() * 1.2;
}
void AnimationTrackEditVolumeDB::draw_bg(int p_clip_left, int p_clip_right) {
-
Ref<Texture2D> volume_texture = get_theme_icon("ColorTrackVu", "EditorIcons");
int tex_h = volume_texture->get_height();
@@ -726,7 +687,6 @@ void AnimationTrackEditVolumeDB::draw_bg(int p_clip_left, int p_clip_right) {
}
void AnimationTrackEditVolumeDB::draw_fg(int p_clip_left, int p_clip_right) {
-
Ref<Texture2D> volume_texture = get_theme_icon("ColorTrackVu", "EditorIcons");
int tex_h = volume_texture->get_height();
int y_from = (get_size().height - tex_h) / 2;
@@ -736,7 +696,6 @@ void AnimationTrackEditVolumeDB::draw_fg(int p_clip_left, int p_clip_right) {
}
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) {
-
if (p_x > p_clip_right || p_next_x < p_clip_left)
return;
@@ -778,7 +737,6 @@ void AnimationTrackEditVolumeDB::draw_key_link(int p_index, float p_pixels_sec,
/// 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) {
@@ -789,12 +747,10 @@ void AnimationTrackEditTypeAudio::_preview_changed(ObjectID p_which) {
}
int AnimationTrackEditTypeAudio::get_key_height() const {
-
Ref<Font> font = get_theme_font("font", "Label");
return int(font->get_height() * 1.5);
}
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()) {
@@ -807,7 +763,6 @@ Rect2 AnimationTrackEditTypeAudio::get_key_rect(int p_index, float p_pixels_sec)
float len = stream->get_length();
if (len == 0) {
-
Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream);
len = preview->get_length();
}
@@ -826,11 +781,9 @@ Rect2 AnimationTrackEditTypeAudio::get_key_rect(int p_index, float p_pixels_sec)
}
bool AnimationTrackEditTypeAudio::is_key_selectable_by_distance() const {
-
return false;
}
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()) {
@@ -909,7 +862,6 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int
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;
@@ -952,9 +904,7 @@ AnimationTrackEditTypeAudio::AnimationTrackEditTypeAudio() {
}
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"];
@@ -964,7 +914,6 @@ bool AnimationTrackEditTypeAudio::can_drop_data(const Point2 &p_point, const Var
}
if (drag_data.has("type") && String(drag_data["type"]) == "files") {
-
Vector<String> files = drag_data["files"];
if (files.size() == 1) {
@@ -980,15 +929,12 @@ bool AnimationTrackEditTypeAudio::can_drop_data(const Point2 &p_point, const Var
return AnimationTrackEdit::can_drop_data(p_point, p_data);
}
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) {
@@ -998,7 +944,6 @@ void AnimationTrackEditTypeAudio::drop_data(const Point2 &p_point, const Variant
}
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();
@@ -1023,12 +968,10 @@ void AnimationTrackEditTypeAudio::drop_data(const Point2 &p_point, const Variant
}
void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) {
-
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()) {
@@ -1086,7 +1029,6 @@ void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && get_default_cursor_shape() == CURSOR_HSIZE) {
-
len_resizing = true;
len_resizing_start = mb->get_shift();
len_resizing_from_px = mb->get_position().x;
@@ -1097,7 +1039,6 @@ void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) {
}
if (len_resizing && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
-
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);
@@ -1128,7 +1069,6 @@ void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) {
/// SUB ANIMATION ///
int AnimationTrackEditTypeAnimation::get_key_height() const {
-
if (!ObjectDB::get_instance(id)) {
return AnimationTrackEdit::get_key_height();
}
@@ -1137,7 +1077,6 @@ int AnimationTrackEditTypeAnimation::get_key_height() const {
return int(font->get_height() * 1.5);
}
Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_sec) {
-
Object *object = ObjectDB::get_instance(id);
if (!object) {
@@ -1153,7 +1092,6 @@ Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_
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) {
@@ -1169,11 +1107,9 @@ Rect2 AnimationTrackEditTypeAnimation::get_key_rect(int p_index, float p_pixels_
}
bool AnimationTrackEditTypeAnimation::is_key_selectable_by_distance() const {
-
return false;
}
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) {
@@ -1191,7 +1127,6 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float 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) {
@@ -1233,13 +1168,11 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
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;
@@ -1283,7 +1216,6 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
}
void AnimationTrackEditTypeAnimation::set_node(Object *p_object) {
-
id = p_object->get_instance_id();
}
@@ -1292,23 +1224,19 @@ 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;
}
if (p_property == "frame" && (p_object->is_class("Sprite2D") || p_object->is_class("Sprite3D") || p_object->is_class("AnimatedSprite2D") || p_object->is_class("AnimatedSprite3D"))) {
-
AnimationTrackEditSpriteFrame *sprite = memnew(AnimationTrackEditSpriteFrame);
sprite->set_node(p_object);
return sprite;
}
if (p_property == "frame_coords" && (p_object->is_class("Sprite2D") || p_object->is_class("Sprite3D"))) {
-
AnimationTrackEditSpriteFrame *sprite = memnew(AnimationTrackEditSpriteFrame);
sprite->set_as_coords();
sprite->set_node(p_object);
@@ -1316,14 +1244,12 @@ AnimationTrackEdit *AnimationTrackEditDefaultPlugin::create_value_track_edit(Obj
}
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;
}
@@ -1339,12 +1265,10 @@ AnimationTrackEdit *AnimationTrackEditDefaultPlugin::create_value_track_edit(Obj
}
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;