~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: interface_icons.c 30531 2010-07-20 11:32:30Z jwilkins $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
25
23
 * ***** END GPL LICENSE BLOCK *****
26
24
 */
27
25
 
 
26
/** \file blender/editors/interface/interface_icons.c
 
27
 *  \ingroup edinterface
 
28
 */
 
29
 
 
30
 
28
31
#include <math.h>
29
32
#include <stdlib.h>
30
33
#include <string.h>
31
34
 
32
35
#ifndef WIN32
33
 
#include <unistd.h>
 
36
#  include <unistd.h>
34
37
#else
35
 
#include <io.h>
36
 
#include <direct.h>
37
 
#include "BLI_winstuff.h"
38
 
#endif   
 
38
#  include <io.h>
 
39
#  include <direct.h>
 
40
#  include "BLI_winstuff.h"
 
41
#endif
 
42
 
39
43
#include "MEM_guardedalloc.h"
40
44
 
41
45
#include "GPU_extensions.h"
42
46
 
43
47
#include "BLI_math.h"
44
48
#include "BLI_blenlib.h"
45
 
#include "BLI_storage_types.h"
 
49
#include "BLI_utildefines.h"
46
50
 
 
51
#include "DNA_brush_types.h"
 
52
#include "DNA_object_types.h"
47
53
#include "DNA_screen_types.h"
48
 
#include "DNA_userdef_types.h"
49
 
#include "DNA_brush_types.h"
 
54
#include "DNA_space_types.h"
 
55
 
 
56
#include "RNA_access.h"
 
57
#include "RNA_enum_types.h"
50
58
 
51
59
#include "BKE_context.h"
52
60
#include "BKE_global.h"
53
 
#include "BKE_image.h"
54
61
#include "BKE_icons.h"
55
 
#include "BKE_brush.h"
56
62
#include "BKE_utildefines.h"
57
63
 
58
64
#include "IMB_imbuf.h"
70
76
#include "interface_intern.h"
71
77
 
72
78
 
73
 
#define ICON_IMAGE_W            600
74
 
#define ICON_IMAGE_H            640
75
 
 
76
 
#define ICON_GRID_COLS          26
77
 
#define ICON_GRID_ROWS          30
78
 
 
79
 
#define ICON_GRID_MARGIN        5
80
 
#define ICON_GRID_W             16
81
 
#define ICON_GRID_H             16
 
79
#define ICON_IMAGE_W        600
 
80
#define ICON_IMAGE_H        640
 
81
 
 
82
#define ICON_GRID_COLS      26
 
83
#define ICON_GRID_ROWS      30
 
84
 
 
85
#define ICON_GRID_MARGIN    5
 
86
#define ICON_GRID_W         16
 
87
#define ICON_GRID_H         16
82
88
 
83
89
typedef struct IconImage {
84
90
        int w;
88
94
 
89
95
typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
90
96
 
91
 
#define ICON_TYPE_PREVIEW       0
92
 
#define ICON_TYPE_TEXTURE       1
93
 
#define ICON_TYPE_BUFFER        2
94
 
#define ICON_TYPE_VECTOR        3
 
97
#define ICON_TYPE_PREVIEW   0
 
98
#define ICON_TYPE_TEXTURE   1
 
99
#define ICON_TYPE_BUFFER    2
 
100
#define ICON_TYPE_VECTOR    3
95
101
 
96
102
typedef struct DrawInfo {
97
103
        int type;
102
108
                        VectorDrawFunc func;
103
109
                } vector;
104
110
                struct {
105
 
                        IconImage* image;
 
111
                        IconImage *image;
106
112
                } buffer;
107
113
                struct {
108
114
                        int x, y, w, h;
121
127
/* ******************* STATIC LOCAL VARS ******************* */
122
128
/* static here to cache results of icon directory scan, so it's not 
123
129
 * scanning the filesystem each time the menu is drawn */
124
 
static struct ListBase iconfilelist = {0, 0};
 
130
static struct ListBase iconfilelist = {NULL, NULL};
125
131
static IconTexture icongltex = {0, 0, 0, 0.0f, 0.0f};
126
132
 
127
133
/* **************************************************** */
136
142
 
137
143
        new_icon = MEM_callocN(sizeof(Icon), "texicon");
138
144
 
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;     
141
147
 
142
148
        di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
143
 
        di->type= type;
 
149
        di->type = type;
144
150
 
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;
150
156
        }
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");
154
160
                iimg->w = size;
155
161
                iimg->h = size;
156
162
 
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));
161
167
                }
162
168
 
163
169
                di->data.buffer.image = iimg;
169
175
        BKE_icon_set(icon_id, new_icon);
170
176
}
171
177
 
172
 
static void def_internal_vicon( int icon_id, VectorDrawFunc drawFunc)
 
