~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/interface/interface_icons.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include "BLI_utildefines.h"
50
50
 
51
51
#include "DNA_brush_types.h"
 
52
#include "DNA_dynamicpaint_types.h"
52
53
#include "DNA_object_types.h"
53
54
#include "DNA_screen_types.h"
54
55
#include "DNA_space_types.h"
59
60
#include "BKE_context.h"
60
61
#include "BKE_global.h"
61
62
#include "BKE_icons.h"
62
 
#include "BKE_utildefines.h"
63
63
 
64
64
#include "IMB_imbuf.h"
65
65
#include "IMB_imbuf_types.h"
75
75
 
76
76
#include "interface_intern.h"
77
77
 
78
 
 
79
 
#define ICON_IMAGE_W        600
80
 
#define ICON_IMAGE_H        640
81
 
 
82
78
#define ICON_GRID_COLS      26
83
79
#define ICON_GRID_ROWS      30
84
80
 
85
 
#define ICON_GRID_MARGIN    5
86
 
#define ICON_GRID_W         16
87
 
#define ICON_GRID_H         16
 
81
#define ICON_GRID_MARGIN    10
 
82
#define ICON_GRID_W         32
 
83
#define ICON_GRID_H         32
88
84
 
89
85
typedef struct IconImage {
90
86
        int w;
91
87
        int h;
92
 
        unsigned int *rect; 
 
88
        unsigned int *rect;
 
89
        unsigned char *datatoc_rect;
 
90
        int datatoc_size;
93
91
} IconImage;
94
92
 
95
93
typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
132
130
 
133
131
/* **************************************************** */
134
132
 
135
 
static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type)
 
133
#ifndef WITH_HEADLESS
 
134
 
 
135
static DrawInfo *def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type)
136
136
{
137
137
        Icon *new_icon = NULL;
138
138
        IconImage *iimg = NULL;
139
139
        DrawInfo *di;
140
 
        int y = 0;
141
 
        int imgsize = 0;
142
140
 
143
141
        new_icon = MEM_callocN(sizeof(Icon), "texicon");
144
142
 
145
143
        new_icon->obj = NULL; /* icon is not for library object */
146
 
        new_icon->type = 0;     
 
144
        new_icon->type = 0;
147
145
 
148
146
        di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
149
147
        di->type = type;
155
153
                di->data.texture.h = size;
156
154
        }
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");
160
157
                iimg->w = size;
161
158
                iimg->h = size;
162
159
 
163
 
                /* Here we store the rect in the icon - same as before */
164
 
                imgsize = bbuf->x;
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 */
 
161
                if (bbuf) {
 
162
                        int y, imgsize;
 
163
                        
 
164
                        iimg->rect = MEM_mallocN(size * size * sizeof(unsigned int), "icon_rect");
 
165
                        
 
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));
 
169
                        else {
 
170
                                /* this code assumes square images */
 
171
                                imgsize = bbuf->x;
 
172
                                for (y = 0; y < size; y++) {
 
173
                                        memcpy(&iimg->rect[y * size], &bbuf->rect[(y + yofs) * imgsize + xofs], size * sizeof(int));
 
174
                                }
 
175
                        }
167
176
                }
168
 
 
169
177
                di->data.buffer.image = iimg;
170
178
        }
171
179
 
173
181
        new_icon->drawinfo = di;
174
182
 
175
183
        BKE_icon_set(icon_id, new_icon);
 
184
        
 
185
        return di;
176
186
}
177
187
 
178
188
static void def_internal_vicon(int icon_id, VectorDrawFunc drawFunc)
347
357
        glColor4f(0.0f, 0.0f, 0.0f, 1);
348
358
        viconutil_draw_lineloop_smooth(pts, 3);
349
359
 
350
 
        glColor3f(.9f, .9f, .9f);
 
360
        glColor3f(0.9f, 0.9f, 0.9f);
