Skip to content

Commit

Permalink
Don't instantiate ColorPicker in EditorPropertyColor constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
larspet committed Jan 20, 2025
1 parent 1b7b009 commit 3376ba6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 12 additions & 8 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2599,18 +2599,24 @@ void EditorPropertyColor::_color_changed(const Color &p_color) {
get_edited_object()->set(get_edited_property(), p_color);
}

void EditorPropertyColor::_picker_created() {
picker->get_popup()->connect("about_to_popup", callable_mp(this, &EditorPropertyColor::_popup_opening));
picker->connect("popup_closed", callable_mp(this, &EditorPropertyColor::_popup_closed), CONNECT_DEFERRED);
}

void EditorPropertyColor::_popup_opening() {
EditorNode::get_singleton()->setup_color_picker(picker->get_picker());
last_color = picker->get_pick_color();
was_checked = !is_checkable() || is_checked();
}

void EditorPropertyColor::_popup_closed() {
get_edited_object()->set(get_edited_property(), was_checked ? Variant(last_color) : Variant());
if (!picker->get_pick_color().is_equal_approx(last_color)) {
emit_changed(get_edited_property(), picker->get_pick_color(), "", false);
}
}

void EditorPropertyColor::_picker_opening() {
last_color = picker->get_pick_color();
was_checked = !is_checkable() || is_checked();
}

void EditorPropertyColor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
Expand Down Expand Up @@ -2654,9 +2660,7 @@ EditorPropertyColor::EditorPropertyColor() {
add_child(picker);
picker->set_flat(true);
picker->connect("color_changed", callable_mp(this, &EditorPropertyColor::_color_changed));
picker->connect("popup_closed", callable_mp(this, &EditorPropertyColor::_popup_closed), CONNECT_DEFERRED);
picker->get_popup()->connect("about_to_popup", callable_mp(EditorNode::get_singleton(), &EditorNode::setup_color_picker).bind(picker->get_picker()));
picker->get_popup()->connect("about_to_popup", callable_mp(this, &EditorPropertyColor::_picker_opening));
picker->connect("picker_created", callable_mp(this, &EditorPropertyColor::_picker_created), CONNECT_ONE_SHOT);
}

////////////// NODE PATH //////////////////////
Expand Down
3 changes: 2 additions & 1 deletion editor/editor_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,9 @@ class EditorPropertyColor : public EditorProperty {
GDCLASS(EditorPropertyColor, EditorProperty);
ColorPickerButton *picker = nullptr;
void _color_changed(const Color &p_color);
void _picker_created();
void _popup_opening();
void _popup_closed();
void _picker_opening();

Color last_color;
bool live_changes_enabled = true;
Expand Down

0 comments on commit 3376ba6

Please sign in to comment.