[Bf-blender-cvs] [452a1c7b383] master: Collections: Add color tagging

Nathan Craddock noreply at git.blender.org
Tue Sep 15 20:47:59 CEST 2020


Commit: 452a1c7b38383fd3f51532c429912677864e4a33
Author: Nathan Craddock
Date:   Tue Sep 15 12:13:03 2020 -0600
Branches: master
https://developer.blender.org/rB452a1c7b38383fd3f51532c429912677864e4a33

Collections: Add color tagging

This adds color tagging to collections. There are 8 color
options which are themable in the user preferences, with an additional
option for no color tag by default.

This adds a new filled collection icon and 8 colored variants of the
icon that can be themed in the user preferences.

In this commit the only interface to setting the color tags is through
Python, and there is nowhere in the interface where the collections are
shown colored. Setting and viewing the color tags from the outliner will
follow.

Manifest Task: https://developer.blender.org/T77777

Differential Revision: https://developer.blender.org/D8622

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

A	release/datafiles/blender_icons16/icon16_outliner_collection.dat
A	release/datafiles/blender_icons32/icon32_outliner_collection.dat
M	release/datafiles/userdef/userdef_default_theme.c
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/editors/include/UI_icons.h
M	source/blender/editors/include/UI_interface_icons.h
M	source/blender/editors/interface/interface_icons.c
M	source/blender/makesdna/DNA_collection_types.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_collection.c
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/release/datafiles/blender_icons16/icon16_outliner_collection.dat b/release/datafiles/blender_icons16/icon16_outliner_collection.dat
new file mode 100644
index 00000000000..c46a6ce6f66
Binary files /dev/null and b/release/datafiles/blender_icons16/icon16_outliner_collection.dat differ
diff --git a/release/datafiles/blender_icons32/icon32_outliner_collection.dat b/release/datafiles/blender_icons32/icon32_outliner_collection.dat
new file mode 100644
index 00000000000..0fdd735553e
Binary files /dev/null and b/release/datafiles/blender_icons32/icon32_outliner_collection.dat differ
diff --git a/release/datafiles/userdef/userdef_default_theme.c b/release/datafiles/userdef/userdef_default_theme.c
index 791630a1a9c..8cbb615491d 100644
--- a/release/datafiles/userdef/userdef_default_theme.c
+++ b/release/datafiles/userdef/userdef_default_theme.c
@@ -1103,6 +1103,32 @@ const bTheme U_theme_default = {
       .active = RGBA(0x000000ff),
     },
   },
+  .collection_color = {
+    {
+      .color = RGBA(0xe4312bff),
+    },
+    {
+      .color = RGBA(0xef7e42ff),
+    },
+    {
+      .color = RGBA(0xe4dd52ff),
+    },
+    {
+      .color = RGBA(0x9ac546ff),
+    },
+    {
+      .color = RGBA(0x46bcc2ff),
+    },
+    {
+      .color = RGBA(0x8b65dcff),
+    },
+    {
+      .color = RGBA(0x999999ff),
+    },
+    {
+      .color = RGBA(0x06d4432ff),
+    },
+  },
 };
 
 /* clang-format on */
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index faea806c6cb..40cb03acdfc 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1019,6 +1019,24 @@ class USERPREF_PT_theme_bone_color_sets(ThemePanel, CenterAlignMixIn, Panel):
             flow.prop(ui, "active")
             flow.prop(ui, "show_colored_constraints")
 
+class USERPREF_PT_theme_collection_colors(ThemePanel, CenterAlignMixIn, Panel):
+    bl_label = "Collection Colors"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw_header(self, _context):
+        layout = self.layout
+
+        layout.label(icon='OUTLINER_COLLECTION')
+
+    def draw_centered(self, context, layout):
+        theme = context.preferences.themes[0]
+
+        layout.use_property_split = True
+
+        flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
+        for i, ui in enumerate(theme.collection_color, 1):
+            flow.prop(ui, "color", text=iface_(f"Color {i:d}"), translate=False)
+
 
 # Base class for dynamically defined theme-space panels.
 # This is not registered.
