Merge pull request #67534 from KoBeWi/more_OK_in_OKHSL
Improve ColorPicker sliders in OKHSL mode
This commit is contained in:
commit
d831ba1d6f
2 changed files with 68 additions and 38 deletions
|
@ -284,46 +284,68 @@ Color ColorModeOKHSL::get_color() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorModeOKHSL::slider_draw(int p_which) {
|
void ColorModeOKHSL::slider_draw(int p_which) {
|
||||||
Vector<Vector2> pos;
|
|
||||||
pos.resize(4);
|
|
||||||
Vector<Color> col;
|
|
||||||
col.resize(4);
|
|
||||||
HSlider *slider = color_picker->get_slider(p_which);
|
HSlider *slider = color_picker->get_slider(p_which);
|
||||||
Size2 size = slider->get_size();
|
Size2 size = slider->get_size();
|
||||||
Color left_color;
|
|
||||||
Color right_color;
|
|
||||||
Color color = color_picker->get_pick_color();
|
|
||||||
const real_t margin = 16 * color_picker->get_theme_default_base_scale();
|
const real_t margin = 16 * color_picker->get_theme_default_base_scale();
|
||||||
|
|
||||||
if (p_which == ColorPicker::SLIDER_COUNT) {
|
if (p_which == 0) { // H
|
||||||
slider->draw_texture_rect(color_picker->get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, 0), Size2(size.x, margin)), true);
|
|
||||||
|
|
||||||
left_color = color;
|
|
||||||
left_color.a = 0;
|
|
||||||
right_color = color;
|
|
||||||
right_color.a = 1;
|
|
||||||
} else if (p_which == 0) {
|
|
||||||
Ref<Texture2D> hue = color_picker->get_theme_icon(SNAME("color_hue"), SNAME("ColorPicker"));
|
Ref<Texture2D> hue = color_picker->get_theme_icon(SNAME("color_hue"), SNAME("ColorPicker"));
|
||||||
slider->draw_set_transform(Point2(), -Math_PI / 2, Size2(1.0, 1.0));
|
slider->draw_set_transform(Point2(), -Math_PI / 2, Size2(1.0, 1.0));
|
||||||
slider->draw_texture_rect(hue, Rect2(Vector2(margin * -1, 0), Vector2(margin, size.x)), false);
|
slider->draw_texture_rect(hue, Rect2(Vector2(margin * -1, 0), Vector2(margin, size.x)), false);
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
Color s_col;
|
|
||||||
Color v_col;
|
|
||||||
s_col.set_ok_hsl(color.get_h(), 0, color.get_v());
|
|
||||||
left_color = (p_which == 1) ? s_col : Color(0, 0, 0);
|
|
||||||
s_col.set_ok_hsl(color.get_h(), 1, color.get_v());
|
|
||||||
v_col.set_ok_hsl(color.get_h(), color.get_s(), 1);
|
|
||||||
right_color = (p_which == 1) ? s_col : v_col;
|
|
||||||
}
|
}
|
||||||
col.set(0, left_color);
|
|
||||||
col.set(1, right_color);
|
Vector<Vector2> pos;
|
||||||
col.set(2, right_color);
|
Vector<Color> col;
|
||||||
col.set(3, left_color);
|
Color left_color;
|
||||||
pos.set(0, Vector2(0, 0));
|
Color right_color;
|
||||||
pos.set(1, Vector2(size.x, 0));
|
Color color = color_picker->get_pick_color();
|
||||||
pos.set(2, Vector2(size.x, margin));
|
|
||||||
pos.set(3, Vector2(0, margin));
|
if (p_which == 2) { // L
|
||||||
|
pos.resize(6);
|
||||||
|
col.resize(6);
|
||||||
|
left_color = Color(0, 0, 0);
|
||||||
|
Color middle_color;
|
||||||
|
middle_color.set_ok_hsl(color.get_ok_hsl_h(), color.get_ok_hsl_s(), 0.5);
|
||||||
|
right_color.set_ok_hsl(color.get_ok_hsl_h(), color.get_ok_hsl_s(), 1);
|
||||||
|
|
||||||
|
col.set(0, left_color);
|
||||||
|
col.set(1, middle_color);
|
||||||
|
col.set(2, right_color);
|
||||||
|
col.set(3, right_color);
|
||||||
|
col.set(4, middle_color);
|
||||||
|
col.set(5, left_color);
|
||||||
|
pos.set(0, Vector2(0, 0));
|
||||||
|
pos.set(1, Vector2(size.x * 0.5, 0));
|
||||||
|
pos.set(2, Vector2(size.x, 0));
|
||||||
|
pos.set(3, Vector2(size.x, margin));
|
||||||
|
pos.set(4, Vector2(size.x * 0.5, margin));
|
||||||
|
pos.set(5, Vector2(0, margin));
|
||||||
|
} else { // A / S
|
||||||
|
pos.resize(4);
|
||||||
|
col.resize(4);
|
||||||
|
|
||||||
|
if (p_which == ColorPicker::SLIDER_COUNT) {
|
||||||
|
slider->draw_texture_rect(color_picker->get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, 0), Size2(size.x, margin)), true);
|
||||||
|
|
||||||
|
left_color = color;
|
||||||
|
left_color.a = 0;
|
||||||
|
right_color = color;
|
||||||
|
right_color.a = 1;
|
||||||
|
} else {
|
||||||
|
left_color.set_ok_hsl(color.get_ok_hsl_h(), 0, color.get_ok_hsl_l());
|
||||||
|
right_color.set_ok_hsl(color.get_ok_hsl_h(), 1, color.get_ok_hsl_l());
|
||||||
|
}
|
||||||
|
|
||||||
|
col.set(0, left_color);
|
||||||
|
col.set(1, right_color);
|
||||||
|
col.set(2, right_color);
|
||||||
|
col.set(3, left_color);
|
||||||
|
pos.set(0, Vector2(0, 0));
|
||||||
|
pos.set(1, Vector2(size.x, 0));
|
||||||
|
pos.set(2, Vector2(size.x, margin));
|
||||||
|
pos.set(3, Vector2(0, margin));
|
||||||
|
}
|
||||||
|
|
||||||
slider->draw_polygon(pos, col);
|
slider->draw_polygon(pos, col);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1087,16 +1087,24 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
Vector<Color> colors;
|
Vector<Color> colors;
|
||||||
Color col;
|
Color col;
|
||||||
col.set_ok_hsl(h, s, 1);
|
col.set_ok_hsl(h, s, 1);
|
||||||
points.resize(4);
|
Color col2;
|
||||||
colors.resize(4);
|
col2.set_ok_hsl(h, s, 0.5);
|
||||||
points.set(0, Vector2());
|
Color col3;
|
||||||
points.set(1, Vector2(c->get_size().x, 0));
|
col3.set_ok_hsl(h, s, 0);
|
||||||
|
points.resize(6);
|
||||||
|
colors.resize(6);
|
||||||
|
points.set(0, Vector2(c->get_size().x, 0));
|
||||||
|
points.set(1, Vector2(c->get_size().x, c->get_size().y * 0.5));
|
||||||
points.set(2, c->get_size());
|
points.set(2, c->get_size());
|
||||||
points.set(3, Vector2(0, c->get_size().y));
|
points.set(3, Vector2(0, c->get_size().y));
|
||||||
|
points.set(4, Vector2(0, c->get_size().y * 0.5));
|
||||||
|
points.set(5, Vector2());
|
||||||
colors.set(0, col);
|
colors.set(0, col);
|
||||||
colors.set(1, col);
|
colors.set(1, col2);
|
||||||
colors.set(2, Color(0, 0, 0));
|
colors.set(2, col3);
|
||||||
colors.set(3, Color(0, 0, 0));
|
colors.set(3, col3);
|
||||||
|
colors.set(4, col2);
|
||||||
|
colors.set(5, col);
|
||||||
c->draw_polygon(points, colors);
|
c->draw_polygon(points, colors);
|
||||||
int y = c->get_size().y - c->get_size().y * CLAMP(v, 0, 1);
|
int y = c->get_size().y - c->get_size().y * CLAMP(v, 0, 1);
|
||||||
col.set_ok_hsl(h, 1, v);
|
col.set_ok_hsl(h, 1, v);
|
||||||
|
|
Loading…
Reference in a new issue