Merge pull request #52142 from NathanLovato/GDQuest/animation-bezier-editor-improvements

Replace close icon with button in the Bezier editor
This commit is contained in:
K. S. Ernest (iFire) Lee 2021-08-27 01:58:00 -07:00 committed by GitHub
commit 00268e37a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 54 deletions

View File

@ -217,6 +217,8 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V
void AnimationBezierTrackEdit::_notification(int p_what) {
if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) {
close_button->set_icon(get_theme_icon(SNAME("Close"), SNAME("EditorIcons")));
bezier_icon = get_theme_icon(SNAME("KeyBezierPoint"), SNAME("EditorIcons"));
bezier_handle_icon = get_theme_icon(SNAME("KeyBezierHandle"), SNAME("EditorIcons"));
selected_icon = get_theme_icon(SNAME("KeyBezierSelected"), SNAME("EditorIcons"));
@ -231,8 +233,8 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
int hsep = get_theme_constant(SNAME("hseparation"), SNAME("ItemList"));
int vsep = get_theme_constant(SNAME("vseparation"), SNAME("ItemList"));
handle_mode_option->set_position(Vector2(right_limit + hsep, get_size().height - handle_mode_option->get_combined_minimum_size().height - vsep));
handle_mode_option->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, handle_mode_option->get_combined_minimum_size().height));
right_column->set_position(Vector2(right_limit + hsep, vsep));
right_column->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, get_size().y - vsep * 2));
}
if (p_what == NOTIFICATION_DRAW) {
if (animation.is_null()) {
@ -261,12 +263,6 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor, Math::round(EDSCALE));
Ref<Texture2D> close_icon = get_theme_icon(SNAME("Close"), SNAME("EditorIcons"));
close_icon_rect.position = Vector2(get_size().width - close_icon->get_width() - hsep, hsep);
close_icon_rect.size = close_icon->get_size();
draw_texture(close_icon, close_icon_rect.position);
String base_path = animation->track_get_path(track);
int end = base_path.find(":");
if (end != -1) {
@ -1126,10 +1122,6 @@ void AnimationBezierTrackEdit::delete_selection() {
}
}
void AnimationBezierTrackEdit::set_block_animation_update_ptr(bool *p_block_ptr) {
block_animation_update_ptr = p_block_ptr;
}
void AnimationBezierTrackEdit::_bind_methods() {
ClassDB::bind_method("_clear_selection", &AnimationBezierTrackEdit::_clear_selection);
ClassDB::bind_method("_clear_selection_for_anim", &AnimationBezierTrackEdit::_clear_selection_for_anim);
@ -1150,21 +1142,6 @@ void AnimationBezierTrackEdit::_bind_methods() {
}
AnimationBezierTrackEdit::AnimationBezierTrackEdit() {
undo_redo = nullptr;
timeline = nullptr;
root = nullptr;
menu = nullptr;
block_animation_update_ptr = nullptr;
moving_selection_attempt = false;
moving_selection = false;
select_single_attempt = -1;
box_selecting = false;
box_selecting_attempt = false;
moving_handle = 0;
play_position_pos = 0;
play_position = memnew(Control);
play_position->set_mouse_filter(MOUSE_FILTER_PASS);
add_child(play_position);
@ -1172,18 +1149,21 @@ AnimationBezierTrackEdit::AnimationBezierTrackEdit() {
play_position->connect("draw", callable_mp(this, &AnimationBezierTrackEdit::_play_position_draw));
set_focus_mode(FOCUS_CLICK);
v_scroll = 0;
v_zoom = 1;
panning_timeline = false;
set_clip_contents(true);
handle_mode = HANDLE_MODE_FREE;
handle_mode_option = memnew(OptionButton);
add_child(handle_mode_option);
close_button = memnew(Button);
close_button->connect("pressed", Callable(this, SNAME("emit_signal")), varray(SNAME("close_request")));
close_button->set_text(TTR("Close"));
right_column = memnew(VBoxContainer);
right_column->add_child(close_button);
right_column->add_spacer();
right_column->add_child(handle_mode_option);
add_child(right_column);
menu = memnew(PopupMenu);
add_child(menu);
menu->connect("id_pressed", callable_mp(this, &AnimationBezierTrackEdit::_menu_selected));
//set_mouse_filter(MOUSE_FILTER_PASS); //scroll has to work too for selection
}

View File

@ -51,11 +51,14 @@ class AnimationBezierTrackEdit : public Control {
HandleMode handle_mode;
OptionButton *handle_mode_option;
AnimationTimelineEdit *timeline;
UndoRedo *undo_redo;
Node *root;
VBoxContainer *right_column;
Button *close_button;
AnimationTimelineEdit *timeline = nullptr;
UndoRedo *undo_redo = nullptr;
Node *root = nullptr;
Control *play_position; //separate control used to draw so updates for only position changed are much faster
float play_position_pos;
float play_position_pos = 0;
Ref<Animation> animation;
int track;
@ -70,37 +73,35 @@ class AnimationBezierTrackEdit : public Control {
Map<int, Rect2> subtracks;
float v_scroll;
float v_zoom;
float v_scroll = 0;
float v_zoom = 1;
PopupMenu *menu;
PopupMenu *menu = nullptr;
void _zoom_changed();
virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _menu_selected(int p_index);
bool *block_animation_update_ptr; //used to block all tracks re-gen (speed up)
void _play_position_draw();
Vector2 insert_at_pos;
bool moving_selection_attempt;
int select_single_attempt;
bool moving_selection;
bool moving_selection_attempt = false;
int select_single_attempt = -1;
bool moving_selection = false;
int moving_selection_from_key;
Vector2 moving_selection_offset;
bool box_selecting_attempt;
bool box_selecting;
bool box_selecting_add;
bool box_selecting_attempt = false;
bool box_selecting = false;
bool box_selecting_add = false;
Vector2 box_selection_from;
Vector2 box_selection_to;
int moving_handle; //0 no move -1 or +1 out
int moving_handle_key;
int moving_handle = 0; //0 no move -1 or +1 out
int moving_handle_key = 0;
Vector2 moving_handle_left;
Vector2 moving_handle_right;
@ -129,7 +130,7 @@ class AnimationBezierTrackEdit : public Control {
Set<int> selection;
bool panning_timeline;
bool panning_timeline = false;
float panning_timeline_from;
float panning_timeline_at;
@ -155,8 +156,6 @@ public:
void set_editor(AnimationTrackEditor *p_editor);
void set_root(Node *p_root);
void set_block_animation_update_ptr(bool *p_block_ptr);
void set_play_position(float p_pos);
void update_play_position();