Various fixes for camera tracking stuff
[blender.git] / source / blender / editors / interface / interface_draw.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) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/interface/interface_draw.c
27  *  \ingroup edinterface
28  */
29
30
31 #include <math.h>
32 #include <string.h>
33
34 #include "DNA_color_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_movieclip_types.h"
38
39 #include "BLI_math.h"
40 #include "BLI_rect.h"
41 #include "BLI_string.h"
42 #include "BLI_utildefines.h"
43
44 #include "BKE_colortools.h"
45 #include "BKE_texture.h"
46
47
48 #include "IMB_imbuf.h"
49 #include "IMB_imbuf_types.h"
50
51 #include "BIF_gl.h"
52 #include "BIF_glutil.h"
53
54 #include "BLF_api.h"
55
56 #include "UI_interface.h"
57
58 /* own include */
59 #include "interface_intern.h"
60
61 #define UI_DISABLED_ALPHA_OFFS  -160
62
63 static int roundboxtype= UI_CNR_ALL;
64
65 void uiSetRoundBox(int type)
66 {
67         /* Not sure the roundbox function is the best place to change this
68          * if this is undone, its not that big a deal, only makes curves edges
69          * square for the  */
70         roundboxtype= type;
71         
72 }
73
74 int uiGetRoundBox(void)
75 {
76         return roundboxtype;
77 }
78
79 void uiDrawBox(int mode, float minx, float miny, float maxx, float maxy, float rad)
80 {
81         float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
82                                           {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
83         int a;
84         
85         /* mult */
86         for(a=0; a<7; a++) {
87                 vec[a][0]*= rad; vec[a][1]*= rad;
88         }
89
90         glBegin(mode);
91
92         /* start with corner right-bottom */
93         if(roundboxtype & UI_CNR_BOTTOM_RIGHT) {
94                 glVertex2f(maxx-rad, miny);
95                 for(a=0; a<7; a++) {
96                         glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
97                 }
98                 glVertex2f(maxx, miny+rad);
99         }
100         else glVertex2f(maxx, miny);
101         
102         /* corner right-top */
103         if(roundboxtype & UI_CNR_TOP_RIGHT) {
104                 glVertex2f(maxx, maxy-rad);
105                 for(a=0; a<7; a++) {
106                         glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
107                 }
108                 glVertex2f(maxx-rad, maxy);
109         }
110         else glVertex2f(maxx, maxy);
111         
112         /* corner left-top */
113         if(roundboxtype & UI_CNR_TOP_LEFT) {
114                 glVertex2f(minx+rad, maxy);
115                 for(a=0; a<7; a++) {
116                         glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
117                 }
118                 glVertex2f(minx, maxy-rad);
119         }
120         else glVertex2f(minx, maxy);
121         
122         /* corner left-bottom */
123         if(roundboxtype & UI_CNR_BOTTOM_LEFT) {
124                 glVertex2f(minx, miny+rad);
125                 for(a=0; a<7; a++) {
126                         glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
127                 }
128                 glVertex2f(minx+rad, miny);
129         }
130         else glVertex2f(minx, miny);
131         
132         glEnd();
133 }
134
135 static void round_box_shade_col(const float col1[3], float const col2[3], const float fac)
136 {
137         float col[3];
138
139         col[0]= (fac*col1[0] + (1.0f-fac)*col2[0]);
140         col[1]= (fac*col1[1] + (1.0f-fac)*col2[1]);
141         col[2]= (fac*col1[2] + (1.0f-fac)*col2[2]);
142         glColor3fv(col);
143 }
144
145 /* linear horizontal shade within button or in outline */
146 /* view2d scrollers use it */
147 void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown)
148 {
149         float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
150                                           {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
151         const float div= maxy - miny;
152         const float idiv= 1.0f / div;
153         float coltop[3], coldown[3], color[4];
154         int a;
155         
156         /* mult */
157         for(a=0; a<7; a++) {
158                 vec[a][0]*= rad; vec[a][1]*= rad;
159         }
160         /* get current color, needs to be outside of glBegin/End */
161         glGetFloatv(GL_CURRENT_COLOR, color);
162
163         /* 'shade' defines strength of shading */       
164         coltop[0]= color[0]+shadetop; if(coltop[0]>1.0f) coltop[0]= 1.0f;
165         coltop[1]= color[1]+shadetop; if(coltop[1]>1.0f) coltop[1]= 1.0f;
166         coltop[2]= color[2]+shadetop; if(coltop[2]>1.0f) coltop[2]= 1.0f;
167         coldown[0]= color[0]+shadedown; if(coldown[0]<0.0f) coldown[0]= 0.0f;
168         coldown[1]= color[1]+shadedown; if(coldown[1]<0.0f) coldown[1]= 0.0f;
169         coldown[2]= color[2]+shadedown; if(coldown[2]<0.0f) coldown[2]= 0.0f;
170
171         glShadeModel(GL_SMOOTH);
172         glBegin(mode);
173
174         /* start with corner right-bottom */
175         if(roundboxtype & UI_CNR_BOTTOM_RIGHT) {
176                 
177                 round_box_shade_col(coltop, coldown, 0.0);
178                 glVertex2f(maxx-rad, miny);
179                 
180                 for(a=0; a<7; a++) {
181                         round_box_shade_col(coltop, coldown, vec[a][1]*idiv);
182                         glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
183                 }
184                 
185                 round_box_shade_col(coltop, coldown, rad*idiv);
186                 glVertex2f(maxx, miny+rad);
187         }
188         else {
189                 round_box_shade_col(coltop, coldown, 0.0);
190                 glVertex2f(maxx, miny);
191         }
192         
193         /* corner right-top */
194         if(roundboxtype & UI_CNR_TOP_RIGHT) {
195                 
196                 round_box_shade_col(coltop, coldown, (div-rad)*idiv);
197                 glVertex2f(maxx, maxy-rad);
198                 
199                 for(a=0; a<7; a++) {
200                         round_box_shade_col(coltop, coldown, (div-rad+vec[a][1])*idiv);
201                         glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
202                 }
203                 round_box_shade_col(coltop, coldown, 1.0);
204                 glVertex2f(maxx-rad, maxy);
205         }
206         else {
207                 round_box_shade_col(coltop, coldown, 1.0);
208                 glVertex2f(maxx, maxy);
209         }
210         
211         /* corner left-top */
212         if(roundboxtype & UI_CNR_TOP_LEFT) {
213                 
214                 round_box_shade_col(coltop, coldown, 1.0);
215                 glVertex2f(minx+rad, maxy);
216                 
217                 for(a=0; a<7; a++) {
218                         round_box_shade_col(coltop, coldown, (div-vec[a][1])*idiv);
219                         glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
220                 }
221                 
222                 round_box_shade_col(coltop, coldown, (div-rad)*idiv);
223                 glVertex2f(minx, maxy-rad);
224         }
225         else {
226                 round_box_shade_col(coltop, coldown, 1.0);
227                 glVertex2f(minx, maxy);
228         }
229         
230         /* corner left-bottom */
231         if(roundboxtype & UI_CNR_BOTTOM_LEFT) {
232                 
233                 round_box_shade_col(coltop, coldown, rad*idiv);
234                 glVertex2f(minx, miny+rad);
235                 
236                 for(a=0; a<7; a++) {
237                         round_box_shade_col(coltop, coldown, (rad-vec[a][1])*idiv);
238                         glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
239                 }
240                 
241                 round_box_shade_col(coltop, coldown, 0.0);
242                 glVertex2f(minx+rad, miny);
243         }
244         else {
245                 round_box_shade_col(coltop, coldown, 0.0);
246                 glVertex2f(minx, miny);
247         }
248         
249         glEnd();
250         glShadeModel(GL_FLAT);
251 }
252
253 /* linear vertical shade within button or in outline */
254 /* view2d scrollers use it */
255 void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadeLeft, float shadeRight)
256 {
257         float vec[7][2]= {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
258                                           {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
259         const float div= maxx - minx;
260         const float idiv= 1.0f / div;
261         float colLeft[3], colRight[3], color[4];
262         int a;
263         
264         /* mult */
265         for(a=0; a<7; a++) {
266                 vec[a][0]*= rad; vec[a][1]*= rad;
267         }
268         /* get current color, needs to be outside of glBegin/End */
269         glGetFloatv(GL_CURRENT_COLOR, color);
270
271         /* 'shade' defines strength of shading */       
272         colLeft[0]= color[0]+shadeLeft; if(colLeft[0]>1.0f) colLeft[0]= 1.0f;
273         colLeft[1]= color[1]+shadeLeft; if(colLeft[1]>1.0f) colLeft[1]= 1.0f;
274         colLeft[2]= color[2]+shadeLeft; if(colLeft[2]>1.0f) colLeft[2]= 1.0f;
275         colRight[0]= color[0]+shadeRight; if(colRight[0]<0.0f) colRight[0]= 0.0f;
276         colRight[1]= color[1]+shadeRight; if(colRight[1]<0.0f) colRight[1]= 0.0f;
277         colRight[2]= color[2]+shadeRight; if(colRight[2]<0.0f) colRight[2]= 0.0f;
278
279         glShadeModel(GL_SMOOTH);
280         glBegin(mode);
281
282         /* start with corner right-bottom */
283         if(roundboxtype & UI_CNR_BOTTOM_RIGHT) {
284                 round_box_shade_col(colLeft, colRight, 0.0);
285                 glVertex2f(maxx-rad, miny);
286                 
287                 for(a=0; a<7; a++) {
288                         round_box_shade_col(colLeft, colRight, vec[a][0]*idiv);
289                         glVertex2f(maxx-rad+vec[a][0], miny+vec[a][1]);
290                 }
291                 
292                 round_box_shade_col(colLeft, colRight, rad*idiv);
293                 glVertex2f(maxx, miny+rad);
294         }
295         else {
296                 round_box_shade_col(colLeft, colRight, 0.0);
297                 glVertex2f(maxx, miny);
298         }
299         
300         /* corner right-top */
301         if(roundboxtype & UI_CNR_TOP_RIGHT) {
302                 round_box_shade_col(colLeft, colRight, 0.0);
303                 glVertex2f(maxx, maxy-rad);
304                 
305                 for(a=0; a<7; a++) {
306                         
307                         round_box_shade_col(colLeft, colRight, (div-rad-vec[a][0])*idiv);
308                         glVertex2f(maxx-vec[a][1], maxy-rad+vec[a][0]);
309                 }
310                 round_box_shade_col(colLeft, colRight, (div-rad)*idiv);
311                 glVertex2f(maxx-rad, maxy);
312         }
313         else {
314                 round_box_shade_col(colLeft, colRight, 0.0);
315                 glVertex2f(maxx, maxy);
316         }
317         
318         /* corner left-top */
319         if(roundboxtype & UI_CNR_TOP_LEFT) {
320                 round_box_shade_col(colLeft, colRight, (div-rad)*idiv);
321                 glVertex2f(minx+rad, maxy);
322                 
323                 for(a=0; a<7; a++) {
324                         round_box_shade_col(colLeft, colRight, (div-rad+vec[a][0])*idiv);
325                         glVertex2f(minx+rad-vec[a][0], maxy-vec[a][1]);
326                 }
327                 
328                 round_box_shade_col(colLeft, colRight, 1.0);
329                 glVertex2f(minx, maxy-rad);
330         }
331         else {
332                 round_box_shade_col(colLeft, colRight, 1.0);
333                 glVertex2f(minx, maxy);
334         }
335         
336         /* corner left-bottom */
337         if(roundboxtype & UI_CNR_BOTTOM_LEFT) {
338                 round_box_shade_col(colLeft, colRight, 1.0);
339                 glVertex2f(minx, miny+rad);
340                 
341                 for(a=0; a<7; a++) {
342                         round_box_shade_col(colLeft, colRight, (vec[a][0])*idiv);
343                         glVertex2f(minx+vec[a][1], miny+rad-vec[a][0]);
344                 }
345                 
346                 round_box_shade_col(colLeft, colRight, 1.0);
347                 glVertex2f(minx+rad, miny);
348         }
349         else {
350                 round_box_shade_col(colLeft, colRight, 1.0);
351                 glVertex2f(minx, miny);
352         }
353         
354         glEnd();
355         glShadeModel(GL_FLAT);
356 }
357
358 /* plain antialiased unfilled rectangle */
359 void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad)
360 {
361         float color[4];
362         
363         if(roundboxtype & UI_RB_ALPHA) {
364                 glGetFloatv(GL_CURRENT_COLOR, color);
365                 color[3]= 0.5;
366                 glColor4fv(color);
367                 glEnable( GL_BLEND );
368         }
369         
370         /* set antialias line */
371         glEnable( GL_LINE_SMOOTH );
372         glEnable( GL_BLEND );
373
374         uiDrawBox(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
375    
376         glDisable( GL_BLEND );
377         glDisable( GL_LINE_SMOOTH );
378 }
379
380 /* (old, used in outliner) plain antialiased filled box */
381 void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad)
382 {
383         float color[4];
384         
385         if(roundboxtype & UI_RB_ALPHA) {
386                 glGetFloatv(GL_CURRENT_COLOR, color);
387                 color[3]= 0.5;
388                 glColor4fv(color);
389                 glEnable( GL_BLEND );
390         }
391         
392         ui_draw_anti_roundbox(GL_POLYGON, minx, miny, maxx, maxy, rad);
393 }
394
395
396 /* ************** generic embossed rect, for window sliders etc ************* */
397
398
399 /* text_draw.c uses this */
400 void uiEmboss(float x1, float y1, float x2, float y2, int sel)
401 {
402         
403         /* below */
404         if(sel) glColor3ub(200,200,200);
405         else glColor3ub(50,50,50);
406         fdrawline(x1, y1, x2, y1);
407
408         /* right */
409         fdrawline(x2, y1, x2, y2);
410         
411         /* top */
412         if(sel) glColor3ub(50,50,50);
413         else glColor3ub(200,200,200);
414         fdrawline(x1, y2, x2, y2);
415
416         /* left */
417         fdrawline(x1, y1, x1, y2);
418         
419 }
420
421 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
422
423 void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect)
424 {
425 #ifdef WITH_HEADLESS
426         (void)rect;
427         (void)but;
428 #else
429         ImBuf *ibuf= (ImBuf *)but->poin;
430         //GLint scissor[4];
431         //int w, h;
432
433         if (!ibuf) return;
434         
435         /* scissor doesn't seem to be doing the right thing...?
436         //glColor4f(1.0, 0.f, 0.f, 1.f);
437         //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax)
438
439         w = (rect->xmax - rect->xmin);
440         h = (rect->ymax - rect->ymin);
441         // prevent drawing outside widget area
442         glGetIntegerv(GL_SCISSOR_BOX, scissor);
443         glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h);
444         */
445         
446         glEnable(GL_BLEND);
447         glColor4f(0.0, 0.0, 0.0, 0.0);
448         
449         glaDrawPixelsSafe((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
450         //glaDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
451         
452         glDisable(GL_BLEND);
453         
454         /* 
455         // restore scissortest
456         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
457         */
458         
459 #endif
460 }
461
462 #if 0
463 #ifdef WITH_INTERNATIONAL
464 static void ui_draw_but_CHARTAB(uiBut *but)
465 {
466         /* XXX 2.50 bad global access */
467         /* Some local variables */
468         float sx, sy, ex, ey;
469         float width, height;
470         float butw, buth;
471         int x, y, cs;
472         wchar_t wstr[2];
473         unsigned char ustr[16];
474         PackedFile *pf;
475         int result = 0;
476         int charmax = G.charmax;
477         
478         /* FO_BUILTIN_NAME font in use. There are TTF FO_BUILTIN_NAME and non-TTF FO_BUILTIN_NAME fonts */
479         if(!strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
480                 if(G.ui_international == TRUE) {
481                         charmax = 0xff;
482                 }
483                 else {
484                         charmax = 0xff;
485                 }
486         }
487
488         /* Category list exited without selecting the area */
489         if(G.charmax == 0)
490                 charmax = G.charmax = 0xffff;
491
492         /* Calculate the size of the button */
493         width = abs(rect->xmax - rect->xmin);
494         height = abs(rect->ymax - rect->ymin);
495         
496         butw = floor(width / 12);
497         buth = floor(height / 6);
498         
499         /* Initialize variables */
500         sx = rect->xmin;
501         ex = rect->xmin + butw;
502         sy = rect->ymin + height - buth;
503         ey = rect->ymin + height;
504
505         cs = G.charstart;
506
507         /* Set the font, in case it is not FO_BUILTIN_NAME font */
508         if(G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
509                 // Is the font file packed, if so then use the packed file
510                 if(G.selfont->packedfile) {
511                         pf = G.selfont->packedfile;             
512                         FTF_SetFont(pf->data, pf->size, 14.0);
513                 }
514                 else {
515                         char tmpStr[256];
516                         int err;
517
518                         BLI_strncpy(tmpStr, G.selfont->name, sizeof(tmpStr));
519                         BLI_path_abs(tmpStr, G.main->name);
520                         err = FTF_SetFont((unsigned char *)tmpStr, 0, 14.0);
521                 }
522         }
523         else {
524                 if(G.ui_international == TRUE) {
525                         FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 14.0);
526                 }
527         }
528
529         /* Start drawing the button itself */
530         glShadeModel(GL_SMOOTH);
531
532         glColor3ub(200,  200,  200);
533         glRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
534
535         glColor3ub(0,  0,  0);
536         for(y = 0; y < 6; y++) {
537                 // Do not draw more than the category allows
538                 if(cs > charmax) break;
539
540                 for(x = 0; x < 12; x++)
541                 {
542                         // Do not draw more than the category allows
543                         if(cs > charmax) break;
544
545                         // Draw one grid cell
546                         glBegin(GL_LINE_LOOP);
547                                 glVertex2f(sx, sy);
548                                 glVertex2f(ex, sy);
549                                 glVertex2f(ex, ey);
550                                 glVertex2f(sx, ey);                             
551                         glEnd();        
552
553                         // Draw character inside the cell
554                         memset(wstr, 0, sizeof(wchar_t)*2);
555                         memset(ustr, 0, 16);
556
557                         // Set the font to be either unicode or FO_BUILTIN_NAME 
558                         wstr[0] = cs;
559                         if(strcmp(G.selfont->name, FO_BUILTIN_NAME))
560                         {
561                                 BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr));
562                         }
563                         else
564                         {
565                                 if(G.ui_international == TRUE)
566                                 {
567                                         BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr));
568                                 }
569                                 else
570                                 {
571                                         ustr[0] = cs;
572                                         ustr[1] = 0;
573                                 }
574                         }
575
576                         if((G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) || (G.selfont && !strcmp(G.selfont->name, FO_BUILTIN_NAME) && G.ui_international == TRUE))
577                         {
578                                 float wid;
579                                 float llx, lly, llz, urx, ury, urz;
580                                 float dx, dy;
581                                 float px, py;
582         
583                                 // Calculate the position
584                                 wid = FTF_GetStringWidth((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
585                                 FTF_GetBoundingBox((char *) ustr, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
586                                 dx = urx-llx;
587                                 dy = ury-lly;
588
589                                 // This isn't fully functional since the but->aspect isn't working like I suspected
590                                 px = sx + ((butw/but->aspect)-dx)/2;
591                                 py = sy + ((buth/but->aspect)-dy)/2;
592
593                                 // Set the position and draw the character
594                                 ui_rasterpos_safe(px, py, but->aspect);
595                                 FTF_DrawString((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
596                         }
597                         else
598                         {
599                                 ui_rasterpos_safe(sx + butw/2, sy + buth/2, but->aspect);
600                                 UI_DrawString(but->font, (char *) ustr, 0);
601                         }
602         
603                         // Calculate the next position and character
604                         sx += butw; ex +=butw;
605                         cs++;
606                 }
607                 /* Add the y position and reset x position */
608                 sy -= buth; 
609                 ey -= buth;
610                 sx = rect->xmin;
611                 ex = rect->xmin + butw;
612         }       
613         glShadeModel(GL_FLAT);
614
615         /* Return Font Settings to original */
616         if(U.fontsize && U.fontname[0]) {
617                 result = FTF_SetFont((unsigned char *)U.fontname, 0, U.fontsize);
618         }
619         else if (U.fontsize) {
620                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, U.fontsize);
621         }
622
623         if (result == 0) {
624                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 11);
625         }
626         
627         /* resets the font size */
628         if(G.ui_international == TRUE) {
629                 // uiSetCurFont(but->block, UI_HELV);
630         }
631 }
632
633 #endif // WITH_INTERNATIONAL
634 #endif
635
636 static void draw_scope_end(rctf *rect, GLint *scissor)
637 {
638         float scaler_x1, scaler_x2;
639         
640         /* restore scissortest */
641         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
642         
643         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
644         
645         /* scale widget */
646         scaler_x1 = rect->xmin + (rect->xmax - rect->xmin)/2 - SCOPE_RESIZE_PAD;
647         scaler_x2 = rect->xmin + (rect->xmax - rect->xmin)/2 + SCOPE_RESIZE_PAD;
648         
649         glColor4f(0.f, 0.f, 0.f, 0.25f);
650         fdrawline(scaler_x1, rect->ymin-4, scaler_x2, rect->ymin-4);
651         fdrawline(scaler_x1, rect->ymin-7, scaler_x2, rect->ymin-7);
652         glColor4f(1.f, 1.f, 1.f, 0.25f);
653         fdrawline(scaler_x1, rect->ymin-5, scaler_x2, rect->ymin-5);
654         fdrawline(scaler_x1, rect->ymin-8, scaler_x2, rect->ymin-8);
655         
656         /* outline */
657         glColor4f(0.f, 0.f, 0.f, 0.5f);
658         uiSetRoundBox(UI_CNR_ALL);
659         uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin, rect->xmax+1, rect->ymax+1, 3.0f);
660 }
661
662 static void histogram_draw_one(float r, float g, float b, float alpha, float x, float y, float w, float h, float *data, int res)
663 {
664         int i;
665         
666         /* under the curve */
667         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
668         glColor4f(r, g, b, alpha);
669         
670         glShadeModel(GL_FLAT);
671         glBegin(GL_QUAD_STRIP);
672         glVertex2f(x, y);
673         glVertex2f(x, y + (data[0]*h));
674         for (i=1; i < res; i++) {
675                 float x2 = x + i * (w/(float)res);
676                 glVertex2f(x2, y + (data[i]*h));
677                 glVertex2f(x2, y);
678         }
679         glEnd();
680         
681         /* curve outline */
682         glColor4f(0.f, 0.f, 0.f, 0.25f);
683         
684         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
685         glEnable(GL_LINE_SMOOTH);
686         glBegin(GL_LINE_STRIP);
687         for (i=0; i < res; i++) {
688                 float x2 = x + i * (w/(float)res);
689                 glVertex2f(x2, y + (data[i]*h));
690         }
691         glEnd();
692         glDisable(GL_LINE_SMOOTH);
693 }
694
695 void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
696 {
697         Histogram *hist = (Histogram *)but->poin;
698         int res = hist->x_resolution;
699         rctf rect;
700         int i;
701         float w, h;
702         //float alpha;
703         GLint scissor[4];
704         
705         rect.xmin = (float)recti->xmin+1;
706         rect.xmax = (float)recti->xmax-1;
707         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
708         rect.ymax = (float)recti->ymax-1;
709         
710         w = rect.xmax - rect.xmin;
711         h = (rect.ymax - rect.ymin) * hist->ymax;
712         
713         glEnable(GL_BLEND);
714         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
715         
716         glColor4f(0.f, 0.f, 0.f, 0.3f);
717         uiSetRoundBox(UI_CNR_ALL);
718         uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
719
720         /* need scissor test, histogram can draw outside of boundary */
721         glGetIntegerv(GL_VIEWPORT, scissor);
722         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));
723
724         glColor4f(1.f, 1.f, 1.f, 0.08f);
725         /* draw grid lines here */
726         for (i=1; i<4; i++) {
727                 fdrawline(rect.xmin, rect.ymin+(i/4.f)*h, rect.xmax, rect.ymin+(i/4.f)*h);
728                 fdrawline(rect.xmin+(i/4.f)*w, rect.ymin, rect.xmin+(i/4.f)*w, rect.ymax);
729         }
730         
731         if (hist->mode == HISTO_MODE_LUMA)
732                 histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res);
733         else {
734                 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
735                         histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res);
736                 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G)
737                         histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res);
738                 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B)
739                         histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res);
740         }
741         
742         /* outline, scale gripper */
743         draw_scope_end(&rect, scissor);
744 }
745
746 void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
747 {
748         Scopes *scopes = (Scopes *)but->poin;
749         rctf rect;
750         int i, c;
751         float w, w3, h, alpha, yofs;
752         GLint scissor[4];
753         float colors[3][3]= MAT3_UNITY;
754         float colorsycc[3][3] = {{1,0,1},{1,1,0},{0,1,1}};
755         float colors_alpha[3][3], colorsycc_alpha[3][3]; /* colors  pre multiplied by alpha for speed up */
756         float min, max;
757         
758         if (scopes==NULL) return;
759         
760         rect.xmin = (float)recti->xmin+1;
761         rect.xmax = (float)recti->xmax-1;
762         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
763         rect.ymax = (float)recti->ymax-1;
764         
765         if (scopes->wavefrm_yfac < 0.5f )
766                 scopes->wavefrm_yfac =0.98f;
767         w = rect.xmax - rect.xmin-7;
768         h = (rect.ymax - rect.ymin)*scopes->wavefrm_yfac;
769         yofs= rect.ymin + (rect.ymax - rect.ymin -h)/2.0f;
770         w3=w/3.0f;
771         
772         /* log scale for alpha */
773         alpha = scopes->wavefrm_alpha*scopes->wavefrm_alpha;
774         
775         for(c=0; c<3; c++) {
776                 for(i=0; i<3; i++) {
777                         colors_alpha[c][i] = colors[c][i] * alpha;
778                         colorsycc_alpha[c][i] = colorsycc[c][i] * alpha;
779                 }
780         }
781                         
782         glEnable(GL_BLEND);
783         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
784         
785         glColor4f(0.f, 0.f, 0.f, 0.3f);
786         uiSetRoundBox(UI_CNR_ALL);
787         uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
788         
789
790         /* need scissor test, waveform can draw outside of boundary */
791         glGetIntegerv(GL_VIEWPORT, scissor);
792         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));
793
794         glColor4f(1.f, 1.f, 1.f, 0.08f);
795         /* draw grid lines here */
796         for (i=0; i<6; i++) {
797                 char str[4];
798                 BLI_snprintf(str, sizeof(str), "%-3d",i*20);
799                 str[3]='\0';
800                 fdrawline(rect.xmin+22, yofs+(i/5.f)*h, rect.xmax+1, yofs+(i/5.f)*h);
801                 BLF_draw_default(rect.xmin+1, yofs-5+(i/5.f)*h, 0, str, sizeof(str)-1);
802                 /* in the loop because blf_draw reset it */
803                 glEnable(GL_BLEND);
804                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
805         }
806         /* 3 vertical separation */
807         if (scopes->wavefrm_mode!= SCOPES_WAVEFRM_LUMA) {
808                 for (i=1; i<3; i++) {
809                         fdrawline(rect.xmin+i*w3, rect.ymin, rect.xmin+i*w3, rect.ymax);
810                 }
811         }
812         
813         /* separate min max zone on the right */
814         fdrawline(rect.xmin+w, rect.ymin, rect.xmin+w, rect.ymax);
815         /* 16-235-240 level in case of ITU-R BT601/709 */
816         glColor4f(1.f, 0.4f, 0.f, 0.2f);
817         if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)){
818                 fdrawline(rect.xmin+22, yofs+h*16.0f/255.0f, rect.xmax+1, yofs+h*16.0f/255.0f);
819                 fdrawline(rect.xmin+22, yofs+h*235.0f/255.0f, rect.xmin+w3, yofs+h*235.0f/255.0f);
820                 fdrawline(rect.xmin+3*w3, yofs+h*235.0f/255.0f, rect.xmax+1, yofs+h*235.0f/255.0f);
821                 fdrawline(rect.xmin+w3, yofs+h*240.0f/255.0f, rect.xmax+1, yofs+h*240.0f/255.0f);
822         }
823         /* 7.5 IRE black point level for NTSC */
824         if (scopes->wavefrm_mode== SCOPES_WAVEFRM_LUMA)
825                 fdrawline(rect.xmin, yofs+h*0.075f, rect.xmax+1, yofs+h*0.075f);
826
827         if (scopes->ok && scopes->waveform_1 != NULL) {
828                 
829                 /* LUMA (1 channel) */
830                 glBlendFunc(GL_ONE,GL_ONE);
831                 glColor3f(alpha, alpha, alpha);
832                 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA){
833
834                         glBlendFunc(GL_ONE,GL_ONE);
835                         
836                         glPushMatrix();
837                         glEnableClientState(GL_VERTEX_ARRAY);
838                         
839                         glTranslatef(rect.xmin, yofs, 0.f);
840                         glScalef(w, h, 0.f);
841                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
842                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
843                                         
844                         glDisableClientState(GL_VERTEX_ARRAY);
845                         glPopMatrix();
846
847                         /* min max */
848                         glColor3f(.5f, .5f, .5f);
849                         min= yofs+scopes->minmax[0][0]*h;
850                         max= yofs+scopes->minmax[0][1]*h;
851                         CLAMP(min, rect.ymin, rect.ymax);
852                         CLAMP(max, rect.ymin, rect.ymax);
853                         fdrawline(rect.xmax-3,min,rect.xmax-3,max);
854                 }
855
856                 /* RGB / YCC (3 channels) */
857                 else if (ELEM4(scopes->wavefrm_mode, SCOPES_WAVEFRM_RGB, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709, SCOPES_WAVEFRM_YCC_JPEG)) {
858                         int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB);
859                         
860                         glBlendFunc(GL_ONE,GL_ONE);
861                         
862                         glPushMatrix();
863                         glEnableClientState(GL_VERTEX_ARRAY);
864                         
865                         glTranslatef(rect.xmin, yofs, 0.f);
866                         glScalef(w3, h, 0.f);
867                         
868                         glColor3fv((rgb)?colors_alpha[0]:colorsycc_alpha[0]);
869                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
870                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
871
872                         glTranslatef(1.f, 0.f, 0.f);
873                         glColor3fv((rgb)?colors_alpha[1]:colorsycc_alpha[1]);
874                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2);
875                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
876                         
877                         glTranslatef(1.f, 0.f, 0.f);
878                         glColor3fv((rgb)?colors_alpha[2]:colorsycc_alpha[2]);
879                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3);
880                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
881                         
882                         glDisableClientState(GL_VERTEX_ARRAY);
883                         glPopMatrix();
884
885                         
886                         /* min max */
887                         for (c=0; c<3; c++) {
888                                 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB)
889                                         glColor3f(colors[c][0]*0.75f, colors[c][1]*0.75f, colors[c][2]*0.75f);
890                                 else
891                                         glColor3f(colorsycc[c][0]*0.75f, colorsycc[c][1]*0.75f, colorsycc[c][2]*0.75f);
892                                 min= yofs+scopes->minmax[c][0]*h;
893                                 max= yofs+scopes->minmax[c][1]*h;
894                                 CLAMP(min, rect.ymin, rect.ymax);
895                                 CLAMP(max, rect.ymin, rect.ymax);
896                                 fdrawline(rect.xmin+w+2+c*2,min,rect.xmin+w+2+c*2,max);
897                         }
898                 }
899                 
900         }
901         
902         /* outline, scale gripper */
903         draw_scope_end(&rect, scissor);
904 }
905
906 static float polar_to_x(float center, float diam, float ampli, float angle)
907 {
908         return center + diam * ampli * cosf(angle);
909 }
910
911 static float polar_to_y(float center, float diam, float ampli, float angle)
912 {
913         return center + diam * ampli * sinf(angle);
914 }
915
916 static void vectorscope_draw_target(float centerx, float centery, float diam, const float colf[3])
917 {
918         float y,u,v;
919         float tangle=0.f, tampli;
920         float dangle, dampli, dangle2, dampli2;
921
922         rgb_to_yuv(colf[0], colf[1], colf[2], &y, &u, &v);
923         if (u>0 && v>=0) tangle=atanf(v/u);
924         else if (u>0 && v<0) tangle= atanf(v/u) + 2.0f * (float)M_PI;
925         else if (u<0) tangle=atanf(v/u) + (float)M_PI;
926         else if (u==0 && v > 0.0f) tangle= (float)M_PI/2.0f;
927         else if (u==0 && v < 0.0f) tangle=-(float)M_PI/2.0f;
928         tampli= sqrtf(u*u+v*v);
929
930         /* small target vary by 2.5 degree and 2.5 IRE unit */
931         glColor4f(1.0f, 1.0f, 1.0, 0.12f);
932         dangle= DEG2RADF(2.5f);
933         dampli= 2.5f/200.0f;
934         glBegin(GL_LINE_STRIP);
935         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
936         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle), polar_to_y(centery,diam,tampli-dampli,tangle+dangle));
937         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle), polar_to_y(centery,diam,tampli-dampli,tangle-dangle));
938         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle), polar_to_y(centery,diam,tampli+dampli,tangle-dangle));
939         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
940         glEnd();
941         /* big target vary by 10 degree and 20% amplitude */
942         glColor4f(1.0f, 1.0f, 1.0, 0.12f);
943         dangle= DEG2RADF(10.0f);
944         dampli= 0.2f*tampli;
945         dangle2= DEG2RADF(5.0f);
946         dampli2= 0.5f*dampli;
947         glBegin(GL_LINE_STRIP);
948         glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle+dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle+dangle));
949         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
950         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli+dampli,tangle+dangle-dangle2));
951         glEnd();
952         glBegin(GL_LINE_STRIP);
953         glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle+dangle), polar_to_y(centery ,diam,tampli-dampli+dampli2,tangle+dangle));
954         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle), polar_to_y(centery,diam,tampli-dampli,tangle+dangle));
955         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli-dampli,tangle+dangle-dangle2));
956         glEnd();
957         glBegin(GL_LINE_STRIP);
958         glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle-dangle), polar_to_y(centery,diam,tampli-dampli+dampli2,tangle-dangle));
959         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle), polar_to_y(centery,diam,tampli-dampli,tangle-dangle));
960         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli-dampli,tangle-dangle+dangle2));
961         glEnd();
962         glBegin(GL_LINE_STRIP);
963         glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle-dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle-dangle));
964         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle), polar_to_y(centery,diam,tampli+dampli,tangle-dangle));
965         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli+dampli,tangle-dangle+dangle2));
966         glEnd();
967 }
968
969 void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
970 {
971         const float skin_rad= DEG2RADF(123.0f); /* angle in radians of the skin tone line */
972         Scopes *scopes = (Scopes *)but->poin;
973         rctf rect;
974         int i, j;
975         float w, h, centerx, centery, diam;
976         float alpha;
977         const float colors[6][3]={{.75,0,0},{.75,.75,0},{0,.75,0},{0,.75,.75},{0,0,.75},{.75,0,.75}};
978         GLint scissor[4];
979         
980         rect.xmin = (float)recti->xmin+1;
981         rect.xmax = (float)recti->xmax-1;
982         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
983         rect.ymax = (float)recti->ymax-1;
984         
985         w = rect.xmax - rect.xmin;
986         h = rect.ymax - rect.ymin;
987         centerx = rect.xmin + w/2;
988         centery = rect.ymin + h/2;
989         diam= (w<h)?w:h;
990         
991         alpha = scopes->vecscope_alpha*scopes->vecscope_alpha*scopes->vecscope_alpha;
992                         
993         glEnable(GL_BLEND);
994         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
995         
996         glColor4f(0.f, 0.f, 0.f, 0.3f);
997         uiSetRoundBox(UI_CNR_ALL);
998         uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
999
1000         /* need scissor test, hvectorscope can draw outside of boundary */
1001         glGetIntegerv(GL_VIEWPORT, scissor);
1002         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));
1003         
1004         glColor4f(1.f, 1.f, 1.f, 0.08f);
1005         /* draw grid elements */
1006         /* cross */
1007         fdrawline(centerx - (diam/2)-5, centery, centerx + (diam/2)+5, centery);
1008         fdrawline(centerx, centery - (diam/2)-5, centerx, centery + (diam/2)+5);
1009         /* circles */
1010         for(j=0; j<5; j++) {
1011                 glBegin(GL_LINE_STRIP);
1012                 for(i=0; i<=360; i=i+15) {
1013                         const float a= DEG2RADF((float)i);
1014                         const float r= (j+1)/10.0f;
1015                         glVertex2f(polar_to_x(centerx,diam,r,a), polar_to_y(centery,diam,r,a));
1016                 }
1017                 glEnd();
1018         }
1019         /* skin tone line */
1020         glColor4f(1.f, 0.4f, 0.f, 0.2f);
1021         fdrawline(polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery,diam,0.5,skin_rad),
1022                   polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery,diam,0.1,skin_rad));
1023         /* saturation points */
1024         for(i=0; i<6; i++)
1025                 vectorscope_draw_target(centerx, centery, diam, colors[i]);
1026         
1027         if (scopes->ok && scopes->vecscope != NULL) {
1028                 /* pixel point cloud */
1029                 glBlendFunc(GL_ONE,GL_ONE);
1030                 glColor3f(alpha, alpha, alpha);
1031
1032                 glPushMatrix();
1033                 glEnableClientState(GL_VERTEX_ARRAY);
1034
1035                 glTranslatef(centerx, centery, 0.f);
1036                 glScalef(diam, diam, 0.f);
1037
1038                 glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope);
1039                 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
1040                 
1041                 glDisableClientState(GL_VERTEX_ARRAY);
1042                 glPopMatrix();
1043         }
1044
1045         /* outline, scale gripper */
1046         draw_scope_end(&rect, scissor);
1047                 
1048         glDisable(GL_BLEND);
1049 }
1050
1051 void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect)
1052 {
1053         ColorBand *coba;
1054         CBData *cbd;
1055         float x1, y1, sizex, sizey;
1056         float v3[2], v1[2], v2[2], v1a[2], v2a[2];
1057         int a;
1058         float pos, colf[4]= {0,0,0,0}; /* initialize incase the colorband isnt valid */
1059                 
1060         coba= (ColorBand *)(but->editcoba? but->editcoba: but->poin);
1061         if(coba==NULL) return;
1062         
1063         x1= rect->xmin;
1064         y1= rect->ymin;
1065         sizex= rect->xmax-x1;
1066         sizey= rect->ymax-y1;
1067
1068         /* first background, to show tranparency */
1069
1070         glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
1071         glRectf(x1, y1, x1+sizex, y1+sizey);
1072         glEnable(GL_POLYGON_STIPPLE);
1073         glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
1074         glPolygonStipple(checker_stipple_sml);
1075         glRectf(x1, y1, x1+sizex, y1+sizey);
1076         glDisable(GL_POLYGON_STIPPLE);
1077
1078         glShadeModel(GL_FLAT);
1079         glEnable(GL_BLEND);
1080         
1081         cbd= coba->data;
1082         
1083         v1[0]= v2[0]= x1;
1084         v1[1]= y1;
1085         v2[1]= y1+sizey;
1086         
1087         glBegin(GL_QUAD_STRIP);
1088         
1089         glColor4fv( &cbd->r );
1090         glVertex2fv(v1); glVertex2fv(v2);
1091         
1092         for( a = 1; a <= sizex; a++ ) {
1093                 pos = ((float)a) / (sizex-1);
1094                 do_colorband( coba, pos, colf );
1095                 if (but->block->color_profile != BLI_PR_NONE)
1096                         linearrgb_to_srgb_v3_v3(colf, colf);
1097                 
1098                 v1[0]=v2[0]= x1 + a;
1099                 
1100                 glColor4fv( colf );
1101                 glVertex2fv(v1); glVertex2fv(v2);
1102         }
1103         
1104         glEnd();
1105         glShadeModel(GL_FLAT);
1106         glDisable(GL_BLEND);
1107         
1108         /* outline */
1109         glColor4f(0.0, 0.0, 0.0, 1.0);
1110         fdrawbox(x1, y1, x1+sizex, y1+sizey);
1111         
1112         /* help lines */
1113         v1[0]= v2[0]=v3[0]= x1;
1114         v1[1]= y1;
1115         v1a[1]= y1+0.25f*sizey;
1116         v2[1]= y1+0.5f*sizey;
1117         v2a[1]= y1+0.75f*sizey;
1118         v3[1]= y1+sizey;
1119         
1120         
1121         cbd= coba->data;
1122         glBegin(GL_LINES);
1123         for(a=0; a<coba->tot; a++, cbd++) {
1124                 v1[0]=v2[0]=v3[0]=v1a[0]=v2a[0]= x1+ cbd->pos*sizex;
1125                 
1126                 if(a==coba->cur) {
1127                         glColor3ub(0, 0, 0);
1128                         glVertex2fv(v1);
1129                         glVertex2fv(v3);
1130                         glEnd();
1131                         
1132                         setlinestyle(2);
1133                         glBegin(GL_LINES);
1134                         glColor3ub(255, 255, 255);
1135                         glVertex2fv(v1);
1136                         glVertex2fv(v3);
1137                         glEnd();
1138                         setlinestyle(0);
1139                         glBegin(GL_LINES);
1140                         
1141                         /* glColor3ub(0, 0, 0);
1142                         glVertex2fv(v1);
1143                         glVertex2fv(v1a);
1144                         glColor3ub(255, 255, 255);
1145                         glVertex2fv(v1a);
1146                         glVertex2fv(v2);
1147                         glColor3ub(0, 0, 0);
1148                         glVertex2fv(v2);
1149                         glVertex2fv(v2a);
1150                         glColor3ub(255, 255, 255);
1151                         glVertex2fv(v2a);
1152                         glVertex2fv(v3);
1153                         */
1154                 }
1155                 else {
1156                         glColor3ub(0, 0, 0);
1157                         glVertex2fv(v1);
1158                         glVertex2fv(v2);
1159                         
1160                         glColor3ub(255, 255, 255);
1161                         glVertex2fv(v2);
1162                         glVertex2fv(v3);
1163                 }       
1164         }
1165         glEnd();
1166
1167 }
1168
1169 void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect)
1170 {
1171         static GLuint displist=0;
1172         int a, old[8];
1173         GLfloat diff[4], diffn[4]={1.0f, 1.0f, 1.0f, 1.0f};
1174         float vec0[4]={0.0f, 0.0f, 0.0f, 0.0f};
1175         float dir[4], size;
1176         
1177         /* store stuff */
1178         glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
1179                 
1180         /* backdrop */
1181         glColor3ubv((unsigned char*)wcol->inner);
1182         uiSetRoundBox(UI_CNR_ALL);
1183         uiDrawBox(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f);
1184         
1185         /* sphere color */
1186         glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn);
1187         glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
1188         
1189         /* disable blender light */
1190         for(a=0; a<8; a++) {
1191                 old[a]= glIsEnabled(GL_LIGHT0+a);
1192                 glDisable(GL_LIGHT0+a);
1193         }
1194         
1195         /* own light */
1196         glEnable(GL_LIGHT7);
1197         glEnable(GL_LIGHTING);
1198         
1199         ui_get_but_vectorf(but, dir);
1200
1201         dir[3]= 0.0f;   /* glLight needs 4 args, 0.0 is sun */
1202         glLightfv(GL_LIGHT7, GL_POSITION, dir); 
1203         glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn); 
1204         glLightfv(GL_LIGHT7, GL_SPECULAR, vec0); 
1205         glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f);
1206         glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f);
1207         
1208         /* transform to button */
1209         glPushMatrix();
1210         glTranslatef(rect->xmin + 0.5f*(rect->xmax-rect->xmin), rect->ymin+ 0.5f*(rect->ymax-rect->ymin), 0.0f);
1211         
1212         if( rect->xmax-rect->xmin < rect->ymax-rect->ymin)
1213                 size= (rect->xmax-rect->xmin)/200.f;
1214         else
1215                 size= (rect->ymax-rect->ymin)/200.f;
1216         
1217         glScalef(size, size, size);
1218         
1219         if(displist==0) {
1220                 GLUquadricObj   *qobj;
1221                 
1222                 displist= glGenLists(1);
1223                 glNewList(displist, GL_COMPILE_AND_EXECUTE);
1224                 
1225                 qobj= gluNewQuadric();
1226                 gluQuadricDrawStyle(qobj, GLU_FILL); 
1227                 glShadeModel(GL_SMOOTH);
1228                 gluSphere( qobj, 100.0, 32, 24);
1229                 glShadeModel(GL_FLAT);
1230                 gluDeleteQuadric(qobj);  
1231                 
1232                 glEndList();
1233         }
1234         else glCallList(displist);
1235         
1236         /* restore */
1237         glDisable(GL_LIGHTING);
1238         glDisable(GL_CULL_FACE);
1239         glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); 
1240         glDisable(GL_LIGHT7);
1241         
1242         /* AA circle */
1243         glEnable(GL_BLEND);
1244         glEnable(GL_LINE_SMOOTH );
1245         glColor3ubv((unsigned char*)wcol->inner);
1246         glutil_draw_lined_arc(0.0f, M_PI*2.0, 100.0f, 32);
1247         glDisable(GL_BLEND);
1248         glDisable(GL_LINE_SMOOTH );
1249
1250         /* matrix after circle */
1251         glPopMatrix();
1252
1253         /* enable blender light */
1254         for(a=0; a<8; a++) {
1255                 if(old[a])
1256                         glEnable(GL_LIGHT0+a);
1257         }
1258 }
1259
1260 static void ui_draw_but_curve_grid(rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
1261 {
1262         float dx, dy, fx, fy;
1263         
1264         glBegin(GL_LINES);
1265         dx= step*zoomx;
1266         fx= rect->xmin + zoomx*(-offsx);
1267         if(fx > rect->xmin) fx -= dx*(floorf(fx-rect->xmin));
1268         while(fx < rect->xmax) {
1269                 glVertex2f(fx, rect->ymin); 
1270                 glVertex2f(fx, rect->ymax);
1271                 fx+= dx;
1272         }
1273         
1274         dy= step*zoomy;
1275         fy= rect->ymin + zoomy*(-offsy);
1276         if(fy > rect->ymin) fy -= dy*(floorf(fy-rect->ymin));
1277         while(fy < rect->ymax) {
1278                 glVertex2f(rect->xmin, fy); 
1279                 glVertex2f(rect->xmax, fy);
1280                 fy+= dy;
1281         }
1282         glEnd();
1283         
1284 }
1285
1286 static void glColor3ubvShade(unsigned char *col, int shade)
1287 {
1288         glColor3ub(col[0]-shade>0?col[0]-shade:0,
1289                    col[1]-shade>0?col[1]-shade:0,
1290                    col[2]-shade>0?col[2]-shade:0);
1291 }
1292
1293 void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect)
1294 {
1295         CurveMapping *cumap;
1296         CurveMap *cuma;
1297         CurveMapPoint *cmp;
1298         float fx, fy, fac[2], zoomx, zoomy, offsx, offsy;
1299         GLint scissor[4];
1300         rcti scissor_new;
1301         int a;
1302
1303         cumap= (CurveMapping *)(but->editcumap? but->editcumap: but->poin);
1304         cuma= cumap->cm+cumap->cur;
1305         
1306         /* need scissor test, curve can draw outside of boundary */
1307         glGetIntegerv(GL_VIEWPORT, scissor);
1308         scissor_new.xmin= ar->winrct.xmin + rect->xmin;
1309         scissor_new.ymin= ar->winrct.ymin + rect->ymin;
1310         scissor_new.xmax= ar->winrct.xmin + rect->xmax;
1311         scissor_new.ymax= ar->winrct.ymin + rect->ymax;
1312         BLI_isect_rcti(&scissor_new, &ar->winrct, &scissor_new);
1313         glScissor(scissor_new.xmin, scissor_new.ymin, scissor_new.xmax-scissor_new.xmin, scissor_new.ymax-scissor_new.ymin);
1314         
1315         /* calculate offset and zoom */
1316         zoomx= (rect->xmax-rect->xmin-2.0f*but->aspect)/(cumap->curr.xmax - cumap->curr.xmin);
1317         zoomy= (rect->ymax-rect->ymin-2.0f*but->aspect)/(cumap->curr.ymax - cumap->curr.ymin);
1318         offsx= cumap->curr.xmin-but->aspect/zoomx;
1319         offsy= cumap->curr.ymin-but->aspect/zoomy;
1320         
1321         /* backdrop */
1322         if(cumap->flag & CUMA_DO_CLIP) {
1323                 glColor3ubvShade((unsigned char *)wcol->inner, -20);
1324                 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1325                 glColor3ubv((unsigned char*)wcol->inner);
1326                 glRectf(rect->xmin + zoomx*(cumap->clipr.xmin-offsx),
1327                                 rect->ymin + zoomy*(cumap->clipr.ymin-offsy),
1328                                 rect->xmin + zoomx*(cumap->clipr.xmax-offsx),
1329                                 rect->ymin + zoomy*(cumap->clipr.ymax-offsy));
1330         }
1331         else {
1332                 glColor3ubv((unsigned char*)wcol->inner);
1333                 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1334         }
1335                 
1336         /* grid, every .25 step */
1337         glColor3ubvShade((unsigned char *)wcol->inner, -16);
1338         ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f);
1339         /* grid, every 1.0 step */
1340         glColor3ubvShade((unsigned char *)wcol->inner, -24);
1341         ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f);
1342         /* axes */
1343         glColor3ubvShade((unsigned char *)wcol->inner, -50);
1344         glBegin(GL_LINES);
1345         glVertex2f(rect->xmin, rect->ymin + zoomy*(-offsy));
1346         glVertex2f(rect->xmax, rect->ymin + zoomy*(-offsy));
1347         glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymin);
1348         glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymax);
1349         glEnd();
1350         
1351         /* magic trigger for curve backgrounds */
1352         if (but->a1 != -1) {
1353                 if (but->a1 == UI_GRAD_H) {
1354                         rcti grid;
1355                         float col[3]= {0.0f, 0.0f, 0.0f}; /* dummy arg */
1356                         
1357                         grid.xmin = rect->xmin + zoomx*(-offsx);
1358                         grid.xmax = rect->xmax + zoomx*(-offsx);
1359                         grid.ymin = rect->ymin + zoomy*(-offsy);
1360                         grid.ymax = rect->ymax + zoomy*(-offsy);
1361                         
1362                         glEnable(GL_BLEND);
1363                         ui_draw_gradient(&grid, col, UI_GRAD_H, 0.5f);
1364                         glDisable(GL_BLEND);
1365                 }
1366         }
1367         
1368         
1369         /* cfra option */
1370         /* XXX 2.48
1371         if(cumap->flag & CUMA_DRAW_CFRA) {
1372                 glColor3ub(0x60, 0xc0, 0x40);
1373                 glBegin(GL_LINES);
1374                 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymin);
1375                 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymax);
1376                 glEnd();
1377         }*/
1378         /* sample option */
1379         /* XXX 2.48
1380          * if(cumap->flag & CUMA_DRAW_SAMPLE) {
1381                 if(cumap->cur==3) {
1382                         float lum= cumap->sample[0]*0.35f + cumap->sample[1]*0.45f + cumap->sample[2]*0.2f;
1383                         glColor3ub(240, 240, 240);
1384                         
1385                         glBegin(GL_LINES);
1386                         glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymin);
1387                         glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymax);
1388                         glEnd();
1389                 }
1390                 else {
1391                         if(cumap->cur==0)
1392                                 glColor3ub(240, 100, 100);
1393                         else if(cumap->cur==1)
1394                                 glColor3ub(100, 240, 100);
1395                         else
1396                                 glColor3ub(100, 100, 240);
1397                         
1398                         glBegin(GL_LINES);
1399                         glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymin);
1400                         glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymax);
1401                         glEnd();
1402                 }
1403         }*/
1404         
1405         /* the curve */
1406         glColor3ubv((unsigned char*)wcol->item);
1407         glEnable(GL_LINE_SMOOTH);
1408         glEnable(GL_BLEND);
1409         glBegin(GL_LINE_STRIP);
1410         
1411         if(cuma->table==NULL)
1412                 curvemapping_changed(cumap, 0); /* 0 = no remove doubles */
1413         cmp= cuma->table;
1414         
1415         /* first point */
1416         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1417                 glVertex2f(rect->xmin, rect->ymin + zoomy*(cmp[0].y-offsy));
1418         else {
1419                 fx= rect->xmin + zoomx*(cmp[0].x-offsx + cuma->ext_in[0]);
1420                 fy= rect->ymin + zoomy*(cmp[0].y-offsy + cuma->ext_in[1]);
1421                 glVertex2f(fx, fy);
1422         }
1423         for(a=0; a<=CM_TABLE; a++) {
1424                 fx= rect->xmin + zoomx*(cmp[a].x-offsx);
1425                 fy= rect->ymin + zoomy*(cmp[a].y-offsy);
1426                 glVertex2f(fx, fy);
1427         }
1428         /* last point */
1429         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1430                 glVertex2f(rect->xmax, rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy));     
1431         else {
1432                 fx= rect->xmin + zoomx*(cmp[CM_TABLE].x-offsx - cuma->ext_out[0]);
1433                 fy= rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy - cuma->ext_out[1]);
1434                 glVertex2f(fx, fy);
1435         }
1436         glEnd();
1437         glDisable(GL_LINE_SMOOTH);
1438         glDisable(GL_BLEND);
1439
1440         /* the points, use aspect to make them visible on edges */
1441         cmp= cuma->curve;
1442         glPointSize(3.0f);
1443         bglBegin(GL_POINTS);
1444         for(a=0; a<cuma->totpoint; a++) {
1445                 if(cmp[a].flag & SELECT)
1446                         UI_ThemeColor(TH_TEXT_HI);
1447                 else
1448                         UI_ThemeColor(TH_TEXT);
1449                 fac[0]= rect->xmin + zoomx*(cmp[a].x-offsx);
1450                 fac[1]= rect->ymin + zoomy*(cmp[a].y-offsy);
1451                 bglVertex2fv(fac);
1452         }
1453         bglEnd();
1454         glPointSize(1.0f);
1455         
1456         /* restore scissortest */
1457         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1458
1459         /* outline */
1460         glColor3ubv((unsigned char*)wcol->outline);
1461         fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1462 }
1463
1464 static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float track_pos[2], int width, float height, int margin)
1465 {
1466         ImBuf *scaleibuf;
1467         const float scalex= ((float)ibuf->x-2*margin) / width;
1468         const float scaley= ((float)ibuf->y-2*margin) / height;
1469         float off_x= (int)track_pos[0]-track_pos[0]+0.5f;
1470         float off_y= (int)track_pos[1]-track_pos[1]+0.5f;
1471         int x, y;
1472
1473         scaleibuf= IMB_allocImBuf(width, height, 32, IB_rect);
1474
1475         for(y= 0; y<height; y++) {
1476                 for (x= 0; x<width; x++) {
1477                         float src_x= scalex*(x)+margin-off_x;
1478                         float src_y= scaley*(y)+margin-off_y;
1479
1480                         bicubic_interpolation(ibuf, scaleibuf, src_x, src_y, x, y);
1481                 }
1482         }
1483
1484         return scaleibuf;
1485 }
1486
1487 void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
1488 {
1489         rctf rect;
1490         int ok= 0;
1491         GLint scissor[4];
1492         MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
1493
1494         rect.xmin = (float)recti->xmin+1;
1495         rect.xmax = (float)recti->xmax-1;
1496         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
1497         rect.ymax = (float)recti->ymax-1;
1498
1499         glEnable(GL_BLEND);
1500         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1501
1502         /* need scissor test, preview image can draw outside of boundary */
1503         glGetIntegerv(GL_VIEWPORT, scissor);
1504         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));
1505
1506         if(scopes->track_disabled) {
1507                 glColor4f(0.7f, 0.3f, 0.3f, 0.3f);
1508                 uiSetRoundBox(15);
1509                 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin, rect.xmax+1, rect.ymax+1, 3.0f);
1510
1511                 ok= 1;
1512         }
1513         else if(scopes->track_preview) {
1514                 /* additional margin around image */
1515                 /* NOTE: should be kept in sync with value from BKE_movieclip_update_scopes */
1516                 const int margin= 3;
1517                 float zoomx, zoomy, track_pos[2], off_x, off_y;
1518                 int a, width, height;
1519                 ImBuf *drawibuf;
1520
1521                 glPushMatrix();
1522
1523                 track_pos[0]= scopes->track_pos[0]-margin;
1524                 track_pos[1]= scopes->track_pos[1]-margin;
1525
1526                 /* draw content of pattern area */
1527                 glScissor(ar->winrct.xmin+rect.xmin, ar->winrct.ymin+rect.ymin, scissor[2], scissor[3]);
1528
1529                 width= rect.xmax-rect.xmin+1;
1530                 height = rect.ymax-rect.ymin;
1531
1532                 zoomx= (float)width / (scopes->track_preview->x-2*margin);
1533                 zoomy= (float)height / (scopes->track_preview->y-2*margin);
1534
1535                 off_x= ((int)track_pos[0]-track_pos[0]+0.5)*zoomx;
1536                 off_y= ((int)track_pos[1]-track_pos[1]+0.5)*zoomy;
1537
1538                 drawibuf= scale_trackpreview_ibuf(scopes->track_preview, track_pos, width, height, margin);
1539
1540                 glaDrawPixelsSafe(rect.xmin, rect.ymin+1, drawibuf->x, drawibuf->y,
1541                                   drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
1542                 IMB_freeImBuf(drawibuf);
1543
1544                 /* draw cross for pizel position */
1545                 glTranslatef(off_x+rect.xmin+track_pos[0]*zoomx, off_y+rect.ymin+track_pos[1]*zoomy, 0.f);
1546                 glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin+rect.ymin, rect.xmax-rect.xmin, rect.ymax-rect.ymin);
1547
1548                 for(a= 0; a< 2; a++) {
1549                         if(a==1) {
1550                                 glLineStipple(3, 0xaaaa);
1551                                 glEnable(GL_LINE_STIPPLE);
1552                                 UI_ThemeColor(TH_SEL_MARKER);
1553                         }
1554                         else {
1555                                 UI_ThemeColor(TH_MARKER_OUTLINE);
1556                         }
1557
1558                         glBegin(GL_LINES);
1559                                 glVertex2f(-10.0f, 0.0f);
1560                                 glVertex2f(10.0f, 0.0f);
1561                                 glVertex2f(0.0f, -10.0f);
1562                                 glVertex2f(0.0f, 10.0f);
1563                         glEnd();
1564                 }
1565
1566                 glDisable(GL_LINE_STIPPLE);
1567                 glPopMatrix();
1568
1569                 ok= 1;
1570         }
1571
1572         if(!ok) {
1573                 glColor4f(0.f, 0.f, 0.f, 0.3f);
1574                 uiSetRoundBox(15);
1575                 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin, rect.xmax+1, rect.ymax+1, 3.0f);
1576         }
1577
1578         /* outline, scale gripper */
1579         draw_scope_end(&rect, scissor);
1580
1581         glDisable(GL_BLEND);
1582 }
1583
1584 /* ****************************************************** */
1585
1586
1587 static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
1588 {
1589         glEnable(GL_BLEND);
1590         glShadeModel(GL_SMOOTH);
1591         
1592         /* right quad */
1593         glBegin(GL_POLYGON);
1594         glColor4ub(0, 0, 0, alpha);
1595         glVertex2f(maxx, miny);
1596         glVertex2f(maxx, maxy-0.3f*shadsize);
1597         glColor4ub(0, 0, 0, 0);
1598         glVertex2f(maxx+shadsize, maxy-0.75f*shadsize);
1599         glVertex2f(maxx+shadsize, miny);
1600         glEnd();
1601         
1602         /* corner shape */
1603         glBegin(GL_POLYGON);
1604         glColor4ub(0, 0, 0, alpha);
1605         glVertex2f(maxx, miny);
1606         glColor4ub(0, 0, 0, 0);
1607         glVertex2f(maxx+shadsize, miny);
1608         glVertex2f(maxx+0.7f*shadsize, miny-0.7f*shadsize);
1609         glVertex2f(maxx, miny-shadsize);
1610         glEnd();
1611         
1612         /* bottom quad */               
1613         glBegin(GL_POLYGON);
1614         glColor4ub(0, 0, 0, alpha);
1615         glVertex2f(minx+0.3f*shadsize, miny);
1616         glVertex2f(maxx, miny);
1617         glColor4ub(0, 0, 0, 0);
1618         glVertex2f(maxx, miny-shadsize);
1619         glVertex2f(minx+0.5f*shadsize, miny-shadsize);
1620         glEnd();
1621         
1622         glDisable(GL_BLEND);
1623         glShadeModel(GL_FLAT);
1624 }
1625
1626 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
1627 {
1628         /* accumulated outline boxes to make shade not linear, is more pleasant */
1629         ui_shadowbox(minx, miny, maxx, maxy, 11.0, (20*alpha)>>8);
1630         ui_shadowbox(minx, miny, maxx, maxy, 7.0, (40*alpha)>>8);
1631         ui_shadowbox(minx, miny, maxx, maxy, 5.0, (80*alpha)>>8);
1632         
1633 }
1634
1635
1636 void ui_dropshadow(rctf *rct, float radius, float aspect, int UNUSED(select))
1637 {
1638         int i;
1639         float rad;
1640         float a;
1641         char alpha= 2;
1642         
1643         glEnable(GL_BLEND);
1644         
1645         if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f)
1646                 rad= (rct->ymax-rct->ymin-10.0f)/2.0f;
1647         else
1648                 rad= radius;
1649
1650         i= 12;
1651 #if 0
1652         if(select) {
1653                 a= i*aspect; /* same as below */
1654         }
1655         else
1656 #endif
1657         {
1658                 a= i*aspect;
1659         }
1660
1661         for(; i--; a-=aspect) {
1662                 /* alpha ranges from 2 to 20 or so */
1663                 glColor4ub(0, 0, 0, alpha);
1664                 alpha+= 2;
1665                 
1666                 uiDrawBox(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a);
1667         }
1668         
1669         /* outline emphasis */
1670         glEnable( GL_LINE_SMOOTH );
1671         glColor4ub(0, 0, 0, 100);
1672         uiDrawBox(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius+0.5f);
1673         glDisable( GL_LINE_SMOOTH );
1674         
1675         glDisable(GL_BLEND);
1676 }
1677