From a1e01f4c026a389b94985b19678a0c69745ca248 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 2 Sep 2022 13:18:09 -0700 Subject: UI: 3D Text Caret Changes to the text caret (cursor) when editing Text objects in the 3D Viewport. See D15797 for more details and examples. Differential Revision: https://developer.blender.org/D15797 Reviewed by Brecht Van Lommel --- source/blender/blenkernel/intern/vfont.c | 19 +++++----- .../draw/engines/overlay/overlay_edit_text.c | 44 +++++++++++++++------- .../blender/draw/engines/overlay/overlay_private.h | 11 ++++-- source/blender/editors/include/UI_resources.h | 2 + source/blender/editors/interface/resources.c | 6 +++ 5 files changed, 55 insertions(+), 27 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/vfont.c b/source/blender/blenkernel/intern/vfont.c index 9a6f861eae8..e016cf8db84 100644 --- a/source/blender/blenkernel/intern/vfont.c +++ b/source/blender/blenkernel/intern/vfont.c @@ -1422,7 +1422,8 @@ static bool vfont_to_curve(Object *ob, for (i = 0; i <= selend; i++, ct++) { if (i >= selstart) { selboxes[i - selstart].x = ct->xof * font_size; - selboxes[i - selstart].y = ct->yof * font_size; + selboxes[i - selstart].y = (ct->yof - 0.25f) * font_size; + selboxes[i - selstart].h = font_size; } } } @@ -1481,17 +1482,17 @@ static bool vfont_to_curve(Object *ob, f = ef->textcurs[0]; - f[0] = font_size * (-0.1f * co + ct->xof); - f[1] = font_size * (0.1f * si + ct->yof); + f[0] = font_size * (-0.02f * co + ct->xof); + f[1] = font_size * (0.1f * si - (0.25f * co) + ct->yof); - f[2] = font_size * (0.1f * co + ct->xof); - f[3] = font_size * (-0.1f * si + ct->yof); + f[2] = font_size * (0.02f * co + ct->xof); + f[3] = font_size * (-0.1f * si - (0.25f * co) + ct->yof); - f[4] = font_size * (0.1f * co + 0.8f * si + ct->xof); - f[5] = font_size * (-0.1f * si + 0.8f * co + ct->yof); + f[4] = font_size * (0.02f * co + 0.8f * si + ct->xof); + f[5] = font_size * (-0.1f * si + 0.75f * co + ct->yof); - f[6] = font_size * (-0.1f * co + 0.8f * si + ct->xof); - f[7] = font_size * (0.1f * si + 0.8f * co + ct->yof); + f[6] = font_size * (-0.02f * co + 0.8f * si + ct->xof); + f[7] = font_size * (0.1f * si + 0.75f * co + ct->yof); } if (mode == FO_SELCHANGE) { diff --git a/source/blender/draw/engines/overlay/overlay_edit_text.c b/source/blender/draw/engines/overlay/overlay_edit_text.c index dfef5b3c241..bd8720042f1 100644 --- a/source/blender/draw/engines/overlay/overlay_edit_text.c +++ b/source/blender/draw/engines/overlay/overlay_edit_text.c @@ -7,6 +7,8 @@ #include "DRW_render.h" +#include "UI_resources.h" + #include "BKE_vfont.h" #include "DNA_curve_types.h" @@ -38,17 +40,24 @@ void OVERLAY_edit_text_cache_init(OVERLAY_Data *vedata) DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.color_wire); } { + /* Cursor (text caret). */ state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA; - DRW_PASS_CREATE(psl->edit_text_overlay_ps, state | pd->clipping_state); - + DRW_PASS_CREATE(psl->edit_text_cursor_ps, state | pd->clipping_state); sh = OVERLAY_shader_uniform_color(); - pd->edit_text_overlay_grp = grp = DRW_shgroup_create(sh, psl->edit_text_overlay_ps); + pd->edit_text_cursor_grp = grp = DRW_shgroup_create(sh, psl->edit_text_cursor_ps); + DRW_shgroup_uniform_vec4(grp, "color", pd->edit_text.cursor_color, 1); - DRW_shgroup_uniform_vec4(grp, "color", pd->edit_text.overlay_color, 1); + /* Selection boxes. */ + state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA; + DRW_PASS_CREATE(psl->edit_text_selection_ps, state | pd->clipping_state); + sh = OVERLAY_shader_uniform_color(); + pd->edit_text_selection_grp = grp = DRW_shgroup_create(sh, psl->edit_text_selection_ps); + DRW_shgroup_uniform_vec4(grp, "color", pd->edit_text.selection_color, 1); - state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_MUL | DRW_STATE_DEPTH_GREATER_EQUAL | + /* Highlight text within selection boxes. */ + state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA | DRW_STATE_DEPTH_GREATER_EQUAL | pd->clipping_state; - DRW_PASS_INSTANCE_CREATE(psl->edit_text_darken_ps, psl->edit_text_overlay_ps, state); + DRW_PASS_INSTANCE_CREATE(psl->edit_text_highlight_ps, psl->edit_text_selection_ps, state); } { /* Create view which will render everything (hopefully) behind the text geometry. */ @@ -112,7 +121,7 @@ static void edit_text_cache_populate_select(OVERLAY_Data *vedata, Object *ob) v2_quad_corners_to_mat4(box, final_mat); mul_m4_m4m4(final_mat, ob->obmat, final_mat); - DRW_shgroup_call_obmat(pd->edit_text_overlay_grp, geom, final_mat); + DRW_shgroup_call_obmat(pd->edit_text_selection_grp, geom, final_mat); } } @@ -128,7 +137,7 @@ static void edit_text_cache_populate_cursor(OVERLAY_Data *vedata, Object *ob) mul_m4_m4m4(mat, ob->obmat, mat); struct GPUBatch *geom = DRW_cache_quad_get(); - DRW_shgroup_call_obmat(pd->edit_text_overlay_grp, geom, mat); + DRW_shgroup_call_obmat(pd->edit_text_cursor_grp, geom, mat); } static void edit_text_cache_populate_boxes(OVERLAY_Data *vedata, Object *ob) @@ -193,11 +202,18 @@ void OVERLAY_edit_text_draw(OVERLAY_Data *vedata) DRW_view_set_active(pd->view_edit_text); - /* Alpha blended. */ - copy_v4_fl4(pd->edit_text.overlay_color, 0.8f, 0.8f, 0.8f, 0.5f); - DRW_draw_pass(psl->edit_text_overlay_ps); + /* Selection Boxes. */ + UI_GetThemeColor4fv(TH_WIDGET_TEXT_SELECTION, pd->edit_text.selection_color); + srgb_to_linearrgb_v4(pd->edit_text.selection_color, pd->edit_text.selection_color); + DRW_draw_pass(psl->edit_text_selection_ps); + + /* Highlight text within selection boxes. */ + UI_GetThemeColor4fv(TH_WIDGET_TEXT_HIGHLIGHT, pd->edit_text.selection_color); + srgb_to_linearrgb_v4(pd->edit_text.selection_color, pd->edit_text.selection_color); + DRW_draw_pass(psl->edit_text_highlight_ps); - /* Multiply previous result where depth test fail. */ - copy_v4_fl4(pd->edit_text.overlay_color, 0.0f, 0.0f, 0.0f, 1.0f); - DRW_draw_pass(psl->edit_text_darken_ps); + /* Cursor (text caret). */ + UI_GetThemeColor4fv(TH_WIDGET_TEXT_CURSOR, pd->edit_text.cursor_color); + srgb_to_linearrgb_v4(pd->edit_text.cursor_color, pd->edit_text.cursor_color); + DRW_draw_pass(psl->edit_text_cursor_ps); } diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h index 06c6ce42fd8..0a783c44029 100644 --- a/source/blender/draw/engines/overlay/overlay_private.h +++ b/source/blender/draw/engines/overlay/overlay_private.h @@ -78,8 +78,9 @@ typedef struct OVERLAY_PassList { DRWPass *edit_mesh_analysis_ps; DRWPass *edit_mesh_normals_ps; DRWPass *edit_particle_ps; - DRWPass *edit_text_overlay_ps; - DRWPass *edit_text_darken_ps; + DRWPass *edit_text_cursor_ps; + DRWPass *edit_text_selection_ps; + DRWPass *edit_text_highlight_ps; DRWPass *edit_text_wire_ps[2]; DRWPass *edit_uv_edges_ps; DRWPass *edit_uv_verts_ps; @@ -252,7 +253,8 @@ typedef struct OVERLAY_PrivateData { DRWShadingGroup *edit_mesh_analysis_grp; DRWShadingGroup *edit_particle_strand_grp; DRWShadingGroup *edit_particle_point_grp; - DRWShadingGroup *edit_text_overlay_grp; + DRWShadingGroup *edit_text_cursor_grp; + DRWShadingGroup *edit_text_selection_grp; DRWShadingGroup *edit_text_wire_grp[2]; DRWShadingGroup *edit_uv_verts_grp; DRWShadingGroup *edit_uv_edges_grp; @@ -338,7 +340,8 @@ typedef struct OVERLAY_PrivateData { int handle_display; } edit_curve; struct { - float overlay_color[4]; + float cursor_color[4]; + float selection_color[4]; } edit_text; struct { bool do_zbufclip; diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h index 22e747e37ad..9a46728097c 100644 --- a/source/blender/editors/include/UI_resources.h +++ b/source/blender/editors/include/UI_resources.h @@ -291,6 +291,8 @@ typedef enum ThemeColorID { TH_WIDGET_EMBOSS, TH_WIDGET_TEXT_CURSOR, + TH_WIDGET_TEXT_SELECTION, + TH_WIDGET_TEXT_HIGHLIGHT, TH_EDITOR_OUTLINE, TH_TRANSPARENT_CHECKER_PRIMARY, diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index cfdcd08df4a..93b94d42d39 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -895,6 +895,12 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid) case TH_WIDGET_TEXT_CURSOR: cp = btheme->tui.widget_text_cursor; break; + case TH_WIDGET_TEXT_SELECTION: + cp = btheme->tui.wcol_text.item; + break; + case TH_WIDGET_TEXT_HIGHLIGHT: + cp = btheme->tui.wcol_text.text_sel; + break; case TH_TRANSPARENT_CHECKER_PRIMARY: cp = btheme->tui.transparent_checker_primary; -- cgit v1.2.3