137
143
new_icon = MEM_callocN(sizeof(Icon), "texicon");
139
new_icon->obj = 0; /* icon is not for library object */
145
new_icon->obj = NULL; /* icon is not for library object */
140
146
new_icon->type = 0;
142
148
di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
145
if(type == ICON_TYPE_TEXTURE) {
146
di->data.texture.x= xofs;
147
di->data.texture.y= yofs;
148
di->data.texture.w= size;
149
di->data.texture.h= size;
151
if (type == ICON_TYPE_TEXTURE) {
152
di->data.texture.x = xofs;
153
di->data.texture.y = yofs;
154
di->data.texture.w = size;
155
di->data.texture.h = size;
151
else if(type == ICON_TYPE_BUFFER) {
157
else if (type == ICON_TYPE_BUFFER) {
152
158
iimg = MEM_mallocN(sizeof(IconImage), "icon_img");
153
iimg->rect = MEM_mallocN(size*size*sizeof(unsigned int), "icon_rect");
159
iimg->rect = MEM_mallocN(size * size * sizeof(unsigned int), "icon_rect");
157
163
/* Here we store the rect in the icon - same as before */
158
164
imgsize = bbuf->x;
159
for (y=0; y<size; y++) {
160
memcpy(&iimg->rect[y*size], &bbuf->rect[(y+yofs)*imgsize+xofs], size*sizeof(int));
165
for (y = 0; y < size; y++) {
166
memcpy(&iimg->rect[y * size], &bbuf->rect[(y + yofs) * imgsize + xofs], size * sizeof(int));
163
169
di->data.buffer.image = iimg;
211
static void viconutil_draw_lineloop(GLint (*pts)[2], int numPoints)
217
static void viconutil_draw_lineloop(GLint(*pts)[2], int numPoints)
215
221
glBegin(GL_LINE_LOOP);
216
for (i=0; i<numPoints; i++) {
222
for (i = 0; i < numPoints; i++) {
217
223
glVertex2iv(pts[i]);
222
static void viconutil_draw_lineloop_smooth(GLint (*pts)[2], int numPoints)
228
static void viconutil_draw_lineloop_smooth(GLint(*pts)[2], int numPoints)
224
230
glEnable(GL_LINE_SMOOTH);
225
231
viconutil_draw_lineloop(pts, numPoints);
226
232
glDisable(GL_LINE_SMOOTH);
229
static void viconutil_draw_points(GLint (*pts)[2], int numPoints, int pointSize)
235
static void viconutil_draw_points(GLint(*pts)[2], int numPoints, int pointSize)
233
239
glBegin(GL_QUADS);
234
for (i=0; i<numPoints; i++) {
240
for (i = 0; i < numPoints; i++) {
235
241
int x = pts[i][0], y = pts[i][1];
237
glVertex2i(x-pointSize,y-pointSize);
238
glVertex2i(x+pointSize,y-pointSize);
239
glVertex2i(x+pointSize,y+pointSize);
240
glVertex2i(x-pointSize,y+pointSize);
243
glVertex2i(x - pointSize, y - pointSize);
244
glVertex2i(x + pointSize, y - pointSize);
245
glVertex2i(x + pointSize, y + pointSize);
246
glVertex2i(x - pointSize, y + pointSize);
245
/* Drawing functions */
251
/* Drawing functions */
247
253
static void vicon_x_draw(int x, int y, int w, int h, float alpha)
417
423
viconutil_draw_lineloop_smooth(pts, 3);
420
static void vicon_move_up_draw(int x, int y, int w, int h, float alpha)
424
glEnable(GL_LINE_SMOOTH);
426
glColor3f(0.0, 0.0, 0.0);
428
glBegin(GL_LINE_STRIP);
429
glVertex2i(x+w/2-d*2, y+h/2+d);
430
glVertex2i(x+w/2, y+h/2-d + 1);
431
glVertex2i(x+w/2+d*2, y+h/2+d);
435
glDisable(GL_LINE_SMOOTH);
438
static void vicon_move_down_draw(int x, int y, int w, int h, float alpha)
442
glEnable(GL_LINE_SMOOTH);
444
glColor3f(0.0, 0.0, 0.0);
446
glBegin(GL_LINE_STRIP);
447
glVertex2i(x+w/2-d*2, y+h/2+d);
448
glVertex2i(x+w/2, y+h/2-d - 1);
449
glVertex2i(x+w/2+d*2, y+h/2+d);
453
glDisable(GL_LINE_SMOOTH);
456
static void init_internal_icons()
458
bTheme *btheme= U.themes.first;
426
static void vicon_move_up_draw(int x, int y, int w, int h, float UNUSED(alpha))
430
glEnable(GL_LINE_SMOOTH);
432
glColor3f(0.0, 0.0, 0.0);
434
glBegin(GL_LINE_STRIP);
435
glVertex2i(x + w / 2 - d * 2, y + h / 2 + d);
436
glVertex2i(x + w / 2, y + h / 2 - d + 1);
437
glVertex2i(x + w / 2 + d * 2, y + h / 2 + d);
441
glDisable(GL_LINE_SMOOTH);
444
static void vicon_move_down_draw(int x, int y, int w, int h, float UNUSED(alpha))
448
glEnable(GL_LINE_SMOOTH);
450
glColor3f(0.0, 0.0, 0.0);
452
glBegin(GL_LINE_STRIP);
453
glVertex2i(x + w / 2 - d * 2, y + h / 2 + d);
454
glVertex2i(x + w / 2, y + h / 2 - d - 1);
455
glVertex2i(x + w / 2 + d * 2, y + h / 2 + d);
459
glDisable(GL_LINE_SMOOTH);
462
#ifndef WITH_HEADLESS
463
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); \
474
/* end INIT_BRUSH_ICON */
479
INIT_BRUSH_ICON(ICON_BRUSH_ADD, add);
480
INIT_BRUSH_ICON(ICON_BRUSH_BLOB, blob);
481
INIT_BRUSH_ICON(ICON_BRUSH_BLUR, blur);
482
INIT_BRUSH_ICON(ICON_BRUSH_CLAY, clay);
483
INIT_BRUSH_ICON(ICON_BRUSH_CLAY_STRIPS, claystrips);
484
INIT_BRUSH_ICON(ICON_BRUSH_CLONE, clone);
485
INIT_BRUSH_ICON(ICON_BRUSH_CREASE, crease);
486
INIT_BRUSH_ICON(ICON_BRUSH_DARKEN, darken);
487
INIT_BRUSH_ICON(ICON_BRUSH_SCULPT_DRAW, draw);
488
INIT_BRUSH_ICON(ICON_BRUSH_FILL, fill);
489
INIT_BRUSH_ICON(ICON_BRUSH_FLATTEN, flatten);
490
INIT_BRUSH_ICON(ICON_BRUSH_GRAB, grab);
491
INIT_BRUSH_ICON(ICON_BRUSH_INFLATE, inflate);
492
INIT_BRUSH_ICON(ICON_BRUSH_LAYER, layer);
493
INIT_BRUSH_ICON(ICON_BRUSH_LIGHTEN, lighten);
494
INIT_BRUSH_ICON(ICON_BRUSH_MIX, mix);
495
INIT_BRUSH_ICON(ICON_BRUSH_MULTIPLY, multiply);
496
INIT_BRUSH_ICON(ICON_BRUSH_NUDGE, nudge);
497
INIT_BRUSH_ICON(ICON_BRUSH_PINCH, pinch);
498
INIT_BRUSH_ICON(ICON_BRUSH_SCRAPE, scrape);
499
INIT_BRUSH_ICON(ICON_BRUSH_SMEAR, smear);
500
INIT_BRUSH_ICON(ICON_BRUSH_SMOOTH, smooth);
501
INIT_BRUSH_ICON(ICON_BRUSH_SNAKE_HOOK, snake_hook);
502
INIT_BRUSH_ICON(ICON_BRUSH_SOFTEN, soften);
503
INIT_BRUSH_ICON(ICON_BRUSH_SUBTRACT, subtract);
504
INIT_BRUSH_ICON(ICON_BRUSH_TEXDRAW, texdraw);
505
INIT_BRUSH_ICON(ICON_BRUSH_THUMB, thumb);
506
INIT_BRUSH_ICON(ICON_BRUSH_ROTATE, twist);
507
INIT_BRUSH_ICON(ICON_BRUSH_VERTEXDRAW, vertexdraw);
509
#undef INIT_BRUSH_ICON
512
static void init_internal_icons(void)
514
bTheme *btheme = UI_GetTheme();
460
516
int x, y, icontype;
461
char iconfilestr[FILE_MAXDIR+FILE_MAXFILE];
517
char iconfilestr[FILE_MAX];
463
if ((btheme!=NULL) && (strlen(btheme->tui.iconfile) > 0)) {
464
char *datadir= BLI_get_folder(BLENDER_DATAFILES, NULL);
466
BLI_make_file_string("/", iconfilestr, datadir, btheme->tui.iconfile);
468
if (BLI_exists(iconfilestr)) {
469
bbuf = IMB_loadiffname(iconfilestr, IB_rect);
470
if(bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H) {
472
printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr);
519
if ((btheme != NULL) && btheme->tui.iconfile[0]) {
520
char *icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
522
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 */
524
if (bbuf && (bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H)) {
525
printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr);
531
printf("%s: 'icons' data path not found, continuing\n", __func__);
480
bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
535
bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons_png, datatoc_blender_icons_png_size, IB_rect, "<blender icons>");
483
538
/* free existing texture if any */
485
540
glDeleteTextures(1, &icongltex.id);
489
544
/* we only use a texture for cards with non-power of two */
490
if(GPU_non_power_of_two_support()) {
545
if (GPU_non_power_of_two_support()) {
491
546
glGenTextures(1, &icongltex.id);
494
549
icongltex.w = bbuf->x;
495
550
icongltex.h = bbuf->y;
496
icongltex.invw = 1.0f/bbuf->x;
497
icongltex.invh = 1.0f/bbuf->y;
551
icongltex.invw = 1.0f / bbuf->x;
552
icongltex.invh = 1.0f / bbuf->y;
499
554
glBindTexture(GL_TEXTURE_2D, icongltex.id);
500
555
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bbuf->x, bbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bbuf->rect);
540
595
IMB_freeImBuf(bbuf);
597
#endif // WITH_HEADLESS
544
599
static void init_iconfile_list(struct ListBase *list)
548
602
struct direntry *dir;
549
603
int restoredir = 1; /* restore to current directory */
550
int totfile, i, index=1;
552
char icondirstr[FILE_MAX];
553
char iconfilestr[FILE_MAX+16]; /* allow 256 chars for file+dir */
604
int totfile, i, index = 1;
554
606
char olddir[FILE_MAX];
557
608
list->first = list->last = NULL;
558
datadir = BLI_get_folder(BLENDER_DATAFILES, NULL);
560
if (!datadir) return;
562
BLI_make_file_string("/", icondirstr, datadir, "");
564
if(BLI_exists(icondirstr)==0)
609
icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
567
/* since BLI_getdir changes the current working directory, restore it
568
back to old value afterwards */
569
if(!BLI_getwdN(olddir))
614
/* since BLI_dir_contents changes the current working directory, restore it
615
* back to old value afterwards */
616
if (!BLI_current_working_dir(olddir, sizeof(olddir)))
571
totfile = BLI_getdir(icondirstr, &dir);
618
totfile = BLI_dir_contents(icondir, &dir);
572
619
if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */
574
for(i=0; i<totfile; i++) {
575
if( (dir[i].type & S_IFREG) ) {
621
for (i = 0; i < totfile; i++) {
622
if ( (dir[i].type & S_IFREG) ) {
576
623
char *filename = dir[i].relname;
578
if(BLI_testextensie(filename, ".png")) {
625
if (BLI_testextensie(filename, ".png")) {
626
/* loading all icons on file start is overkill & slows startup
627
* its possible they change size after blender load anyway. */
630
char iconfilestr[FILE_MAX + 16]; /* allow 256 chars for file+dir */
580
632
/* check to see if the image is the right size, continue if not */
581
633
/* copying strings here should go ok, assuming that we never get back
582
a complete path to file longer than 256 chars */
583
sprintf(iconfilestr, "%s/%s", icondirstr, filename);
584
if(BLI_exists(iconfilestr)) bbuf = IMB_loadiffname(iconfilestr, IB_rect);
590
if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H))
634
* a complete path to file longer than 256 chars */
635
BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, filename);
636
bbuf = IMB_loadiffname(iconfilestr, IB_rect);
647
/* bad size or failed to load */
648
if ((ifilex != ICON_IMAGE_W) || (ifiley != ICON_IMAGE_H)) {
649
printf("icon '%s' is wrong size %dx%d\n", iconfilestr, ifilex, ifiley);
593
654
/* found a potential icon file, so make an entry for it in the cache list */
594
655
ifile = MEM_callocN(sizeof(IconFile), "IconFile");
738
804
void UI_icons_init(int first_dyn_id)
740
809
init_iconfile_list(&iconfilelist);
741
810
BKE_icons_init(first_dyn_id);
742
811
init_internal_icons();
745
/* Render size for preview images at level miplevel */
746
static int preview_render_size(int miplevel)
816
/* Render size for preview images and icons
818
static int preview_render_size(enum eIconSizes size)
750
case 1: return PREVIEW_DEFAULT_HEIGHT;
821
case ICON_SIZE_ICON: return 32;
822
case ICON_SIZE_PREVIEW: return PREVIEW_DEFAULT_HEIGHT;
755
static void icon_create_mipmap(struct PreviewImage* prv_img, int miplevel)
827
/* Create rect for the icon
829
static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size)
757
unsigned int size = preview_render_size(miplevel);
831
unsigned int render_size = preview_render_size(size);
761
printf("Error: requested preview image does not exist");
834
if (G.debug & G_DEBUG)
835
printf("%s, error: requested preview image does not exist", __func__);
763
if (!prv_img->rect[miplevel]) {
764
prv_img->w[miplevel] = size;
765
prv_img->h[miplevel] = size;
766
prv_img->changed[miplevel] = 1;
767
prv_img->changed_timestamp[miplevel] = 0;
768
prv_img->rect[miplevel] = MEM_callocN(size*size*sizeof(unsigned int), "prv_rect");
837
if (!prv_img->rect[size]) {
838
prv_img->w[size] = render_size;
839
prv_img->h[size] = render_size;
840
prv_img->changed[size] = 1;
841
prv_img->changed_timestamp[size] = 0;
842
prv_img->rect[size] = MEM_callocN(render_size * render_size * sizeof(unsigned int), "prv_rect");
772
846
/* only called when icon has changed */
773
847
/* only call with valid pointer from UI_icon_draw */
774
static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, int miplevel)
848
static void icon_set_image(bContext *C, ID *id, PreviewImage *prv_img, enum eIconSizes size)
778
printf("No preview image for this ID: %s\n", id->name);
851
if (G.debug & G_DEBUG)
852
printf("%s: no preview image for this ID: %s\n", __func__, id->name);
782
/* create the preview rect */
783
icon_create_mipmap(prv_img, miplevel);
856
icon_create_rect(prv_img, size);
785
ED_preview_icon_job(C, prv_img, id, prv_img->rect[miplevel],
786
prv_img->w[miplevel], prv_img->h[miplevel]);
858
ED_preview_icon_job(C, prv_img, id, prv_img->rect[size],
859
prv_img->w[size], prv_img->h[size]);
789
static void icon_draw_rect(float x, float y, int w, int h, float aspect, int rw, int rh, unsigned int *rect, float alpha, float *rgb)
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)
867
if (w <= 0 || h <= 0 || w > 2000 || h > 2000) {
868
printf("%s: icons are %i x %i pixels?\n", __func__, w, h);
869
BLI_assert(!"invalid icon size");
791
873
/* modulate color */
793
875
glPixelTransferf(GL_ALPHA_SCALE, alpha);
796
878
glPixelTransferf(GL_RED_SCALE, rgb[0]);
797
879
glPixelTransferf(GL_GREEN_SCALE, rgb[1]);
798
880
glPixelTransferf(GL_BLUE_SCALE, rgb[2]);
803
// XXX ui_rasterpos_safe(x, y, aspect);
883
/* rect contains image in 'rendersize', we only scale if needed */
884
if (rw != w && rh != h) {
885
/* first allocate imbuf for scaling and copy preview into it */
886
ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
887
memcpy(ima->rect, rect, rw * rh * sizeof(unsigned int));
888
IMB_scaleImBuf(ima, w, h); /* scale it */
807
// XXX - TODO 2.5 verify whether this case can happen
809
printf("what the heck! - icons are %i x %i pixels?\n", w, h);
811
/* rect contains image in 'rendersize', we only scale if needed */
812
else if(rw!=w && rh!=h) {
813
if(w>2000 || h>2000) { /* something has gone wrong! */
815
printf("insane icon size w=%d h=%d\n",w,h);
820
/* first allocate imbuf for scaling and copy preview into it */
821
ima = IMB_allocImBuf(rw, rh, 32, IB_rect, 0);
822
memcpy(ima->rect, rect, rw*rh*sizeof(unsigned int));
825
IMB_scaleImBuf(ima, w, h);
826
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
894
glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
832
898
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect);
834
904
/* restore color */
836
906
glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
839
909
glPixelTransferf(GL_RED_SCALE, 1.0f);
840
910
glPixelTransferf(GL_GREEN_SCALE, 1.0f);
841
911
glPixelTransferf(GL_BLUE_SCALE, 1.0f);
845
static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy, int iw, int ih, float alpha, float *rgb)
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])
847
917
float x1, x2, y1, y2;
849
if(rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
919
if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
850
920
else glColor4f(1.0f, 1.0f, 1.0f, alpha);
852
x1= ix*icongltex.invw;
853
x2= (ix + ih)*icongltex.invw;
854
y1= iy*icongltex.invh;
855
y2= (iy + ih)*icongltex.invh;
922
x1 = ix * icongltex.invw;
923
x2 = (ix + ih) * icongltex.invw;
924
y1 = iy * icongltex.invh;
925
y2 = (iy + ih) * icongltex.invh;
857
927
glEnable(GL_TEXTURE_2D);
858
928
glBindTexture(GL_TEXTURE_2D, icongltex.id);
862
932
glVertex2f(x, y);
864
934
glTexCoord2f(x2, y1);
935
glVertex2f(x + w, y);
867
937
glTexCoord2f(x2, y2);
868
glVertex2f(x+w, y+h);
938
glVertex2f(x + w, y + h);
870
940
glTexCoord2f(x1, y2);
941
glVertex2f(x, y + h);
874
944
glBindTexture(GL_TEXTURE_2D, 0);
875
945
glDisable(GL_TEXTURE_2D);
878
/* Drawing size for preview images at level miplevel */
879
static int preview_size(int miplevel)
948
/* Drawing size for preview images */
949
static int get_draw_size(enum eIconSizes size)
882
case 0: return ICON_DEFAULT_HEIGHT;
883
case 1: return PREVIEW_DEFAULT_HEIGHT;
952
case ICON_SIZE_ICON: return ICON_DEFAULT_HEIGHT;
953
case ICON_SIZE_PREVIEW: return PREVIEW_DEFAULT_HEIGHT;
888
static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, int miplevel, int draw_size, int nocreate)
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)
960
bTheme *btheme = UI_GetTheme();
890
961
Icon *icon = NULL;
891
962
DrawInfo *di = NULL;
964
float fdraw_size = is_preview ? draw_size : (draw_size * UI_DPI_ICON_FAC);
895
967
icon = BKE_icon_get(icon_id);
968
alpha *= btheme->tui.icon_alpha;
899
printf("icon_draw_mipmap: Internal error, no icon for icon ID: %d\n", icon_id);
971
if (G.debug & G_DEBUG)
972
printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
903
di = (DrawInfo*)icon->drawinfo;
976
di = (DrawInfo *)icon->drawinfo;
906
979
di = icon_create_drawinfo();
912
985
/* scale width and height according to aspect */
913
w = (int)(draw_size/aspect + 0.5f);
914
h = (int)(draw_size/aspect + 0.5f);
986
w = (int)(fdraw_size / aspect + 0.5f);
987
h = (int)(fdraw_size / aspect + 0.5f);
916
if(di->type == ICON_TYPE_VECTOR) {
989
if (di->type == ICON_TYPE_VECTOR) {
917
990
/* vector icons use the uiBlock transformation, they are not drawn
918
with untransformed coordinates like the other icons */
919
di->data.vector.func(x, y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f);
991
* with untransformed coordinates like the other icons */
992
di->data.vector.func((int)x, (int)y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f);
921
else if(di->type == ICON_TYPE_TEXTURE) {
922
icon_draw_texture(x, y, w, h, di->data.texture.x, di->data.texture.y,
923
di->data.texture.w, di->data.texture.h, alpha, rgb);
994
else if (di->type == ICON_TYPE_TEXTURE) {
995
icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y,
996
di->data.texture.w, di->data.texture.h, alpha, rgb);
925
else if(di->type == ICON_TYPE_BUFFER) {
998
else if (di->type == ICON_TYPE_BUFFER) {
926
999
/* it is a builtin icon */
927
iimg= di->data.buffer.image;
929
if(!iimg->rect) return; /* something has gone wrong! */
931
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb);
1000
iimg = di->data.buffer.image;
1002
if (!iimg->rect) return; /* something has gone wrong! */
1004
icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview);
933
else if(di->type == ICON_TYPE_PREVIEW) {
934
PreviewImage* pi = BKE_previewimg_get((ID*)icon->obj);
1006
else if (di->type == ICON_TYPE_PREVIEW) {
1007
PreviewImage *pi = BKE_previewimg_get((ID *)icon->obj);
937
1010
/* no create icon on this level in code */
938
if(!pi->rect[miplevel]) return; /* something has gone wrong! */
1011
if (!pi->rect[size]) return; /* something has gone wrong! */
940
1013
/* preview images use premul alpha ... */
941
1014
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
942
icon_draw_rect(x, y, w, h, aspect, pi->w[miplevel], pi->h[miplevel], pi->rect[miplevel], 1.0f, NULL);
1015
icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], 1.0f, NULL, is_preview);
943
1016
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
948
void ui_id_icon_render(bContext *C, ID *id, int preview)
1021
static void ui_id_preview_image_render_size(bContext *C, ID *id, PreviewImage *pi, int size)
1023
if ((pi->changed[size] || !pi->rect[size])) { /* changed only ever set by dynamic icons */
1024
/* create the rect if necessary */
1025
icon_set_image(C, id, pi, size);
1027
pi->changed[size] = 0;
1031
static void ui_id_icon_render(bContext *C, ID *id, int big)
1033
PreviewImage *pi = BKE_previewimg_get(id);
1037
ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_PREVIEW); /* bigger preview size */
1039
ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_ICON); /* icon size */
1043
static void ui_id_brush_render(bContext *C, ID *id)
950
1045
PreviewImage *pi = BKE_previewimg_get(id);
953
if ((pi->changed[0] ||!pi->rect[0])) /* changed only ever set by dynamic icons */
1051
for (i = 0; i < NUM_ICON_SIZES; i++) {
1052
/* check if rect needs to be created; changed
1053
* only set by dynamic icons */
1054
if ((pi->changed[i] || !pi->rect[i])) {
1055
icon_set_image(C, id, pi, i);
1062
static int ui_id_brush_get_icon(bContext *C, ID *id)
1064
Brush *br = (Brush *)id;
1066
if (br->flag & BRUSH_CUSTOM_ICON) {
1068
ui_id_brush_render(C, id);
1071
Object *ob = CTX_data_active_object(C);
1073
EnumPropertyItem *items = NULL;
1076
/* XXX: this is not nice, should probably make brushes
1077
* be strictly in one paint mode only to avoid
1078
* checking various context stuff here */
1080
if (CTX_wm_view3d(C) && ob) {
1081
if (ob->mode & OB_MODE_SCULPT)
1082
mode = OB_MODE_SCULPT;
1083
else if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT))
1084
mode = OB_MODE_VERTEX_PAINT;
1085
else if (ob->mode & OB_MODE_TEXTURE_PAINT)
1086
mode = OB_MODE_TEXTURE_PAINT;
1088
else if ((sima = CTX_wm_space_image(C)) &&
1089
(sima->flag & SI_DRAWTOOL))
955
/* create the preview rect if necessary */
957
icon_set_image(C, id, pi, 0); /* icon size */
959
icon_set_image(C, id, pi, 1); /* preview size */
1091
mode = OB_MODE_TEXTURE_PAINT;
1094
/* reset the icon */
1095
if (mode == OB_MODE_SCULPT) {
1096
items = brush_sculpt_tool_items;
1097
tool = br->sculpt_tool;
1099
else if (mode == OB_MODE_VERTEX_PAINT) {
1100
items = brush_vertex_tool_items;
1101
tool = br->vertexpaint_tool;
1103
else if (mode == OB_MODE_TEXTURE_PAINT) {
1104
items = brush_image_tool_items;
1105
tool = br->imagepaint_tool;
1108
if (!items || !RNA_enum_icon_from_value(items, tool, &id->icon_id))
966
int ui_id_icon_get(bContext *C, ID *id, int preview)
1115
int ui_id_icon_get(bContext *C, ID *id, int big)
1120
switch (GS(id->name)) {
1122
iconid = ui_id_brush_get_icon(C, id);
973
1124
case ID_MA: /* fall through */
974
1125
case ID_TE: /* fall through */
975
1126
case ID_IM: /* fall through */
976
1127
case ID_WO: /* fall through */
977
1128
case ID_LA: /* fall through */
978
case ID_BR: /* fall through */
979
iconid= BKE_icon_getid(id);
1129
iconid = BKE_icon_getid(id);
980
1130
/* checks if not exists, or changed */
981
ui_id_icon_render(C, id, preview);
1131
ui_id_icon_render(C, id, big);
990
static void icon_draw_mipmap(float x, float y, int icon_id, float aspect, float alpha, int miplevel, int nocreate)
1140
static void icon_draw_at_size(float x, float y, int icon_id, float aspect, float alpha, enum eIconSizes size, int nocreate)
992
int draw_size = preview_size(miplevel);
993
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, miplevel, draw_size, nocreate);
1142
int draw_size = get_draw_size(size);
1143
icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, nocreate, FALSE);
996
1146
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha)
998
icon_draw_mipmap(x, y, icon_id, aspect, alpha, PREVIEW_MIPMAP_ZERO, 0);
1148
icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0);
1001
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, float *rgb)
1151
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3])
1003
int draw_size = preview_size(PREVIEW_MIPMAP_ZERO);
1004
icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, PREVIEW_MIPMAP_ZERO, draw_size, 0);
1153
int draw_size = get_draw_size(ICON_SIZE_ICON);
1154
icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, FALSE, FALSE);
1007
1157
void UI_icon_draw(float x, float y, int icon_id)
1012
1162
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)
1014
icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, 0, size, 1);
1164
icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, TRUE, FALSE);
1017
1167
void UI_icon_draw_preview(float x, float y, int icon_id)
1019
icon_draw_mipmap(x, y, icon_id, 1.0f, 1.0f, PREVIEW_MIPMAP_LARGE, 0);
1169
icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, 0);
1022
1172
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect)
1024
icon_draw_mipmap(x, y, icon_id, aspect, 1.0f, PREVIEW_MIPMAP_LARGE, 0);
1174
icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, 0);
1027
1177
void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspect, int size)
1029
icon_draw_size(x, y, icon_id, aspect, 1.0f, NULL, PREVIEW_MIPMAP_LARGE, size, 0);
1179
icon_draw_size(x, y, icon_id, aspect, 1.0f, NULL, ICON_SIZE_PREVIEW, size, FALSE, TRUE);