diff options
author | Harley Acheson <harley.acheson@gmail.com> | 2022-09-02 23:18:09 +0300 |
---|---|---|
committer | Harley Acheson <harley.acheson@gmail.com> | 2022-09-02 23:18:09 +0300 |
commit | a1e01f4c026a389b94985b19678a0c69745ca248 (patch) | |
tree | e245393f148b58fe94c52a488759d0452a131247 /source/blender/draw/engines | |
parent | 65a215b819346cc889b0e09b2d4d83b21e2185ec (diff) |
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
Diffstat (limited to 'source/blender/draw/engines')
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_edit_text.c | 44 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_private.h | 11 |
2 files changed, 37 insertions, 18 deletions
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; |