From 14e1dfda4e145fb4d6975fd1531fad149b761bbb Mon Sep 17 00:00:00 2001 From: Antonioya Date: Wed, 31 Oct 2018 11:00:02 +0100 Subject: GP: New Autolock Inactive Layer This option locks any layer no active to avoid any accidental change. --- source/blender/blenkernel/intern/gpencil.c | 9 ++++++- source/blender/makesdna/DNA_gpencil_types.h | 2 ++ source/blender/makesrna/intern/rna_gpencil.c | 38 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 97aed40e998..63d7f3697f0 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -996,11 +996,18 @@ void BKE_gpencil_layer_setactive(bGPdata *gpd, bGPDlayer *active) return; /* loop over layers deactivating all */ - for (gpl = gpd->layers.first; gpl; gpl = gpl->next) + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { gpl->flag &= ~GP_LAYER_ACTIVE; + if (gpd->flag & GP_DATA_AUTOLOCK_LAYERS) { + gpl->flag |= GP_LAYER_LOCKED; + } + } /* set as active one */ active->flag |= GP_LAYER_ACTIVE; + if (gpd->flag & GP_DATA_AUTOLOCK_LAYERS) { + active->flag &= ~GP_LAYER_LOCKED; + } } /* delete the active gp-layer */ diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h index 2c59dd899a9..42070839fac 100644 --- a/source/blender/makesdna/DNA_gpencil_types.h +++ b/source/blender/makesdna/DNA_gpencil_types.h @@ -448,6 +448,8 @@ typedef enum eGPdata_Flag { GP_DATA_STROKE_POLYGON = (1 << 18), /* Use adaptative UV scales */ GP_DATA_UV_ADAPTATIVE = (1 << 19), + /* Autolock not active layers */ + GP_DATA_AUTOLOCK_LAYERS = (1 << 20), } eGPdata_Flag; /* gpd->onion_flag */ diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c index 73f26e9848e..9a8673e9a26 100644 --- a/source/blender/makesrna/intern/rna_gpencil.c +++ b/source/blender/makesrna/intern/rna_gpencil.c @@ -101,6 +101,38 @@ static void rna_GPencil_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointe WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL); } +static void rna_GPencil_autolock(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + bGPdata *gpd = (bGPdata *)ptr->id.data; + bGPDlayer *gpl = NULL; + + if (gpd->flag & GP_DATA_AUTOLOCK_LAYERS) { + bGPDlayer *layer = BKE_gpencil_layer_getactive(gpd); + + /* Lock all other layers */ + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { + /* unlock active layer */ + if (gpl == layer) { + gpl->flag &= ~GP_LAYER_LOCKED; + } + else { + gpl->flag |= GP_LAYER_LOCKED; + } + } + } + else { + /* If disable is better unlock all layers by default or it looks there is + * a problem in the UI because the user expects all layers will be unlocked + */ + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { + gpl->flag &= ~GP_LAYER_LOCKED; + } + } + + /* standard update */ + rna_GPencil_update(bmain, scene, ptr); +} + static void rna_GPencil_editmode_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { bGPdata *gpd = (bGPdata *)ptr->id.data; @@ -1410,6 +1442,12 @@ static void rna_def_gpencil_data(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Adaptative UV", "Automatic UVs are calculated depending of the stroke size"); RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update"); + prop = RNA_def_property(srna, "use_autolock_layers", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_AUTOLOCK_LAYERS); + RNA_def_property_ui_text(prop, "Autolock Layers", + "Lock automatically all layers except active one to avoid accidental changes"); + RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_autolock"); + prop = RNA_def_property(srna, "edit_line_color", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "line_color"); RNA_def_property_array(prop, 4); -- cgit v1.2.3