351
361
        viconutil_draw_points(pts, 3, 1);
352
362
}
353
363
 
460
470
}
461
471
 
462
472
#ifndef WITH_HEADLESS
 
473
 
463
474
static void init_brush_icons(void)
464
475
{
465
476
 
466
 
#define INIT_BRUSH_ICON(icon_id, name)                                        \
467
 
        {                                                                         \
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);                                                  \
473
 
        } (void)0
 
477
#define INIT_BRUSH_ICON(icon_id, name)                                          \
 
478
        {                                                                           \
 
479
                unsigned char *rect = (unsigned char *)datatoc_ ##name## _png;                  \
 
480
                int size = datatoc_ ##name## _png_size;                                                                 \
 
481
                DrawInfo *di;                                                                                                                   \
 
482
                \
 
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;                                                             \
 
486
        }
474
487
        /* end INIT_BRUSH_ICON */
475
488
 
476
 
        ImBuf *bbuf;
477
 
        const int w = 96;
 
489
        const int w = 96; /* warning, brush size hardcoded in C, but it gets scaled */
478
490
 
479
491
        INIT_BRUSH_ICON(ICON_BRUSH_ADD, add);
480
492
        INIT_BRUSH_ICON(ICON_BRUSH_BLOB, blob);
491
503
        INIT_BRUSH_ICON(ICON_BRUSH_INFLATE, inflate);
492
504
        INIT_BRUSH_ICON(ICON_BRUSH_LAYER, layer);
493
505
        INIT_BRUSH_ICON(ICON_BRUSH_LIGHTEN, lighten);
 
506
        INIT_BRUSH_ICON(ICON_BRUSH_MASK, mask);
494
507
        INIT_BRUSH_ICON(ICON_BRUSH_MIX, mix);
495
508
        INIT_BRUSH_ICON(ICON_BRUSH_MULTIPLY, multiply);
496
509
        INIT_BRUSH_ICON(ICON_BRUSH_NUDGE, nudge);
509
522
#undef INIT_BRUSH_ICON
510
523
}
511
524
 
 
525
static void icon_verify_datatoc(IconImage *iimg)
 
526
{
 
527
        /* if it has own rect, things are all OK */
 
528
        if (iimg->rect)
 
529
                return;
 
530
        
 
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);
 
537
                
 
538
                iimg->rect = bbuf->rect;
 
539
                bbuf->rect = NULL;
 
540
                IMB_freeImBuf(bbuf);
 
541
        }
 
542
}
 
543
 
 
544
static void init_matcap_icons(void)
 
545
{
 
546
        /* dynamic allocation now, tucking datatoc pointers in DrawInfo */
 
547
#define INIT_MATCAP_ICON(icon_id, name)                                       \
 
548
        {                                                                         \
 
549
                unsigned char *rect = (unsigned char *)datatoc_ ##name## _jpg;        \
 
550
                int size = datatoc_ ##name## _jpg_size;                               \
 
551
                DrawInfo *di;                                                         \
 
552
                                                                                      \
 
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;                           \
 
556
        } (void)0
 
557
 
 
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);
 
582
 
 
583
#undef INIT_MATCAP_ICON
 
584
 
 
585
}
 
586
 
512
587
static void init_internal_icons(void)
513
588
{
514
 
        bTheme *btheme = UI_GetTheme();
515
 
        ImBuf *bbuf = NULL;
 
589
//      bTheme *btheme = UI_GetTheme();
 
590
        ImBuf *b16buf = NULL, *b32buf = NULL;
516
591
        int x, y, icontype;
517
 
        char iconfilestr[FILE_MAX];
518
 
        
 
592
 
 
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];
 
597
                
521
598
                if (icondir) {
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__);
532
609
                }
533
610
        }
534
 
        if (bbuf == NULL)
535
 
                bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons_png, datatoc_blender_icons_png_size, IB_rect, "<blender icons>");
 
611
#endif
 
