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