コード例 #1
0
int UI_icon_get_height(int icon_id)
{
	Icon *icon = NULL;
	DrawInfo *di = NULL;

	icon = BKE_icon_get(icon_id);
	
	if (icon == NULL) {
		if (G.debug & G_DEBUG)
			printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
		return 0;
	}
	
	di = (DrawInfo *)icon->drawinfo;

	if (!di) {
		di = icon_create_drawinfo();
		icon->drawinfo = di;
	}
	
	if (di)
		return ICON_DEFAULT_HEIGHT;

	return 0;
}
コード例 #2
0
ファイル: interface_icons.c プロジェクト: diekev/blender
void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool big)
{
	Icon *icon = BKE_icon_get(icon_id);

	if (icon) {
		DrawInfo *di = (DrawInfo *)icon->drawinfo;

		if (!di) {
			di = icon_create_drawinfo();

			icon->drawinfo = di;
			icon->drawinfo_free = UI_icons_free_drawinfo;
		}

		if (di) {
			switch (di->type) {
				case ICON_TYPE_PREVIEW:
				{
					ID *id = (icon->type != 0) ? icon->obj : NULL;
					PreviewImage *prv = id ? BKE_previewimg_id_ensure(id) : icon->obj;

					if (prv) {
						const int size = big ? ICON_SIZE_PREVIEW : ICON_SIZE_ICON;

						if (id || (prv->tag & PRV_TAG_DEFFERED) != 0) {
							ui_id_preview_image_render_size(C, NULL, id, prv, size, true);
						}
					}
					break;
				}
			}
		}
	}
}
コード例 #3
0
void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool big)
{
	Icon *icon = BKE_icon_get(icon_id);

	if (icon) {
		DrawInfo *di = (DrawInfo *)icon->drawinfo;

		if (!di) {
			di = icon_create_drawinfo();

			icon->drawinfo = di;
			icon->drawinfo_free = UI_icons_free_drawinfo;
		}

		if (di) {
			if (di->type == ICON_TYPE_PREVIEW) {
				PreviewImage *prv = (icon->type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) : icon->obj;

				if (prv) {
					const int size = big ? ICON_SIZE_PREVIEW : ICON_SIZE_ICON;

					if (!prv->use_deferred || prv->rect[size] || (prv->flag[size] & PRV_USER_EDITED)) {
						return;
					}

					icon_create_rect(prv, size);

					/* Always using job (background) version. */
					ED_preview_icon_job(C, prv, NULL, prv->rect[size], prv->w[size], prv->h[size]);

					prv->flag[size] &= ~PRV_CHANGED;
				}
			}
		}
	}
}
コード例 #4
0
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);
		}
	}
}
コード例 #5
0
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);
		}
	}
}