UI: Use SVG Icons for Alert Icons on Dialogs

Use new SVG icons in place of current "Alert" icons, used on dialogs
and confirmations. No need for alert_icons.svg, alert_icons.png,
alert_icons_update.py. Also looks better as they are made at exact
requested size instead of 256x256 then scaled down to display.

Pull Request: https://projects.blender.org/blender/blender/pulls/123786
This commit is contained in:
Harley Acheson
2024-06-26 20:54:20 +02:00
committed by Harley Acheson
parent fe4c7c4178
commit 5c377686e7
3 changed files with 32 additions and 16 deletions

View File

@@ -54,7 +54,7 @@ enum eAlertIcon {
ALERT_ICON_MAX,
};
ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon);
ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon, float size);
/**
* Resizable Icons for Blender

View File

@@ -4785,10 +4785,10 @@ uiBut *uiDefButImage(
uiBut *uiDefButAlert(uiBlock *block, int icon, int x, int y, short width, short height)
{
ImBuf *ibuf = UI_icon_alert_imbuf_get((eAlertIcon)icon);
ImBuf *ibuf = UI_icon_alert_imbuf_get((eAlertIcon)icon, float(width));
if (ibuf) {
bTheme *btheme = UI_GetTheme();
return uiDefButImage(block, ibuf, x, y, width, height, btheme->tui.wcol_menu_back.text);
return uiDefButImage(block, ibuf, x, y, ibuf->x, ibuf->y, btheme->tui.wcol_menu_back.text);
}
return nullptr;
}

View File

@@ -2612,25 +2612,41 @@ void UI_icon_text_overlay_init_from_count(IconTextOverlay *text_overlay,
/* ********** Alert Icons ********** */
ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon)
ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon, float size)
{
#ifdef WITH_HEADLESS
UNUSED_VARS(icon);
UNUSED_VARS(icon, size);
return nullptr;
#else
if (icon == ALERT_ICON_NONE) {
int icon_id = ICON_NONE;
switch (icon) {
case ALERT_ICON_WARNING:
icon_id = ICON_WARNING_LARGE;
break;
case ALERT_ICON_QUESTION:
icon_id = ICON_QUESTION_LARGE;
break;
case ALERT_ICON_ERROR:
icon_id = ICON_CANCEL_LARGE;
break;
case ALERT_ICON_INFO:
icon_id = ICON_INFO_LARGE;
break;
}
if (icon_id == ICON_NONE) {
return nullptr;
}
const int ALERT_IMG_SIZE = 256;
icon = eAlertIcon(std::min<int>(icon, ALERT_ICON_MAX - 1));
const int left = icon * ALERT_IMG_SIZE;
const rcti crop = {left, left + ALERT_IMG_SIZE - 1, 0, ALERT_IMG_SIZE - 1};
ImBuf *ibuf = IMB_ibImageFromMemory((const uchar *)datatoc_alert_icons_png,
datatoc_alert_icons_png_size,
IB_rect,
nullptr,
"alert_icon");
IMB_rect_crop(ibuf, &crop);
int width;
int height;
blender::Array<uchar> bitmap = BLF_svg_icon_bitmap(icon_id, size, &width, &height);
if (bitmap.is_empty()) {
return nullptr;
}
ImBuf *ibuf = IMB_allocFromBuffer(bitmap.data(), nullptr, width, height, 4);
IMB_flipy(ibuf);
IMB_premultiply_alpha(ibuf);
return ibuf;
#endif