97248e8710caa0316ef2025d9683d453e30c4c4f
[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 #if 0
437         //glColor4f(1.0, 0.f, 0.f, 1.f);
438         //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax)
439
440         w = (rect->xmax - rect->xmin);
441         h = (rect->ymax - rect->ymin);
442         // prevent drawing outside widget area
443         glGetIntegerv(GL_SCISSOR_BOX, scissor);
444         glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h);
445 #endif
446         
447         glEnable(GL_BLEND);
448         glColor4f(0.0, 0.0, 0.0, 0.0);
449         
450         glaDrawPixelsSafe((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
451         //glaDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
452         
453         glDisable(GL_BLEND);
454         
455 #if 0
456         // restore scissortest
457         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
458 #endif
459         
460 #endif
461 }
462
463 #if 0
464 #ifdef WITH_INTERNATIONAL
465 static void ui_draw_but_CHARTAB(uiBut *but)
466 {
467         /* XXX 2.50 bad global access */
468         /* Some local variables */
469         float sx, sy, ex, ey;
470         float width, height;
471         float butw, buth;
472         int x, y, cs;
473         wchar_t wstr[2];
474         unsigned char ustr[16];
475         PackedFile *pf;
476         int result = 0;
477         int charmax = G.charmax;
478         
479         /* FO_BUILTIN_NAME font in use. There are TTF FO_BUILTIN_NAME and non-TTF FO_BUILTIN_NAME fonts */
480         if(!strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
481                 if(G.ui_international == TRUE) {
482                         charmax = 0xff;
483                 }
484                 else {
485                         charmax = 0xff;
486                 }
487         }
488
489         /* Category list exited without selecting the area */
490         if(G.charmax == 0)
491                 charmax = G.charmax = 0xffff;
492
493         /* Calculate the size of the button */
494         width = abs(rect->xmax - rect->xmin);
495         height = abs(rect->ymax - rect->ymin);
496         
497         butw = floor(width / 12);
498         buth = floor(height / 6);
499         
500         /* Initialize variables */
501         sx = rect->xmin;
502         ex = rect->xmin + butw;
503         sy = rect->ymin + height - buth;
504         ey = rect->ymin + height;
505
506         cs = G.charstart;
507
508         /* Set the font, in case it is not FO_BUILTIN_NAME font */
509         if(G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) {
510                 // Is the font file packed, if so then use the packed file
511                 if(G.selfont->packedfile) {
512                         pf = G.selfont->packedfile;             
513                         FTF_SetFont(pf->data, pf->size, 14.0);
514                 }
515                 else {
516                         char tmpStr[256];
517                         int err;
518
519                         BLI_strncpy(tmpStr, G.selfont->name, sizeof(tmpStr));
520                         BLI_path_abs(tmpStr, G.main->name);
521                         err = FTF_SetFont((unsigned char *)tmpStr, 0, 14.0);
522                 }
523         }
524         else {
525                 if(G.ui_international == TRUE) {
526                         FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 14.0);
527                 }
528         }
529
530         /* Start drawing the button itself */
531         glShadeModel(GL_SMOOTH);
532
533         glColor3ub(200,  200,  200);
534         glRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
535
536         glColor3ub(0,  0,  0);
537         for(y = 0; y < 6; y++) {
538                 // Do not draw more than the category allows
539                 if(cs > charmax) break;
540
541                 for(x = 0; x < 12; x++)
542                 {
543                         // Do not draw more than the category allows
544                         if(cs > charmax) break;
545
546                         // Draw one grid cell
547                         glBegin(GL_LINE_LOOP);
548                                 glVertex2f(sx, sy);
549                                 glVertex2f(ex, sy);
550                                 glVertex2f(ex, ey);
551                                 glVertex2f(sx, ey);                             
552                         glEnd();        
553
554                         // Draw character inside the cell
555                         memset(wstr, 0, sizeof(wchar_t)*2);
556                         memset(ustr, 0, 16);
557
558                         // Set the font to be either unicode or FO_BUILTIN_NAME 
559                         wstr[0] = cs;
560                         if(strcmp(G.selfont->name, FO_BUILTIN_NAME))
561                         {
562                                 BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr));
563                         }
564                         else
565                         {
566                                 if(G.ui_international == TRUE)
567                                 {
568                                         BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr));
569                                 }
570                                 else
571                                 {
572                                         ustr[0] = cs;
573                                         ustr[1] = 0;
574                                 }
575                         }
576
577                         if((G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) || (G.selfont && !strcmp(G.selfont->name, FO_BUILTIN_NAME) && G.ui_international == TRUE))
578                         {
579                                 float wid;
580                                 float llx, lly, llz, urx, ury, urz;
581                                 float dx, dy;
582                                 float px, py;
583         
584                                 // Calculate the position
585                                 wid = FTF_GetStringWidth((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
586                                 FTF_GetBoundingBox((char *) ustr, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
587                                 dx = urx-llx;
588                                 dy = ury-lly;
589
590                                 // This isn't fully functional since the but->aspect isn't working like I suspected
591                                 px = sx + ((butw/but->aspect)-dx)/2;
592                                 py = sy + ((buth/but->aspect)-dy)/2;
593
594                                 // Set the position and draw the character
595                                 ui_rasterpos_safe(px, py, but->aspect);
596                                 FTF_DrawString((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
597                         }
598                         else
599                         {
600                                 ui_rasterpos_safe(sx + butw/2, sy + buth/2, but->aspect);
601                                 UI_DrawString(but->font, (char *) ustr, 0);
602                         }
603         
604                         // Calculate the next position and character
605                         sx += butw; ex +=butw;
606                         cs++;
607                 }
608                 /* Add the y position and reset x position */
609                 sy -= buth; 
610                 ey -= buth;
611                 sx = rect->xmin;
612                 ex = rect->xmin + butw;
613         }       
614         glShadeModel(GL_FLAT);
615
616         /* Return Font Settings to original */
617         if(U.fontsize && U.fontname[0]) {
618                 result = FTF_SetFont((unsigned char *)U.fontname, 0, U.fontsize);
619         }
620         else if (U.fontsize) {
621                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, U.fontsize);
622         }
623
624         if (result == 0) {
625                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 11);
626         }
627         
628         /* resets the font size */
629         if(G.ui_international == TRUE) {
630                 // uiSetCurFont(but->block, UI_HELV);
631         }
632 }
633
634 #endif // WITH_INTERNATIONAL
635 #endif
636
637 static void draw_scope_end(rctf *rect, GLint *scissor)
638 {
639         float scaler_x1, scaler_x2;
640         
641         /* restore scissortest */
642         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
643         
644         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
645         
646         /* scale widget */
647         scaler_x1 = rect->xmin + (rect->xmax - rect->xmin)/2 - SCOPE_RESIZE_PAD;
648         scaler_x2 = rect->xmin + (rect->xmax - rect->xmin)/2 + SCOPE_RESIZE_PAD;
649         
650         glColor4f(0.f, 0.f, 0.f, 0.25f);
651         fdrawline(scaler_x1, rect->ymin-4, scaler_x2, rect->ymin-4);
652         fdrawline(scaler_x1, rect->ymin-7, scaler_x2, rect->ymin-7);
653         glColor4f(1.f, 1.f, 1.f, 0.25f);
654         fdrawline(scaler_x1, rect->ymin-5, scaler_x2, rect->ymin-5);
655         fdrawline(scaler_x1, rect->ymin-8, scaler_x2, rect->ymin-8);
656         
657         /* outline */
658         glColor4f(0.f, 0.f, 0.f, 0.5f);
659         uiSetRoundBox(UI_CNR_ALL);
660         uiDrawBox(GL_LINE_LOOP, rect->xmin-1, rect->ymin, rect->xmax+1, rect->ymax+1, 3.0f);
661 }
662
663 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)
664 {
665         int i;
666         
667         /* under the curve */
668         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
669         glColor4f(r, g, b, alpha);
670         
671         glShadeModel(GL_FLAT);
672         glBegin(GL_QUAD_STRIP);
673         glVertex2f(x, y);
674         glVertex2f(x, y + (data[0]*h));
675         for (i=1; i < res; i++) {
676                 float x2 = x + i * (w/(float)res);
677                 glVertex2f(x2, y + (data[i]*h));
678                 glVertex2f(x2, y);
679         }
680         glEnd();
681         
682         /* curve outline */
683         glColor4f(0.f, 0.f, 0.f, 0.25f);
684         
685         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
686         glEnable(GL_LINE_SMOOTH);
687         glBegin(GL_LINE_STRIP);
688         for (i=0; i < res; i++) {
689                 float x2 = x + i * (w/(float)res);
690                 glVertex2f(x2, y + (data[i]*h));
691         }
692         glEnd();
693         glDisable(GL_LINE_SMOOTH);
694 }
695
696 void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
697 {
698         Histogram *hist = (Histogram *)but->poin;
699         int res = hist->x_resolution;
700         rctf rect;
701         int i;
702         float w, h;
703         //float alpha;
704         GLint scissor[4];
705         
706         rect.xmin = (float)recti->xmin+1;
707         rect.xmax = (float)recti->xmax-1;
708         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
709         rect.ymax = (float)recti->ymax-1;
710         
711         w = rect.xmax - rect.xmin;
712         h = (rect.ymax - rect.ymin) * hist->ymax;
713         
714         glEnable(GL_BLEND);
715         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
716         
717         glColor4f(0.f, 0.f, 0.f, 0.3f);
718         uiSetRoundBox(UI_CNR_ALL);
719         uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
720
721         /* need scissor test, histogram can draw outside of boundary */
722         glGetIntegerv(GL_VIEWPORT, scissor);
723         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));
724
725         glColor4f(1.f, 1.f, 1.f, 0.08f);
726         /* draw grid lines here */
727         for (i=1; i<4; i++) {
728                 fdrawline(rect.xmin, rect.ymin+(i/4.f)*h, rect.xmax, rect.ymin+(i/4.f)*h);
729                 fdrawline(rect.xmin+(i/4.f)*w, rect.ymin, rect.xmin+(i/4.f)*w, rect.ymax);
730         }
731         
732         if (hist->mode == HISTO_MODE_LUMA)
733                 histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res);
734         else {
735                 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
736                         histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res);
737                 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G)
738                         histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res);
739                 if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B)
740                         histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res);
741         }
742         
743         /* outline, scale gripper */
744         draw_scope_end(&rect, scissor);
745 }
746
747 void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
748 {
749         Scopes *scopes = (Scopes *)but->poin;
750         rctf rect;
751         int i, c;
752         float w, w3, h, alpha, yofs;
753         GLint scissor[4];
754         float colors[3][3]= MAT3_UNITY;
755         float colorsycc[3][3] = {{1,0,1},{1,1,0},{0,1,1}};
756         float colors_alpha[3][3], colorsycc_alpha[3][3]; /* colors  pre multiplied by alpha for speed up */
757         float min, max;
758         
759         if (scopes==NULL) return;
760         
761         rect.xmin = (float)recti->xmin+1;
762         rect.xmax = (float)recti->xmax-1;
763         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
764         rect.ymax = (float)recti->ymax-1;
765         
766         if (scopes->wavefrm_yfac < 0.5f )
767                 scopes->wavefrm_yfac =0.98f;
768         w = rect.xmax - rect.xmin-7;
769         h = (rect.ymax - rect.ymin)*scopes->wavefrm_yfac;
770         yofs= rect.ymin + (rect.ymax - rect.ymin -h)/2.0f;
771         w3=w/3.0f;
772         
773         /* log scale for alpha */
774         alpha = scopes->wavefrm_alpha*scopes->wavefrm_alpha;
775         
776         for(c=0; c<3; c++) {
777                 for(i=0; i<3; i++) {
778                         colors_alpha[c][i] = colors[c][i] * alpha;
779                         colorsycc_alpha[c][i] = colorsycc[c][i] * alpha;
780                 }
781         }
782                         
783         glEnable(GL_BLEND);
784         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
785         
786         glColor4f(0.f, 0.f, 0.f, 0.3f);
787         uiSetRoundBox(UI_CNR_ALL);
788         uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
789         
790
791         /* need scissor test, waveform can draw outside of boundary */
792         glGetIntegerv(GL_VIEWPORT, scissor);
793         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));
794
795         glColor4f(1.f, 1.f, 1.f, 0.08f);
796         /* draw grid lines here */
797         for (i=0; i<6; i++) {
798                 char str[4];
799                 BLI_snprintf(str, sizeof(str), "%-3d",i*20);
800                 str[3]='\0';
801                 fdrawline(rect.xmin+22, yofs+(i/5.f)*h, rect.xmax+1, yofs+(i/5.f)*h);
802                 BLF_draw_default(rect.xmin+1, yofs-5+(i/5.f)*h, 0, str, sizeof(str)-1);
803                 /* in the loop because blf_draw reset it */
804                 glEnable(GL_BLEND);
805                 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
806         }
807         /* 3 vertical separation */
808         if (scopes->wavefrm_mode!= SCOPES_WAVEFRM_LUMA) {
809                 for (i=1; i<3; i++) {
810                         fdrawline(rect.xmin+i*w3, rect.ymin, rect.xmin+i*w3, rect.ymax);
811                 }
812         }
813         
814         /* separate min max zone on the right */
815         fdrawline(rect.xmin+w, rect.ymin, rect.xmin+w, rect.ymax);
816         /* 16-235-240 level in case of ITU-R BT601/709 */
817         glColor4f(1.f, 0.4f, 0.f, 0.2f);
818         if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)){
819                 fdrawline(rect.xmin+22, yofs+h*16.0f/255.0f, rect.xmax+1, yofs+h*16.0f/255.0f);
820                 fdrawline(rect.xmin+22, yofs+h*235.0f/255.0f, rect.xmin+w3, yofs+h*235.0f/255.0f);
821                 fdrawline(rect.xmin+3*w3, yofs+h*235.0f/255.0f, rect.xmax+1, yofs+h*235.0f/255.0f);
822                 fdrawline(rect.xmin+w3, yofs+h*240.0f/255.0f, rect.xmax+1, yofs+h*240.0f/255.0f);
823         }
824         /* 7.5 IRE black point level for NTSC */
825         if (scopes->wavefrm_mode== SCOPES_WAVEFRM_LUMA)
826                 fdrawline(rect.xmin, yofs+h*0.075f, rect.xmax+1, yofs+h*0.075f);
827
828         if (scopes->ok && scopes->waveform_1 != NULL) {
829                 
830                 /* LUMA (1 channel) */
831                 glBlendFunc(GL_ONE,GL_ONE);
832                 glColor3f(alpha, alpha, alpha);
833                 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA){
834
835                         glBlendFunc(GL_ONE,GL_ONE);
836                         
837                         glPushMatrix();
838                         glEnableClientState(GL_VERTEX_ARRAY);
839                         
840                         glTranslatef(rect.xmin, yofs, 0.f);
841                         glScalef(w, h, 0.f);
842                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
843                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
844                                         
845                         glDisableClientState(GL_VERTEX_ARRAY);
846                         glPopMatrix();
847
848                         /* min max */
849                         glColor3f(.5f, .5f, .5f);
850                         min= yofs+scopes->minmax[0][0]*h;
851                         max= yofs+scopes->minmax[0][1]*h;
852                         CLAMP(min, rect.ymin, rect.ymax);
853                         CLAMP(max, rect.ymin, rect.ymax);
854                         fdrawline(rect.xmax-3,min,rect.xmax-3,max);
855                 }
856
857                 /* RGB / YCC (3 channels) */
858                 else if (ELEM4(scopes->wavefrm_mode, SCOPES_WAVEFRM_RGB, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709, SCOPES_WAVEFRM_YCC_JPEG)) {
859                         int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB);
860                         
861                         glBlendFunc(GL_ONE,GL_ONE);
862                         
863                         glPushMatrix();
864                         glEnableClientState(GL_VERTEX_ARRAY);
865                         
866                         glTranslatef(rect.xmin, yofs, 0.f);
867                         glScalef(w3, h, 0.f);
868                         
869                         glColor3fv((rgb)?colors_alpha[0]:colorsycc_alpha[0]);
870                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
871                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
872
873                         glTranslatef(1.f, 0.f, 0.f);
874                         glColor3fv((rgb)?colors_alpha[1]:colorsycc_alpha[1]);
875                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2);
876                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
877                         
878                         glTranslatef(1.f, 0.f, 0.f);
879                         glColor3fv((rgb)?colors_alpha[2]:colorsycc_alpha[2]);
880                         glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3);
881                         glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
882                         
883                         glDisableClientState(GL_VERTEX_ARRAY);
884                         glPopMatrix();
885
886                         
887                         /* min max */
888                         for (c=0; c<3; c++) {
889                                 if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB)
890                                         glColor3f(colors[c][0]*0.75f, colors[c][1]*0.75f, colors[c][2]*0.75f);
891                                 else
892                                         glColor3f(colorsycc[c][0]*0.75f, colorsycc[c][1]*0.75f, colorsycc[c][2]*0.75f);
893                                 min= yofs+scopes->minmax[c][0]*h;
894                                 max= yofs+scopes->minmax[c][1]*h;
895                                 CLAMP(min, rect.ymin, rect.ymax);
896                                 CLAMP(max, rect.ymin, rect.ymax);
897                                 fdrawline(rect.xmin+w+2+c*2,min,rect.xmin+w+2+c*2,max);
898                         }
899                 }
900                 
901         }
902         
903         /* outline, scale gripper */
904         draw_scope_end(&rect, scissor);
905 }
906
907 static float polar_to_x(float center, float diam, float ampli, float angle)
908 {
909         return center + diam * ampli * cosf(angle);
910 }
911
912 static float polar_to_y(float center, float diam, float ampli, float angle)
913 {
914         return center + diam * ampli * sinf(angle);
915 }
916
917 static void vectorscope_draw_target(float centerx, float centery, float diam, const float colf[3])
918 {
919         float y,u,v;
920         float tangle=0.f, tampli;
921         float dangle, dampli, dangle2, dampli2;
922
923         rgb_to_yuv(colf[0], colf[1], colf[2], &y, &u, &v);
924         if (u>0 && v>=0) tangle=atanf(v/u);
925         else if (u>0 && v<0) tangle= atanf(v/u) + 2.0f * (float)M_PI;
926         else if (u<0) tangle=atanf(v/u) + (float)M_PI;
927         else if (u==0 && v > 0.0f) tangle= (float)M_PI/2.0f;
928         else if (u==0 && v < 0.0f) tangle=-(float)M_PI/2.0f;
929         tampli= sqrtf(u*u+v*v);
930
931         /* small target vary by 2.5 degree and 2.5 IRE unit */
932         glColor4f(1.0f, 1.0f, 1.0, 0.12f);
933         dangle= DEG2RADF(2.5f);
934         dampli= 2.5f/200.0f;
935         glBegin(GL_LINE_STRIP);
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         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
941         glEnd();
942         /* big target vary by 10 degree and 20% amplitude */
943         glColor4f(1.0f, 1.0f, 1.0, 0.12f);
944         dangle= DEG2RADF(10.0f);
945         dampli= 0.2f*tampli;
946         dangle2= DEG2RADF(5.0f);
947         dampli2= 0.5f*dampli;
948         glBegin(GL_LINE_STRIP);
949         glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle+dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle+dangle));
950         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle), polar_to_y(centery,diam,tampli+dampli,tangle+dangle));
951         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli+dampli,tangle+dangle-dangle2));
952         glEnd();
953         glBegin(GL_LINE_STRIP);
954         glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle+dangle), polar_to_y(centery ,diam,tampli-dampli+dampli2,tangle+dangle));
955         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle), polar_to_y(centery,diam,tampli-dampli,tangle+dangle));
956         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle+dangle-dangle2), polar_to_y(centery,diam,tampli-dampli,tangle+dangle-dangle2));
957         glEnd();
958         glBegin(GL_LINE_STRIP);
959         glVertex2f(polar_to_x(centerx,diam,tampli-dampli+dampli2,tangle-dangle), polar_to_y(centery,diam,tampli-dampli+dampli2,tangle-dangle));
960         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle), polar_to_y(centery,diam,tampli-dampli,tangle-dangle));
961         glVertex2f(polar_to_x(centerx,diam,tampli-dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli-dampli,tangle-dangle+dangle2));
962         glEnd();
963         glBegin(GL_LINE_STRIP);
964         glVertex2f(polar_to_x(centerx,diam,tampli+dampli-dampli2,tangle-dangle), polar_to_y(centery,diam,tampli+dampli-dampli2,tangle-dangle));
965         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle), polar_to_y(centery,diam,tampli+dampli,tangle-dangle));
966         glVertex2f(polar_to_x(centerx,diam,tampli+dampli,tangle-dangle+dangle2), polar_to_y(centery,diam,tampli+dampli,tangle-dangle+dangle2));
967         glEnd();
968 }
969
970 void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
971 {
972         const float skin_rad= DEG2RADF(123.0f); /* angle in radians of the skin tone line */
973         Scopes *scopes = (Scopes *)but->poin;
974         rctf rect;
975         int i, j;
976         float w, h, centerx, centery, diam;
977         float alpha;
978         const float colors[6][3]={{.75,0,0},{.75,.75,0},{0,.75,0},{0,.75,.75},{0,0,.75},{.75,0,.75}};
979         GLint scissor[4];
980         
981         rect.xmin = (float)recti->xmin+1;
982         rect.xmax = (float)recti->xmax-1;
983         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
984         rect.ymax = (float)recti->ymax-1;
985         
986         w = rect.xmax - rect.xmin;
987         h = rect.ymax - rect.ymin;
988         centerx = rect.xmin + w/2;
989         centery = rect.ymin + h/2;
990         diam= (w<h)?w:h;
991         
992         alpha = scopes->vecscope_alpha*scopes->vecscope_alpha*scopes->vecscope_alpha;
993                         
994         glEnable(GL_BLEND);
995         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
996         
997         glColor4f(0.f, 0.f, 0.f, 0.3f);
998         uiSetRoundBox(UI_CNR_ALL);
999         uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin-1, rect.xmax+1, rect.ymax+1, 3.0f);
1000
1001         /* need scissor test, hvectorscope can draw outside of boundary */
1002         glGetIntegerv(GL_VIEWPORT, scissor);
1003         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));
1004         
1005         glColor4f(1.f, 1.f, 1.f, 0.08f);
1006         /* draw grid elements */
1007         /* cross */
1008         fdrawline(centerx - (diam/2)-5, centery, centerx + (diam/2)+5, centery);
1009         fdrawline(centerx, centery - (diam/2)-5, centerx, centery + (diam/2)+5);
1010         /* circles */
1011         for(j=0; j<5; j++) {
1012                 glBegin(GL_LINE_STRIP);
1013                 for(i=0; i<=360; i=i+15) {
1014                         const float a= DEG2RADF((float)i);
1015                         const float r= (j+1)/10.0f;
1016                         glVertex2f(polar_to_x(centerx,diam,r,a), polar_to_y(centery,diam,r,a));
1017                 }
1018                 glEnd();
1019         }
1020         /* skin tone line */
1021         glColor4f(1.f, 0.4f, 0.f, 0.2f);
1022         fdrawline(polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery,diam,0.5,skin_rad),
1023                   polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery,diam,0.1,skin_rad));
1024         /* saturation points */
1025         for(i=0; i<6; i++)
1026                 vectorscope_draw_target(centerx, centery, diam, colors[i]);
1027         
1028         if (scopes->ok && scopes->vecscope != NULL) {
1029                 /* pixel point cloud */
1030                 glBlendFunc(GL_ONE,GL_ONE);
1031                 glColor3f(alpha, alpha, alpha);
1032
1033                 glPushMatrix();
1034                 glEnableClientState(GL_VERTEX_ARRAY);
1035
1036                 glTranslatef(centerx, centery, 0.f);
1037                 glScalef(diam, diam, 0.f);
1038
1039                 glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope);
1040                 glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
1041                 
1042                 glDisableClientState(GL_VERTEX_ARRAY);
1043                 glPopMatrix();
1044         }
1045
1046         /* outline, scale gripper */
1047         draw_scope_end(&rect, scissor);
1048                 
1049         glDisable(GL_BLEND);
1050 }
1051
1052 void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect)
1053 {
1054         ColorBand *coba;
1055         CBData *cbd;
1056         float x1, y1, sizex, sizey;
1057         float v3[2], v1[2], v2[2], v1a[2], v2a[2];
1058         int a;
1059         float pos, colf[4]= {0,0,0,0}; /* initialize incase the colorband isnt valid */
1060                 
1061         coba= (ColorBand *)(but->editcoba? but->editcoba: but->poin);
1062         if(coba==NULL) return;
1063         
1064         x1= rect->xmin;
1065         y1= rect->ymin;
1066         sizex= rect->xmax-x1;
1067         sizey= rect->ymax-y1;
1068
1069         /* first background, to show tranparency */
1070
1071         glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255);
1072         glRectf(x1, y1, x1+sizex, y1+sizey);
1073         glEnable(GL_POLYGON_STIPPLE);
1074         glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255);
1075         glPolygonStipple(checker_stipple_sml);
1076         glRectf(x1, y1, x1+sizex, y1+sizey);
1077         glDisable(GL_POLYGON_STIPPLE);
1078
1079         glShadeModel(GL_FLAT);
1080         glEnable(GL_BLEND);
1081         
1082         cbd= coba->data;
1083         
1084         v1[0]= v2[0]= x1;
1085         v1[1]= y1;
1086         v2[1]= y1+sizey;
1087         
1088         glBegin(GL_QUAD_STRIP);
1089         
1090         glColor4fv( &cbd->r );
1091         glVertex2fv(v1); glVertex2fv(v2);
1092         
1093         for( a = 1; a <= sizex; a++ ) {
1094                 pos = ((float)a) / (sizex-1);
1095                 do_colorband( coba, pos, colf );
1096                 if (but->block->color_profile != BLI_PR_NONE)
1097                         linearrgb_to_srgb_v3_v3(colf, colf);
1098                 
1099                 v1[0]=v2[0]= x1 + a;
1100                 
1101                 glColor4fv( colf );
1102                 glVertex2fv(v1); glVertex2fv(v2);
1103         }
1104         
1105         glEnd();
1106         glShadeModel(GL_FLAT);
1107         glDisable(GL_BLEND);
1108         
1109         /* outline */
1110         glColor4f(0.0, 0.0, 0.0, 1.0);
1111         fdrawbox(x1, y1, x1+sizex, y1+sizey);
1112         
1113         /* help lines */
1114         v1[0]= v2[0]=v3[0]= x1;
1115         v1[1]= y1;
1116         v1a[1]= y1+0.25f*sizey;
1117         v2[1]= y1+0.5f*sizey;
1118         v2a[1]= y1+0.75f*sizey;
1119         v3[1]= y1+sizey;
1120         
1121         
1122         cbd= coba->data;
1123         glBegin(GL_LINES);
1124         for(a=0; a<coba->tot; a++, cbd++) {
1125                 v1[0]=v2[0]=v3[0]=v1a[0]=v2a[0]= x1+ cbd->pos*sizex;
1126                 
1127                 if(a==coba->cur) {
1128                         glColor3ub(0, 0, 0);
1129                         glVertex2fv(v1);
1130                         glVertex2fv(v3);
1131                         glEnd();
1132                         
1133                         setlinestyle(2);
1134                         glBegin(GL_LINES);
1135                         glColor3ub(255, 255, 255);
1136                         glVertex2fv(v1);
1137                         glVertex2fv(v3);
1138                         glEnd();
1139                         setlinestyle(0);
1140                         glBegin(GL_LINES);
1141                         
1142 #if 0
1143                         glColor3ub(0, 0, 0);
1144                         glVertex2fv(v1);
1145                         glVertex2fv(v1a);
1146                         glColor3ub(255, 255, 255);
1147                         glVertex2fv(v1a);
1148                         glVertex2fv(v2);
1149                         glColor3ub(0, 0, 0);
1150                         glVertex2fv(v2);
1151                         glVertex2fv(v2a);
1152                         glColor3ub(255, 255, 255);
1153                         glVertex2fv(v2a);
1154                         glVertex2fv(v3);
1155 #endif
1156                 }
1157                 else {
1158                         glColor3ub(0, 0, 0);
1159                         glVertex2fv(v1);
1160                         glVertex2fv(v2);
1161                         
1162                         glColor3ub(255, 255, 255);
1163                         glVertex2fv(v2);
1164                         glVertex2fv(v3);
1165                 }       
1166         }
1167         glEnd();
1168
1169 }
1170
1171 void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect)
1172 {
1173         static GLuint displist=0;
1174         int a, old[8];
1175         GLfloat diff[4], diffn[4]={1.0f, 1.0f, 1.0f, 1.0f};
1176         float vec0[4]={0.0f, 0.0f, 0.0f, 0.0f};
1177         float dir[4], size;
1178         
1179         /* store stuff */
1180         glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
1181                 
1182         /* backdrop */
1183         glColor3ubv((unsigned char*)wcol->inner);
1184         uiSetRoundBox(UI_CNR_ALL);
1185         uiDrawBox(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f);
1186         
1187         /* sphere color */
1188         glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn);
1189         glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
1190         
1191         /* disable blender light */
1192         for(a=0; a<8; a++) {
1193                 old[a]= glIsEnabled(GL_LIGHT0+a);
1194                 glDisable(GL_LIGHT0+a);
1195         }
1196         
1197         /* own light */
1198         glEnable(GL_LIGHT7);
1199         glEnable(GL_LIGHTING);
1200         
1201         ui_get_but_vectorf(but, dir);
1202
1203         dir[3]= 0.0f;   /* glLight needs 4 args, 0.0 is sun */
1204         glLightfv(GL_LIGHT7, GL_POSITION, dir); 
1205         glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn); 
1206         glLightfv(GL_LIGHT7, GL_SPECULAR, vec0); 
1207         glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f);
1208         glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f);
1209         
1210         /* transform to button */
1211         glPushMatrix();
1212         glTranslatef(rect->xmin + 0.5f*(rect->xmax-rect->xmin), rect->ymin+ 0.5f*(rect->ymax-rect->ymin), 0.0f);
1213         
1214         if( rect->xmax-rect->xmin < rect->ymax-rect->ymin)
1215                 size= (rect->xmax-rect->xmin)/200.f;
1216         else
1217                 size= (rect->ymax-rect->ymin)/200.f;
1218         
1219         glScalef(size, size, size);
1220         
1221         if(displist==0) {
1222                 GLUquadricObj   *qobj;
1223                 
1224                 displist= glGenLists(1);
1225                 glNewList(displist, GL_COMPILE_AND_EXECUTE);
1226                 
1227                 qobj= gluNewQuadric();
1228                 gluQuadricDrawStyle(qobj, GLU_FILL); 
1229                 glShadeModel(GL_SMOOTH);
1230                 gluSphere( qobj, 100.0, 32, 24);
1231                 glShadeModel(GL_FLAT);
1232                 gluDeleteQuadric(qobj);  
1233                 
1234                 glEndList();
1235         }
1236         else glCallList(displist);
1237         
1238         /* restore */
1239         glDisable(GL_LIGHTING);
1240         glDisable(GL_CULL_FACE);
1241         glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); 
1242         glDisable(GL_LIGHT7);
1243         
1244         /* AA circle */
1245         glEnable(GL_BLEND);
1246         glEnable(GL_LINE_SMOOTH );
1247         glColor3ubv((unsigned char*)wcol->inner);
1248         glutil_draw_lined_arc(0.0f, M_PI*2.0, 100.0f, 32);
1249         glDisable(GL_BLEND);
1250         glDisable(GL_LINE_SMOOTH );
1251
1252         /* matrix after circle */
1253         glPopMatrix();
1254
1255         /* enable blender light */
1256         for(a=0; a<8; a++) {
1257                 if(old[a])
1258                         glEnable(GL_LIGHT0+a);
1259         }
1260 }
1261
1262 static void ui_draw_but_curve_grid(rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
1263 {
1264         float dx, dy, fx, fy;
1265         
1266         glBegin(GL_LINES);
1267         dx= step*zoomx;
1268         fx= rect->xmin + zoomx*(-offsx);
1269         if(fx > rect->xmin) fx -= dx*(floorf(fx-rect->xmin));
1270         while(fx < rect->xmax) {
1271                 glVertex2f(fx, rect->ymin); 
1272                 glVertex2f(fx, rect->ymax);
1273                 fx+= dx;
1274         }
1275         
1276         dy= step*zoomy;
1277         fy= rect->ymin + zoomy*(-offsy);
1278         if(fy > rect->ymin) fy -= dy*(floorf(fy-rect->ymin));
1279         while(fy < rect->ymax) {
1280                 glVertex2f(rect->xmin, fy); 
1281                 glVertex2f(rect->xmax, fy);
1282                 fy+= dy;
1283         }
1284         glEnd();
1285         
1286 }
1287
1288 static void glColor3ubvShade(unsigned char *col, int shade)
1289 {
1290         glColor3ub(col[0]-shade>0?col[0]-shade:0,
1291                    col[1]-shade>0?col[1]-shade:0,
1292                    col[2]-shade>0?col[2]-shade:0);
1293 }
1294
1295 void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect)
1296 {
1297         CurveMapping *cumap;
1298         CurveMap *cuma;
1299         CurveMapPoint *cmp;
1300         float fx, fy, fac[2], zoomx, zoomy, offsx, offsy;
1301         GLint scissor[4];
1302         rcti scissor_new;
1303         int a;
1304
1305         cumap= (CurveMapping *)(but->editcumap? but->editcumap: but->poin);
1306         cuma= cumap->cm+cumap->cur;
1307         
1308         /* need scissor test, curve can draw outside of boundary */
1309         glGetIntegerv(GL_VIEWPORT, scissor);
1310         scissor_new.xmin= ar->winrct.xmin + rect->xmin;
1311         scissor_new.ymin= ar->winrct.ymin + rect->ymin;
1312         scissor_new.xmax= ar->winrct.xmin + rect->xmax;
1313         scissor_new.ymax= ar->winrct.ymin + rect->ymax;
1314         BLI_isect_rcti(&scissor_new, &ar->winrct, &scissor_new);
1315         glScissor(scissor_new.xmin, scissor_new.ymin, scissor_new.xmax-scissor_new.xmin, scissor_new.ymax-scissor_new.ymin);
1316         
1317         /* calculate offset and zoom */
1318         zoomx= (rect->xmax-rect->xmin-2.0f*but->aspect)/(cumap->curr.xmax - cumap->curr.xmin);
1319         zoomy= (rect->ymax-rect->ymin-2.0f*but->aspect)/(cumap->curr.ymax - cumap->curr.ymin);
1320         offsx= cumap->curr.xmin-but->aspect/zoomx;
1321         offsy= cumap->curr.ymin-but->aspect/zoomy;
1322         
1323         /* backdrop */
1324         if(cumap->flag & CUMA_DO_CLIP) {
1325                 glColor3ubvShade((unsigned char *)wcol->inner, -20);
1326                 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1327                 glColor3ubv((unsigned char*)wcol->inner);
1328                 glRectf(rect->xmin + zoomx*(cumap->clipr.xmin-offsx),
1329                                 rect->ymin + zoomy*(cumap->clipr.ymin-offsy),
1330                                 rect->xmin + zoomx*(cumap->clipr.xmax-offsx),
1331                                 rect->ymin + zoomy*(cumap->clipr.ymax-offsy));
1332         }
1333         else {
1334                 glColor3ubv((unsigned char*)wcol->inner);
1335                 glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1336         }
1337                 
1338         /* grid, every .25 step */
1339         glColor3ubvShade((unsigned char *)wcol->inner, -16);
1340         ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f);
1341         /* grid, every 1.0 step */
1342         glColor3ubvShade((unsigned char *)wcol->inner, -24);
1343         ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f);
1344         /* axes */
1345         glColor3ubvShade((unsigned char *)wcol->inner, -50);
1346         glBegin(GL_LINES);
1347         glVertex2f(rect->xmin, rect->ymin + zoomy*(-offsy));
1348         glVertex2f(rect->xmax, rect->ymin + zoomy*(-offsy));
1349         glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymin);
1350         glVertex2f(rect->xmin + zoomx*(-offsx), rect->ymax);
1351         glEnd();
1352         
1353         /* magic trigger for curve backgrounds */
1354         if (but->a1 != -1) {
1355                 if (but->a1 == UI_GRAD_H) {
1356                         rcti grid;
1357                         float col[3]= {0.0f, 0.0f, 0.0f}; /* dummy arg */
1358                         
1359                         grid.xmin = rect->xmin + zoomx*(-offsx);
1360                         grid.xmax = rect->xmax + zoomx*(-offsx);
1361                         grid.ymin = rect->ymin + zoomy*(-offsy);
1362                         grid.ymax = rect->ymax + zoomy*(-offsy);
1363                         
1364                         glEnable(GL_BLEND);
1365                         ui_draw_gradient(&grid, col, UI_GRAD_H, 0.5f);
1366                         glDisable(GL_BLEND);
1367                 }
1368         }
1369         
1370         
1371         /* cfra option */
1372         /* XXX 2.48 */
1373 #if 0
1374         if(cumap->flag & CUMA_DRAW_CFRA) {
1375                 glColor3ub(0x60, 0xc0, 0x40);
1376                 glBegin(GL_LINES);
1377                 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymin);
1378                 glVertex2f(rect->xmin + zoomx*(cumap->sample[0]-offsx), rect->ymax);
1379                 glEnd();
1380         }
1381 #endif
1382         /* sample option */
1383
1384         /* XXX 2.48 */
1385 #if 0
1386         if(cumap->flag & CUMA_DRAW_SAMPLE) {
1387                 if(cumap->cur==3) {
1388                         float lum= cumap->sample[0]*0.35f + cumap->sample[1]*0.45f + cumap->sample[2]*0.2f;
1389                         glColor3ub(240, 240, 240);
1390                         
1391                         glBegin(GL_LINES);
1392                         glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymin);
1393                         glVertex2f(rect->xmin + zoomx*(lum-offsx), rect->ymax);
1394                         glEnd();
1395                 }
1396                 else {
1397                         if(cumap->cur==0)
1398                                 glColor3ub(240, 100, 100);
1399                         else if(cumap->cur==1)
1400                                 glColor3ub(100, 240, 100);
1401                         else
1402                                 glColor3ub(100, 100, 240);
1403                         
1404                         glBegin(GL_LINES);
1405                         glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymin);
1406                         glVertex2f(rect->xmin + zoomx*(cumap->sample[cumap->cur]-offsx), rect->ymax);
1407                         glEnd();
1408                 }
1409         }
1410 #endif
1411
1412         /* the curve */
1413         glColor3ubv((unsigned char*)wcol->item);
1414         glEnable(GL_LINE_SMOOTH);
1415         glEnable(GL_BLEND);
1416         glBegin(GL_LINE_STRIP);
1417         
1418         if(cuma->table==NULL)
1419                 curvemapping_changed(cumap, 0); /* 0 = no remove doubles */
1420         cmp= cuma->table;
1421         
1422         /* first point */
1423         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1424                 glVertex2f(rect->xmin, rect->ymin + zoomy*(cmp[0].y-offsy));
1425         else {
1426                 fx= rect->xmin + zoomx*(cmp[0].x-offsx + cuma->ext_in[0]);
1427                 fy= rect->ymin + zoomy*(cmp[0].y-offsy + cuma->ext_in[1]);
1428                 glVertex2f(fx, fy);
1429         }
1430         for(a=0; a<=CM_TABLE; a++) {
1431                 fx= rect->xmin + zoomx*(cmp[a].x-offsx);
1432                 fy= rect->ymin + zoomy*(cmp[a].y-offsy);
1433                 glVertex2f(fx, fy);
1434         }
1435         /* last point */
1436         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
1437                 glVertex2f(rect->xmax, rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy));     
1438         else {
1439                 fx= rect->xmin + zoomx*(cmp[CM_TABLE].x-offsx - cuma->ext_out[0]);
1440                 fy= rect->ymin + zoomy*(cmp[CM_TABLE].y-offsy - cuma->ext_out[1]);
1441                 glVertex2f(fx, fy);
1442         }
1443         glEnd();
1444         glDisable(GL_LINE_SMOOTH);
1445         glDisable(GL_BLEND);
1446
1447         /* the points, use aspect to make them visible on edges */
1448         cmp= cuma->curve;
1449         glPointSize(3.0f);
1450         bglBegin(GL_POINTS);
1451         for(a=0; a<cuma->totpoint; a++) {
1452                 if(cmp[a].flag & SELECT)
1453                         UI_ThemeColor(TH_TEXT_HI);
1454                 else
1455                         UI_ThemeColor(TH_TEXT);
1456                 fac[0]= rect->xmin + zoomx*(cmp[a].x-offsx);
1457                 fac[1]= rect->ymin + zoomy*(cmp[a].y-offsy);
1458                 bglVertex2fv(fac);
1459         }
1460         bglEnd();
1461         glPointSize(1.0f);
1462         
1463         /* restore scissortest */
1464         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
1465
1466         /* outline */
1467         glColor3ubv((unsigned char*)wcol->outline);
1468         fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
1469 }
1470
1471 static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float track_pos[2], int width, float height, int margin)
1472 {
1473         ImBuf *scaleibuf;
1474         const float scalex= ((float)ibuf->x-2*margin) / width;
1475         const float scaley= ((float)ibuf->y-2*margin) / height;
1476         float off_x= (int)track_pos[0]-track_pos[0]+0.5f;
1477         float off_y= (int)track_pos[1]-track_pos[1]+0.5f;
1478         int x, y;
1479
1480         scaleibuf= IMB_allocImBuf(width, height, 32, IB_rect);
1481
1482         for(y= 0; y<height; y++) {
1483                 for (x= 0; x<width; x++) {
1484                         float src_x= scalex*(x)+margin-off_x;
1485                         float src_y= scaley*(y)+margin-off_y;
1486
1487                         bicubic_interpolation(ibuf, scaleibuf, src_x, src_y, x, y);
1488                 }
1489         }
1490
1491         return scaleibuf;
1492 }
1493
1494 void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
1495 {
1496         rctf rect;
1497         int ok= 0;
1498         GLint scissor[4];
1499         MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
1500
1501         rect.xmin = (float)recti->xmin+1;
1502         rect.xmax = (float)recti->xmax-1;
1503         rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
1504         rect.ymax = (float)recti->ymax-1;
1505
1506         glEnable(GL_BLEND);
1507         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1508
1509         /* need scissor test, preview image can draw outside of boundary */
1510         glGetIntegerv(GL_VIEWPORT, scissor);
1511         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));
1512
1513         if(scopes->track_disabled) {
1514                 glColor4f(0.7f, 0.3f, 0.3f, 0.3f);
1515                 uiSetRoundBox(15);
1516                 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin, rect.xmax+1, rect.ymax+1, 3.0f);
1517
1518                 ok= 1;
1519         }
1520         else if(scopes->track_preview) {
1521                 /* additional margin around image */
1522                 /* NOTE: should be kept in sync with value from BKE_movieclip_update_scopes */
1523                 const int margin= 3;
1524                 float zoomx, zoomy, track_pos[2], off_x, off_y;
1525                 int a, width, height;
1526                 ImBuf *drawibuf;
1527
1528                 glPushMatrix();
1529
1530                 track_pos[0]= scopes->track_pos[0]-margin;
1531                 track_pos[1]= scopes->track_pos[1]-margin;
1532
1533                 /* draw content of pattern area */
1534                 glScissor(ar->winrct.xmin+rect.xmin, ar->winrct.ymin+rect.ymin, scissor[2], scissor[3]);
1535
1536                 width= rect.xmax-rect.xmin+1;
1537                 height = rect.ymax-rect.ymin;
1538
1539                 if(width > 0 && height > 0) {
1540                         zoomx= (float)width / (scopes->track_preview->x-2*margin);
1541                         zoomy= (float)height / (scopes->track_preview->y-2*margin);
1542
1543                         off_x= ((int)track_pos[0]-track_pos[0]+0.5f)*zoomx;
1544                         off_y= ((int)track_pos[1]-track_pos[1]+0.5f)*zoomy;
1545
1546                         drawibuf= scale_trackpreview_ibuf(scopes->track_preview, track_pos, width, height, margin);
1547
1548                         glaDrawPixelsSafe(rect.xmin, rect.ymin+1, drawibuf->x, drawibuf->y,
1549                                           drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
1550                         IMB_freeImBuf(drawibuf);
1551
1552                         /* draw cross for pizel position */
1553                         glTranslatef(off_x+rect.xmin+track_pos[0]*zoomx, off_y+rect.ymin+track_pos[1]*zoomy, 0.f);
1554                         glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin+rect.ymin, rect.xmax-rect.xmin, rect.ymax-rect.ymin);
1555
1556                         for(a= 0; a< 2; a++) {
1557                                 if(a==1) {
1558                                         glLineStipple(3, 0xaaaa);
1559                                         glEnable(GL_LINE_STIPPLE);
1560                                         UI_ThemeColor(TH_SEL_MARKER);
1561                                 }
1562                                 else {
1563                                         UI_ThemeColor(TH_MARKER_OUTLINE);
1564                                 }
1565
1566                                 glBegin(GL_LINES);
1567                                         glVertex2f(-10.0f, 0.0f);
1568                                         glVertex2f(10.0f, 0.0f);
1569                                         glVertex2f(0.0f, -10.0f);
1570                                         glVertex2f(0.0f, 10.0f);
1571                                         glEnd();
1572                         }
1573                 }
1574
1575                 glDisable(GL_LINE_STIPPLE);
1576                 glPopMatrix();
1577
1578                 ok= 1;
1579         }
1580
1581         if(!ok) {
1582                 glColor4f(0.f, 0.f, 0.f, 0.3f);
1583                 uiSetRoundBox(15);
1584                 uiDrawBox(GL_POLYGON, rect.xmin-1, rect.ymin, rect.xmax+1, rect.ymax+1, 3.0f);
1585         }
1586
1587         /* outline, scale gripper */
1588         draw_scope_end(&rect, scissor);
1589
1590         glDisable(GL_BLEND);
1591 }
1592
1593 /* ****************************************************** */
1594
1595
1596 static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
1597 {
1598         glEnable(GL_BLEND);
1599         glShadeModel(GL_SMOOTH);
1600         
1601         /* right quad */
1602         glBegin(GL_POLYGON);
1603         glColor4ub(0, 0, 0, alpha);
1604         glVertex2f(maxx, miny);
1605         glVertex2f(maxx, maxy-0.3f*shadsize);
1606         glColor4ub(0, 0, 0, 0);
1607         glVertex2f(maxx+shadsize, maxy-0.75f*shadsize);
1608         glVertex2f(maxx+shadsize, miny);
1609         glEnd();
1610         
1611         /* corner shape */
1612         glBegin(GL_POLYGON);
1613         glColor4ub(0, 0, 0, alpha);
1614         glVertex2f(maxx, miny);
1615         glColor4ub(0, 0, 0, 0);
1616         glVertex2f(maxx+shadsize, miny);
1617         glVertex2f(maxx+0.7f*shadsize, miny-0.7f*shadsize);
1618         glVertex2f(maxx, miny-shadsize);
1619         glEnd();
1620         
1621         /* bottom quad */               
1622         glBegin(GL_POLYGON);
1623         glColor4ub(0, 0, 0, alpha);
1624         glVertex2f(minx+0.3f*shadsize, miny);
1625         glVertex2f(maxx, miny);
1626         glColor4ub(0, 0, 0, 0);
1627         glVertex2f(maxx, miny-shadsize);
1628         glVertex2f(minx+0.5f*shadsize, miny-shadsize);
1629         glEnd();
1630         
1631         glDisable(GL_BLEND);
1632         glShadeModel(GL_FLAT);
1633 }
1634
1635 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
1636 {
1637         /* accumulated outline boxes to make shade not linear, is more pleasant */
1638         ui_shadowbox(minx, miny, maxx, maxy, 11.0, (20*alpha)>>8);
1639         ui_shadowbox(minx, miny, maxx, maxy, 7.0, (40*alpha)>>8);
1640         ui_shadowbox(minx, miny, maxx, maxy, 5.0, (80*alpha)>>8);
1641         
1642 }
1643
1644
1645 void ui_dropshadow(rctf *rct, float radius, float aspect, int UNUSED(select))
1646 {
1647         int i;
1648         float rad;
1649         float a;
1650         char alpha= 2;
1651         
1652         glEnable(GL_BLEND);
1653         
1654         if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f)
1655                 rad= (rct->ymax-rct->ymin-10.0f)/2.0f;
1656         else
1657                 rad= radius;
1658
1659         i= 12;
1660 #if 0
1661         if(select) {
1662                 a= i*aspect; /* same as below */
1663         }
1664         else
1665 #endif
1666         {
1667                 a= i*aspect;
1668         }
1669
1670         for(; i--; a-=aspect) {
1671                 /* alpha ranges from 2 to 20 or so */
1672                 glColor4ub(0, 0, 0, alpha);
1673                 alpha+= 2;
1674                 
1675                 uiDrawBox(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a);
1676         }
1677         
1678         /* outline emphasis */
1679         glEnable( GL_LINE_SMOOTH );
1680         glColor4ub(0, 0, 0, 100);
1681         uiDrawBox(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius+0.5f);
1682         glDisable( GL_LINE_SMOOTH );
1683         
1684         glDisable(GL_BLEND);
1685 }
1686