GPencil: Add support to display the material name in selected strokes

2D artists have requested a way to see in viewport the name of the material assigned to a stroke. This is a special request for 2D animation and required to manage complex drawings with multiple materials on it. We don't need add a separate option for this in the panel.

Now, when enable Name option in the Viewport Display panel, when you select a stroke in edit mode, the name of the material is displayed near the first point selected.

Design reviewed by @mendio and @pepeland
This commit is contained in:
Antonio Vazquez 2019-03-11 17:42:45 +01:00
parent 84cb5f3b5c
commit 057117de78
Notes: blender-bot 2023-02-14 11:08:33 +01:00
Referenced by issue #62465, Grease pencil material users below zero
1 changed files with 60 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "DNA_constraint_types.h"
#include "DNA_camera_types.h"
#include "DNA_curve_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
#include "DNA_modifier_types.h"
@ -2873,6 +2874,60 @@ static void OBJECT_cache_populate_particles(
}
}
static void OBJECT_gpencil_color_names(Object *ob, struct DRWTextStore *dt, uchar color[4])
{
if (ob->mode != OB_MODE_EDIT_GPENCIL) {
return;
}
bGPdata *gpd = (bGPdata *)ob->data;
if (gpd == NULL) {
return;
}
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if (gpl->flag & GP_LAYER_HIDE) {
continue;
}
bGPDframe *gpf = gpl->actframe;
if (gpf == NULL) {
continue;
}
for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
Material *ma = give_current_material(ob, gps->mat_nr + 1);
if (ma == NULL) {
continue;
}
MaterialGPencilStyle *gp_style = ma->gp_style;
/* skip stroke if it doesn't have any valid data */
if ((gps->points == NULL) || (gps->totpoints < 1) || (gp_style == NULL)) {
continue;
}
/* check if the color is visible */
if (gp_style->flag & GP_STYLE_COLOR_HIDE) {
continue;
}
/* only if selected */
if (gps->flag & GP_STROKE_SELECT) {
float fpt[3];
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
if (pt->flag & GP_SPOINT_SELECT) {
mul_v3_m4v3(fpt, ob->obmat, &pt->x);
DRW_text_cache_add(
dt, fpt,
ma->id.name + 2, strlen(ma->id.name + 2),
10, 0, DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, color);
break;
}
}
}
}
}
}
static void OBJECT_cache_populate(void *vedata, Object *ob)
{
OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
@ -3143,6 +3198,11 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
dt, ob->obmat[3],
ob->id.name + 2, strlen(ob->id.name + 2),
10, 0, DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, color);
/* draw grease pencil stroke names */
if (ob->type == OB_GPENCIL) {
OBJECT_gpencil_color_names(ob, dt, color);
}
}
if ((ob->dtx & OB_TEXSPACE) && ELEM(ob->type, OB_MESH, OB_CURVE, OB_MBALL)) {