[Bf-blender-cvs] [057117de786] master: GPencil: Add support to display the material name in selected strokes

Antonioya noreply at git.blender.org
Mon Mar 11 17:42:53 CET 2019


Commit: 057117de7869cc7adb5f82f25879f15ce18ac4dd
Author: Antonioya
Date:   Mon Mar 11 17:42:45 2019 +0100
Branches: master
https://developer.blender.org/rB057117de7869cc7adb5f82f25879f15ce18ac4dd

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

===================================================================

M	source/blender/draw/modes/object_mode.c

===================================================================

diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 3c64fe14100..1a7e9e40d6d 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -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)) {



More information about the Bf-blender-cvs mailing list