2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * Contributors: Blender Foundation, full recode
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file blender/editors/interface/interface_icons.c
27 * \ingroup edinterface
34 #include "MEM_guardedalloc.h"
37 #include "GPU_matrix.h"
38 #include "GPU_batch.h"
39 #include "GPU_immediate.h"
40 #include "GPU_state.h"
42 #include "BLI_blenlib.h"
43 #include "BLI_utildefines.h"
44 #include "BLI_fileops_types.h"
45 #include "BLI_math_vector.h"
47 #include "DNA_brush_types.h"
48 #include "DNA_curve_types.h"
49 #include "DNA_dynamicpaint_types.h"
50 #include "DNA_gpencil_types.h"
51 #include "DNA_object_types.h"
52 #include "DNA_screen_types.h"
53 #include "DNA_space_types.h"
54 #include "DNA_workspace_types.h"
56 #include "RNA_access.h"
57 #include "RNA_enum_types.h"
59 #include "BKE_context.h"
60 #include "BKE_global.h"
61 #include "BKE_paint.h"
62 #include "BKE_icons.h"
63 #include "BKE_appdir.h"
64 #include "BKE_studiolight.h"
66 #include "IMB_imbuf.h"
67 #include "IMB_imbuf_types.h"
68 #include "IMB_thumbs.h"
70 #include "BIF_glutil.h"
72 #include "DEG_depsgraph.h"
74 #include "DRW_engine.h"
76 #include "ED_datafiles.h"
77 #include "ED_keyframes_draw.h"
78 #include "ED_render.h"
80 #include "UI_interface.h"
81 #include "UI_interface_icons.h"
86 #include "interface_intern.h"
89 #define ICON_GRID_COLS 26
90 #define ICON_GRID_ROWS 30
92 #define ICON_GRID_MARGIN 10
93 #define ICON_GRID_W 32
94 #define ICON_GRID_H 32
95 #endif /* WITH_HEADLESS */
97 typedef struct IconImage {
105 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
107 #define ICON_TYPE_PREVIEW 0
108 #define ICON_TYPE_COLOR_TEXTURE 1
109 #define ICON_TYPE_MONO_TEXTURE 2
110 #define ICON_TYPE_BUFFER 3
111 #define ICON_TYPE_VECTOR 4
112 #define ICON_TYPE_GEOM 5
113 #define ICON_TYPE_EVENT 6 /* draw keymap entries using custom renderer. */
114 #define ICON_TYPE_GPLAYER 7
115 #define ICON_TYPE_BLANK 8
117 typedef struct DrawInfo {
121 /* type specific data */
136 /* Can be packed into a single int. */
141 struct DrawInfo *next;
146 typedef struct IconTexture {
154 typedef struct IconType {
159 /* ******************* STATIC LOCAL VARS ******************* */
160 /* static here to cache results of icon directory scan, so it's not
161 * scanning the filesystem each time the menu is drawn */
162 static struct ListBase iconfilelist = {NULL, NULL};
163 static IconTexture icongltex = {0, 0, 0, 0.0f, 0.0f};
165 #ifndef WITH_HEADLESS
167 static const IconType icontypes[] = {
168 #define DEF_ICON(name) {ICON_TYPE_MONO_TEXTURE, 0},
169 #define DEF_ICON_COLLECTION(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_COLLECTION},
170 #define DEF_ICON_OBJECT(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_OBJECT},
171 #define DEF_ICON_OBJECT_DATA(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_OBJECT_DATA},
172 #define DEF_ICON_MODIFIER(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_MODIFIER},
173 #define DEF_ICON_SHADING(name) {ICON_TYPE_MONO_TEXTURE, TH_ICON_SHADING},
174 #define DEF_ICON_VECTOR(name) {ICON_TYPE_VECTOR, 0},
175 #define DEF_ICON_COLOR(name) {ICON_TYPE_COLOR_TEXTURE, 0},
176 #define DEF_ICON_BLANK(name) {ICON_TYPE_BLANK, 0},
177 #include "UI_icons.h"
180 /* **************************************************** */
182 static DrawInfo *def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type, int theme_color)
184 Icon *new_icon = NULL;
185 IconImage *iimg = NULL;
188 new_icon = MEM_callocN(sizeof(Icon), "texicon");
190 new_icon->obj = NULL; /* icon is not for library object */
191 new_icon->id_type = 0;
193 di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
196 if (ELEM(type, ICON_TYPE_COLOR_TEXTURE, ICON_TYPE_MONO_TEXTURE)) {
197 di->data.texture.theme_color = theme_color;
198 di->data.texture.x = xofs;
199 di->data.texture.y = yofs;
200 di->data.texture.w = size;
201 di->data.texture.h = size;
203 else if (type == ICON_TYPE_BUFFER) {
204 iimg = MEM_callocN(sizeof(IconImage), "icon_img");
208 /* icon buffers can get initialized runtime now, via datatoc */
212 iimg->rect = MEM_mallocN(size * size * sizeof(uint), "icon_rect");
214 /* Here we store the rect in the icon - same as before */
215 if (size == bbuf->x && size == bbuf->y && xofs == 0 && yofs == 0)
216 memcpy(iimg->rect, bbuf->rect, size * size * sizeof(int));
218 /* this code assumes square images */
220 for (y = 0; y < size; y++) {
221 memcpy(&iimg->rect[y * size], &bbuf->rect[(y + yofs) * imgsize + xofs], size * sizeof(int));
225 di->data.buffer.image = iimg;
228 new_icon->drawinfo_free = UI_icons_free_drawinfo;
229 new_icon->drawinfo = di;
231 BKE_icon_set(icon_id, new_icon);
236 static void def_internal_vicon(int icon_id, VectorDrawFunc drawFunc)
238 Icon *new_icon = NULL;
241 new_icon = MEM_callocN(sizeof(Icon), "texicon");
243 new_icon->obj = NULL; /* icon is not for library object */
244 new_icon->id_type = 0;
246 di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
247 di->type = ICON_TYPE_VECTOR;
248 di->data.vector.func = drawFunc;
250 new_icon->drawinfo_free = NULL;
251 new_icon->drawinfo = di;
253 BKE_icon_set(icon_id, new_icon);
256 /* Vector Icon Drawing Routines */
260 static void viconutil_set_point(GLint pt[2], int x, int y)
266 static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float alpha)
269 int cx = x + w / 2 - 4;
271 int d = w / 5, d2 = w / 7;
273 viconutil_set_point(pts[0], cx - d2, cy + d);
274 viconutil_set_point(pts[1], cx - d2, cy - d);
275 viconutil_set_point(pts[2], cx + d2, cy);
277 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
278 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
279 immUniformColor4f(0.2f, 0.2f, 0.2f, alpha);
281 immBegin(GPU_PRIM_TRIS, 3);
282 immVertex2iv(pos, pts[0]);
283 immVertex2iv(pos, pts[1]);
284 immVertex2iv(pos, pts[2]);
290 static void vicon_keytype_draw_wrapper(int x, int y, int w, int h, float alpha, short key_type, short handle_type)
292 /* init dummy theme state for Action Editor - where these colors are defined
293 * (since we're doing this offscreen, free from any particular space_id)
295 struct bThemeState theme_state;
297 UI_Theme_Store(&theme_state);
298 UI_SetTheme(SPACE_ACTION, RGN_TYPE_WINDOW);
300 /* the "x" and "y" given are the bottom-left coordinates of the icon,
301 * while the draw_keyframe_shape() function needs the midpoint for
304 float xco = x + w / 2 + 0.5f;
305 float yco = y + h / 2 + 0.5f;
307 GPUVertFormat *format = immVertexFormat();
308 uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
309 uint size_id = GPU_vertformat_attr_add(format, "size", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
310 uint color_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
311 uint outline_color_id = GPU_vertformat_attr_add(format, "outlineColor", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
312 uint flags_id = GPU_vertformat_attr_add(format, "flags", GPU_COMP_U32, 1, GPU_FETCH_INT);
314 immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
315 GPU_enable_program_point_size();
316 immUniform2f("ViewportSize", -1.0f, -1.0f);
317 immBegin(GPU_PRIM_POINTS, 1);
320 * - size: (default icon size == 16, default dopesheet icon size == 10)
321 * - sel: true unless in handletype icons (so that "keyframe" state shows the iconic yellow icon)
323 bool sel = (handle_type == KEYFRAME_HANDLE_NONE);
325 draw_keyframe_shape(xco, yco, (10.0f / 16.0f) * h, sel, key_type, KEYFRAME_SHAPE_BOTH, alpha,
326 pos_id, size_id, color_id, outline_color_id,
327 flags_id, handle_type, KEYFRAME_EXTREME_NONE);
330 GPU_disable_program_point_size();
333 UI_Theme_Restore(&theme_state);
336 static void vicon_keytype_keyframe_draw(int x, int y, int w, int h, float alpha)
338 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_KEYFRAME, KEYFRAME_HANDLE_NONE);
341 static void vicon_keytype_breakdown_draw(int x, int y, int w, int h, float alpha)
343 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_BREAKDOWN, KEYFRAME_HANDLE_NONE);
346 static void vicon_keytype_extreme_draw(int x, int y, int w, int h, float alpha)
348 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_EXTREME, KEYFRAME_HANDLE_NONE);
351 static void vicon_keytype_jitter_draw(int x, int y, int w, int h, float alpha)
353 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_JITTER, KEYFRAME_HANDLE_NONE);
356 static void vicon_keytype_moving_hold_draw(int x, int y, int w, int h, float alpha)
358 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_MOVEHOLD, KEYFRAME_HANDLE_NONE);
361 static void vicon_handletype_free_draw(int x, int y, int w, int h, float alpha)
363 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_KEYFRAME, KEYFRAME_HANDLE_FREE);
366 static void vicon_handletype_aligned_draw(int x, int y, int w, int h, float alpha)
368 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_KEYFRAME, KEYFRAME_HANDLE_ALIGNED);
371 static void vicon_handletype_vector_draw(int x, int y, int w, int h, float alpha)
373 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_KEYFRAME, KEYFRAME_HANDLE_VECTOR);
376 static void vicon_handletype_auto_draw(int x, int y, int w, int h, float alpha)
378 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_KEYFRAME, KEYFRAME_HANDLE_AUTO);
381 static void vicon_handletype_auto_clamp_draw(int x, int y, int w, int h, float alpha)
383 vicon_keytype_draw_wrapper(x, y, w, h, alpha, BEZT_KEYTYPE_KEYFRAME, KEYFRAME_HANDLE_AUTO_CLAMP);
386 static void vicon_colorset_draw(int index, int x, int y, int w, int h, float UNUSED(alpha))
388 bTheme *btheme = UI_GetTheme();
389 ThemeWireColor *cs = &btheme->tarm[index];
391 /* Draw three bands of color: One per color
392 * x-----a-----b-----c
394 * x-----a-----b-----c
396 const int a = x + w / 3;
397 const int b = x + w / 3 * 2;
400 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
401 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
403 /* XXX: Include alpha into this... */
405 immUniformColor3ubv((uchar *)cs->solid);
406 immRecti(pos, x, y, a, y + h);
409 immUniformColor3ubv((uchar *)cs->select);
410 immRecti(pos, a, y, b, y + h);
413 immUniformColor3ubv((uchar *)cs->active);
414 immRecti(pos, b, y, c, y + h);
419 #define DEF_ICON_VECTOR_COLORSET_DRAW_NTH(prefix, index) \
420 static void vicon_colorset_draw_##prefix(int x, int y, int w, int h, float alpha) \
422 vicon_colorset_draw(index, x, y, w, h, alpha); \
425 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(01, 0)
426 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(02, 1)
427 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(03, 2)
428 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(04, 3)
429 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(05, 4)
430 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(06, 5)
431 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(07, 6)
432 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(08, 7)
433 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(09, 8)
434 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(10, 9)
435 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(11, 10)
436 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(12, 11)
437 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(13, 12)
438 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(14, 13)
439 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(15, 14)
440 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(16, 15)
441 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(17, 16)
442 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(18, 17)
443 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(19, 18)
444 DEF_ICON_VECTOR_COLORSET_DRAW_NTH(20, 19)
446 #undef DEF_ICON_VECTOR_COLORSET_DRAW_NTH
448 /* Dynamically render icon instead of rendering a plain color to a texture/buffer
449 * This is mot strictly a "vicon", as it needs access to icon->obj to get the color info,
450 * but it works in a very similar way.
452 static void vicon_gplayer_color_draw(Icon *icon, int x, int y, int w, int h)
454 bGPDlayer *gpl = (bGPDlayer *)icon->obj;
456 /* Just draw a colored rect - Like for vicon_colorset_draw() */
457 /* TODO: Make this have rounded corners, and maybe be a bit smaller.
458 * However, UI_draw_roundbox_aa() draws the colors too dark, so can't be used.
460 uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
461 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
463 immUniformColor3fv(gpl->color);
464 immRecti(pos, x, y, x + w - 1, y + h - 1);
470 #ifndef WITH_HEADLESS
472 static void init_brush_icons(void)
475 #define INIT_BRUSH_ICON(icon_id, name) \
477 uchar *rect = (uchar *)datatoc_ ##name## _png; \
478 int size = datatoc_ ##name## _png_size; \
481 di = def_internal_icon(NULL, icon_id, 0, 0, w, ICON_TYPE_BUFFER, 0); \
482 di->data.buffer.image->datatoc_rect = rect; \
483 di->data.buffer.image->datatoc_size = size; \
485 /* end INIT_BRUSH_ICON */
487 const int w = 96; /* warning, brush size hardcoded in C, but it gets scaled */
489 INIT_BRUSH_ICON(ICON_BRUSH_BLOB, blob);
490 INIT_BRUSH_ICON(ICON_BRUSH_BLUR, blur);
491 INIT_BRUSH_ICON(ICON_BRUSH_CLAY, clay);
492 INIT_BRUSH_ICON(ICON_BRUSH_CLAY_STRIPS, claystrips);
493 INIT_BRUSH_ICON(ICON_BRUSH_CLONE, clone);
494 INIT_BRUSH_ICON(ICON_BRUSH_CREASE, crease);
495 INIT_BRUSH_ICON(ICON_BRUSH_SCULPT_DRAW, draw);
496 INIT_BRUSH_ICON(ICON_BRUSH_FILL, fill);
497 INIT_BRUSH_ICON(ICON_BRUSH_FLATTEN, flatten);
498 INIT_BRUSH_ICON(ICON_BRUSH_GRAB, grab);
499 INIT_BRUSH_ICON(ICON_BRUSH_INFLATE, inflate);
500 INIT_BRUSH_ICON(ICON_BRUSH_LAYER, layer);
501 INIT_BRUSH_ICON(ICON_BRUSH_MASK, mask);
502 INIT_BRUSH_ICON(ICON_BRUSH_MIX, mix);
503 INIT_BRUSH_ICON(ICON_BRUSH_NUDGE, nudge);
504 INIT_BRUSH_ICON(ICON_BRUSH_PINCH, pinch);
505 INIT_BRUSH_ICON(ICON_BRUSH_SCRAPE, scrape);
506 INIT_BRUSH_ICON(ICON_BRUSH_SMEAR, smear);
507 INIT_BRUSH_ICON(ICON_BRUSH_SMOOTH, smooth);
508 INIT_BRUSH_ICON(ICON_BRUSH_SNAKE_HOOK, snake_hook);
509 INIT_BRUSH_ICON(ICON_BRUSH_SOFTEN, soften);
510 INIT_BRUSH_ICON(ICON_BRUSH_TEXDRAW, texdraw);
511 INIT_BRUSH_ICON(ICON_BRUSH_TEXFILL, texfill);
512 INIT_BRUSH_ICON(ICON_BRUSH_TEXMASK, texmask);
513 INIT_BRUSH_ICON(ICON_BRUSH_THUMB, thumb);
514 INIT_BRUSH_ICON(ICON_BRUSH_ROTATE, twist);
516 /* grease pencil sculpt */
517 INIT_BRUSH_ICON(ICON_GPBRUSH_SMOOTH, gp_brush_smooth);
518 INIT_BRUSH_ICON(ICON_GPBRUSH_THICKNESS, gp_brush_thickness);
519 INIT_BRUSH_ICON(ICON_GPBRUSH_STRENGTH, gp_brush_strength);
520 INIT_BRUSH_ICON(ICON_GPBRUSH_GRAB, gp_brush_grab);
521 INIT_BRUSH_ICON(ICON_GPBRUSH_PUSH, gp_brush_push);
522 INIT_BRUSH_ICON(ICON_GPBRUSH_TWIST, gp_brush_twist);
523 INIT_BRUSH_ICON(ICON_GPBRUSH_PINCH, gp_brush_pinch);
524 INIT_BRUSH_ICON(ICON_GPBRUSH_RANDOMIZE, gp_brush_randomize);
525 INIT_BRUSH_ICON(ICON_GPBRUSH_CLONE, gp_brush_clone);
526 INIT_BRUSH_ICON(ICON_GPBRUSH_WEIGHT, gp_brush_weight);
528 /* grease pencil drawing brushes */
529 INIT_BRUSH_ICON(ICON_GPBRUSH_PENCIL, gp_brush_pencil);
530 INIT_BRUSH_ICON(ICON_GPBRUSH_PEN, gp_brush_pen);
531 INIT_BRUSH_ICON(ICON_GPBRUSH_INK, gp_brush_ink);
532 INIT_BRUSH_ICON(ICON_GPBRUSH_INKNOISE, gp_brush_inknoise);
533 INIT_BRUSH_ICON(ICON_GPBRUSH_BLOCK, gp_brush_block);
534 INIT_BRUSH_ICON(ICON_GPBRUSH_MARKER, gp_brush_marker);
535 INIT_BRUSH_ICON(ICON_GPBRUSH_FILL, gp_brush_fill);
536 INIT_BRUSH_ICON(ICON_GPBRUSH_ERASE_SOFT, gp_brush_erase_soft);
537 INIT_BRUSH_ICON(ICON_GPBRUSH_ERASE_HARD, gp_brush_erase_hard);
538 INIT_BRUSH_ICON(ICON_GPBRUSH_ERASE_STROKE, gp_brush_erase_stroke);
540 #undef INIT_BRUSH_ICON
543 static DrawInfo *g_di_event_list = NULL;
545 int UI_icon_from_event_type(short event_type, short event_value)
547 if (event_type == RIGHTSHIFTKEY) {
548 event_type = LEFTSHIFTKEY;
550 else if (event_type == RIGHTCTRLKEY) {
551 event_type = LEFTCTRLKEY;
553 else if (event_type == RIGHTALTKEY) {
554 event_type = LEFTALTKEY;
556 else if (event_type == EVT_TWEAK_L) {
557 event_type = LEFTMOUSE;
558 event_value = KM_CLICK_DRAG;
560 else if (event_type == EVT_TWEAK_M) {
561 event_type = MIDDLEMOUSE;
562 event_value = KM_CLICK_DRAG;
564 else if (event_type == EVT_TWEAK_R) {
565 event_type = RIGHTMOUSE;
566 event_value = KM_CLICK_DRAG;
569 DrawInfo *di = g_di_event_list;
571 if (di->data.input.event_type == event_type) {
572 return di->data.input.icon;
574 } while ((di = di->data.input.next));
576 if (event_type == LEFTMOUSE) {
577 return ELEM(event_value, KM_CLICK, KM_PRESS) ? ICON_MOUSE_LMB : ICON_MOUSE_LMB_DRAG;
579 else if (event_type == MIDDLEMOUSE) {
580 return ELEM(event_value, KM_CLICK, KM_PRESS) ? ICON_MOUSE_MMB : ICON_MOUSE_MMB_DRAG;
582 else if (event_type == RIGHTMOUSE) {
583 return ELEM(event_value, KM_CLICK, KM_PRESS) ? ICON_MOUSE_RMB : ICON_MOUSE_RMB_DRAG;
589 int UI_icon_from_keymap_item(const wmKeyMapItem *kmi, int r_icon_mod[4])
592 memset(r_icon_mod, 0x0, sizeof(int[4]));
594 if (!ELEM(kmi->ctrl, KM_NOTHING, KM_ANY)) {
595 r_icon_mod[i++] = ICON_EVENT_CTRL;
597 if (!ELEM(kmi->alt, KM_NOTHING, KM_ANY)) {
598 r_icon_mod[i++] = ICON_EVENT_ALT;
600 if (!ELEM(kmi->shift, KM_NOTHING, KM_ANY)) {
601 r_icon_mod[i++] = ICON_EVENT_SHIFT;
603 if (!ELEM(kmi->oskey, KM_NOTHING, KM_ANY)) {
604 r_icon_mod[i++] = ICON_EVENT_OS;
607 return UI_icon_from_event_type(kmi->type, kmi->val);
610 static void init_event_icons(void)
612 DrawInfo *di_next = NULL;
614 #define INIT_EVENT_ICON(icon_id, type, value) \
616 DrawInfo *di = def_internal_icon(NULL, icon_id, 0, 0, w, ICON_TYPE_EVENT, 0); \
617 di->data.input.event_type = type; \
618 di->data.input.event_value = value; \
619 di->data.input.icon = icon_id; \
620 di->data.input.next = di_next; \
623 /* end INIT_EVENT_ICON */
625 const int w = 16; /* DUMMY */
627 INIT_EVENT_ICON(ICON_EVENT_A, AKEY, KM_ANY);
628 INIT_EVENT_ICON(ICON_EVENT_B, BKEY, KM_ANY);
629 INIT_EVENT_ICON(ICON_EVENT_C, CKEY, KM_ANY);
630 INIT_EVENT_ICON(ICON_EVENT_D, DKEY, KM_ANY);
631 INIT_EVENT_ICON(ICON_EVENT_E, EKEY, KM_ANY);
632 INIT_EVENT_ICON(ICON_EVENT_F, FKEY, KM_ANY);
633 INIT_EVENT_ICON(ICON_EVENT_G, GKEY, KM_ANY);
634 INIT_EVENT_ICON(ICON_EVENT_H, HKEY, KM_ANY);
635 INIT_EVENT_ICON(ICON_EVENT_I, IKEY, KM_ANY);
636 INIT_EVENT_ICON(ICON_EVENT_J, JKEY, KM_ANY);
637 INIT_EVENT_ICON(ICON_EVENT_K, KKEY, KM_ANY);
638 INIT_EVENT_ICON(ICON_EVENT_L, LKEY, KM_ANY);
639 INIT_EVENT_ICON(ICON_EVENT_M, MKEY, KM_ANY);
640 INIT_EVENT_ICON(ICON_EVENT_N, NKEY, KM_ANY);
641 INIT_EVENT_ICON(ICON_EVENT_O, OKEY, KM_ANY);
642 INIT_EVENT_ICON(ICON_EVENT_P, PKEY, KM_ANY);
643 INIT_EVENT_ICON(ICON_EVENT_Q, QKEY, KM_ANY);
644 INIT_EVENT_ICON(ICON_EVENT_R, RKEY, KM_ANY);
645 INIT_EVENT_ICON(ICON_EVENT_S, SKEY, KM_ANY);
646 INIT_EVENT_ICON(ICON_EVENT_T, TKEY, KM_ANY);
647 INIT_EVENT_ICON(ICON_EVENT_U, UKEY, KM_ANY);
648 INIT_EVENT_ICON(ICON_EVENT_V, VKEY, KM_ANY);
649 INIT_EVENT_ICON(ICON_EVENT_W, WKEY, KM_ANY);
650 INIT_EVENT_ICON(ICON_EVENT_X, XKEY, KM_ANY);
651 INIT_EVENT_ICON(ICON_EVENT_Y, YKEY, KM_ANY);
652 INIT_EVENT_ICON(ICON_EVENT_Z, ZKEY, KM_ANY);
653 INIT_EVENT_ICON(ICON_EVENT_SHIFT, LEFTSHIFTKEY, KM_ANY);
654 INIT_EVENT_ICON(ICON_EVENT_CTRL, LEFTCTRLKEY, KM_ANY);
655 INIT_EVENT_ICON(ICON_EVENT_ALT, LEFTALTKEY, KM_ANY);
656 INIT_EVENT_ICON(ICON_EVENT_OS, OSKEY, KM_ANY);
657 INIT_EVENT_ICON(ICON_EVENT_F1, F1KEY, KM_ANY);
658 INIT_EVENT_ICON(ICON_EVENT_F2, F2KEY, KM_ANY);
659 INIT_EVENT_ICON(ICON_EVENT_F3, F3KEY, KM_ANY);
660 INIT_EVENT_ICON(ICON_EVENT_F4, F4KEY, KM_ANY);
661 INIT_EVENT_ICON(ICON_EVENT_F5, F5KEY, KM_ANY);
662 INIT_EVENT_ICON(ICON_EVENT_F6, F6KEY, KM_ANY);
663 INIT_EVENT_ICON(ICON_EVENT_F7, F7KEY, KM_ANY);
664 INIT_EVENT_ICON(ICON_EVENT_F8, F8KEY, KM_ANY);
665 INIT_EVENT_ICON(ICON_EVENT_F9, F9KEY, KM_ANY);
666 INIT_EVENT_ICON(ICON_EVENT_F10, F10KEY, KM_ANY);
667 INIT_EVENT_ICON(ICON_EVENT_F11, F11KEY, KM_ANY);
668 INIT_EVENT_ICON(ICON_EVENT_F12, F12KEY, KM_ANY);
669 INIT_EVENT_ICON(ICON_EVENT_ESC, ESCKEY, KM_ANY);
670 INIT_EVENT_ICON(ICON_EVENT_TAB, TABKEY, KM_ANY);
671 INIT_EVENT_ICON(ICON_EVENT_PAGEUP, PAGEUPKEY, KM_ANY);
672 INIT_EVENT_ICON(ICON_EVENT_PAGEDOWN, PAGEDOWNKEY, KM_ANY);
673 INIT_EVENT_ICON(ICON_EVENT_RETURN, RETKEY, KM_ANY);
675 g_di_event_list = di_next;
677 #undef INIT_EVENT_ICON
680 static void icon_verify_datatoc(IconImage *iimg)
682 /* if it has own rect, things are all OK */
686 if (iimg->datatoc_rect) {
687 ImBuf *bbuf = IMB_ibImageFromMemory(iimg->datatoc_rect,
688 iimg->datatoc_size, IB_rect, NULL, "<matcap icon>");
689 /* w and h were set on initialize */
690 if (bbuf->x != iimg->h && bbuf->y != iimg->w)
691 IMB_scaleImBuf(bbuf, iimg->w, iimg->h);
693 iimg->rect = bbuf->rect;
699 static void init_internal_icons(void)
701 // bTheme *btheme = UI_GetTheme();
702 ImBuf *b16buf = NULL, *b32buf = NULL;
705 #if 0 // temp disabled
706 if ((btheme != NULL) && btheme->tui.iconfile[0]) {
707 char *icondir = BKE_appdir_folder_id(BLENDER_DATAFILES, "icons");
708 char iconfilestr[FILE_MAX];
711 BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile);
713 /* if the image is missing bbuf will just be NULL */
714 bbuf = IMB_loadiffname(iconfilestr, IB_rect, NULL);
716 if (bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) {
717 printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr);
723 printf("%s: 'icons' data path not found, continuing\n", __func__);
728 b16buf = IMB_ibImageFromMemory((uchar *)datatoc_blender_icons16_png,
729 datatoc_blender_icons16_png_size, IB_rect, NULL, "<blender icons>");
731 IMB_premultiply_alpha(b16buf);
734 b32buf = IMB_ibImageFromMemory((uchar *)datatoc_blender_icons32_png,
735 datatoc_blender_icons32_png_size, IB_rect, NULL, "<blender icons>");
737 IMB_premultiply_alpha(b32buf);
739 if (b16buf && b32buf) {
740 /* Free existing texture if any. */
742 glDeleteTextures(1, &icongltex.id);
746 /* Allocate OpenGL texture. */
747 glGenTextures(1, &icongltex.id);
752 icongltex.w = b32buf->x;
753 icongltex.h = b32buf->y;
754 icongltex.invw = 1.0f / b32buf->x;
755 icongltex.invh = 1.0f / b32buf->y;
757 glBindTexture(GL_TEXTURE_2D, icongltex.id);
759 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, b32buf->x, b32buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b32buf->rect);
760 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, b16buf->x, b16buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b16buf->rect);
762 while (b16buf->x > 1) {
763 ImBuf *nbuf = IMB_onehalf(b16buf);
764 glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, nbuf->x, nbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nbuf->rect);
766 IMB_freeImBuf(b16buf);
770 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
771 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
773 glBindTexture(GL_TEXTURE_2D, 0);
777 for (y = 0; y < ICON_GRID_ROWS; y++) {
778 /* Row W has monochrome icons. */
779 for (x = 0; x < ICON_GRID_COLS; x++) {
780 IconType icontype = icontypes[y * ICON_GRID_COLS + x];
781 if (!ELEM(icontype.type, ICON_TYPE_COLOR_TEXTURE, ICON_TYPE_MONO_TEXTURE)) {
785 def_internal_icon(b32buf, BIFICONID_FIRST + y * ICON_GRID_COLS + x,
786 x * (ICON_GRID_W + ICON_GRID_MARGIN) + ICON_GRID_MARGIN,
787 y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W,
788 icontype.type, icontype.theme_color);
793 def_internal_vicon(ICON_SMALL_TRI_RIGHT_VEC, vicon_small_tri_right_draw);
795 def_internal_vicon(ICON_KEYTYPE_KEYFRAME_VEC, vicon_keytype_keyframe_draw);
796 def_internal_vicon(ICON_KEYTYPE_BREAKDOWN_VEC, vicon_keytype_breakdown_draw);
797 def_internal_vicon(ICON_KEYTYPE_EXTREME_VEC, vicon_keytype_extreme_draw);
798 def_internal_vicon(ICON_KEYTYPE_JITTER_VEC, vicon_keytype_jitter_draw);
799 def_internal_vicon(ICON_KEYTYPE_MOVING_HOLD_VEC, vicon_keytype_moving_hold_draw);
801 def_internal_vicon(ICON_HANDLETYPE_FREE_VEC, vicon_handletype_free_draw);
802 def_internal_vicon(ICON_HANDLETYPE_ALIGNED_VEC, vicon_handletype_aligned_draw);
803 def_internal_vicon(ICON_HANDLETYPE_VECTOR_VEC, vicon_handletype_vector_draw);
804 def_internal_vicon(ICON_HANDLETYPE_AUTO_VEC, vicon_handletype_auto_draw);
805 def_internal_vicon(ICON_HANDLETYPE_AUTO_CLAMP_VEC, vicon_handletype_auto_clamp_draw);
807 def_internal_vicon(ICON_COLORSET_01_VEC, vicon_colorset_draw_01);
808 def_internal_vicon(ICON_COLORSET_02_VEC, vicon_colorset_draw_02);
809 def_internal_vicon(ICON_COLORSET_03_VEC, vicon_colorset_draw_03);
810 def_internal_vicon(ICON_COLORSET_04_VEC, vicon_colorset_draw_04);
811 def_internal_vicon(ICON_COLORSET_05_VEC, vicon_colorset_draw_05);
812 def_internal_vicon(ICON_COLORSET_06_VEC, vicon_colorset_draw_06);
813 def_internal_vicon(ICON_COLORSET_07_VEC, vicon_colorset_draw_07);
814 def_internal_vicon(ICON_COLORSET_08_VEC, vicon_colorset_draw_08);
815 def_internal_vicon(ICON_COLORSET_09_VEC, vicon_colorset_draw_09);
816 def_internal_vicon(ICON_COLORSET_10_VEC, vicon_colorset_draw_10);
817 def_internal_vicon(ICON_COLORSET_11_VEC, vicon_colorset_draw_11);
818 def_internal_vicon(ICON_COLORSET_12_VEC, vicon_colorset_draw_12);
819 def_internal_vicon(ICON_COLORSET_13_VEC, vicon_colorset_draw_13);
820 def_internal_vicon(ICON_COLORSET_14_VEC, vicon_colorset_draw_14);
821 def_internal_vicon(ICON_COLORSET_15_VEC, vicon_colorset_draw_15);
822 def_internal_vicon(ICON_COLORSET_16_VEC, vicon_colorset_draw_16);
823 def_internal_vicon(ICON_COLORSET_17_VEC, vicon_colorset_draw_17);
824 def_internal_vicon(ICON_COLORSET_18_VEC, vicon_colorset_draw_18);
825 def_internal_vicon(ICON_COLORSET_19_VEC, vicon_colorset_draw_19);
826 def_internal_vicon(ICON_COLORSET_20_VEC, vicon_colorset_draw_20);
828 IMB_freeImBuf(b16buf);
829 IMB_freeImBuf(b32buf);
832 #endif /* WITH_HEADLESS */
834 static void init_iconfile_list(struct ListBase *list)
837 struct direntry *dir;
838 int totfile, i, index = 1;
841 BLI_listbase_clear(list);
842 icondir = BKE_appdir_folder_id(BLENDER_DATAFILES, "icons");
847 totfile = BLI_filelist_dir_contents(icondir, &dir);
849 for (i = 0; i < totfile; i++) {
850 if ((dir[i].type & S_IFREG)) {
851 const char *filename = dir[i].relname;
853 if (BLI_path_extension_check(filename, ".png")) {
854 /* loading all icons on file start is overkill & slows startup
855 * its possible they change size after blender load anyway. */
858 char iconfilestr[FILE_MAX + 16]; /* allow 256 chars for file+dir */
860 /* check to see if the image is the right size, continue if not */
861 /* copying strings here should go ok, assuming that we never get back
862 * a complete path to file longer than 256 chars */
863 BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, filename);
864 bbuf = IMB_loadiffname(iconfilestr, IB_rect);
875 /* bad size or failed to load */
876 if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) {
877 printf("icon '%s' is wrong size %dx%d\n", iconfilestr, ifilex, ifiley);
882 /* found a potential icon file, so make an entry for it in the cache list */
883 ifile = MEM_callocN(sizeof(IconFile), "IconFile");
885 BLI_strncpy(ifile->filename, filename, sizeof(ifile->filename));
886 ifile->index = index;
888 BLI_addtail(list, ifile);
895 BLI_filelist_free(dir, totfile);
899 static void free_iconfile_list(struct ListBase *list)
901 IconFile *ifile = NULL, *next_ifile = NULL;
903 for (ifile = list->first; ifile; ifile = next_ifile) {
904 next_ifile = ifile->next;
905 BLI_freelinkN(list, ifile);
909 #endif /* WITH_HEADLESS */
911 int UI_iconfile_get_index(const char *filename)
914 ListBase *list = &(iconfilelist);
916 for (ifile = list->first; ifile; ifile = ifile->next) {
917 if (BLI_path_cmp(filename, ifile->filename) == 0) {
925 ListBase *UI_iconfile_list(void)
927 ListBase *list = &(iconfilelist);
933 void UI_icons_free(void)
935 #ifndef WITH_HEADLESS
937 glDeleteTextures(1, &icongltex.id);
941 free_iconfile_list(&iconfilelist);
946 void UI_icons_free_drawinfo(void *drawinfo)
948 DrawInfo *di = drawinfo;
951 if (di->type == ICON_TYPE_BUFFER) {
952 if (di->data.buffer.image) {
953 if (di->data.buffer.image->rect)
954 MEM_freeN(di->data.buffer.image->rect);
955 MEM_freeN(di->data.buffer.image);
958 else if (di->type == ICON_TYPE_GEOM) {
959 if (di->data.geom.image_cache) {
960 IMB_freeImBuf(di->data.geom.image_cache);
969 * #Icon.data_type and #Icon.obj
971 static DrawInfo *icon_create_drawinfo(Icon *icon)
973 int icon_data_type = icon->obj_type;
976 di = MEM_callocN(sizeof(DrawInfo), "di_icon");
978 if (ELEM(icon_data_type, ICON_DATA_ID, ICON_DATA_PREVIEW)) {
979 di->type = ICON_TYPE_PREVIEW;
981 else if (icon_data_type == ICON_DATA_GEOM) {
982 di->type = ICON_TYPE_GEOM;
984 else if (icon_data_type == ICON_DATA_STUDIOLIGHT) {
985 di->type = ICON_TYPE_BUFFER;
987 else if (icon_data_type == ICON_DATA_GPLAYER) {
988 di->type = ICON_TYPE_GPLAYER;
997 static DrawInfo *icon_ensure_drawinfo(Icon *icon)
999 if (icon->drawinfo) {
1000 return icon->drawinfo;
1002 DrawInfo *di = icon_create_drawinfo(icon);
1003 icon->drawinfo = di;
1004 icon->drawinfo_free = UI_icons_free_drawinfo;
1008 /* note!, returns unscaled by DPI */
1009 int UI_icon_get_width(int icon_id)
1012 DrawInfo *di = NULL;
1014 icon = BKE_icon_get(icon_id);
1017 if (G.debug & G_DEBUG)
1018 printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
1022 di = icon_ensure_drawinfo(icon);
1024 return ICON_DEFAULT_WIDTH;
1030 int UI_icon_get_height(int icon_id)
1032 Icon *icon = BKE_icon_get(icon_id);
1034 if (G.debug & G_DEBUG)
1035 printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
1039 DrawInfo *di = icon_ensure_drawinfo(icon);
1041 return ICON_DEFAULT_HEIGHT;
1047 void UI_icons_init()
1049 #ifndef WITH_HEADLESS
1050 init_iconfile_list(&iconfilelist);
1051 init_internal_icons();
1057 /* Render size for preview images and icons
1059 int UI_preview_render_size(enum eIconSizes size)
1062 case ICON_SIZE_ICON:
1063 return ICON_RENDER_DEFAULT_HEIGHT;
1064 case ICON_SIZE_PREVIEW:
1065 return PREVIEW_RENDER_DEFAULT_HEIGHT;
1071 /* Create rect for the icon
1073 static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size)
1075 uint render_size = UI_preview_render_size(size);
1078 if (G.debug & G_DEBUG)
1079 printf("%s, error: requested preview image does not exist", __func__);
1081 else if (!prv_img->rect[size]) {
1082 prv_img->w[size] = render_size;
1083 prv_img->h[size] = render_size;
1084 prv_img->flag[size] |= PRV_CHANGED;
1085 prv_img->changed_timestamp[size] = 0;
1086 prv_img->rect[size] = MEM_callocN(render_size * render_size * sizeof(uint), "prv_rect");
1090 static void ui_id_preview_image_render_size(
1091 const bContext *C, Scene *scene, ID *id, PreviewImage *pi, int size, const bool use_job);
1093 static void ui_studiolight_icon_job_exec(void *customdata, short *UNUSED(stop), short *UNUSED(do_update), float *UNUSED(progress))
1095 Icon **tmp = (Icon **)customdata;
1097 DrawInfo *di = icon_ensure_drawinfo(icon);
1098 StudioLight *sl = icon->obj;
1099 BKE_studiolight_preview(di->data.buffer.image->rect, sl, icon->id_type);
1102 static void ui_studiolight_kill_icon_preview_job(wmWindowManager *wm, int icon_id)
1104 Icon *icon = BKE_icon_get(icon_id);
1105 WM_jobs_kill_type(wm, icon, WM_JOB_TYPE_STUDIOLIGHT);
1109 static void ui_studiolight_free_function(StudioLight *sl, void *data)
1111 wmWindowManager *wm = data;
1113 /* Happens if job was canceled or already finished. */
1117 // get icons_id, get icons and kill wm jobs
1118 if (sl->icon_id_radiance) {
1119 ui_studiolight_kill_icon_preview_job(wm, sl->icon_id_radiance);
1121 if (sl->icon_id_irradiance) {
1122 ui_studiolight_kill_icon_preview_job(wm, sl->icon_id_irradiance);
1124 if (sl->icon_id_matcap) {
1125 ui_studiolight_kill_icon_preview_job(wm, sl->icon_id_matcap);
1127 if (sl->icon_id_matcap_flipped) {
1128 ui_studiolight_kill_icon_preview_job(wm, sl->icon_id_matcap_flipped);
1132 static void ui_studiolight_icon_job_end(void *customdata)
1134 Icon **tmp = (Icon **)customdata;
1136 StudioLight *sl = icon->obj;
1137 BKE_studiolight_set_free_function(sl, &ui_studiolight_free_function, NULL);
1140 void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool big)
1142 Icon *icon = BKE_icon_get(icon_id);
1145 DrawInfo *di = icon_ensure_drawinfo(icon);
1149 case ICON_TYPE_PREVIEW:
1151 ID *id = (icon->id_type != 0) ? icon->obj : NULL;
1152 PreviewImage *prv = id ? BKE_previewimg_id_ensure(id) : icon->obj;
1153 /* Using jobs for screen previews crashes due to offscreen rendering.
1154 * XXX would be nicer if PreviewImage could store if it supports jobs */
1155 const bool use_jobs = !id || (GS(id->name) != ID_SCR);
1158 const int size = big ? ICON_SIZE_PREVIEW : ICON_SIZE_ICON;
1160 if (id || (prv->tag & PRV_TAG_DEFFERED) != 0) {
1161 ui_id_preview_image_render_size(C, NULL, id, prv, size, use_jobs);
1166 case ICON_TYPE_BUFFER:
1168 if (icon->obj_type == ICON_DATA_STUDIOLIGHT) {
1169 if (di->data.buffer.image == NULL) {
1170 wmWindowManager *wm = CTX_wm_manager(C);
1171 StudioLight *sl = icon->obj;
1172 BKE_studiolight_set_free_function(sl, &ui_studiolight_free_function, wm);
1173 IconImage *img = MEM_mallocN(sizeof(IconImage), __func__);
1175 img->w = STUDIOLIGHT_ICON_SIZE;
1176 img->h = STUDIOLIGHT_ICON_SIZE;
1177 size_t size = STUDIOLIGHT_ICON_SIZE * STUDIOLIGHT_ICON_SIZE * sizeof(uint);
1178 img->rect = MEM_mallocN(size, __func__);
1179 memset(img->rect, 0, size);
1180 di->data.buffer.image = img;
1182 wmJob *wm_job = WM_jobs_get(wm, CTX_wm_window(C), icon, "StudioLight Icon", 0, WM_JOB_TYPE_STUDIOLIGHT);
1183 Icon **tmp = MEM_callocN(sizeof(Icon *), __func__);
1185 WM_jobs_customdata_set(wm_job, tmp, MEM_freeN);
1186 WM_jobs_timer(wm_job, 0.01, 0, NC_WINDOW);
1187 WM_jobs_callbacks(wm_job, ui_studiolight_icon_job_exec, NULL, NULL, ui_studiolight_icon_job_end);
1188 WM_jobs_start(CTX_wm_manager(C), wm_job);
1198 /* only called when icon has changed */
1199 /* only call with valid pointer from UI_icon_draw */
1200 static void icon_set_image(
1201 const bContext *C, Scene *scene, ID *id, PreviewImage *prv_img, enum eIconSizes size, const bool use_job)
1204 if (G.debug & G_DEBUG)
1205 printf("%s: no preview image for this ID: %s\n", __func__, id->name);
1209 if (prv_img->flag[size] & PRV_USER_EDITED) {
1210 /* user-edited preview, do not auto-update! */
1214 icon_create_rect(prv_img, size);
1217 /* Job (background) version */
1218 ED_preview_icon_job(C, prv_img, id, prv_img->rect[size], prv_img->w[size], prv_img->h[size]);
1222 scene = CTX_data_scene(C);
1224 /* Immediate version */
1225 ED_preview_icon_render(CTX_data_main(C), scene, id, prv_img->rect[size], prv_img->w[size], prv_img->h[size]);
1229 PreviewImage *UI_icon_to_preview(int icon_id)
1231 Icon *icon = BKE_icon_get(icon_id);
1234 DrawInfo *di = (DrawInfo *)icon->drawinfo;
1236 if (di->type == ICON_TYPE_PREVIEW) {
1237 PreviewImage *prv = (icon->id_type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) : icon->obj;
1240 return BKE_previewimg_copy(prv);
1243 else if (di->data.buffer.image) {
1246 bbuf = IMB_ibImageFromMemory(di->data.buffer.image->datatoc_rect, di->data.buffer.image->datatoc_size,
1247 IB_rect, NULL, __func__);
1249 PreviewImage *prv = BKE_previewimg_create();
1251 prv->rect[0] = bbuf->rect;
1253 prv->w[0] = bbuf->x;
1254 prv->h[0] = bbuf->y;
1257 IMB_freeImBuf(bbuf);
1267 static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh,
1268 uint *rect, float alpha, const float rgb[3], const float desaturate)
1277 if (w <= 0 || h <= 0 || w > 2000 || h > 2000) {
1278 printf("%s: icons are %i x %i pixels?\n", __func__, w, h);
1279 BLI_assert(!"invalid icon size");
1282 /* modulate color */
1283 float col[4] = {1.0f, 1.0f, 1.0f, alpha};
1291 /* rect contains image in 'rendersize', we only scale if needed */
1292 if (rw != w || rh != h) {
1293 /* preserve aspect ratio and center */
1296 draw_h = (int)(((float)rh / (float)rw) * (float)w);
1297 draw_y += (h - draw_h) / 2;
1300 draw_w = (int)(((float)rw / (float)rh) * (float)h);
1302 draw_x += (w - draw_w) / 2;
1304 /* if the image is squared, the draw_ initialization values are good */
1306 /* first allocate imbuf for scaling and copy preview into it */
1307 ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
1308 memcpy(ima->rect, rect, rw * rh * sizeof(uint));
1309 IMB_scaleImBuf(ima, draw_w, draw_h); /* scale it */
1314 GPUBuiltinShader shader;
1315 if (desaturate != 0.0f) {
1316 shader = GPU_SHADER_2D_IMAGE_DESATURATE_COLOR;
1319 shader = GPU_SHADER_2D_IMAGE_COLOR;
1321 IMMDrawPixelsTexState state = immDrawPixelsTexSetup(shader);
1323 if (shader == GPU_SHADER_2D_IMAGE_DESATURATE_COLOR) {
1324 immUniform1f("factor", desaturate);
1327 immDrawPixelsTex(&state, draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
1334 /* High enough to make a difference, low enough so that
1335 * small draws are still efficient with the use of glUniform.
1336 * NOTE TODO: We could use UBO but we would need some triple
1337 * buffer system + persistent mapping for this to be more
1338 * efficient than simple glUniform calls. */
1339 #define ICON_DRAW_CACHE_SIZE 16
1341 typedef struct IconDrawCall {
1348 IconDrawCall drawcall_cache[ICON_DRAW_CACHE_SIZE];
1349 int calls; /* Number of calls batched together */
1352 } g_icon_draw_cache = {{{{0}}}};
1354 void UI_icon_draw_cache_begin(void)
1356 BLI_assert(g_icon_draw_cache.enabled == false);
1357 g_icon_draw_cache.enabled = true;
1360 static void icon_draw_cache_flush_ex(void)
1362 if (g_icon_draw_cache.calls == 0)
1365 /* We need to flush widget base first to ensure correct ordering. */
1366 UI_widgetbase_draw_cache_flush();
1368 GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1370 glActiveTexture(GL_TEXTURE0);
1371 glBindTexture(GL_TEXTURE_2D, icongltex.id);
1373 GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR);
1374 GPU_shader_bind(shader);
1376 int img_loc = GPU_shader_get_uniform(shader, "image");
1377 int data_loc = GPU_shader_get_uniform(shader, "calls_data[0]");
1379 glUniform1i(img_loc, 0);
1380 glUniform4fv(data_loc, ICON_DRAW_CACHE_SIZE * 3, (float *)g_icon_draw_cache.drawcall_cache);
1382 GPU_draw_primitive(GPU_PRIM_TRIS, 6 * g_icon_draw_cache.calls);
1384 glBindTexture(GL_TEXTURE_2D, 0);
1386 g_icon_draw_cache.calls = 0;
1388 GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1391 void UI_icon_draw_cache_end(void)
1393 BLI_assert(g_icon_draw_cache.enabled == true);
1394 g_icon_draw_cache.enabled = false;
1396 /* Don't change blend state if it's not needed. */
1397 if (g_icon_draw_cache.calls == 0)
1401 icon_draw_cache_flush_ex();
1405 static void icon_draw_texture_cached(
1406 float x, float y, float w, float h, int ix, int iy,
1407 int UNUSED(iw), int ih, float alpha, const float rgb[3])
1411 GPU_matrix_model_view_projection_get(mvp);
1413 IconDrawCall *call = &g_icon_draw_cache.drawcall_cache[g_icon_draw_cache.calls];
1414 g_icon_draw_cache.calls++;
1416 /* Manual mat4*vec2 */
1417 call->pos.xmin = x * mvp[0][0] + y * mvp[1][0] + mvp[3][0];
1418 call->pos.ymin = x * mvp[0][1] + y * mvp[1][1] + mvp[3][1];
1419 call->pos.xmax = call->pos.xmin + w * mvp[0][0] + h * mvp[1][0];
1420 call->pos.ymax = call->pos.ymin + w * mvp[0][1] + h * mvp[1][1];
1422 call->tex.xmin = ix * icongltex.invw;
1423 call->tex.xmax = (ix + ih) * icongltex.invw;
1424 call->tex.ymin = iy * icongltex.invh;
1425 call->tex.ymax = (iy + ih) * icongltex.invh;
1427 if (rgb) copy_v4_fl4(call->color, rgb[0], rgb[1], rgb[2], alpha);
1428 else copy_v4_fl(call->color, alpha);
1430 if (g_icon_draw_cache.calls == ICON_DRAW_CACHE_SIZE) {
1431 icon_draw_cache_flush_ex();
1435 static void icon_draw_texture(
1436 float x, float y, float w, float h, int ix, int iy,
1437 int iw, int ih, float alpha, const float rgb[3])
1439 if (g_icon_draw_cache.enabled) {
1440 icon_draw_texture_cached(x, y, w, h, ix, iy, iw, ih, alpha, rgb);
1444 /* We need to flush widget base first to ensure correct ordering. */
1445 UI_widgetbase_draw_cache_flush();
1447 GPU_blend_set_func(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1449 float x1, x2, y1, y2;
1451 x1 = ix * icongltex.invw;
1452 x2 = (ix + ih) * icongltex.invw;
1453 y1 = iy * icongltex.invh;
1454 y2 = (iy + ih) * icongltex.invh;
1456 glActiveTexture(GL_TEXTURE0);
1457 glBindTexture(GL_TEXTURE_2D, icongltex.id);
1459 GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR);
1460 GPU_shader_bind(shader);
1462 if (rgb) glUniform4f(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR), rgb[0], rgb[1], rgb[2], alpha);
1463 else glUniform4f(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_COLOR), alpha, alpha, alpha, alpha);
1465 glUniform1i(GPU_shader_get_uniform(shader, "image"), 0);
1466 glUniform4f(GPU_shader_get_uniform(shader, "rect_icon"), x1, y1, x2, y2);
1467 glUniform4f(GPU_shader_get_uniform(shader, "rect_geom"), x, y, x + w, y + h);
1469 GPU_draw_primitive(GPU_PRIM_TRI_STRIP, 4);
1471 glBindTexture(GL_TEXTURE_2D, 0);
1473 GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1476 /* Drawing size for preview images */
1477 static int get_draw_size(enum eIconSizes size)
1480 case ICON_SIZE_ICON:
1481 return ICON_DEFAULT_HEIGHT;
1482 case ICON_SIZE_PREVIEW:
1483 return PREVIEW_DEFAULT_HEIGHT;
1491 static void icon_draw_size(
1492 float x, float y, int icon_id, float aspect, float alpha, const float rgb[3],
1493 enum eIconSizes size, int draw_size, const float desaturate, const char mono_rgba[4])
1495 bTheme *btheme = UI_GetTheme();
1498 const float fdraw_size = (float)draw_size;
1501 icon = BKE_icon_get(icon_id);
1502 alpha *= btheme->tui.icon_alpha;
1505 if (G.debug & G_DEBUG)
1506 printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
1510 /* scale width and height according to aspect */
1511 w = (int)(fdraw_size / aspect + 0.5f);
1512 h = (int)(fdraw_size / aspect + 0.5f);
1514 DrawInfo *di = icon_ensure_drawinfo(icon);
1516 /* We need to flush widget base first to ensure correct ordering. */
1517 UI_widgetbase_draw_cache_flush();
1519 if (di->type == ICON_TYPE_VECTOR) {
1520 /* vector icons use the uiBlock transformation, they are not drawn
1521 * with untransformed coordinates like the other icons */
1522 di->data.vector.func((int)x, (int)y, w, h, 1.0f);
1524 else if (di->type == ICON_TYPE_GEOM) {
1525 #ifdef USE_UI_TOOLBAR_HACK
1526 /* TODO(campbell): scale icons up for toolbar,
1527 * we need a way to detect larger buttons and do this automatic. */
1529 float scale = (float)ICON_DEFAULT_HEIGHT_TOOLBAR / (float)ICON_DEFAULT_HEIGHT;
1530 y = (y + (h / 2)) - ((h * scale) / 2);
1536 /* This could re-generate often if rendered at different sizes in the one interface.
1537 * TODO(campbell): support caching multiple sizes. */
1538 ImBuf *ibuf = di->data.geom.image_cache;
1539 if ((ibuf == NULL) ||
1544 IMB_freeImBuf(ibuf);
1546 ibuf = BKE_icon_geom_rasterize(icon->obj, w, h);
1547 di->data.geom.image_cache = ibuf;
1550 GPU_blend_set_func_separate(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1551 icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, rgb, desaturate);
1552 GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1554 else if (di->type == ICON_TYPE_EVENT) {
1555 const short event_type = di->data.input.event_type;
1556 const short event_value = di->data.input.event_value;
1557 icon_draw_rect_input(x, y, w, h, alpha, event_type, event_value);
1559 else if (di->type == ICON_TYPE_COLOR_TEXTURE) {
1560 /* texture image use premul alpha for correct scaling */
1561 icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y,
1562 di->data.texture.w, di->data.texture.h, alpha, rgb);
1564 else if (di->type == ICON_TYPE_MONO_TEXTURE) {
1565 /* icon that matches text color, assumed to be white */
1567 if (!UI_GetIconThemeColor4fv(di->data.texture.theme_color, color)) {
1569 rgba_uchar_to_float(color, (const uchar *)mono_rgba);
1572 UI_GetThemeColor4fv(TH_TEXT, color);
1577 mul_v3_v3(color, rgb);
1580 mul_v4_fl(color, alpha);
1582 icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y,
1583 di->data.texture.w, di->data.texture.h, color[3], color);
1586 else if (di->type == ICON_TYPE_BUFFER) {
1587 /* it is a builtin icon */
1588 iimg = di->data.buffer.image;
1589 #ifndef WITH_HEADLESS
1590 icon_verify_datatoc(iimg);
1592 if (!iimg->rect) return; /* something has gone wrong! */
1594 icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, desaturate);
1596 else if (di->type == ICON_TYPE_PREVIEW) {
1597 PreviewImage *pi = (icon->id_type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) : icon->obj;
1600 /* no create icon on this level in code */
1601 if (!pi->rect[size]) return; /* something has gone wrong! */
1603 /* Preview images use premultiplied alpha. */
1604 GPU_blend_set_func_separate(GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1605 icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, rgb, desaturate);
1606 GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
1609 else if (di->type == ICON_TYPE_GPLAYER) {
1610 BLI_assert(icon->obj != NULL);
1612 /* Just draw a colored rect - Like for vicon_colorset_draw() */
1613 #ifndef WITH_HEADLESS
1614 vicon_gplayer_color_draw(icon, (int)x, (int)y, w, h);
1619 static void ui_id_preview_image_render_size(
1620 const bContext *C, Scene *scene, ID *id, PreviewImage *pi, int size, const bool use_job)
1622 /* changed only ever set by dynamic icons */
1623 if (((pi->flag[size] & PRV_CHANGED) || !pi->rect[size])) {
1624 /* create the rect if necessary */
1625 icon_set_image(C, scene, id, pi, size, use_job);
1627 pi->flag[size] &= ~PRV_CHANGED;
1631 void UI_id_icon_render(const bContext *C, Scene *scene, ID *id, const bool big, const bool use_job)
1633 PreviewImage *pi = BKE_previewimg_id_ensure(id);
1637 /* bigger preview size */
1638 ui_id_preview_image_render_size(C, scene, id, pi, ICON_SIZE_PREVIEW, use_job);
1642 ui_id_preview_image_render_size(C, scene, id, pi, ICON_SIZE_ICON, use_job);
1647 static void ui_id_icon_render(const bContext *C, ID *id, bool use_jobs)
1649 PreviewImage *pi = BKE_previewimg_id_ensure(id);
1655 for (i = 0; i < NUM_ICON_SIZES; i++) {
1656 /* check if rect needs to be created; changed
1657 * only set by dynamic icons */
1658 if (((pi->flag[i] & PRV_CHANGED) || !pi->rect[i])) {
1659 icon_set_image(C, NULL, id, pi, i, use_jobs);
1660 pi->flag[i] &= ~PRV_CHANGED;
1666 static int ui_id_brush_get_icon(const bContext *C, ID *id)
1668 Brush *br = (Brush *)id;
1670 if (br->flag & BRUSH_CUSTOM_ICON) {
1671 BKE_icon_id_ensure(id);
1672 ui_id_icon_render(C, id, true);
1675 WorkSpace *workspace = CTX_wm_workspace(C);
1676 Object *ob = CTX_data_active_object(C);
1677 const EnumPropertyItem *items = NULL;
1678 ePaintMode paint_mode = PAINT_MODE_INVALID;
1679 ScrArea *sa = CTX_wm_area(C);
1680 char space_type = sa->spacetype;
1681 /* When in an unsupported space. */
1682 if (!ELEM(space_type, SPACE_VIEW3D, SPACE_IMAGE)) {
1683 space_type = workspace->tools_space_type;
1686 /* XXX: this is not nice, should probably make brushes
1687 * be strictly in one paint mode only to avoid
1688 * checking various context stuff here */
1690 if ((space_type == SPACE_VIEW3D) && ob) {
1691 if (ob->mode & OB_MODE_SCULPT) {
1692 paint_mode = PAINT_MODE_SCULPT;
1694 else if (ob->mode & OB_MODE_VERTEX_PAINT) {
1695 paint_mode = PAINT_MODE_VERTEX;
1697 else if (ob->mode & OB_MODE_WEIGHT_PAINT) {
1698 paint_mode = PAINT_MODE_WEIGHT;
1700 else if (ob->mode & OB_MODE_TEXTURE_PAINT) {
1701 paint_mode = PAINT_MODE_TEXTURE_3D;
1704 else if (space_type == SPACE_IMAGE) {
1706 if (sa->spacetype == space_type) {
1707 SpaceImage *sima = sa->spacedata.first;
1708 sima_mode = sima->mode;
1711 sima_mode = workspace->tools_mode;
1714 if (sima_mode == SI_MODE_PAINT) {
1715 paint_mode = PAINT_MODE_TEXTURE_2D;
1719 /* reset the icon */
1721 (ob->mode & OB_MODE_PAINT_GPENCIL) &&
1722 (br->gpencil_settings != NULL))
1724 switch (br->gpencil_settings->icon_id) {
1725 case GP_BRUSH_ICON_PENCIL:
1726 br->id.icon_id = ICON_GPBRUSH_PENCIL;
1728 case GP_BRUSH_ICON_PEN:
1729 br->id.icon_id = ICON_GPBRUSH_PEN;
1731 case GP_BRUSH_ICON_INK:
1732 br->id.icon_id = ICON_GPBRUSH_INK;
1734 case GP_BRUSH_ICON_INKNOISE:
1735 br->id.icon_id = ICON_GPBRUSH_INKNOISE;
1737 case GP_BRUSH_ICON_BLOCK:
1738 br->id.icon_id = ICON_GPBRUSH_BLOCK;
1740 case GP_BRUSH_ICON_MARKER:
1741 br->id.icon_id = ICON_GPBRUSH_MARKER;
1743 case GP_BRUSH_ICON_FILL:
1744 br->id.icon_id = ICON_GPBRUSH_FILL;
1746 case GP_BRUSH_ICON_ERASE_SOFT:
1747 br->id.icon_id = ICON_GPBRUSH_ERASE_SOFT;
1749 case GP_BRUSH_ICON_ERASE_HARD:
1750 br->id.icon_id = ICON_GPBRUSH_ERASE_HARD;
1752 case GP_BRUSH_ICON_ERASE_STROKE:
1753 br->id.icon_id = ICON_GPBRUSH_ERASE_STROKE;
1756 br->id.icon_id = ICON_GPBRUSH_PEN;
1761 else if (paint_mode != PAINT_MODE_INVALID) {
1762 items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
1763 const uint tool_offset = BKE_paint_get_brush_tool_offset_from_paintmode(paint_mode);
1764 const int tool_type = *(char *)POINTER_OFFSET(br, tool_offset);
1765 if (!items || !RNA_enum_icon_from_value(items, tool_type, &id->icon_id)) {
1777 static int ui_id_screen_get_icon(const bContext *C, ID *id)
1779 BKE_icon_id_ensure(id);
1780 /* Don't use jobs here, offscreen rendering doesn't like this and crashes. */
1781 ui_id_icon_render(C, id, false);
1786 int ui_id_icon_get(const bContext *C, ID *id, const bool big)
1791 switch (GS(id->name)) {
1793 iconid = ui_id_brush_get_icon(C, id);
1795 case ID_MA: /* fall through */
1796 case ID_TE: /* fall through */
1797 case ID_IM: /* fall through */
1798 case ID_WO: /* fall through */
1799 case ID_LA: /* fall through */
1800 iconid = BKE_icon_id_ensure(id);
1801 /* checks if not exists, or changed */
1802 UI_id_icon_render(C, NULL, id, big, true);
1805 iconid = ui_id_screen_get_icon(C, id);
1814 int UI_rnaptr_icon_get(bContext *C, PointerRNA *ptr, int rnaicon, const bool big)
1821 /* try ID, material, texture or dynapaint slot */
1822 if (RNA_struct_is_ID(ptr->type)) {
1825 else if (RNA_struct_is_a(ptr->type, &RNA_MaterialSlot)) {
1826 id = RNA_pointer_get(ptr, "material").data;
1828 else if (RNA_struct_is_a(ptr->type, &RNA_TextureSlot)) {
1829 id = RNA_pointer_get(ptr, "texture").data;
1831 else if (RNA_struct_is_a(ptr->type, &RNA_DynamicPaintSurface)) {
1832 DynamicPaintSurface *surface = ptr->data;
1834 if (surface->format == MOD_DPAINT_SURFACE_F_PTEX)
1835 return ICON_SHADING_TEXTURE;
1836 else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX)
1837 return ICON_OUTLINER_DATA_MESH;
1838 else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ)
1839 return ICON_FILE_IMAGE;
1841 else if (RNA_struct_is_a(ptr->type, &RNA_StudioLight)) {
1842 StudioLight *sl = ptr->data;
1843 switch (sl->flag & STUDIOLIGHT_FLAG_ORIENTATIONS) {
1844 case STUDIOLIGHT_TYPE_STUDIO:
1845 return sl->icon_id_irradiance;
1846 case STUDIOLIGHT_TYPE_WORLD:
1848 return sl->icon_id_radiance;
1849 case STUDIOLIGHT_TYPE_MATCAP:
1850 return sl->icon_id_matcap;
1854 /* get icon from ID */
1856 int icon = ui_id_icon_get(C, id, big);
1858 return icon ? icon : rnaicon;
1864 int UI_idcode_icon_get(const int idcode)
1870 return ICON_ARMATURE_DATA;
1872 return ICON_BRUSH_DATA;
1874 return ICON_CAMERA_DATA;
1878 return ICON_CURVE_DATA;
1880 return ICON_GREASEPENCIL;
1884 return ICON_IMAGE_DATA;
1886 return ICON_LIGHT_DATA;
1888 return ICON_LINE_DATA;
1890 return ICON_LATTICE_DATA;
1892 return ICON_MATERIAL_DATA;
1894 return ICON_META_DATA;
1896 return ICON_TRACKER;
1898 return ICON_MESH_DATA;
1900 return ICON_MOD_MASK; /* TODO! this would need its own icon! */
1902 return ICON_NODETREE;
1904 return ICON_OBJECT_DATA;
1906 return ICON_PARTICLE_DATA;
1908 return ICON_COLOR; /* TODO! this would need its own icon! */
1910 return ICON_CURVE_BEZCURVE; /* TODO! this would need its own icon! */
1912 return ICON_LIGHTPROBE_CUBEMAP;
1914 return ICON_SCENE_DATA;
1916 return ICON_SPEAKER;
1920 return ICON_TEXTURE_DATA;
1924 return ICON_FONT_DATA;
1926 return ICON_WORLD_DATA;
1932 static void icon_draw_at_size(
1933 float x, float y, int icon_id, float aspect, float alpha,
1934 enum eIconSizes size, const float desaturate, const char mono_color[4])
1936 int draw_size = get_draw_size(size);
1937 icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, desaturate, mono_color);
1940 void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha, const char mono_color[4])
1942 icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0.0f, mono_color);
1945 void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3], const char mono_color[4])
1947 int draw_size = get_draw_size(ICON_SIZE_ICON);
1948 icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false, mono_color);
1951 void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha, float desaturate, const char mono_color[4])
1953 icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, desaturate, mono_color);
1956 /* draws icon with dpi scale factor */
1957 void UI_icon_draw(float x, float y, int icon_id)
1959 UI_icon_draw_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f, NULL);
1962 void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
1964 UI_icon_draw_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha, NULL);
1967 void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)
1969 icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, false, NULL);
1972 void UI_icon_draw_preview(float x, float y, int icon_id)
1974 icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, false, NULL);
1977 void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect)
1979 icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, false, NULL);
1982 void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspect, float alpha, int size)
1984 icon_draw_size(x, y, icon_id, aspect, alpha, NULL, ICON_SIZE_PREVIEW, size, false, NULL);