178
static void def_internal_vicon(int icon_id, VectorDrawFunc drawFunc)
173
179
{
174
180
        Icon *new_icon = NULL;
175
 
        DrawInfo* di;
 
181
        DrawInfo *di;
176
182
 
177
183
        new_icon = MEM_callocN(sizeof(Icon), "texicon");
178
184
 
179
 
        new_icon->obj = 0; /* icon is not for library object */
 
185
        new_icon->obj = NULL; /* icon is not for library object */
180
186
        new_icon->type = 0;
181
187
 
182
188
        di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
183
 
        di->type= ICON_TYPE_VECTOR;
184
 
        di->data.vector.func =drawFunc;
 
189
        di->type = ICON_TYPE_VECTOR;
 
190
        di->data.vector.func = drawFunc;
185
191
 
186
 
        new_icon->drawinfo_free = 0;
 
192
        new_icon->drawinfo_free = NULL;
187
193
        new_icon->drawinfo = di;
188
194
 
189
195
        BKE_icon_set(icon_id, new_icon);
191
197
 
192
198
/* Vector Icon Drawing Routines */
193
199
 
194
 
        /* Utilities */
 
200
/* Utilities */
195
201
 
196
202
static void viconutil_set_point(GLint pt[2], int x, int y)
197
203
{
199
205
        pt[1] = y;
200
206
}
201
207
 
202
 
static void viconutil_draw_tri(GLint (*pts)[2])
 
208
static void viconutil_draw_tri(GLint(*pts)[2])
203
209
{
204
210
        glBegin(GL_TRIANGLES);
205
211
        glVertex2iv(pts[0]);
208
214
        glEnd();
209
215
}
210
216
 
211
 
static void viconutil_draw_lineloop(GLint (*pts)[2], int numPoints)
 
217
static void viconutil_draw_lineloop(GLint(*pts)[2], int numPoints)
212
218
{
213
219
        int i;
214
220
 
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]);
218
224
        }
219
225
        glEnd();
220
226
}
221
227
 
222
 
static void viconutil_draw_lineloop_smooth(GLint (*pts)[2], int numPoints)
 
228
static void viconutil_draw_lineloop_smooth(GLint(*pts)[2], int numPoints)
223
229
{
224
230
        glEnable(GL_LINE_SMOOTH);
225
231
        viconutil_draw_lineloop(pts, numPoints);
226
232
        glDisable(GL_LINE_SMOOTH);
227
233
}
228
234
 
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)
230
236
{
231
237
        int i;
232
238
 
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];
236
242
 
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);
241
247
        }
242
248
        glEnd();
243
249
}
244
250
 
245
 
        /* Drawing functions */
 
251
/* Drawing functions */
246
252
 
247
253
static void vicon_x_draw(int x, int y, int w, int h, float alpha)
248
254
{
251
257
        w -= 6;
252
258
        h -= 6;
253
259
 
254
 
        glEnable( GL_LINE_SMOOTH );
 
260
        glEnable(GL_LINE_SMOOTH);
255
261
 
256
262
        glLineWidth(2.5);
257
263
        
258
264
        glColor4f(0.0, 0.0, 0.0, alpha);
259
265
        glBegin(GL_LINES);
260
 
        glVertex2i(x  ,y  );
261
 
        glVertex2i(x+w,y+h);
262
 
        glVertex2i(x+w,y  );
263
 
        glVertex2i(x  ,y+h);
 
266
        glVertex2i(x, y);
 
267
        glVertex2i(x + w, y + h);
 
268
        glVertex2i(x + w, y);
 
269
        glVertex2i(x, y + h);
264
270
        glEnd();
265
271
 
266
272
        glLineWidth(1.0);
267
273
        
268
 
        glDisable( GL_LINE_SMOOTH );
 
274
        glDisable(GL_LINE_SMOOTH);
269
275
}
270
276
 
271
277
static void vicon_view3d_draw(int x, int y, int w, int h, float alpha)
272
278
{
273
 
        int cx = x + w/2;
274
 
        int cy = y + h/2;
275
 
        int d = MAX2(2, h/3);
 
279
        int cx = x + w / 2;
 
280
        int cy = y + h / 2;
 
281
        int d = MAX2(2, h / 3);
276
282
 
277
283
        glColor4f(0.5, 0.5, 0.5, alpha);
278
284
        glBegin(GL_LINES);
279
 
        glVertex2i(x  , cy-d);
280
 
        glVertex2i(x+w, cy-d);
281
 
        glVertex2i(x  , cy+d);
282
 
        glVertex2i(x+w, cy+d);
 
285
        glVertex2i(x, cy - d);
 
286
        glVertex2i(x + w, cy - d);
 
287
        glVertex2i(x, cy + d);
 
288
        glVertex2i(x + w, cy + d);
283
289
 
284
 
        glVertex2i(cx-d, y  );
285
 
        glVertex2i(cx-d, y+h);
286
 
        glVertex2i(cx+d, y  );
287
 
        glVertex2i(cx+d, y+h);
 
290
        glVertex2i(cx - d, y);
 
291
        glVertex2i(cx - d, y + h);
 
292
        glVertex2i(cx + d, y);
 
293
        glVertex2i(cx + d, y + h);
288
294
        glEnd();
289
295
        
290
296
        glColor4f(0.0, 0.0, 0.0, alpha);
291
297
        glBegin(GL_LINES);
292
 
        glVertex2i(x  , cy);
293
 
        glVertex2i(x+w, cy);
294
 
        glVertex2i(cx, y  );
295
 
        glVertex2i(cx, y+h);
 
298
        glVertex2i(x, cy);
 
299
        glVertex2i(x + w, cy);
 
300
        glVertex2i(cx, y);
 
301
        glVertex2i(cx, y + h);
296
302
        glEnd();
297
303
}
298
304
 
