Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_manager_text.cc
- This file was moved from source/blender/draw/intern/draw_manager_text.c.
| Show All 32 Lines | |||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "draw_manager_text.h" | #include "draw_manager_text.h" | ||||
| #include "intern/bmesh_polygon.h" | #include "intern/bmesh_polygon.h" | ||||
| typedef struct ViewCachedString { | struct ViewCachedString { | ||||
| float vec[3]; | float vec[3]; | ||||
| union { | union { | ||||
| uchar ub[4]; | uchar ub[4]; | ||||
| int pack; | int pack; | ||||
| } col; | } col; | ||||
| short sco[2]; | short sco[2]; | ||||
| short xoffs, yoffs; | short xoffs, yoffs; | ||||
| short flag; | short flag; | ||||
| int str_len; | int str_len; | ||||
| /* str is allocated past the end */ | /* str is allocated past the end */ | ||||
| char str[0]; | char str[0]; | ||||
| } ViewCachedString; | }; | ||||
| typedef struct DRWTextStore { | struct DRWTextStore { | ||||
| BLI_memiter *cache_strings; | BLI_memiter *cache_strings; | ||||
| } DRWTextStore; | }; | ||||
| DRWTextStore *DRW_text_cache_create(void) | DRWTextStore *DRW_text_cache_create(void) | ||||
| { | { | ||||
| DRWTextStore *dt = MEM_callocN(sizeof(*dt), __func__); | DRWTextStore *dt = MEM_cnew<DRWTextStore>(__func__); | ||||
| dt->cache_strings = BLI_memiter_create(1 << 14); /* 16kb */ | dt->cache_strings = BLI_memiter_create(1 << 14); /* 16kb */ | ||||
| return dt; | return dt; | ||||
| } | } | ||||
| void DRW_text_cache_destroy(struct DRWTextStore *dt) | void DRW_text_cache_destroy(DRWTextStore *dt) | ||||
| { | { | ||||
| BLI_memiter_destroy(dt->cache_strings); | BLI_memiter_destroy(dt->cache_strings); | ||||
| MEM_freeN(dt); | MEM_freeN(dt); | ||||
| } | } | ||||
| void DRW_text_cache_add(DRWTextStore *dt, | void DRW_text_cache_add(DRWTextStore *dt, | ||||
| const float co[3], | const float co[3], | ||||
| const char *str, | const char *str, | ||||
| Show All 9 Lines | void DRW_text_cache_add(DRWTextStore *dt, | ||||
| if (flag & DRW_TEXT_CACHE_STRING_PTR) { | if (flag & DRW_TEXT_CACHE_STRING_PTR) { | ||||
| BLI_assert(str_len == strlen(str)); | BLI_assert(str_len == strlen(str)); | ||||
| alloc_len = sizeof(void *); | alloc_len = sizeof(void *); | ||||
| } | } | ||||
| else { | else { | ||||
| alloc_len = str_len + 1; | alloc_len = str_len + 1; | ||||
| } | } | ||||
| vos = BLI_memiter_alloc(dt->cache_strings, sizeof(ViewCachedString) + alloc_len); | vos = static_cast<ViewCachedString *>( | ||||
| BLI_memiter_alloc(dt->cache_strings, sizeof(ViewCachedString) + alloc_len)); | |||||
| copy_v3_v3(vos->vec, co); | copy_v3_v3(vos->vec, co); | ||||
| copy_v4_v4_uchar(vos->col.ub, col); | copy_v4_v4_uchar(vos->col.ub, col); | ||||
| vos->xoffs = xoffs; | vos->xoffs = xoffs; | ||||
| vos->yoffs = yoffs; | vos->yoffs = yoffs; | ||||
| vos->flag = flag; | vos->flag = flag; | ||||
| vos->str_len = str_len; | vos->str_len = str_len; | ||||
| Show All 21 Lines | static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region) | ||||
| const int font_id = BLF_default(); | const int font_id = BLF_default(); | ||||
| const uiStyle *style = UI_style_get(); | const uiStyle *style = UI_style_get(); | ||||
| BLF_size(font_id, style->widget.points * U.dpi_fac); | BLF_size(font_id, style->widget.points * U.dpi_fac); | ||||
| BLI_memiter_iter_init(dt->cache_strings, &it); | BLI_memiter_iter_init(dt->cache_strings, &it); | ||||
| while ((vos = BLI_memiter_iter_step(&it))) { | while ((vos = static_cast<ViewCachedString *>(BLI_memiter_iter_step(&it)))) { | ||||
| if (vos->sco[0] != IS_CLIPPED) { | if (vos->sco[0] != IS_CLIPPED) { | ||||
| if (col_pack_prev != vos->col.pack) { | if (col_pack_prev != vos->col.pack) { | ||||
| BLF_color4ubv(font_id, vos->col.ub); | BLF_color4ubv(font_id, vos->col.ub); | ||||
| col_pack_prev = vos->col.pack; | col_pack_prev = vos->col.pack; | ||||
| } | } | ||||
| BLF_position( | BLF_position( | ||||
| font_id, (float)(vos->sco[0] + vos->xoffs), (float)(vos->sco[1] + vos->yoffs), 2.0f); | font_id, float(vos->sco[0] + vos->xoffs), float(vos->sco[1] + vos->yoffs), 2.0f); | ||||
| BLF_draw(font_id, | BLF_draw(font_id, | ||||
| (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str, | (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str, | ||||
| vos->str_len); | vos->str_len); | ||||
| } | } | ||||
| } | } | ||||
| GPU_matrix_pop(); | GPU_matrix_pop(); | ||||
| GPU_matrix_projection_set(original_proj); | GPU_matrix_projection_set(original_proj); | ||||
| } | } | ||||
| void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, struct View3D *v3d) | void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, View3D *v3d) | ||||
| { | { | ||||
| ViewCachedString *vos; | ViewCachedString *vos; | ||||
| if (v3d) { | if (v3d) { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| int tot = 0; | int tot = 0; | ||||
| /* project first and test */ | /* project first and test */ | ||||
| BLI_memiter_handle it; | BLI_memiter_handle it; | ||||
| BLI_memiter_iter_init(dt->cache_strings, &it); | BLI_memiter_iter_init(dt->cache_strings, &it); | ||||
| while ((vos = BLI_memiter_iter_step(&it))) { | while ((vos = static_cast<ViewCachedString *>(BLI_memiter_iter_step(&it)))) { | ||||
| if (ED_view3d_project_short_ex( | if (ED_view3d_project_short_ex( | ||||
| region, | region, | ||||
| (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob, | (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob, | ||||
| (vos->flag & DRW_TEXT_CACHE_LOCALCLIP) != 0, | (vos->flag & DRW_TEXT_CACHE_LOCALCLIP) != 0, | ||||
| vos->vec, | vos->vec, | ||||
| vos->sco, | vos->sco, | ||||
| V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == | V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == | ||||
| V3D_PROJ_RET_OK) { | V3D_PROJ_RET_OK) { | ||||
| Show All 19 Lines | if (v3d) { | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* project first */ | /* project first */ | ||||
| BLI_memiter_handle it; | BLI_memiter_handle it; | ||||
| BLI_memiter_iter_init(dt->cache_strings, &it); | BLI_memiter_iter_init(dt->cache_strings, &it); | ||||
| View2D *v2d = ®ion->v2d; | View2D *v2d = ®ion->v2d; | ||||
| float viewmat[4][4]; | float viewmat[4][4]; | ||||
| rctf region_space = {0.0f, region->winx, 0.0f, region->winy}; | rctf region_space = {0.0f, float(region->winx), 0.0f, float(region->winy)}; | ||||
| BLI_rctf_transform_calc_m4_pivot_min(&v2d->cur, ®ion_space, viewmat); | BLI_rctf_transform_calc_m4_pivot_min(&v2d->cur, ®ion_space, viewmat); | ||||
| while ((vos = BLI_memiter_iter_step(&it))) { | while ((vos = static_cast<ViewCachedString *>(BLI_memiter_iter_step(&it)))) { | ||||
| float p[3]; | float p[3]; | ||||
| copy_v3_v3(p, vos->vec); | copy_v3_v3(p, vos->vec); | ||||
| mul_m4_v3(viewmat, p); | mul_m4_v3(viewmat, p); | ||||
| vos->sco[0] = p[0]; | vos->sco[0] = p[0]; | ||||
| vos->sco[1] = p[1]; | vos->sco[1] = p[1]; | ||||
| } | } | ||||
| drw_text_cache_draw_ex(dt, region); | drw_text_cache_draw_ex(dt, region); | ||||
| } | } | ||||
| } | } | ||||
| void DRW_text_edit_mesh_measure_stats(ARegion *region, | void DRW_text_edit_mesh_measure_stats(ARegion *region, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| Object *ob, | Object *ob, | ||||
| const UnitSettings *unit) | const UnitSettings *unit) | ||||
| { | { | ||||
| /* Do not use ascii when using non-default unit system, some unit chars are utf8 (micro, square, | /* Do not use ascii when using non-default unit system, some unit chars are utf8 (micro, square, | ||||
| * etc.). See bug T36090. | * etc.). See bug T36090. | ||||
| */ | */ | ||||
| struct DRWTextStore *dt = DRW_text_cache_ensure(); | DRWTextStore *dt = DRW_text_cache_ensure(); | ||||
| const short txt_flag = DRW_TEXT_CACHE_GLOBALSPACE; | const short txt_flag = DRW_TEXT_CACHE_GLOBALSPACE; | ||||
| Mesh *me = ob->data; | Mesh *me = static_cast<Mesh *>(ob->data); | ||||
| BMEditMesh *em = me->edit_mesh; | BMEditMesh *em = me->edit_mesh; | ||||
| float v1[3], v2[3], v3[3], vmid[3], fvec[3]; | float v1[3], v2[3], v3[3], vmid[3], fvec[3]; | ||||
| char numstr[32]; /* Stores the measurement display text here */ | char numstr[32]; /* Stores the measurement display text here */ | ||||
| size_t numstr_len; | size_t numstr_len; | ||||
| const char *conv_float; /* Use a float conversion matching the grid size */ | const char *conv_float; /* Use a float conversion matching the grid size */ | ||||
| uchar col[4] = {0, 0, 0, 255}; /* color of the text to draw */ | uchar col[4] = {0, 0, 0, 255}; /* color of the text to draw */ | ||||
| float area; /* area of the face */ | float area; /* area of the face */ | ||||
| float grid = unit->system ? unit->scale_length : v3d->grid; | float grid = unit->system ? unit->scale_length : v3d->grid; | ||||
| const bool do_global = (v3d->flag & V3D_GLOBAL_STATS) != 0; | const bool do_global = (v3d->flag & V3D_GLOBAL_STATS) != 0; | ||||
| const bool do_moving = (G.moving & G_TRANSFORM_EDIT) != 0; | const bool do_moving = (G.moving & G_TRANSFORM_EDIT) != 0; | ||||
| float clip_planes[4][4]; | float clip_planes[4][4]; | ||||
| /* allow for displaying shape keys and deform mods */ | /* allow for displaying shape keys and deform mods */ | ||||
| BMIter iter; | BMIter iter; | ||||
| const float(*vert_coords)[3] = (me->runtime.edit_data ? me->runtime.edit_data->vertexCos : NULL); | const float(*vert_coords)[3] = (me->runtime.edit_data ? me->runtime.edit_data->vertexCos : | ||||
| const bool use_coords = (vert_coords != NULL); | nullptr); | ||||
| const bool use_coords = (vert_coords != nullptr); | |||||
| /* when 2 or more edge-info options are enabled, space apart */ | /* when 2 or more edge-info options are enabled, space apart */ | ||||
| short edge_tex_count = 0; | short edge_tex_count = 0; | ||||
| if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_LEN) { | if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_LEN) { | ||||
| edge_tex_count += 1; | edge_tex_count += 1; | ||||
| } | } | ||||
| if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_ANG) { | if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_ANG) { | ||||
| edge_tex_count += 1; | edge_tex_count += 1; | ||||
| } | } | ||||
| if ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_INDICES) && (em->selectmode & SCE_SELECT_EDGE)) { | if ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_INDICES) && (em->selectmode & SCE_SELECT_EDGE)) { | ||||
| edge_tex_count += 1; | edge_tex_count += 1; | ||||
| } | } | ||||
| const short edge_tex_sep = (short)((edge_tex_count - 1) * 5.0f * U.dpi_fac); | const short edge_tex_sep = short((edge_tex_count - 1) * 5.0f * U.dpi_fac); | ||||
| /* Make the precision of the display value proportionate to the grid-size. */ | /* Make the precision of the display value proportionate to the grid-size. */ | ||||
| if (grid <= 0.01f) { | if (grid <= 0.01f) { | ||||
| conv_float = "%.6g"; | conv_float = "%.6g"; | ||||
| } | } | ||||
| else if (grid <= 0.1f) { | else if (grid <= 0.1f) { | ||||
| conv_float = "%.5g"; | conv_float = "%.5g"; | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | void DRW_text_edit_mesh_measure_stats(ARegion *region, | ||||
| } | } | ||||
| if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_ANG) { | if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_ANG) { | ||||
| const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS); | const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS); | ||||
| BMEdge *eed; | BMEdge *eed; | ||||
| UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGEANG, col); | UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGEANG, col); | ||||
| const float(*poly_normals)[3] = NULL; | const float(*poly_normals)[3] = nullptr; | ||||
| if (use_coords) { | if (use_coords) { | ||||
| BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE); | BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE); | ||||
| BKE_editmesh_cache_ensure_poly_normals(em, me->runtime.edit_data); | BKE_editmesh_cache_ensure_poly_normals(em, me->runtime.edit_data); | ||||
| poly_normals = me->runtime.edit_data->polyNos; | poly_normals = me->runtime.edit_data->polyNos; | ||||
| } | } | ||||
| BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | ||||
| BMLoop *l_a, *l_b; | BMLoop *l_a, *l_b; | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | void DRW_text_edit_mesh_measure_stats(ARegion *region, | ||||
| if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_AREA) { | if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_AREA) { | ||||
| /* would be nice to use BM_face_calc_area, but that is for 2d faces | /* would be nice to use BM_face_calc_area, but that is for 2d faces | ||||
| * so instead add up tessellation triangle areas */ | * so instead add up tessellation triangle areas */ | ||||
| UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col); | UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col); | ||||
| int i, n; | int i, n; | ||||
| BMFace *f = NULL; | BMFace *f = nullptr; | ||||
| /* Alternative to using `poly_to_tri_count(i, BM_elem_index_get(f->l_first))` | /* Alternative to using `poly_to_tri_count(i, BM_elem_index_get(f->l_first))` | ||||
| * without having to add an extra loop. */ | * without having to add an extra loop. */ | ||||
| int looptri_index = 0; | int looptri_index = 0; | ||||
| BM_ITER_MESH_INDEX (f, &iter, em->bm, BM_FACES_OF_MESH, i) { | BM_ITER_MESH_INDEX (f, &iter, em->bm, BM_FACES_OF_MESH, i) { | ||||
| const int f_looptri_len = f->len - 2; | const int f_looptri_len = f->len - 2; | ||||
| if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { | if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { | ||||
| n = 0; | n = 0; | ||||
| area = 0; | area = 0; | ||||
| Show All 21 Lines | BM_ITER_MESH_INDEX (f, &iter, em->bm, BM_FACES_OF_MESH, i) { | ||||
| mul_mat3_m4_v3(ob->obmat, v1); | mul_mat3_m4_v3(ob->obmat, v1); | ||||
| mul_mat3_m4_v3(ob->obmat, v2); | mul_mat3_m4_v3(ob->obmat, v2); | ||||
| mul_mat3_m4_v3(ob->obmat, v3); | mul_mat3_m4_v3(ob->obmat, v3); | ||||
| } | } | ||||
| area += area_tri_v3(v1, v2, v3); | area += area_tri_v3(v1, v2, v3); | ||||
| } | } | ||||
| mul_v3_fl(vmid, 1.0f / (float)n); | mul_v3_fl(vmid, 1.0f / float(n)); | ||||
| mul_m4_v3(ob->obmat, vmid); | mul_m4_v3(ob->obmat, vmid); | ||||
| if (unit->system) { | if (unit->system) { | ||||
| numstr_len = BKE_unit_value_as_string( | numstr_len = BKE_unit_value_as_string( | ||||
| numstr, | numstr, | ||||
| sizeof(numstr), | sizeof(numstr), | ||||
| (double)(area * unit->scale_length * unit->scale_length), | double(area * unit->scale_length * unit->scale_length), | ||||
| 3, | 3, | ||||
| B_UNIT_AREA, | B_UNIT_AREA, | ||||
| unit, | unit, | ||||
| false); | false); | ||||
| } | } | ||||
| else { | else { | ||||
| numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, area); | numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, area); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines | |||||