@@ -193,19 +193,21 @@ void ColorPicker::init_shaders() {
193
193
194
194
shader_type canvas_item;
195
195
196
+ uniform float wheel_radius = 0.42;
197
+
196
198
void fragment() {
197
199
float x = UV.x - 0.5;
198
200
float y = UV.y - 0.5;
199
201
float a = atan(y, x);
200
202
x += 0.001;
201
203
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 );
203
205
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 );
205
207
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 );
207
209
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 );
209
211
210
212
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);
211
213
}
@@ -1315,70 +1317,46 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
1315
1317
1316
1318
PickerShapeType actual_shape = _get_actual_shape ();
1317
1319
if (p_which == 0 ) {
1318
- Vector<Point2> points;
1319
- Vector<Color> colors;
1320
- Vector<Color> colors2;
1321
1320
Color col = color;
1322
1321
Vector2 center = c->get_size () / 2.0 ;
1323
1322
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;
1331
1338
1332
1339
points.set (0 , center - Vector2 (ring_radius_x, ring_radius_y));
1333
1340
points.set (1 , center + Vector2 (ring_radius_x, -ring_radius_y));
1334
1341
points.set (2 , center + Vector2 (ring_radius_x, ring_radius_y));
1335
1342
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 : {
1381
1343
}
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);
1382
1360
}
1383
1361
1384
1362
int x;
@@ -1393,25 +1371,23 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
1393
1371
x = center.x + hue_offset.x - (theme_cache.picker_cursor ->get_width () / 2 );
1394
1372
y = center.y + hue_offset.y - (theme_cache.picker_cursor ->get_height () / 2 );
1395
1373
} 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 ;
1398
1376
1399
1377
Size2 real_size (c->get_size ().x - corner_x * 2 , c->get_size ().y - corner_y * 2 );
1400
1378
x = CLAMP (real_size.x * s, 0 , real_size.x ) + corner_x - (theme_cache.picker_cursor ->get_width () / 2 );
1401
1379
y = CLAMP (real_size.y - real_size.y * v, 0 , real_size.y ) + corner_y - (theme_cache.picker_cursor ->get_height () / 2 );
1402
1380
}
1381
+ Color _col = color;
1382
+ _col.a = 1.0 ;
1383
+ c->draw_texture (theme_cache.picker_cursor_bg , Point2 (x, y), _col);
1403
1384
c->draw_texture (theme_cache.picker_cursor , Point2 (x, y));
1404
1385
1405
- col.set_hsv (h, 1 , 1 );
1406
1386
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);
1415
1391
}
1416
1392
1417
1393
} else if (p_which == 1 ) {
@@ -2187,6 +2163,7 @@ void ColorPicker::_bind_methods() {
2187
2163
BIND_THEME_ITEM (Theme::DATA_TYPE_ICON, ColorPicker, sample_revert);
2188
2164
BIND_THEME_ITEM (Theme::DATA_TYPE_ICON, ColorPicker, overbright_indicator);
2189
2165
BIND_THEME_ITEM (Theme::DATA_TYPE_ICON, ColorPicker, picker_cursor);
2166
+ BIND_THEME_ITEM (Theme::DATA_TYPE_ICON, ColorPicker, picker_cursor_bg);
2190
2167
BIND_THEME_ITEM (Theme::DATA_TYPE_ICON, ColorPicker, color_hue);
2191
2168
2192
2169
BIND_THEME_ITEM_EXT (Theme::DATA_TYPE_STYLEBOX, ColorPicker, mode_button_normal, " tab_unselected" , " TabContainer" );
@@ -2337,6 +2314,7 @@ ColorPicker::ColorPicker() {
2337
2314
2338
2315
wheel_mat.instantiate ();
2339
2316
wheel_mat->set_shader (wheel_shader);
2317
+ wheel_mat->set_shader_parameter (" wheel_radius" , WHEEL_RADIUS);
2340
2318
circle_mat.instantiate ();
2341
2319
circle_mat->set_shader (circle_shader);
2342
2320
0 commit comments