GPencil: Fix unreported autolock layers using Dopesheet

When select a layer in Dopesheet, the autolock layer was not working.

Now the Dopesheet code calls the function for autolock. Also some code cleanup to move the logic to new function.
This commit is contained in:
Antonio Vazquez 2019-09-03 18:58:57 +02:00
parent e91ea20ebe
commit 1abb1ba9a3
Notes: blender-bot 2023-02-14 10:11:54 +01:00
Referenced by issue #69597, Changing Grease Pencil Layer in Dopesheet unlocks all layers
5 changed files with 37 additions and 25 deletions

View File

@ -149,6 +149,7 @@ bool BKE_gpencil_layer_delframe(struct bGPDlayer *gpl, struct bGPDframe *gpf);
struct bGPDlayer *BKE_gpencil_layer_getactive(struct bGPdata *gpd);
void BKE_gpencil_layer_setactive(struct bGPdata *gpd, struct bGPDlayer *active);
void BKE_gpencil_layer_delete(struct bGPdata *gpd, struct bGPDlayer *gpl);
void BKE_gpencil_layer_autolock_set(struct bGPdata *gpd);
/* Brush */
struct Material *BKE_gpencil_brush_material_get(struct Brush *brush);

View File

@ -267,7 +267,8 @@ bGPDframe *BKE_gpencil_frame_addnew(bGPDlayer *gpl, int cframe)
/* check whether frame was added successfully */
if (state == -1) {
CLOG_ERROR(&LOG, "Frame (%d) existed already for this layer. Using existing frame", cframe);
CLOG_ERROR(
&LOG, "Frame (%d) existed already for this layer_active. Using existing frame", cframe);
/* free the newly created one, and use the old one instead */
MEM_freeN(gpf);
@ -1015,6 +1016,37 @@ void BKE_gpencil_layer_setactive(bGPdata *gpd, bGPDlayer *active)
}
}
/* Set locked layers for autolock mode. */
void BKE_gpencil_layer_autolock_set(bGPdata *gpd)
{
BLI_assert(gpd != NULL);
bGPDlayer *gpl;
if (gpd->flag & GP_DATA_AUTOLOCK_LAYERS) {
bGPDlayer *layer_active = BKE_gpencil_layer_getactive(gpd);
/* Lock all other layers */
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* unlock active layer */
if (gpl == layer_active) {
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;
}
}
}
/* delete the active gp-layer */
void BKE_gpencil_layer_delete(bGPdata *gpd, bGPDlayer *gpl)
{

View File

@ -3114,6 +3114,7 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index,
ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, gpl, ANIMTYPE_GPLAYER);
/* update other layer status */
BKE_gpencil_layer_setactive(gpd, gpl);
BKE_gpencil_layer_autolock_set(gpd);
}
/* Grease Pencil updates */

View File

@ -1724,6 +1724,7 @@ static void mouse_action_keys(bAnimContext *ac,
/* Update other layer status. */
if (BKE_gpencil_layer_getactive(gpd) != gpl) {
BKE_gpencil_layer_setactive(gpd, gpl);
BKE_gpencil_layer_autolock_set(gpd);
WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
}
}

View File

@ -151,30 +151,7 @@ static void rna_GPencil_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointe
static void rna_GPencil_autolock(Main *bmain, Scene *scene, PointerRNA *ptr)
{
bGPdata *gpd = (bGPdata *)ptr->owner_id;
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;
}
}
BKE_gpencil_layer_autolock_set(gpd);
/* standard update */
rna_GPencil_update(bmain, scene, ptr);