Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_icons.c
| Show All 19 Lines | |||||
| /** \file | /** \file | ||||
| * \ingroup edinterface | * \ingroup edinterface | ||||
| */ | */ | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "GPU_state.h" | #include "GPU_state.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| # define ICON_GRID_ROWS 30 | # define ICON_GRID_ROWS 30 | ||||
| # define ICON_MONO_BORDER_OUTSET 2 | # define ICON_MONO_BORDER_OUTSET 2 | ||||
| # define ICON_GRID_MARGIN 10 | # define ICON_GRID_MARGIN 10 | ||||
| # define ICON_GRID_W 32 | # define ICON_GRID_W 32 | ||||
| # define ICON_GRID_H 32 | # define ICON_GRID_H 32 | ||||
| #endif /* WITH_HEADLESS */ | #endif /* WITH_HEADLESS */ | ||||
| static CLG_LogRef LOG = {"interface.icons"}; | |||||
| typedef struct IconImage { | typedef struct IconImage { | ||||
| int w; | int w; | ||||
| int h; | int h; | ||||
| uint *rect; | uint *rect; | ||||
| const uchar *datatoc_rect; | const uchar *datatoc_rect; | ||||
| int datatoc_size; | int datatoc_size; | ||||
| } IconImage; | } IconImage; | ||||
| ▲ Show 20 Lines • Show All 817 Lines • ▼ Show 20 Lines | if ((btheme != NULL) && btheme->tui.iconfile[0]) { | ||||
| if (icondir) { | if (icondir) { | ||||
| BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile); | BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile); | ||||
| /* if the image is missing bbuf will just be NULL */ | /* if the image is missing bbuf will just be NULL */ | ||||
| bbuf = IMB_loadiffname(iconfilestr, IB_rect, NULL); | bbuf = IMB_loadiffname(iconfilestr, IB_rect, NULL); | ||||
| if (bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) { | if (bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) { | ||||
| printf( | CLOG_WARN(&LOG, | ||||
| "\n***WARNING***\n" | "\n***WARNING***\n" | ||||
| "Icons file '%s' too small.\n" | "Icons file '%s' too small.\n" | ||||
| "Using built-in Icons instead\n", | "Using built-in Icons instead", | ||||
| iconfilestr); | iconfilestr); | ||||
| IMB_freeImBuf(bbuf); | IMB_freeImBuf(bbuf); | ||||
| bbuf = NULL; | bbuf = NULL; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: 'icons' data path not found, continuing\n", __func__); | CLOG_STR_WARN("'icons' data path not found, continuing"); | ||||
| } | } | ||||
| } | } | ||||
| # endif | # endif | ||||
| /* Define icons. */ | /* Define icons. */ | ||||
| for (y = 0; y < ICON_GRID_ROWS; y++) { | for (y = 0; y < ICON_GRID_ROWS; y++) { | ||||
| /* Row W has monochrome icons. */ | /* Row W has monochrome icons. */ | ||||
| for (x = 0; x < ICON_GRID_COLS; x++) { | for (x = 0; x < ICON_GRID_COLS; x++) { | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | # if 0 | ||||
| IMB_freeImBuf(bbuf); | IMB_freeImBuf(bbuf); | ||||
| } | } | ||||
| else { | else { | ||||
| ifilex = ifiley = 0; | ifilex = ifiley = 0; | ||||
| } | } | ||||
| /* bad size or failed to load */ | /* bad size or failed to load */ | ||||
| if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) { | if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) { | ||||
| printf("icon '%s' is wrong size %dx%d\n", iconfilestr, ifilex, ifiley); | CLOG_WARN(&LOG, "icon '%s' is wrong size %dx%d", iconfilestr, ifilex, ifiley); | ||||
| continue; | continue; | ||||
| } | } | ||||
| # endif /* removed */ | # endif /* removed */ | ||||
| /* found a potential icon file, so make an entry for it in the cache list */ | /* found a potential icon file, so make an entry for it in the cache list */ | ||||
| ifile = MEM_callocN(sizeof(IconFile), "IconFile"); | ifile = MEM_callocN(sizeof(IconFile), "IconFile"); | ||||
| BLI_strncpy(ifile->filename, filename, sizeof(ifile->filename)); | BLI_strncpy(ifile->filename, filename, sizeof(ifile->filename)); | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | |||||
| int UI_icon_get_width(int icon_id) | int UI_icon_get_width(int icon_id) | ||||
| { | { | ||||
| Icon *icon = NULL; | Icon *icon = NULL; | ||||
| DrawInfo *di = NULL; | DrawInfo *di = NULL; | ||||
| icon = BKE_icon_get(icon_id); | icon = BKE_icon_get(icon_id); | ||||
| if (icon == NULL) { | if (icon == NULL) { | ||||
| if (G.debug & G_DEBUG) { | CLOG_ERROR(&LOG, "Internal error, no icon for icon ID: %d", icon_id); | ||||
| printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id); | |||||
| } | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| di = icon_ensure_drawinfo(icon); | di = icon_ensure_drawinfo(icon); | ||||
| if (di) { | if (di) { | ||||
| return ICON_DEFAULT_WIDTH; | return ICON_DEFAULT_WIDTH; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| int UI_icon_get_height(int icon_id) | int UI_icon_get_height(int icon_id) | ||||
| { | { | ||||
| Icon *icon = BKE_icon_get(icon_id); | Icon *icon = BKE_icon_get(icon_id); | ||||
| if (icon == NULL) { | if (icon == NULL) { | ||||
| if (G.debug & G_DEBUG) { | CLOG_ERROR(&LOG, "Internal error, no icon for icon ID: %d", icon_id); | ||||
| printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id); | |||||
| } | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| DrawInfo *di = icon_ensure_drawinfo(icon); | DrawInfo *di = icon_ensure_drawinfo(icon); | ||||
| if (di) { | if (di) { | ||||
| return ICON_DEFAULT_HEIGHT; | return ICON_DEFAULT_HEIGHT; | ||||
| } | } | ||||
| Show All 38 Lines | |||||
| /* Create rect for the icon | /* Create rect for the icon | ||||
| */ | */ | ||||
| static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size) | static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size) | ||||
| { | { | ||||
| uint render_size = UI_preview_render_size(size); | uint render_size = UI_preview_render_size(size); | ||||
| if (!prv_img) { | if (!prv_img) { | ||||
| if (G.debug & G_DEBUG) { | CLOG_STR_ERROR(&LOG, "Requested preview image does not exist"); | ||||
| printf("%s, error: requested preview image does not exist", __func__); | |||||
| } | |||||
| } | } | ||||
| else if (!prv_img->rect[size]) { | else if (!prv_img->rect[size]) { | ||||
| prv_img->w[size] = render_size; | prv_img->w[size] = render_size; | ||||
| prv_img->h[size] = render_size; | prv_img->h[size] = render_size; | ||||
| prv_img->flag[size] |= PRV_CHANGED; | prv_img->flag[size] |= PRV_CHANGED; | ||||
| prv_img->changed_timestamp[size] = 0; | prv_img->changed_timestamp[size] = 0; | ||||
| prv_img->rect[size] = MEM_callocN(render_size * render_size * sizeof(uint), "prv_rect"); | prv_img->rect[size] = MEM_callocN(render_size * render_size * sizeof(uint), "prv_rect"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | |||||
| static void icon_set_image(const bContext *C, | static void icon_set_image(const bContext *C, | ||||
| Scene *scene, | Scene *scene, | ||||
| ID *id, | ID *id, | ||||
| PreviewImage *prv_img, | PreviewImage *prv_img, | ||||
| enum eIconSizes size, | enum eIconSizes size, | ||||
| const bool use_job) | const bool use_job) | ||||
| { | { | ||||
| if (!prv_img) { | if (!prv_img) { | ||||
| if (G.debug & G_DEBUG) { | CLOG_ERROR(&LOG, "No preview image for this ID: %s", id->name); | ||||
| printf("%s: no preview image for this ID: %s\n", __func__, id->name); | |||||
| } | |||||
| return; | return; | ||||
| } | } | ||||
| if (prv_img->flag[size] & PRV_USER_EDITED) { | if (prv_img->flag[size] & PRV_USER_EDITED) { | ||||
| /* user-edited preview, do not auto-update! */ | /* user-edited preview, do not auto-update! */ | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | static void icon_draw_rect(float x, | ||||
| ImBuf *ima = NULL; | ImBuf *ima = NULL; | ||||
| int draw_w = w; | int draw_w = w; | ||||
| int draw_h = h; | int draw_h = h; | ||||
| int draw_x = x; | int draw_x = x; | ||||
| int draw_y = y; | int draw_y = y; | ||||
| /* sanity check */ | /* sanity check */ | ||||
| if (w <= 0 || h <= 0 || w > 2000 || h > 2000) { | if (w <= 0 || h <= 0 || w > 2000 || h > 2000) { | ||||
| printf("%s: icons are %i x %i pixels?\n", __func__, w, h); | CLOG_FATAL(&LOG, "icons are %i x %i pixels?", w, h); | ||||
| BLI_assert(!"invalid icon size"); | BLI_assert(!"invalid icon size"); | ||||
| return; | return; | ||||
| } | } | ||||
| /* modulate color */ | /* modulate color */ | ||||
| float col[4] = {alpha, alpha, alpha, alpha}; | float col[4] = {alpha, alpha, alpha, alpha}; | ||||
| /* rect contains image in 'rendersize', we only scale if needed */ | /* rect contains image in 'rendersize', we only scale if needed */ | ||||
| if (rw != w || rh != h) { | if (rw != w || rh != h) { | ||||
| ▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | static void icon_draw_size(float x, | ||||
| IconImage *iimg; | IconImage *iimg; | ||||
| const float fdraw_size = (float)draw_size; | const float fdraw_size = (float)draw_size; | ||||
| int w, h; | int w, h; | ||||
| icon = BKE_icon_get(icon_id); | icon = BKE_icon_get(icon_id); | ||||
| alpha *= btheme->tui.icon_alpha; | alpha *= btheme->tui.icon_alpha; | ||||
| if (icon == NULL) { | if (icon == NULL) { | ||||
| if (G.debug & G_DEBUG) { | CLOG_ERROR(&LOG, "Internal error, no icon for icon ID: %d", icon_id); | ||||
| printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id); | |||||
| } | |||||
| return; | return; | ||||
| } | } | ||||
| /* scale width and height according to aspect */ | /* scale width and height according to aspect */ | ||||
| w = (int)(fdraw_size / aspect + 0.5f); | w = (int)(fdraw_size / aspect + 0.5f); | ||||
| h = (int)(fdraw_size / aspect + 0.5f); | h = (int)(fdraw_size / aspect + 0.5f); | ||||
| DrawInfo *di = icon_ensure_drawinfo(icon); | DrawInfo *di = icon_ensure_drawinfo(icon); | ||||
| ▲ Show 20 Lines • Show All 595 Lines • Show Last 20 Lines | |||||