300
306
{
301
307
        GLint pts[4][2];
302
308
 
303
 
        viconutil_set_point(pts[0], x+3  , y+3  );
304
 
        viconutil_set_point(pts[1], x+w-3, y+3  );
305
 
        viconutil_set_point(pts[2], x+w-3, y+h-3);
306
 
        viconutil_set_point(pts[3], x+3  , y+h-3);
 
309
        viconutil_set_point(pts[0], x + 3,     y + 3);
 
310
        viconutil_set_point(pts[1], x + w - 3, y + 3);
 
311
        viconutil_set_point(pts[2], x + w - 3, y + h - 3);
 
312
        viconutil_set_point(pts[3], x + 3,     y + h - 3);
307
313
 
308
314
        glColor4f(0.0, 0.0, 0.0, alpha);
309
315
        viconutil_draw_lineloop(pts, 4);
316
322
{
317
323
        GLint pts[3][2];
318
324
 
319
 
        viconutil_set_point(pts[0], x+w/2, y+h-2);
320
 
        viconutil_set_point(pts[1], x+3, y+4);
321
 
        viconutil_set_point(pts[2], x+w-3, y+4);
 
325
        viconutil_set_point(pts[0], x + w / 2, y + h - 2);
 
326
        viconutil_set_point(pts[1], x + 3,     y + 4);
 
327
        viconutil_set_point(pts[2], x + w - 3, y + 4);
322
328
 
323
329
        glColor4f(0.5, 0.5, 0.5, alpha);
324
330
        viconutil_draw_tri(pts);
330
336
        viconutil_draw_points(pts, 3, 1);
331
337
}
332
338
 
333
 
static void vicon_editmode_dehlt_draw(int x, int y, int w, int h, float alpha)
 
339
static void vicon_editmode_dehlt_draw(int x, int y, int w, int h, float UNUSED(alpha))
334
340
{
335
341
        GLint pts[3][2];
336
342
 
337
 
        viconutil_set_point(pts[0], x+w/2, y+h-2);
338
 
        viconutil_set_point(pts[1], x+3, y+4);
339
 
        viconutil_set_point(pts[2], x+w-3, y+4);
 
343
        viconutil_set_point(pts[0], x + w / 2, y + h - 2);
 
344
        viconutil_set_point(pts[1], x + 3,     y + 4);
 
345
        viconutil_set_point(pts[2], x + w - 3, y + 4);
340
346
 
341
347
        glColor4f(0.0f, 0.0f, 0.0f, 1);
342
348
        viconutil_draw_lineloop_smooth(pts, 3);
345
351
        viconutil_draw_points(pts, 3, 1);
346
352
}
347
353
 
348
 
static void vicon_disclosure_tri_right_draw(int x, int y, int w, int h, float alpha)
 
354
static void vicon_disclosure_tri_right_draw(int x, int y, int w, int UNUSED(h), float alpha)
349
355
{
350
356
        GLint pts[3][2];
351
 
        int cx = x+w/2;
352
 
        int cy = y+w/2;
353
 
        int d = w/3, d2 = w/5;
 
357
        int cx = x + w / 2;
 
358
        int cy = y + w / 2;
 
359
        int d = w / 3, d2 = w / 5;
354
360
 
355
 
        viconutil_set_point(pts[0], cx-d2, cy+d);
356
 
        viconutil_set_point(pts[1], cx-d2, cy-d);
357
 
        viconutil_set_point(pts[2], cx+d2, cy);
 
361
        viconutil_set_point(pts[0], cx - d2, cy + d);
 
362
        viconutil_set_point(pts[1], cx - d2, cy - d);
 
363
        viconutil_set_point(pts[2], cx + d2, cy);
358
364
 
359
365
        glShadeModel(GL_SMOOTH);
360
366
        glBegin(GL_TRIANGLES);
370
376
        viconutil_draw_lineloop_smooth(pts, 3);
371
377
}
372
378
 
373
 
static void vicon_small_tri_right_draw(int x, int y, int w, int h, float alpha)
 
379
static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float alpha)
374
380
{
375
381
        GLint pts[3][2];
376
 
        int cx = x+w/2-4;
377
 
        int cy = y+w/2;
378
 
        int d = w/5, d2 = w/7;
 
382
        int cx = x + w / 2 - 4;
 
383
        int cy = y + w / 2;
 
384
        int d = w / 5, d2 = w / 7;
379
385
 
380
 
        viconutil_set_point(pts[0], cx-d2, cy+d);
381
 
        viconutil_set_point(pts[1], cx-d2, cy-d);
382
 
        viconutil_set_point(pts[2], cx+d2, cy);
 
386
        viconutil_set_point(pts[0], cx - d2, cy + d);
 
387
        viconutil_set_point(pts[1], cx - d2, cy - d);
 
388
        viconutil_set_point(pts[2], cx + d2, cy);
383
389
 
384
390
        glColor4f(0.2f, 0.2f, 0.2f, alpha);
385
391
 
392
398
        glShadeModel(GL_FLAT);
393
399
}
394
400
 
395
 
static void vicon_disclosure_tri_down_draw(int x, int y, int w, int h, float alpha)
 
401
static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), float alpha)
396
402
{
397
403
        GLint pts[3][2];
398
 
        int cx = x+w/2;
399
 
        int cy = y+w/2;
400
 
        int d = w/3, d2 = w/5;
 
404
        int cx = x + w / 2;
 
405
        int cy = y + w / 2;
 
406
        int d = w / 3, d2 = w / 5;
401
407
 
402
 
        viconutil_set_point(pts[0], cx+d, cy+d2);
403
 
        viconutil_set_point(pts[1], cx-d, cy+d2);
404
 
        viconutil_set_point(pts[2], cx, cy-d2);
 
408
        viconutil_set_point(pts[0], cx + d, cy + d2);
 
409
        viconutil_set_point(pts[1], cx - d, cy + d2);
 
410
        viconutil_set_point(pts[2], cx, cy - d2);
405
411
 
406
412
        glShadeModel(GL_SMOOTH);
407
413
        glBegin(GL_TRIANGLES);
417
423
        viconutil_draw_lineloop_smooth(pts, 3);
418
424
}
419
425
 
