[Bf-blender-cvs] [14e1dfda4e1] blender2.8: GP: New Autolock Inactive Layer

Antonioya noreply at git.blender.org
Wed Oct 31 11:00:34 CET 2018


Commit: 14e1dfda4e145fb4d6975fd1531fad149b761bbb
Author: Antonioya
Date:   Wed Oct 31 11:00:02 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB14e1dfda4e145fb4d6975fd1531fad149b761bbb

GP: New Autolock Inactive Layer

This option locks any layer no active to avoid any accidental change.

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index a40ba463603..7f7813cad36 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -160,6 +160,10 @@ class DATA_PT_gpencil_datapanel(Panel):
         if gpl:
             row.prop(gpl, "opacity", text="Opacity", slider=True)
 
+            # autolock layers
+            row = layout.row(align=True)
+            row.prop(gpd, "use_autolock_layers", text="Autolock Inactive Layers")
+
 
 class DATA_PT_gpencil_layer_optionpanel(LayerDataButtonsPanel, Panel):
     bl_space_type = 'PROPERTIES'
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);



More information about the Bf-blender-cvs mailing list