diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-01-27 19:08:22 +0100 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-01-27 19:08:22 +0100 |
commit | 0c7e7e2c2880565ef3b2d7455e89aee9373b7b8f (patch) | |
tree | 6c9e157e0cb70af5dc5f36230286e8f4c8182ce3 | |
parent | 9a2dd3ebbb9dfe5e4aae24308f25762676135fb1 (diff) | |
parent | c927409f25a082820bf8f186838391d421528da2 (diff) |
Merge pull request #3470 from MarianoGnu/master
Get color constructor from ColorPicker
-rw-r--r-- | scene/gui/color_picker.cpp | 52 | ||||
-rw-r--r-- | scene/gui/color_picker.h | 6 |
2 files changed, 44 insertions, 14 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index bcf25a93c1..862a5d6bcb 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -122,7 +122,7 @@ void ColorPicker::_value_changed(double) { update_material(uv_material,color); update_material(w_material,color); - html->set_text(color.to_html(edit_alpha && color.a<1)); + c_text->set_text(color.to_html(edit_alpha && color.a<1)); sample->update(); @@ -153,9 +153,18 @@ void ColorPicker::_update_color() { scroll[i]->set_val(color.components[i]*255); } - html->set_text(color.to_html(edit_alpha && color.a<1)); - html->grab_focus(); - html->select(); + if (text_is_constructor) { + String t = "Color("+String::num(color.r)+","+String::num(color.g)+","+String::num(color.b); + if (edit_alpha && color.a<1) + t+=(","+String::num(color.a)+")") ; + else + t+=")"; + c_text->set_text(t); + } else { + c_text->set_text(color.to_html(edit_alpha && color.a<1)); + } + c_text->grab_focus(); + c_text->select(); sample->update(); updating=false; @@ -175,6 +184,21 @@ void ColorPicker::_update_presets() preset->set_texture(t); } +void ColorPicker::_text_type_toggled() +{ + if (!get_tree()->is_editor_hint()) + return; + text_is_constructor = !text_is_constructor; + if (text_is_constructor) { + text_type->set_text(""); + text_type->set_icon(get_icon("Script", "EditorIcons")); + } else { + text_type->set_text("#"); + text_type->set_icon(NULL); + } + _update_color(); +} + Color ColorPicker::get_color() const { return color; @@ -366,6 +390,7 @@ void ColorPicker::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_preset"), &ColorPicker::add_preset); ObjectTypeDB::bind_method(_MD("_value_changed"),&ColorPicker::_value_changed); ObjectTypeDB::bind_method(_MD("_html_entered"),&ColorPicker::_html_entered); + ObjectTypeDB::bind_method(_MD("_text_type_toggled"),&ColorPicker::_text_type_toggled); ObjectTypeDB::bind_method(_MD("_add_preset_pressed"), &ColorPicker::_add_preset_pressed); ObjectTypeDB::bind_method(_MD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed); ObjectTypeDB::bind_method(_MD("_sample_draw"),&ColorPicker::_sample_draw); @@ -383,6 +408,7 @@ ColorPicker::ColorPicker() : updating=true; edit_alpha=true; + text_is_constructor = false; raw_mode_enabled=false; changing_color=false; screen=NULL; @@ -492,14 +518,16 @@ ColorPicker::ColorPicker() : btn_mode->connect("toggled", this, "set_raw_mode"); hhb->add_child(btn_mode); vbr->add_child(hhb); - html_num = memnew( Label ); - hhb->add_child(html_num); - - html = memnew( LineEdit ); - hhb->add_child(html); - html->connect("text_entered",this,"_html_entered"); - html_num->set_text("#"); - html->set_h_size_flags(SIZE_EXPAND_FILL); + text_type = memnew( Button ); + text_type->set_flat(true); + text_type->connect("pressed", this, "_text_type_toggled"); + hhb->add_child(text_type); + + c_text = memnew( LineEdit ); + hhb->add_child(c_text); + c_text->connect("text_entered",this,"_html_entered"); + text_type->set_text("#"); + c_text->set_h_size_flags(SIZE_EXPAND_FILL); _update_controls(); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index c6c7fe537d..59668ebac1 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -62,10 +62,11 @@ private: HSlider *scroll[4]; SpinBox *values[4]; Label *labels[4]; - Label *html_num; - LineEdit *html; + Button *text_type; + LineEdit *c_text; bool edit_alpha; Size2i ms; + bool text_is_constructor; Color color; bool raw_mode_enabled; @@ -78,6 +79,7 @@ private: void _update_controls(); void _update_color(); void _update_presets(); + void _text_type_toggled(); void _sample_draw(); void _hsv_draw(int p_wich,Control *c); |