Merging r39050 through r39101 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / interface / interface_widgets.c
1 /*
2 * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2009 Blender Foundation.
19  * All rights reserved.
20  * 
21  * Contributor(s): Blender Foundation
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/interface/interface_widgets.c
27  *  \ingroup edinterface
28  */
29
30
31 #include <limits.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <assert.h>
35
36
37 #include "DNA_screen_types.h"
38 #include "DNA_userdef_types.h"
39
40 #include "BLI_math.h"
41 #include "BLI_listbase.h"
42 #include "BLI_rect.h"
43 #include "BLI_string.h"
44 #include "BLI_utildefines.h"
45
46 #include "BKE_context.h"
47 #include "BKE_curve.h"
48 #include "BKE_utildefines.h"
49
50 #include "RNA_access.h"
51
52 #include "BIF_gl.h"
53 #include "BIF_glutil.h"
54
55 #include "BLF_api.h"
56
57 #include "UI_interface.h"
58 #include "UI_interface_icons.h"
59
60
61 #include "interface_intern.h"
62
63 /* ************** widget base functions ************** */
64 /*
65          - in: roundbox codes for corner types and radius
66          - return: array of [size][2][x,y] points, the edges of the roundbox, + UV coords
67  
68          - draw black box with alpha 0 on exact button boundbox
69          - for ever AA step:
70                 - draw the inner part for a round filled box, with color blend codes or texture coords
71                 - draw outline in outline color
72                 - draw outer part, bottom half, extruded 1 pixel to bottom, for emboss shadow
73                 - draw extra decorations
74          - draw background color box with alpha 1 on exact button boundbox
75  
76  */
77
78 /* fill this struct with polygon info to draw AA'ed */
79 /* it has outline, back, and two optional tria meshes */
80
81 typedef struct uiWidgetTrias {
82         int tot;
83         
84         float vec[32][2];
85         int (*index)[3];
86         
87 } uiWidgetTrias;
88
89 typedef struct uiWidgetBase {
90         
91         int totvert, halfwayvert;
92         float outer_v[64][2];
93         float inner_v[64][2];
94         float inner_uv[64][2];
95         
96         short inner, outline, emboss; /* set on/off */
97         short shadedir;
98         
99         uiWidgetTrias tria1;
100         uiWidgetTrias tria2;
101         
102 } uiWidgetBase;
103
104 /* uiWidgetType: for time being only for visual appearance,
105    later, a handling callback can be added too 
106 */
107 typedef struct uiWidgetType {
108         
109         /* pointer to theme color definition */
110         uiWidgetColors *wcol_theme;
111         uiWidgetStateColors *wcol_state;
112         
113         /* converted colors for state */
114         uiWidgetColors wcol;
115         
116         void (*state)(struct uiWidgetType *, int state);
117         void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign);
118         void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign);
119         void (*text)(uiFontStyle *, uiWidgetColors *, uiBut *, rcti *);
120         
121 } uiWidgetType;
122
123
124 /* *********************** draw data ************************** */
125
126 static float cornervec[9][2]= {{0.0, 0.0}, {0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, 
127 {0.707, 0.293}, {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}, {1.0, 1.0}};
128
129 static float jit[8][2]= {{0.468813 , -0.481430}, {-0.155755 , -0.352820}, 
130 {0.219306 , -0.238501},  {-0.393286 , -0.110949}, {-0.024699 , 0.013908}, 
131 {0.343805 , 0.147431}, {-0.272855 , 0.269918}, {0.095909 , 0.388710}};
132
133 static float num_tria_vert[3][2]= { 
134 {-0.352077, 0.532607}, {-0.352077, -0.549313}, {0.330000, -0.008353}};
135
136 static int num_tria_face[1][3]= {
137 {0, 1, 2}};
138
139 static float scroll_circle_vert[16][2]= {
140 {0.382684, 0.923879}, {0.000001, 1.000000}, {-0.382683, 0.923880}, {-0.707107, 0.707107},
141 {-0.923879, 0.382684}, {-1.000000, 0.000000}, {-0.923880, -0.382684}, {-0.707107, -0.707107},
142 {-0.382683, -0.923880}, {0.000000, -1.000000}, {0.382684, -0.923880}, {0.707107, -0.707107},
143 {0.923880, -0.382684}, {1.000000, -0.000000}, {0.923880, 0.382683}, {0.707107, 0.707107}};
144
145 static int scroll_circle_face[14][3]= {
146 {0, 1, 2}, {2, 0, 3}, {3, 0, 15}, {3, 15, 4}, {4, 15, 14}, {4, 14, 5}, {5, 14, 13}, {5, 13, 6}, 
147 {6, 13, 12}, {6, 12, 7}, {7, 12, 11}, {7, 11, 8}, {8, 11, 10}, {8, 10, 9}};
148
149 static float menu_tria_vert[6][2]= {
150 {-0.41, 0.16}, {0.41, 0.16}, {0, 0.82}, 
151 {0, -0.82}, {-0.41, -0.16}, {0.41, -0.16}};
152
153 static int menu_tria_face[2][3]= {{2, 0, 1}, {3, 5, 4}};
154
155 static float check_tria_vert[6][2]= {
156 {-0.578579, 0.253369},  {-0.392773, 0.412794},  {-0.004241, -0.328551}, 
157 {-0.003001, 0.034320},  {1.055313, 0.864744},   {0.866408, 1.026895}};
158
159 static int check_tria_face[4][3]= {
160 {3, 2, 4}, {3, 4, 5}, {1, 0, 3}, {0, 2, 3}};
161
162 GLubyte checker_stipple_sml[32*32/8] =
163 {
164         255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
165         255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
166         0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
167         0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
168         255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
169         255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0, \
170         0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
171         0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255, \
172 };
173
174 /* ************************************************* */
175
176 void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3)
177 {
178         float color[4];
179         int j;
180         
181         glEnable(GL_BLEND);
182         glGetFloatv(GL_CURRENT_COLOR, color);
183         color[3]*= 0.125;
184         glColor4fv(color);
185         
186         /* for each AA step */
187         for(j=0; j<8; j++) {
188                 glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f);
189
190                 glBegin(GL_POLYGON);
191                 glVertex2f(x1, y1);
192                 glVertex2f(x2, y2);
193                 glVertex2f(x3, y3);
194                 glEnd();
195                 
196                 glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f);
197         }
198
199         glDisable(GL_BLEND);
200         
201 }
202
203 static void widget_init(uiWidgetBase *wtb)
204 {
205         wtb->totvert= wtb->halfwayvert= 0;
206         wtb->tria1.tot= 0;
207         wtb->tria2.tot= 0;
208         
209         wtb->inner= 1;
210         wtb->outline= 1;
211         wtb->emboss= 1;
212         wtb->shadedir= 1;
213 }
214
215 /* helper call, makes shadow rect, with 'sun' above menu, so only shadow to left/right/bottom */
216 /* return tot */
217 static int round_box_shadow_edges(float (*vert)[2], rcti *rect, float rad, int roundboxalign, float step)
218 {
219         float vec[9][2];
220         float minx, miny, maxx, maxy;
221         int a, tot= 0;
222         
223         rad+= step;
224         
225         if(2.0f*rad > rect->ymax-rect->ymin)
226                 rad= 0.5f*(rect->ymax-rect->ymin);
227         
228         minx= rect->xmin-step;
229         miny= rect->ymin-step;
230         maxx= rect->xmax+step;
231         maxy= rect->ymax+step;
232         
233         /* mult */
234         for(a=0; a<9; a++) {
235                 vec[a][0]= rad*cornervec[a][0]; 
236                 vec[a][1]= rad*cornervec[a][1]; 
237         }
238         
239         /* start with left-top, anti clockwise */
240         if(roundboxalign & 1) {
241                 for(a=0; a<9; a++, tot++) {
242                         vert[tot][0]= minx+rad-vec[a][0];
243                         vert[tot][1]= maxy-vec[a][1];
244                 }
245         }
246         else {
247                 for(a=0; a<9; a++, tot++) {
248                         vert[tot][0]= minx;
249                         vert[tot][1]= maxy;
250                 }
251         }
252         
253         if(roundboxalign & 8) {
254                 for(a=0; a<9; a++, tot++) {
255                         vert[tot][0]= minx+vec[a][1];
256                         vert[tot][1]= miny+rad-vec[a][0];
257                 }
258         }
259         else {
260                 for(a=0; a<9; a++, tot++) {
261                         vert[tot][0]= minx;
262                         vert[tot][1]= miny;
263                 }
264         }
265         
266         if(roundboxalign & 4) {
267                 for(a=0; a<9; a++, tot++) {
268                         vert[tot][0]= maxx-rad+vec[a][0];
269                         vert[tot][1]= miny+vec[a][1];
270                 }
271         }
272         else {
273                 for(a=0; a<9; a++, tot++) {
274                         vert[tot][0]= maxx;
275                         vert[tot][1]= miny;
276                 }
277         }
278         
279         if(roundboxalign & 2) {
280                 for(a=0; a<9; a++, tot++) {
281                         vert[tot][0]= maxx-vec[a][1];
282                         vert[tot][1]= maxy-rad+vec[a][0];
283                 }
284         }
285         else {
286                 for(a=0; a<9; a++, tot++) {
287                         vert[tot][0]= maxx;
288                         vert[tot][1]= maxy;
289                 }
290         }
291         return tot;
292 }
293
294 /* this call has 1 extra arg to allow mask outline */
295 static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad, float radi)
296 {
297         float vec[9][2], veci[9][2];
298         float minx= rect->xmin, miny= rect->ymin, maxx= rect->xmax, maxy= rect->ymax;
299         float minxi= minx + 1.0f; /* boundbox inner */
300         float maxxi= maxx - 1.0f;
301         float minyi= miny + 1.0f;
302         float maxyi= maxy - 1.0f;
303         float facxi= (maxxi!=minxi) ? 1.0f/(maxxi-minxi) : 0.0f; /* for uv, can divide by zero */
304         float facyi= (maxyi!=minyi) ? 1.0f/(maxyi-minyi) : 0.0f;
305         int a, tot= 0, minsize;
306         const int hnum= ((roundboxalign & (1|2))==(1|2) || (roundboxalign & (4|8))==(4|8)) ? 1 : 2;
307         const int vnum= ((roundboxalign & (1|8))==(1|8) || (roundboxalign & (2|4))==(2|4)) ? 1 : 2;
308
309         minsize= MIN2((rect->xmax-rect->xmin)*hnum, (rect->ymax-rect->ymin)*vnum);
310         
311         if(2.0f*rad > minsize)
312                 rad= 0.5f*minsize;
313
314         if(2.0f*(radi+1.0f) > minsize)
315                 radi= 0.5f*minsize - 1.0f;
316         
317         /* mult */
318         for(a=0; a<9; a++) {
319                 veci[a][0]= radi*cornervec[a][0]; 
320                 veci[a][1]= radi*cornervec[a][1]; 
321                 vec[a][0]= rad*cornervec[a][0]; 
322                 vec[a][1]= rad*cornervec[a][1]; 
323         }
324         
325         /* corner left-bottom */
326         if(roundboxalign & 8) {
327                 
328                 for(a=0; a<9; a++, tot++) {
329                         wt->inner_v[tot][0]= minxi+veci[a][1];
330                         wt->inner_v[tot][1]= minyi+radi-veci[a][0];
331                         
332                         wt->outer_v[tot][0]= minx+vec[a][1];
333                         wt->outer_v[tot][1]= miny+rad-vec[a][0];
334                         
335                         wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
336                         wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
337                 }
338         }
339         else {
340                 wt->inner_v[tot][0]= minxi;
341                 wt->inner_v[tot][1]= minyi;
342                 
343                 wt->outer_v[tot][0]= minx;
344                 wt->outer_v[tot][1]= miny;
345
346                 wt->inner_uv[tot][0]= 0.0f;
347                 wt->inner_uv[tot][1]= 0.0f;
348                 
349                 tot++;
350         }
351         
352         /* corner right-bottom */
353         if(roundboxalign & 4) {
354                 
355                 for(a=0; a<9; a++, tot++) {
356                         wt->inner_v[tot][0]= maxxi-radi+veci[a][0];
357                         wt->inner_v[tot][1]= minyi+veci[a][1];
358                         
359                         wt->outer_v[tot][0]= maxx-rad+vec[a][0];
360                         wt->outer_v[tot][1]= miny+vec[a][1];
361                         
362                         wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
363                         wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
364                 }
365         }
366         else {
367                 wt->inner_v[tot][0]= maxxi;
368                 wt->inner_v[tot][1]= minyi;
369                 
370                 wt->outer_v[tot][0]= maxx;
371                 wt->outer_v[tot][1]= miny;
372
373                 wt->inner_uv[tot][0]= 1.0f;
374                 wt->inner_uv[tot][1]= 0.0f;
375                 
376                 tot++;
377         }
378         
379         wt->halfwayvert= tot;
380         
381         /* corner right-top */
382         if(roundboxalign & 2) {
383                 
384                 for(a=0; a<9; a++, tot++) {
385                         wt->inner_v[tot][0]= maxxi-veci[a][1];
386                         wt->inner_v[tot][1]= maxyi-radi+veci[a][0];
387                         
388                         wt->outer_v[tot][0]= maxx-vec[a][1];
389                         wt->outer_v[tot][1]= maxy-rad+vec[a][0];
390                         
391                         wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
392                         wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
393                 }
394         }
395         else {
396                 wt->inner_v[tot][0]= maxxi;
397                 wt->inner_v[tot][1]= maxyi;
398                 
399                 wt->outer_v[tot][0]= maxx;
400                 wt->outer_v[tot][1]= maxy;
401                 
402                 wt->inner_uv[tot][0]= 1.0f;
403                 wt->inner_uv[tot][1]= 1.0f;
404                 
405                 tot++;
406         }
407         
408         /* corner left-top */
409         if(roundboxalign & 1) {
410                 
411                 for(a=0; a<9; a++, tot++) {
412                         wt->inner_v[tot][0]= minxi+radi-veci[a][0];
413                         wt->inner_v[tot][1]= maxyi-veci[a][1];
414                         
415                         wt->outer_v[tot][0]= minx+rad-vec[a][0];
416                         wt->outer_v[tot][1]= maxy-vec[a][1];
417                         
418                         wt->inner_uv[tot][0]= facxi*(wt->inner_v[tot][0] - minxi);
419                         wt->inner_uv[tot][1]= facyi*(wt->inner_v[tot][1] - minyi);
420                 }
421                 
422         }
423         else {
424                 
425                 wt->inner_v[tot][0]= minxi;
426                 wt->inner_v[tot][1]= maxyi;
427                 
428                 wt->outer_v[tot][0]= minx;
429                 wt->outer_v[tot][1]= maxy;
430                 
431                 wt->inner_uv[tot][0]= 0.0f;
432                 wt->inner_uv[tot][1]= 1.0f;
433                 
434                 tot++;
435         }
436                 
437         wt->totvert= tot;
438 }
439
440 static void round_box_edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, float rad)
441 {
442         round_box__edges(wt, roundboxalign, rect, rad, rad-1.0f);
443 }
444
445
446 /* based on button rect, return scaled array of triangles */
447 static void widget_num_tria(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
448 {
449         float centx, centy, sizex, sizey, minsize;
450         int a, i1=0, i2=1;
451         
452         minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
453         
454         /* center position and size */
455         centx= (float)rect->xmin + 0.5f*minsize;
456         centy= (float)rect->ymin + 0.5f*minsize;
457         sizex= sizey= -0.5f*triasize*minsize;
458
459         if(where=='r') {
460                 centx= (float)rect->xmax - 0.5f*minsize;
461                 sizex= -sizex;
462         }       
463         else if(where=='t') {
464                 centy= (float)rect->ymax - 0.5f*minsize;
465                 sizey= -sizey;
466                 i2=0; i1= 1;
467         }       
468         else if(where=='b') {
469                 sizex= -sizex;
470                 i2=0; i1= 1;
471         }       
472         
473         for(a=0; a<3; a++) {
474                 tria->vec[a][0]= sizex*num_tria_vert[a][i1] + centx;
475                 tria->vec[a][1]= sizey*num_tria_vert[a][i2] + centy;
476         }
477         
478         tria->tot= 1;
479         tria->index= num_tria_face;
480 }
481
482 static void widget_scroll_circle(uiWidgetTrias *tria, rcti *rect, float triasize, char where)
483 {
484         float centx, centy, sizex, sizey, minsize;
485         int a, i1=0, i2=1;
486         
487         minsize= MIN2(rect->xmax-rect->xmin, rect->ymax-rect->ymin);
488         
489         /* center position and size */
490         centx= (float)rect->xmin + 0.5f*minsize;
491         centy= (float)rect->ymin + 0.5f*minsize;
492         sizex= sizey= -0.5f*triasize*minsize;
493
494         if(where=='r') {
495                 centx= (float)rect->xmax - 0.5f*minsize;
496                 sizex= -sizex;
497         }       
498         else if(where=='t') {
499                 centy= (float)rect->ymax - 0.5f*minsize;
500                 sizey= -sizey;
501                 i2=0; i1= 1;
502         }       
503         else if(where=='b') {
504                 sizex= -sizex;
505                 i2=0; i1= 1;
506         }       
507         
508         for(a=0; a<16; a++) {
509                 tria->vec[a][0]= sizex*scroll_circle_vert[a][i1] + centx;
510                 tria->vec[a][1]= sizey*scroll_circle_vert[a][i2] + centy;
511         }
512         
513         tria->tot= 14;
514         tria->index= scroll_circle_face;
515 }
516
517 static void widget_trias_draw(uiWidgetTrias *tria)
518 {
519         int a;
520         
521         glBegin(GL_TRIANGLES);
522         for(a=0; a<tria->tot; a++) {
523                 glVertex2fv(tria->vec[ tria->index[a][0] ]);
524                 glVertex2fv(tria->vec[ tria->index[a][1] ]);
525                 glVertex2fv(tria->vec[ tria->index[a][2] ]);
526         }
527         glEnd();
528         
529 }
530
531 static void widget_menu_trias(uiWidgetTrias *tria, rcti *rect)
532 {
533         float centx, centy, size, asp;
534         int a;
535                 
536         /* center position and size */
537         centx= rect->xmax - 0.5f*(rect->ymax-rect->ymin);
538         centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
539         size= 0.4f*(rect->ymax-rect->ymin);
540         
541         /* XXX exception */
542         asp= ((float)rect->xmax-rect->xmin)/((float)rect->ymax-rect->ymin);
543         if(asp > 1.2f && asp < 2.6f)
544                 centx= rect->xmax - 0.3f*(rect->ymax-rect->ymin);
545         
546         for(a=0; a<6; a++) {
547                 tria->vec[a][0]= size*menu_tria_vert[a][0] + centx;
548                 tria->vec[a][1]= size*menu_tria_vert[a][1] + centy;
549         }
550
551         tria->tot= 2;
552         tria->index= menu_tria_face;
553 }
554
555 static void widget_check_trias(uiWidgetTrias *tria, rcti *rect)
556 {
557         float centx, centy, size;
558         int a;
559         
560         /* center position and size */
561         centx= rect->xmin + 0.5f*(rect->ymax-rect->ymin);
562         centy= rect->ymin + 0.5f*(rect->ymax-rect->ymin);
563         size= 0.5f*(rect->ymax-rect->ymin);
564         
565         for(a=0; a<6; a++) {
566                 tria->vec[a][0]= size*check_tria_vert[a][0] + centx;
567                 tria->vec[a][1]= size*check_tria_vert[a][1] + centy;
568         }
569         
570         tria->tot= 4;
571         tria->index= check_tria_face;
572 }
573
574
575 /* prepares shade colors */
576 static void shadecolors4(char *coltop, char *coldown, const char *color, short shadetop, short shadedown)
577 {
578         
579         coltop[0]= CLAMPIS(color[0]+shadetop, 0, 255);
580         coltop[1]= CLAMPIS(color[1]+shadetop, 0, 255);
581         coltop[2]= CLAMPIS(color[2]+shadetop, 0, 255);
582         coltop[3]= color[3];
583
584         coldown[0]= CLAMPIS(color[0]+shadedown, 0, 255);
585         coldown[1]= CLAMPIS(color[1]+shadedown, 0, 255);
586         coldown[2]= CLAMPIS(color[2]+shadedown, 0, 255);
587         coldown[3]= color[3];   
588 }
589
590 static void round_box_shade_col4(const char col1[4], const char col2[4], const float fac)
591 {
592         unsigned char col[4];
593         const int faci= FTOCHAR(fac);
594         const int facm= 255-faci;
595
596         col[0]= (faci*col1[0] + facm*col2[0])>>8;
597         col[1]= (faci*col1[1] + facm*col2[1])>>8;
598         col[2]= (faci*col1[2] + facm*col2[2])>>8;
599         col[3]= (faci*col1[3] + facm*col2[3])>>8;
600
601         glColor4ubv(col);
602 }
603
604 static void widgetbase_outline(uiWidgetBase *wtb)
605 {
606         int a;
607         
608         /* outline */
609         glBegin(GL_QUAD_STRIP);
610         for(a=0; a<wtb->totvert; a++) {
611                 glVertex2fv(wtb->outer_v[a]);
612                 glVertex2fv(wtb->inner_v[a]);
613         }
614         glVertex2fv(wtb->outer_v[0]);
615         glVertex2fv(wtb->inner_v[0]);
616         glEnd();
617 }
618
619 static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
620 {
621         int j, a;
622         
623         glEnable(GL_BLEND);
624
625         /* backdrop non AA */
626         if(wtb->inner) {
627                 if(wcol->shaded==0) {
628                         if (wcol->alpha_check) {
629                                 float x_mid= 0.0f; /* used for dumb clamping of values */
630
631                                 /* dark checkers */
632                                 glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
633                                 glBegin(GL_POLYGON);
634                                 for(a=0; a<wtb->totvert; a++) {
635                                         glVertex2fv(wtb->inner_v[a]);
636                                 }
637                                 glEnd();
638
639                                 /* light checkers */
640                                 glEnable(GL_POLYGON_STIPPLE);
641                                 glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
642                                 glPolygonStipple(checker_stipple_sml);
643                                 glBegin(GL_POLYGON);
644                                 for(a=0; a<wtb->totvert; a++) {
645                                         glVertex2fv(wtb->inner_v[a]);
646                                 }
647                                 glEnd();
648                                 glDisable(GL_POLYGON_STIPPLE);
649
650                                 /* alpha fill */
651                                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
652
653                                 glColor4ubv((unsigned char*)wcol->inner);
654                                 glBegin(GL_POLYGON);
655                                 for(a=0; a<wtb->totvert; a++) {
656                                         glVertex2fv(wtb->inner_v[a]);
657                                         x_mid += wtb->inner_v[a][0];
658                                 }
659                                 x_mid /= wtb->totvert;
660                                 glEnd();
661
662                                 /* 1/2 solid color */
663                                 glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
664                                 glBegin(GL_POLYGON);
665                                 for(a=0; a<wtb->totvert; a++)
666                                         glVertex2f(MIN2(wtb->inner_v[a][0], x_mid), wtb->inner_v[a][1]);
667                                 glEnd();
668                         }
669                         else {
670                                 /* simple fill */
671                                 glColor4ubv((unsigned char*)wcol->inner);
672                                 glBegin(GL_POLYGON);
673                                 for(a=0; a<wtb->totvert; a++)
674                                         glVertex2fv(wtb->inner_v[a]);
675                                 glEnd();
676                         }
677                 }
678                 else {
679                         char col1[4], col2[4];
680                         
681                         shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown);
682                         
683                         glShadeModel(GL_SMOOTH);
684                         glBegin(GL_POLYGON);
685                         for(a=0; a<wtb->totvert; a++) {
686                                 round_box_shade_col4(col1, col2, wtb->inner_uv[a][wtb->shadedir]);
687                                 glVertex2fv(wtb->inner_v[a]);
688                         }
689                         glEnd();
690                         glShadeModel(GL_FLAT);
691                 }
692         }
693         
694         /* for each AA step */
695         if(wtb->outline) {
696                 for(j=0; j<8; j++) {
697                         glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f);
698                         
699                         /* outline */
700                         glColor4ub(wcol->outline[0], wcol->outline[1], wcol->outline[2], 32);
701                         glBegin(GL_QUAD_STRIP);
702                         for(a=0; a<wtb->totvert; a++) {
703                                 glVertex2fv(wtb->outer_v[a]);
704                                 glVertex2fv(wtb->inner_v[a]);
705                         }
706                         glVertex2fv(wtb->outer_v[0]);
707                         glVertex2fv(wtb->inner_v[0]);
708                         glEnd();
709                 
710                         /* emboss bottom shadow */
711                         if(wtb->emboss) {
712                                 glColor4f(1.0f, 1.0f, 1.0f, 0.02f);
713                                 glBegin(GL_QUAD_STRIP);
714                                 for(a=0; a<wtb->halfwayvert; a++) {
715                                         glVertex2fv(wtb->outer_v[a]);
716                                         glVertex2f(wtb->outer_v[a][0], wtb->outer_v[a][1]-1.0f);
717                                 }
718                                 glEnd();
719                         }
720                         
721                         glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f);
722                 }
723         }
724         
725         /* decoration */
726         if(wtb->tria1.tot || wtb->tria2.tot) {
727                 /* for each AA step */
728                 for(j=0; j<8; j++) {
729                         glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f);
730
731                         if(wtb->tria1.tot) {
732                                 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
733                                 widget_trias_draw(&wtb->tria1);
734                         }
735                         if(wtb->tria2.tot) {
736                                 glColor4ub(wcol->item[0], wcol->item[1], wcol->item[2], 32);
737                                 widget_trias_draw(&wtb->tria2);
738                         }
739                 
740                         glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f);
741                 }
742         }
743
744         glDisable(GL_BLEND);
745         
746 }
747
748 /* *********************** text/icon ************************************** */
749
750 #define PREVIEW_PAD     4
751
752 static void widget_draw_preview(BIFIconID icon, float UNUSED(alpha), rcti *rect)
753 {
754         int w, h, size;
755
756         if(icon==ICON_NONE)
757                 return;
758
759         w = rect->xmax - rect->xmin;
760         h = rect->ymax - rect->ymin;
761         size = MIN2(w, h);
762         size -= PREVIEW_PAD*2;  /* padding */
763
764         if(size > 0) {
765                 int x = rect->xmin + w/2 - size/2;
766                 int y = rect->ymin + h/2 - size/2;
767
768                 UI_icon_draw_preview_aspect_size(x, y, icon, 1.0f, size);
769         }
770 }
771
772
773 /* icons have been standardized... and this call draws in untransformed coordinates */
774
775 static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect)
776 {
777         int xs=0, ys=0;
778         float aspect, height;
779         
780         if (but->flag & UI_ICON_PREVIEW) {
781                 widget_draw_preview(icon, alpha, rect);
782                 return;
783         }
784         
785         /* this icon doesn't need draw... */
786         if(icon==ICON_BLANK1 && (but->flag & UI_ICON_SUBMENU)==0) return;
787         
788         /* we need aspect from block, for menus... these buttons are scaled in uiPositionBlock() */
789         aspect= but->block->aspect;
790         if(aspect != but->aspect) {
791                 /* prevent scaling up icon in pupmenu */
792                 if (aspect < 1.0f) {                    
793                         height= UI_DPI_ICON_SIZE;
794                         aspect = 1.0f;
795                         
796                 }
797                 else 
798                         height= UI_DPI_ICON_SIZE/aspect;
799         }
800         else
801                 height= UI_DPI_ICON_SIZE;
802         
803         /* calculate blend color */
804         if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) {
805                 if(but->flag & UI_SELECT);
806                 else if(but->flag & UI_ACTIVE);
807                 else alpha= 0.5f;
808         }
809         
810         /* extra feature allows more alpha blending */
811         if(but->type==LABEL && but->a1==1.0f) alpha *= but->a2;
812         
813         glEnable(GL_BLEND);
814         
815         if(icon && icon!=ICON_BLANK1) {
816                 if(but->flag & UI_ICON_LEFT) {
817                         if (but->type==BUT_TOGDUAL) {
818                                 if (but->drawstr[0]) {
819                                         xs= rect->xmin-1;
820                                 } else {
821                                         xs= (rect->xmin+rect->xmax- height)/2;
822                                 }
823                         }
824                         else if (but->block->flag & UI_BLOCK_LOOP) {
825                                 if(but->type==SEARCH_MENU)
826                                         xs= rect->xmin+4;
827                                 else
828                                         xs= rect->xmin+1;
829                         }
830                         else if ((but->type==ICONROW) || (but->type==ICONTEXTROW)) {
831                                 xs= rect->xmin+3;
832                         }
833                         else {
834                                 xs= rect->xmin+4;
835                         }
836                         ys= (rect->ymin+rect->ymax- height)/2;
837                 }
838                 else {
839                         xs= (rect->xmin+rect->xmax- height)/2;
840                         ys= (rect->ymin+rect->ymax- height)/2;
841                 }
842                 
843                 /* to indicate draggable */
844                 if(but->dragpoin && (but->flag & UI_ACTIVE)) {
845                         float rgb[3]= {1.25f, 1.25f, 1.25f};
846                         UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb);
847                 }
848                 else
849                         UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
850         }
851         
852         if(but->flag & UI_ICON_SUBMENU) {
853                 xs= rect->xmax-17;
854                 ys= (rect->ymin+rect->ymax- height)/2;
855                 
856                 UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, aspect, alpha);
857         }
858         
859         glDisable(GL_BLEND);
860 }
861
862 /* sets but->ofs to make sure text is correctly visible */
863 static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
864 {
865         int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
866         int okwidth= rect->xmax-rect->xmin - border;
867         
868         if (but->flag & UI_HAS_ICON) okwidth -= UI_DPI_ICON_SIZE;
869         
870         /* need to set this first */
871         uiStyleFontSet(fstyle);
872         
873         if (fstyle->kerning==1) /* for BLF_width */
874                 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
875
876         /* if text editing we define ofs dynamically */
877         if(but->editstr && but->pos >= 0) {
878                 if(but->ofs > but->pos)
879                         but->ofs= but->pos;
880         }
881         else but->ofs= 0;
882         
883         but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
884         
885         while(but->strwidth > okwidth) {
886                 
887                 /* textbut exception, clip right when... */
888                 if(but->editstr && but->pos >= 0) {
889                         float width;
890                         char buf[UI_MAX_DRAW_STR];
891                         
892                         /* copy draw string */
893                         BLI_strncpy(buf, but->drawstr, sizeof(buf));
894                         /* string position of cursor */
895                         buf[but->pos]= 0;
896                         width= BLF_width(fstyle->uifont_id, buf+but->ofs);
897                         
898                         /* if cursor is at 20 pixels of right side button we clip left */
899                         if(width > okwidth-20)
900                                 but->ofs++;
901                         else {
902                                 /* shift string to the left */
903                                 if(width < 20 && but->ofs > 0)
904                                         but->ofs--;
905                                 but->drawstr[ strlen(but->drawstr)-1 ]= 0;
906                         }
907                 }
908                 else
909                         but->ofs++;
910
911                 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
912                 
913                 if(but->strwidth < 10) break;
914         }
915         
916         if (fstyle->kerning==1)
917                 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
918 }
919
920 static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
921 {
922         int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
923         int okwidth= rect->xmax-rect->xmin - border;
924         char *cpoin=NULL;
925         char *cpend = but->drawstr + strlen(but->drawstr);
926         
927         /* need to set this first */
928         uiStyleFontSet(fstyle);
929         
930         if (fstyle->kerning==1) /* for BLF_width */
931                 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
932         
933         but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr);
934         but->ofs= 0;
935         
936         /* find the space after ':' separator */
937         cpoin= strrchr(but->drawstr, ':');
938         
939         if (cpoin && (cpoin < cpend-2)) {
940                 char *cp2 = cpoin;
941                 
942                 /* chop off the leading text, starting from the right */
943                 while (but->strwidth > okwidth && cp2 > but->drawstr) {
944                         /* shift the text after and including cp2 back by 1 char, +1 to include null terminator */
945                         memmove(cp2-1, cp2, strlen(cp2)+1);
946                         cp2--;
947                         
948                         but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
949                         if(but->strwidth < 10) break;
950                 }
951         
952         
953                 /* after the leading text is gone, chop off the : and following space, with ofs */
954                 while ((but->strwidth > okwidth) && (but->ofs < 2))
955                 {
956                         but->ofs++;
957                         but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
958                         if(but->strwidth < 10) break;
959                 }
960                 
961         }
962
963         /* once the label's gone, chop off the least significant digits */
964         while(but->strwidth > okwidth ) {
965                 int pos= strlen(but->drawstr);
966                 
967                 but->drawstr[ pos-1 ] = 0;
968                 pos--;
969                 
970                 but->strwidth= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
971                 if(but->strwidth < 10) break;
972         }
973         
974         if (fstyle->kerning==1)
975                 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
976 }
977
978
979 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
980 {
981 //      int transopts;
982         char *cpoin = NULL;
983         
984         /* for underline drawing */
985         float font_xofs, font_yofs;
986
987         uiStyleFontSet(fstyle);
988         
989         if(but->editstr || (but->flag & UI_TEXT_LEFT))
990                 fstyle->align= UI_STYLE_TEXT_LEFT;
991         else
992                 fstyle->align= UI_STYLE_TEXT_CENTER;                    
993         
994         if (fstyle->kerning==1) /* for BLF_width */
995                 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
996         
997         /* text button selection and cursor */
998         if(but->editstr && but->pos != -1) {
999                 short t=0, pos=0, ch;
1000                 short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
1001
1002                 if ((but->selend - but->selsta) > 0) {
1003                         /* text button selection */
1004                         selsta_tmp = but->selsta;
1005                         selend_tmp = but->selend;
1006                         
1007                         if(but->drawstr[0]!=0) {
1008
1009                                 if (but->selsta >= but->ofs) {
1010                                         ch= but->drawstr[selsta_tmp];
1011                                         but->drawstr[selsta_tmp]= 0;
1012                                         
1013                                         selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
1014                                         
1015                                         but->drawstr[selsta_tmp]= ch;
1016                                 } else
1017                                         selsta_draw = 0;
1018                                 
1019                                 ch= but->drawstr[selend_tmp];
1020                                 but->drawstr[selend_tmp]= 0;
1021                                 
1022                                 selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr+but->ofs);
1023                                 
1024                                 but->drawstr[selend_tmp]= ch;
1025
1026                                 glColor3ubv((unsigned char*)wcol->item);
1027                                 glRects(rect->xmin+selsta_draw, rect->ymin+2, rect->xmin+selwidth_draw, rect->ymax-2);
1028                         }
1029                 } else {
1030                         /* text cursor */
1031                         pos= but->pos;
1032                         if(pos >= but->ofs) {
1033                                 if(but->drawstr[0]!=0) {
1034                                         ch= but->drawstr[pos];
1035                                         but->drawstr[pos]= 0;
1036                                         
1037                                         t= BLF_width(fstyle->uifont_id, but->drawstr+but->ofs) / but->aspect;
1038                                         
1039                                         but->drawstr[pos]= ch;
1040                                 }
1041
1042                                 glColor3f(0.20, 0.6, 0.9);
1043                                 glRects(rect->xmin+t, rect->ymin+2, rect->xmin+t+2, rect->ymax-2);
1044                         }
1045                 }
1046         }
1047         
1048         if (fstyle->kerning == 1)
1049                 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1050         
1051         //      ui_rasterpos_safe(x, y, but->aspect);
1052 //      if(but->type==IDPOIN) transopts= 0;     // no translation, of course!
1053 //      else transopts= ui_translate_buttons();
1054         
1055         /* cut string in 2 parts - only for menu entries */
1056         if((but->block->flag & UI_BLOCK_LOOP)) {
1057                 if(ELEM5(but->type, SLI, NUM, TEX, NUMSLI, NUMABS)==0) {
1058                         cpoin= strchr(but->drawstr, '|');
1059                         if(cpoin) *cpoin= 0;            
1060                 }
1061         }
1062         
1063         glColor3ubv((unsigned char*)wcol->text);
1064
1065         uiStyleFontDrawExt(fstyle, rect, but->drawstr+but->ofs, &font_xofs, &font_yofs);
1066
1067         if(but->menu_key != '\0') {
1068                 char fixedbuf[128];
1069                 char *str;
1070
1071                 BLI_strncpy(fixedbuf, but->drawstr + but->ofs, sizeof(fixedbuf));
1072
1073                 str= strchr(fixedbuf, but->menu_key-32); /* upper case */
1074                 if(str==NULL)
1075                         str= strchr(fixedbuf, but->menu_key);
1076
1077                 if(str) {
1078                         int ul_index= -1;
1079                         float ul_advance;
1080
1081                         ul_index= (int)(str - fixedbuf);
1082
1083                         if (fstyle->kerning == 1) {
1084                                 BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1085                         }
1086
1087                         fixedbuf[ul_index]= '\0';
1088                         ul_advance= BLF_width(fstyle->uifont_id, fixedbuf);
1089
1090                         BLF_position(fstyle->uifont_id, rect->xmin+font_xofs + ul_advance, rect->ymin+font_yofs, 0.0f);
1091                         BLF_draw(fstyle->uifont_id, "_", 2);
1092
1093                         if (fstyle->kerning == 1) {
1094                                 BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
1095                         }
1096                 }
1097         }
1098
1099         /* part text right aligned */
1100         if(cpoin) {
1101                 fstyle->align= UI_STYLE_TEXT_RIGHT;
1102                 rect->xmax-=5;
1103                 uiStyleFontDraw(fstyle, rect, cpoin+1);
1104                 *cpoin= '|';
1105         }
1106 }
1107
1108 /* draws text and icons for buttons */
1109 static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
1110 {
1111         
1112         if(but==NULL) return;
1113
1114         /* clip but->drawstr to fit in available space */
1115         if (but->editstr && but->pos >= 0) {
1116                 ui_text_leftclip(fstyle, but, rect);
1117         }
1118         else if (ELEM4(but->type, NUM, NUMABS, NUMSLI, SLI)) {
1119                 ui_text_label_rightclip(fstyle, but, rect);
1120         }
1121         else if (ELEM(but->type, TEX, SEARCH_MENU)) {
1122                 ui_text_leftclip(fstyle, but, rect);
1123         }
1124         else if ((but->block->flag & UI_BLOCK_LOOP) && (but->type == BUT)) {
1125                 ui_text_leftclip(fstyle, but, rect);
1126         }
1127         else but->ofs= 0;
1128         
1129         /* check for button text label */
1130         if (but->type == ICONTEXTROW) {
1131                 widget_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 1.0f, rect);
1132         }
1133         else {
1134                                 
1135                 if(but->type==BUT_TOGDUAL) {
1136                         int dualset= 0;
1137                         if(but->pointype==SHO)
1138                                 dualset= BTST( *(((short *)but->poin)+1), but->bitnr);
1139                         else if(but->pointype==INT)
1140                                 dualset= BTST( *(((int *)but->poin)+1), but->bitnr);
1141                         
1142                         widget_draw_icon(but, ICON_DOT, dualset?1.0f:0.25f, rect);
1143                 }
1144                 
1145                 /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
1146                 and offset the text label to accommodate it */
1147                 
1148                 if (but->flag & UI_HAS_ICON) {
1149                         widget_draw_icon(but, but->icon+but->iconadd, 1.0f, rect);
1150                         
1151                         rect->xmin += (int)((float)UI_icon_get_width(but->icon+but->iconadd) * UI_DPI_ICON_FAC);
1152                         
1153                         if(but->editstr || (but->flag & UI_TEXT_LEFT)) 
1154                                 rect->xmin += 5;
1155                 }
1156                 else if((but->flag & UI_TEXT_LEFT)) 
1157                         rect->xmin += 5;
1158                 
1159                 /* always draw text for textbutton cursor */
1160                 widget_draw_text(fstyle, wcol, but, rect);
1161
1162         }
1163 }
1164
1165
1166
1167 /* *********************** widget types ************************************* */
1168
1169
1170 /*   uiWidgetStateColors
1171         char inner_anim[4];
1172         char inner_anim_sel[4];
1173         char inner_key[4];
1174         char inner_key_sel[4];
1175         char inner_driven[4];
1176         char inner_driven_sel[4];
1177         float blend;
1178  
1179 */
1180
1181 static struct uiWidgetStateColors wcol_state_colors= {
1182         {115, 190, 76, 255},
1183         {90, 166, 51, 255},
1184         {240, 235, 100, 255},
1185         {215, 211, 75, 255},
1186         {180, 0, 255, 255},
1187         {153, 0, 230, 255},
1188         0.5f, 0.0f
1189 };
1190
1191 /*  uiWidgetColors
1192         float outline[3];
1193         float inner[4];
1194         float inner_sel[4];
1195         float item[3];
1196         float text[3];
1197         float text_sel[3];
1198
1199         short shaded;
1200         float shadetop, shadedown;
1201 */      
1202
1203 static struct uiWidgetColors wcol_num= {
1204         {25, 25, 25, 255},
1205         {180, 180, 180, 255},
1206         {153, 153, 153, 255},
1207         {90, 90, 90, 255},
1208         
1209         {0, 0, 0, 255},
1210         {255, 255, 255, 255},
1211         
1212         1,
1213         -20, 0
1214 };
1215
1216 static struct uiWidgetColors wcol_numslider= {
1217         {25, 25, 25, 255},
1218         {180, 180, 180, 255},
1219         {153, 153, 153, 255},
1220         {128, 128, 128, 255},
1221         
1222         {0, 0, 0, 255},
1223         {255, 255, 255, 255},
1224         
1225         1,
1226         -20, 0
1227 };
1228
1229 static struct uiWidgetColors wcol_text= {
1230         {25, 25, 25, 255},
1231         {153, 153, 153, 255},
1232         {153, 153, 153, 255},
1233         {90, 90, 90, 255},
1234         
1235         {0, 0, 0, 255},
1236         {255, 255, 255, 255},
1237         
1238         1,
1239         0, 25
1240 };
1241
1242 static struct uiWidgetColors wcol_option= {
1243         {0, 0, 0, 255},
1244         {70, 70, 70, 255},
1245         {70, 70, 70, 255},
1246         {255, 255, 255, 255},
1247         
1248         {0, 0, 0, 255},
1249         {255, 255, 255, 255},
1250         
1251         1,
1252         15, -15
1253 };
1254
1255 /* button that shows popup */
1256 static struct uiWidgetColors wcol_menu= {
1257         {0, 0, 0, 255},
1258         {70, 70, 70, 255},
1259         {70, 70, 70, 255},
1260         {255, 255, 255, 255},
1261         
1262         {255, 255, 255, 255},
1263         {204, 204, 204, 255},
1264         
1265         1,
1266         15, -15
1267 };
1268
1269 /* button that starts pulldown */
1270 static struct uiWidgetColors wcol_pulldown= {
1271         {0, 0, 0, 255},
1272         {63, 63, 63, 255},
1273         {86, 128, 194, 255},
1274         {255, 255, 255, 255},
1275         
1276         {0, 0, 0, 255},
1277         {0, 0, 0, 255},
1278         
1279         0,
1280         25, -20
1281 };
1282
1283 /* button inside menu */
1284 static struct uiWidgetColors wcol_menu_item= {
1285         {0, 0, 0, 255},
1286         {0, 0, 0, 0},
1287         {86, 128, 194, 255},
1288         {255, 255, 255, 255},
1289         
1290         {255, 255, 255, 255},
1291         {0, 0, 0, 255},
1292         
1293         1,
1294         38, 0
1295 };
1296
1297 /* backdrop menu + title text color */
1298 static struct uiWidgetColors wcol_menu_back= {
1299         {0, 0, 0, 255},
1300         {25, 25, 25, 230},
1301         {45, 45, 45, 230},
1302         {100, 100, 100, 255},
1303         
1304         {160, 160, 160, 255},
1305         {255, 255, 255, 255},
1306         
1307         0,
1308         25, -20
1309 };
1310
1311
1312 static struct uiWidgetColors wcol_radio= {
1313         {0, 0, 0, 255},
1314         {70, 70, 70, 255},
1315         {86, 128, 194, 255},
1316         {255, 255, 255, 255},
1317         
1318         {255, 255, 255, 255},
1319         {0, 0, 0, 255},
1320         
1321         1,
1322         15, -15
1323 };
1324
1325 static struct uiWidgetColors wcol_regular= {
1326         {25, 25, 25, 255},
1327         {153, 153, 153, 255},
1328         {100, 100, 100, 255},
1329         {25, 25, 25, 255},
1330         
1331         {0, 0, 0, 255},
1332         {255, 255, 255, 255},
1333         
1334         0,
1335         0, 0
1336 };
1337
1338 static struct uiWidgetColors wcol_tool= {
1339         {25, 25, 25, 255},
1340         {153, 153, 153, 255},
1341         {100, 100, 100, 255},
1342         {25, 25, 25, 255},
1343         
1344         {0, 0, 0, 255},
1345         {255, 255, 255, 255},
1346         
1347         1,
1348         15, -15
1349 };
1350
1351 static struct uiWidgetColors wcol_box= {
1352         {25, 25, 25, 255},
1353         {128, 128, 128, 255},
1354         {100, 100, 100, 255},
1355         {25, 25, 25, 255},
1356         
1357         {0, 0, 0, 255},
1358         {255, 255, 255, 255},
1359         
1360         0,
1361         0, 0
1362 };
1363
1364 static struct uiWidgetColors wcol_toggle= {
1365         {25, 25, 25, 255},
1366         {153, 153, 153, 255},
1367         {100, 100, 100, 255},
1368         {25, 25, 25, 255},
1369         
1370         {0, 0, 0, 255},
1371         {255, 255, 255, 255},
1372         
1373         0,
1374         0, 0
1375 };
1376
1377 static struct uiWidgetColors wcol_scroll= {
1378         {50, 50, 50, 180},
1379         {80, 80, 80, 180},
1380         {100, 100, 100, 180},
1381         {128, 128, 128, 255},
1382         
1383         {0, 0, 0, 255},
1384         {255, 255, 255, 255},
1385         
1386         1,
1387         5, -5
1388 };
1389
1390 static struct uiWidgetColors wcol_progress= {
1391         {0, 0, 0, 255},
1392         {190, 190, 190, 255},
1393         {100, 100, 100, 180},
1394         {68, 68, 68, 255},
1395         
1396         {0, 0, 0, 255},
1397         {255, 255, 255, 255},
1398         
1399         0,
1400         0, 0
1401 };
1402
1403 static struct uiWidgetColors wcol_list_item= {
1404         {0, 0, 0, 255},
1405         {0, 0, 0, 0},
1406         {86, 128, 194, 255},
1407         {0, 0, 0, 255},
1408         
1409         {0, 0, 0, 255},
1410         {0, 0, 0, 255},
1411         
1412         0,
1413         0, 0
1414 };
1415
1416 /* free wcol struct to play with */
1417 static struct uiWidgetColors wcol_tmp= {
1418         {0, 0, 0, 255},
1419         {128, 128, 128, 255},
1420         {100, 100, 100, 255},
1421         {25, 25, 25, 255},
1422         
1423         {0, 0, 0, 255},
1424         {255, 255, 255, 255},
1425         
1426         0,
1427         0, 0
1428 };
1429
1430
1431 /* called for theme init (new theme) and versions */
1432 void ui_widget_color_init(ThemeUI *tui)
1433 {
1434         tui->wcol_regular= wcol_regular;
1435         tui->wcol_tool= wcol_tool;
1436         tui->wcol_text= wcol_text;
1437         tui->wcol_radio= wcol_radio;
1438         tui->wcol_option= wcol_option;
1439         tui->wcol_toggle= wcol_toggle;
1440         tui->wcol_num= wcol_num;
1441         tui->wcol_numslider= wcol_numslider;
1442         tui->wcol_menu= wcol_menu;
1443         tui->wcol_pulldown= wcol_pulldown;
1444         tui->wcol_menu_back= wcol_menu_back;
1445         tui->wcol_menu_item= wcol_menu_item;
1446         tui->wcol_box= wcol_box;
1447         tui->wcol_scroll= wcol_scroll;
1448         tui->wcol_list_item= wcol_list_item;
1449         tui->wcol_progress= wcol_progress;
1450
1451         tui->wcol_state= wcol_state_colors;
1452 }
1453
1454 /* ************ button callbacks, state ***************** */
1455
1456 static void widget_state_blend(char *cp, const char *cpstate, const float fac)
1457 {
1458         if(fac != 0.0f) {
1459                 cp[0]= (int)((1.0f-fac)*cp[0] + fac*cpstate[0]);
1460                 cp[1]= (int)((1.0f-fac)*cp[1] + fac*cpstate[1]);
1461                 cp[2]= (int)((1.0f-fac)*cp[2] + fac*cpstate[2]);
1462         }
1463 }
1464
1465 /* copy colors from theme, and set changes in it based on state */
1466 static void widget_state(uiWidgetType *wt, int state)
1467 {
1468         uiWidgetStateColors *wcol_state= wt->wcol_state;
1469
1470         wt->wcol= *(wt->wcol_theme);
1471         
1472         if(state & UI_SELECT) {
1473                 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel)
1474
1475                 if(state & UI_BUT_ANIMATED_KEY)
1476                         widget_state_blend(wt->wcol.inner, wcol_state->inner_key_sel, wcol_state->blend);
1477                 else if(state & UI_BUT_ANIMATED)
1478                         widget_state_blend(wt->wcol.inner, wcol_state->inner_anim_sel, wcol_state->blend);
1479                 else if(state & UI_BUT_DRIVEN)
1480                         widget_state_blend(wt->wcol.inner, wcol_state->inner_driven_sel, wcol_state->blend);
1481
1482                 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1483                 
1484                 if(state & UI_SELECT)
1485                         SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
1486         }
1487         else {
1488                 if(state & UI_BUT_ANIMATED_KEY)
1489                         widget_state_blend(wt->wcol.inner, wcol_state->inner_key, wcol_state->blend);
1490                 else if(state & UI_BUT_ANIMATED)
1491                         widget_state_blend(wt->wcol.inner, wcol_state->inner_anim, wcol_state->blend);
1492                 else if(state & UI_BUT_DRIVEN)
1493                         widget_state_blend(wt->wcol.inner, wcol_state->inner_driven, wcol_state->blend);
1494
1495                 if(state & UI_ACTIVE) { /* mouse over? */
1496                         wt->wcol.inner[0]= wt->wcol.inner[0]>=240? 255 : wt->wcol.inner[0]+15;
1497                         wt->wcol.inner[1]= wt->wcol.inner[1]>=240? 255 : wt->wcol.inner[1]+15;
1498                         wt->wcol.inner[2]= wt->wcol.inner[2]>=240? 255 : wt->wcol.inner[2]+15;
1499                 }
1500         }
1501
1502         if(state & UI_BUT_REDALERT) {
1503                 char red[4]= {255, 0, 0};
1504                 widget_state_blend(wt->wcol.inner, red, 0.4f);
1505         }
1506 }
1507
1508 /* sliders use special hack which sets 'item' as inner when drawing filling */
1509 static void widget_state_numslider(uiWidgetType *wt, int state)
1510 {
1511         uiWidgetStateColors *wcol_state= wt->wcol_state;
1512         float blend= wcol_state->blend - 0.2f; // XXX special tweak to make sure that bar will still be visible
1513
1514         /* call this for option button */
1515         widget_state(wt, state);
1516         
1517         /* now, set the inner-part so that it reflects state settings too */
1518         // TODO: maybe we should have separate settings for the blending colors used for this case?
1519         if(state & UI_SELECT) {
1520                 
1521                 if(state & UI_BUT_ANIMATED_KEY)
1522                         widget_state_blend(wt->wcol.item, wcol_state->inner_key_sel, blend);
1523                 else if(state & UI_BUT_ANIMATED)
1524                         widget_state_blend(wt->wcol.item, wcol_state->inner_anim_sel, blend);
1525                 else if(state & UI_BUT_DRIVEN)
1526                         widget_state_blend(wt->wcol.item, wcol_state->inner_driven_sel, blend);
1527                 
1528                 if(state & UI_SELECT)
1529                         SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
1530         }
1531         else {
1532                 if(state & UI_BUT_ANIMATED_KEY)
1533                         widget_state_blend(wt->wcol.item, wcol_state->inner_key, blend);
1534                 else if(state & UI_BUT_ANIMATED)
1535                         widget_state_blend(wt->wcol.item, wcol_state->inner_anim, blend);
1536                 else if(state & UI_BUT_DRIVEN)
1537                         widget_state_blend(wt->wcol.item, wcol_state->inner_driven, blend);
1538         }
1539 }
1540
1541 /* labels use theme colors for text */
1542 static void widget_state_label(uiWidgetType *wt, int state)
1543 {
1544         /* call this for option button */
1545         widget_state(wt, state);
1546
1547         if(state & UI_SELECT)
1548                 UI_GetThemeColor4ubv(TH_TEXT_HI, (unsigned char *)wt->wcol.text);
1549         else
1550                 UI_GetThemeColor4ubv(TH_TEXT, (unsigned char *)wt->wcol.text);
1551         
1552 }
1553
1554 /* labels use theme colors for text */
1555 static void widget_state_option_menu(uiWidgetType *wt, int state)
1556 {
1557         
1558         /* call this for option button */
1559         widget_state(wt, state);
1560         
1561         /* if not selected we get theme from menu back */
1562         if(state & UI_SELECT)
1563                 UI_GetThemeColor4ubv(TH_TEXT_HI, (unsigned char *)wt->wcol.text);
1564         else {
1565                 bTheme *btheme= U.themes.first; /* XXX */
1566
1567                 VECCOPY(wt->wcol.text, btheme->tui.wcol_menu_back.text);
1568         }
1569 }
1570
1571
1572 static void widget_state_nothing(uiWidgetType *wt, int UNUSED(state))
1573 {
1574         wt->wcol= *(wt->wcol_theme);
1575 }       
1576
1577 /* special case, button that calls pulldown */
1578 static void widget_state_pulldown(uiWidgetType *wt, int state)
1579 {
1580         wt->wcol= *(wt->wcol_theme);
1581         
1582         QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1583         VECCOPY(wt->wcol.outline, wt->wcol.inner);
1584
1585         if(state & UI_ACTIVE)
1586                 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1587 }
1588
1589 /* special case, menu items */
1590 static void widget_state_menu_item(uiWidgetType *wt, int state)
1591 {
1592         wt->wcol= *(wt->wcol_theme);
1593         
1594         if(state & (UI_BUT_DISABLED|UI_BUT_INACTIVE)) {
1595                 wt->wcol.text[0]= 0.5f*(wt->wcol.text[0]+wt->wcol.text_sel[0]);
1596                 wt->wcol.text[1]= 0.5f*(wt->wcol.text[1]+wt->wcol.text_sel[1]);
1597                 wt->wcol.text[2]= 0.5f*(wt->wcol.text[2]+wt->wcol.text_sel[2]);
1598         }
1599         else if(state & UI_ACTIVE) {
1600                 QUATCOPY(wt->wcol.inner, wt->wcol.inner_sel);
1601                 VECCOPY(wt->wcol.text, wt->wcol.text_sel);
1602         }
1603 }
1604
1605
1606 /* ************ menu backdrop ************************* */
1607
1608 /* outside of rect, rad to left/bottom/right */
1609 static void widget_softshadow(rcti *rect, int roundboxalign, float radin, float radout)
1610 {
1611         uiWidgetBase wtb;
1612         rcti rect1= *rect;
1613         float alpha, alphastep;
1614         int step, tot, a;
1615         
1616         /* prevent tooltips to not show round shadow */
1617         if( 2.0f*radout > 0.2f*(rect1.ymax-rect1.ymin) )
1618                 rect1.ymax -= 0.2f*(rect1.ymax-rect1.ymin);
1619         else
1620                 rect1.ymax -= 2.0f*radout;
1621         
1622         /* inner part */
1623         tot= round_box_shadow_edges(wtb.inner_v, &rect1, radin, roundboxalign & 12, 0.0f);
1624         
1625         /* inverse linear shadow alpha */
1626         alpha= 0.15;
1627         alphastep= 0.67;
1628         
1629         for(step= 1; step<=radout; step++, alpha*=alphastep) {
1630                 round_box_shadow_edges(wtb.outer_v, &rect1, radin, 15, (float)step);
1631                 
1632                 glColor4f(0.0f, 0.0f, 0.0f, alpha);
1633                 
1634                 glBegin(GL_QUAD_STRIP);
1635                 for(a=0; a<tot; a++) {
1636                         glVertex2fv(wtb.outer_v[a]);
1637                         glVertex2fv(wtb.inner_v[a]);
1638                 }
1639                 glEnd();
1640         }
1641         
1642 }
1643
1644 static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction)
1645 {
1646         uiWidgetBase wtb;
1647         int roundboxalign= 15;
1648         
1649         widget_init(&wtb);
1650         
1651         /* menu is 2nd level or deeper */
1652         if (flag & UI_BLOCK_POPUP) {
1653                 //rect->ymin -= 4.0;
1654                 //rect->ymax += 4.0;
1655         }
1656         else if (direction == UI_DOWN) {
1657                 roundboxalign= 12;
1658                 rect->ymin -= 4.0;
1659         } 
1660         else if (direction == UI_TOP) {
1661                 roundboxalign= 3;
1662                 rect->ymax += 4.0;
1663         }
1664         
1665         glEnable(GL_BLEND);
1666         widget_softshadow(rect, roundboxalign, 5.0f, 8.0f);
1667         
1668         round_box_edges(&wtb, roundboxalign, rect, 5.0f);
1669         wtb.emboss= 0;
1670         widgetbase_draw(&wtb, wcol);
1671         
1672         glDisable(GL_BLEND);
1673 }
1674
1675
1676 static void ui_hsv_cursor(float x, float y)
1677 {
1678         
1679         glPushMatrix();
1680         glTranslatef(x, y, 0.0f);
1681         
1682         glColor3f(1.0f, 1.0f, 1.0f);
1683         glutil_draw_filled_arc(0.0f, M_PI*2.0, 3.0f, 8);
1684         
1685         glEnable(GL_BLEND);
1686         glEnable(GL_LINE_SMOOTH );
1687         glColor3f(0.0f, 0.0f, 0.0f);
1688         glutil_draw_lined_arc(0.0f, M_PI*2.0, 3.0f, 12);
1689         glDisable(GL_BLEND);
1690         glDisable(GL_LINE_SMOOTH );
1691         
1692         glPopMatrix();
1693         
1694 }
1695
1696 void ui_hsvcircle_vals_from_pos(float *valrad, float *valdist, rcti *rect, float mx, float my)
1697 {
1698         /* duplication of code... well, simple is better now */
1699         float centx= (float)(rect->xmin + rect->xmax)/2;
1700         float centy= (float)(rect->ymin + rect->ymax)/2;
1701         float radius, dist;
1702         
1703         if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1704                 radius= (float)(rect->ymax - rect->ymin)/2; 
1705         else
1706                 radius= (float)(rect->xmax - rect->xmin)/2; 
1707
1708         mx-= centx;
1709         my-= centy;
1710         dist= sqrt( mx*mx + my*my);
1711         if(dist < radius)
1712                 *valdist= dist/radius;
1713         else
1714                 *valdist= 1.0f;
1715         
1716         *valrad= atan2f(mx, my)/(2.0f*(float)M_PI) + 0.5f;
1717 }
1718
1719 static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, rcti *rect)
1720 {
1721         /* gouraud triangle fan */
1722         float radstep, ang= 0.0f;
1723         float centx, centy, radius;
1724         float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
1725         int a, tot= 32;
1726         int color_profile = but->block->color_profile;
1727         
1728         if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
1729                 color_profile = BLI_PR_NONE;
1730         
1731         radstep= 2.0f*(float)M_PI/(float)tot;
1732         centx= (float)(rect->xmin + rect->xmax)/2;
1733         centy= (float)(rect->ymin + rect->ymax)/2;
1734         
1735         if( rect->xmax-rect->xmin > rect->ymax-rect->ymin )
1736                 radius= (float)(rect->ymax - rect->ymin)/2; 
1737         else
1738                 radius= (float)(rect->xmax - rect->xmin)/2; 
1739         
1740         /* color */
1741         ui_get_but_vectorf(but, rgb);
1742         copy_v3_v3(hsv, ui_block_hsv_get(but->block));
1743         rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
1744         copy_v3_v3(hsvo, hsv);
1745         
1746         /* exception: if 'lock' is set
1747          * lock the value of the color wheel to 1.
1748          * Useful for color correction tools where you're only interested in hue. */
1749         if (but->flag & UI_BUT_COLOR_LOCK)
1750                 hsv[2] = 1.f;
1751         else if (color_profile)
1752                 hsv[2] = linearrgb_to_srgb(hsv[2]);
1753         
1754         hsv_to_rgb(0.f, 0.f, hsv[2], colcent, colcent+1, colcent+2);
1755         
1756         glShadeModel(GL_SMOOTH);
1757
1758         glBegin(GL_TRIANGLE_FAN);
1759         glColor3fv(colcent);
1760         glVertex2f( centx, centy);
1761         
1762         for(a=0; a<=tot; a++, ang+=radstep) {
1763                 float si= sin(ang);
1764                 float co= cos(ang);
1765                 
1766                 ui_hsvcircle_vals_from_pos(hsv, hsv+1, rect, centx + co*radius, centy + si*radius);
1767                 CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */
1768
1769                 hsv_to_rgb(hsv[0], hsv[1], hsv[2], col, col+1, col+2);
1770                 glColor3fv(col);
1771                 glVertex2f( centx + co*radius, centy + si*radius);
1772         }
1773         glEnd();
1774         
1775         glShadeModel(GL_FLAT);
1776         
1777         /* fully rounded outline */
1778         glPushMatrix();
1779         glTranslatef(centx, centy, 0.0f);
1780         glEnable(GL_BLEND);
1781         glEnable(GL_LINE_SMOOTH );
1782         glColor3ubv((unsigned char*)wcol->outline);
1783         glutil_draw_lined_arc(0.0f, M_PI*2.0, radius, tot + 1);
1784         glDisable(GL_BLEND);
1785         glDisable(GL_LINE_SMOOTH );
1786         glPopMatrix();
1787
1788         /* cursor */
1789         ang= 2.0f*(float)M_PI*hsvo[0] + 0.5f*(float)M_PI;
1790
1791         if(but->flag & UI_BUT_COLOR_CUBIC)
1792                 radius= (1.0f - powf(1.0f - hsvo[1], 3.0f)) *radius;
1793         else
1794                 radius= hsvo[1] * radius;
1795
1796         ui_hsv_cursor(centx + cosf(-ang)*radius, centy + sinf(-ang)*radius);
1797         
1798 }
1799
1800 /* ************ custom buttons, old stuff ************** */
1801
1802 /* draws in resolution of 20x4 colors */
1803 void ui_draw_gradient(rcti *rect, float *hsv, int type, float alpha)
1804 {
1805         int a;
1806         float h= hsv[0], s= hsv[1], v= hsv[2];
1807         float dx, dy, sx1, sx2, sy;
1808         float col0[4][3];       // left half, rect bottom to top
1809         float col1[4][3];       // right half, rect bottom to top
1810
1811         /* draw series of gouraud rects */
1812         glShadeModel(GL_SMOOTH);
1813         
1814         switch(type) {
1815                 case UI_GRAD_SV:
1816                         hsv_to_rgb(h, 0.0, 0.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1817                         hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1818                         hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1819                         hsv_to_rgb(h, 1.0, 0.0,   &col1[3][0], &col1[3][1], &col1[3][2]);
1820                         break;
1821                 case UI_GRAD_HV:
1822                         hsv_to_rgb(0.0, s, 0.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1823                         hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1824                         hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1825                         hsv_to_rgb(0.0, s, 1.0,   &col1[3][0], &col1[3][1], &col1[3][2]);
1826                         break;
1827                 case UI_GRAD_HS:
1828                         hsv_to_rgb(0.0, 0.0, v,   &col1[0][0], &col1[0][1], &col1[0][2]);
1829                         hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1830                         hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1831                         hsv_to_rgb(0.0, 1.0, v,   &col1[3][0], &col1[3][1], &col1[3][2]);
1832                         break;
1833                 case UI_GRAD_H:
1834                         hsv_to_rgb(0.0, 1.0, 1.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1835                         VECCOPY(col1[1], col1[0]);
1836                         VECCOPY(col1[2], col1[0]);
1837                         VECCOPY(col1[3], col1[0]);
1838                         break;
1839                 case UI_GRAD_S:
1840                         hsv_to_rgb(1.0, 0.0, 1.0,   &col1[1][0], &col1[1][1], &col1[1][2]);
1841                         VECCOPY(col1[0], col1[1]);
1842                         VECCOPY(col1[2], col1[1]);
1843                         VECCOPY(col1[3], col1[1]);
1844                         break;
1845                 case UI_GRAD_V:
1846                         hsv_to_rgb(1.0, 1.0, 0.0,   &col1[2][0], &col1[2][1], &col1[2][2]);
1847                         VECCOPY(col1[0], col1[2]);
1848                         VECCOPY(col1[1], col1[2]);
1849                         VECCOPY(col1[3], col1[2]);
1850                         break;
1851                 default:
1852                         assert(!"invalid 'type' argument");
1853                         hsv_to_rgb(1.0, 1.0, 1.0,   &col1[2][0], &col1[2][1], &col1[2][2]);
1854                         VECCOPY(col1[0], col1[2]);
1855                         VECCOPY(col1[1], col1[2]);
1856                         VECCOPY(col1[3], col1[2]);                      
1857         }
1858         
1859         /* old below */
1860         
1861         for(dx=0.0f; dx<1.0f; dx+= 0.05f) {
1862                 // previous color
1863                 VECCOPY(col0[0], col1[0]);
1864                 VECCOPY(col0[1], col1[1]);
1865                 VECCOPY(col0[2], col1[2]);
1866                 VECCOPY(col0[3], col1[3]);
1867                 
1868                 // new color
1869                 switch(type) {
1870                         case UI_GRAD_SV:
1871                                 hsv_to_rgb(h, 0.0, dx,   &col1[0][0], &col1[0][1], &col1[0][2]);
1872                                 hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
1873                                 hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1874                                 hsv_to_rgb(h, 1.0, dx,   &col1[3][0], &col1[3][1], &col1[3][2]);
1875                                 break;
1876                         case UI_GRAD_HV:
1877                                 hsv_to_rgb(dx, s, 0.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1878                                 hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1879                                 hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1880                                 hsv_to_rgb(dx, s, 1.0,   &col1[3][0], &col1[3][1], &col1[3][2]);
1881                                 break;
1882                         case UI_GRAD_HS:
1883                                 hsv_to_rgb(dx, 0.0, v,   &col1[0][0], &col1[0][1], &col1[0][2]);
1884                                 hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1885                                 hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1886                                 hsv_to_rgb(dx, 1.0, v,   &col1[3][0], &col1[3][1], &col1[3][2]);
1887                                 break;
1888                         case UI_GRAD_H:
1889                                 hsv_to_rgb(dx, 1.0, 1.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1890                                 VECCOPY(col1[1], col1[0]);
1891                                 VECCOPY(col1[2], col1[0]);
1892                                 VECCOPY(col1[3], col1[0]);
1893                                 break;
1894                         case UI_GRAD_S:
1895                                 hsv_to_rgb(h, dx, 1.0,   &col1[1][0], &col1[1][1], &col1[1][2]);
1896                                 VECCOPY(col1[0], col1[1]);
1897                                 VECCOPY(col1[2], col1[1]);
1898                                 VECCOPY(col1[3], col1[1]);
1899                                 break;
1900                         case UI_GRAD_V:
1901                                 hsv_to_rgb(h, 1.0, dx,   &col1[2][0], &col1[2][1], &col1[2][2]);
1902                                 VECCOPY(col1[0], col1[2]);
1903                                 VECCOPY(col1[1], col1[2]);
1904                                 VECCOPY(col1[3], col1[2]);
1905                                 break;
1906                 }
1907                 
1908                 // rect
1909                 sx1= rect->xmin + dx*(rect->xmax-rect->xmin);
1910                 sx2= rect->xmin + (dx+0.05f)*(rect->xmax-rect->xmin);
1911                 sy= rect->ymin;
1912                 dy= (rect->ymax-rect->ymin)/3.0;
1913                 
1914                 glBegin(GL_QUADS);
1915                 for(a=0; a<3; a++, sy+=dy) {
1916                         glColor4f(col0[a][0], col0[a][1], col0[a][2], alpha);
1917                         glVertex2f(sx1, sy);
1918                         
1919                         glColor4f(col1[a][0], col1[a][1], col1[a][2], alpha);
1920                         glVertex2f(sx2, sy);
1921
1922                         glColor4f(col1[a+1][0], col1[a+1][1], col1[a+1][2], alpha);
1923                         glVertex2f(sx2, sy+dy);
1924                         
1925                         glColor4f(col0[a+1][0], col0[a+1][1], col0[a+1][2], alpha);
1926                         glVertex2f(sx1, sy+dy);
1927                 }
1928                 glEnd();
1929         }
1930         
1931         glShadeModel(GL_FLAT);
1932         
1933 }
1934
1935
1936
1937 static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect)
1938 {
1939         float rgb[3], h,s,v;
1940         float x=0.0f, y=0.0f;
1941         float *hsv= ui_block_hsv_get(but->block);
1942         float hsvn[3];
1943         
1944         h= hsv[0];
1945         s= hsv[1];
1946         v= hsv[2];
1947         
1948         ui_get_but_vectorf(but, rgb);
1949         rgb_to_hsv_compat(rgb[0], rgb[1], rgb[2], &h, &s, &v);
1950
1951         hsvn[0]= h;
1952         hsvn[1]= s;
1953         hsvn[2]= v;
1954         
1955         ui_draw_gradient(rect, hsvn, but->a1, 1.f);
1956         
1957         switch((int)but->a1) {
1958                 case UI_GRAD_SV:
1959                         x= v; y= s; break;
1960                 case UI_GRAD_HV:
1961                         x= h; y= v; break;
1962                 case UI_GRAD_HS:
1963                         x= h; y= s; break;
1964                 case UI_GRAD_H:
1965                         x= h; y= 0.5; break;
1966                 case UI_GRAD_S:
1967                         x= s; y= 0.5; break;
1968                 case UI_GRAD_V:
1969                         x= v; y= 0.5; break;
1970         }
1971         
1972         /* cursor */
1973         x= rect->xmin + x*(rect->xmax-rect->xmin);
1974         y= rect->ymin + y*(rect->ymax-rect->ymin);
1975         CLAMP(x, rect->xmin+3.0f, rect->xmax-3.0f);
1976         CLAMP(y, rect->ymin+3.0f, rect->ymax-3.0f);
1977         
1978         ui_hsv_cursor(x, y);
1979         
1980         /* outline */
1981         glColor3ub(0,  0,  0);
1982         fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
1983 }
1984
1985 /* vertical 'value' slider, using new widget code */
1986 static void ui_draw_but_HSV_v(uiBut *but, rcti *rect)
1987 {
1988         uiWidgetBase wtb;
1989         float rad= 0.5f*(rect->xmax - rect->xmin);
1990         float x, y;
1991         float rgb[3], hsv[3], v, range;
1992         int color_profile = but->block->color_profile;
1993         
1994         if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
1995                 color_profile = BLI_PR_NONE;
1996
1997         ui_get_but_vectorf(but, rgb);
1998         rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
1999         v = hsv[2];
2000         
2001         if (color_profile)
2002                 v = linearrgb_to_srgb(v);
2003
2004         /* map v from property range to [0,1] */
2005         range = but->softmax - but->softmin;
2006         v =     (v - but->softmin)/range;
2007         
2008         widget_init(&wtb);
2009         
2010         /* fully rounded */
2011         round_box_edges(&wtb, 15, rect, rad);
2012         
2013         /* setup temp colors */
2014         wcol_tmp.outline[0]= wcol_tmp.outline[1]= wcol_tmp.outline[2]= 0;
2015         wcol_tmp.inner[0]= wcol_tmp.inner[1]= wcol_tmp.inner[2]= 128;
2016         wcol_tmp.shadetop= 127;
2017         wcol_tmp.shadedown= -128;
2018         wcol_tmp.shaded= 1;
2019         
2020         widgetbase_draw(&wtb, &wcol_tmp);
2021
2022         /* cursor */
2023         x= rect->xmin + 0.5f * (rect->xmax-rect->xmin);
2024         y= rect->ymin + v * (rect->ymax-rect->ymin);
2025         CLAMP(y, rect->ymin+3.0f, rect->ymax-3.0f);
2026         
2027         ui_hsv_cursor(x, y);
2028         
2029 }
2030
2031
2032 /* ************ separator, for menus etc ***************** */
2033 static void ui_draw_separator(rcti *rect,  uiWidgetColors *wcol)
2034 {
2035         int y = rect->ymin + (rect->ymax - rect->ymin)/2 - 1;
2036         unsigned char col[4];
2037         
2038         col[0] = wcol->text[0];
2039         col[1] = wcol->text[1];
2040         col[2] = wcol->text[2];
2041         col[3] = 7;
2042         
2043         glEnable(GL_BLEND);
2044         glColor4ubv(col);
2045         sdrawline(rect->xmin, y, rect->xmax, y);
2046         glDisable(GL_BLEND);
2047 }
2048
2049 /* ************ button callbacks, draw ***************** */
2050
2051 static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2052 {
2053         uiWidgetBase wtb;
2054         float rad= 0.5f*(rect->ymax - rect->ymin);
2055         float textofs = rad*0.75f;
2056
2057         if(state & UI_SELECT)
2058                 SWAP(short, wcol->shadetop, wcol->shadedown);
2059         
2060         widget_init(&wtb);
2061         
2062         /* fully rounded */
2063         round_box_edges(&wtb, roundboxalign, rect, rad);
2064         
2065         /* decoration */
2066         if(!(state & UI_TEXTINPUT)) {
2067                 widget_num_tria(&wtb.tria1, rect, 0.6f, 'l');
2068                 widget_num_tria(&wtb.tria2, rect, 0.6f, 'r');
2069         }
2070
2071         widgetbase_draw(&wtb, wcol);
2072         
2073         /* text space */
2074         rect->xmin += textofs;
2075         rect->xmax -= textofs;
2076 }
2077
2078 //static int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
2079 int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol)
2080 {
2081         float dist, vec[4][2];
2082
2083         vec[0][0]= rect->xmin;
2084         vec[0][1]= rect->ymin;
2085         vec[3][0]= rect->xmax;
2086         vec[3][1]= rect->ymax;
2087         
2088         dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
2089         
2090         vec[1][0]= vec[0][0]+dist;
2091         vec[1][1]= vec[0][1];
2092         
2093         vec[2][0]= vec[3][0]-dist;
2094         vec[2][1]= vec[3][1];
2095         
2096         forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], coord_array[0], resol, sizeof(float)*2);
2097         forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], coord_array[0]+1, resol, sizeof(float)*2);
2098         
2099         return 1;
2100 }
2101
2102 #define LINK_RESOL      24
2103 void ui_draw_link_bezier(rcti *rect)
2104 {
2105         float coord_array[LINK_RESOL+1][2];
2106         
2107         if(ui_link_bezier_points(rect, coord_array, LINK_RESOL)) {
2108                 /* we can reuse the dist variable here to increment the GL curve eval amount*/
2109                 // const float dist= 1.0f/(float)LINK_RESOL; // UNUSED
2110                 int i;
2111
2112                 glEnable(GL_BLEND);
2113                 glEnable(GL_LINE_SMOOTH);
2114                 
2115                 glBegin(GL_LINE_STRIP);
2116                 for(i=0; i<=LINK_RESOL; i++) {
2117                         glVertex2fv(coord_array[i]);
2118                 }
2119                 glEnd();
2120                 
2121                 glDisable(GL_BLEND);
2122                 glDisable(GL_LINE_SMOOTH);
2123
2124         }
2125 }
2126
2127 /* function in use for buttons and for view2d sliders */
2128 void uiWidgetScrollDraw(uiWidgetColors *wcol, rcti *rect, rcti *slider, int state)
2129 {
2130         uiWidgetBase wtb;
2131         float rad;
2132         int horizontal;
2133         short outline=0;
2134
2135         widget_init(&wtb);
2136
2137         /* determine horizontal/vertical */
2138         horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
2139         
2140         if(horizontal)
2141                 rad= 0.5f*(rect->ymax - rect->ymin);
2142         else
2143                 rad= 0.5f*(rect->xmax - rect->xmin);
2144         
2145         wtb.shadedir= (horizontal)? 1: 0;
2146         
2147         /* draw back part, colors swapped and shading inverted */
2148         if(horizontal)
2149                 SWAP(short, wcol->shadetop, wcol->shadedown);
2150         
2151         round_box_edges(&wtb, 15, rect, rad); 
2152         widgetbase_draw(&wtb, wcol);
2153         
2154         /* slider */
2155         if(slider->xmax-slider->xmin<2 || slider->ymax-slider->ymin<2);
2156         else {
2157                 
2158                 SWAP(short, wcol->shadetop, wcol->shadedown);
2159                 
2160                 QUATCOPY(wcol->inner, wcol->item);
2161                 
2162                 if(wcol->shadetop>wcol->shadedown)
2163                         wcol->shadetop+= 20;    /* XXX violates themes... */
2164                 else wcol->shadedown+= 20;
2165                 
2166                 if(state & UI_SCROLL_PRESSED) {
2167                         wcol->inner[0]= wcol->inner[0]>=250? 255 : wcol->inner[0]+5;
2168                         wcol->inner[1]= wcol->inner[1]>=250? 255 : wcol->inner[1]+5;
2169                         wcol->inner[2]= wcol->inner[2]>=250? 255 : wcol->inner[2]+5;
2170                 }
2171
2172                 /* draw */
2173                 wtb.emboss= 0; /* only emboss once */
2174                 
2175                 /* exception for progress bar */
2176                 if (state & UI_SCROLL_NO_OUTLINE)       
2177                         SWAP(short, outline, wtb.outline);
2178                 
2179                 round_box_edges(&wtb, 15, slider, rad); 
2180                 
2181                 if(state & UI_SCROLL_ARROWS) {
2182                         if(wcol->item[0] > 48) wcol->item[0]-= 48;
2183                         if(wcol->item[1] > 48) wcol->item[1]-= 48;
2184                         if(wcol->item[2] > 48) wcol->item[2]-= 48;
2185                         wcol->item[3]= 255;
2186                         
2187                         if(horizontal) {
2188                                 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'l');
2189                                 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 'r');
2190                         }
2191                         else {
2192                                 widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'b');
2193                                 widget_scroll_circle(&wtb.tria2, slider, 0.6f, 't');
2194                         }
2195                 }
2196                 widgetbase_draw(&wtb, wcol);
2197                 
2198                 if (state & UI_SCROLL_NO_OUTLINE)
2199                         SWAP(short, outline, wtb.outline);
2200         }       
2201 }
2202
2203 static void widget_scroll(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2204 {
2205         rcti rect1;
2206         double value;
2207         float fac, size, min;
2208         int horizontal;
2209
2210         /* calculate slider part */
2211         value= ui_get_but_val(but);
2212
2213         size= (but->softmax + but->a1 - but->softmin);
2214         size= MAX2(size, 2);
2215         
2216         /* position */
2217         rect1= *rect;
2218
2219         /* determine horizontal/vertical */
2220         horizontal= (rect->xmax - rect->xmin > rect->ymax - rect->ymin);
2221         
2222         if(horizontal) {
2223                 fac= (rect->xmax - rect->xmin)/(size);
2224                 rect1.xmin= rect1.xmin + ceilf(fac*((float)value - but->softmin));
2225                 rect1.xmax= rect1.xmin + ceilf(fac*(but->a1 - but->softmin));
2226
2227                 /* ensure minimium size */
2228                 min= rect->ymax - rect->ymin;
2229
2230                 if(rect1.xmax - rect1.xmin < min) {
2231                         rect1.xmax= rect1.xmin + min;
2232
2233                         if(rect1.xmax > rect->xmax) {
2234                                 rect1.xmax= rect->xmax;
2235                                 rect1.xmin= MAX2(rect1.xmax - min, rect->xmin);
2236                         }
2237                 }
2238         }
2239         else {
2240                 fac= (rect->ymax - rect->ymin)/(size);
2241                 rect1.ymax= rect1.ymax - ceilf(fac*((float)value - but->softmin));
2242                 rect1.ymin= rect1.ymax - ceilf(fac*(but->a1 - but->softmin));
2243
2244                 /* ensure minimium size */
2245                 min= rect->xmax - rect->xmin;
2246
2247                 if(rect1.ymax - rect1.ymin < min) {
2248                         rect1.ymax= rect1.ymin + min;
2249
2250                         if(rect1.ymax > rect->ymax) {
2251                                 rect1.ymax= rect->ymax;
2252                                 rect1.ymin= MAX2(rect1.ymax - min, rect->ymin);
2253                         }
2254                 }
2255         }
2256
2257         if(state & UI_SELECT)
2258                 state= UI_SCROLL_PRESSED;
2259         else
2260                 state= 0;
2261         uiWidgetScrollDraw(wcol, rect, &rect1, state);
2262 }
2263
2264 static void widget_progressbar(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2265 {
2266         rcti rect_prog = *rect, rect_bar = *rect;
2267         float value = but->a1;
2268         float w, min;
2269         
2270         /* make the progress bar a proportion of the original height */
2271         /* hardcoded 4px high for now */
2272         rect_prog.ymax = rect_prog.ymin + 4;
2273         rect_bar.ymax = rect_bar.ymin + 4;
2274         
2275         w = value * (rect_prog.xmax - rect_prog.xmin);
2276         
2277         /* ensure minimium size */
2278         min= rect_prog.ymax - rect_prog.ymin;
2279         w = MAX2(w, min);
2280         
2281         rect_bar.xmax = rect_bar.xmin + w;
2282                 
2283         uiWidgetScrollDraw(wcol, &rect_prog, &rect_bar, UI_SCROLL_NO_OUTLINE);
2284         
2285         /* raise text a bit */
2286         rect->ymin += 6;
2287         rect->xmin -= 6;
2288 }
2289
2290 static void widget_link(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2291 {
2292         
2293         if(but->flag & UI_SELECT) {
2294                 rcti rectlink;
2295                 
2296                 UI_ThemeColor(TH_TEXT_HI);
2297                 
2298                 rectlink.xmin= (rect->xmin+rect->xmax)/2;
2299                 rectlink.ymin= (rect->ymin+rect->ymax)/2;
2300                 rectlink.xmax= but->linkto[0];
2301                 rectlink.ymax= but->linkto[1];
2302                 
2303                 ui_draw_link_bezier(&rectlink);
2304         }
2305 }
2306
2307 static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2308 {
2309         uiWidgetBase wtb, wtb1;
2310         rcti rect1;
2311         double value;
2312         float offs, toffs, fac;
2313         char outline[3];
2314
2315         widget_init(&wtb);
2316         widget_init(&wtb1);
2317         
2318         /* backdrop first */
2319         
2320         /* fully rounded */
2321         offs= 0.5f*(rect->ymax - rect->ymin);
2322         toffs = offs*0.75f;
2323         round_box_edges(&wtb, roundboxalign, rect, offs);
2324
2325         wtb.outline= 0;
2326         widgetbase_draw(&wtb, wcol);
2327         
2328         /* draw left/right parts only when not in text editing */
2329         if(!(state & UI_TEXTINPUT)) {
2330                 
2331                         /* slider part */
2332                 VECCOPY(outline, wcol->outline);
2333                 VECCOPY(wcol->outline, wcol->item);
2334                 VECCOPY(wcol->inner, wcol->item);
2335
2336                 if(!(state & UI_SELECT))
2337                         SWAP(short, wcol->shadetop, wcol->shadedown);
2338                 
2339                 rect1= *rect;
2340                 
2341                 value= ui_get_but_val(but);
2342                 fac= ((float)value-but->softmin)*(rect1.xmax - rect1.xmin - offs)/(but->softmax - but->softmin);
2343                 
2344                 /* left part of slider, always rounded */
2345                 rect1.xmax= rect1.xmin + ceil(offs+1.0f);
2346                 round_box_edges(&wtb1, roundboxalign & ~6, &rect1, offs);
2347                 wtb1.outline= 0;
2348                 widgetbase_draw(&wtb1, wcol);
2349                 
2350                 /* right part of slider, interpolate roundness */
2351                 rect1.xmax= rect1.xmin + fac + offs;
2352                 rect1.xmin+=  floor(offs-1.0f);
2353                 if(rect1.xmax + offs > rect->xmax)
2354                         offs*= (rect1.xmax + offs - rect->xmax)/offs;
2355                 else 
2356                         offs= 0.0f;
2357                 round_box_edges(&wtb1, roundboxalign & ~9, &rect1, offs);
2358                 
2359                 widgetbase_draw(&wtb1, wcol);
2360                 VECCOPY(wcol->outline, outline);
2361                 
2362                 if(!(state & UI_SELECT))
2363                         SWAP(short, wcol->shadetop, wcol->shadedown);
2364         }
2365         
2366         /* outline */
2367         wtb.outline= 1;
2368         wtb.inner= 0;
2369         widgetbase_draw(&wtb, wcol);
2370         
2371         /* text space */
2372         rect->xmin += toffs;
2373         rect->xmax -= toffs;
2374 }
2375
2376 /* I think 3 is sufficient border to indicate keyed status */
2377 #define SWATCH_KEYED_BORDER 3
2378
2379 static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2380 {
2381         uiWidgetBase wtb;
2382         float col[4];
2383         int color_profile = but->block->color_profile;
2384         
2385         col[3]= 1.0f;
2386
2387         if (but->rnaprop) {
2388                 if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
2389                         color_profile = BLI_PR_NONE;
2390
2391                 if(RNA_property_array_length(&but->rnapoin, but->rnaprop)==4) {
2392                         col[3]= RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
2393                 }
2394         }
2395         
2396         widget_init(&wtb);
2397         
2398         /* half rounded */
2399         round_box_edges(&wtb, roundboxalign, rect, 5.0f);
2400                 
2401         ui_get_but_vectorf(but, col);
2402         
2403         if(state & (UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN|UI_BUT_REDALERT)) {
2404                 // draw based on state - color for keyed etc
2405                 widgetbase_draw(&wtb, wcol);
2406                 
2407                 // inset to draw swatch color
2408                 rect->xmin+= SWATCH_KEYED_BORDER;
2409                 rect->xmax-= SWATCH_KEYED_BORDER;
2410                 rect->ymin+= SWATCH_KEYED_BORDER;
2411                 rect->ymax-= SWATCH_KEYED_BORDER;
2412                 
2413                 round_box_edges(&wtb, roundboxalign, rect, 5.0f);
2414         }
2415         
2416         if (color_profile)
2417                 linearrgb_to_srgb_v3_v3(col, col);
2418         
2419         wcol->inner[0]= FTOCHAR(col[0]);
2420         wcol->inner[1]= FTOCHAR(col[1]);
2421         wcol->inner[2]= FTOCHAR(col[2]);
2422         wcol->inner[3]= FTOCHAR(col[3]);
2423         wcol->shaded = 0;
2424         wcol->alpha_check = (wcol->inner[3] < 255);
2425
2426         widgetbase_draw(&wtb, wcol);
2427         
2428 }
2429
2430 static void widget_icon_has_anim(uiBut *UNUSED(but), uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2431 {
2432         if(state & (UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN|UI_BUT_REDALERT)) {
2433                 uiWidgetBase wtb;
2434         
2435                 widget_init(&wtb);
2436                 wtb.outline= 0;
2437                 
2438                 /* rounded */
2439                 round_box_edges(&wtb, 15, rect, 10.0f);
2440                 widgetbase_draw(&wtb, wcol);
2441         }       
2442 }
2443
2444
2445 static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
2446 {
2447         uiWidgetBase wtb;
2448         
2449         if(state & UI_SELECT)
2450                 SWAP(short, wcol->shadetop, wcol->shadedown);
2451         
2452         widget_init(&wtb);
2453         
2454         /* half rounded */
2455         round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2456         
2457         widgetbase_draw(&wtb, wcol);
2458
2459 }
2460
2461
2462 static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2463 {
2464         uiWidgetBase wtb;
2465         
2466         widget_init(&wtb);
2467         
2468         /* half rounded */
2469         round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2470         
2471         /* decoration */
2472         widget_menu_trias(&wtb.tria1, rect);
2473         
2474         widgetbase_draw(&wtb, wcol);
2475         
2476         /* text space */
2477         rect->xmax -= (rect->ymax-rect->ymin);
2478 }
2479
2480 static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2481 {
2482         uiWidgetBase wtb;
2483         
2484         widget_init(&wtb);
2485         
2486         /* half rounded */
2487         round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2488         
2489         /* decoration */
2490         widgetbase_draw(&wtb, wcol);
2491 }
2492
2493 static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2494 {
2495         if(state & UI_ACTIVE) {
2496                 uiWidgetBase wtb;
2497                 float rad= 0.5f*(rect->ymax - rect->ymin); // 4.0f
2498                 
2499                 widget_init(&wtb);
2500                 
2501                 /* half rounded */
2502                 round_box_edges(&wtb, 15, rect, rad);
2503                 
2504                 widgetbase_draw(&wtb, wcol);
2505         }
2506 }
2507
2508 static void widget_menu_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2509 {
2510         uiWidgetBase wtb;
2511         
2512         widget_init(&wtb);
2513         
2514         /* not rounded, no outline */
2515         wtb.outline= 0;
2516         round_box_edges(&wtb, 0, rect, 0.0f);
2517         
2518         widgetbase_draw(&wtb, wcol);
2519 }
2520
2521 static void widget_list_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
2522 {
2523         uiWidgetBase wtb;
2524         
2525         widget_init(&wtb);
2526         
2527         /* rounded, but no outline */
2528         wtb.outline= 0;
2529         round_box_edges(&wtb, 15, rect, 4.0f);
2530         
2531         widgetbase_draw(&wtb, wcol);
2532 }
2533
2534 static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
2535 {
2536         uiWidgetBase wtb;
2537         rcti recttemp= *rect;
2538         int delta;
2539         
2540         widget_init(&wtb);
2541         
2542         /* square */
2543         recttemp.xmax= recttemp.xmin + (recttemp.ymax-recttemp.ymin);
2544         
2545         /* smaller */
2546         delta= 1 + (recttemp.ymax-recttemp.ymin)/8;
2547         recttemp.xmin+= delta;
2548         recttemp.ymin+= delta;
2549         recttemp.xmax-= delta;
2550         recttemp.ymax-= delta;
2551         
2552         /* half rounded */
2553         round_box_edges(&wtb, 15, &recttemp, 4.0f);
2554         
2555         /* decoration */
2556         if(state & UI_SELECT) {
2557                 widget_check_trias(&wtb.tria1, &recttemp);
2558         }
2559         
2560         widgetbase_draw(&wtb, wcol);
2561         
2562         /* text space */
2563         rect->xmin += (rect->ymax-rect->ymin)*0.7 + delta;
2564 }
2565
2566
2567 static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2568 {
2569         uiWidgetBase wtb;
2570         
2571         widget_init(&wtb);
2572         
2573         /* half rounded */
2574         round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2575         
2576         widgetbase_draw(&wtb, wcol);
2577
2578 }
2579
2580 static void widget_box(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2581 {
2582         uiWidgetBase wtb;
2583         char old_col[3];
2584         
2585         widget_init(&wtb);
2586         
2587         VECCOPY(old_col, wcol->inner);
2588         
2589         /* abuse but->hsv - if it's non-zero, use this color as the box's background */
2590         if (but->col[3]) {
2591                 wcol->inner[0] = but->col[0];
2592                 wcol->inner[1] = but->col[1];
2593                 wcol->inner[2] = but->col[2];
2594         }
2595         
2596         /* half rounded */
2597         round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2598         
2599         widgetbase_draw(&wtb, wcol);
2600         
2601         /* store the box bg as gl clearcolor, to retrieve later when drawing semi-transparent rects
2602          * over the top to indicate disabled buttons */
2603         /* XXX, this doesnt work right since the color applies to buttons outside the box too. */
2604         glClearColor(wcol->inner[0]/255.0, wcol->inner[1]/255.0, wcol->inner[2]/255.0, 1.0);
2605         
2606         VECCOPY(wcol->inner, old_col);
2607 }
2608
2609 static void widget_but(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2610 {
2611         uiWidgetBase wtb;
2612         
2613         widget_init(&wtb);
2614         
2615         /* half rounded */
2616         round_box_edges(&wtb, roundboxalign, rect, 4.0f);
2617                 
2618         widgetbase_draw(&wtb, wcol);
2619
2620 }
2621
2622 static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
2623 {
2624         uiWidgetBase wtb;
2625         float rad= 5.0f; //0.5f*(rect->ymax - rect->ymin);
2626         
2627         widget_init(&wtb);
2628         
2629         /* half rounded */
2630         round_box_edges(&wtb, roundboxalign, rect, rad);
2631
2632         widgetbase_draw(&wtb, wcol);
2633 }
2634
2635 static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *wt, rcti *rect)
2636 {
2637         uiWidgetBase wtb;
2638         unsigned char col[4];
2639         
2640         /* state copy! */
2641         wt->wcol= *(wt->wcol_theme);
2642         
2643         widget_init(&wtb);
2644         
2645         if(but->block->drawextra) {
2646                 /* note: drawextra can change rect +1 or -1, to match round errors of existing previews */
2647                 but->block->drawextra(C, but->poin, but->block->drawextra_arg1, but->block->drawextra_arg2, rect);
2648                 
2649                 /* make mask to draw over image */
2650                 UI_GetThemeColor3ubv(TH_BACK, col);
2651                 glColor3ubv(col);
2652                 
2653                 round_box__edges(&wtb, 15, rect, 0.0f, 4.0);
2654                 widgetbase_outline(&wtb);
2655         }
2656         
2657         /* outline */
2658         round_box_edges(&wtb, 15, rect, 5.0f);
2659         wtb.outline= 1;
2660         wtb.inner= 0;
2661         widgetbase_draw(&wtb, &wt->wcol);
2662         
2663 }
2664
2665
2666 static void widget_disabled(rcti *rect)
2667 {
2668         float col[4];
2669         
2670         glEnable(GL_BLEND);
2671         
2672         /* can't use theme TH_BACK or TH_PANEL... undefined */
2673         glGetFloatv(GL_COLOR_CLEAR_VALUE, col);
2674         glColor4f(col[0], col[1], col[2], 0.5f);
2675
2676         /* need -1 and +1 to make it work right for aligned buttons,
2677          * but problem may be somewhere else? */
2678         glRectf(rect->xmin-1, rect->ymin-1, rect->xmax, rect->ymax+1);
2679         
2680         glDisable(GL_BLEND);
2681 }
2682
2683 static uiWidgetType *widget_type(uiWidgetTypeEnum type)
2684 {
2685         bTheme *btheme= U.themes.first;
2686         static uiWidgetType wt;
2687         
2688         /* defaults */
2689         wt.wcol_theme= &btheme->tui.wcol_regular;
2690         wt.wcol_state= &btheme->tui.wcol_state;
2691         wt.state= widget_state;
2692         wt.draw= widget_but;
2693         wt.custom= NULL;
2694         wt.text= widget_draw_text_icon;
2695         
2696         switch(type) {
2697                 case UI_WTYPE_REGULAR:
2698                         break;
2699
2700                 case UI_WTYPE_LABEL:
2701                         wt.draw= NULL;
2702                         wt.state= widget_state_label;
2703                         break;
2704                         
2705                 case UI_WTYPE_TOGGLE:
2706                         wt.wcol_theme= &btheme->tui.wcol_toggle;
2707                         break;
2708                         
2709                 case UI_WTYPE_OPTION:
2710                         wt.wcol_theme= &btheme->tui.wcol_option;
2711                         wt.draw= widget_optionbut;
2712                         break;
2713                         
2714                 case UI_WTYPE_RADIO:
2715                         wt.wcol_theme= &btheme->tui.wcol_radio;
2716                         wt.draw= widget_radiobut;
2717                         break;
2718
2719                 case UI_WTYPE_NUMBER:
2720                         wt.wcol_theme= &btheme->tui.wcol_num;
2721                         wt.draw= widget_numbut;
2722                         break;
2723                         
2724                 case UI_WTYPE_SLIDER:
2725                         wt.wcol_theme= &btheme->tui.wcol_numslider;
2726                         wt.custom= widget_numslider;
2727                         wt.state= widget_state_numslider;
2728                         break;
2729                         
2730                 case UI_WTYPE_EXEC:
2731                         wt.wcol_theme= &btheme->tui.wcol_tool;
2732                         wt.draw= widget_roundbut;
2733                         break;
2734                         
2735                         
2736                         /* strings */
2737                 case UI_WTYPE_NAME:
2738                         wt.wcol_theme= &btheme->tui.wcol_text;
2739                         wt.draw= widget_textbut;
2740                         break;
2741                         
2742                 case UI_WTYPE_NAME_LINK:
2743                         break;
2744                         
2745                 case UI_WTYPE_POINTER_LINK:
2746                         break;
2747                         
2748                 case UI_WTYPE_FILENAME:
2749                         break;
2750                         
2751                         
2752                         /* start menus */
2753                 case UI_WTYPE_MENU_RADIO:
2754                         wt.wcol_theme= &btheme->tui.wcol_menu;
2755                         wt.draw= widget_menubut;
2756                         break;
2757
2758                 case UI_WTYPE_MENU_ICON_RADIO:
2759                         wt.wcol_theme= &btheme->tui.wcol_menu;
2760                         wt.draw= widget_menuiconbut;
2761                         break;
2762                         
2763                 case UI_WTYPE_MENU_POINTER_LINK:
2764                         wt.wcol_theme= &btheme->tui.wcol_menu;
2765                         wt.draw= widget_menubut;
2766                         break;
2767                         
2768                 case UI_WTYPE_PULLDOWN:
2769                         wt.wcol_theme= &btheme->tui.wcol_pulldown;
2770                         wt.draw= widget_pulldownbut;
2771                         wt.state= widget_state_pulldown;
2772                         break;
2773                         
2774                         /* in menus */
2775                 case UI_WTYPE_MENU_ITEM:
2776                         wt.wcol_theme= &btheme->tui.wcol_menu_item;
2777                         wt.draw= widget_menu_itembut;
2778                         wt.state= widget_state_menu_item;
2779                         break;
2780                         
2781                 case UI_WTYPE_MENU_BACK:
2782                         wt.wcol_theme= &btheme->tui.wcol_menu_back;
2783                         wt.draw= widget_menu_back;
2784                         break;
2785                         
2786                         /* specials */
2787                 case UI_WTYPE_ICON:
2788                         wt.custom= widget_icon_has_anim;
2789                         break;
2790                         
2791                 case UI_WTYPE_SWATCH:
2792                         wt.custom= widget_swatch;
2793                         break;
2794                         
2795                 case UI_WTYPE_BOX:
2796                         wt.custom= widget_box;
2797                         wt.wcol_theme= &btheme->tui.wcol_box;
2798                         break;
2799                         
2800                 case UI_WTYPE_RGB_PICKER:
2801                         break;
2802                         
2803                 case UI_WTYPE_NORMAL:
2804                         break;
2805
2806                 case UI_WTYPE_SCROLL:
2807                         wt.wcol_theme= &btheme->tui.wcol_scroll;
2808                         wt.state= widget_state_nothing;
2809                         wt.custom= widget_scroll;
2810                         break;
2811
2812                 case UI_WTYPE_LISTITEM:
2813                         wt.wcol_theme= &btheme->tui.wcol_list_item;
2814                         wt.draw= widget_list_itembut;
2815                         break;
2816                         
2817                 case UI_WTYPE_PROGRESSBAR:
2818                         wt.wcol_theme= &btheme->tui.wcol_progress;
2819                         wt.custom= widget_progressbar;
2820                         break;
2821         }
2822         
2823         return &wt;
2824 }
2825
2826
2827 static int widget_roundbox_set(uiBut *but, rcti *rect)
2828 {
2829         /* alignment */
2830         if(but->flag & UI_BUT_ALIGN) {
2831                 
2832                 if(but->flag & UI_BUT_ALIGN_TOP)
2833                         rect->ymax+= 1;
2834                 if(but->flag & UI_BUT_ALIGN_LEFT)
2835                         rect->xmin-= 1;
2836                 
2837                 switch(but->flag & UI_BUT_ALIGN) {
2838                         case UI_BUT_ALIGN_TOP:
2839                                 return (12);
2840                                 break;
2841                         case UI_BUT_ALIGN_DOWN:
2842                                 return (3);
2843                                 break;
2844                         case UI_BUT_ALIGN_LEFT:
2845                                 return (6);
2846                                 break;
2847                         case UI_BUT_ALIGN_RIGHT:
2848                                 return (9);
2849                                 break;
2850                                 
2851                         case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT:
2852                                 return (1);
2853                                 break;
2854                         case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT:
2855                                 return (2);
2856                                 break;
2857                         case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
2858                                 return (8);
2859                                 break;
2860                         case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
2861                                 return (4);
2862                                 break;
2863                                 
2864                         default:
2865                                 return (0);
2866                                 break;
2867                 }
2868         } 
2869         return 15;
2870 }
2871
2872 /* conversion from old to new buttons, so still messy */
2873 void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rcti *rect)
2874 {
2875         bTheme *btheme= U.themes.first;
2876         ThemeUI *tui= &btheme->tui;
2877         uiFontStyle *fstyle= &style->widget;
2878         uiWidgetType *wt= NULL;
2879
2880         /* handle menus separately */
2881         if(but->dt==UI_EMBOSSP) {
2882                 switch (but->type) {
2883                         case LABEL:
2884                                 widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2885                                 break;
2886                         case SEPR:
2887                                 ui_draw_separator(rect, &tui->wcol_menu_item);
2888                                 break;
2889                                 
2890                         default:
2891                                 wt= widget_type(UI_WTYPE_MENU_ITEM);
2892                 }
2893         }
2894         else if(but->dt==UI_EMBOSSN) {
2895                 /* "nothing" */
2896                 wt= widget_type(UI_WTYPE_ICON);
2897         }
2898         else {
2899                 
2900                 switch (but->type) {
2901                         case LABEL:
2902                                 if(but->block->flag & UI_BLOCK_LOOP)
2903                                         widget_draw_text_icon(&style->widgetlabel, &tui->wcol_menu_back, but, rect);
2904                                 else {
2905                                         wt= widget_type(UI_WTYPE_LABEL);
2906                                         fstyle= &style->widgetlabel;
2907                                 }
2908                                 break;
2909                                 
2910                         case SEPR:
2911                                 break;
2912                                 
2913                         case BUT:
2914                                 wt= widget_type(UI_WTYPE_EXEC);
2915                                 break;
2916
2917                         case NUM:
2918                                 wt= widget_type(UI_WTYPE_NUMBER);
2919                                 break;
2920                                 
2921                         case NUMSLI:
2922                         case HSVSLI:
2923                                 wt= widget_type(UI_WTYPE_SLIDER);
2924                                 break;
2925                                 
2926                         case ROW:
2927                                 wt= widget_type(UI_WTYPE_RADIO);
2928                                 break;
2929
2930                         case LISTROW:
2931                                 wt= widget_type(UI_WTYPE_LISTITEM);
2932                                 break;
2933                                 
2934                         case TEX:
2935                                 wt= widget_type(UI_WTYPE_NAME);
2936                                 break;
2937                                 
2938                         case SEARCH_MENU:
2939                                 wt= widget_type(UI_WTYPE_NAME);
2940                                 if(but->block->flag & UI_BLOCK_LOOP)
2941                                         wt->wcol_theme= &btheme->tui.wcol_menu_back;
2942                                 break;
2943                                 
2944                         case TOGBUT:
2945                         case TOG:
2946                         case TOGN:
2947                         case TOG3:
2948                                 wt= widget_type(UI_WTYPE_TOGGLE);
2949                                 break;
2950                                 
2951                         case OPTION:
2952                         case OPTIONN:
2953                                 if (!(but->flag & UI_HAS_ICON)) {
2954                                         wt= widget_type(UI_WTYPE_OPTION);
2955                                         but->flag |= UI_TEXT_LEFT;
2956                                 }
2957                                 else
2958                                         wt= widget_type(UI_WTYPE_TOGGLE);
2959                                 
2960                                 /* option buttons have strings outside, on menus use different colors */
2961                                 if(but->block->flag & UI_BLOCK_LOOP)
2962                                         wt->state= widget_state_option_menu;
2963                                 
2964                                 break;
2965                                 
2966                         case MENU:
2967                         case BLOCK:
2968                         case ICONTEXTROW:
2969                                 if(!but->str[0] && but->icon)
2970                                         wt= widget_type(UI_WTYPE_MENU_ICON_RADIO);
2971                                 else
2972                                         wt= widget_type(UI_WTYPE_MENU_RADIO);
2973                                 break;
2974                                 
2975                         case PULLDOWN:
2976                                 wt= widget_type(UI_WTYPE_PULLDOWN);
2977                                 break;
2978                         
2979                         case BUTM:
2980                                 wt= widget_type(UI_WTYPE_MENU_ITEM);
2981                                 break;
2982                                 
2983                         case COL:
2984                                 wt= widget_type(UI_WTYPE_SWATCH);
2985                                 break;
2986                                 
2987                         case ROUNDBOX:
2988                         case LISTBOX:
2989                                 wt= widget_type(UI_WTYPE_BOX);
2990                                 break;
2991                                 
2992                         case LINK:
2993                         case INLINK:
2994                                 wt= widget_type(UI_WTYPE_ICON);
2995                                 wt->custom= widget_link;
2996                                 
2997                                 break;
2998                         
2999                         case BUT_EXTRA:
3000                                 widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
3001                                 break;
3002                                 
3003                         case HSVCUBE:
3004                                 if(but->a1 == UI_GRAD_V_ALT) // vertical V slider, uses new widget draw now
3005                                         ui_draw_but_HSV_v(but, rect);
3006                                 else  // other HSV pickers...
3007                                         ui_draw_but_HSVCUBE(but, rect);
3008                                 break;
3009                                 
3010                         case HSVCIRCLE:
3011                                 ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
3012                                 break;
3013                                 
3014                         case BUT_COLORBAND:
3015                                 ui_draw_but_COLORBAND(but, &tui->wcol_regular, rect);
3016                                 break;
3017                                 
3018                         case BUT_NORMAL:
3019                                 ui_draw_but_NORMAL(but, &tui->wcol_regular, rect);
3020                                 break;
3021                                 
3022                         case BUT_IMAGE:
3023                                 ui_draw_but_IMAGE(ar, but, &tui->wcol_regular, rect);
3024                                 break;
3025                         
3026                         case HISTOGRAM:
3027                                 ui_draw_but_HISTOGRAM(ar, but, &tui->wcol_regular, rect);
3028                                 break;
3029                                 
3030                         case WAVEFORM:
3031                                 ui_draw_but_WAVEFORM(ar, but, &tui->wcol_regular, rect);
3032                                 break;
3033                                 
3034                         case VECTORSCOPE:
3035                                 ui_draw_but_VECTORSCOPE(ar, but, &tui->wcol_regular, rect);
3036                                 break;
3037                                         
3038                         case BUT_CURVE:
3039                                 ui_draw_but_CURVE(ar, but, &tui->wcol_regular, rect);
3040                                 break;
3041                                 
3042                         case PROGRESSBAR:
3043                                 wt= widget_type(UI_WTYPE_PROGRESSBAR);
3044                                 fstyle= &style->widgetlabel;
3045                                 break;
3046
3047                         case SCROLL:
3048                                 wt= widget_type(UI_WTYPE_SCROLL);
3049                                 break;
3050
3051                         case TRACKPREVIEW:
3052                                 ui_draw_but_TRACKPREVIEW(ar, but, &tui->wcol_regular, rect);
3053                                 break;
3054
3055                         default:
3056                                 wt= widget_type(UI_WTYPE_REGULAR);
3057                 }
3058         }
3059         
3060         if(wt) {
3061                 rcti disablerect= *rect; /* rect gets clipped smaller for text */
3062                 int roundboxalign, state;
3063                 
3064                 roundboxalign= widget_roundbox_set(but, rect);
3065
3066                 state= but->flag;
3067                 if(but->editstr) state |= UI_TEXTINPUT;
3068                 
3069                 wt->state(wt, state);
3070                 if(wt->custom)
3071                         wt->custom(but, &wt->wcol, rect, state, roundboxalign);
3072                 else if(wt->draw)
3073                         wt->draw(&wt->wcol, rect, state, roundboxalign);
3074                 wt->text(fstyle, &wt->wcol, but, rect);
3075                 
3076                 if(state & (UI_BUT_DISABLED|UI_BUT_INACTIVE))
3077                         if(but->dt!=UI_EMBOSSP)
3078                                 widget_disabled(&disablerect);
3079         }
3080 }
3081
3082 void ui_draw_menu_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
3083 {
3084         uiWidgetType *wt= widget_type(UI_WTYPE_MENU_BACK);
3085         
3086         wt->state(wt, 0);
3087         if(block)
3088                 wt->draw(&wt->wcol, rect, block->flag, block->direction);
3089         else
3090                 wt->draw(&wt->wcol, rect, 0, 0);
3091         
3092         if(block) {
3093                 if(block->flag & UI_BLOCK_CLIPTOP) {
3094                         /* XXX no scaling for UI here yet */
3095                         glColor3ubv((unsigned char*)wt->wcol.text);
3096                         UI_DrawTriIcon((rect->xmax+rect->xmin)/2, rect->ymax-8, 't');
3097                 }
3098                 if(block->flag & UI_BLOCK_CLIPBOTTOM) {
3099                         /* XXX no scaling for UI here yet */
3100                         glColor3ubv((unsigned char*)wt->wcol.text);
3101                         UI_DrawTriIcon((rect->xmax+rect->xmin)/2, rect->ymin+10, 'v');
3102                 }
3103         }       
3104 }
3105
3106 void ui_draw_search_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
3107 {
3108         uiWidgetType *wt= widget_type(UI_WTYPE_BOX);
3109         
3110         glEnable(GL_BLEND);
3111         widget_softshadow(rect, 15, 5.0f, 8.0f);
3112         glDisable(GL_BLEND);
3113
3114         wt->state(wt, 0);
3115         if(block)
3116                 wt->draw(&wt->wcol, rect, block->flag, 15);
3117         else
3118                 wt->draw(&wt->wcol, rect, 0, 15);
3119         
3120 }
3121
3122
3123 /* helper call to draw a menu item without button */
3124 /* state: UI_ACTIVE or 0 */
3125 void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, i