420
 
static void vicon_move_up_draw(int x, int y, int w, int h, float alpha)
421
 
{
422
 
        int d=-2;
423
 
 
424
 
        glEnable(GL_LINE_SMOOTH);
425
 
        glLineWidth(1);
426
 
        glColor3f(0.0, 0.0, 0.0);
427
 
 
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);
432
 
        glEnd();
433
 
 
434
 
        glLineWidth(1.0);
435
 
        glDisable(GL_LINE_SMOOTH);
436
 
}
437
 
 
438
 
static void vicon_move_down_draw(int x, int y, int w, int h, float alpha)
439
 
{
440
 
        int d=2;
441
 
 
442
 
        glEnable(GL_LINE_SMOOTH);
443
 
        glLineWidth(1);
444
 
        glColor3f(0.0, 0.0, 0.0);
445
 
 
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);
450
 
        glEnd();
451
 
 
452
 
        glLineWidth(1.0);
453
 
        glDisable(GL_LINE_SMOOTH);
454
 
}
455
 
 
456
 
static void init_internal_icons()
457
 
{
458
 
        bTheme *btheme= U.themes.first;
459
 
        ImBuf *bbuf= NULL;
 
426
static void vicon_move_up_draw(int x, int y, int w, int h, float UNUSED(alpha))
 
427
{
 
428
        int d = -2;
 
429
 
 
430
        glEnable(GL_LINE_SMOOTH);
 
431
        glLineWidth(1);
 
432
        glColor3f(0.0, 0.0, 0.0);
 
433
 
 
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);
 
438
        glEnd();
 
439
 
 
440
        glLineWidth(1.0);
 
441
        glDisable(GL_LINE_SMOOTH);
 
442
}
 
443
 
 
444
static void vicon_move_down_draw(int x, int y, int w, int h, float UNUSED(alpha))
 
445
{
 
446
        int d = 2;
 
447
 
 
448
        glEnable(GL_LINE_SMOOTH);
 
449
        glLineWidth(1);
 
450
        glColor3f(0.0, 0.0, 0.0);
 
451
 
 
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);
 
456
        glEnd();
 
457
 
 
458
        glLineWidth(1.0);
 
459
        glDisable(GL_LINE_SMOOTH);
 
460
}
 
461
 
 
462
#ifndef WITH_HEADLESS
 
463
static void init_brush_icons(void)
 
464
{
 
465
 
 
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
 
474
        /* end INIT_BRUSH_ICON */
 
475
 
 
476
        ImBuf *bbuf;
 
477
        const int w = 96;
 
478
 
 
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);
 
508
 
 
509
#undef INIT_BRUSH_ICON
 
510
}
 
511
 
 
512
static void init_internal_icons(void)
 
