static void icon_draw_size( float x, float y, int icon_id, float aspect, float alpha, const float rgb[3], enum eIconSizes size, int draw_size, const bool UNUSED(nocreate), const bool is_preview) { bTheme *btheme = UI_GetTheme(); Icon *icon = NULL; DrawInfo *di = NULL; IconImage *iimg; const float fdraw_size = (float)draw_size; int w, h; icon = BKE_icon_get(icon_id); alpha *= btheme->tui.icon_alpha; if (icon == NULL) { if (G.debug & G_DEBUG) printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id); return; } di = (DrawInfo *)icon->drawinfo; if (!di) { di = icon_create_drawinfo(); icon->drawinfo = di; icon->drawinfo_free = UI_icons_free_drawinfo; } /* scale width and height according to aspect */ w = (int)(fdraw_size / aspect + 0.5f); h = (int)(fdraw_size / aspect + 0.5f); if (di->type == ICON_TYPE_VECTOR) { /* vector icons use the uiBlock transformation, they are not drawn * with untransformed coordinates like the other icons */ di->data.vector.func((int)x, (int)y, w, h, 1.0f); } else if (di->type == ICON_TYPE_TEXTURE) { /* texture image use premul alpha for correct scaling */ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y, di->data.texture.w, di->data.texture.h, alpha, rgb); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else if (di->type == ICON_TYPE_BUFFER) { /* it is a builtin icon */ iimg = di->data.buffer.image; #ifndef WITH_HEADLESS icon_verify_datatoc(iimg); #endif if (!iimg->rect) return; /* something has gone wrong! */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else if (di->type == ICON_TYPE_PREVIEW) { PreviewImage *pi = (icon->type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) : icon->obj; if (pi) { /* no create icon on this level in code */ if (!pi->rect[size]) return; /* something has gone wrong! */ /* preview images use premul alpha ... */ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, rgb, is_preview); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } }
static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, enum eIconSizes size, int draw_size, int UNUSED(nocreate), short is_preview) { bTheme *btheme= UI_GetTheme(); Icon *icon = NULL; DrawInfo *di = NULL; IconImage *iimg; float fdraw_size= is_preview ? draw_size : (draw_size * UI_DPI_ICON_FAC); int w, h; icon = BKE_icon_get(icon_id); alpha *= btheme->tui.icon_alpha; if (icon==NULL) { if (G.f & G_DEBUG) printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id); return; } di = (DrawInfo*)icon->drawinfo; if (!di) { di = icon_create_drawinfo(); icon->drawinfo = di; icon->drawinfo_free = UI_icons_free_drawinfo; } /* scale width and height according to aspect */ w = (int)(fdraw_size/aspect + 0.5f); h = (int)(fdraw_size/aspect + 0.5f); if(di->type == ICON_TYPE_VECTOR) { /* vector icons use the uiBlock transformation, they are not drawn with untransformed coordinates like the other icons */ di->data.vector.func((int)x, (int)y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f); } else if(di->type == ICON_TYPE_TEXTURE) { icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y, di->data.texture.w, di->data.texture.h, alpha, rgb); } else if(di->type == ICON_TYPE_BUFFER) { /* it is a builtin icon */ iimg= di->data.buffer.image; if(!iimg->rect) return; /* something has gone wrong! */ icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview); } else if(di->type == ICON_TYPE_PREVIEW) { PreviewImage* pi = BKE_previewimg_get((ID*)icon->obj); if(pi) { /* no create icon on this level in code */ if(!pi->rect[size]) return; /* something has gone wrong! */ /* preview images use premul alpha ... */ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], 1.0f, NULL, is_preview); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } }