diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-07-07 23:31:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-07 23:31:24 +0200 |
commit | 47e5fed48530c6361923ec79bd5a427218ff6b2a (patch) | |
tree | 0543da879677072413d9b79b82424c2fd87ff9a4 /scene/gui | |
parent | b1068f9f01f5a5382ed3f1994d1302a35e96f445 (diff) | |
parent | 94a464f555500583920759bae4397ea4daddb309 (diff) |
Merge pull request #50261 from Razoric480/cache-color-picker-presets
Add cache to ColorPicker for color presets
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/color_picker.cpp | 16 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 1 |
2 files changed, 14 insertions, 3 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 049de4c8c5..659d14ae70 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -40,6 +40,8 @@ #endif #include "scene/main/window.h" +List<Color> ColorPicker::preset_cache; + void ColorPicker::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { @@ -57,11 +59,17 @@ void ColorPicker::_notification(int p_what) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { - PackedColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PackedColorArray()); + if (preset_cache.is_empty()) { + PackedColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PackedColorArray()); + for (int i = 0; i < saved_presets.size(); i++) { + preset_cache.push_back(saved_presets[i]); + } + } - for (int i = 0; i < saved_presets.size(); i++) { - add_preset(saved_presets[i]); + for (int i = 0; i < preset_cache.size(); i++) { + presets.push_back(preset_cache[i]); } + preset->update(); } #endif } break; @@ -413,6 +421,7 @@ void ColorPicker::add_preset(const Color &p_color) { presets.move_to_back(presets.find(p_color)); } else { presets.push_back(p_color); + preset_cache.push_back(p_color); } preset->update(); @@ -427,6 +436,7 @@ void ColorPicker::add_preset(const Color &p_color) { void ColorPicker::erase_preset(const Color &p_color) { if (presets.find(p_color)) { presets.erase(presets.find(p_color)); + preset_cache.erase(preset_cache.find(p_color)); preset->update(); #ifdef TOOLS_ENABLED diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 3bd2ff9375..60da3957aa 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -58,6 +58,7 @@ public: private: static Ref<Shader> wheel_shader; static Ref<Shader> circle_shader; + static List<Color> preset_cache; Control *screen = nullptr; Control *uv_edit = memnew(Control); |