513
{
 
514
        bTheme *btheme = UI_GetTheme();
 
515
        ImBuf *bbuf = NULL;
460
516
        int x, y, icontype;
461
 
        char iconfilestr[FILE_MAXDIR+FILE_MAXFILE];
 
517
        char iconfilestr[FILE_MAX];
462
518
        
463
 
        if ((btheme!=NULL) && (strlen(btheme->tui.iconfile) > 0)) {
464
 
                char *datadir= BLI_get_folder(BLENDER_DATAFILES, NULL);
465
 
                if (datadir) {
466
 
                        BLI_make_file_string("/", iconfilestr, datadir, btheme->tui.iconfile);
467
 
                        
468
 
                        if (BLI_exists(iconfilestr)) {
469
 
                                bbuf = IMB_loadiffname(iconfilestr, IB_rect);
470
 
                                if(bbuf->x < ICON_IMAGE_W || bbuf->y < ICON_IMAGE_H) {
471
 
                                        if (G.f & G_DEBUG)
472
 
                                                printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr);
473
 
                                        IMB_freeImBuf(bbuf);
474
 
                                        bbuf= NULL;
475
 
                                }
 
519
        if ((btheme != NULL) && btheme->tui.iconfile[0]) {
 
520
                char *icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
 
521
                if (icondir) {
 
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);
 
526
                                IMB_freeImBuf(bbuf);
 
527
                                bbuf = NULL;
476
528
                        }
477
529
                }
 
530
                else {
 
531
                        printf("%s: 'icons' data path not found, continuing\n", __func__);
 
532
                }
478
533
        }
479
 
        if(bbuf==NULL)
480
 
                bbuf = IMB_ibImageFromMemory((unsigned char*)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect);
 
534
        if (bbuf == NULL)
 
535
                bbuf = IMB_ibImageFromMemory((unsigned char *)datatoc_blender_icons_png, datatoc_blender_icons_png_size, IB_rect, "<blender icons>");
481
536
 
482
 
        if(bbuf) {
 
537
        if (bbuf) {
483
538
                /* free existing texture if any */
484
 
                if(icongltex.id) {
 
539
                if (icongltex.id) {
485
540
                        glDeleteTextures(1, &icongltex.id);
486
 
                        icongltex.id= 0;
 
541
                        icongltex.id = 0;
487
542
                }
488
543
 
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);
492
547
 
493
 
                        if(icongltex.id) {
 
548
                        if (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;
498
553
 
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);
502
557
                                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
503
558
                                glBindTexture(GL_TEXTURE_2D, 0);
504
559
 
505
 
                                if(glGetError() == GL_OUT_OF_MEMORY) {
 
560
                                if (glGetError() == GL_OUT_OF_MEMORY) {
506
561
                                        glDeleteTextures(1, &icongltex.id);
507
 
                                        icongltex.id= 0;
 
562
                                        icongltex.id = 0;
508
563
                                }
509
564
                        }
510
565
                }
511
566
        }
512
567
 
513
 
        if(icongltex.id)
514
 
                icontype= ICON_TYPE_TEXTURE;
 
568
        if (icongltex.id)
 
569
                icontype = ICON_TYPE_TEXTURE;
515
570
        else
516
 
                icontype= ICON_TYPE_BUFFER;
 
571
                icontype = ICON_TYPE_BUFFER;
517
572
        
518
 
        if(bbuf) {
519
 
                for (y=0; y<ICON_GRID_ROWS; y++) {
520
 
                        for (x=0; x<ICON_GRID_COLS; x++) {
521
 
                                def_internal_icon(bbuf, BIFICONID_FIRST + y*ICON_GRID_COLS + x,
522
 
                                        x*(ICON_GRID_W+ICON_GRID_MARGIN)+ICON_GRID_MARGIN,
523
 
                                        y*(ICON_GRID_H+ICON_GRID_MARGIN)+ICON_GRID_MARGIN, ICON_GRID_W,
524
 
                                        icontype);
 
573
        if (bbuf) {
 
574
                for (y = 0; y < ICON_GRID_ROWS; y++) {
 
575
                        for (x = 0; x < ICON_GRID_COLS; x++) {
 
576
                                def_internal_icon(bbuf, BIFICONID_FIRST + y * ICON_GRID_COLS + x,
 
577
                                                  x * (ICON_GRID_W + ICON_GRID_MARGIN) + ICON_GRID_MARGIN,
 
578
                                                  y * (ICON_GRID_H + ICON_GRID_MARGIN) + ICON_GRID_MARGIN, ICON_GRID_W,
 
579
                                                  icontype);
525
580
                        }
526
581
                }
527
582
        }
539
594
 
540
595
        IMB_freeImBuf(bbuf);
541
596
}
542
 
 
 
597
#endif // WITH_HEADLESS
543
598
 
544
599
static void init_iconfile_list(struct ListBase *list)
545
600
{
546
601
        IconFile *ifile;
547
 
        ImBuf *bbuf= NULL;
548
602
        struct direntry *dir;
549
603
        int restoredir = 1; /* restore to current directory */
550
 
        int totfile, i, index=1;
551
 
        int ifilex, ifiley;
552
 
        char icondirstr[FILE_MAX];
553
 
        char iconfilestr[FILE_MAX+16]; /* allow 256 chars for file+dir */
 
604
        int totfile, i, index = 1;
 
605
        const char *icondir;
554
606
        char olddir[FILE_MAX];
555
 
        char *datadir= NULL;
556
607
 
557
608
        list->first = list->last = NULL;
558
 
        datadir = BLI_get_folder(BLENDER_DATAFILES, NULL);
559
 
 
560
 
        if (!datadir) return;
561
 
 
562
 
        BLI_make_file_string("/", icondirstr, datadir, "");
563
 
        
564
 
        if(BLI_exists(icondirstr)==0)
 
609
        icondir = BLI_get_folder(BLENDER_DATAFILES, "icons");
 
610
 
 
611
        if (icondir == NULL)
565
612
                return;
566
613
        
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))) 
570
617
                restoredir = 0;
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 */
573
620
 
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;
577
624
                        
578
 
                        if(BLI_testextensie(filename, ".png")) {
579
 
                        
 
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. */
 
628
#if 0
 
629
                                int ifilex, ifiley;
 
630
                                char iconfilestr[FILE_MAX + 16]; /* allow 256 chars for file+dir */
 
631
                                ImBuf *bbuf = NULL;
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);
585
 
                                
586
 
                                ifilex = bbuf->x;
587
 
                                ifiley = bbuf->y;
588
 
                                IMB_freeImBuf(bbuf);
589
 
                                
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);
 
637
 
 
638
                                if (bbuf) {
 
639
                                        ifilex = bbuf->x;
 
640
                                        ifiley = bbuf->y;
 
641
                                        IMB_freeImBuf(bbuf);
 
642
                                }
 
643
                                else {
 
644
                                        ifilex = ifiley = 0;
 
645
                                }
 
646
                                
 
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);
591
650
                                        continue;
592
 
                        
 
651
                                }
 
652
#endif          /* removed */
 
653
 
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");
595
656
                                
603
664
                }
604
665
        }
605
666
        
606
 
        /* free temporary direntry structure that's been created by BLI_getdir() */
607
 
        i= totfile-1;
 
667
        /* free temporary direntry structure that's been created by BLI_dir_contents() */
 
668
        i = totfile - 1;
608
669
        
609
 
        for(; i>=0; i--){
 
670
        for (; i >= 0; i--) {
610
671
                MEM_freeN(dir[i].relname);
611
672
                MEM_freeN(dir[i].path);
612
 
                if (dir[i].string) MEM_freeN(dir[i].string);
 
673
                if (dir[i].string) {
 
674
                        MEM_freeN(dir[i].string);
 
675
                }
613
676
        }
614
677
        free(dir);
615
 
        dir= 0;
 
678
        dir = NULL;
616
679
}
617
680
 
