Blender V4.3
overlay_edit_text.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DRW_render.hh"
10
11#include "UI_resources.hh"
12
13#include "BLI_math_color.h"
14#include "BLI_math_rotation.h"
15
16#include "BKE_vfont.hh"
17
18#include "DNA_curve_types.h"
19
20#include "overlay_private.hh"
21
23{
24 OVERLAY_PassList *psl = vedata->psl;
25 OVERLAY_PrivateData *pd = vedata->stl->pd;
26 const DRWContextState *draw_ctx = DRW_context_state_get();
27 View3D *v3d = draw_ctx->v3d;
28 DRWShadingGroup *grp;
29 GPUShader *sh;
31
35
36 /* Run Twice for in-front passes. */
37 for (int i = 0; i < 2; i++) {
41
44 DRW_shgroup_uniform_vec4_copy(grp, "ucolor", G_draw.block.color_wire);
45 }
46 {
47 /* Cursor (text caret). */
52 DRW_shgroup_uniform_vec4(grp, "ucolor", pd->edit_text.cursor_color, 1);
53
54 /* Selection boxes. */
60
61 /* Highlight text within selection boxes. */
65 }
66 {
67 /* Create view which will render everything (hopefully) behind the text geometry. */
68 DRWView *default_view = (DRWView *)DRW_view_default_get();
69 pd->view_edit_text = DRW_view_create_with_zoffset(default_view, draw_ctx->rv3d, -5.0f);
70 }
71}
72
73/* Use 2D quad corners to create a matrix that set
74 * a [-1..1] quad at the right position. */
75static void v2_quad_corners_to_mat4(const float corners[4][2], float r_mat[4][4])
76{
77 unit_m4(r_mat);
78 sub_v2_v2v2(r_mat[0], corners[1], corners[0]);
79 sub_v2_v2v2(r_mat[1], corners[3], corners[0]);
80 mul_v2_fl(r_mat[0], 0.5f);
81 mul_v2_fl(r_mat[1], 0.5f);
82 copy_v2_v2(r_mat[3], corners[0]);
83 add_v2_v2(r_mat[3], r_mat[0]);
84 add_v2_v2(r_mat[3], r_mat[1]);
85}
86
88{
89 OVERLAY_PrivateData *pd = vedata->stl->pd;
90 const Curve *cu = static_cast<Curve *>(ob->data);
91 EditFont *ef = cu->editfont;
92 float final_mat[4][4], box[4][2];
93 blender::gpu::Batch *geom = DRW_cache_quad_get();
94
95 for (int i = 0; i < ef->selboxes_len; i++) {
96 EditFontSelBox *sb = &ef->selboxes[i];
97
98 float selboxw;
99 if (i + 1 != ef->selboxes_len) {
100 if (ef->selboxes[i + 1].y == sb->y) {
101 selboxw = ef->selboxes[i + 1].x - sb->x;
102 }
103 else {
104 selboxw = sb->w;
105 }
106 }
107 else {
108 selboxw = sb->w;
109 }
110 /* NOTE: v2_quad_corners_to_mat4 don't need the 3rd corner. */
111 if (sb->rot == 0.0f) {
112 copy_v2_fl2(box[0], sb->x, sb->y);
113 copy_v2_fl2(box[1], sb->x + selboxw, sb->y);
114 copy_v2_fl2(box[3], sb->x, sb->y + sb->h);
115 }
116 else {
117 float mat[2][2];
118 angle_to_mat2(mat, sb->rot);
119 copy_v2_fl2(box[0], sb->x, sb->y);
120 mul_v2_v2fl(box[1], mat[0], selboxw);
121 add_v2_v2(box[1], &sb->x);
122 mul_v2_v2fl(box[3], mat[1], sb->h);
123 add_v2_v2(box[3], &sb->x);
124 }
125 v2_quad_corners_to_mat4(box, final_mat);
126 mul_m4_m4m4(final_mat, ob->object_to_world().ptr(), final_mat);
127
129 }
130}
131
133{
134 OVERLAY_PrivateData *pd = vedata->stl->pd;
135 const Curve *cu = static_cast<Curve *>(ob->data);
136 EditFont *edit_font = cu->editfont;
137 float(*cursor)[2] = edit_font->textcurs;
138 float mat[4][4];
139
140 v2_quad_corners_to_mat4(cursor, mat);
141 mul_m4_m4m4(mat, ob->object_to_world().ptr(), mat);
142
143 blender::gpu::Batch *geom = DRW_cache_quad_get();
145}
146
148{
150 const Curve *cu = static_cast<Curve *>(ob->data);
151
152 for (int i = 0; i < cu->totbox; i++) {
153 TextBox *tb = &cu->tb[i];
154 const bool is_active = (i == (cu->actbox - 1));
155 float *color = is_active ? G_draw.block.color_active : G_draw.block.color_wire;
156
157 if ((tb->w != 0.0f) || (tb->h != 0.0f)) {
158 float vecs[4][3];
159 vecs[0][0] = vecs[1][0] = vecs[2][0] = vecs[3][0] = cu->xof + tb->x;
160 vecs[0][1] = vecs[1][1] = vecs[2][1] = vecs[3][1] = cu->yof + tb->y + cu->fsize_realtime;
161 vecs[0][2] = vecs[1][2] = vecs[2][2] = vecs[3][2] = 0.001;
162
163 vecs[1][0] += tb->w;
164 vecs[2][0] += tb->w;
165 vecs[2][1] -= tb->h;
166 vecs[3][1] -= tb->h;
167
168 for (int j = 0; j < 4; j++) {
169 mul_v3_m4v3(vecs[j], ob->object_to_world().ptr(), vecs[j]);
170 }
171 for (int j = 0; j < 4; j++) {
172 OVERLAY_extra_line_dashed(cb, vecs[j], vecs[(j + 1) % 4], color);
173 }
174 }
175 }
176}
177
179{
180 OVERLAY_PrivateData *pd = vedata->stl->pd;
181 blender::gpu::Batch *geom;
182 bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
183
185 if (geom) {
186 DRW_shgroup_call(pd->edit_text_wire_grp[do_in_front], geom, ob);
187 }
188
192}
193
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void unit_m4(float m[4][4])
Definition rct.c:1127
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void angle_to_mat2(float R[2][2], float angle)
MINLINE void copy_v2_fl2(float v[2], float x, float y)
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
@ OB_DRAW_IN_FRONT
@ CURVE_HANDLE_NONE
#define DRW_PASS_INSTANCE_CREATE(pass, original, state)
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_call_obmat(shgroup, geom, obmat)
#define DRW_shgroup_call(shgroup, geom, ob)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
@ TH_WIDGET_TEXT_HIGHLIGHT
@ TH_WIDGET_TEXT_SELECTION
@ TH_WIDGET_TEXT_CURSOR
void UI_GetThemeColor4fv(int colorid, float col[4])
struct GPUShader GPUShader
blender::gpu::Batch * DRW_cache_text_edge_wire_get(Object *ob)
blender::gpu::Batch * DRW_cache_quad_get()
DRWView * DRW_view_create_with_zoffset(const DRWView *parent_view, const RegionView3D *rv3d, float offset)
DRW_Global G_draw
const DRWContextState * DRW_context_state_get()
bool DRW_state_is_fbo()
const DRWView * DRW_view_default_get()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_vec4(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_draw_pass(DRWPass *pass)
void DRW_view_set_active(const DRWView *view)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_BLEND_ALPHA
Definition draw_state.hh:55
@ DRW_STATE_DEPTH_GREATER_EQUAL
Definition draw_state.hh:41
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
@ DRW_STATE_DEPTH_ALWAYS
Definition draw_state.hh:36
draw_view in_light_buf[] float
static ulong state[N]
static void edit_text_cache_populate_boxes(OVERLAY_Data *vedata, Object *ob)
static void edit_text_cache_populate_select(OVERLAY_Data *vedata, Object *ob)
static void edit_text_cache_populate_cursor(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_edit_text_cache_init(OVERLAY_Data *vedata)
void OVERLAY_edit_text_cache_populate(OVERLAY_Data *vedata, Object *ob)
static void v2_quad_corners_to_mat4(const float corners[4][2], float r_mat[4][4])
void OVERLAY_edit_text_draw(OVERLAY_Data *vedata)
OVERLAY_ExtraCallBuffers * OVERLAY_extra_call_buffer_get(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_extra_line_dashed(OVERLAY_ExtraCallBuffers *cb, const float start[3], const float end[3], const float color[4])
GPUShader * OVERLAY_shader_uniform_color()
struct TextBox * tb
struct EditFont * editfont
float fsize_realtime
RegionView3D * rv3d
float textcurs[4][2]
Definition BKE_vfont.hh:40
EditFontSelBox * selboxes
Definition BKE_vfont.hh:41
int selboxes_len
Definition BKE_vfont.hh:42
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
OVERLAY_FramebufferList * fbl
GPUFrameBuffer * overlay_default_fb
DRWPass * edit_text_highlight_ps
DRWPass * edit_text_selection_ps
DRWPass * edit_text_cursor_ps
DRWPass * edit_text_wire_ps[2]
OVERLAY_ShadingData shdata
DRWShadingGroup * edit_text_cursor_grp
DRWShadingGroup * edit_text_wire_grp[2]
DRWShadingGroup * edit_text_selection_grp
struct OVERLAY_PrivateData::@216210106171324025244131023234223216173313152160 edit_text
struct OVERLAY_PrivateData::@017025346316061011333067144345352107066311354153 edit_curve
OVERLAY_PrivateData * pd
View3DOverlay overlay