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.
This commit is contained in:
Antonio Vazquez 2019-02-14 16:36:40 +01:00
parent a2510434bb
commit 76747d0a11
Notes: blender-bot 2023-06-26 11:58:59 +02:00
Referenced by issue #61456, Erasing blank canvas activates Move operator
1 changed files with 21 additions and 2 deletions

View 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... */