Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_edit_text.c
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2019 Blender Foundation. */ | * Copyright 2019 Blender Foundation. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup draw_engine | * \ingroup draw_engine | ||||
| */ | */ | ||||
| #include "DRW_render.h" | #include "DRW_render.h" | ||||
| #include "UI_resources.h" | |||||
| #include "BKE_vfont.h" | #include "BKE_vfont.h" | ||||
| #include "DNA_curve_types.h" | #include "DNA_curve_types.h" | ||||
| #include "overlay_private.h" | #include "overlay_private.h" | ||||
| void OVERLAY_edit_text_cache_init(OVERLAY_Data *vedata) | void OVERLAY_edit_text_cache_init(OVERLAY_Data *vedata) | ||||
| { | { | ||||
| Show All 15 Lines | for (int i = 0; i < 2; i++) { | ||||
| state |= ((i == 0) ? DRW_STATE_DEPTH_LESS_EQUAL : DRW_STATE_DEPTH_ALWAYS); | state |= ((i == 0) ? DRW_STATE_DEPTH_LESS_EQUAL : DRW_STATE_DEPTH_ALWAYS); | ||||
| DRW_PASS_CREATE(psl->edit_text_wire_ps[i], state | pd->clipping_state); | DRW_PASS_CREATE(psl->edit_text_wire_ps[i], state | pd->clipping_state); | ||||
| sh = OVERLAY_shader_uniform_color(); | sh = OVERLAY_shader_uniform_color(); | ||||
| pd->edit_text_wire_grp[i] = grp = DRW_shgroup_create(sh, psl->edit_text_wire_ps[i]); | pd->edit_text_wire_grp[i] = grp = DRW_shgroup_create(sh, psl->edit_text_wire_ps[i]); | ||||
| DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.color_wire); | DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.color_wire); | ||||
| } | } | ||||
| { | { | ||||
| /* Cursor (text caret). */ | |||||
| state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA; | 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(); | 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; | 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. */ | /* Create view which will render everything (hopefully) behind the text geometry. */ | ||||
| DRWView *default_view = (DRWView *)DRW_view_default_get(); | DRWView *default_view = (DRWView *)DRW_view_default_get(); | ||||
| pd->view_edit_text = DRW_view_create_with_zoffset(default_view, draw_ctx->rv3d, -5.0f); | pd->view_edit_text = DRW_view_create_with_zoffset(default_view, draw_ctx->rv3d, -5.0f); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | else { | ||||
| mul_v2_v2fl(box[1], mat[0], selboxw); | mul_v2_v2fl(box[1], mat[0], selboxw); | ||||
| add_v2_v2(box[1], &sb->x); | add_v2_v2(box[1], &sb->x); | ||||
| mul_v2_v2fl(box[3], mat[1], sb->h); | mul_v2_v2fl(box[3], mat[1], sb->h); | ||||
| add_v2_v2(box[3], &sb->x); | add_v2_v2(box[3], &sb->x); | ||||
| } | } | ||||
| v2_quad_corners_to_mat4(box, final_mat); | v2_quad_corners_to_mat4(box, final_mat); | ||||
| mul_m4_m4m4(final_mat, ob->obmat, 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); | ||||
| } | } | ||||
| } | } | ||||
| static void edit_text_cache_populate_cursor(OVERLAY_Data *vedata, Object *ob) | static void edit_text_cache_populate_cursor(OVERLAY_Data *vedata, Object *ob) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| const Curve *cu = ob->data; | const Curve *cu = ob->data; | ||||
| EditFont *edit_font = cu->editfont; | EditFont *edit_font = cu->editfont; | ||||
| float(*cursor)[2] = edit_font->textcurs; | float(*cursor)[2] = edit_font->textcurs; | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| v2_quad_corners_to_mat4(cursor, mat); | v2_quad_corners_to_mat4(cursor, mat); | ||||
| mul_m4_m4m4(mat, ob->obmat, mat); | mul_m4_m4m4(mat, ob->obmat, mat); | ||||
| struct GPUBatch *geom = DRW_cache_quad_get(); | 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) | static void edit_text_cache_populate_boxes(OVERLAY_Data *vedata, Object *ob) | ||||
| { | { | ||||
| OVERLAY_ExtraCallBuffers *cb = OVERLAY_extra_call_buffer_get(vedata, ob); | OVERLAY_ExtraCallBuffers *cb = OVERLAY_extra_call_buffer_get(vedata, ob); | ||||
| const Curve *cu = ob->data; | const Curve *cu = ob->data; | ||||
| for (int i = 0; i < cu->totbox; i++) { | for (int i = 0; i < cu->totbox; i++) { | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (DRW_state_is_fbo()) { | ||||
| GPU_framebuffer_bind(fbl->overlay_default_fb); | GPU_framebuffer_bind(fbl->overlay_default_fb); | ||||
| } | } | ||||
| DRW_draw_pass(psl->edit_text_wire_ps[0]); | DRW_draw_pass(psl->edit_text_wire_ps[0]); | ||||
| DRW_draw_pass(psl->edit_text_wire_ps[1]); | DRW_draw_pass(psl->edit_text_wire_ps[1]); | ||||
| DRW_view_set_active(pd->view_edit_text); | DRW_view_set_active(pd->view_edit_text); | ||||
| /* Alpha blended. */ | /* Selection Boxes. */ | ||||
| copy_v4_fl4(pd->edit_text.overlay_color, 0.8f, 0.8f, 0.8f, 0.5f); | UI_GetThemeColor4fv(TH_WIDGET_TEXT_SELECTION, pd->edit_text.selection_color); | ||||
| DRW_draw_pass(psl->edit_text_overlay_ps); | srgb_to_linearrgb_v4(pd->edit_text.selection_color, pd->edit_text.selection_color); | ||||
| DRW_draw_pass(psl->edit_text_selection_ps); | |||||
| /* Multiply previous result where depth test fail. */ | |||||
| copy_v4_fl4(pd->edit_text.overlay_color, 0.0f, 0.0f, 0.0f, 1.0f); | /* Highlight text within selection boxes. */ | ||||
| DRW_draw_pass(psl->edit_text_darken_ps); | UI_GetThemeColor4fv(TH_WIDGET_TEXT_HIGHLIGHT, pd->edit_text.selection_color); | ||||
brecht: If we are going to use the text button selection color, we should also be using its selected… | |||||
| srgb_to_linearrgb_v4(pd->edit_text.selection_color, pd->edit_text.selection_color); | |||||
| DRW_draw_pass(psl->edit_text_highlight_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); | |||||
| } | } | ||||
If we are going to use the text button selection color, we should also be using its selected text color to ensure it's visible on top of the selection in all themes.