[Bf-blender-cvs] [52668c5] master: GPencil: Layers with alpha = 0 should not be editable

Joshua Leung noreply at git.blender.org
Mon Feb 8 14:47:09 CET 2016


Commit: 52668c56b74f75c45a6b5176704dfd168fd3e6ac
Author: Joshua Leung
Date:   Tue Feb 9 02:44:02 2016 +1300
Branches: master
https://developer.blender.org/rB52668c56b74f75c45a6b5176704dfd168fd3e6ac

GPencil: Layers with alpha = 0 should not be editable

* Added a new API function to test if a GPencil layer is visible or not
* Replaced all editability checks with this new "super check"
* Replaced all magic number thresholds for opacity visiblity with a single define

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/screen/screen_context.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index dc43628..24e330d 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -58,6 +58,11 @@ struct bGPdata *gpencil_data_duplicate(struct bGPdata *gpd, bool internal_copy);
 void gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe *gpf);
 
 
+/* Stroke and Fill - Alpha Visibility Threshold */
+#define GPENCIL_ALPHA_OPACITY_THRESH 0.001f
+
+bool gpencil_layer_is_editable(const struct bGPDlayer *gpl);
+
 /* How gpencil_layer_getframe() should behave when there
  * is no existing GP-Frame on the frame requested.
  */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index afdac83..485c4f5 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -435,16 +435,41 @@ void gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf)
 
 /* -------- GP-Layer API ---------- */
 
+/* Check if the given layer is able to be edited or not */
+bool gpencil_layer_is_editable(const bGPDlayer *gpl)
+{
+	/* Sanity check */
+	if (gpl == NULL)
+		return false;
+	
+	/* Layer must be: Visible + Editable */
+	if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0) {
+		/* Opacity must be sufficiently high that it is still "visible"
+		 * Otherwise, it's not really "visible" to the user, so no point editing...
+		 */
+		if ((gpl->color[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gpl->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH)) {
+			return true;
+		}
+	}
+	
+	/* Something failed */
+	return false;
+}
+
+/* Look up the gp-frame on the requested frame number, but don't add a new one */
 bGPDframe *BKE_gpencil_layer_find_frame(bGPDlayer *gpl, int cframe)
 {
 	bGPDframe *gpf;
-
+	
+	/* Search in reverse order, since this is often used for playback/adding,
+	 * where it's less likely that we're interested in the earlier frames
+	 */
 	for (gpf = gpl->frames.last; gpf; gpf = gpf->prev) {
 		if (gpf->framenum == cframe) {
 			return gpf;
 		}
 	}
-
+	
 	return NULL;
 }
 
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 66d8628..b5d9283 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -993,7 +993,7 @@ static void gp_draw_data_layers(bGPdata *gpd, int offsx, int offsy, int winx, in
 		
 		/* fill strokes... */
 		// XXX: this is not a very good limit
-		GP_DRAWFLAG_APPLY((gpl->fill[3] > 0.001f), GP_DRAWDATA_FILL);
+		GP_DRAWFLAG_APPLY((gpl->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH), GP_DRAWDATA_FILL);
 #undef GP_DRAWFLAG_APPLY
 		
 		/* draw 'onionskins' (frame left + right) */
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 0d1698e..ef80f25 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -1118,9 +1118,7 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso)
 	/* go through each layer, and ensure that we've got a valid frame to use */
 	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 		/* only editable and visible layers are considered */
-		if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 &&
-		    (gpl->actframe != NULL))
-		{
+		if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
 			bGPDframe *gpf = gpl->actframe;
 			
 			/* Make a new frame to work on if the layer's frame and the current scene frame don't match up 
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 4852723..03d5ed3 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -391,7 +391,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
 		/* no active layer - let's just create one */
 		gpl = gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
 	}
-	else if (gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) {
+	else if (gpencil_layer_is_editable(gpl) == false) {
 		BKE_report(op->reports, RPT_ERROR, "Can not paste strokes when active layer is hidden or locked");
 		return OPERATOR_CANCELLED;
 	}
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index ab6253c..b76ed90 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -931,7 +931,7 @@ static void gp_stroke_doeraser(tGPsdata *p)
 		bGPDframe *gpf = gpl->actframe;
 		
 		/* only affect layer if it's editable (and visible) */
-		if (gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) {
+		if (gpencil_layer_is_editable(gpl) == false) {
 			continue;
 		}
 		else if (gpf == NULL) {
@@ -1220,7 +1220,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode)
 		bGPDlayer *gpl;
 		for (gpl = p->gpd->layers.first; gpl; gpl = gpl->next) {
 			/* Skip if layer not editable */
-			if (gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED))
+			if (gpencil_layer_is_editable(gpl) == false)
 				continue;
 			
 			/* Add a new frame if needed (and based off the active frame,
diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c
index 8a7ee3a..f61ad34 100644
--- a/source/blender/editors/screen/screen_context.c
+++ b/source/blender/editors/screen/screen_context.c
@@ -511,7 +511,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 			bGPDlayer *gpl;
 			
 			for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-				if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0) {
+				if (gpencil_layer_is_editable(gpl)) {
 					CTX_data_list_add(result, &gpd->id, &RNA_GPencilLayer, gpl);
 				}
 			}
@@ -527,7 +527,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
 			bGPDlayer *gpl;
 			
 			for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-				if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 && (gpl->actframe)) {
+				if (gpencil_layer_is_editable(gpl) && (gpl->actframe)) {
 					bGPDframe *gpf = gpl->actframe;
 					bGPDstroke *gps;
 					
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index ab0db79..03e3fa0 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -7645,9 +7645,7 @@ static void createTransGPencil(bContext *C, TransInfo *t)
 	 */
 	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 		/* only editable and visible layers are considered */
-		if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 &&
-		    (gpl->actframe != NULL))
-		{
+		if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
 			bGPDframe *gpf = gpl->actframe;
 			bGPDstroke *gps;
 			
@@ -7701,9 +7699,7 @@ static void createTransGPencil(bContext *C, TransInfo *t)
 	/* Second Pass: Build transdata array */
 	for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 		/* only editable and visible layers are considered */
-		if ((gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) == 0 &&
-		    (gpl->actframe != NULL))
-		{
+		if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
 			bGPDframe *gpf = gpl->actframe;
 			bGPDstroke *gps;
 			
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index c1fc1a8..291456a 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -145,7 +145,7 @@ static int rna_GPencilLayer_is_stroke_visible_get(PointerRNA *ptr)
 	 * about this limit for showing/not showing
 	 */
 	bGPDlayer *gpl = (bGPDlayer *)ptr->data;
-	return (gpl->color[3] > 0.001f);
+	return (gpl->color[3] > GPENCIL_ALPHA_OPACITY_THRESH);
 }
 
 static int rna_GPencilLayer_is_fill_visible_get(PointerRNA *ptr)
@@ -154,7 +154,7 @@ static int rna_GPencilLayer_is_fill_visible_get(PointerRNA *ptr)
 	 * about this limit for showing/not showing
 	 */
 	bGPDlayer *gpl = (bGPDlayer *)ptr->data;
-	return (gpl->fill[3] > 0.001f);
+	return (gpl->fill[3] > GPENCIL_ALPHA_OPACITY_THRESH);
 }
 
 static PointerRNA rna_GPencil_active_layer_get(PointerRNA *ptr)




More information about the Bf-blender-cvs mailing list