From abf3f6b88a64c24fc5ca7ffb4521d4f25dbb909b Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Sun, 15 Oct 2023 15:37:02 -0700 Subject: [PATCH 1/5] WIP: UI: Color Picker Position Indication Changes to how the current positions in the color picker are shown. --- .../editors/interface/interface_widgets.cc | 113 +++++++++++------- 1 file changed, 67 insertions(+), 46 deletions(-) diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index db45dedb23e..ed62c2f84b9 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -2910,25 +2910,36 @@ static void widget_menu_back( GPU_blend(GPU_BLEND_NONE); } -static void ui_hsv_cursor(const float x, const float y, const float zoom) +static void ui_hsv_cursor( + const float x, const float y, const float zoom, const float rgb[3], const float hsv[3]) { - const float radius = zoom * 3.0f * U.pixelsize; - const uint pos = GPU_vertformat_attr_add( - immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - - immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - - immUniformColor3f(1.0f, 1.0f, 1.0f); - imm_draw_circle_fill_2d(pos, x, y, radius, 8); + const float radius = zoom * ((14.0f * UI_SCALE_FAC) + U.pixelsize); + float fg = MIN2(1.0f - hsv[2] + 0.2, 0.8f); + float bg = hsv[2] / 2.0f; GPU_blend(GPU_BLEND_ALPHA); - GPU_line_smooth(true); - immUniformColor3f(0.0f, 0.0f, 0.0f); - imm_draw_circle_wire_2d(pos, x, y, radius, 12); - GPU_blend(GPU_BLEND_NONE); - GPU_line_smooth(false); + const uint pos = GPU_vertformat_attr_add( + immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + GPU_program_point_size(true); + immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA); + immUniformColor3fv(rgb); + immUniform1f("outlineWidth", U.pixelsize); + + immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, bg); + immUniform1f("size", radius); + immBegin(GPU_PRIM_POINTS, 1); + immVertex2f(pos, x, y); + immEnd(); + + immUniform4f("outlineColor", 1.0f, 1.0f, 1.0f, fg); + immUniform1f("size", radius - 1.0f); + immBegin(GPU_PRIM_POINTS, 1); + immVertex2f(pos, x, y); + immEnd(); immUnbindProgram(); + GPU_program_point_size(false); + GPU_blend(GPU_BLEND_NONE); } void ui_hsvcircle_vals_from_pos( @@ -3072,7 +3083,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const float xpos, ypos; ui_hsvcircle_pos_from_vals(cpicker, rect, hsv, &xpos, &ypos); const float zoom = 1.0f / but->block->aspect; - ui_hsv_cursor(xpos, ypos, zoom); + ui_hsv_cursor(xpos, ypos, zoom, rgb, hsv); } /** \} */ @@ -3304,13 +3315,9 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect) ui_draw_gradient(rect, hsv_n, hsv_but->gradient_type, 1.0f); ui_hsvcube_pos_from_vals(hsv_but, rect, hsv_n, &x, &y); - CLAMP(x, rect->xmin + 3.0f, rect->xmax - 3.0f); - CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f); const float zoom = 1.0f / but->block->aspect; - ui_hsv_cursor(x, y, zoom); - /* outline */ const uint pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -3318,6 +3325,32 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect) immUniformColor3ub(0, 0, 0); imm_draw_box_wire_2d(pos, (rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax)); immUnbindProgram(); + + if (BLI_rcti_size_x(rect) / BLI_rcti_size_y(rect) < 3) { + float margin = (4.0f * UI_SCALE_FAC); + CLAMP(x, rect->xmin + margin, rect->xmax - margin); + CLAMP(y, rect->ymin + margin, rect->ymax - margin); + ui_hsv_cursor(x, y, zoom, rgb, hsv); + } + else { + rctf rectf; + BLI_rctf_rcti_copy(&rectf, rect); + float margin = (2.0f * UI_SCALE_FAC); + CLAMP(x, rect->xmin + margin, rect->xmax - margin); + CLAMP(y, rect->ymin + margin, rect->ymax - margin); + + rectf.ymax += 1; + rectf.xmin = x - (4.0f * UI_SCALE_FAC) - U.pixelsize; + rectf.xmax = x + (4.0f * UI_SCALE_FAC) + U.pixelsize; + float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + UI_draw_roundbox_4fv(&rectf, false, 0, col); + + rectf.xmin += 1.0f; + rectf.xmax -= 1.0f; + float inner[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + float col2[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + UI_draw_roundbox_4fv_ex(&rectf, col2, nullptr, 0.0f, inner, U.pixelsize, 0.0f); + } } /* vertical 'value' slider, using new widget code */ @@ -3348,38 +3381,26 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) v = (v - min) / (max - min); } - widget_init(&wtb); + rctf rectf; + BLI_rctf_rcti_copy(&rectf, rect); - /* fully rounded */ - round_box_edges(&wtb, UI_CNR_ALL, rect, rad); - - /* setup temp colors */ - uiWidgetColors colors{}; - colors.outline[0] = 0; - colors.outline[1] = 0; - colors.outline[2] = 0; - colors.outline[3] = 255; - colors.inner[0] = 128; - colors.inner[1] = 128; - colors.inner[2] = 128; - colors.inner[3] = 255; - colors.shadetop = 127; - colors.shadedown = -128; - colors.shaded = 1; - widgetbase_draw(&wtb, &colors); - - /* We are drawing on top of widget bases. Flush cache. */ - GPU_blend(GPU_BLEND_ALPHA); - UI_widgetbase_draw_cache_flush(); - GPU_blend(GPU_BLEND_NONE); + float inner1[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + float inner2[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + float outline[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + UI_draw_roundbox_4fv_ex(&rectf, inner1, inner2, U.pixelsize, outline, 1.0f, 0.0f); /* cursor */ - x = rect->xmin + 0.5f * BLI_rcti_size_x(rect); y = rect->ymin + v * BLI_rcti_size_y(rect); - CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f); - const float zoom = 1.0f / but->block->aspect; - ui_hsv_cursor(x, y, zoom); + rectf.ymin = y - (4.0f * UI_SCALE_FAC) - U.pixelsize; + rectf.ymax = y + (4.0f * UI_SCALE_FAC) + U.pixelsize; + float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + UI_draw_roundbox_4fv(&rectf, false, 0, col); + + rectf.ymin += 1.0f; + rectf.ymax -= 1.0f; + float col2[4] = {v, v, v, 1.0f}; + UI_draw_roundbox_4fv_ex(&rectf, col2, nullptr, 0.0f, inner1, U.pixelsize, 0.0f); } /** Separator for menus. */ -- 2.30.2 From 81e79b63ea4ebb1a984865ea9caef3beaa52703e Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 16 Nov 2023 10:33:59 -0800 Subject: [PATCH 2/5] Add active state changes --- .../editors/interface/interface_widgets.cc | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index ee192ed794e..0821e2df4e3 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -2909,10 +2909,14 @@ static void widget_menu_back( GPU_blend(GPU_BLEND_NONE); } -static void ui_hsv_cursor( - const float x, const float y, const float zoom, const float rgb[3], const float hsv[3]) +static void ui_hsv_cursor(const float x, + const float y, + const float zoom, + const float rgb[3], + const float hsv[3], + const bool is_active) { - const float radius = zoom * ((14.0f * UI_SCALE_FAC) + U.pixelsize); + const float radius = zoom * (((is_active ? 20.0f : 12.0f) * UI_SCALE_FAC) + U.pixelsize); float fg = MIN2(1.0f - hsv[2] + 0.2, 0.8f); float bg = hsv[2] / 2.0f; @@ -3082,7 +3086,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const float xpos, ypos; ui_hsvcircle_pos_from_vals(cpicker, rect, hsv, &xpos, &ypos); const float zoom = 1.0f / but->block->aspect; - ui_hsv_cursor(xpos, ypos, zoom, rgb, hsv); + ui_hsv_cursor(xpos, ypos, zoom, rgb, hsv, but->flag & UI_SELECT); } /** \} */ @@ -3329,7 +3333,7 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect) float margin = (4.0f * UI_SCALE_FAC); CLAMP(x, rect->xmin + margin, rect->xmax - margin); CLAMP(y, rect->ymin + margin, rect->ymax - margin); - ui_hsv_cursor(x, y, zoom, rgb, hsv); + ui_hsv_cursor(x, y, zoom, rgb, hsv, but->flag & UI_SELECT); } else { rctf rectf; @@ -3337,10 +3341,17 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect) float margin = (2.0f * UI_SCALE_FAC); CLAMP(x, rect->xmin + margin, rect->xmax - margin); CLAMP(y, rect->ymin + margin, rect->ymax - margin); - rectf.ymax += 1; rectf.xmin = x - (4.0f * UI_SCALE_FAC) - U.pixelsize; rectf.xmax = x + (4.0f * UI_SCALE_FAC) + U.pixelsize; + + if (but->flag & UI_SELECT) { + rectf.xmin -= U.pixelsize; + rectf.xmax += U.pixelsize; + rectf.ymin -= U.pixelsize; + rectf.ymax += U.pixelsize; + } + float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; UI_draw_roundbox_4fv(&rectf, false, 0, col); @@ -3390,10 +3401,17 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) /* cursor */ y = rect->ymin + v * BLI_rcti_size_y(rect); - rectf.ymin = y - (4.0f * UI_SCALE_FAC) - U.pixelsize; rectf.ymax = y + (4.0f * UI_SCALE_FAC) + U.pixelsize; float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + + if (but->flag & UI_SELECT) { + rectf.xmin -= U.pixelsize; + rectf.xmax += U.pixelsize; + rectf.ymin -= U.pixelsize; + rectf.ymax += U.pixelsize; + } + UI_draw_roundbox_4fv(&rectf, false, 0, col); rectf.ymin += 1.0f; -- 2.30.2 From c3343398d83f3e56034f51bd8d96a31fd1f32cd2 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 17 Nov 2023 08:35:55 -0800 Subject: [PATCH 3/5] Comment changes. Const vars. --- .../editors/interface/interface_widgets.cc | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index 0821e2df4e3..8ee5a8200cc 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -2916,9 +2916,8 @@ static void ui_hsv_cursor(const float x, const float hsv[3], const bool is_active) { + /* Draw the circle larger while the mouse button is pressed down. */ const float radius = zoom * (((is_active ? 20.0f : 12.0f) * UI_SCALE_FAC) + U.pixelsize); - float fg = MIN2(1.0f - hsv[2] + 0.2, 0.8f); - float bg = hsv[2] / 2.0f; GPU_blend(GPU_BLEND_ALPHA); const uint pos = GPU_vertformat_attr_add( @@ -2928,6 +2927,10 @@ static void ui_hsv_cursor(const float x, immUniformColor3fv(rgb); immUniform1f("outlineWidth", U.pixelsize); + /* Alpha of outline colors just strong enough to give good contrast. */ + const float fg = MIN2(1.0f - hsv[2] + 0.2, 0.8f); + const float bg = hsv[2] / 2.0f; + immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, bg); immUniform1f("size", radius); immBegin(GPU_PRIM_POINTS, 1); @@ -3330,15 +3333,17 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect) immUnbindProgram(); if (BLI_rcti_size_x(rect) / BLI_rcti_size_y(rect) < 3) { + /* This is for the full square HSV cube. */ float margin = (4.0f * UI_SCALE_FAC); CLAMP(x, rect->xmin + margin, rect->xmax - margin); CLAMP(y, rect->ymin + margin, rect->ymax - margin); ui_hsv_cursor(x, y, zoom, rgb, hsv, but->flag & UI_SELECT); } else { + /* This is for the narrow horizontal gradient. */ rctf rectf; BLI_rctf_rcti_copy(&rectf, rect); - float margin = (2.0f * UI_SCALE_FAC); + const float margin = (2.0f * UI_SCALE_FAC); CLAMP(x, rect->xmin + margin, rect->xmax - margin); CLAMP(y, rect->ymin + margin, rect->ymax - margin); rectf.ymax += 1; @@ -3346,19 +3351,20 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect) rectf.xmax = x + (4.0f * UI_SCALE_FAC) + U.pixelsize; if (but->flag & UI_SELECT) { + /* Make the indicator larger while the mouse button is pressed. */ rectf.xmin -= U.pixelsize; rectf.xmax += U.pixelsize; rectf.ymin -= U.pixelsize; rectf.ymax += U.pixelsize; } - float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + const float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; UI_draw_roundbox_4fv(&rectf, false, 0, col); rectf.xmin += 1.0f; rectf.xmax -= 1.0f; - float inner[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - float col2[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + const float inner[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + const float col2[4] = {0.0f, 0.0f, 0.0f, 0.0f}; UI_draw_roundbox_4fv_ex(&rectf, col2, nullptr, 0.0f, inner, U.pixelsize, 0.0f); } } @@ -3394,9 +3400,9 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) rctf rectf; BLI_rctf_rcti_copy(&rectf, rect); - float inner1[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - float inner2[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - float outline[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + const float inner1[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + const float inner2[4] = {0.0f, 0.0f, 0.0f, 1.0f}; + const float outline[4] = {0.0f, 0.0f, 0.0f, 1.0f}; UI_draw_roundbox_4fv_ex(&rectf, inner1, inner2, U.pixelsize, outline, 1.0f, 0.0f); /* cursor */ @@ -3406,6 +3412,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; if (but->flag & UI_SELECT) { + /* Enlarge the indicator while the mouse button is pressed down. */ rectf.xmin -= U.pixelsize; rectf.xmax += U.pixelsize; rectf.ymin -= U.pixelsize; @@ -3416,7 +3423,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) rectf.ymin += 1.0f; rectf.ymax -= 1.0f; - float col2[4] = {v, v, v, 1.0f}; + const float col2[4] = {v, v, v, 1.0f}; UI_draw_roundbox_4fv_ex(&rectf, col2, nullptr, 0.0f, inner1, U.pixelsize, 0.0f); } -- 2.30.2 From e76e9af23624cf564f1c06733416ccd6696a7bce Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 17 Nov 2023 09:38:19 -0800 Subject: [PATCH 4/5] unused vars. --- source/blender/editors/interface/interface_widgets.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index 8ee5a8200cc..a6ccb65abba 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -3375,9 +3375,6 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) const uiButHSVCube *hsv_but = (uiButHSVCube *)but; bTheme *btheme = UI_GetTheme(); uiWidgetColors *wcol = &btheme->tui.wcol_numslider; - uiWidgetBase wtb; - const float rad = wcol->roundness * BLI_rcti_size_x(rect); - float x, y; float rgb[3], hsv[3], v; ui_but_v3_get(but, rgb); @@ -3406,7 +3403,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) UI_draw_roundbox_4fv_ex(&rectf, inner1, inner2, U.pixelsize, outline, 1.0f, 0.0f); /* cursor */ - y = rect->ymin + v * BLI_rcti_size_y(rect); + const float y = rect->ymin + v * BLI_rcti_size_y(rect); rectf.ymin = y - (4.0f * UI_SCALE_FAC) - U.pixelsize; rectf.ymax = y + (4.0f * UI_SCALE_FAC) + U.pixelsize; float col[4] = {0.0f, 0.0f, 0.0f, 1.0f}; @@ -3419,7 +3416,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) rectf.ymax += U.pixelsize; } - UI_draw_roundbox_4fv(&rectf, false, 0, col); + UI_draw_roundbox_4fv(&rectf, false, 0.0f, col); rectf.ymin += 1.0f; rectf.ymax -= 1.0f; -- 2.30.2 From a775b995783b6970e8e50e8ecfd174847cb166fa Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 17 Nov 2023 10:12:34 -0800 Subject: [PATCH 5/5] more unused vars. --- source/blender/editors/interface/interface_widgets.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/blender/editors/interface/interface_widgets.cc b/source/blender/editors/interface/interface_widgets.cc index a6ccb65abba..9fdc06f1a3e 100644 --- a/source/blender/editors/interface/interface_widgets.cc +++ b/source/blender/editors/interface/interface_widgets.cc @@ -3373,8 +3373,6 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect) static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect) { const uiButHSVCube *hsv_but = (uiButHSVCube *)but; - bTheme *btheme = UI_GetTheme(); - uiWidgetColors *wcol = &btheme->tui.wcol_numslider; float rgb[3], hsv[3], v; ui_but_v3_get(but, rgb); -- 2.30.2