133
131
/* **************************************************** */
135
static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type)
133
#ifndef WITH_HEADLESS
135
static DrawInfo *def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type)
137
137
Icon *new_icon = NULL;
138
138
IconImage *iimg = NULL;
143
141
new_icon = MEM_callocN(sizeof(Icon), "texicon");
145
143
new_icon->obj = NULL; /* icon is not for library object */
148
146
di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
155
153
di->data.texture.h = size;
157
155
else if (type == ICON_TYPE_BUFFER) {
158
iimg = MEM_mallocN(sizeof(IconImage), "icon_img");
159
iimg->rect = MEM_mallocN(size * size * sizeof(unsigned int), "icon_rect");
156
iimg = MEM_callocN(sizeof(IconImage), "icon_img");
163
/* Here we store the rect in the icon - same as before */
165
for (y = 0; y < size; y++) {
166
memcpy(&iimg->rect[y * size], &bbuf->rect[(y + yofs) * imgsize + xofs], size * sizeof(int));
160
/* icon buffers can get initialized runtime now, via datatoc */
164
iimg->rect = MEM_mallocN(size * size * sizeof(unsigned int), "icon_rect");
166
/* Here we store the rect in the icon - same as before */
167
if (size == bbuf->x && size == bbuf->y && xofs == 0 && yofs == 0)
168
memcpy(iimg->rect, bbuf->rect, size * size * sizeof(int));
170
/* this code assumes square images */
172
for (y = 0; y < size; y++) {
173
memcpy(&iimg->rect[y * size], &bbuf->rect[(y + yofs) * imgsize + xofs], size * sizeof(int));
169
177
di->data.buffer.image = iimg;
462
472
#ifndef WITH_HEADLESS
463
474
static void init_brush_icons(void)
466
#define INIT_BRUSH_ICON(icon_id, name) \
468
bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_ ##name## _png, \
469
datatoc_ ##name## _png_size, \
470
IB_rect, "<brush icon>"); \
471
def_internal_icon(bbuf, icon_id, 0, 0, w, ICON_TYPE_BUFFER); \
472
IMB_freeImBuf(bbuf); \
477
#define INIT_BRUSH_ICON(icon_id, name) \
479
unsigned char *rect = (unsigned char *)datatoc_ ##name## _png; \
480
int size = datatoc_ ##name## _png_size; \
483
di = def_internal_icon(NULL, icon_id, 0, 0, w, ICON_TYPE_BUFFER); \
484
di->data.buffer.image->datatoc_rect = rect; \
485
di->data.buffer.image->datatoc_size = size; \
474
487
/* end INIT_BRUSH_ICON */
489
const int w = 96; /* warning, brush size hardcoded in C, but it gets scaled */
479
491
INIT_BRUSH_ICON(ICON_BRUSH_ADD, add);
480
492
INIT_BRUSH_ICON(ICON_BRUSH_BLOB, blob);
509
522
#undef INIT_BRUSH_ICON
525
static void icon_verify_datatoc(IconImage *iimg)
527
/* if it has own rect, things are all OK */
531
if (iimg->datatoc_rect) {
532
ImBuf *bbuf = IMB_ibImageFromMemory(iimg->datatoc_rect,
533
iimg->datatoc_size, IB_rect, NULL, "<matcap icon>");
534
/* w and h were set on initialize */
535
if (bbuf->x != iimg->h && bbuf->y != iimg->w)
536
IMB_scaleImBuf(bbuf, iimg->w, iimg->h);
538
iimg->rect = bbuf->rect;
544
static void init_matcap_icons(void)
546
/* dynamic allocation now, tucking datatoc pointers in DrawInfo */
547
#define INIT_MATCAP_ICON(icon_id, name) \
549
unsigned char *rect = (unsigned char *)datatoc_ ##name## _jpg; \
550
int size = datatoc_ ##name## _jpg_size; \
553
di = def_internal_icon(NULL, icon_id, 0, 0, 96, ICON_TYPE_BUFFER); \
554
di->data.buffer.image->datatoc_rect = rect; \
555
di->data.buffer.image->datatoc_size = size; \
558
INIT_MATCAP_ICON(ICON_MATCAP_01, mc01);
559
INIT_MATCAP_ICON(ICON_MATCAP_02, mc02);
560
INIT_MATCAP_ICON(ICON_MATCAP_03, mc03);
561
INIT_MATCAP_ICON(ICON_MATCAP_04, mc04);
562
INIT_MATCAP_ICON(ICON_MATCAP_05, mc05);
563
INIT_MATCAP_ICON(ICON_MATCAP_06, mc06);
564
INIT_MATCAP_ICON(ICON_MATCAP_07, mc07);
565
INIT_MATCAP_ICON(ICON_MATCAP_08, mc08);
566
INIT_MATCAP_ICON(ICON_MATCAP_09, mc09);
567
INIT_MATCAP_ICON(ICON_MATCAP_10, mc10);
568
INIT_MATCAP_ICON(ICON_MATCAP_11, mc11);
569
INIT_MATCAP_ICON(ICON_MATCAP_12, mc12);
570
INIT_MATCAP_ICON(ICON_MATCAP_13, mc13);
571
INIT_MATCAP_ICON(ICON_MATCAP_14, mc14);
572
INIT_MATCAP_ICON(ICON_MATCAP_15, mc15);
573
INIT_MATCAP_ICON(ICON_MATCAP_16, mc16);
574
INIT_MATCAP_ICON(ICON_MATCAP_17, mc17);
575
INIT_MATCAP_ICON(ICON_MATCAP_18, mc18);
576
INIT_MATCAP_ICON(ICON_MATCAP_19, mc19);
577
INIT_MATCAP_ICON(ICON_MATCAP_20, mc20);
578
INIT_MATCAP_ICON(ICON_MATCAP_21, mc21);
579
INIT_MATCAP_ICON(ICON_MATCAP_22, mc22);
580
INIT_MATCAP_ICON(ICON_MATCAP_23, mc23);
581
INIT_MATCAP_ICON(ICON_MATCAP_24, mc24);
583
#undef INIT_MATCAP_ICON
512
587
static void init_internal_icons(void)
514
bTheme *btheme = UI_GetTheme();
589
// bTheme *btheme = UI_GetTheme();
590
ImBuf *b16buf = NULL, *b32buf = NULL;
516
591
int x, y, icontype;
517
char iconfilestr[FILE_MAX];
593
#if 0 // temp disabled
519
594
if ((btheme != NULL) && btheme->tui.iconfile[0]) {
520
595
char *icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
596
char iconfilestr[FILE_MAX];
522
599
BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile);
523
bbuf = IMB_loadiffname(iconfilestr, IB_rect); /* if the image is missing bbuf will just be NULL */
600
bbuf = IMB_loadiffname(iconfilestr, IB_rect, NULL); /* if the image is missing bbuf will just be NULL */
524
601
if (bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) {
525
602
printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr);
526
603
IMB_freeImBuf(bbuf);
531
608
printf("%s: 'icons' data path not found, continuing\n", __func__);
535
bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons_png, datatoc_blender_icons_png_size, IB_rect, "<blender icons>");
613
b16buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons16_png,
614
datatoc_blender_icons16_png_size, IB_rect, NULL, "<blender icons>");
616
IMB_premultiply_alpha(b16buf);
619
b32buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons32_png,
620
datatoc_blender_icons32_png_size, IB_rect, NULL, "<blender icons>");
622
IMB_premultiply_alpha(b32buf);
624
if (b16buf && b32buf) {
538
625
/* free existing texture if any */
539
626
if (icongltex.id) {
540
627
glDeleteTextures(1, &icongltex.id);
546
633
glGenTextures(1, &icongltex.id);
548
635
if (icongltex.id) {
549
icongltex.w = bbuf->x;
550
icongltex.h = bbuf->y;
551
icongltex.invw = 1.0f / bbuf->x;
552
icongltex.invh = 1.0f / bbuf->y;
638
icongltex.w = b32buf->x;
639
icongltex.h = b32buf->y;
640
icongltex.invw = 1.0f / b32buf->x;
641
icongltex.invh = 1.0f / b32buf->y;
554
643
glBindTexture(GL_TEXTURE_2D, icongltex.id);
555
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bbuf->x, bbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bbuf->rect);
556
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
645
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, b32buf->x, b32buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b32buf->rect);
646
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, b16buf->x, b16buf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, b16buf->rect);
648
while (b16buf->x > 1) {
649
ImBuf *nbuf = IMB_onehalf(b16buf);
650
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, nbuf->x, nbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nbuf->rect);
652
IMB_freeImBuf(b16buf);
656
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
557
657
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
558
659
glBindTexture(GL_TEXTURE_2D, 0);
560
661
if (glGetError() == GL_OUT_OF_MEMORY) {
561
662
glDeleteTextures(1, &icongltex.id);
562
663
icongltex.id = 0;
584
685
def_internal_vicon(VICO_VIEW3D_VEC, vicon_view3d_draw);
585
686
def_internal_vicon(VICO_EDIT_VEC, vicon_edit_draw);
586
def_internal_vicon(VICO_EDITMODE_DEHLT, vicon_editmode_dehlt_draw);
587
def_internal_vicon(VICO_EDITMODE_HLT, vicon_editmode_hlt_draw);
687
def_internal_vicon(VICO_EDITMODE_VEC_DEHLT, vicon_editmode_dehlt_draw);
688
def_internal_vicon(VICO_EDITMODE_VEC_HLT, vicon_editmode_hlt_draw);
588
689
def_internal_vicon(VICO_DISCLOSURE_TRI_RIGHT_VEC, vicon_disclosure_tri_right_draw);
589
690
def_internal_vicon(VICO_DISCLOSURE_TRI_DOWN_VEC, vicon_disclosure_tri_down_draw);
590
691
def_internal_vicon(VICO_MOVE_UP_VEC, vicon_move_up_draw);
859
966
prv_img->w[size], prv_img->h[size]);
862
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, unsigned int *rect, float alpha, const float rgb[3], short is_preview)
969
PreviewImage *UI_icon_to_preview(int icon_id)
971
Icon *icon = BKE_icon_get(icon_id);
974
DrawInfo *di = (DrawInfo *)icon->drawinfo;
975
if (di && di->data.buffer.image) {
978
bbuf = IMB_ibImageFromMemory(di->data.buffer.image->datatoc_rect, di->data.buffer.image->datatoc_size, IB_rect, NULL, "<matcap buffer>");
980
PreviewImage *prv = BKE_previewimg_create();
982
prv->rect[0] = bbuf->rect;
997
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh,
998
unsigned int *rect, float alpha, const float rgb[3], short is_preview)
864
1000
ImBuf *ima = NULL;
915
static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy, int UNUSED(iw), int ih, float alpha, const float rgb[3])
1051
static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy,
1052
int UNUSED(iw), int ih, float alpha, const float rgb[3])
917
1054
float x1, x2, y1, y2;
919
1056
if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
920
else glColor4f(1.0f, 1.0f, 1.0f, alpha);
1057
else glColor4f(alpha, alpha, alpha, alpha);
922
1059
x1 = ix * icongltex.invw;
923
1060
x2 = (ix + ih) * icongltex.invw;
958
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, int UNUSED(nocreate), short is_preview)
1102
static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, const float rgb[3],
1103
enum eIconSizes size, int draw_size, int UNUSED(nocreate), short is_preview)
960
1105
bTheme *btheme = UI_GetTheme();
961
1106
Icon *icon = NULL;
962
1107
DrawInfo *di = NULL;
963
1108
IconImage *iimg;
964
float fdraw_size = is_preview ? draw_size : (draw_size * UI_DPI_ICON_FAC);
1109
const float fdraw_size = (float)draw_size;
967
1112
icon = BKE_icon_get(icon_id);
989
1134
if (di->type == ICON_TYPE_VECTOR) {
990
1135
/* vector icons use the uiBlock transformation, they are not drawn
991
1136
* with untransformed coordinates like the other icons */
992
di->data.vector.func((int)x, (int)y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f);
1137
di->data.vector.func((int)x, (int)y, w, h, 1.0f);
994
1139
else if (di->type == ICON_TYPE_TEXTURE) {
1140
/* texture image use premul alpha for correct scaling */
1141
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
995
1142
icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y,
996
1143
di->data.texture.w, di->data.texture.h, alpha, rgb);
1144
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
998
1146
else if (di->type == ICON_TYPE_BUFFER) {
999
/* it is a builtin icon */
1147
/* it is a builtin icon */
1000
1148
iimg = di->data.buffer.image;
1149
#ifndef WITH_HEADLESS
1150
icon_verify_datatoc(iimg);
1002
1152
if (!iimg->rect) return; /* something has gone wrong! */
1154
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1004
1155
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview);
1156
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1006
1158
else if (di->type == ICON_TYPE_PREVIEW) {
1007
1159
PreviewImage *pi = BKE_previewimg_get((ID *)icon->obj);
1010
1162
/* no create icon on this level in code */
1011
1163
if (!pi->rect[size]) return; /* something has gone wrong! */
1292
int UI_rnaptr_icon_get(bContext *C, PointerRNA *ptr, int rnaicon, int big)
1299
/* try ID, material, texture or dynapaint slot */
1300
if (RNA_struct_is_ID(ptr->type)) {
1303
else if (RNA_struct_is_a(ptr->type, &RNA_MaterialSlot)) {
1304
id = RNA_pointer_get(ptr, "material").data;
1306
else if (RNA_struct_is_a(ptr->type, &RNA_TextureSlot)) {
1307
id = RNA_pointer_get(ptr, "texture").data;
1309
else if (RNA_struct_is_a(ptr->type, &RNA_DynamicPaintSurface)) {
1310
DynamicPaintSurface *surface = (DynamicPaintSurface *)ptr->data;
1312
if (surface->format == MOD_DPAINT_SURFACE_F_PTEX)
1313
return ICON_TEXTURE_SHADED;
1314
else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX)
1315
return ICON_OUTLINER_DATA_MESH;
1316
else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ)
1317
return ICON_FILE_IMAGE;
1320
/* get icon from ID */
1322
int icon = ui_id_icon_get(C, id, big);
1324
return icon ? icon : rnaicon;
1140
1330
static void icon_draw_at_size(float x, float y, int icon_id, float aspect, float alpha, enum eIconSizes size, int nocreate)
1142
1332
int draw_size = get_draw_size(size);
1154
1344
icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, FALSE, FALSE);
1347
/* draws icon with dpi scale factor */
1157
1348
void UI_icon_draw(float x, float y, int icon_id)
1159
UI_icon_draw_aspect(x, y, icon_id, 1.0f, 1.0f);
1350
UI_icon_draw_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f);
1162
1353
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)