Cleanup: reduce number of UI_icon_draw variations

This commit is contained in:
2019-05-09 19:19:52 +02:00
parent 5f7eebda23
commit 6148ed8cf9
7 changed files with 48 additions and 96 deletions

View File

@@ -53,6 +53,7 @@ typedef struct IconFile {
*/
void UI_icons_init(void);
void UI_icons_reload_internal_textures(void);
int UI_icon_get_width(int icon_id);
int UI_icon_get_height(int icon_id);
@@ -65,16 +66,16 @@ int UI_preview_render_size(enum eIconSizes size);
void UI_icon_draw(float x, float y, int icon_id);
void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha);
void UI_icon_draw_preview(float x, float y, int icon_id);
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect);
void UI_icon_draw_preview_aspect_size(
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);
void UI_icon_draw_ex(float x,
float y,
int icon_id,
float aspect,
float alpha,
float desaturate,
const char mono_color[4]);
void UI_icon_draw_aspect(
float x, float y, int icon_id, float aspect, float alpha, const char mono_color[4]);
void UI_icon_draw_aspect_color(
float x, float y, int icon_id, float aspect, const float rgb[3], const char mono_color[4]);
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha);
void UI_icon_draw_desaturate(float x,
float y,
int icon_id,
@@ -82,6 +83,7 @@ void UI_icon_draw_desaturate(float x,
float alpha,
float desaturate,
const char mono_color[4]);
void UI_icons_free(void);
void UI_icons_free_drawinfo(void *drawinfo);

View File

@@ -1467,7 +1467,6 @@ static void icon_draw_rect(float x,
int rh,
uint *rect,
float alpha,
const float rgb[3],
const float desaturate)
{
ImBuf *ima = NULL;
@@ -1485,12 +1484,6 @@ static void icon_draw_rect(float x,
/* modulate color */
float col[4] = {1.0f, 1.0f, 1.0f, alpha};
if (rgb) {
col[0] = rgb[0];
col[1] = rgb[1];
col[2] = rgb[2];
}
/* rect contains image in 'rendersize', we only scale if needed */
if (rw != w || rh != h) {
/* preserve aspect ratio and center */
@@ -1766,7 +1759,6 @@ static void icon_draw_size(float x,
int icon_id,
float aspect,
float alpha,
const float rgb[3],
enum eIconSizes size,
int draw_size,
const float desaturate,
@@ -1827,7 +1819,7 @@ static void icon_draw_size(float x,
GPU_blend_set_func_separate(
GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, rgb, desaturate);
icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, desaturate);
GPU_blend_set_func_separate(
GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
}
@@ -1847,7 +1839,7 @@ static void icon_draw_size(float x,
di->data.texture.w,
di->data.texture.h,
alpha,
rgb,
NULL,
false);
}
else if (di->type == ICON_TYPE_MONO_TEXTURE) {
@@ -1866,10 +1858,6 @@ static void icon_draw_size(float x,
with_border = (btheme->tui.icon_border_intensity > 0.0f);
}
if (rgb) {
mul_v3_v3(color, rgb);
}
mul_v4_fl(color, alpha);
float border_outset = 0.0;
@@ -1903,7 +1891,7 @@ static void icon_draw_size(float x,
return;
}
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, desaturate);
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, desaturate);
}
else if (di->type == ICON_TYPE_PREVIEW) {
PreviewImage *pi = (icon->id_type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) :
@@ -1920,7 +1908,7 @@ static void icon_draw_size(float x,
GPU_blend_set_func_separate(
GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
icon_draw_rect(
x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, rgb, desaturate);
x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, desaturate);
GPU_blend_set_func_separate(
GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
}
@@ -2242,71 +2230,30 @@ int UI_idcode_icon_get(const int idcode)
}
}
static void icon_draw_at_size(float x,
float y,
int icon_id,
float aspect,
float alpha,
enum eIconSizes size,
const float desaturate,
const char mono_color[4])
{
int draw_size = get_draw_size(size);
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, desaturate, mono_color);
}
void UI_icon_draw_aspect(
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);
}
void UI_icon_draw_aspect_color(
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);
icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false, mono_color);
}
void UI_icon_draw_desaturate(float x,
float y,
int icon_id,
float aspect,
float alpha,
float desaturate,
const char mono_color[4])
{
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, desaturate, mono_color);
}
/* draws icon with dpi scale factor */
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_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, 0.0f, NULL);
}
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_ex(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, 0.0f, NULL);
}
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)
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, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, false, NULL);
icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, false, NULL);
}
void UI_icon_draw_preview(float x, float y, int icon_id)
void UI_icon_draw_ex(float x,
float y,
int icon_id,
float aspect,
float alpha,
float desaturate,
const char mono_color[4])
{
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)
{
icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, false, NULL);
}
void UI_icon_draw_preview_aspect_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);
int draw_size = get_draw_size(ICON_SIZE_ICON);
icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, draw_size, desaturate, mono_color);
}

