Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_icons.c
| Show First 20 Lines • Show All 409 Lines • ▼ Show 20 Lines | |||||
| static void vicon_collection_color_draw( | static void vicon_collection_color_draw( | ||||
| short color_tag, int x, int y, int w, int UNUSED(h), float UNUSED(alpha)) | short color_tag, int x, int y, int w, int UNUSED(h), float UNUSED(alpha)) | ||||
| { | { | ||||
| bTheme *btheme = UI_GetTheme(); | bTheme *btheme = UI_GetTheme(); | ||||
| const ThemeCollectionColor *collection_color = &btheme->collection_color[color_tag]; | const ThemeCollectionColor *collection_color = &btheme->collection_color[color_tag]; | ||||
| const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | ||||
| UI_icon_draw_ex( | UI_icon_draw_ex(x, | ||||
| x, y, ICON_OUTLINER_COLLECTION, aspect, 1.0f, 0.0f, collection_color->color, true); | y, | ||||
| ICON_OUTLINER_COLLECTION, | |||||
| aspect, | |||||
| 1.0f, | |||||
| 0.0f, | |||||
| collection_color->color, | |||||
| true, | |||||
| UI_NO_ICON_OVERLAY_TEXT); | |||||
JacquesLucke: Using `1` to disable the indicator seems wrong. Better define e.g. `UI_NO_ICON_INDICATOR` as -1… | |||||
| } | } | ||||
| # define DEF_ICON_COLLECTION_COLOR_DRAW(index, color) \ | # 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) \ | 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); \ | vicon_collection_color_draw(color, x, y, w, h, alpha); \ | ||||
| } | } | ||||
| Show All 11 Lines | |||||
| static void vicon_strip_color_draw( | static void vicon_strip_color_draw( | ||||
| short color_tag, int x, int y, int w, int UNUSED(h), float UNUSED(alpha)) | short color_tag, int x, int y, int w, int UNUSED(h), float UNUSED(alpha)) | ||||
| { | { | ||||
| bTheme *btheme = UI_GetTheme(); | bTheme *btheme = UI_GetTheme(); | ||||
| const ThemeStripColor *strip_color = &btheme->strip_color[color_tag]; | const ThemeStripColor *strip_color = &btheme->strip_color[color_tag]; | ||||
| const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | ||||
| UI_icon_draw_ex(x, y, ICON_SNAP_FACE, aspect, 1.0f, 0.0f, strip_color->color, true); | UI_icon_draw_ex( | ||||
| x, y, ICON_SNAP_FACE, aspect, 1.0f, 0.0f, strip_color->color, true, UI_NO_ICON_OVERLAY_TEXT); | |||||
| } | } | ||||
| # define DEF_ICON_STRIP_COLOR_DRAW(index, color) \ | # define DEF_ICON_STRIP_COLOR_DRAW(index, color) \ | ||||
| static void vicon_strip_color_draw_##index(int x, int y, int w, int h, float alpha) \ | static void vicon_strip_color_draw_##index(int x, int y, int w, int h, float alpha) \ | ||||
| { \ | { \ | ||||
| vicon_strip_color_draw(color, x, y, w, h, alpha); \ | vicon_strip_color_draw(color, x, y, w, h, alpha); \ | ||||
| } | } | ||||
| Show All 11 Lines | |||||
| # define ICON_INDIRECT_DATA_ALPHA 0.6f | # define ICON_INDIRECT_DATA_ALPHA 0.6f | ||||
| static void vicon_strip_color_draw_library_data_indirect( | static void vicon_strip_color_draw_library_data_indirect( | ||||
| int x, int y, int w, int UNUSED(h), float alpha) | int x, int y, int w, int UNUSED(h), float alpha) | ||||
| { | { | ||||
| const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | ||||
| UI_icon_draw_ex( | UI_icon_draw_ex(x, | ||||
| x, y, ICON_LIBRARY_DATA_DIRECT, aspect, ICON_INDIRECT_DATA_ALPHA * alpha, 0.0f, NULL, false); | y, | ||||
| ICON_LIBRARY_DATA_DIRECT, | |||||
| aspect, | |||||
| ICON_INDIRECT_DATA_ALPHA * alpha, | |||||
| 0.0f, | |||||
| NULL, | |||||
| false, | |||||
| UI_NO_ICON_OVERLAY_TEXT); | |||||
| } | } | ||||
| static void vicon_strip_color_draw_library_data_override_noneditable( | static void vicon_strip_color_draw_library_data_override_noneditable( | ||||
| int x, int y, int w, int UNUSED(h), float alpha) | int x, int y, int w, int UNUSED(h), float alpha) | ||||
| { | { | ||||
| const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; | ||||
| UI_icon_draw_ex(x, | UI_icon_draw_ex(x, | ||||
| y, | y, | ||||
| ICON_LIBRARY_DATA_OVERRIDE, | ICON_LIBRARY_DATA_OVERRIDE, | ||||
| aspect, | aspect, | ||||
| ICON_INDIRECT_DATA_ALPHA * alpha * 0.75f, | ICON_INDIRECT_DATA_ALPHA * alpha * 0.75f, | ||||
| 0.0f, | 0.0f, | ||||
| NULL, | NULL, | ||||
| false); | false, | ||||
| UI_NO_ICON_OVERLAY_TEXT); | |||||
| } | } | ||||
| /* Dynamically render icon instead of rendering a plain color to a texture/buffer | /* 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, | * 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. | * but it works in a very similar way. | ||||
| */ | */ | ||||
| static void vicon_gplayer_color_draw(Icon *icon, int x, int y, int w, int h) | static void vicon_gplayer_color_draw(Icon *icon, int x, int y, int w, int h) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 1,211 Lines • ▼ Show 20 Lines | static void icon_draw_texture(float x, | ||||
| float w, | float w, | ||||
| float h, | float h, | ||||
| int ix, | int ix, | ||||
| int iy, | int iy, | ||||
| int iw, | int iw, | ||||
| int ih, | int ih, | ||||
| float alpha, | float alpha, | ||||
| const float rgb[3], | const float rgb[3], | ||||
| bool with_border) | bool with_border, | ||||
| const IconTextOverlay *text_overlay) | |||||
| { | { | ||||
| if (g_icon_draw_cache.enabled) { | const float zoom_factor = w / UI_DPI_ICON_SIZE; | ||||
| float text_width = 0.0f; | |||||
| /* No need to show if too zoomed out, otherwise it just adds noise. */ | |||||
| const bool show_indicator = (text_overlay && text_overlay->text[0] != '\0') && | |||||
| (zoom_factor > 0.7f); | |||||
Not Done Inline ActionsI think either the naming indicator_number is wrong or the > 1 should be moved out of here. To me, indicator_number does not imply that it's useless when it is e.g. 0 or 1. Not sure which approach would be better here. Longer term it may become useful to pass the "indicator string" into this function (limited to e.g. 3 characters). For now it's prooobably fine as is. JacquesLucke: I think either the naming `indicator_number` is wrong or the `> 1` should be moved out of here. | |||||
| if (show_indicator) { | |||||
| /* Handle the little numbers on top of the icon. */ | |||||
| uchar text_color[4]; | |||||
| UI_GetThemeColor3ubv(TH_TEXT, text_color); | |||||
| text_color[3] = 255; | |||||
| uiFontStyle fstyle_small = *UI_FSTYLE_WIDGET; | |||||
| fstyle_small.points *= zoom_factor; | |||||
| fstyle_small.points *= 0.8f; | |||||
| rcti text_rect = { | |||||
| .xmax = x + UI_UNIT_X * zoom_factor, | |||||
| .xmin = x, | |||||
| .ymax = y, | |||||
| .ymin = y, | |||||
| }; | |||||
| UI_fontstyle_draw(&fstyle_small, | |||||
| &text_rect, | |||||
| text_overlay->text, | |||||
| sizeof(text_overlay->text), | |||||
| text_color, | |||||
| &(struct uiFontStyleDraw_Params){ | |||||
| .align = UI_STYLE_TEXT_RIGHT, | |||||
| }); | |||||
| text_width = (float)UI_fontstyle_string_width(&fstyle_small, text_overlay->text) / UI_UNIT_X / | |||||
| zoom_factor; | |||||
| } | |||||
| /* Draw the actual icon. */ | |||||
| if (!show_indicator && g_icon_draw_cache.enabled) { | |||||
| icon_draw_texture_cached(x, y, w, h, ix, iy, iw, ih, alpha, rgb, with_border); | icon_draw_texture_cached(x, y, w, h, ix, iy, iw, ih, alpha, rgb, with_border); | ||||
| return; | return; | ||||
| } | } | ||||
| /* We need to flush widget base first to ensure correct ordering. */ | /* We need to flush widget base first to ensure correct ordering. */ | ||||
| UI_widgetbase_draw_cache_flush(); | UI_widgetbase_draw_cache_flush(); | ||||
Not Done Inline ActionsPersonally, I think I prefer +99 instead of just 999 when the number is too large. 999 looks like it's an exact number which is most likely wrong. We could potentially still show the actual number on hover, but that's can be done separately. JacquesLucke: Personally, I think I prefer `+99` instead of just `999` when the number is too large. `999`… | |||||
| GPU_blend(GPU_BLEND_ALPHA_PREMULT); | GPU_blend(GPU_BLEND_ALPHA_PREMULT); | ||||
| const float x1 = ix * icongltex.invw; | const float x1 = ix * icongltex.invw; | ||||
| const float x2 = (ix + ih) * icongltex.invw; | const float x2 = (ix + ih) * icongltex.invw; | ||||
| const float y1 = iy * icongltex.invh; | const float y1 = iy * icongltex.invh; | ||||
| const float y2 = (iy + ih) * icongltex.invh; | const float y2 = (iy + ih) * icongltex.invh; | ||||
| GPUTexture *texture = with_border ? icongltex.tex[1] : icongltex.tex[0]; | GPUTexture *texture = with_border ? icongltex.tex[1] : icongltex.tex[0]; | ||||
| GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR); | GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_ICON); | ||||
| GPU_shader_bind(shader); | GPU_shader_bind(shader); | ||||
| const int img_binding = GPU_shader_get_texture_binding(shader, "image"); | const int img_binding = GPU_shader_get_texture_binding(shader, "image"); | ||||
| const int color_loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR); | const int color_loc = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR); | ||||
| const int rect_tex_loc = GPU_shader_get_uniform(shader, "rect_icon"); | const int rect_tex_loc = GPU_shader_get_uniform(shader, "rect_icon"); | ||||
| const int rect_geom_loc = GPU_shader_get_uniform(shader, "rect_geom"); | const int rect_geom_loc = GPU_shader_get_uniform(shader, "rect_geom"); | ||||
| if (rgb) { | if (rgb) { | ||||
| GPU_shader_uniform_vector(shader, color_loc, 4, 1, (float[4]){UNPACK3(rgb), alpha}); | GPU_shader_uniform_vector(shader, color_loc, 4, 1, (float[4]){UNPACK3(rgb), alpha}); | ||||
| } | } | ||||
| else { | else { | ||||
| GPU_shader_uniform_vector(shader, color_loc, 4, 1, (float[4]){alpha, alpha, alpha, alpha}); | GPU_shader_uniform_vector(shader, color_loc, 4, 1, (float[4]){alpha, alpha, alpha, alpha}); | ||||
| } | } | ||||
| GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, (float[4]){x1, y1, x2, y2}); | GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, (float[4]){x1, y1, x2, y2}); | ||||
| GPU_shader_uniform_vector(shader, rect_geom_loc, 4, 1, (float[4]){x, y, x + w, y + h}); | GPU_shader_uniform_vector(shader, rect_geom_loc, 4, 1, (float[4]){x, y, x + w, y + h}); | ||||
| GPU_shader_uniform_1f(shader, "text_width", text_width); | |||||
| GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false); | GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false); | ||||
| GPUBatch *quad = GPU_batch_preset_quad(); | GPUBatch *quad = GPU_batch_preset_quad(); | ||||
| GPU_batch_set_shader(quad, shader); | GPU_batch_set_shader(quad, shader); | ||||
| GPU_batch_draw(quad); | GPU_batch_draw(quad); | ||||
| GPU_texture_unbind(texture); | GPU_texture_unbind(texture); | ||||
| Show All 18 Lines | static void icon_draw_size(float x, | ||||
| float y, | float y, | ||||
| int icon_id, | int icon_id, | ||||
| float aspect, | float aspect, | ||||
| float alpha, | float alpha, | ||||
| enum eIconSizes size, | enum eIconSizes size, | ||||
| int draw_size, | int draw_size, | ||||
| const float desaturate, | const float desaturate, | ||||
| const uchar mono_rgba[4], | const uchar mono_rgba[4], | ||||
| const bool mono_border) | const bool mono_border, | ||||
| const IconTextOverlay *text_overlay) | |||||
| { | { | ||||
| bTheme *btheme = UI_GetTheme(); | bTheme *btheme = UI_GetTheme(); | ||||
| const float fdraw_size = (float)draw_size; | const float fdraw_size = (float)draw_size; | ||||
| Icon *icon = BKE_icon_get(icon_id); | Icon *icon = BKE_icon_get(icon_id); | ||||
| alpha *= btheme->tui.icon_alpha; | alpha *= btheme->tui.icon_alpha; | ||||
| if (icon == NULL) { | if (icon == NULL) { | ||||
| ▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | icon_draw_texture(x, | ||||
| (float)w, | (float)w, | ||||
| (float)h, | (float)h, | ||||
| di->data.texture.x, | di->data.texture.x, | ||||
| di->data.texture.y, | di->data.texture.y, | ||||
| di->data.texture.w, | di->data.texture.w, | ||||
| di->data.texture.h, | di->data.texture.h, | ||||
| alpha, | alpha, | ||||
| NULL, | NULL, | ||||
| false); | false, | ||||
| text_overlay); | |||||
| } | } | ||||
| else if (di->type == ICON_TYPE_MONO_TEXTURE) { | else if (di->type == ICON_TYPE_MONO_TEXTURE) { | ||||
| /* Monochrome icon that uses text or theme color. */ | /* Monochrome icon that uses text or theme color. */ | ||||
| const bool with_border = mono_border && (btheme->tui.icon_border_intensity > 0.0f); | const bool with_border = mono_border && (btheme->tui.icon_border_intensity > 0.0f); | ||||
| float color[4]; | float color[4]; | ||||
| if (mono_rgba) { | if (mono_rgba) { | ||||
| rgba_uchar_to_float(color, (const uchar *)mono_rgba); | rgba_uchar_to_float(color, (const uchar *)mono_rgba); | ||||
| } | } | ||||
| Show All 17 Lines | icon_draw_texture(x - border_outset, | ||||
| (float)w + 2 * border_outset, | (float)w + 2 * border_outset, | ||||
| (float)h + 2 * border_outset, | (float)h + 2 * border_outset, | ||||
| di->data.texture.x - border_texel, | di->data.texture.x - border_texel, | ||||
| di->data.texture.y - border_texel, | di->data.texture.y - border_texel, | ||||
| di->data.texture.w + 2 * border_texel, | di->data.texture.w + 2 * border_texel, | ||||
| di->data.texture.h + 2 * border_texel, | di->data.texture.h + 2 * border_texel, | ||||
| color[3], | color[3], | ||||
| color, | color, | ||||
| with_border); | with_border, | ||||
| text_overlay); | |||||
| } | } | ||||
| else if (di->type == ICON_TYPE_BUFFER) { | else if (di->type == ICON_TYPE_BUFFER) { | ||||
| /* it is a builtin icon */ | /* it is a builtin icon */ | ||||
| IconImage *iimg = di->data.buffer.image; | IconImage *iimg = di->data.buffer.image; | ||||
| #ifndef WITH_HEADLESS | #ifndef WITH_HEADLESS | ||||
| icon_verify_datatoc(iimg); | icon_verify_datatoc(iimg); | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 500 Lines • ▼ Show 20 Lines | if (collection->color_tag != COLLECTION_COLOR_NONE) { | ||||
| icon = ICON_COLLECTION_COLOR_01 + collection->color_tag; | icon = ICON_COLLECTION_COLOR_01 + collection->color_tag; | ||||
| } | } | ||||
| return icon; | return icon; | ||||
| } | } | ||||
| void UI_icon_draw(float x, float y, int icon_id) | void UI_icon_draw(float x, float y, int icon_id) | ||||
| { | { | ||||
| UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, 1.0f, 0.0f, NULL, false); | UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, 1.0f, 0.0f, NULL, false, UI_NO_ICON_OVERLAY_TEXT); | ||||
| } | } | ||||
| void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha) | void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha) | ||||
| { | { | ||||
| UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false); | UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false, UI_NO_ICON_OVERLAY_TEXT); | ||||
| } | } | ||||
| void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size) | void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size) | ||||
| { | { | ||||
| icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, false, NULL, false); | icon_draw_size(x, | ||||
| y, | |||||
| icon_id, | |||||
| aspect, | |||||
| alpha, | |||||
| ICON_SIZE_PREVIEW, | |||||
| size, | |||||
| false, | |||||
| NULL, | |||||
| false, | |||||
| UI_NO_ICON_OVERLAY_TEXT); | |||||
| } | } | ||||
| void UI_icon_draw_ex(float x, | void UI_icon_draw_ex(float x, | ||||
| float y, | float y, | ||||
| int icon_id, | int icon_id, | ||||
| float aspect, | float aspect, | ||||
| float alpha, | float alpha, | ||||
| float desaturate, | float desaturate, | ||||
| const uchar mono_color[4], | const uchar mono_color[4], | ||||
| const bool mono_border) | const bool mono_border, | ||||
| const IconTextOverlay *text_overlay) | |||||
| { | { | ||||
| const int draw_size = get_draw_size(ICON_SIZE_ICON); | const int draw_size = get_draw_size(ICON_SIZE_ICON); | ||||
| icon_draw_size(x, | icon_draw_size(x, | ||||
| y, | y, | ||||
| icon_id, | icon_id, | ||||
| aspect, | aspect, | ||||
| alpha, | alpha, | ||||
| ICON_SIZE_ICON, | ICON_SIZE_ICON, | ||||
| draw_size, | draw_size, | ||||
| desaturate, | desaturate, | ||||
| mono_color, | mono_color, | ||||
| mono_border); | mono_border, | ||||
| text_overlay); | |||||
| } | |||||
| void UI_icon_text_overlay_init_from_count(IconTextOverlay *text_overlay, | |||||
Done Inline ActionsUI_icon_text_overlay_init_from_count JacquesLucke: `UI_icon_text_overlay_init_from_count` | |||||
| const int icon_indicator_number) | |||||
| { | |||||
| /* The icon indicator is used as an aggregator, no need to show if it is 1. */ | |||||
| if (icon_indicator_number < 2) { | |||||
| text_overlay->text[0] = '\0'; | |||||
| return; | |||||
| } | |||||
| BLI_str_format_integer_unit(text_overlay->text, icon_indicator_number); | |||||
| } | } | ||||
| /* ********** Alert Icons ********** */ | /* ********** Alert Icons ********** */ | ||||
| ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon) | ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon) | ||||
| { | { | ||||
| #ifdef WITH_HEADLESS | #ifdef WITH_HEADLESS | ||||
| UNUSED_VARS(icon); | UNUSED_VARS(icon); | ||||
| Show All 16 Lines | |||||
Using 1 to disable the indicator seems wrong. Better define e.g. UI_NO_ICON_INDICATOR as -1 somewhere and use that.