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