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
This commit is contained in:
Nathan Craddock 2020-09-15 12:13:03 -06:00
parent f137022f99
commit 452a1c7b38
Notes: blender-bot 2023-02-14 07:30:31 +01:00
Referenced by commit 0633a89e18, UI: Remove remaining uses of old collection icon
Referenced by issue #77408, Continued Outliner Improvements Design
16 changed files with 186 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -58,7 +58,9 @@ typedef struct Collection {
short flag;
/* Runtime-only, always cleared on file load. */
short tag;
char _pad[4];
int16_t color_tag;
char _pad[2];
/* Runtime. Cache of objects in this collection and all its
* children. This is created on demand when e.g. some physics
@ -92,3 +94,18 @@ enum {
* Using a generic tag like LIB_TAG_DOIT for this is just impossible, we need our very own. */
COLLECTION_TAG_RELATION_REBUILD = (1 << 0),
};
/* Collection->color_tag. */
typedef enum CollectionColorTag {
COLLECTION_COLOR_NONE = -1,
COLLECTION_COLOR_01,
COLLECTION_COLOR_02,
COLLECTION_COLOR_03,
COLLECTION_COLOR_04,
COLLECTION_COLOR_05,
COLLECTION_COLOR_06,
COLLECTION_COLOR_07,
COLLECTION_COLOR_08,
COLLECTION_COLOR_TOT,
} CollectionColorTag;

View File

@ -453,6 +453,10 @@ typedef enum eWireColor_Flags {
/* TH_WIRECOLOR_TEXTCOLS = (1 << 1), */ /* UNUSED */
} eWireColor_Flags;
typedef struct ThemeCollectionColor {
unsigned char color[4];
} ThemeCollectionColor;
/**
* A theme.
*
@ -491,6 +495,9 @@ typedef struct bTheme {
ThemeWireColor tarm[20];
/*ThemeWireColor tobj[20];*/
/* See COLLECTION_COLOR_TOT for the number of collection colors. */
ThemeCollectionColor collection_color[8];
int active_theme_area;
char _pad0[4];
} bTheme;

View File

@ -645,6 +645,7 @@ extern StructRNA RNA_TextureNodeViewer;
extern StructRNA RNA_TextureSlot;
extern StructRNA RNA_Theme;
extern StructRNA RNA_ThemeBoneColorSet;
extern StructRNA RNA_ThemeCollectionColor;
extern StructRNA RNA_ThemeConsole;
extern StructRNA RNA_ThemeDopeSheet;
extern StructRNA RNA_ThemeFileBrowser;

View File

@ -236,6 +236,8 @@ extern const EnumPropertyItem rna_enum_attribute_type_items[];
extern const EnumPropertyItem rna_enum_attribute_domain_items[];
extern const EnumPropertyItem *rna_enum_attribute_domain_itemf(struct ID *id, bool *r_free);
extern const EnumPropertyItem rna_enum_collection_color_items[];
/* API calls */
int rna_node_tree_type_to_enum(struct bNodeTreeType *typeinfo);
int rna_node_tree_idname_to_enum(const char *idname);

View File

@ -30,6 +30,19 @@
#include "WM_types.h"
const EnumPropertyItem rna_enum_collection_color_items[] = {
{COLLECTION_COLOR_NONE, "NONE", ICON_X, "None", "Assign no color tag to the collection"},
{COLLECTION_COLOR_01, "COLOR_01", ICON_COLLECTION_COLOR_01, "Color 01", ""},
{COLLECTION_COLOR_02, "COLOR_02", ICON_COLLECTION_COLOR_02, "Color 02", ""},
{COLLECTION_COLOR_03, "COLOR_03", ICON_COLLECTION_COLOR_03, "Color 03", ""},
{COLLECTION_COLOR_04, "COLOR_04", ICON_COLLECTION_COLOR_04, "Color 04", ""},
{COLLECTION_COLOR_05, "COLOR_05", ICON_COLLECTION_COLOR_05, "Color 05", ""},
{COLLECTION_COLOR_06, "COLOR_06", ICON_COLLECTION_COLOR_06, "Color 06", ""},
{COLLECTION_COLOR_07, "COLOR_07", ICON_COLLECTION_COLOR_07, "Color 07", ""},
{COLLECTION_COLOR_08, "COLOR_08", ICON_COLLECTION_COLOR_08, "Color 08", ""},
{0, NULL, 0, NULL, NULL},
};
#ifdef RNA_RUNTIME
# include "DNA_object_types.h"
@ -474,6 +487,12 @@ void RNA_def_collections(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Disable in Renders", "Globally disable in renders");
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_flag_update");
prop = RNA_def_property(srna, "color_tag", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "color_tag");
RNA_def_property_enum_items(prop, rna_enum_collection_color_items);
RNA_def_property_ui_text(prop, "Collection Color", "Color tag for a collection");
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL);
RNA_define_lib_overridable(false);
}

View File

@ -3623,6 +3623,23 @@ static void rna_def_userdef_theme_colorset(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
}
static void rna_def_userdef_theme_collection_color(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "ThemeCollectionColor", NULL);
RNA_def_struct_sdna(srna, "ThemeCollectionColor");
RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
RNA_def_struct_ui_text(srna, "Theme Collection Color", "Theme settings for collection colors");
prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "color");
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Color", "Collection Color Tag");
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
}
static void rna_def_userdef_theme_space_clip(BlenderRNA *brna)
{
StructRNA *srna;
@ -3939,6 +3956,12 @@ static void rna_def_userdef_themes(BlenderRNA *brna)
RNA_def_property_collection_sdna(prop, NULL, "tarm", "");
RNA_def_property_struct_type(prop, "ThemeBoneColorSet");
RNA_def_property_ui_text(prop, "Bone Color Sets", "");
prop = RNA_def_property(srna, "collection_color", PROP_COLLECTION, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_collection_sdna(prop, NULL, "collection_color", "");
RNA_def_property_struct_type(prop, "ThemeCollectionColor");
RNA_def_property_ui_text(prop, "Collection Color", "");
}
static void rna_def_userdef_addon(BlenderRNA *brna)
@ -4180,6 +4203,7 @@ static void rna_def_userdef_dothemes(BlenderRNA *brna)
rna_def_userdef_theme_space_topbar(brna);
rna_def_userdef_theme_space_statusbar(brna);
rna_def_userdef_theme_colorset(brna);
rna_def_userdef_theme_collection_color(brna);
rna_def_userdef_themes(brna);
}