612
        if (b16buf == NULL)
 
613
                b16buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons16_png,
 
614
                                             datatoc_blender_icons16_png_size, IB_rect, NULL, "<blender icons>");
 
615
        if (b16buf)
 
616
                IMB_premultiply_alpha(b16buf);
536
617
 
537
 
        if (bbuf) {
 
618
        if (b32buf == NULL)
 
619
                b32buf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons32_png,
 
620
                                             datatoc_blender_icons32_png_size, IB_rect, NULL, "<blender icons>");
 
621
        if (b32buf)
 
622
                IMB_premultiply_alpha(b32buf);
 
623
        
 
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);
547
634
 
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;
 
636
                                int level = 2;
 
637
                                
 
638
                                icongltex.w = b32buf->x;
 
639
                                icongltex.h = b32buf->y;
 
640
                                icongltex.invw = 1.0f / b32buf->x;
 
641
                                icongltex.invh = 1.0f / b32buf->y;
553
642
 
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);
 
644
                                
 
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);
 
647
                                
 
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);
 
651
                                        level++;
 
652
                                        IMB_freeImBuf(b16buf);
 
653
                                        b16buf = nbuf;
 
654
                                }
 
655
                                
 
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);
 
658
                                
558
659
                                glBindTexture(GL_TEXTURE_2D, 0);
559
 
 
 
660
                                