618
681
static void free_iconfile_list(struct ListBase *list)
619
682
{
620
 
        IconFile *ifile=NULL, *next_ifile=NULL;
 
683
        IconFile *ifile = NULL, *next_ifile = NULL;
621
684
        
622
 
        for(ifile=list->first; ifile; ifile=next_ifile) {
 
685
        for (ifile = list->first; ifile; ifile = next_ifile) {
623
686
                next_ifile = ifile->next;
624
687
                BLI_freelinkN(list, ifile);
625
688
        }
626
689
}
627
690
 
628
 
int UI_iconfile_get_index(char *filename)
 
691
int UI_iconfile_get_index(const char *filename)
629
692
{
630
693
        IconFile *ifile;
631
 
        ListBase *list=&(iconfilelist);
 
694
        ListBase *list = &(iconfilelist);
632
695
        
633
 
        for(ifile=list->first; ifile; ifile=ifile->next) {
634
 
                if ( BLI_streq(filename, ifile->filename)) {
 
696
        for (ifile = list->first; ifile; ifile = ifile->next) {
 
697
                if (BLI_path_cmp(filename, ifile->filename) == 0) {
635
698
                        return ifile->index;
636
699
                }
637
700
        }
641
704
 
642
705
ListBase *UI_iconfile_list(void)
643
706
{
644
 
        ListBase *list=&(iconfilelist);
 
707
        ListBase *list = &(iconfilelist);
645
708
        
646
709
        return list;
647
710
}
648
711
 
649
712
 
650
 
void UI_icons_free()
 
713
void UI_icons_free(void)
651
714
{
652
 
        if(icongltex.id) {
 
715
#ifndef WITH_HEADLESS
 
716
        if (icongltex.id) {
653
717
                glDeleteTextures(1, &icongltex.id);
654
 
                icongltex.id= 0;
 
718
                icongltex.id = 0;
655
719
        }
656
720
 
657
721
        free_iconfile_list(&iconfilelist);
658
722
        BKE_icons_free();
 
723
#endif
659
724
}
660
725
 
661
726
void UI_icons_free_drawinfo(void *drawinfo)
662
727
{
663
728
        DrawInfo *di = drawinfo;
664
729
 
665
 
        if(di) {
666
 
                if(di->type == ICON_TYPE_BUFFER) {
667
 
                        if(di->data.buffer.image) {
 
730
        if (di) {
 
731
                if (di->type == ICON_TYPE_BUFFER) {
 
732
                        if (di->data.buffer.image) {
668
733
                                MEM_freeN(di->data.buffer.image->rect);
669
734
                                MEM_freeN(di->data.buffer.image);
670
735
                        }
674
739
        }
675
740
}
676
741
 
677
 
static DrawInfo *icon_create_drawinfo()
 
742
static DrawInfo *icon_create_drawinfo(void)
678
743
{
679
744
        DrawInfo *di = NULL;
680
745
 
681
746
        di = MEM_callocN(sizeof(DrawInfo), "di_icon");
682
 
        di->type= ICON_TYPE_PREVIEW;
 
747
        di->type = ICON_TYPE_PREVIEW;
683
748
 
684
749
        return di;
685
750
}
686
751
 
 
752
/* note!, returns unscaled by DPI, may need to multiply result by UI_DPI_ICON_FAC */
687
753
int UI_icon_get_width(int icon_id)
688
754
{
689
755
        Icon *icon = NULL;
691
757
 
692
758
        icon = BKE_icon_get(icon_id);
693
759
        
694
 
        if (!icon) {
695
 
                if (G.f & G_DEBUG)
696
 
                        printf("UI_icon_get_width: Internal error, no icon for icon ID: %d\n", icon_id);
 
760
        if (icon == NULL) {
 
761
                if (G.debug & G_DEBUG)
 
762
                        printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
697
763
                return 0;
698
764
        }
699
765
        
716
782
 
717
783
        icon = BKE_icon_get(icon_id);
718
784
        
719
 
        if (!icon) {
720
 
                if (G.f & G_DEBUG)
721
 
                        printf("UI_icon_get_height: Internal error, no icon for icon ID: %d\n", icon_id);
 
785
        if (icon == NULL) {
 
786
                if (G.debug & G_DEBUG)
 
787
                        printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
722
788
                return 0;
723
789
        }
724
790
        
725
 
        di = (DrawInfo*)icon->drawinfo;
 
791
        di = (DrawInfo *)icon->drawinfo;
726
792
 
727
793
        if (!di) {
728
794
                di = icon_create_drawinfo();
737
803
 
738
804
void UI_icons_init(int first_dyn_id)
739
805
{
 
806
#ifdef WITH_HEADLESS
 
807
        (void)first_dyn_id;
 
808
#else
740
809
        init_iconfile_list(&iconfilelist);
741
810
        BKE_icons_init(first_dyn_id);
742
811
        init_internal_icons();
 
812
        init_brush_icons();
 
813
#endif
743
814
}
744
815
 
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
 
817
 */
 
818
static int preview_render_size(enum eIconSizes size)
747
819
{
748
 
        switch (miplevel) {
749
 
                case 0: return 32;
750
 
                case 1: return PREVIEW_DEFAULT_HEIGHT;
 
820
        switch (size) {
 
821
                case ICON_SIZE_ICON:    return 32;
 
822
                case ICON_SIZE_PREVIEW: return PREVIEW_DEFAULT_HEIGHT;
751
823
        }
752
824
        return 0;
753
825
}
754
826
 
755
 
static void icon_create_mipmap(struct PreviewImage* prv_img, int miplevel) 
 
827
/* Create rect for the icon
 
828
 */
 
829
static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size)
756
830
{
757
 
        unsigned int size = preview_render_size(miplevel);
 
831
        unsigned int render_size = preview_render_size(size);
758
832
 
759
833
        if (!prv_img) {
760
 
                if (G.f & G_DEBUG)
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__);
762
836
        }
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");
769
843
        }
770
844
}
771
845
 
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)
775
849
{
776
850
        if (!prv_img) {
777
 
                if (G.f & G_DEBUG)
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);
779
853
                return;
780
854
        }       
781
855
 
782
 
        /* create the preview rect */
783
 
        icon_create_mipmap(prv_img, miplevel);
 
856
        icon_create_rect(prv_img, size);
784
857
 
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]);
787
860
}
788
861
 
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)
790
863
{
 
864
        ImBuf *ima = NULL;
 
865
 
 
866
        /* sanity check */
 
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");
 
870
                return;
 
871
        }
 
872
 
791
873
        /* modulate color */
792
 
        if(alpha != 1.0f)
 
874
        if (alpha != 1.0f)
793
875
                glPixelTransferf(GL_ALPHA_SCALE, alpha);
794
876
 
795
 
        if(rgb) {
 
877
        if (rgb) {
796
878
                glPixelTransferf(GL_RED_SCALE, rgb[0]);
797
879
                glPixelTransferf(GL_GREEN_SCALE, rgb[1]);
798
880
                glPixelTransferf(GL_BLUE_SCALE, rgb[2]);
799
881
        }
800
882
 
801
 
        /* position */
802
 
        glRasterPos2f(x, y);
803
 
        // XXX ui_rasterpos_safe(x, y, aspect);
804
 
        
 
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 */
 
889
                rect = ima->rect;
 
890
        }
 
891
 
805
892
        /* draw */
806
 
        if((w<1 || h<1)) {
807
 
                // XXX - TODO 2.5 verify whether this case can happen
808
 
                if (G.f & G_DEBUG)
809
 
                        printf("what the heck! - icons are %i x %i pixels?\n", w, h);
810
 
        }
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! */
814
 
                        if (G.f & G_DEBUG)
815
 
                                printf("insane icon size w=%d h=%d\n",w,h);
816
 
                }
817
 
                else {
818
 
                        ImBuf *ima;
819
 
 
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));    
823
 
                        
824
 
                        /* scale it */
825
 
                        IMB_scaleImBuf(ima, w, h);
826
 
                        glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
827
 
                        
828
 
                        IMB_freeImBuf(ima);
829
 
                }
830
 
        }
831
 
        else
 
893
        if (is_preview) {
 
894
                glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
 
895
        }
 
896
        else {
 
897
                glRasterPos2f(x, y);
832
898
                glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect);
 
899
        }
 
900
 
 
901
        if (ima)
 
902
                IMB_freeImBuf(ima);
833
903
 
834
904
        /* restore color */
835
 
        if(alpha != 0.0f)
 
905
        if (alpha != 0.0f)
836
906
                glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
837
907
        
838
 
        if(rgb) {
 
908
        if (rgb) {
839
909
                glPixelTransferf(GL_RED_SCALE, 1.0f);
840
910
                glPixelTransferf(GL_GREEN_SCALE, 1.0f);
841
911
                glPixelTransferf(GL_BLUE_SCALE, 1.0f);
842
912
        }
843
913
}
844
914
 
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])
846
916
{
847
917
        float x1, x2, y1, y2;
848
918
 
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);
851
921
 
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;
856
926
 
