Merge pull request #706 from rollenrolm/color-picker-fix

Fix bug #471, Colour picker labels are incorrect in HSV and RAW mode

seems fine to me
This commit is contained in:
Juan Linietsky 2014-09-18 23:34:29 -03:00
commit a6a39f18e0

View File

@ -52,9 +52,6 @@ void ColorPicker::_notification(int p_what) {
void ColorPicker::_update_controls() { void ColorPicker::_update_controls() {
int cw = get_constant("color_width");
if (edit_alpha) { if (edit_alpha) {
values[3]->show(); values[3]->show();
scroll[3]->show(); scroll[3]->show();
@ -65,8 +62,6 @@ void ColorPicker::_update_controls() {
labels[3]->hide(); labels[3]->hide();
} }
} }
@ -106,8 +101,8 @@ void ColorPicker::_value_changed(double) {
} break; } break;
case MODE_HSV: { case MODE_HSV: {
color.set_hsv( CLAMP(scroll[0]->get_val()/255,0,0.99), scroll[1]->get_val()/255, scroll[2]->get_val()/255 ); color.set_hsv( CLAMP(scroll[0]->get_val()/359,0,0.9972), scroll[1]->get_val()/100, scroll[2]->get_val()/100 );
color.a=scroll[3]->get_val()/255.0; color.a=scroll[3]->get_val()/100.0;
} break; } break;
case MODE_RAW: { case MODE_RAW: {
@ -147,29 +142,50 @@ void ColorPicker::_update_color() {
case MODE_RAW: { case MODE_RAW: {
static const char*_lt[4]={"R","G","B","A"};
for(int i=0;i<4;i++) { for(int i=0;i<4;i++) {
scroll[i]->set_max(255);
scroll[i]->set_step(0.01); scroll[i]->set_step(0.01);
scroll[i]->set_val(color.components[i]); scroll[i]->set_val(color.components[i]);
labels[i]->set_text(_lt[i]);
} }
} break; } break;
case MODE_RGB: { case MODE_RGB: {
static const char*_lt[4]={"R","G","B","A"};
for(int i=0;i<4;i++) { for(int i=0;i<4;i++) {
scroll[i]->set_max(255);
scroll[i]->set_step(1); scroll[i]->set_step(1);
scroll[i]->set_val(color.components[i]*255); scroll[i]->set_val(color.components[i]*255);
labels[i]->set_text(_lt[i]);
} }
} break; } break;
case MODE_HSV: { case MODE_HSV: {
static const char*_lt[4]={"H","S","V","A"};
for(int i=0;i<4;i++) { for(int i=0;i<4;i++) {
scroll[i]->set_step(1); labels[i]->set_text(_lt[i]);
} }
scroll[0]->set_val( color.get_h()*255 ); scroll[0]->set_max(359);
scroll[1]->set_val( color.get_s()*255 ); scroll[0]->set_step(0.01);
scroll[2]->set_val( color.get_v()*255 ); scroll[0]->set_val( color.get_h()*359 );
scroll[3]->set_val(color.a*255);
scroll[1]->set_max(100);
scroll[1]->set_step(0.01);
scroll[1]->set_val( color.get_s()*100 );
scroll[2]->set_max(100);
scroll[2]->set_step(0.01);
scroll[2]->set_val( color.get_v()*100 );
scroll[3]->set_max(100);
scroll[3]->set_step(0.01);
scroll[3]->set_val( color.a*100);
} break; } break;
} }
@ -260,9 +276,6 @@ ColorPicker::ColorPicker() {
HBoxContainer *hbc = memnew( HBoxContainer ); HBoxContainer *hbc = memnew( HBoxContainer );
labels[i]=memnew( Label ); labels[i]=memnew( Label );
static const char*_lt[4]={"R","G","B","A"};
labels[i]->set_text(_lt[i]);
hbc->add_child(labels[i]); hbc->add_child(labels[i]);
scroll[i]=memnew( HSlider ); scroll[i]=memnew( HSlider );
@ -274,8 +287,6 @@ ColorPicker::ColorPicker() {
scroll[i]->set_min(0); scroll[i]->set_min(0);
scroll[i]->set_max(255);
scroll[i]->set_step(1);
scroll[i]->set_page(0); scroll[i]->set_page(0);
scroll[i]->set_h_size_flags(SIZE_EXPAND_FILL); scroll[i]->set_h_size_flags(SIZE_EXPAND_FILL);