View File

@@ -765,12 +765,13 @@ void ui_draw_aligned_panel(uiStyle *style,
panel_title_color_get(show_background, col_title);
GPU_blend(true);
UI_icon_draw_aspect(headrect.xmax - ((PNL_ICON * 2.2f) / block->aspect),
headrect.ymin + (5.0f / block->aspect),
(panel->flag & PNL_PIN) ? ICON_PINNED : ICON_UNPINNED,
(block->aspect / UI_DPI_FAC),
1.0f,
(const char *)col_title);
UI_icon_draw_ex(headrect.xmax - ((PNL_ICON * 2.2f) / block->aspect),
headrect.ymin + (5.0f / block->aspect),
(panel->flag & PNL_PIN) ? ICON_PINNED : ICON_UNPINNED,
(block->aspect / UI_DPI_FAC),
1.0f,
0.0f,
(const char *)col_title);
GPU_blend(false);
}

View File

@@ -1421,7 +1421,7 @@ static void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect)
int x = rect->xmin + w / 2 - size / 2;
int y = rect->ymin + h / 2 - size / 2;
UI_icon_draw_preview_aspect_size(x, y, icon, 1.0f, alpha, size);
UI_icon_draw_preview(x, y, icon, 1.0f, alpha, size);
}
}
@@ -1508,16 +1508,18 @@ static void widget_draw_icon(
/* to indicate draggable */
if (but->dragpoin && (but->flag & UI_ACTIVE)) {
float rgb[3] = {1.25f, 1.25f, 1.25f};
UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb, mono_color);
UI_icon_draw_ex(xs, ys, icon, aspect, 1.25f, 0.0f, mono_color);
}
else if ((but->flag & (UI_ACTIVE | UI_SELECT | UI_SELECT_DRAW)) || !UI_but_is_tool(but)) {
UI_icon_draw_aspect(xs, ys, icon, aspect, alpha, mono_color);
else if ((but->flag & (UI_ACTIVE | UI_SELECT | UI_SELECT_DRAW))) {
UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, mono_color);
}
else if (!UI_but_is_tool(but)) {
UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, mono_color);
}
else {
const bTheme *btheme = UI_GetTheme();
UI_icon_draw_desaturate(
xs, ys, icon, aspect, alpha, 1.0 - btheme->tui.icon_saturation, mono_color);
const float desaturate = 1.0 - btheme->tui.icon_saturation;
UI_icon_draw_ex(xs, ys, icon, aspect, alpha, desaturate, mono_color);
}
}
@@ -5201,7 +5203,7 @@ void ui_draw_menu_item(
GPU_blend(true);
/* XXX scale weak get from fstyle? */
UI_icon_draw_aspect(xs, ys, iconid, aspect, 1.0f, wt->wcol.text);
UI_icon_draw_ex(xs, ys, iconid, aspect, 1.0f, 0.0f, wt->wcol.text);
GPU_blend(false);
}
}

View File

@@ -203,7 +203,7 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
alpha = min_ff(alpha, 0.75f);
UI_icon_draw_aspect(x, y, ICON_FULLSCREEN_EXIT, 0.7f / UI_DPI_FAC, alpha, NULL);
UI_icon_draw_ex(x, y, ICON_FULLSCREEN_EXIT, 0.7f / UI_DPI_FAC, 0.0f, alpha, NULL);
/* debug drawing :
* The click_rect is the same as defined in fullscreen_click_rcti_init

View File

@@ -478,7 +478,7 @@ static void file_draw_preview(uiBlock *block,
GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
if (icon) {
UI_icon_draw_aspect((float)xco, (float)yco, icon, icon_aspect, 1.0f, NULL);
UI_icon_draw_ex((float)xco, (float)yco, icon, icon_aspect, 1.0f, 0.0f, NULL);
}
/* border */

View File

@@ -442,7 +442,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
drag_rect_minmax(rect, x, y, x + iconsize, y + iconsize);
}
else {
UI_icon_draw_aspect(x, y, drag->icon, 1.0f / UI_DPI_FAC, 0.8, text_col);
UI_icon_draw_ex(x, y, drag->icon, 1.0f / UI_DPI_FAC, 0.8, 0.0f, text_col);
}
}