@@ -2256,6 +2274,7 @@ classes = (
     USERPREF_PT_theme_interface_icons,
     USERPREF_PT_theme_text_style,
     USERPREF_PT_theme_bone_color_sets,
+    USERPREF_PT_theme_collection_colors,
 
     USERPREF_PT_file_paths_data,
     USERPREF_PT_file_paths_render,
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 836ce542793..e8b29ffac3e 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -204,6 +204,7 @@ static Collection *collection_add(Main *bmain,
 
   /* Create new collection. */
   Collection *collection = BKE_libblock_alloc(bmain, ID_GR, name, 0);
+  collection->color_tag = COLLECTION_COLOR_NONE;
 
   /* We increase collection user count when linking to Collections. */
   id_us_min(&collection->id);
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 2db2bb3c29e..3bf464602bc 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -661,5 +661,11 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
    */
   {
     /* Keep this block, even when empty. */
+    LISTBASE_FOREACH (Collection *, collection, &bmain->collections) {
+      collection->color_tag = COLLECTION_COLOR_NONE;
+    }
+    LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
+      scene->master_collection->color_tag = COLLECTION_COLOR_NONE;
+    }
   }
 }
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index a0a60630986..d53959a1949 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -236,6 +236,9 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
    */
   {
     /* Keep this block, even when empty. */
+    for (int i = 0; i < COLLECTION_COLOR_TOT; ++i) {
+      FROM_DEFAULT_V4_UCHAR(collection_color[i].color);
+    }
 
     FROM_DEFAULT_V4_UCHAR(space_properties.match);
   }
diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h
index 452a1fca111..e976aac27a2 100644
--- a/source/blender/editors/include/UI_icons.h
+++ b/source/blender/editors/include/UI_icons.h
@@ -320,7 +320,7 @@ DEF_ICON_OBJECT(OUTLINER_OB_GROUP_INSTANCE)
 DEF_ICON_OBJECT(OUTLINER_OB_GREASEPENCIL)
 DEF_ICON_OBJECT(OUTLINER_OB_LIGHTPROBE)
 DEF_ICON_OBJECT(OUTLINER_OB_IMAGE)
-DEF_ICON_BLANK(321)
+DEF_ICON(OUTLINER_COLLECTION)
 DEF_ICON(RESTRICT_COLOR_OFF)
 DEF_ICON(RESTRICT_COLOR_ON)
 DEF_ICON(HIDE_ON)
@@ -980,6 +980,15 @@ DEF_ICON_VECTOR(COLORSET_18_VEC)
 DEF_ICON_VECTOR(COLORSET_19_VEC)
 DEF_ICON_VECTOR(COLORSET_20_VEC)
 
+DEF_ICON_VECTOR(COLLECTION_COLOR_01)
+DEF_ICON_VECTOR(COLLECTION_COLOR_02)
+DEF_ICON_VECTOR(COLLECTION_COLOR_03)
+DEF_ICON_VECTOR(COLLECTION_COLOR_04)
+DEF_ICON_VECTOR(COLLECTION_COLOR_05)
+DEF_ICON_VECTOR(COLLECTION_COLOR_06)
+DEF_ICON_VECTOR(COLLECTION_COLOR_07)
+DEF_ICON_VECTOR(COLLECTION_COLOR_08)
+
 /* Events  */
 DEF_ICON_COLOR(EVENT_A)
 DEF_ICON_COLOR(EVENT_B)
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index bbe66f7fd73..9c0539d5c2f 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -32,6 +32,7 @@ struct PointerRNA;
 struct PreviewImage;
 struct Scene;
 struct bContext;
+struct Collection;
 
 enum eIconSizes;
 
