diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-12-07 22:39:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-07 22:39:12 +0100 |
commit | d303a7e6d7f438ea5b27acb39221913aa1a3ffec (patch) | |
tree | 063993738a41278fa915478a494dfe49a11c531b /scene/gui | |
parent | dc2fadc14d1c83fc43683e90a215182c9db1b781 (diff) | |
parent | e19520e8fea78facaf6a2e2b2f0f1bc839c87c47 (diff) |
Merge pull request #22680 from lupoDharkael/color-picker-presets
ColorPicker: extend access to presets from gds
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/color_picker.cpp | 27 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 3 |
2 files changed, 29 insertions, 1 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index c5d3def4c1..19c6cde111 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -253,6 +253,24 @@ void ColorPicker::add_preset(const Color &p_color) { bt_add_preset->hide(); } +void ColorPicker::erase_preset(const Color &p_color) { + + if (presets.find(p_color)) { + presets.erase(presets.find(p_color)); + preset->update(); + } +} + +PoolColorArray ColorPicker::get_presets() const { + + PoolColorArray arr; + arr.resize(presets.size()); + for (int i = 0; i < presets.size(); i++) { + arr.set(i, presets[i]); + } + return arr; +} + void ColorPicker::set_raw_mode(bool p_enabled) { if (raw_mode_enabled == p_enabled) @@ -446,7 +464,9 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) { set_pick_color(presets[index]); } else if (bev->is_pressed() && bev->get_button_index() == BUTTON_RIGHT) { int index = bev->get_position().x / (preset->get_size().x / presets.size()); - presets.erase(presets[index]); + Color clicked_preset = presets[index]; + presets.erase(clicked_preset); + emit_signal("preset_removed", clicked_preset); preset->update(); bt_add_preset->show(); } @@ -501,6 +521,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) { void ColorPicker::_add_preset_pressed() { add_preset(color); + emit_signal("preset_added", color); } void ColorPicker::_screen_pick_pressed() { @@ -553,6 +574,8 @@ void ColorPicker::_bind_methods() { ClassDB::bind_method(D_METHOD("set_edit_alpha", "show"), &ColorPicker::set_edit_alpha); ClassDB::bind_method(D_METHOD("is_editing_alpha"), &ColorPicker::is_editing_alpha); ClassDB::bind_method(D_METHOD("add_preset", "color"), &ColorPicker::add_preset); + ClassDB::bind_method(D_METHOD("erase_preset", "color"), &ColorPicker::erase_preset); + ClassDB::bind_method(D_METHOD("get_presets"), &ColorPicker::get_presets); ClassDB::bind_method(D_METHOD("_value_changed"), &ColorPicker::_value_changed); ClassDB::bind_method(D_METHOD("_html_entered"), &ColorPicker::_html_entered); ClassDB::bind_method(D_METHOD("_text_type_toggled"), &ColorPicker::_text_type_toggled); @@ -575,6 +598,8 @@ void ColorPicker::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deferred_mode"), "set_deferred_mode", "is_deferred_mode"); ADD_SIGNAL(MethodInfo("color_changed", PropertyInfo(Variant::COLOR, "color"))); + ADD_SIGNAL(MethodInfo("preset_added", PropertyInfo(Variant::COLOR, "color"))); + ADD_SIGNAL(MethodInfo("preset_removed", PropertyInfo(Variant::COLOR, "color"))); } ColorPicker::ColorPicker() : diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 0166da7118..e32c830434 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -105,6 +105,9 @@ public: Color get_pick_color() const; void add_preset(const Color &p_color); + void erase_preset(const Color &p_color); + PoolColorArray get_presets() const; + void set_raw_mode(bool p_enabled); bool is_raw_mode() const; |