[Bf-blender-cvs] [ddd5d35fba0] greasepencil-refactor: GPencil: New list of Masking Layers

Antonio Vazquez noreply at git.blender.org
Sun Feb 9 18:17:48 CET 2020


Commit: ddd5d35fba0dc4c260802d3e224a391fd2230469
Author: Antonio Vazquez
Date:   Sun Feb 9 18:09:54 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBddd5d35fba0dc4c260802d3e224a391fd2230469

GPencil: New list of Masking Layers

This replaces the old unique layer for masking with a full list.

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.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 02745874283..b6f90da3941 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -171,11 +171,9 @@ class DATA_PT_gpencil_layers(DataButtonsPanel, Panel):
             layout.use_property_decorate = True
             col = layout.column(align=True)
 
-            if not gpl.mask_layer:
+            if not gpl.use_mask_layer:
                 col = layout.row(align=True)
                 col.prop(gpl, "blend_mode", text="Blend")
-                col = layout.row(align=True)
-                col.prop_search(gpl, "mask_layer_name", gpd, "layers", icon='GREASEPENCIL')
 
             col = layout.row(align=True)
             col.prop(gpl, "opacity", text="Opacity", slider=True)
@@ -310,6 +308,34 @@ class GPENCIL_UL_vgroups(UIList):
             layout.label(text="", icon_value=icon)
 
 
+class GPENCIL_UL_masks(UIList):
+    def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
+        mask = item
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            layout.prop(mask, "name", text="", emboss=False, icon_value=icon)
+        elif self.layout_type == 'GRID':
+            layout.alignment = 'CENTER'
+            layout.prop(mask, "name", text="", emboss=False, icon_value=icon)
+
+
+class DATA_PT_gpencil_layer_masks(ObjectButtonsPanel, Panel):
+    bl_label = "Masks"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw(self, context):
+        layout = self.layout
+        ob = context.active_object
+        gpd = ob.data
+        gpl = gpd.layers.active
+        if gpl:
+            rows = 4
+            row = layout.row()
+            row.template_list("GPENCIL_UL_masks", "", gpl, "mask_layers", gpl.mask_layers, "active_mask_index", rows=rows)
+            col = row.column(align=True)
+            col.operator("gpencil.layer_mask_add", icon="ADD", text="")
+            col.operator("gpencil.layer_mask_remove", icon='REMOVE', text="")
+
+
 class DATA_PT_gpencil_vertex_groups(ObjectButtonsPanel, Panel):
     bl_label = "Vertex Groups"
     bl_options = {'DEFAULT_CLOSED'}
