Skip to content

Commit

Permalink
Unify ColorPicker HSV Rectangle/Wheel draw
Browse files Browse the repository at this point in the history
(cherry picked from commit blazium-engine/blazium@f7c6762)

Co-authored-by: Mounir Tohami <53877170+WhalesState@users.noreply.github.com>
  • Loading branch information
Spartan322 and WhalesState committed Oct 23, 2024
1 parent 3a91796 commit 9db102a
Showing 1 changed file with 23 additions and 48 deletions.
71 changes: 23 additions & 48 deletions scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,69 +1138,44 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
PickerShapeType actual_shape = _get_actual_shape();
if (p_which == 0) {
Vector<Point2> points;
Vector<Color> colors;
Vector<Color> 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<Color> 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;

points.set(0, center - Vector2(ring_radius_x, ring_radius_y));
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<Color> 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;
Expand Down

0 comments on commit 9db102a

Please sign in to comment.