GPencil: Implement custom channel color in Dopesheet
authorAntonioya <blendergit@gmail.com>
Wed, 3 Apr 2019 08:25:49 +0000 (10:25 +0200)
committerAntonioya <blendergit@gmail.com>
Wed, 3 Apr 2019 08:25:49 +0000 (10:25 +0200)
A new parameter in the layer adjustment panel allows to define the color of the channel in Dopesheet.

This is needed when there are a lot of layers.

See D4623 for more details.

release/scripts/startup/bl_ui/properties_data_gpencil.py
source/blender/blenkernel/intern/gpencil.c
source/blender/blenloader/intern/versioning_280.c
source/blender/editors/animation/anim_channels_defines.c
source/blender/makesrna/intern/rna_gpencil.c

index 2374faa..0348b24 100644 (file)
@@ -224,6 +224,23 @@ class DATA_PT_gpencil_layer_relations(LayerDataButtonsPanel, Panel):
             col.prop_search(gpl, "parent_bone", parent.data, "bones", text="Bone")
 
 
+class DATA_PT_gpencil_layer_display(LayerDataButtonsPanel, Panel):
+    bl_label = "Display"
+    bl_parent_id = 'DATA_PT_gpencil_layers'
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw(self, context):
+        layout = self.layout
+        layout.use_property_split = True
+        layout.use_property_decorate = False
+
+        gpd = context.gpencil
+        gpl = gpd.layers.active
+
+        col = layout.row(align=True)
+        col.prop(gpl, "channel_color")
+
+
 class DATA_PT_gpencil_onion_skinning(DataButtonsPanel, Panel):
     bl_label = "Onion Skinning"
     bl_options = {'DEFAULT_CLOSED'}
@@ -449,6 +466,7 @@ classes = (
     DATA_PT_gpencil_onion_skinning_display,
     DATA_PT_gpencil_layer_adjustments,
     DATA_PT_gpencil_layer_relations,
+    DATA_PT_gpencil_layer_display,
     DATA_PT_gpencil_vertex_groups,
     DATA_PT_gpencil_strokes,
     DATA_PT_gpencil_display,
index 6981d70..2ef8568 100644 (file)
@@ -374,6 +374,8 @@ bGPDlayer *BKE_gpencil_layer_addnew(bGPdata *gpd, const char *name, bool setacti
                /* thickness parameter represents "thickness change", not absolute thickness */
                gpl->thickness = 0;
                gpl->opacity = 1.0f;
+               /* default channel color */
+               ARRAY_SET_ITEMS(gpl->color, 0.2f, 0.2f, 0.2f);
        }
 
        /* auto-name */
index 4173bb9..a1087ca 100644 (file)
@@ -2952,6 +2952,19 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
                                mat->blend_shadow = MA_BS_SOLID;
                        }
                }
+
+               /* grease pencil default animation channel color */
+               {
+                       for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
+                               if (gpd->flag & GP_DATA_ANNOTATIONS) {
+                                       continue;
+                               }
+                               for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+                                       /* default channel color */
+                                       ARRAY_SET_ITEMS(gpl->color, 0.2f, 0.2f, 0.2f);
+                               }
+                       }
+               }
        }
 
        {
index 997b3c2..618ac8f 100644 (file)
@@ -220,6 +220,23 @@ static void acf_generic_channel_color(bAnimContext *ac, bAnimListElem *ale, floa
        }
 }
 
+/* get backdrop color for grease pencil channels */
+static void acf_gpencil_channel_color(bAnimContext *ac, bAnimListElem *ale, float r_color[3])
+{
+       const bAnimChannelType *acf = ANIM_channel_get_typeinfo(ale);
+       short indent = (acf->get_indent_level) ? acf->get_indent_level(ac, ale) : 0;
+       bool showGroupColors = acf_show_channel_colors(ac);
+       
+       if ((showGroupColors) && (ale->type == ANIMTYPE_GPLAYER)) {
+               bGPDlayer *gpl = (bGPDlayer *)ale->data;
+               copy_v3_v3(r_color, gpl->color);
+       }
+       else {
+               int colOfs = 10 - 10 * indent;
+               UI_GetThemeColorShade3fv(TH_SHADE2, colOfs, r_color);
+       }
+}
+
 /* backdrop for generic channels */
 static void acf_generic_channel_backdrop(bAnimContext *ac, bAnimListElem *ale, float yminc, float ymaxc)
 {
@@ -3058,7 +3075,7 @@ static bAnimChannelType ACF_GPL =
        "GPencil Layer",                /* type name */
        ACHANNEL_ROLE_CHANNEL,          /* role */
 
-       acf_generic_channel_color,      /* backdrop color */
+       acf_gpencil_channel_color,      /* backdrop color */
        acf_generic_channel_backdrop,   /* backdrop */
        acf_generic_indention_flexible, /* indent level */
        acf_generic_group_offset,       /* offset */
index eefac81..73203be 100644 (file)
@@ -1145,6 +1145,15 @@ static void rna_def_gpencil_layer(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Opacity", "Layer Opacity");
        RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
+       /* layer channel color (grease pencil)  */
+       prop = RNA_def_property(srna, "channel_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+       RNA_def_property_float_sdna(prop, NULL, "color");
+       RNA_def_property_array(prop, 3);
+       RNA_def_property_range(prop, 0.0f, 1.0f);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_ui_text(prop, "Custom Channel Color",
+               "Custom color for animation channel in Dopesheet");
+       RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
        /* Stroke Drawing Color (Annotations) */
        prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);