GP: New Autolock Inactive Layer

This option locks any layer no active to avoid any accidental change.
This commit is contained in:
Antonioya
2018-10-31 11:00:02 +01:00
parent 7bc84559aa
commit 14e1dfda4e
4 changed files with 52 additions and 1 deletions

View File

@@ -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'

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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);