GP: Avoid eraser in empty frames and add warning.
authorAntonioya <blendergit@gmail.com>
Thu, 14 Feb 2019 15:36:40 +0000 (16:36 +0100)
committerAntonioya <blendergit@gmail.com>
Thu, 14 Feb 2019 15:52:14 +0000 (16:52 +0100)
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.

source/blender/editors/gpencil/gpencil_paint.c

index 8fc7978aa442bcc1c4ef359014a7b22143e4a967..3ab2b20559657b4a09332fcc87ae9fe534859162 100644 (file)
@@ -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... */