857
927
        glEnable(GL_TEXTURE_2D);
858
928
        glBindTexture(GL_TEXTURE_2D, icongltex.id);
862
932
        glVertex2f(x, y);
863
933
 
864
934
        glTexCoord2f(x2, y1);
865
 
        glVertex2f(x+w, y);
 
935
        glVertex2f(x + w, y);
866
936
 
867
937
        glTexCoord2f(x2, y2);
868
 
        glVertex2f(x+w, y+h);
 
938
        glVertex2f(x + w, y + h);
869
939
 
870
940
        glTexCoord2f(x1, y2);
871
 
        glVertex2f(x, y+h);
 
941
        glVertex2f(x, y + h);
872
942
        glEnd();
873
943
 
874
944
        glBindTexture(GL_TEXTURE_2D, 0);
875
945
        glDisable(GL_TEXTURE_2D);
876
946
}
877
947
 
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)
880
950
{
881
 
        switch (miplevel) {
882
 
                case 0: return ICON_DEFAULT_HEIGHT;
883
 
                case 1: return PREVIEW_DEFAULT_HEIGHT;
 
951
        switch (size) {
 
952
                case ICON_SIZE_ICON: return ICON_DEFAULT_HEIGHT;
 
953
                case ICON_SIZE_PREVIEW: return PREVIEW_DEFAULT_HEIGHT;
884
954
        }
885
955
        return 0;
886
956
}
887
957
 
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)
889
959
{
 
960
        bTheme *btheme = UI_GetTheme();
890
961
        Icon *icon = NULL;
891
962
        DrawInfo *di = NULL;
892
963
        IconImage *iimg;
 
964
        float fdraw_size = is_preview ? draw_size : (draw_size * UI_DPI_ICON_FAC);
893
965
        int w, h;
894
966
        
895
967
        icon = BKE_icon_get(icon_id);
 
968
        alpha *= btheme->tui.icon_alpha;
896
969
        
897
 
        if (!icon) {
898
 
                if (G.f & G_DEBUG)
899
 
                        printf("icon_draw_mipmap: Internal error, no icon for icon ID: %d\n", icon_id);
 
970
        if (icon == NULL) {
 
971
                if (G.debug & G_DEBUG)
 
972
                        printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
900
973
                return;
901
974
        }
902
975
 
903
 
        di = (DrawInfo*)icon->drawinfo;
 
976
        di = (DrawInfo *)icon->drawinfo;
904
977
        
905
978
        if (!di) {
906
979
                di = icon_create_drawinfo();
910
983
        }
911
984
        
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);
915
988
        
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); 
920
993
        } 
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);
924
997
        }
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;
928
 
 
929
 
                if(!iimg->rect) return; /* something has gone wrong! */
