diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-10-02 20:04:38 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-10-08 20:46:00 +0300 |
commit | cf8e71db615c2d74bf87f18ab8389a675cbe6c51 (patch) | |
tree | 9f29f386985d521b4e28d644e4cd6e6d7e53015d /source/blender/editors/interface | |
parent | 2ac65f6153a2da2df7cda908689bb7c1865f088d (diff) |
UI: add icon color coding for different data types in the outliner.
For now we have categories collection, object, object data, modifiers &
constraints, and shading. The icons can be categorized by adding e.g.
DEF_ICON_OBJECT() in UI_icons.h.
Light themes will need to be updated to use darker colors to keep icons
visible in the outliner.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_icons.c | 50 | ||||
-rw-r--r-- | source/blender/editors/interface/resources.c | 36 |
2 files changed, 66 insertions, 20 deletions
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 1737cd74c8a..5c53fbb739b 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -129,6 +129,7 @@ typedef struct DrawInfo { } buffer; struct { int x, y, w, h; + int theme_color; } texture; struct { /* Can be packed into a single int. */ @@ -149,29 +150,35 @@ typedef struct IconTexture { float invh; } IconTexture; +typedef struct IconType { + int type; + int theme_color; +} IconType; + /* ******************* STATIC LOCAL VARS ******************* */ /* static here to cache results of icon directory scan, so it's not * scanning the filesystem each time the menu is drawn */ static struct ListBase iconfilelist = {NULL, NULL}; static IconTexture icongltex = {0, 0, 0, 0.0f, 0.0f}; -static const int icontypes[] = { -#define DEF_ICON(name) ICON_TYPE_MONO_TEXTURE, -#define DEF_ICON_VECTOR(name) ICON_TYPE_VECTOR, -#define DEF_ICON_COLOR(name) ICON_TYPE_COLOR_TEXTURE, -#define DEF_ICON_BLANK(name) ICON_TYPE_BLANK, +static const IconType icontypes[] = { +#define DEF_ICON(name) {ICON_TYPE_MONO_TEXTURE, 0}, +#define DEF_ICON_COLLECTION(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_COLLECTION}, +#define DEF_ICON_OBJECT(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_OBJECT}, +#define DEF_ICON_OBJECT_DATA(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_OBJECT_DATA}, +#define DEF_ICON_MODIFIER(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_MODIFIER}, +#define DEF_ICON_SHADING(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_SHADING}, +#define DEF_ICON_VECTOR(name) {ICON_TYPE_VECTOR, 0}, +#define DEF_ICON_COLOR(name) {ICON_TYPE_COLOR_TEXTURE, 0}, +#define DEF_ICON_BLANK(name) {ICON_TYPE_BLANK, 0}, #include "UI_icons.h" -#undef DEF_ICON -#undef DEF_ICON_VECTOR -#undef DEF_ICON_COLOR -#undef DEF_ICON_BLANK }; /* **************************************************** */ #ifndef WITH_HEADLESS -static DrawInfo *def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type) +static DrawInfo *def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type, int theme_color) { Icon *new_icon = NULL; IconImage *iimg = NULL; @@ -186,6 +193,7 @@ static DrawInfo *def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, di->type = type; if (ELEM(type, ICON_TYPE_COLOR_TEXTURE, ICON_TYPE_MONO_TEXTURE)) { + di->data.texture.theme_color = theme_color; di->data.texture.x = xofs; di->data.texture.y = yofs; di->data.texture.w = size; @@ -439,7 +447,7 @@ static void init_brush_icons(void) int size = datatoc_ ##name## _png_size; \ DrawInfo *di; \ \ - di = def_internal_icon(NULL, icon_id, 0, 0, w, ICON_TYPE_BUFFER); \ + di = def_internal_icon(NULL, icon_id, 0, 0, w, ICON_TYPE_BUFFER, 0); \ di->data.buffer.image->datatoc_rect = rect; \ di->data.buffer.image->datatoc_size = size; \ } @@ -580,7 +588,7 @@ static void init_event_icons(void) #define INIT_EVENT_ICON(icon_id, type, value) \ { \ - DrawInfo *di = def_internal_icon(NULL, icon_id, 0, 0, w, ICON_TYPE_EVENT); \ + DrawInfo *di = def_internal_icon(NULL, icon_id, 0, 0, w, ICON_TYPE_EVENT, 0); \ di->data.input.event_type = type; \ di->data.input.event_value = value; \ di->data.input.icon = icon_id; \ @@ -741,15 +749,15 @@ static void init_internal_icons(void) for (y = 0; y < ICON_GRID_ROWS; y++) { /* Row W has monochrome icons. */ for (x = 0; x < ICON_GRID_COLS; x++) { - int icontype = icontypes[y * ICON_GRID_COLS + x]; - if (!ELEM(icontype, ICON_TYPE_COLOR_TEXTURE, ICON_TYPE_MONO_TEXTURE)) { + IconType icontype = icontypes[y * ICON_GRID_COLS + x]; + if (!ELEM(icontype.type, ICON_TYPE_COLOR_TEXTURE, ICON_TYPE_MONO_TEXTURE)) { continue; } def_internal_icon(b32buf, BIFICONID_FIRST + y * ICON_GRID_COLS + x, x * (ICON_GRID_W + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W, - icontype); + icontype.type, icontype.theme_color); } } } @@ -1528,11 +1536,13 @@ static void icon_draw_size( else if (di->type == ICON_TYPE_MONO_TEXTURE) { /* icon that matches text color, assumed to be white */ float color[4]; - if (mono_rgba) { - rgba_uchar_to_float(color, (const uchar *)mono_rgba); - } - else { - UI_GetThemeColor4fv(TH_TEXT, color); + if (!UI_GetIconThemeColor4fv(di->data.texture.theme_color, color)) { + if (mono_rgba) { + rgba_uchar_to_float(color, (const uchar *)mono_rgba); + } + else { + UI_GetThemeColor4fv(TH_TEXT, color); + } } if (rgb) { diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index fbbaa544e2c..33a8a2ec5fa 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -686,6 +686,17 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo case TH_GIZMO_B: cp = btheme->tui.gizmo_b; break; + case TH_ICON_COLLECTION: + cp = btheme->tui.icon_collection; break; + case TH_ICON_OBJECT: + cp = btheme->tui.icon_object; break; + case TH_ICON_OBJECT_DATA: + cp = btheme->tui.icon_object_data; break; + case TH_ICON_MODIFIER: + cp = btheme->tui.icon_modifier; break; + case TH_ICON_SHADING: + cp = btheme->tui.icon_shading; break; + case TH_INFO_SELECTED: cp = ts->info_selected; break; @@ -1109,6 +1120,31 @@ void UI_GetThemeColorType4ubv(int colorid, int spacetype, char col[4]) col[3] = cp[3]; } +bool UI_GetIconThemeColor4fv(int colorid, float col[4]) +{ + if (colorid == 0) { + return false; + } + + /* Only colored icons in outliner and popups, overall UI is intended + * to stay monochrome and out of the way except a few places where it + * is important to communicate different data types. */ + if (!((theme_spacetype == SPACE_OUTLINER) || + (theme_regionid == RGN_TYPE_TEMPORARY))) + { + return false; + } + + const unsigned char *cp; + cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); + col[0] = ((float)cp[0]) / 255.0f; + col[1] = ((float)cp[1]) / 255.0f; + col[2] = ((float)cp[2]) / 255.0f; + col[3] = ((float)cp[3]) / 255.0f; + + return true; +} + void UI_GetColorPtrShade3ubv(const unsigned char cp[3], unsigned char col[3], int offset) { int r, g, b; |