Fix #99187: Increased Contrast of Transform Cursors

When transforming Objects, like scaling and rotating we see a custom
drawn cursor at the mouse position. In the default theme this is
entirely black, doesn't change with background color, and can be very
hard to see in some circumstances. This PR uses the same colors as the
text overlays and adds a contrasting shadow to help add some contrast.

Pull Request: https://projects.blender.org/blender/blender/pulls/132671
This commit is contained in:
Harley Acheson 2025-01-14 23:01:11 +01:00 committed by Harley Acheson
parent 78090a0ce5
commit 26c15292a7

View file

@ -80,7 +80,7 @@ bool transform_draw_cursor_poll(bContext *C)
return (region && ELEM(region->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW)) ? true : false;
}
void transform_draw_cursor_draw(bContext * /*C*/, int x, int y, void *customdata)
void transform_draw_cursor_draw(bContext *C, int x, int y, void *customdata)
{
TransInfo *t = (TransInfo *)customdata;
@ -105,6 +105,23 @@ void transform_draw_cursor_draw(bContext * /*C*/, int x, int y, void *customdata
float viewport_size[4];
GPU_viewport_size_get_f(viewport_size);
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
float fg_color[4];
float bg_color[4];
if (v3d && scene) {
/* Use overlay colors for 3D Viewport. */
ED_view3d_text_colors_get(scene, v3d, fg_color, bg_color);
}
else {
/* Otherwise editor foreground and background colors. */
UI_GetThemeColor3fv(TH_TEXT_HI, fg_color);
UI_GetThemeColor3fv(TH_BACK, bg_color);
}
fg_color[3] = 1.0f;
bg_color[3] = 0.5f;
GPU_line_smooth(true);
GPU_blend(GPU_BLEND_ALPHA);
const uint pos_id = GPU_vertformat_attr_add(
@ -116,22 +133,34 @@ void transform_draw_cursor_draw(bContext * /*C*/, int x, int y, void *customdata
immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
immUniform1i("colors_len", 0); /* "simple" mode. */
immUniformThemeColor3(TH_VIEW_OVERLAY);
immUniform1f("dash_width", DASH_LENGTH);
immUniform1f("udash_factor", 0.5f);
/* Draw in background color first. */
immUniformColor4fv(bg_color);
immBegin(GPU_PRIM_LINES, 2);
immVertex2fv(pos_id, cent);
immVertex2f(pos_id, tmval[0], tmval[1]);
immEnd();
/* Then foreground over top, shifted slightly. */
immUniformColor4fv(fg_color);
immBegin(GPU_PRIM_LINES, 2);
immVertex2f(pos_id, cent[0] - U.pixelsize, cent[1] + U.pixelsize);
immVertex2f(pos_id, tmval[0] - U.pixelsize, tmval[1] + U.pixelsize);
immEnd();
immUnbindProgram();
}
/* And now, solid lines. */
immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
immUniformThemeColor3(TH_VIEW_OVERLAY);
immUniform2fv("viewportSize", &viewport_size[2]);
immUniform1f("lineWidth", ARROW_WIDTH);
/* First pass is background color and wider lines. */
immUniformColor4fv(bg_color);
immUniform1f("lineWidth", ARROW_WIDTH * 2.0f);
GPU_matrix_push();
GPU_matrix_translate_3f(float(x), float(y), 0.0f);
@ -141,12 +170,24 @@ void transform_draw_cursor_draw(bContext * /*C*/, int x, int y, void *customdata
GPU_matrix_rotate_axis(-RAD2DEGF(atan2f(cent[0] - tmval[0], cent[1] - tmval[1])), 'Z');
drawArrow(pos_id, UP);
drawArrow(pos_id, DOWN);
immUniformColor4fv(fg_color);
immUniform1f("lineWidth", ARROW_WIDTH);
drawArrow(pos_id, UP);
drawArrow(pos_id, DOWN);
break;
case HLP_HARROW:
drawArrow(pos_id, RIGHT);
drawArrow(pos_id, LEFT);
immUniform1f("lineWidth", ARROW_WIDTH);
immUniformColor4fv(fg_color);
drawArrow(pos_id, RIGHT);
drawArrow(pos_id, LEFT);
break;
case HLP_VARROW:
drawArrow(pos_id, UP);
drawArrow(pos_id, DOWN);
immUniform1f("lineWidth", ARROW_WIDTH);
immUniformColor4fv(fg_color);
drawArrow(pos_id, UP);
drawArrow(pos_id, DOWN);
break;
@ -157,6 +198,10 @@ void transform_draw_cursor_draw(bContext * /*C*/, int x, int y, void *customdata
GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z');
drawArrow(pos_id, UP);
drawArrow(pos_id, DOWN);
immUniform1f("lineWidth", ARROW_WIDTH);
immUniformColor4fv(fg_color);
drawArrow(pos_id, UP);
drawArrow(pos_id, DOWN);
break;
}
case HLP_ANGLE: {
@ -164,14 +209,34 @@ void transform_draw_cursor_draw(bContext * /*C*/, int x, int y, void *customdata
float angle = atan2f(tmval[1] - cent[1], tmval[0] - cent[0]);
GPU_matrix_translate_3f(cosf(angle), sinf(angle), 0);
GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z');
immUniform1f("lineWidth", ARROW_WIDTH * 2.0f);
drawArrow(pos_id, DOWN);
immUniformColor4fv(fg_color);
immUniform1f("lineWidth", ARROW_WIDTH);
drawArrow(pos_id, DOWN);
GPU_matrix_pop();
GPU_matrix_translate_3f(cosf(angle), sinf(angle), 0);
GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z');
immUniformColor4fv(bg_color);
immUniform1f("lineWidth", ARROW_WIDTH * 2.0f);
drawArrow(pos_id, UP);
immUniformColor4fv(fg_color);
immUniform1f("lineWidth", ARROW_WIDTH);
drawArrow(pos_id, UP);
break;
}
case HLP_TRACKBALL: {
immUniformColor4fv(bg_color);
GPU_matrix_translate_3f(U.pixelsize, -U.pixelsize, 0.0f);
drawArrow(pos_id, RIGHT);
drawArrow(pos_id, LEFT);
drawArrow(pos_id, UP);
drawArrow(pos_id, DOWN);
GPU_matrix_translate_3f(-U.pixelsize, U.pixelsize, 0.0f);
immUniform1f("lineWidth", ARROW_WIDTH);
uchar col[3], col2[3];
UI_GetThemeColor3ubv(TH_GRID, col);
UI_make_axis_color(col, 'X', col2);