diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -151,6 +151,7 @@ typedef struct IconTexture { typedef struct IconType { int type; int theme_color; + char *name; } IconType; /* ******************* STATIC LOCAL VARS ******************* */ @@ -161,19 +162,19 @@ static IconTexture icongltex = {{NULL, NULL}, 0, 0, 0, 0.0f, 0.0f}; #ifndef WITH_HEADLESS -static const IconType icontypes[] = { -# define DEF_ICON(name) {ICON_TYPE_MONO_TEXTURE, 0}, -# define DEF_ICON_SCENE(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_SCENE}, -# 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_FOLDER(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_FOLDER}, -# define DEF_ICON_FUND(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_FUND}, -# 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}, +static IconType icontypes[] = { +# define DEF_ICON(name) {ICON_TYPE_MONO_TEXTURE, 0, #name}, +# define DEF_ICON_SCENE(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_SCENE, #name}, +# define DEF_ICON_COLLECTION(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_COLLECTION, #name}, +# define DEF_ICON_OBJECT(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_OBJECT, #name}, +# define DEF_ICON_OBJECT_DATA(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_OBJECT_DATA, #name}, +# define DEF_ICON_MODIFIER(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_MODIFIER, #name}, +# define DEF_ICON_SHADING(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_SHADING, #name}, +# define DEF_ICON_FOLDER(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_FOLDER, #name}, +# define DEF_ICON_FUND(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_FUND, #name}, +# define DEF_ICON_VECTOR(name) {ICON_TYPE_VECTOR, 0, #name}, +# define DEF_ICON_COLOR(name) {ICON_TYPE_COLOR_TEXTURE, 0, #name}, +# define DEF_ICON_BLANK(name) {ICON_TYPE_BLANK, 0, #name}, # include "UI_icons.h" }; @@ -830,6 +831,52 @@ static void free_icons_textures(void) } } +static void UI_icons_load_external_file(ImBuf *bbuf, const int resolution_divider) +{ + char dir_name[FILE_MAXFILE]; + BLI_snprintf(dir_name, sizeof(dir_name), "blender_icons%u", 32 / resolution_divider); + const char *icon_directory = BKE_appdir_folder_id(BLENDER_DATAFILES, dir_name); + + if (!BLI_exists(icon_directory)) { + return; + } + + for (int y = 0; y < ICON_GRID_ROWS; y++) { + for (int x = 0; x < ICON_GRID_COLS; x++) { + IconType *icontype = &icontypes[y * ICON_GRID_COLS + x]; + + // is_color + if (0) { + icontype->type = ICON_TYPE_COLOR_TEXTURE; + } + + char icon_file[FILE_MAXFILE]; + BLI_snprintf(icon_file, sizeof(icon_file), "icon%u_%s.png", 32 / resolution_divider, icontype->name); + char icon_filepath[FILE_MAX]; + BLI_join_dirfile(icon_filepath, sizeof(icon_filepath), icon_directory, icon_file); + + ImBuf *ibuf = IMB_loadiffname(icon_filepath, IB_rect, NULL); + + if (ibuf) { + const int size_w = ICON_GRID_W / resolution_divider; + const int size_h = ICON_GRID_H / resolution_divider; + const int margin = ICON_GRID_MARGIN / resolution_divider; + + if (ibuf->x == size_w && ibuf->y == size_h) { + for (int k = 0; k < size_h; k++) { + memcpy(&bbuf->rect[(k + y * (size_h + margin) + margin) * bbuf->x + + x * (size_w + margin) + margin], + &ibuf->rect[k * ibuf->x], + ibuf->x * sizeof(int)); + } + } + + IMB_freeImBuf(ibuf); + } + } + } +} + /* Reload the textures for internal icons. * This function will release the previous textures. */ void UI_icons_reload_internal_textures(void) @@ -846,6 +893,9 @@ void UI_icons_reload_internal_textures(void) NULL, ""); } + + UI_icons_load_external_file(b16buf, 2); + if (b16buf) { if (need_icons_with_border) { b16buf_border = create_mono_icon_with_border(b16buf, 2, icon_border_intensity); @@ -861,6 +911,9 @@ void UI_icons_reload_internal_textures(void) NULL, ""); } + + UI_icons_load_external_file(b32buf, 1); + if (b32buf) { if (need_icons_with_border) { b32buf_border = create_mono_icon_with_border(b32buf, 1, icon_border_intensity);