Get color constructor from ColorPicker
This commit is contained in:
parent
5d3fb49826
commit
c927409f25
2 changed files with 43 additions and 13 deletions
|
@ -122,7 +122,7 @@ void ColorPicker::_value_changed(double) {
|
||||||
update_material(uv_material,color);
|
update_material(uv_material,color);
|
||||||
update_material(w_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();
|
sample->update();
|
||||||
|
|
||||||
|
@ -153,9 +153,18 @@ void ColorPicker::_update_color() {
|
||||||
scroll[i]->set_val(color.components[i]*255);
|
scroll[i]->set_val(color.components[i]*255);
|
||||||
}
|
}
|
||||||
|
|
||||||
html->set_text(color.to_html(edit_alpha && color.a<1));
|
if (text_is_constructor) {
|
||||||
html->grab_focus();
|
String t = "Color("+String::num(color.r)+","+String::num(color.g)+","+String::num(color.b);
|
||||||
html->select();
|
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();
|
sample->update();
|
||||||
updating=false;
|
updating=false;
|
||||||
|
@ -175,6 +184,21 @@ void ColorPicker::_update_presets()
|
||||||
preset->set_texture(t);
|
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 {
|
Color ColorPicker::get_color() const {
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
|
@ -366,6 +390,7 @@ void ColorPicker::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("add_preset"), &ColorPicker::add_preset);
|
ObjectTypeDB::bind_method(_MD("add_preset"), &ColorPicker::add_preset);
|
||||||
ObjectTypeDB::bind_method(_MD("_value_changed"),&ColorPicker::_value_changed);
|
ObjectTypeDB::bind_method(_MD("_value_changed"),&ColorPicker::_value_changed);
|
||||||
ObjectTypeDB::bind_method(_MD("_html_entered"),&ColorPicker::_html_entered);
|
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("_add_preset_pressed"), &ColorPicker::_add_preset_pressed);
|
||||||
ObjectTypeDB::bind_method(_MD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed);
|
ObjectTypeDB::bind_method(_MD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed);
|
||||||
ObjectTypeDB::bind_method(_MD("_sample_draw"),&ColorPicker::_sample_draw);
|
ObjectTypeDB::bind_method(_MD("_sample_draw"),&ColorPicker::_sample_draw);
|
||||||
|
@ -383,6 +408,7 @@ ColorPicker::ColorPicker() :
|
||||||
|
|
||||||
updating=true;
|
updating=true;
|
||||||
edit_alpha=true;
|
edit_alpha=true;
|
||||||
|
text_is_constructor = false;
|
||||||
raw_mode_enabled=false;
|
raw_mode_enabled=false;
|
||||||
changing_color=false;
|
changing_color=false;
|
||||||
screen=NULL;
|
screen=NULL;
|
||||||
|
@ -492,14 +518,16 @@ ColorPicker::ColorPicker() :
|
||||||
btn_mode->connect("toggled", this, "set_raw_mode");
|
btn_mode->connect("toggled", this, "set_raw_mode");
|
||||||
hhb->add_child(btn_mode);
|
hhb->add_child(btn_mode);
|
||||||
vbr->add_child(hhb);
|
vbr->add_child(hhb);
|
||||||
html_num = memnew( Label );
|
text_type = memnew( Button );
|
||||||
hhb->add_child(html_num);
|
text_type->set_flat(true);
|
||||||
|
text_type->connect("pressed", this, "_text_type_toggled");
|
||||||
|
hhb->add_child(text_type);
|
||||||
|
|
||||||
html = memnew( LineEdit );
|
c_text = memnew( LineEdit );
|
||||||
hhb->add_child(html);
|
hhb->add_child(c_text);
|
||||||
html->connect("text_entered",this,"_html_entered");
|
c_text->connect("text_entered",this,"_html_entered");
|
||||||
html_num->set_text("#");
|
text_type->set_text("#");
|
||||||
html->set_h_size_flags(SIZE_EXPAND_FILL);
|
c_text->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
|
|
||||||
|
|
||||||
_update_controls();
|
_update_controls();
|
||||||
|
|
|
@ -62,10 +62,11 @@ private:
|
||||||
HSlider *scroll[4];
|
HSlider *scroll[4];
|
||||||
SpinBox *values[4];
|
SpinBox *values[4];
|
||||||
Label *labels[4];
|
Label *labels[4];
|
||||||
Label *html_num;
|
Button *text_type;
|
||||||
LineEdit *html;
|
LineEdit *c_text;
|
||||||
bool edit_alpha;
|
bool edit_alpha;
|
||||||
Size2i ms;
|
Size2i ms;
|
||||||
|
bool text_is_constructor;
|
||||||
|
|
||||||
Color color;
|
Color color;
|
||||||
bool raw_mode_enabled;
|
bool raw_mode_enabled;
|
||||||
|
@ -78,6 +79,7 @@ private:
|
||||||
void _update_controls();
|
void _update_controls();
|
||||||
void _update_color();
|
void _update_color();
|
||||||
void _update_presets();
|
void _update_presets();
|
||||||
|
void _text_type_toggled();
|
||||||
void _sample_draw();
|
void _sample_draw();
|
||||||
void _hsv_draw(int p_wich,Control *c);
|
void _hsv_draw(int p_wich,Control *c);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue