From 9db102a5300df7e24cdb83c30bf3c21441505b29 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Wed, 23 Oct 2024 02:26:18 -0400 Subject: [PATCH] Unify `ColorPicker` HSV Rectangle/Wheel draw (cherry picked from commit blazium-engine/blazium@f7c6762df94867d93465612ec6be86b28593dc47) Co-authored-by: Mounir Tohami <53877170+WhalesState@users.noreply.github.com> --- scene/gui/color_picker.cpp | 71 ++++++++++++-------------------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index d4e40e284f5..802301c8be2 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -1138,16 +1138,13 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { PickerShapeType actual_shape = _get_actual_shape(); if (p_which == 0) { Vector points; - Vector colors; - Vector colors2; Color col = color; Vector2 center = c->get_size() / 2.0; - switch (actual_shape) { - case SHAPE_HSV_WHEEL: { - points.resize(4); - colors.resize(4); - colors2.resize(4); + if (current_shape == SHAPE_HSV_RECTANGLE || current_shape == SHAPE_HSV_WHEEL) { + points.resize(4); + Vector colors2; + if (current_shape == SHAPE_HSV_WHEEL) { real_t ring_radius_x = Math_SQRT12 * c->get_size().width * 0.42; real_t ring_radius_y = Math_SQRT12 * c->get_size().height * 0.42; @@ -1155,52 +1152,30 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { points.set(1, center + Vector2(ring_radius_x, -ring_radius_y)); points.set(2, center + Vector2(ring_radius_x, ring_radius_y)); points.set(3, center + Vector2(-ring_radius_x, ring_radius_y)); - colors.set(0, Color(1, 1, 1, 1)); - colors.set(1, Color(1, 1, 1, 1)); - colors.set(2, Color(0, 0, 0, 1)); - colors.set(3, Color(0, 0, 0, 1)); - c->draw_polygon(points, colors); - - col.set_hsv(h, 1, 1); - col.a = 0; - colors2.set(0, col); - col.a = 1; - colors2.set(1, col); - col.set_hsv(h, 1, 0); - colors2.set(2, col); - col.a = 0; - colors2.set(3, col); - c->draw_polygon(points, colors2); - break; - } - case SHAPE_HSV_RECTANGLE: { - points.resize(4); - colors.resize(4); - colors2.resize(4); + } else { points.set(0, Vector2()); points.set(1, Vector2(c->get_size().x, 0)); points.set(2, c->get_size()); points.set(3, Vector2(0, c->get_size().y)); - colors.set(0, Color(1, 1, 1, 1)); - colors.set(1, Color(1, 1, 1, 1)); - colors.set(2, Color(0, 0, 0, 1)); - colors.set(3, Color(0, 0, 0, 1)); - c->draw_polygon(points, colors); - col = color; - col.set_hsv(h, 1, 1); - col.a = 0; - colors2.set(0, col); - col.a = 1; - colors2.set(1, col); - col.set_hsv(h, 1, 0); - colors2.set(2, col); - col.a = 0; - colors2.set(3, col); - c->draw_polygon(points, colors2); - break; - } - default: { } + Vector colors = { + Color(1, 1, 1, 1), + Color(1, 1, 1, 1), + Color(0, 0, 0, 1), + Color(0, 0, 0, 1) + }; + c->draw_polygon(points, colors); + + col.set_hsv(h, 1, 1); + col.a = 0; + colors2.append(col); + col.a = 1; + colors2.append(col); + col.set_hsv(h, 1, 0); + colors2.append(col); + col.a = 0; + colors2.append(col); + c->draw_polygon(points, colors2); } int x;