560
661
                                if (glGetError() == GL_OUT_OF_MEMORY) {
561
662
                                        glDeleteTextures(1, &icongltex.id);
562
663
                                        icongltex.id = 0;
570
671
        else
571
672
                icontype = ICON_TYPE_BUFFER;
572
673
        
573
 
        if (bbuf) {
 
674
        if (b32buf) {
574
675
                for (y = 0; y < ICON_GRID_ROWS; y++) {
575
676
                        for (x = 0; x < ICON_GRID_COLS; x++) {
576
 
                                def_internal_icon(bbuf, BIFICONID_FIRST + y * ICON_GRID_COLS + x,
 
677
                                def_internal_icon(b32buf, BIFICONID_FIRST + y * ICON_GRID_COLS + x,
577
678
                                                  x * (ICON_GRID_W + ICON_GRID_MARGIN) + ICON_GRID_MARGIN,
578
679
                                                  y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W,
579
680
                                                  icontype);
583
684
 
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);
592
693
        def_internal_vicon(VICO_X_VEC, vicon_x_draw);
593
694
        def_internal_vicon(VICO_SMALL_TRI_RIGHT_VEC, vicon_small_tri_right_draw);
594
695
 
595
 
        IMB_freeImBuf(bbuf);
 
696
        IMB_freeImBuf(b16buf);
 
697
        IMB_freeImBuf(b32buf);
 
698
        
596
699
}
597
 
#endif // WITH_HEADLESS
 
700
#endif  /* WITH_HEADLESS */
598
701
 
599
702
static void init_iconfile_list(struct ListBase *list)
600
703
{
619
722
        if (restoredir && !chdir(olddir)) {} /* fix warning about checking return value */
620
723
 
621
724
        for (i = 0; i < totfile; i++) {
622
 
                if ( (dir[i].type & S_IFREG) ) {
 
725
                if ((dir[i].type & S_IFREG)) {
623
726
                        char *filename = dir[i].relname;
624
727
                        
625
728
                        if (BLI_testextensie(filename, ".png")) {
688
791
        }
689
792
}
690
793
 
 
794
#endif  /* WITH_HEADLESS */
 
795
 
691
796
int UI_iconfile_get_index(const char *filename)
692
797
{
693
798
        IconFile *ifile;
730
835
        if (di) {
731
836
                if (di->type == ICON_TYPE_BUFFER) {
732
837
                        if (di->data.buffer.image) {
733
 
                                MEM_freeN(di->data.buffer.image->rect);
 
838
                                if (di->data.buffer.image->rect)
 
839
                                        MEM_freeN(di->data.buffer.image->rect);
734
840
                                MEM_freeN(di->data.buffer.image);
735
841
                        }
736
842
                }
749
855
        return di;
750
856
}
751
857
 
752
 
/* note!, returns unscaled by DPI, may need to multiply result by UI_DPI_ICON_FAC */
 
858
/* note!, returns unscaled by DPI */
753
859
int UI_icon_get_width(int icon_id)
754
860
{
755
861
        Icon *icon = NULL;
810
916
        BKE_icons_init(first_dyn_id);
811
917
        init_internal_icons();
812
918
        init_brush_icons();
 
919
        init_matcap_icons();
813
920
#endif
814
921
}
815
922
 
834
941
                if (G.debug & G_DEBUG)
835
942
                        printf("%s, error: requested preview image does not exist", __func__);
836
943
        }
837
 
        if (!prv_img->rect[size]) {
 
944
        else if (!prv_img->rect[size]) {
838
945
                prv_img->w[size] = render_size;
839
946
                prv_img->h[size] = render_size;
840
947
                prv_img->changed[size] = 1;
851
958
                if (G.debug & G_DEBUG)
852
959
                        printf("%s: no preview image for this ID: %s\n", __func__, id->name);
853
960
                return;
854
 
        }       
 
961
        }
855
962
 
856
963
        icon_create_rect(prv_img, size);
857
964
 
859
966
                            prv_img->w[size], prv_img->h[size]);
860
967
}
861
968
 
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)
 
970
{
 
971
        Icon *icon = BKE_icon_get(icon_id);
 
972
        
 
973
        if (icon) {
 
974
                DrawInfo *di = (DrawInfo *)icon->drawinfo;
 
975
                if (di && di->data.buffer.image) {
 
976
                        ImBuf *bbuf;
 
977
                        
 
978
                        bbuf = IMB_ibImageFromMemory(di->data.buffer.image->datatoc_rect, di->data.buffer.image->datatoc_size, IB_rect, NULL, "<matcap buffer>");
 
979
                        if (bbuf) {
 
980
                                PreviewImage *prv = BKE_previewimg_create();
 
981
                                
 
982
                                prv->rect[0] = bbuf->rect;
 
983
 
 
984
                                prv->w[0] = bbuf->x;
 
985
                                prv->h[0] = bbuf->y;
 
986
                                
 
987
                                bbuf->rect = NULL;
 
988
                                IMB_freeImBuf(bbuf);
 
989
                                
 
990
                                return prv;
 
991
                        }
 
992
                }
 
993
        }
 
994
        return NULL;
 
995
}
 
996
 
 
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)
863
999
{
864
1000
        ImBuf *ima = NULL;
865
1001
 
912
1048
        }
913
1049
}
914
1050
 
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])
916
1053
{
917
1054
        float x1, x2, y1, y2;
918
1055
 
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);
921
1058
 
922
1059
        x1 = ix * icongltex.invw;
923
1060
        x2 = (ix + ih) * icongltex.invw;
927
1064
        glEnable(GL_TEXTURE_2D);
928
1065
        glBindTexture(GL_TEXTURE_2D, icongltex.id);
929
1066
 
 
1067
        /* sharper downscaling, has no effect when scale matches with a mip level */
 
1068
        glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -0.5f);
 
1069
 
930
1070
        glBegin(GL_QUADS);
931
1071
        glTexCoord2f(x1, y1);
932
1072
        glVertex2f(x, y);
941
1081
        glVertex2f(x, y + h);
942
1082
        glEnd();
943
1083
 
 
1084
        glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0.0f);
 
1085
 
944
1086
        glBindTexture(GL_TEXTURE_2D, 0);
945
1087
        glDisable(GL_TEXTURE_2D);
946
1088
}
955
1097
        return 0;
956
1098
}
957
1099
 
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)
 
