Merge pull request #24310 from merumelu/color-picker-fixes

ColorPicker fixes
This commit is contained in:
Rémi Verschelde 2018-12-13 10:22:40 +01:00 committed by GitHub
commit d119428ff9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 17 deletions

View File

@ -204,22 +204,9 @@ void ColorPicker::_update_presets() {
preset->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), Rect2(Point2(), preset_size), true); preset->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), Rect2(Point2(), preset_size), true);
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
PoolColorArray arr_to_save = PoolColorArray();
for (int i = 0; i < presets.size(); i++) {
preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]);
arr_to_save.insert(i, presets[i]);
}
EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save);
}
#else
for (int i = 0; i < presets.size(); i++) { for (int i = 0; i < presets.size(); i++) {
preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]); preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]);
} }
#endif
} }
void ColorPicker::_text_type_toggled() { void ColorPicker::_text_type_toggled() {
@ -251,6 +238,13 @@ void ColorPicker::add_preset(const Color &p_color) {
preset->update(); preset->update();
if (presets.size() == 10) if (presets.size() == 10)
bt_add_preset->hide(); bt_add_preset->hide();
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
PoolColorArray arr_to_save = get_presets();
EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save);
}
#endif
} }
void ColorPicker::erase_preset(const Color &p_color) { void ColorPicker::erase_preset(const Color &p_color) {
@ -258,6 +252,13 @@ void ColorPicker::erase_preset(const Color &p_color) {
if (presets.find(p_color)) { if (presets.find(p_color)) {
presets.erase(presets.find(p_color)); presets.erase(presets.find(p_color));
preset->update(); preset->update();
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
PoolColorArray arr_to_save = get_presets();
EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save);
}
#endif
} }
} }
@ -462,16 +463,15 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) { if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
int index = bev->get_position().x / (preset->get_size().x / presets.size()); int index = bev->get_position().x / (preset->get_size().x / presets.size());
set_pick_color(presets[index]); set_pick_color(presets[index]);
_update_color();
emit_signal("color_changed", color);
} else if (bev->is_pressed() && bev->get_button_index() == BUTTON_RIGHT) { } else if (bev->is_pressed() && bev->get_button_index() == BUTTON_RIGHT) {
int index = bev->get_position().x / (preset->get_size().x / presets.size()); int index = bev->get_position().x / (preset->get_size().x / presets.size());
Color clicked_preset = presets[index]; Color clicked_preset = presets[index];
presets.erase(clicked_preset); erase_preset(clicked_preset);
emit_signal("preset_removed", clicked_preset); emit_signal("preset_removed", clicked_preset);
preset->update();
bt_add_preset->show(); bt_add_preset->show();
} }
_update_color();
emit_signal("color_changed", color);
} }
Ref<InputEventMouseMotion> mev = p_event; Ref<InputEventMouseMotion> mev = p_event;