spaces -> tabs, (4 spaces == 1 tab, only for white space preceding text)
[blender.git] / source / blender / editors / interface / interface_draw.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * Contributor(s): Blender Foundation
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include <math.h>
29 #include <string.h>
30
31 #include "DNA_color_types.h"
32 #include "DNA_listBase.h"
33 #include "DNA_object_types.h"
34 #include "DNA_screen_types.h"
35 #include "DNA_texture_types.h"
36 #include "DNA_userdef_types.h"
37
38 #include "BLI_math.h"
39
40 #include "BKE_colortools.h"
41 #include "BKE_texture.h"
42 #include "BKE_utildefines.h"
43
44 #include "IMB_imbuf.h"
45 #include "IMB_imbuf_types.h"
46
47 #include "BIF_gl.h"
48 #include "BIF_glutil.h"
49
50 #include "UI_interface.h"
51 #include "UI_interface_icons.h"
52
53 #include "interface_intern.h"
54
55 #define UI_RB_ALPHA 16
56 #define UI_DISABLED_ALPHA_OFFS  -160
57
58 static int roundboxtype= 15;
59
60 void uiSetRoundBox(int type)
61 {
62         /* Not sure the roundbox function is the best place to change this
63          * if this is undone, its not that big a deal, only makes curves edges
64          * square for the  */
65         roundboxtype= type;
66
67         /* flags to set which corners will become rounded:
68
69         1------2
70         |      |
71         8------4
72         */
73         
74 }
75
76 int uiGetRoundBox(void)
77 {
78         return roundboxtype;
79 }
80
81 void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad)
82 {
83         float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
84                                           {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
85         int a;
86         
87         /* mult */
88         for(a=0; a<7; a++) {
89                 vec[a][0]*= rad; vec[a][1]*= rad;
90         }
91
92         glBegin(mode);
93
94         /* start with corner right-bottom */
95         if(roundboxtype & 4) {
96                 glVertex2f(maxx-rad, miny);
97                 for(a=0; a<7; a++) {
98                         glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
99                 }
100                 glVertex2f(maxx, miny+rad);
101         }
102         else glVertex2f(maxx, miny);
103         
104         /* corner right-top */
105         if(roundboxtype & 2) {
106                 glVertex2f(maxx, maxy-rad);
107                 for(a=0; a<7; a++) {
108                         glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
109                 }
110                 glVertex2f(maxx-rad, maxy);
111         }
112         else glVertex2f(maxx, maxy);
113         
114         /* corner left-top */
115         if(roundboxtype & 1) {
116                 glVertex2f(minx+rad, maxy);
117                 for(a=0; a<7; a++) {
118                         glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
119                 }
120                 glVertex2f(minx, maxy-rad);
121         }
122         else glVertex2f(minx, maxy);
123         
124         /* corner left-bottom */
125         if(roundboxtype & 8) {
126                 glVertex2f(minx, miny+rad);
127                 for(a=0; a<7; a++) {
128                         glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
129                 }
130                 glVertex2f(minx+rad, miny);
131         }
132         else glVertex2f(minx, miny);
133         
134         glEnd();
135 }
136
137 static void round_box_shade_col(float *col1, float *col2, float fac)
138 {
139         float col[3];
140
141         col[0]= (fac*col1[0] + (1.0-fac)*col2[0]);
142         col[1]= (fac*col1[1] + (1.0-fac)*col2[1]);
143         col[2]= (fac*col1[2] + (1.0-fac)*col2[2]);
144         
145         glColor3fv(col);
146 }
147
148
149 /* linear horizontal shade within button or in outline */
150 /* view2d scrollers use it */
151 void gl_round_box_shade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown)
152 {
153         float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
154                                           {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
155         float div= maxy-miny;
156         float coltop[3], coldown[3], color[4];
157         int a;
158         
159         /* mult */
160         for(a=0; a<7; a++) {
161                 vec[a][0]*= rad; vec[a][1]*= rad;
162         }
163         /* get current color, needs to be outside of glBegin/End */
164         glGetFloatv(GL_CURRENT_COLOR, color);
165
166         /* 'shade' defines strength of shading */       
167         coltop[0]= color[0]+shadetop; if(coltop[0]>1.0) coltop[0]= 1.0;
168         coltop[1]= color[1]+shadetop; if(coltop[1]>1.0) coltop[1]= 1.0;
169         coltop[2]= color[2]+shadetop; if(coltop[2]>1.0) coltop[2]= 1.0;
170         coldown[0]= color[0]+shadedown; if(coldown[0]<0.0) coldown[0]= 0.0;
171         coldown[1]= color[1]+shadedown; if(coldown[1]<0.0) coldown[1]= 0.0;
172         coldown[2]= color[2]+shadedown; if(coldown[2]<0.0) coldown[2]= 0.0;
173
174         glShadeModel(GL_SMOOTH);
175         glBegin(mode);
176
177         /* start with corner right-bottom */
178         if(roundboxtype & 4) {
179                 
180                 round_box_shade_col(coltop, coldown, 0.0);
181                 glVertex2f(maxx-rad, miny);
182                 
183                 for(a=0; a<7; a++) {
184                         round_box_shade_col(coltop, coldown, vec[a][1]/div);
185                         glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
186                 }
187                 
188                 round_box_shade_col(coltop, coldown, rad/div);
189                 glVertex2f(maxx, miny+rad);
190         }
191         else {
192                 round_box_shade_col(coltop, coldown, 0.0);
193                 glVertex2f(maxx, miny);
194         }
195         
196         /* corner right-top */
197         if(roundboxtype & 2) {
198                 
199                 round_box_shade_col(coltop, coldown, (div-rad)/div);
200                 glVertex2f(maxx, maxy-rad);
201                 
202                 for(a=0; a<7; a++) {
203                         round_box_shade_col(coltop, coldown, (div-rad+vec[a][1])/div);
204                         glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
205                 }
206                 round_box_shade_col(coltop, coldown, 1.0);
207                 glVertex2f(maxx-rad, maxy);
208         }
209         else {
210                 round_box_shade_col(coltop, coldown, 1.0);
211                 glVertex2f(maxx, maxy);
212         }
213         
214         /* corner left-top */
215         if(roundboxtype & 1) {
216                 
217                 round_box_shade_col(coltop, coldown, 1.0);
218                 glVertex2f(minx+rad, maxy);
219                 
220                 for(a=0; a<7; a++) {
221                         round_box_shade_col(coltop, coldown, (div-vec[a][1])/div);
222                         glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
223                 }
224                 
225                 round_box_shade_col(coltop, coldown, (div-rad)/div);
226                 glVertex2f(minx, maxy-rad);
227         }
228         else {
229                 round_box_shade_col(coltop, coldown, 1.0);
230                 glVertex2f(minx, maxy);
231         }
232         
233         /* corner left-bottom */
234         if(roundboxtype & 8) {
235                 
236                 round_box_shade_col(coltop, coldown, rad/div);
237                 glVertex2f(minx, miny+rad);
238                 
239                 for(a=0; a<7; a++) {
240                         round_box_shade_col(coltop, coldown, (rad-vec[a][1])/div);
241                         glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
242                 }
243                 
244                 round_box_shade_col(coltop, coldown, 0.0);
245                 glVertex2f(minx+rad, miny);
246         }
247         else {
248                 round_box_shade_col(coltop, coldown, 0.0);
249                 glVertex2f(minx, miny);
250         }
251         
252         glEnd();
253         glShadeModel(GL_FLAT);
254 }
255
256 /* linear vertical shade within button or in outline */
257 /* view2d scrollers use it */
258 void gl_round_box_vertical_shade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadeLeft, float shadeRight)
259 {
260         float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
261                                           {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
262         float div= maxx-minx;
263         float colLeft[3], colRight[3], color[4];
264         int a;
265         
266         /* mult */
267         for(a=0; a<7; a++) {
268                 vec[a][0]*= rad; vec[a][1]*= rad;
269         }
270         /* get current color, needs to be outside of glBegin/End */
271         glGetFloatv(GL_CURRENT_COLOR, color);
272
273         /* 'shade' defines strength of shading */       
274         colLeft[0]= color[0]+shadeLeft; if(colLeft[0]>1.0) colLeft[0]= 1.0;
275         colLeft[1]= color[1]+shadeLeft; if(colLeft[1]>1.0) colLeft[1]= 1.0;
276         colLeft[2]= color[2]+shadeLeft; if(colLeft[2]>1.0) colLeft[2]= 1.0;
277         colRight[0]= color[0]+shadeRight; if(colRight[0]<0.0) colRight[0]= 0.0;
278         colRight[1]= color[1]+shadeRight; if(colRight[1]<0.0) colRight[1]= 0.0;
279         colRight[2]= color[2]+shadeRight; if(colRight[2]<0.0) colRight[2]= 0.0;
280
281         glShadeModel(GL_SMOOTH);
282         glBegin(mode);
283
284         /* start with corner right-bottom */
285         if(roundboxtype & 4) {
286                 round_box_shade_col(colLeft, colRight, 0.0);
287                 glVertex2f(maxx-rad, miny);
288                 
289                 for(a=0; a<7; a++) {
290                         round_box_shade_col(colLeft, colRight, vec[a][0]/div);
291                         glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
292                 }
293                 
294                 round_box_shade_col(colLeft, colRight, rad/div);
295                 glVertex2f(maxx, miny+rad);
296         }
297         else {
298                 round_box_shade_col(colLeft, colRight, 0.0);
299                 glVertex2f(maxx, miny);
300         }
301         
302         /* corner right-top */
303         if(roundboxtype & 2) {
304                 round_box_shade_col(colLeft, colRight, 0.0);
305                 glVertex2f(maxx, maxy-rad);
306                 
307                 for(a=0; a<7; a++) {
308                         
309                         round_box_shade_col(colLeft, colRight, (div-rad-vec[a][0])/div);
310                         glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
311                 }
312                 round_box_shade_col(colLeft, colRight, (div-rad)/div);
313                 glVertex2f(maxx-rad, maxy);
314         }
315         else {
316                 round_box_shade_col(colLeft, colRight, 0.0);
317                 glVertex2f(maxx, maxy);
318         }
319         
320         /* corner left-top */
321         if(roundboxtype & 1) {
322                 round_box_shade_col(colLeft, colRight, (div-rad)/div);
323                 glVertex2f(minx+rad, maxy);
324                 
325                 for(a=0; a<7; a++) {
326                         round_box_shade_col(colLeft, colRight, (div-rad+vec[a][0])/div);
327                         glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
328                 }
329                 
330                 round_box_shade_col(colLeft, colRight, 1.0);
331                 glVertex2f(minx, maxy-rad);
332         }
333         else {
334                 round_box_shade_col(colLeft, colRight, 1.0);
335                 glVertex2f(minx, maxy);
336         }
337         
338         /* corner left-bottom */
339         if(roundboxtype & 8) {
340                 round_box_shade_col(colLeft, colRight, 1.0);
341                 glVertex2f(minx, miny+rad);
342                 
343                 for(a=0; a<7; a++) {
344                         round_box_shade_col(colLeft, colRight, (vec[a][0])/div);
345                         glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
346                 }
347                 
348                 round_box_shade_col(colLeft, colRight, 1.0);
349                 glVertex2f(minx+rad, miny);
350         }
351         else {
352                 round_box_shade_col(colLeft, colRight, 1.0);
353                 glVertex2f(minx, miny);
354         }
355         
356         glEnd();
357         glShadeModel(GL_FLAT);
358 }
359
360 /* plain antialiased unfilled rectangle */
361 void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad)
362 {
363         float color[4];
364         
365         if(roundboxtype & UI_RB_ALPHA) {
366                 glGetFloatv(GL_CURRENT_COLOR, color);
367                 color[3]= 0.5;
368                 glColor4fv(color);
369                 glEnable( GL_BLEND );
370         }
371         
372         /* set antialias line */
373         glEnable( GL_LINE_SMOOTH );
374         glEnable( GL_BLEND );
375
376         gl_round_box(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
377    
378         glDisable( GL_BLEND );
379         glDisable( GL_LINE_SMOOTH );
380 }
381
382 /* plain fake antialiased unfilled round rectangle */
383 void uiRoundRectFakeAA(float minx, float miny, float maxx, float maxy, float rad, float asp)
384 {
385         float color[4], alpha;
386         float raddiff;
387         int i, passes=4;
388         
389         /* get the colour and divide up the alpha */
390         glGetFloatv(GL_CURRENT_COLOR, color);
391         alpha = 1; //color[3];
392         color[3]= 0.5*alpha/(float)passes;
393         glColor4fv(color);
394         
395         /* set the 'jitter amount' */
396         raddiff = (1/(float)passes) * asp;
397         
398         glEnable( GL_BLEND );
399         
400         /* draw lots of lines on top of each other */
401         for (i=passes; i>=(-passes); i--) {
402                 gl_round_box(GL_LINE_LOOP, minx, miny, maxx, maxy, rad+(i*raddiff));
403         }
404         
405         glDisable( GL_BLEND );
406         
407         color[3] = alpha;
408         glColor4fv(color);
409 }
410
411 /* (old, used in outliner) plain antialiased filled box */
412 void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad)
413 {
414         float color[4];
415         
416         if(roundboxtype & UI_RB_ALPHA) {
417                 glGetFloatv(GL_CURRENT_COLOR, color);
418                 color[3]= 0.5;
419                 glColor4fv(color);
420                 glEnable( GL_BLEND );
421         }
422         
423         /* solid part */
424         gl_round_box(GL_POLYGON, minx, miny, maxx, maxy, rad);
425         
426         /* set antialias line */
427         glEnable( GL_LINE_SMOOTH );
428         glEnable( GL_BLEND );
429         
430         gl_round_box(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
431         
432         glDisable( GL_BLEND );
433         glDisable( GL_LINE_SMOOTH );
434 }
435
436
437 /* ************** generic embossed rect, for window sliders etc ************* */
438
439
440 /* text_draw.c uses this */
441 void uiEmboss(float x1, float y1, float x2, float y2, int sel)
442 {
443         
444         /* below */
445         if(sel) glColor3ub(200,200,200);
446         else glColor3ub(50,50,50);
447         fdrawline(x1, y1, x2, y1);
448
449         /* right */
450         fdrawline(x2, y1, x2, y2);
451         
452         /* top */
453         if(sel) glColor3ub(50,50,50);
454         else glColor3ub(200,200,200);
455         fdrawline(x1, y2, x2, y2);
456
457         /* left */
458         fdrawline(x1, y1, x1, y2);
459         
460 }
461
462 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
463
464 void ui_draw_but_IMAGE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect)
465 {
466         extern char datatoc_splash_png[];
467         extern int datatoc_splash_png_size;
468         ImBuf *ibuf;
469         //GLint scissor[4];
470         //int w, h;
471         
472         /* hardcoded to splash, loading and freeing every draw, eek! */
473         ibuf= IMB_ibImageFromMemory((int *)datatoc_splash_png, datatoc_splash_png_size, IB_rect);
474
475         if (!ibuf) return;
476         
477         /* scissor doesn't seem to be doing the right thing...?
478         //glColor4f(1.0, 0.f, 0.f, 1.f);
479         //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax)
480
481         w = (rect->xmax - rect->xmin);
482         h = (rect->ymax - rect->ymin);
483         // prevent drawing outside widget area
484         glGetIntegerv(GL_SCISSOR_BOX, scissor);
485         glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h);
486         */
487         
488         glEnable(GL_BLEND);
489         glColor4f(0.0, 0.0, 0.0, 0.0);
490         
491         glaDrawPixelsSafe((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
492         //glaDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
493         
494         glDisable(GL_BLEND);
495         
496         /* 
497         // restore scissortest
498         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
499         */
500         
501         IMB_freeImBuf(ibuf);
502 }
503
504 #if 0
505 #ifdef INTERNATIONAL
506 static void ui_draw_but_CHARTAB(uiBut *but)
507 {
508         /* XXX 2.50 bad global access */
509         /* Some local variables */
510         float sx, sy, ex, ey;
511         float width, height;
512         float butw, buth;
513         int x, y, cs;
514         wchar_t wstr[2];
515         unsigned char ustr[16];
516         PackedFile *pf;
517         int result = 0;
518         int charmax = G.charmax;
519         
520         /* <builtin> font in use. There are TTF <builtin> and non-TTF <builtin> fonts */
521         if(!strcmp(G.selfont->name, "<builtin>"))
522         {
523                 if(G.ui_international == TRUE)
524                 {
525                         charmax = 0xff;
526                 }
527                 else
528                 {
529                         charmax = 0xff;
530                 }
531         }
532
533         /* Category list exited without selecting the area */
534         if(G.charmax == 0)
535                 charmax = G.charmax = 0xffff;
536
537         /* Calculate the size of the button */
538         width = abs(rect->xmax - rect->xmin);
539         height = abs(rect->ymax - rect->ymin);
540         
541         butw = floor(width / 12);
542         buth = floor(height / 6);
543         
544         /* Initialize variables */
545         sx = rect->xmin;
546         ex = rect->xmin + butw;
547         sy = rect->ymin + height - buth;
548         ey = rect->ymin + height;
549
550         cs = G.charstart;
551
552         /* Set the font, in case it is not <builtin> font */
553         if(G.selfont && strcmp(G.selfont->name, "<builtin>"))
554         {
555                 char tmpStr[256];
556
557                 // Is the font file packed, if so then use the packed file
558                 if(G.selfont->packedfile)
559                 {
560                         pf = G.selfont->packedfile;             
561                         FTF_SetFont(pf->data, pf->size, 14.0);
562                 }
563                 else
564                 {
565                         int err;
566
567                         strcpy(tmpStr, G.selfont->name);
568                         BLI_path_abs(tmpStr, G.sce);
569                         err = FTF_SetFont((unsigned char *)tmpStr, 0, 14.0);
570                 }
571         }
572         else
573         {
574                 if(G.ui_international == TRUE)
575                 {
576                         FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 14.0);
577                 }
578         }
579
580         /* Start drawing the button itself */
581         glShadeModel(GL_SMOOTH);
582
583         glColor3ub(200,  200,  200);
584         glRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
585
586         glColor3ub(0,  0,  0);
587         for(y = 0; y < 6; y++)
588         {
589                 // Do not draw more than the category allows
590                 if(cs > charmax) break;
591
592                 for(x = 0; x < 12; x++)
593                 {
594                         // Do not draw more than the category allows
595                         if(cs > charmax) break;
596
597                         // Draw one grid cell
598                         glBegin(GL_LINE_LOOP);
599                                 glVertex2f(sx, sy);
600                                 glVertex2f(ex, sy);
601                                 glVertex2f(ex, ey);
602                                 glVertex2f(sx, ey);                             
603                         glEnd();        
604
605                         // Draw character inside the cell
606                         memset(wstr, 0, sizeof(wchar_t)*2);
607                         memset(ustr, 0, 16);
608
609                         // Set the font to be either unicode or <builtin>                               
610                         wstr[0] = cs;
611                         if(strcmp(G.selfont->name, "<builtin>"))
612                         {
613                                 wcs2utf8s((char *)ustr, (wchar_t *)wstr);
614                         }
615                         else
616                         {
617                                 if(G.ui_international == TRUE)
618                                 {
619                                         wcs2utf8s((char *)ustr, (wchar_t *)wstr);
620                                 }
621                                 else
622                                 {
623                                         ustr[0] = cs;
624                                         ustr[1] = 0;
625                                 }
626                         }
627
628                         if((G.selfont && strcmp(G.selfont->name, "<builtin>")) || (G.selfont && !strcmp(G.selfont->name, "<builtin>") && G.ui_international == TRUE))
629                         {
630                                 float wid;
631                                 float llx, lly, llz, urx, ury, urz;
632                                 float dx, dy;
633                                 float px, py;
634         
635                                 // Calculate the position
636                                 wid = FTF_GetStringWidth((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
637                                 FTF_GetBoundingBox((char *) ustr, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
638                                 dx = urx-llx;
639                                 dy = ury-lly;
640
641                                 // This isn't fully functional since the but->aspect isn't working like I suspected
642                                 px = sx + ((butw/but->aspect)-dx)/2;
643                                 py = sy + ((buth/but->aspect)-dy)/2;
644
645                                 // Set the position and draw the character
646                                 ui_rasterpos_safe(px, py, but->aspect);
647                                 FTF_DrawString((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
648                         }
649                         else
650                         {
651                                 ui_rasterpos_safe(sx + butw/2, sy + buth/2, but->aspect);
652                                 UI_DrawString(but->font, (char *) ustr, 0);
653                         }
654         
655                         // Calculate the next position and character
656                         sx += butw; ex +=butw;
657                         cs++;
658                 }
659                 /* Add the y position and reset x position */
660                 sy -= buth; 
661                 ey -= buth;
662                 sx = rect->xmin;
663                 ex = rect->xmin + butw;
664         }       
665         glShadeModel(GL_FLAT);
666
667         /* Return Font Settings to original */
668         if(U.fontsize && U.fontname[0])
669         {
670                 result = FTF_SetFont((unsigned char *)U.fontname, 0, U.fontsize);
671         }
672         else if (U.fontsize)
673         {
674                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, U.fontsize);
675         }
676
677         if (result == 0)
678         {
679                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 11);
680         }
681         
682         /* resets the font size */
683         if(G.ui_international == TRUE)
684         {
685                 // uiSetCurFont(but->block, UI_HELV);
686         }
687 }
688
689 #endif // INTERNATIONAL
690 #endif
691
692
693 void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *recti)
694 {
695         Histogram *hist = (Histogram *)but->poin;
696         int res = hist->x_resolution;
697         rctf rect;
698         int i;
699         int rgb;
700         float w, h;
701         float alpha;
702         GLint scissor[4];
703         
704         if (hist==NULL) { printf("hist is null \n"); return; }
705         
706         rect.xmin = (float)recti->xmin;
707         rect.xmax = (float)recti->xmax;
708         rect.ymin = (float)recti->ymin;
709         rect.ymax = (float)recti->ymax;
710         
711         w = rect.xmax - rect.xmin;
712         h = rect.ymax - rect.ymin;
713         h *= hist->ymax;
714         
715         glEnable(GL_BLEND);
716         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
717         
718         glColor4f(0.f, 0.f, 0.f, 0.3f);
719         uiSetRoundBox(15);
720         gl_round_box(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
721         
722         glColor4f(1.f, 1.f, 1.f, 0.08f);
723         /* draw grid lines here */
724         for (i=1; i<4; i++) {
725                 fdrawline(rect.xmin, rect.ymin+(i/4.f)*h, rect.xmax, rect.ymin+(i/4.f)*h);
726                 fdrawline(rect.xmin+(i/4.f)*w, rect.ymin, rect.xmin+(i/4.f)*w, rect.ymax);
727         }
728         
729         /* need scissor test, histogram can draw outside of boundary */
730         glGetIntegerv(GL_VIEWPORT, scissor);
731         glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
732                 
733         for (rgb=0; rgb<3; rgb++) {
734                 float *data = NULL;
735                 
736                 if (rgb==0)                     data = hist->data_r;
737                 else if (rgb==1)        data = hist->data_g;
738                 else if (rgb==2)        data = hist->data_b;
739                 
740                 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
741                 alpha = 0.75;
742                 if (rgb==0)                     glColor4f(1.f, 0.f, 0.f, alpha);
743                 else if (rgb==1)        glColor4f(0.f, 1.f, 0.f, alpha);
744                 else if (rgb==2)        glColor4f(0.f, 0.f, 1.f, alpha);
745                 
746                 glShadeModel(GL_FLAT);
747                 glBegin(GL_QUAD_STRIP);
748                 glVertex2f(rect.xmin, rect.ymin);
749                 glVertex2f(rect.xmin, rect.ymin + (data[0]*h));
750                 for (i=1; i < res; i++) {
751                         float x = rect.xmin + i * (w/(float)res);
752                         glVertex2f(x, rect.ymin + (data[i]*h));
753                         glVertex2f(x, rect.ymin);
754                 }
755                 glEnd();
756                 
757                 glColor4f(0.f, 0.f, 0.f, 0.25f);
758                 
759                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
760                 glEnable(GL_LINE_SMOOTH);
761                 glBegin(GL_LINE_STRIP);
762                 for (i=0; i < res; i++) {
763                         float x = rect.xmin + i * (w/(float)res);
764                         glVertex2f(x, rect.ymin + (data[i]*h));
765                 }
766                 glEnd();
767                 glDisable(GL_LINE_SMOOTH);
768         }
769         
770         /* restore scissortest */
771         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
772         
773         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
774         glColor4f(0.f, 0.f, 0.f, 0.5f);
775         uiSetRoundBox(15);
776         gl_round_box(GL_LINE_LOOP, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
777         
778         glDisable(GL_BLEND);
779 }
780
781
782 void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *wcol, rcti *rect)
783 {
784         ColorBand *coba;
785         CBData *cbd;
786         float x1, y1, sizex, sizey;
787         float dx, v3[2], v1[2], v2[2], v1a[2], v2a[2];
788         int a;
789         float pos, colf[4]= {0,0,0,0}; /* initialize incase the colorband isnt valid */
790                 
791         coba= (ColorBand *)(but->editcoba? but->editcoba: but->poin);
792         if(coba==NULL) return;
793         
794         x1= rect->xmin;
795         y1= rect->ymin;
796         sizex= rect->xmax-x1;
797         sizey= rect->ymax-y1;
798         
799         /* first background, to show tranparency */
800         dx= sizex/12.0;
801         v1[0]= x1;
802         for(a=0; a<12; a++) {
803                 if(a & 1) glColor3f(0.3, 0.3, 0.3); else glColor3f(0.8, 0.8, 0.8);
804                 glRectf(v1[0], y1, v1[0]+dx, y1+0.5*sizey);
805                 if(a & 1) glColor3f(0.8, 0.8, 0.8); else glColor3f(0.3, 0.3, 0.3);
806                 glRectf(v1[0], y1+0.5*sizey, v1[0]+dx, y1+sizey);
807                 v1[0]+= dx;
808         }
809         
810         glShadeModel(GL_FLAT);
811         glEnable(GL_BLEND);
812         
813         cbd= coba->data;
814         
815         v1[0]= v2[0]= x1;
816         v1[1]= y1;
817         v2[1]= y1+sizey;
818         
819         glBegin(GL_QUAD_STRIP);
820         
821         glColor4fv( &cbd->r );
822         glVertex2fv(v1); glVertex2fv(v2);
823         
824         for( a = 1; a < sizex; a++ ) {
825                 pos = ((float)a) / (sizex-1);
826                 do_colorband( coba, pos, colf );
827                 if (but->block->color_profile != BLI_PR_NONE)
828                         linearrgb_to_srgb_v3_v3(colf, colf);
829                 
830                 v1[0]=v2[0]= x1 + a;
831                 
832                 glColor4fv( colf );
833                 glVertex2fv(v1); glVertex2fv(v2);
834         }
835         
836         glEnd();
837         glShadeModel(GL_FLAT);
838         glDisable(GL_BLEND);
839         
840         /* outline */
841         v1[0]= x1; v1[1]= y1;
842         
843         cpack(0x0);
844         glBegin(GL_LINE_LOOP);
845         glVertex2fv(v1);
846         v1[0]+= sizex;
847         glVertex2fv(v1);
848         v1[1]+= sizey;
849         glVertex2fv(v1);
850         v1[0]-= sizex;
851         glVertex2fv(v1);
852         glEnd();
853         
854         
855         /* help lines */
856         v1[0]= v2[0]=v3[0]= x1;
857         v1[1]= y1;
858         v1a[1]= y1+0.25*sizey;
859         v2[1]= y1+0.5*sizey;
860         v2a[1]= y1+0.75*sizey;
861         v3[1]= y1+sizey;
862         
863         
864         cbd= coba->data;
865         glBegin(GL_LINES);
866         for(a=0; a<coba->tot; a++, cbd++) {
867                 v1[0]=v2[0]=v3[0]=v1a[0]=v2a[0]= x1+ cbd->pos*sizex;
868                 
869                 if(a==coba->cur) {
870                         glColor3ub(0, 0, 0);
871                         glVertex2fv(v1);
872                         glVertex2fv(v3);
873                         glEnd();
874                         
875                         setlinestyle(2);
876                         glBegin(GL_LINES);
877                         glColor3ub(255, 255, 255);
878                         glVertex2fv(v1);
879                         glVertex2fv(v3);
880                         glEnd();
881                         setlinestyle(0);
882                         glBegin(GL_LINES);
883                         
884                         /* glColor3ub(0, 0, 0);
885                         glVertex2fv(v1);
886                         glVertex2fv(v1a);
887                         glColor3ub(255, 255, 255);
888                         glVertex2fv(v1a);
889                         glVertex2fv(v2);
890                         glColor3ub(0, 0, 0);
891                         glVertex2fv(v2);
892                         glVertex2fv(v2a);
893                         glColor3ub(255, 255, 255);
894                         glVertex2fv(v2a);
895                         glVertex2fv(v3);
896                         */
897                 }
898                 else {
899                         glColor3ub(0, 0, 0);
900                         glVertex2fv(v1);
901                         glVertex2fv(v2);
902                         
903                         glColor3ub(255, 255, 255);
904                         glVertex2fv(v2);
905                         glVertex2fv(v3);
906                 }       
907         }
908         glEnd();
909 }
910
911 void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect)
912 {
913         static GLuint displist=0;
914         int a, old[8];
915         GLfloat diff[4], diffn[4]={1.0f, 1.0f, 1.0f, 1.0f};
916         float vec0[4]={0.0f, 0.0f, 0.0f, 0.0f};
917         float dir[4], size;
918         
919         /* store stuff */
920         glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
921                 
922         /* backdrop */
923         glColor3ubv((unsigned char*)wcol->inner);
924         uiSetRoundBox(15);
925         gl_round_box(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f);
926         
927         /* sphere color */
928         glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn);
929         glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
930         
931         /* disable blender light */
932         for(a=0; a<8; a++) {
933                 old[a]= glIsEnabled(GL_LIGHT0+a);
934                 glDisable(GL_LIGHT0+a);
935         }
936         
937         /* own light */
938         glEnable(GL_LIGHT7);
939         glEnable(GL_LIGHTING);
940         
941         ui_get_but_vectorf(but, dir);
942
943         dir[3]= 0.0f;   /* glLight needs 4 args, 0.0 is sun */
944         glLightfv(GL_LIGHT7, GL_POSITION, dir); 
945         glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn); 
946         glLightfv(GL_LIGHT7, GL_SPECULAR, vec0); 
947         glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f);
948         glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f);
949         
950         /* transform to button */
951         glPushMatrix();
952         glTranslatef(rect->xmin + 0.5f*(rect->xmax-rect->xmin), rect->ymin+ 0.5f*(rect->ymax-rect->ymin), 0.0f);
953         
954         if( rect->xmax-rect->xmin < rect->ymax-rect->ymin)
955                 size= (rect->xmax-rect->xmin)/200.f;
956         else
957                 size= (rect->ymax-rect->ymin)/200.f;
958         
959         glScalef(size, size, size);
960         
961         if(displist==0) {
962                 GLUquadricObj   *qobj;
963                 
964                 displist= glGenLists(1);
965                 glNewList(displist, GL_COMPILE_AND_EXECUTE);
966                 
967                 qobj= gluNewQuadric();
968                 gluQuadricDrawStyle(qobj, GLU_FILL); 
969                 glShadeModel(GL_SMOOTH);
970                 gluSphere( qobj, 100.0, 32, 24);
971                 glShadeModel(GL_FLAT);
972                 gluDeleteQuadric(qobj);  
973                 
974                 glEndList();
975         }
976         else glCallList(displist);
977         
978         /* restore */
979         glDisable(GL_LIGHTING);
980         glDisable(GL_CULL_FACE);
981         glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); 
982         glDisable(GL_LIGHT7);
983         
984         /* AA circle */
985         glEnable(GL_BLEND);
986         glEnable(GL_LINE_SMOOTH );
987         glColor3ubv((unsigned char*)wcol->inner);
988         glutil_draw_lined_arc(0.0f, M_PI*2.0, 100.0f, 32);
989         glDisable(GL_BLEND);
990         glDisable(GL_LINE_SMOOTH );
991
992         /* matrix after circle */
993         glPopMatrix();
994
995         /* enable blender light */
996         for(a=0; a<8; a++) {
997                 if(old[a])
998                         glEnable(GL_LIGHT0+a);
999         }
1000 }
1001
1002 static void ui_draw_but_curve_grid(rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
1003 {
1004         float dx, dy, fx, fy;
1005         
1006         glBegin(GL_LINES);
1007         dx= step*zoomx;
1008         fx= rect->xmin + zoomx*(-offsx);
1009         if(fx > rect->xmin) fx -= dx*( floor(fx-rect->xmin));
1010         while(fx < rect->xmax) {
1011                 glVertex2f(fx, rect->ymin); 
1012                 glVertex2f(fx, rect->ymax);
1013                 fx+= dx;
1014         }
1015         
1016         dy= step*zoomy;
1017         fy= rect->ymin + zoomy*(-offsy);
1018         if(fy > rect->ymin) fy -= dy*( floor(fy-rect->ymin));
1019         while(fy < rect->ymax) {
1020                 glVertex2f(rect->xmin, fy); 
1021                 glVertex2f(rect->xmax, fy);
1022                 fy+= dy;
1023         }
1024         glEnd();
1025         
1026 }
1027
1028 static void glColor3ubvShade(char *col, int shade)
1029 {
1030         glColor3ub(col[0]-shade>0?col[0]-shade:0, 
1031                            col[1]-shade>0?col[1]-shade:0,
1032                            col[2]-shade>0?col[2]-shade:0);
1033 }
1034
1035 void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect)
1036 {
1037         CurveMapping *cumap;
1038         CurveMap *cuma;
1039         CurveMapPoint *cmp;
1040         float fx, fy, fac[2], zoomx, zoomy, offsx, offsy;
1041         GLint scissor[4];
1042         int a;
1043
1044         cumap= (CurveMapping *)(but->editcumap? but->editcumap: but->poin);
1045         cuma= cumap->cm+cumap->cur;
1046         
1047         /* need scissor test, curve can draw outside of boundary */
1048         glGetIntegerv(GL_VIEWPORT, scissor);
1049         glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin+rect->ymin, rect->xmax-rect->xmin, rect->ymax-rect->ymin);
1050         
1051         /* calculate offset and zoom */
1052         zoomx= (rect->xmax-rect->xmin-2.0*but->aspect)/(cumap->curr.xmax - cumap->curr.xmin);
1053         zoomy= (rect->ymax-rect->ymin-2.0*but->aspect)/(cumap->curr.ymax - cumap->curr.ymin);
1054         offsx= cumap->curr.xmin-but->aspect/zoomx;
1055         offsy= cumap->curr.ymin-but->aspect/zoomy;
1056         
1057         /* backdrop */
1058         if(cumap->flag & CUMA_DO_CLIP) {
1059                 glColor3ubvShade(wcol->inner, -20);
1060                 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1061                 glColor3ubv((unsigned char*)wcol->inner);
1062                 glRectf(rect->xmin + zoomx*(cumap->clipr.xmin-offsx),
1063                                 rect->ymin + zoomy*(cumap->clipr.ymin-offsy),
1064                                 rect->xmin + zoomx*(cumap->clipr.xmax-offsx),
1065                                 rect->ymin + zoomy*(cumap->clipr.ymax-offsy));
1066         }
1067         else {
1068                 glColor3ubv((unsigned char*)wcol->inner);
1069                 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1070         }
1071                 
1072         /* grid, every .25 step */
1073         glColor3ubvShade(wcol->inner, -16);
1074         ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f);
1075         /* grid, every 1.0 step */
1076         glColor3ubvShade(wcol->inner, -24);
1077         ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f);
1078         /* axes */
1079         glColor3ubvShade(wcol->inner, -50);
1080         glBegin(GL_LINES);
1081         glVertex2f(rect->xmin, rect->ymin + zoomy*(-offsy));
1082         glVertex2f(rect->xmax, rect->ymin + zoomy*(-offsy));
1083         glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymin);
1084         glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymax);
1085         glEnd();
1086         
1087         /* magic trigger for curve backgrounds */
1088         if (but->a1 != -1) {
1089                 if (but->a1 == UI_GRAD_H) {
1090                         rcti grid;
1091                         float col[3];
1092                         
1093                         grid.xmin = rect->xmin + zoomx*(-offsx);
1094                         grid.xmax = rect->xmax + zoomx*(-offsx);
1095                         grid.ymin = rect->ymin + zoomy*(-offsy);
1096                         grid.ymax = rect->ymax + zoomy*(-offsy);
1097                         
1098                         glEnable(GL_BLEND);
1099                         ui_draw_gradient(&grid, col, UI_GRAD_H, 0.5f);
1100                         glDisable(GL_BLEND);
1101                 }
1102         }
1103         
1104         
1105         /* cfra option */
1106         /* XXX 2.48
1107         if(cumap->flag & CUMA_DRAW_CFRA) {
1108                 glColor3ub(0x60, 0xc0, 0x40);
1109                 glBegin(GL_LINES);
1110                 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymin);
1111                 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymax);
1112                 glEnd();
1113         }*/
1114         /* sample option */
1115         /* XXX 2.48
1116          * if(cumap->flag & CUMA_DRAW_SAMPLE) {
1117                 if(cumap->cur==3) {
1118                         float lum= cumap->sample[0]*0.35f + cumap->sample[1]*0.45f + cumap->sample[2]*0.2f;
1119                         glColor3ub(240, 240, 240);
1120                         
1121                         glBegin(GL_LINES);
1122                         glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymin);
1123                         glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymax);
1124                         glEnd();
1125                 }
1126                 else {
1127                         if(cumap->cur==0)
1128                                 glColor3ub(240, 100, 100);
1129                         else if(cumap->cur==1)
1130                                 glColor3ub(100, 240, 100);
1131                         else
1132                                 glColor3ub(100, 100, 240);
1133                         
1134                         glBegin(GL_LINES);
1135                         glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymin);
1136                         glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymax);
1137                         glEnd();
1138                 }
1139         }*/
1140         
1141         /* the curve */
1142         glColor3ubv((unsigned char*)wcol->item);
1143         glEnable(GL_LINE_SMOOTH);
1144         glEnable(GL_BLEND);
1145         glBegin(GL_LINE_STRIP);
1146         
1147         if(cuma->table==NULL)
1148                 curvemapping_changed(cumap, 0); /* 0 = no remove doubles */
1149         cmp= cuma->table;
1150         
1151         /* first point */
1152         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1153                 glVertex2f(rect->xmin, rect->ymin + zoomy*(cmp[0].y-offsy));
1154         else {
1155                 fx= rect->xmin + zoomx*(cmp[0].x-offsx + cuma->ext_in[0]);
1156                 fy= rect->ymin + zoomy*(cmp[0].y-offsy + cuma->ext_in[1]);
1157                 glVertex2f(fx, fy);
1158         }
1159         for(a=0; a<=CM_TABLE; a++) {
1160                 fx= rect->xmin + zoomx*(cmp[a].x-offsx);
1161                 fy= rect->ymin + zoomy*(cmp[a].y-offsy);
1162                 glVertex2f(fx, fy);
1163         }
1164         /* last point */
1165         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1166                 glVertex2f(rect->xmax, rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy));     
1167         else {
1168                 fx= rect->xmin + zoomx*(cmp[CM_TABLE].x-offsx - cuma->ext_out[0]);
1169                 fy= rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy - cuma->ext_out[1]);
1170                 glVertex2f(fx, fy);
1171         }
1172         glEnd();
1173         glDisable(GL_LINE_SMOOTH);
1174         glDisable(GL_BLEND);
1175
1176         /* the points, use aspect to make them visible on edges */
1177         cmp= cuma->curve;
1178         glPointSize(3.0f);
1179         bglBegin(GL_POINTS);
1180         for(a=0; a<cuma->totpoint; a++) {
1181                 if(cmp[a].flag & SELECT)
1182                         UI_ThemeColor(TH_TEXT_HI);
1183                 else
1184                         UI_ThemeColor(TH_TEXT);
1185                 fac[0]= rect->xmin + zoomx*(cmp[a].x-offsx);
1186                 fac[1]= rect->ymin + zoomy*(cmp[a].y-offsy);
1187                 bglVertex2fv(fac);
1188         }
1189         bglEnd();
1190         glPointSize(1.0f);
1191         
1192         /* restore scissortest */
1193         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1194
1195         /* outline */
1196         glColor3ubv((unsigned char*)wcol->outline);
1197         fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1198 }
1199
1200
1201 /* ****************************************************** */
1202
1203
1204 static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
1205 {
1206         glEnable(GL_BLEND);
1207         glShadeModel(GL_SMOOTH);
1208         
1209         /* right quad */
1210         glBegin(GL_POLYGON);
1211         glColor4ub(0, 0, 0, alpha);
1212         glVertex2f(maxx, miny);
1213         glVertex2f(maxx, maxy-0.3*shadsize);
1214         glColor4ub(0, 0, 0, 0);
1215         glVertex2f(maxx+shadsize, maxy-0.75*shadsize);
1216         glVertex2f(maxx+shadsize, miny);
1217         glEnd();
1218         
1219         /* corner shape */
1220         glBegin(GL_POLYGON);
1221         glColor4ub(0, 0, 0, alpha);
1222         glVertex2f(maxx, miny);
1223         glColor4ub(0, 0, 0, 0);
1224         glVertex2f(maxx+shadsize, miny);
1225         glVertex2f(maxx+0.7*shadsize, miny-0.7*shadsize);
1226         glVertex2f(maxx, miny-shadsize);
1227         glEnd();
1228         
1229         /* bottom quad */               
1230         glBegin(GL_POLYGON);
1231         glColor4ub(0, 0, 0, alpha);
1232         glVertex2f(minx+0.3*shadsize, miny);
1233         glVertex2f(maxx, miny);
1234         glColor4ub(0, 0, 0, 0);
1235         glVertex2f(maxx, miny-shadsize);
1236         glVertex2f(minx+0.5*shadsize, miny-shadsize);
1237         glEnd();
1238         
1239         glDisable(GL_BLEND);
1240         glShadeModel(GL_FLAT);
1241 }
1242
1243 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
1244 {
1245         /* accumulated outline boxes to make shade not linear, is more pleasant */
1246         ui_shadowbox(minx, miny, maxx, maxy, 11.0, (20*alpha)>>8);
1247         ui_shadowbox(minx, miny, maxx, maxy, 7.0, (40*alpha)>>8);
1248         ui_shadowbox(minx, miny, maxx, maxy, 5.0, (80*alpha)>>8);
1249         
1250 }
1251
1252
1253 void ui_dropshadow(rctf *rct, float radius, float aspect, int select)
1254 {
1255         float rad;
1256         float a;
1257         char alpha= 2;
1258         
1259         glEnable(GL_BLEND);
1260         
1261         if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f)
1262                 rad= (rct->ymax-rct->ymin-10.0f)/2.0f;
1263         else
1264                 rad= radius;
1265         
1266         if(select) a= 12.0f*aspect; else a= 12.0f*aspect;
1267         for(; a>0.0f; a-=aspect) {
1268                 /* alpha ranges from 2 to 20 or so */
1269                 glColor4ub(0, 0, 0, alpha);
1270                 alpha+= 2;
1271                 
1272                 gl_round_box(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a);
1273         }
1274         
1275         /* outline emphasis */
1276         glEnable( GL_LINE_SMOOTH );
1277         glColor4ub(0, 0, 0, 100);
1278         gl_round_box(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius);
1279         glDisable( GL_LINE_SMOOTH );
1280         
1281         glDisable(GL_BLEND);
1282 }
1283