Blender  V3.3
overlay_edit_text.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. */
3 
8 #include "DRW_render.h"
9 
10 #include "BKE_vfont.h"
11 
12 #include "DNA_curve_types.h"
13 
14 #include "overlay_private.h"
15 
17 {
18  OVERLAY_PassList *psl = vedata->psl;
19  OVERLAY_PrivateData *pd = vedata->stl->pd;
20  const DRWContextState *draw_ctx = DRW_context_state_get();
21  View3D *v3d = draw_ctx->v3d;
22  DRWShadingGroup *grp;
23  GPUShader *sh;
25 
29 
30  /* Run Twice for in-front passes. */
31  for (int i = 0; i < 2; i++) {
35 
39  }
40  {
43 
46 
47  DRW_shgroup_uniform_vec4(grp, "color", pd->edit_text.overlay_color, 1);
48 
50  pd->clipping_state;
52  }
53  {
54  /* Create view which will render everything (hopefully) behind the text geometry. */
55  DRWView *default_view = (DRWView *)DRW_view_default_get();
56  pd->view_edit_text = DRW_view_create_with_zoffset(default_view, draw_ctx->rv3d, -5.0f);
57  }
58 }
59 
60 /* Use 2D quad corners to create a matrix that set
61  * a [-1..1] quad at the right position. */
62 static void v2_quad_corners_to_mat4(const float corners[4][2], float r_mat[4][4])
63 {
64  unit_m4(r_mat);
65  sub_v2_v2v2(r_mat[0], corners[1], corners[0]);
66  sub_v2_v2v2(r_mat[1], corners[3], corners[0]);
67  mul_v2_fl(r_mat[0], 0.5f);
68  mul_v2_fl(r_mat[1], 0.5f);
69  copy_v2_v2(r_mat[3], corners[0]);
70  add_v2_v2(r_mat[3], r_mat[0]);
71  add_v2_v2(r_mat[3], r_mat[1]);
72 }
73 
75 {
76  OVERLAY_PrivateData *pd = vedata->stl->pd;
77  const Curve *cu = ob->data;
78  EditFont *ef = cu->editfont;
79  float final_mat[4][4], box[4][2];
80  struct GPUBatch *geom = DRW_cache_quad_get();
81 
82  for (int i = 0; i < ef->selboxes_len; i++) {
83  EditFontSelBox *sb = &ef->selboxes[i];
84 
85  float selboxw;
86  if (i + 1 != ef->selboxes_len) {
87  if (ef->selboxes[i + 1].y == sb->y) {
88  selboxw = ef->selboxes[i + 1].x - sb->x;
89  }
90  else {
91  selboxw = sb->w;
92  }
93  }
94  else {
95  selboxw = sb->w;
96  }
97  /* NOTE: v2_quad_corners_to_mat4 don't need the 3rd corner. */
98  if (sb->rot == 0.0f) {
99  copy_v2_fl2(box[0], sb->x, sb->y);
100  copy_v2_fl2(box[1], sb->x + selboxw, sb->y);
101  copy_v2_fl2(box[3], sb->x, sb->y + sb->h);
102  }
103  else {
104  float mat[2][2];
105  angle_to_mat2(mat, sb->rot);
106  copy_v2_fl2(box[0], sb->x, sb->y);
107  mul_v2_v2fl(box[1], mat[0], selboxw);
108  add_v2_v2(box[1], &sb->x);
109  mul_v2_v2fl(box[3], mat[1], sb->h);
110  add_v2_v2(box[3], &sb->x);
111  }
112  v2_quad_corners_to_mat4(box, final_mat);
113  mul_m4_m4m4(final_mat, ob->obmat, final_mat);
114 
115  DRW_shgroup_call_obmat(pd->edit_text_overlay_grp, geom, final_mat);
116  }
117 }
118 
120 {
121  OVERLAY_PrivateData *pd = vedata->stl->pd;
122  const Curve *cu = ob->data;
123  EditFont *edit_font = cu->editfont;
124  float(*cursor)[2] = edit_font->textcurs;
125  float mat[4][4];
126 
127  v2_quad_corners_to_mat4(cursor, mat);
128  mul_m4_m4m4(mat, ob->obmat, mat);
129 
130  struct GPUBatch *geom = DRW_cache_quad_get();
132 }
133 
135 {
137  const Curve *cu = ob->data;
138 
139  for (int i = 0; i < cu->totbox; i++) {
140  TextBox *tb = &cu->tb[i];
141  const bool is_active = (i == (cu->actbox - 1));
142  float *color = is_active ? G_draw.block.color_active : G_draw.block.color_wire;
143 
144  if ((tb->w != 0.0f) || (tb->h != 0.0f)) {
145  float vecs[4][3];
146  vecs[0][0] = vecs[1][0] = vecs[2][0] = vecs[3][0] = cu->xof + tb->x;
147  vecs[0][1] = vecs[1][1] = vecs[2][1] = vecs[3][1] = cu->yof + tb->y + cu->fsize_realtime;
148  vecs[0][2] = vecs[1][2] = vecs[2][2] = vecs[3][2] = 0.001;
149 
150  vecs[1][0] += tb->w;
151  vecs[2][0] += tb->w;
152  vecs[2][1] -= tb->h;
153  vecs[3][1] -= tb->h;
154 
155  for (int j = 0; j < 4; j++) {
156  mul_v3_m4v3(vecs[j], ob->obmat, vecs[j]);
157  }
158  for (int j = 0; j < 4; j++) {
159  OVERLAY_extra_line_dashed(cb, vecs[j], vecs[(j + 1) % 4], color);
160  }
161  }
162  }
163 }
164 
166 {
167  OVERLAY_PrivateData *pd = vedata->stl->pd;
168  struct GPUBatch *geom;
169  bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
170 
171  geom = DRW_cache_text_edge_wire_get(ob);
172  if (geom) {
173  DRW_shgroup_call(pd->edit_text_wire_grp[do_in_front], geom, ob);
174  }
175 
178  edit_text_cache_populate_boxes(vedata, ob);
179 }
180 
182 {
183  OVERLAY_PrivateData *pd = vedata->stl->pd;
184  OVERLAY_PassList *psl = vedata->psl;
185  OVERLAY_FramebufferList *fbl = vedata->fbl;
186 
187  if (DRW_state_is_fbo()) {
189  }
190 
193 
195 
196  /* Alpha blended. */
197  copy_v4_fl4(pd->edit_text.overlay_color, 0.8f, 0.8f, 0.8f, 0.5f);
199 
200  /* Multiply previous result where depth test fail. */
201  copy_v4_fl4(pd->edit_text.overlay_color, 0.0f, 0.0f, 0.0f, 1.0f);
203 }
typedef float(TangentPoint)[2]
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void unit_m4(float m[4][4])
Definition: rct.c:1090
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
void angle_to_mat2(float R[2][2], float angle)
MINLINE void copy_v2_fl2(float v[2], float x, float y)
MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
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)
Definition: DRW_render.h:691
DRWState
Definition: DRW_render.h:298
@ DRW_STATE_BLEND_ALPHA
Definition: DRW_render.h:328
@ DRW_STATE_DEPTH_GREATER_EQUAL
Definition: DRW_render.h:314
@ DRW_STATE_WRITE_DEPTH
Definition: DRW_render.h:302
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:303
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition: DRW_render.h:311
@ DRW_STATE_DEPTH_ALWAYS
Definition: DRW_render.h:309
@ DRW_STATE_BLEND_MUL
Definition: DRW_render.h:333
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:690
#define DRW_shgroup_call_obmat(shgroup, geom, obmat)
Definition: DRW_render.h:420
#define DRW_shgroup_call(shgroup, geom, ob)
Definition: DRW_render.h:414
GPUBatch
Definition: GPU_batch.h:78
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
struct GPUShader GPUShader
Definition: GPU_shader.h:20
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input 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 a color
GPUBatch * DRW_cache_quad_get(void)
Definition: draw_cache.c:389
GPUBatch * DRW_cache_text_edge_wire_get(Object *ob)
Definition: draw_cache.c:2995
struct DRW_Global G_draw
Definition: draw_common.c:32
DRWView * DRW_view_create_with_zoffset(const DRWView *parent_view, const RegionView3D *rv3d, float offset)
Definition: draw_common.c:255
bool DRW_state_is_fbo(void)
const DRWContextState * DRW_context_state_get(void)
void DRW_shgroup_uniform_vec4(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
const DRWView * DRW_view_default_get(void)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
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)
const int state
ccl_gpu_kernel_postfix ccl_global float int int int int sh
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(void)
float xof
struct TextBox * tb
struct EditFont * editfont
float fsize_realtime
float yof
struct View3D * v3d
Definition: DRW_render.h:976
struct RegionView3D * rv3d
Definition: DRW_render.h:975
GlobalsUboStorage block
Definition: draw_common.h:127
float textcurs[4][2]
Definition: BKE_vfont.h:36
EditFontSelBox * selboxes
Definition: BKE_vfont.h:37
int selboxes_len
Definition: BKE_vfont.h:38
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
OVERLAY_FramebufferList * fbl
struct GPUFrameBuffer * overlay_default_fb
DRWPass * edit_text_darken_ps
DRWPass * edit_text_overlay_ps
DRWPass * edit_text_wire_ps[2]
struct OVERLAY_PrivateData::@251 edit_text
OVERLAY_ShadingData shdata
DRWShadingGroup * edit_text_wire_grp[2]
DRWShadingGroup * edit_text_overlay_grp
struct OVERLAY_PrivateData::@250 edit_curve
struct OVERLAY_PrivateData * pd
float obmat[4][4]
void * data
View3DOverlay overlay