1100
 
 
1101
 
 
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)
959
1104
{
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;
965
1110
        int w, h;
966
1111
        
967
1112
        icon = BKE_icon_get(icon_id);
978
1123
        if (!di) {
979
1124
                di = icon_create_drawinfo();
980
1125
        
981
 
                icon->drawinfo = di;            
982
 
                icon->drawinfo_free = UI_icons_free_drawinfo;           
 
1126
                icon->drawinfo = di;
 
1127
                icon->drawinfo_free = UI_icons_free_drawinfo;
983
1128
        }
984
1129
        
985
1130
        /* scale width and height according to aspect */
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); 
993
 
        } 
 
1137
                di->data.vector.func((int)x, (int)y, w, h, 1.0f);
 
1138
        }
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);
997
1145
        }
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;
1001
 
 
 
1149
#ifndef WITH_HEADLESS
 
1150
                icon_verify_datatoc(iimg);
 
1151
#endif
1002
1152
                if (!iimg->rect) return;  /* something has gone wrong! */
1003
1153
 
 
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);
1005
1157
        }
1006
1158
        else if (di->type == ICON_TYPE_PREVIEW) {
1007
1159
                PreviewImage *pi = BKE_previewimg_get((ID *)icon->obj);
1008
1160
 
1009
 
                if (pi) {                       
 
1161
                if (pi) {
1010
1162
                        /* no create icon on this level in code */
1011
1163
                        if (!pi->rect[size]) return;  /* something has gone wrong! */
1012
1164
                        
1086
1238
                                mode = OB_MODE_TEXTURE_PAINT;
1087
1239
                }
1088
1240
                else if ((sima = CTX_wm_space_image(C)) &&
1089
 
                         (sima->flag & SI_DRAWTOOL))
 
1241
                         (sima->mode == SI_MODE_PAINT))
1090
1242
                {
1091
1243
                        mode = OB_MODE_TEXTURE_PAINT;
1092
1244
                }
1137
1289
        return iconid;
1138
1290
}
1139
1291
 
 
1292
int UI_rnaptr_icon_get(bContext *C, PointerRNA *ptr, int rnaicon, int big)
 
1293
{
 
1294
        ID *id = NULL;
 
1295
 
 
1296
        if (!ptr->data)
 
1297
                return rnaicon;
 
1298
 
 
1299
        /* try ID, material, texture or dynapaint slot */
 
1300
        if (RNA_struct_is_ID(ptr->type)) {
 
1301
                id = ptr->id.data;
 
1302
        }
 
1303
        else if (RNA_struct_is_a(ptr->type, &RNA_MaterialSlot)) {
 
1304
                id = RNA_pointer_get(ptr, "material").data;
 
1305
        }
 
1306
        else if (RNA_struct_is_a(ptr->type, &RNA_TextureSlot)) {
 
1307
                id = RNA_pointer_get(ptr, "texture").data;
 
1308
        }
 
1309
        else if (RNA_struct_is_a(ptr->type, &RNA_DynamicPaintSurface)) {
 
1310
                DynamicPaintSurface *surface = (DynamicPaintSurface *)ptr->data;
 
1311
 
 
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;
 
1318
        }
 
1319
 
 
1320
        /* get icon from ID */
 
1321
        if (id) {
 
1322
                int icon = ui_id_icon_get(C, id, big);
 
1323
 
 
1324
                return icon ? icon : rnaicon;
 
1325
        }
 
1326
 
 
1327
        return rnaicon;
 
1328
}
 
1329
 
1140
1330
static void icon_draw_at_size(float x, float y, int icon_id, float aspect, float alpha, enum eIconSizes size, int nocreate)
1141
1331
{
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);
1155
1345
}
1156
1346
 
 
1347
/* draws icon with dpi scale factor */
1157
1348
void UI_icon_draw(float x, float y, int icon_id)
1158
1349
{
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);
1160
1351
}
1161
1352
 
1162
1353
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)