930
 
 
931
 
                icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb);
 
1000
                iimg = di->data.buffer.image;
 
1001
 
 
1002
                if (!iimg->rect) return;  /* something has gone wrong! */
 
1003
 
 
1004
                icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview);
932
1005
        }
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);
935
1008
 
936
 
                if(pi) {                        
 
1009
                if (pi) {                       
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! */
939
1012
                        
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);
944
1017
                }
945
1018
        }
946
1019
}
947
1020
 
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)
 
1022
{
 
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);
 
1026
 
 
1027
                pi->changed[size] = 0;
 
1028
        }
 
1029
}
 
1030
 
 
1031
static void ui_id_icon_render(bContext *C, ID *id, int big)
 
1032
{
 
1033
        PreviewImage *pi = BKE_previewimg_get(id);
 
1034
 
 
1035
        if (pi) {
 
1036
                if (big)
 
1037
                        ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_PREVIEW);  /* bigger preview size */
 
1038
                else
 
1039
                        ui_id_preview_image_render_size(C, id, pi, ICON_SIZE_ICON);     /* icon size */
 
1040
        }
 
1041
}
 
1042
 
 
1043
static void ui_id_brush_render(bContext *C, ID *id)
949
1044
{
950
1045
        PreviewImage *pi = BKE_previewimg_get(id); 
951
 
                
952
 
        if (pi) {                       
953
 
                if ((pi->changed[0] ||!pi->rect[0])) /* changed only ever set by dynamic icons */
 
1046
        enum eIconSizes i;
 
1047
        
 
1048
        if (!pi)
 
1049
                return;
 
1050
        
 
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);
 
1056
                        pi->changed[i] = 0;
 
1057
                }
 
1058
        }
 
1059
}
 
1060
 
 
1061
 
 
1062
static int ui_id_brush_get_icon(bContext *C, ID *id)
 
1063
{
 
1064
        Brush *br = (Brush *)id;
 
1065
 
 
1066
        if (br->flag & BRUSH_CUSTOM_ICON) {
 
1067
                BKE_icon_getid(id);
 
1068
                ui_id_brush_render(C, id);
 
1069
        }
 
1070
        else {
 
1071
                Object *ob = CTX_data_active_object(C);
 
1072
                SpaceImage *sima;
 
1073
                EnumPropertyItem *items = NULL;
 
1074
                int tool, mode = 0;
 
1075
 
 
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 */
 
1079
 
 
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;
 
1087
                }
 
1088
                else if ((sima = CTX_wm_space_image(C)) &&
 
1089
                         (sima->flag & SI_DRAWTOOL))
954
1090
                {
955
 
                        /* create the preview rect if necessary */                              
956
 
                        
957
 
                        icon_set_image(C, id, pi, 0);           /* icon size */
958
 
                        if (preview)
959
 
                                icon_set_image(C, id, pi, 1);   /* preview size */
960
 
                        
961
 
                        pi->changed[0] = 0;
962
 
                }
 
1091
                        mode = OB_MODE_TEXTURE_PAINT;
 
1092
                }
 
1093
 
 
1094
                /* reset the icon */
 
1095
                if (mode == OB_MODE_SCULPT) {
 
1096
                        items = brush_sculpt_tool_items;
 
1097
                        tool = br->sculpt_tool;
 
1098
                }
 
1099
                else if (mode == OB_MODE_VERTEX_PAINT) {
 
1100
                        items = brush_vertex_tool_items;
 
1101
                        tool = br->vertexpaint_tool;
 
1102
                }
 
1103
                else if (mode == OB_MODE_TEXTURE_PAINT) {
 
1104
                        items = brush_image_tool_items;
 
1105
                        tool = br->imagepaint_tool;
 
1106
                }
 
1107
 
 
1108
                if (!items || !RNA_enum_icon_from_value(items, tool, &id->icon_id))
 
1109
                        id->icon_id = 0;
963
1110
        }
 
1111
 
 
1112
        return id->icon_id;
964
1113
}
965
1114
 
966
 
int ui_id_icon_get(bContext *C, ID *id, int preview)
 
1115
int ui_id_icon_get(bContext *C, ID *id, int big)
967
1116
{
968
 
        int iconid= 0;
 
1117
        int iconid = 0;
969
1118
        
970
1119
        /* icon */
971
 
        switch(GS(id->name))
972
 
        {
 
1120
        switch (GS(id->name)) {
 
1121
                case ID_BR:
 
1122
                        iconid = ui_id_brush_get_icon(C, id);
 
1123
                        break;
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);
982
1132
                        break;
983
1133
                default:
984
1134
                        break;
987
1137
        return iconid;
988
1138
}
989
1139
 
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)
991
1141
{
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);
994
1144
}
995
1145
 
996
1146
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha)
997
1147
{
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);
999
1149
}
1000
1150
 
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])
1002
1152
{
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);
1005
1155
}
1006
1156
 
1007
1157
void UI_icon_draw(float x, float y, int icon_id)
1011
1161
 
1012
1162
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)
1013
1163
{
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);
1015
1165
}
1016
1166
 
1017
1167
void UI_icon_draw_preview(float x, float y, int icon_id)
1018
1168
{
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);
1020
1170
}
1021
1171
 
1022
1172
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect)
1023
1173
{
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);
1025
1175
}
1026
1176
 
1027
1177
void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspect, int size)
1028
1178
{
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);
1030
1180
}
1031
1181