@@ -107,6 +108,7 @@ int UI_rnaptr_icon_get(struct bContext *C, struct PointerRNA *ptr, int rnaicon,
 int UI_idcode_icon_get(const int idcode);
 int UI_library_icon_get(const struct ID *id);
 int UI_mode_icon_get(const int mode);
+int UI_collection_color_icon_get(const struct Collection *collection);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index d22ddb5f2b7..7008d22becc 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -41,6 +41,7 @@
 #include "BLI_utildefines.h"
 
 #include "DNA_brush_types.h"
+#include "DNA_collection_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_dynamicpaint_types.h"
 #include "DNA_gpencil_types.h"
@@ -461,6 +462,33 @@ DEF_ICON_VECTOR_COLORSET_DRAW_NTH(20, 19)
 
 #  undef DEF_ICON_VECTOR_COLORSET_DRAW_NTH
 
+static void vicon_collection_color_draw(
+    short color_tag, int x, int y, int UNUSED(w), int UNUSED(h), float UNUSED(alpha))
+{
+  bTheme *btheme = UI_GetTheme();
+  const ThemeCollectionColor *collection_color = &btheme->collection_color[color_tag];
+
+  UI_icon_draw_ex(
+      x, y, ICON_OUTLINER_COLLECTION, U.inv_dpi_fac, 1.0f, 0.0f, collection_color->color, true);
+}
+
+#  define DEF_ICON_COLLECTION_COLOR_DRAW(index, color) \
+    static void vicon_collection_color_draw_##index(int x, int y, int w, int h, float alpha) \
+    { \
+      vicon_collection_color_draw(color, x, y, w, h, alpha); \
+    }
+
+DEF_ICON_COLLECTION_COLOR_DRAW(01, COLLECTION_COLOR_01);
+DEF_ICON_COLLECTION_COLOR_DRAW(02, COLLECTION_COLOR_02);
+DEF_ICON_COLLECTION_COLOR_DRAW(03, COLLECTION_COLOR_03);
+DEF_ICON_COLLECTION_COLOR_DRAW(04, COLLECTION_COLOR_04);
+DEF_ICON_COLLECTION_COLOR_DRAW(05, COLLECTION_COLOR_05);
+DEF_ICON_COLLECTION_COLOR_DRAW(06, COLLECTION_COLOR_06);
+DEF_ICON_COLLECTION_COLOR_DRAW(07, COLLECTION_COLOR_07);
+DEF_ICON_COLLECTION_COLOR_DRAW(08, COLLECTION_COLOR_08);
+
+#  undef DEF_ICON_COLLECTION_COLOR_DRAW
+
 /* Dynamically render icon instead of rendering a plain color to a texture/buffer
  * This is not strictly a "vicon", as it needs access to icon->obj to get the color info,
  * but it works in a very similar way.
@@ -969,6 +997,15 @@ static void init_internal_icons(void)
   def_internal_vicon(ICON_COLORSET_18_VEC, vicon_colorset_draw_18);
   def_internal_vicon(ICON_COLORSET_19_VEC, vicon_colorset_draw_19);
   def_internal_vicon(ICON_COLORSET_20_VEC, vicon_colorset_draw_20);
+
+  def_internal_vicon(ICON_COLLECTION_COLOR_01, vicon_collection_color_draw_01);
+  def_internal_vicon(ICON_COLLECTION_COLOR_02, vicon_collection_color_draw_02);
+  def_internal_vicon(ICON_COLLECTION_COLOR_03, vicon_collection_color_draw_03);
+  def_internal_vicon(ICON_COLLECTION_COLOR_04, vicon_collection_color_draw_04);
+  def_internal_vicon(ICON_COLLECTION_COLOR_05, vicon_collection_color_draw_05);
+  def_internal_vicon(ICON_COLLECTION_COLOR_06, vicon_collection_color_draw_06);
+  def_internal_vicon(ICON_COLLECTION_COLOR_07, vicon_collection_color_draw_07);
+  def_internal_vicon(ICON_COLLECTION_COLOR_08, vicon_collection_color_draw_08);
 }
 
 static void init_iconfile_list(struct ListBase *list)
@@ -2324,6 +2361,17 @@ int UI_mode_icon_get(const int mode)
   }
 }
 
+int UI_collection_color_icon_get(const Collection *collection)
+{
+  int icon = ICON_OUTLINER_COLLECTION;
+
+  if (collection->color_tag != COLLECTION_COLOR_NONE) {
+    icon = ICON_COLLECTION_COLOR_01 + collection->color_tag;
+  }
+
+  return icon;
+}
+
 /* draws icon with dpi scale factor */
 void UI_icon_draw(float x, float y, int icon_id)
 {
diff --git a/source/blender/makesdna/DNA_collection_types.h b/source/blender/makesdna/DNA_collection_types.h
index 6cf02137fa6..e188426fdda 100644
--- a/source/blender/makesdna/DNA_collection_types.h
+++ b/source/blender/makesdna/DNA_collection_types.h
@@ -58,7 +58,9 @@ typedef struct Collection {
   short flag;
   /* Runtime-only, always cleared on file load. */
   shor

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list