Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_icons.c
| Show First 20 Lines • Show All 1,612 Lines • ▼ Show 20 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, | ||||
| const float rgb[3], | const float rgb[3], | ||||
| enum eIconSizes size, | enum eIconSizes size, | ||||
| int draw_size, | int draw_size, | ||||
| const float desaturate, | const float desaturate, | ||||
| const char mono_rgba[4]) | const char mono_rgba[4], | ||||
| bool disabled) | |||||
| { | { | ||||
| bTheme *btheme = UI_GetTheme(); | bTheme *btheme = UI_GetTheme(); | ||||
| Icon *icon = NULL; | Icon *icon = NULL; | ||||
| 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); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | icon_draw_texture(x, | ||||
| 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, | ||||
| rgb); | rgb); | ||||
| } | } | ||||
| else if (di->type == ICON_TYPE_MONO_TEXTURE) { | else if (di->type == ICON_TYPE_MONO_TEXTURE) { | ||||
| if (disabled) { | |||||
| float bottomColor[4] = {0, 0, 0, 1}; | |||||
| float topColor[4] = {1, 1, 1, 1}; | |||||
| float bottomAlpha = 0.4f; | |||||
| float topAlpha = 0.2f; | |||||
| /* offset the two version by Line Width if possible, not more than 2 */ | |||||
| int offsetSize = MIN2((U.dpi_fac < 1.5) ? 1 : U.pixelsize, 2); | |||||
| /* center both if enough pixels */ | |||||
| int nudge = offsetSize / 2; | |||||
| mul_v4_fl(bottomColor, bottomAlpha); | |||||
| icon_draw_texture(x - nudge, | |||||
| y + nudge, | |||||
| (float)w, | |||||
| (float)h, | |||||
| di->data.texture.x, | |||||
| di->data.texture.y, | |||||
| di->data.texture.w, | |||||
| di->data.texture.h, | |||||
| bottomAlpha, | |||||
| bottomColor); | |||||
| mul_v4_fl(topColor, topAlpha); | |||||
| icon_draw_texture(x + offsetSize - nudge, | |||||
| y - offsetSize + nudge, | |||||
| (float)w, | |||||
| (float)h, | |||||
| di->data.texture.x, | |||||
| di->data.texture.y, | |||||
| di->data.texture.w, | |||||
| di->data.texture.h, | |||||
| topAlpha, | |||||
| topColor); | |||||
| } | |||||
| else { | |||||
| /* icon that matches text color, assumed to be white */ | /* icon that matches text color, assumed to be white */ | ||||
| float color[4]; | float color[4]; | ||||
| if (!UI_GetIconThemeColor4fv(di->data.texture.theme_color, color)) { | if (!UI_GetIconThemeColor4fv(di->data.texture.theme_color, color)) { | ||||
| if (mono_rgba) { | if (mono_rgba) { | ||||
| rgba_uchar_to_float(color, (const uchar *)mono_rgba); | rgba_uchar_to_float(color, (const uchar *)mono_rgba); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_GetThemeColor4fv(TH_TEXT, color); | UI_GetThemeColor4fv(TH_TEXT, color); | ||||
| } | } | ||||
| } | } | ||||
| if (rgb) { | if (rgb) { | ||||
| mul_v3_v3(color, rgb); | mul_v3_v3(color, rgb); | ||||
| } | } | ||||
| mul_v4_fl(color, alpha); | /* Icon Outline */ | ||||
| float outlineColor[4] = {0, 0, 0, 1}; | |||||
| float outlineAlpha = 0.35f; | |||||
| /* is this icon a dark color? */ | |||||
| if ((color[0] * 0.2126f) + (color[1] * 0.7152f) + (color[2] * 0.0722f) < 0.5) { | |||||
| outlineColor[0] = 1; | |||||
| outlineColor[1] = 1; | |||||
| outlineColor[2] = 1; | |||||
| outlineAlpha = 0.1f; | |||||
| } | |||||
| int outlineSize = (U.dpi_fac < 1.5) ? 1 : U.pixelsize; | |||||
| /* outline alpha scales with icon alpha */ | |||||
| outlineAlpha *= alpha; | |||||
| if (outlineAlpha > 0.01) { | |||||
| mul_v4_fl(outlineColor, outlineAlpha); | |||||
| icon_draw_texture(x - outlineSize, | |||||
| y - outlineSize, | |||||
| (float)w + outlineSize + outlineSize, | |||||
| (float)h + outlineSize + outlineSize, | |||||
| di->data.texture.x, | |||||
| di->data.texture.y, | |||||
| di->data.texture.w, | |||||
| di->data.texture.h, | |||||
| outlineAlpha, | |||||
| outlineColor); | |||||
| } | |||||
| mul_v4_fl(color, alpha); | |||||
| icon_draw_texture(x, | icon_draw_texture(x, | ||||
| y, | y, | ||||
| (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, | ||||
| color[3], | color[3], | ||||
| color); | color); | ||||
| } | } | ||||
| } | |||||
| else if (di->type == ICON_TYPE_BUFFER) { | else if (di->type == ICON_TYPE_BUFFER) { | ||||
| /* it is a builtin icon */ | /* it is a builtin icon */ | ||||
| iimg = di->data.buffer.image; | iimg = di->data.buffer.image; | ||||
| #ifndef WITH_HEADLESS | #ifndef WITH_HEADLESS | ||||
| icon_verify_datatoc(iimg); | icon_verify_datatoc(iimg); | ||||
| #endif | #endif | ||||
| if (!iimg->rect) { | if (!iimg->rect) { | ||||
| ▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | static void icon_draw_at_size(float x, | ||||
| int icon_id, | int icon_id, | ||||
| float aspect, | float aspect, | ||||
| float alpha, | float alpha, | ||||
| enum eIconSizes size, | enum eIconSizes size, | ||||
| const float desaturate, | const float desaturate, | ||||
| const char mono_color[4]) | const char mono_color[4]) | ||||
| { | { | ||||
| int draw_size = get_draw_size(size); | int draw_size = get_draw_size(size); | ||||
| icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, desaturate, mono_color); | icon_draw_size( | ||||
| x, y, icon_id, aspect, alpha, NULL, size, draw_size, desaturate, mono_color, false); | |||||
| } | } | ||||
| void UI_icon_draw_aspect( | void UI_icon_draw_aspect( | ||||
| float x, float y, int icon_id, float aspect, float alpha, const char mono_color[4]) | float x, float y, int icon_id, float aspect, float alpha, const char mono_color[4]) | ||||
| { | { | ||||
| icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0.0f, mono_color); | icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0.0f, mono_color); | ||||
| } | } | ||||
| void UI_icon_draw_aspect_color( | void UI_icon_draw_aspect_color( | ||||
| float x, float y, int icon_id, float aspect, const float rgb[3], const char mono_color[4]) | float x, float y, int icon_id, float aspect, const float rgb[3], const char mono_color[4]) | ||||
| { | { | ||||
| int draw_size = get_draw_size(ICON_SIZE_ICON); | int draw_size = get_draw_size(ICON_SIZE_ICON); | ||||
| icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false, mono_color); | icon_draw_size( | ||||
| x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false, mono_color, false); | |||||
| } | } | ||||
| void UI_icon_draw_desaturate(float x, | void UI_icon_draw_desaturate(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 char mono_color[4]) | const char mono_color[4]) | ||||
| { | { | ||||
| icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, desaturate, mono_color); | icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, desaturate, mono_color); | ||||
| } | } | ||||
| void UI_icon_draw_disabled(float x, float y, int icon_id, float aspect) | |||||
| { | |||||
| icon_draw_size( | |||||
| x, y, icon_id, aspect, 1.0f, NULL, ICON_SIZE_ICON, ICON_DEFAULT_HEIGHT, 0, NULL, true); | |||||
| } | |||||
| /* draws icon with dpi scale factor */ | /* draws icon with dpi scale factor */ | ||||
| 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_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, NULL); | UI_icon_draw_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, NULL); | ||||
| } | } | ||||
| 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_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, NULL); | UI_icon_draw_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, NULL); | ||||
| } | } | ||||
| void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha) | void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha) | ||||
| { | { | ||||
| icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, false, NULL); | icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, false, NULL, false); | ||||
| } | } | ||||
| void UI_icon_draw_preview(float x, float y, int icon_id) | void UI_icon_draw_preview(float x, float y, int icon_id) | ||||
| { | { | ||||
| icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, false, NULL); | icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, false, NULL); | ||||
| } | } | ||||
| void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect) | void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect) | ||||
| { | { | ||||
| icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, false, NULL); | icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, false, NULL); | ||||
| } | } | ||||
| void UI_icon_draw_preview_aspect_size( | void UI_icon_draw_preview_aspect_size( | ||||
| float x, float y, int icon_id, float aspect, float alpha, int size) | float x, float y, int icon_id, float aspect, float alpha, int size) | ||||
| { | { | ||||
| icon_draw_size(x, y, icon_id, aspect, alpha, NULL, ICON_SIZE_PREVIEW, size, false, NULL); | icon_draw_size(x, y, icon_id, aspect, alpha, NULL, ICON_SIZE_PREVIEW, size, false, NULL, false); | ||||
| } | } | ||||