@@ -193,19 +193,21 @@ void ColorPicker::init_shaders() {
193193
194194shader_type canvas_item;
195195
196+ uniform float wheel_radius = 0.42;
197+
196198void fragment() {
197199 float x = UV.x - 0.5;
198200 float y = UV.y - 0.5;
199201 float a = atan(y, x);
200202 x += 0.001;
201203 y += 0.001;
202- float b = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42 );
204+ float b = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > wheel_radius );
203205 x -= 0.002;
204- float b2 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42 );
206+ float b2 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > wheel_radius );
205207 y -= 0.002;
206- float b3 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42 );
208+ float b3 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > wheel_radius );
207209 x += 0.002;
208- float b4 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42 );
210+ float b4 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > wheel_radius );
209211
210212 COLOR = vec4(clamp((abs(fract(((a - TAU) / TAU) + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0) - 1.0), 0.0, 1.0), (b + b2 + b3 + b4) / 4.00);
211213}
@@ -1315,70 +1317,46 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
13151317
13161318 PickerShapeType actual_shape = _get_actual_shape();
13171319 if (p_which == 0) {
1318- Vector<Point2> points;
1319- Vector<Color> colors;
1320- Vector<Color> colors2;
13211320 Color col = color;
13221321 Vector2 center = c->get_size() / 2.0;
13231322
1324- switch (actual_shape) {
1325- case SHAPE_HSV_WHEEL: {
1326- points.resize(4);
1327- colors.resize(4);
1328- colors2.resize(4);
1329- real_t ring_radius_x = Math_SQRT12 * c->get_size().width * 0.42;
1330- real_t ring_radius_y = Math_SQRT12 * c->get_size().height * 0.42;
1323+ if (actual_shape == SHAPE_HSV_RECTANGLE || actual_shape == SHAPE_HSV_WHEEL) {
1324+ Vector<Point2> points;
1325+ Vector<Color> colors;
1326+ Vector<Color> colors2;
1327+ points.resize(4);
1328+ colors.resize(4);
1329+ colors2.resize(4);
1330+ if (actual_shape == SHAPE_HSV_RECTANGLE) {
1331+ points.set(0, Vector2());
1332+ points.set(1, Vector2(c->get_size().x, 0));
1333+ points.set(2, c->get_size());
1334+ points.set(3, Vector2(0, c->get_size().y));
1335+ } else {
1336+ real_t ring_radius_x = Math_SQRT12 * c->get_size().width * WHEEL_RADIUS;
1337+ real_t ring_radius_y = Math_SQRT12 * c->get_size().height * WHEEL_RADIUS;
13311338
13321339 points.set(0, center - Vector2(ring_radius_x, ring_radius_y));
13331340 points.set(1, center + Vector2(ring_radius_x, -ring_radius_y));
13341341 points.set(2, center + Vector2(ring_radius_x, ring_radius_y));
13351342 points.set(3, center + Vector2(-ring_radius_x, ring_radius_y));
1336- colors.set(0, Color(1, 1, 1, 1));
1337- colors.set(1, Color(1, 1, 1, 1));
1338- colors.set(2, Color(0, 0, 0, 1));
1339- colors.set(3, Color(0, 0, 0, 1));
1340- c->draw_polygon(points, colors);
1341-
1342- col.set_hsv(h, 1, 1);
1343- col.a = 0;
1344- colors2.set(0, col);
1345- col.a = 1;
1346- colors2.set(1, col);
1347- col.set_hsv(h, 1, 0);
1348- colors2.set(2, col);
1349- col.a = 0;
1350- colors2.set(3, col);
1351- c->draw_polygon(points, colors2);
1352- break;
1353- }
1354- case SHAPE_HSV_RECTANGLE: {
1355- points.resize(4);
1356- colors.resize(4);
1357- colors2.resize(4);
1358- points.set(0, Vector2());
1359- points.set(1, Vector2(c->get_size().x, 0));
1360- points.set(2, c->get_size());
1361- points.set(3, Vector2(0, c->get_size().y));
1362- colors.set(0, Color(1, 1, 1, 1));
1363- colors.set(1, Color(1, 1, 1, 1));
1364- colors.set(2, Color(0, 0, 0, 1));
1365- colors.set(3, Color(0, 0, 0, 1));
1366- c->draw_polygon(points, colors);
1367- col = color;
1368- col.set_hsv(h, 1, 1);
1369- col.a = 0;
1370- colors2.set(0, col);
1371- col.a = 1;
1372- colors2.set(1, col);
1373- col.set_hsv(h, 1, 0);
1374- colors2.set(2, col);
1375- col.a = 0;
1376- colors2.set(3, col);
1377- c->draw_polygon(points, colors2);
1378- break;
1379- }
1380- default: {
13811343 }
1344+ colors.set(0, Color(1, 1, 1, 1));
1345+ colors.set(1, Color(1, 1, 1, 1));
1346+ colors.set(2, Color(0, 0, 0, 1));
1347+ colors.set(3, Color(0, 0, 0, 1));
1348+ c->draw_polygon(points, colors);
1349+
1350+ col.set_hsv(h, 1, 1);
1351+ col.a = 0;
1352+ colors2.set(0, col);
1353+ col.a = 1;
1354+ colors2.set(1, col);
1355+ col.set_hsv(h, 1, 0);
1356+ colors2.set(2, col);
1357+ col.a = 0;
1358+ colors2.set(3, col);
1359+ c->draw_polygon(points, colors2);
13821360 }
13831361
13841362 int x;
@@ -1393,25 +1371,23 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
13931371 x = center.x + hue_offset.x - (theme_cache.picker_cursor->get_width() / 2);
13941372 y = center.y + hue_offset.y - (theme_cache.picker_cursor->get_height() / 2);
13951373 } else {
1396- real_t corner_x = (c == wheel_uv) ? center.x - Math_SQRT12 * c->get_size().width * 0.42 : 0;
1397- real_t corner_y = (c == wheel_uv) ? center.y - Math_SQRT12 * c->get_size().height * 0.42 : 0;
1374+ real_t corner_x = (c == wheel_uv) ? center.x - Math_SQRT12 * c->get_size().width * WHEEL_RADIUS : 0;
1375+ real_t corner_y = (c == wheel_uv) ? center.y - Math_SQRT12 * c->get_size().height * WHEEL_RADIUS : 0;
13981376
13991377 Size2 real_size(c->get_size().x - corner_x * 2, c->get_size().y - corner_y * 2);
14001378 x = CLAMP(real_size.x * s, 0, real_size.x) + corner_x - (theme_cache.picker_cursor->get_width() / 2);
14011379 y = CLAMP(real_size.y - real_size.y * v, 0, real_size.y) + corner_y - (theme_cache.picker_cursor->get_height() / 2);
14021380 }
1381+ Color _col = color;
1382+ _col.a = 1.0;
1383+ c->draw_texture(theme_cache.picker_cursor_bg, Point2(x, y), _col);
14031384 c->draw_texture(theme_cache.picker_cursor, Point2(x, y));
14041385
1405- col.set_hsv(h, 1, 1);
14061386 if (actual_shape == SHAPE_HSV_WHEEL) {
1407- points.resize(4);
1408- double h1 = h - (0.5 / 360);
1409- double h2 = h + (0.5 / 360);
1410- points.set(0, Point2(center.x + (center.x * Math::cos(h1 * Math_TAU)), center.y + (center.y * Math::sin(h1 * Math_TAU))));
1411- points.set(1, Point2(center.x + (center.x * Math::cos(h1 * Math_TAU) * 0.84), center.y + (center.y * Math::sin(h1 * Math_TAU) * 0.84)));
1412- points.set(2, Point2(center.x + (center.x * Math::cos(h2 * Math_TAU)), center.y + (center.y * Math::sin(h2 * Math_TAU))));
1413- points.set(3, Point2(center.x + (center.x * Math::cos(h2 * Math_TAU) * 0.84), center.y + (center.y * Math::sin(h2 * Math_TAU) * 0.84)));
1414- c->draw_multiline(points, col.inverted());
1387+ float _radius = WHEEL_RADIUS * 2.0;
1388+ _radius += (1.0 - _radius) * 0.5;
1389+ 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);
1390+ c->draw_texture(theme_cache.picker_cursor, pos);
14151391 }
14161392
14171393 } else if (p_which == 1) {
@@ -2187,6 +2163,7 @@ void ColorPicker::_bind_methods() {
21872163 BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, sample_revert);
21882164 BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, overbright_indicator);
21892165 BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, picker_cursor);
2166+ BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, picker_cursor_bg);
21902167 BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ColorPicker, color_hue);
21912168
21922169 BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, ColorPicker, mode_button_normal, "tab_unselected", "TabContainer");
@@ -2337,6 +2314,7 @@ ColorPicker::ColorPicker() {
23372314
23382315 wheel_mat.instantiate();
23392316 wheel_mat->set_shader(wheel_shader);
2317+ wheel_mat->set_shader_parameter("wheel_radius", WHEEL_RADIUS);
23402318 circle_mat.instantiate();
23412319 circle_mat->set_shader(circle_shader);
23422320
0 commit comments