mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
Merge pull request #99662 from beicause/color-picker-wheels-in-okhsl
ColorPicker: Allow other color wheels in okhsl mode
This commit is contained in:
commit
deb9705b77
3 changed files with 16 additions and 26 deletions
|
|
@ -53,7 +53,6 @@ public:
|
||||||
|
|
||||||
virtual void slider_draw(int p_which) = 0;
|
virtual void slider_draw(int p_which) = 0;
|
||||||
virtual bool apply_theme() const { return false; }
|
virtual bool apply_theme() const { return false; }
|
||||||
virtual ColorPicker::PickerShapeType get_shape_override() const { return ColorPicker::SHAPE_MAX; }
|
|
||||||
|
|
||||||
ColorMode(ColorPicker *p_color_picker);
|
ColorMode(ColorPicker *p_color_picker);
|
||||||
virtual ~ColorMode() {}
|
virtual ~ColorMode() {}
|
||||||
|
|
@ -144,7 +143,6 @@ public:
|
||||||
virtual void _value_changed() override;
|
virtual void _value_changed() override;
|
||||||
|
|
||||||
virtual void slider_draw(int p_which) override;
|
virtual void slider_draw(int p_which) override;
|
||||||
virtual ColorPicker::PickerShapeType get_shape_override() const override { return ColorPicker::SHAPE_OKHSL_CIRCLE; }
|
|
||||||
|
|
||||||
ColorModeOKHSL(ColorPicker *p_color_picker) :
|
ColorModeOKHSL(ColorPicker *p_color_picker) :
|
||||||
ColorMode(p_color_picker) {}
|
ColorMode(p_color_picker) {}
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,7 @@ void ColorPicker::_update_controls() {
|
||||||
alpha_label->hide();
|
alpha_label->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_get_actual_shape()) {
|
switch (current_shape) {
|
||||||
case SHAPE_HSV_RECTANGLE:
|
case SHAPE_HSV_RECTANGLE:
|
||||||
wheel_edit->hide();
|
wheel_edit->hide();
|
||||||
w_edit->show();
|
w_edit->show();
|
||||||
|
|
@ -562,7 +562,7 @@ void ColorPicker::_copy_color_to_hsv() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorPicker::_copy_hsv_to_color() {
|
void ColorPicker::_copy_hsv_to_color() {
|
||||||
if (_get_actual_shape() == SHAPE_OKHSL_CIRCLE) {
|
if (current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
color.set_ok_hsl(ok_hsl_h, ok_hsl_s, ok_hsl_l, color.a);
|
color.set_ok_hsl(ok_hsl_h, ok_hsl_s, ok_hsl_l, color.a);
|
||||||
} else {
|
} else {
|
||||||
color.set_hsv(h, s, v, color.a);
|
color.set_hsv(h, s, v, color.a);
|
||||||
|
|
@ -594,10 +594,6 @@ bool ColorPicker::_select_from_recent_preset_hbc(const Color &p_color) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorPicker::PickerShapeType ColorPicker::_get_actual_shape() const {
|
|
||||||
return modes[current_mode]->get_shape_override() != SHAPE_MAX ? modes[current_mode]->get_shape_override() : current_shape;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColorPicker::_reset_sliders_theme() {
|
void ColorPicker::_reset_sliders_theme() {
|
||||||
Ref<StyleBoxFlat> style_box_flat(memnew(StyleBoxFlat));
|
Ref<StyleBoxFlat> style_box_flat(memnew(StyleBoxFlat));
|
||||||
style_box_flat->set_content_margin(SIDE_TOP, 16 * theme_cache.base_scale);
|
style_box_flat->set_content_margin(SIDE_TOP, 16 * theme_cache.base_scale);
|
||||||
|
|
@ -1322,19 +1318,18 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PickerShapeType actual_shape = _get_actual_shape();
|
|
||||||
if (p_which == 0) {
|
if (p_which == 0) {
|
||||||
Color col = color;
|
Color col = color;
|
||||||
Vector2 center = c->get_size() / 2.0;
|
Vector2 center = c->get_size() / 2.0;
|
||||||
|
|
||||||
if (actual_shape == SHAPE_HSV_RECTANGLE || actual_shape == SHAPE_HSV_WHEEL) {
|
if (current_shape == SHAPE_HSV_RECTANGLE || current_shape == SHAPE_HSV_WHEEL) {
|
||||||
Vector<Point2> points;
|
Vector<Point2> points;
|
||||||
Vector<Color> colors;
|
Vector<Color> colors;
|
||||||
Vector<Color> colors2;
|
Vector<Color> colors2;
|
||||||
points.resize(4);
|
points.resize(4);
|
||||||
colors.resize(4);
|
colors.resize(4);
|
||||||
colors2.resize(4);
|
colors2.resize(4);
|
||||||
if (actual_shape == SHAPE_HSV_RECTANGLE) {
|
if (current_shape == SHAPE_HSV_RECTANGLE) {
|
||||||
points.set(0, Vector2());
|
points.set(0, Vector2());
|
||||||
points.set(1, Vector2(c->get_size().x, 0));
|
points.set(1, Vector2(c->get_size().x, 0));
|
||||||
points.set(2, c->get_size());
|
points.set(2, c->get_size());
|
||||||
|
|
@ -1368,9 +1363,9 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
if (actual_shape == SHAPE_VHS_CIRCLE || actual_shape == SHAPE_OKHSL_CIRCLE) {
|
if (current_shape == SHAPE_VHS_CIRCLE || current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
Vector2 hue_offset;
|
Vector2 hue_offset;
|
||||||
if (actual_shape == SHAPE_OKHSL_CIRCLE) {
|
if (current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
hue_offset = center * Vector2(Math::cos(ok_hsl_h * Math_TAU), Math::sin(ok_hsl_h * Math_TAU)) * ok_hsl_s;
|
hue_offset = center * Vector2(Math::cos(ok_hsl_h * Math_TAU), Math::sin(ok_hsl_h * Math_TAU)) * ok_hsl_s;
|
||||||
} else {
|
} else {
|
||||||
hue_offset = center * Vector2(Math::cos(h * Math_TAU), Math::sin(h * Math_TAU)) * s;
|
hue_offset = center * Vector2(Math::cos(h * Math_TAU), Math::sin(h * Math_TAU)) * s;
|
||||||
|
|
@ -1390,7 +1385,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
c->draw_texture(theme_cache.picker_cursor_bg, Point2(x, y), _col);
|
c->draw_texture(theme_cache.picker_cursor_bg, Point2(x, y), _col);
|
||||||
c->draw_texture(theme_cache.picker_cursor, Point2(x, y));
|
c->draw_texture(theme_cache.picker_cursor, Point2(x, y));
|
||||||
|
|
||||||
if (actual_shape == SHAPE_HSV_WHEEL) {
|
if (current_shape == SHAPE_HSV_WHEEL) {
|
||||||
float _radius = WHEEL_RADIUS * 2.0;
|
float _radius = WHEEL_RADIUS * 2.0;
|
||||||
_radius += (1.0 - _radius) * 0.5;
|
_radius += (1.0 - _radius) * 0.5;
|
||||||
Point2 pos = center - (theme_cache.picker_cursor->get_size() * 0.5) + Point2(center.x * Math::cos(h * Math_TAU) * _radius, center.y * Math::sin(h * Math_TAU) * _radius);
|
Point2 pos = center - (theme_cache.picker_cursor->get_size() * 0.5) + Point2(center.x * Math::cos(h * Math_TAU) * _radius, center.y * Math::sin(h * Math_TAU) * _radius);
|
||||||
|
|
@ -1398,7 +1393,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (p_which == 1) {
|
} else if (p_which == 1) {
|
||||||
if (actual_shape == SHAPE_HSV_RECTANGLE) {
|
if (current_shape == SHAPE_HSV_RECTANGLE) {
|
||||||
c->draw_set_transform(Point2(), -Math_PI / 2, Size2(c->get_size().x, -c->get_size().y));
|
c->draw_set_transform(Point2(), -Math_PI / 2, Size2(c->get_size().x, -c->get_size().y));
|
||||||
c->draw_texture_rect(theme_cache.color_hue, Rect2(Point2(), Size2(1, 1)));
|
c->draw_texture_rect(theme_cache.color_hue, Rect2(Point2(), Size2(1, 1)));
|
||||||
c->draw_set_transform(Point2(), 0, Size2(1, 1));
|
c->draw_set_transform(Point2(), 0, Size2(1, 1));
|
||||||
|
|
@ -1406,7 +1401,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
Color col;
|
Color col;
|
||||||
col.set_hsv(h, 1, 1);
|
col.set_hsv(h, 1, 1);
|
||||||
c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
|
c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
|
||||||
} else if (actual_shape == SHAPE_OKHSL_CIRCLE) {
|
} else if (current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
Vector<Point2> points;
|
Vector<Point2> points;
|
||||||
Vector<Color> colors;
|
Vector<Color> colors;
|
||||||
Color col;
|
Color col;
|
||||||
|
|
@ -1433,7 +1428,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
int y = c->get_size().y - c->get_size().y * CLAMP(ok_hsl_l, 0, 1);
|
int y = c->get_size().y - c->get_size().y * CLAMP(ok_hsl_l, 0, 1);
|
||||||
col.set_ok_hsl(ok_hsl_h, 1, ok_hsl_l);
|
col.set_ok_hsl(ok_hsl_h, 1, ok_hsl_l);
|
||||||
c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
|
c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
|
||||||
} else if (actual_shape == SHAPE_VHS_CIRCLE) {
|
} else if (current_shape == SHAPE_VHS_CIRCLE) {
|
||||||
Vector<Point2> points;
|
Vector<Point2> points;
|
||||||
Vector<Color> colors;
|
Vector<Color> colors;
|
||||||
Color col;
|
Color col;
|
||||||
|
|
@ -1455,9 +1450,9 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
|
||||||
}
|
}
|
||||||
} else if (p_which == 2) {
|
} else if (p_which == 2) {
|
||||||
c->draw_rect(Rect2(Point2(), c->get_size()), Color(1, 1, 1));
|
c->draw_rect(Rect2(Point2(), c->get_size()), Color(1, 1, 1));
|
||||||
if (actual_shape == SHAPE_VHS_CIRCLE) {
|
if (current_shape == SHAPE_VHS_CIRCLE) {
|
||||||
circle_mat->set_shader_parameter("v", v);
|
circle_mat->set_shader_parameter("v", v);
|
||||||
} else if (actual_shape == SHAPE_OKHSL_CIRCLE) {
|
} else if (current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
circle_mat->set_shader_parameter("ok_hsl_l", ok_hsl_l);
|
circle_mat->set_shader_parameter("ok_hsl_l", ok_hsl_l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1471,12 +1466,11 @@ void ColorPicker::_slider_draw(int p_which) {
|
||||||
|
|
||||||
void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
|
void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
|
||||||
Ref<InputEventMouseButton> bev = p_event;
|
Ref<InputEventMouseButton> bev = p_event;
|
||||||
PickerShapeType actual_shape = _get_actual_shape();
|
|
||||||
|
|
||||||
if (bev.is_valid()) {
|
if (bev.is_valid()) {
|
||||||
if (bev->is_pressed() && bev->get_button_index() == MouseButton::LEFT) {
|
if (bev->is_pressed() && bev->get_button_index() == MouseButton::LEFT) {
|
||||||
Vector2 center = c->get_size() / 2.0;
|
Vector2 center = c->get_size() / 2.0;
|
||||||
if (actual_shape == SHAPE_VHS_CIRCLE || actual_shape == SHAPE_OKHSL_CIRCLE) {
|
if (current_shape == SHAPE_VHS_CIRCLE || current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
real_t dist = center.distance_to(bev->get_position());
|
real_t dist = center.distance_to(bev->get_position());
|
||||||
if (dist <= center.x) {
|
if (dist <= center.x) {
|
||||||
real_t rad = center.angle_to_point(bev->get_position());
|
real_t rad = center.angle_to_point(bev->get_position());
|
||||||
|
|
@ -1546,7 +1540,7 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 center = c->get_size() / 2.0;
|
Vector2 center = c->get_size() / 2.0;
|
||||||
if (actual_shape == SHAPE_VHS_CIRCLE || actual_shape == SHAPE_OKHSL_CIRCLE) {
|
if (current_shape == SHAPE_VHS_CIRCLE || current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
real_t dist = center.distance_to(mev->get_position());
|
real_t dist = center.distance_to(mev->get_position());
|
||||||
real_t rad = center.angle_to_point(mev->get_position());
|
real_t rad = center.angle_to_point(mev->get_position());
|
||||||
h = ((rad >= 0) ? rad : (Math_TAU + rad)) / Math_TAU;
|
h = ((rad >= 0) ? rad : (Math_TAU + rad)) / Math_TAU;
|
||||||
|
|
@ -1582,13 +1576,12 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) {
|
||||||
|
|
||||||
void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
|
void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
|
||||||
Ref<InputEventMouseButton> bev = p_event;
|
Ref<InputEventMouseButton> bev = p_event;
|
||||||
PickerShapeType actual_shape = _get_actual_shape();
|
|
||||||
|
|
||||||
if (bev.is_valid()) {
|
if (bev.is_valid()) {
|
||||||
if (bev->is_pressed() && bev->get_button_index() == MouseButton::LEFT) {
|
if (bev->is_pressed() && bev->get_button_index() == MouseButton::LEFT) {
|
||||||
changing_color = true;
|
changing_color = true;
|
||||||
float y = CLAMP((float)bev->get_position().y, 0, w_edit->get_size().height);
|
float y = CLAMP((float)bev->get_position().y, 0, w_edit->get_size().height);
|
||||||
if (actual_shape == SHAPE_VHS_CIRCLE || actual_shape == SHAPE_OKHSL_CIRCLE) {
|
if (current_shape == SHAPE_VHS_CIRCLE || current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
v = 1.0 - (y / w_edit->get_size().height);
|
v = 1.0 - (y / w_edit->get_size().height);
|
||||||
ok_hsl_l = v;
|
ok_hsl_l = v;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1617,7 +1610,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float y = CLAMP((float)mev->get_position().y, 0, w_edit->get_size().height);
|
float y = CLAMP((float)mev->get_position().y, 0, w_edit->get_size().height);
|
||||||
if (actual_shape == SHAPE_VHS_CIRCLE || actual_shape == SHAPE_OKHSL_CIRCLE) {
|
if (current_shape == SHAPE_VHS_CIRCLE || current_shape == SHAPE_OKHSL_CIRCLE) {
|
||||||
v = 1.0 - (y / w_edit->get_size().height);
|
v = 1.0 - (y / w_edit->get_size().height);
|
||||||
ok_hsl_l = v;
|
ok_hsl_l = v;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,6 @@ private:
|
||||||
void _copy_color_to_hsv();
|
void _copy_color_to_hsv();
|
||||||
void _copy_hsv_to_color();
|
void _copy_hsv_to_color();
|
||||||
|
|
||||||
PickerShapeType _get_actual_shape() const;
|
|
||||||
void create_slider(GridContainer *gc, int idx);
|
void create_slider(GridContainer *gc, int idx);
|
||||||
void _reset_sliders_theme();
|
void _reset_sliders_theme();
|
||||||
void _html_submitted(const String &p_html);
|
void _html_submitted(const String &p_html);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue