[Bf-blender-cvs] [76747d0a115] master: GP: Avoid eraser in empty frames and add warning.

Antonioya noreply at git.blender.org
Thu Feb 14 16:52:23 CET 2019


Commit: 76747d0a11582ccd49fde494a51187dc191d6aee
Author: Antonioya
Date:   Thu Feb 14 16:36:40 2019 +0100
Branches: master
https://developer.blender.org/rB76747d0a11582ccd49fde494a51187dc191d6aee

GP: Avoid eraser in empty frames and add warning.

Also capture event to avoid Move transform.

Note: Now it's using a report message. Maybe this can be removed, but without the message, the event is captured by move transform.

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

M	source/blender/editors/gpencil/gpencil_paint.c

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

diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 8fc7978aa44..3ab2b205596 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -2084,7 +2084,8 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps
 		if (p->custom_color[3])
 			copy_v3_v3(p->gpl->color, p->custom_color);
 	}
-	if (p->gpl->flag & GP_LAYER_LOCKED) {
+	if ((paintmode != GP_PAINTMODE_ERASER) &&
+		(p->gpl->flag & GP_LAYER_LOCKED)) {
 		p->status = GP_STATUS_ERROR;
 		if (G.debug & G_DEBUG)
 			printf("Error: Cannot paint on locked layer\n");
@@ -3123,6 +3124,8 @@ static void gpencil_guide_event_handling(bContext *C, wmOperator *op, const wmEv
 static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	tGPsdata *p = NULL;
+	Object *ob = CTX_data_active_object(C);
+	bGPdata *gpd = (bGPdata *)ob->data;
 
 	if (G.debug & G_DEBUG)
 		printf("GPencil - Starting Drawing\n");
@@ -3141,6 +3144,23 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
 			return OPERATOR_CANCELLED;
 		}
 	}
+	else {
+		/* don't erase empty frames */
+		bool has_layer_to_erase = false;
+		for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+			/* Skip if layer not editable */
+			if (gpencil_layer_is_editable(gpl)) {
+				if (gpl->actframe && gpl->actframe->strokes.first) {
+					has_layer_to_erase = true;
+					break;
+				}
+			}
+		}
+		if (!has_layer_to_erase) {
+			BKE_report(op->reports, RPT_ERROR, "Nothing to erase or all layers locked");
+			return OPERATOR_FINISHED;
+		}
+	}
 
 	/* try to initialize context data needed while drawing */
 	if (!gpencil_draw_init(C, op, event)) {
@@ -3193,7 +3213,6 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
 		gpencil_guide_event_handling(C, op, event, p);
 	}
 
-	Object *ob = CTX_data_active_object(C);
 	if (ob && (ob->type == OB_GPENCIL) && ((p->gpd->flag & GP_DATA_STROKE_PAINTMODE) == 0)) {
 		/* FIXME: use the mode switching operator, this misses notifiers, messages. */
 		/* Just set paintmode flag... */



More information about the Bf-blender-cvs mailing list