@@ -418,6 +444,7 @@ class DATA_PT_custom_props_gpencil(DataButtonsPanel, PropertyPanel, Panel):
 classes = (
     DATA_PT_context_gpencil,
     DATA_PT_gpencil_layers,
+    DATA_PT_gpencil_layer_masks,
     DATA_PT_gpencil_onion_skinning,
     DATA_PT_gpencil_onion_skinning_custom_colors,
     DATA_PT_gpencil_onion_skinning_display,
@@ -431,6 +458,7 @@ classes = (
     DATA_PT_custom_props_gpencil,
 
     GPENCIL_UL_vgroups,
+    GPENCIL_UL_masks,
 
     GPENCIL_MT_layer_context_menu,
     GPENCIL_MT_gpencil_vertex_group,
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index f0858ed49d8..37cf1ad275f 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -692,10 +692,10 @@ class GPENCIL_UL_layer(UIList):
             row = layout.row(align=True)
 
             icon_mask = 'LAYER_ACTIVE'
-            if gpl.mask_layer:
+            if gpl.use_mask_layer:
                 icon_mask = 'HOLDOUT_ON' if gpl.invert_mask else 'MOD_MASK'
 
-            row.prop(gpl, "mask_layer", text="", icon=icon_mask, emboss=False)
+            row.prop(gpl, "use_mask_layer", text="", icon=icon_mask, emboss=False)
 
             subrow = row.row(align=True)
             subrow.prop(
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 82a1f5b6b0a..1f52323f540 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -165,8 +165,8 @@ class TOPBAR_PT_gpencil_layers(Panel):
 
             srow = col.row(align=True)
             srow.prop(gpl, "opacity", text="Opacity", slider=True)
-            srow.prop(gpl, "mask_layer", text="",
-                      icon='MOD_MASK' if gpl.mask_layer else 'LAYER_ACTIVE')
+            srow.prop(gpl, "use_mask_layer", text="",
+                      icon='MOD_MASK' if gpl.use_mask_layer else 'LAYER_ACTIVE')
 
             srow = col.row(align=True)
             srow.prop(gpl, "use_lights")
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index f19af3cb1b7..ee2651949ca 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -90,6 +90,7 @@ void BKE_gpencil_free_frames(struct bGPDlayer *gpl);
 void BKE_gpencil_free_layers(struct ListBase *list);
 void BKE_gpencil_free(struct bGPdata *gpd, bool free_all);
 void BKE_gpencil_eval_delete(struct bGPdata *gpd_eval);
+void BKE_gpencil_free_layer_masks(struct bGPDlayer *gpl);
 
 void BKE_gpencil_batch_cache_dirty_tag(struct bGPdata *gpd);
 void BKE_gpencil_batch_cache_free(struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index cc793816c12..dab7bedef87 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -180,6 +180,15 @@ void BKE_gpencil_free_frames(bGPDlayer *gpl)
   gpl->actframe = NULL;
 }
 
+void BKE_gpencil_free_layer_masks(bGPDlayer *gpl)
+{
+  /* Free masks.*/
+  bGPDlayer_Mask *mask_next = NULL;
+  for (bGPDlayer_Mask *mask = gpl->mask_layers.first; mask; mask = mask_next) {
+    mask_next = mask->next;
+    BLI_freelinkN(&gpl->mask_layers, mask);
+  }
+}
 /* Free all of the gp-layers for a viewport (list should be &gpd->layers or so) */
 void BKE_gpencil_free_layers(ListBase *list)
 {
@@ -196,6 +205,10 @@ void BKE_gpencil_free_layers(ListBase *list)
 
     /* free layers and their data */
     BKE_gpencil_free_frames(gpl);
+
+    /* Free masks.*/
+    BKE_gpencil_free_layer_masks(gpl);
+
     BLI_freelinkN(list, gpl);
   }
 }
@@ -397,7 +410,6 @@ bGPDlayer *BKE_gpencil_layer_addnew(bGPdata *gpd, const char *name, bool setacti
 
   /* Enable always affected by scene lights. */
   gpl->flag |= GP_LAYER_USE_LIGHTS;
-  gpl->mask_layer[0] = '\0';
   /* make this one the active one */
   if (setactive) {
     BKE_gpencil_layer_active_set(gpd, gpl);
@@ -635,6 +647,14 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
   gpl_dst = MEM_dupallocN(gpl_src);
   gpl_dst->prev = gpl_dst->next = NULL;
 
+  /* Copy masks. */
+  BLI_listbase_clear(&gpl_dst->mask_layers);
+  LISTBASE_FOREACH (bGPDlayer_Mask *, mask_src, &gpl_src->mask_layers) {
+    bGPDlayer_Mask *mask_dst = MEM_dupallocN(mask_src);
+    mask_dst->prev = mask_dst->next = NULL;
+    BLI_addtail(&gpl_dst->mask_layers, mask_dst);
+  }
+
   /* copy frames */
   BLI_listbase_clear(&gpl_dst->frames);
   for (gpf_src = gpl_src->frames.first; gpf_src; gpf_src = gpf_src->next) {
@@ -1094,6 +1114,9 @@ void BKE_gpencil_layer_delete(bGPdata *gpd, bGPDlayer *gpl)
   /* free layer */
   BKE_gpencil_free_frames(gpl);
 
+  /* Free Masks. */
+  BKE_gpencil_free_layer_masks(gpl);
+
   /* free icon providing preview of icon color */
   BKE_icon_delete(gpl->runtime.icon_id);
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 37fcf10e553..bcadae42152 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6991,6 +6991,9 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
 
     gpl->runtime.icon_id = 0;
 
+    /* Relink masks. */
+    link_list(fd, &gpl->mask_layers);
+
     LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
       /* relink strokes (and their points) */
       link_list(fd, &gpf->strokes);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index dd8a5a6795a..d555313510b 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2727,6 +2727,8 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd)
     /* write grease-pencil layers to file */
     writelist(wd, DATA, bGPDlayer, &gpd->layers);
     LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+      /* Write mask list. */
+      writelist(wd, DATA, bGPDframe, &gpl->mask_layers);
       /* write this layer's frames to file */
       writelist(wd, DATA, bGPDframe, &gpl->frames);
       LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index 6b4e017c96b..e81959c476d 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -134,12 +134,13 @@ GPENCIL_tLayer *gpencil_layer_cache_add(GPENCIL_PrivateData *pd, Object *ob, bGP
   tgp_layer->layer_id = BLI_findindex(&gpd->layers, gpl);
   tgp_layer->mask_id = -1;
 
-  bGPDlayer *gpl_mask = BKE_gpencil_layer_named_get(gpd, gpl->mask_layer);
-  if (gpl_mask && (gpl_mask != gpl) && ((gpl_mask->flag & GP_LAYER_HIDE) == 0)) {
-    mask_invert = (gpl->flag & GP_LAYER_MASK_INVERT) != 0;
-    tgp_layer->mask_id = BLI_findindex(&gpd->layers, gpl_mask);
-    pd->use_mask_fb = true;
-  }
+  // TODO GPXX (New masking)
+  // bGPDlayer *gpl_mask = BKE_gpencil_layer_named_get(gpd, gpl->mask_layer);
+  // if (gpl_mask && (gpl_mask != gpl) && ((gpl_mask->flag & GP_LAYER_HIDE) == 0)) {
+  //  mask_invert = (gpl->flag & GP_LAYER_MASK_INVERT) != 0;
+  //  tgp_layer->mask_id = BLI_findindex(&gpd->layers, gpl_mask);
+  //  pd->use_mask_fb = true;
+  //}
 
   const bool is_masked = tgp_layer->mask_id != -1;
 
@@ -228,4 +229,4 @@ GPENCIL_tLayer *gpencil_layer_cache_get(GPENCIL_tObject *tgp_ob, int number)
     }
   }
   return NULL;
-}
\ No newline at end of file
+}
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index f5c0548eaa1..932f2893dec 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -5089,32

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list