Changed frame numbering to only alter hashes if they are in the filename (not the...
[blender-staging.git] / source / blender / src / interface_draw.c
1
2 /**
3  * $Id$
4  *
5  * ***** BEGIN GPL LICENSE BLOCK *****
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  *
21  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22  * All rights reserved.
23  *
24  * The Original Code is: all of this file.
25  *
26  * Contributor(s): none yet.
27  *
28  * ***** END GPL LICENSE BLOCK *****
29  */
30
31 /* 
32      a full doc with API notes can be found in bf-blender/blender/doc/interface_API.txt
33
34  */
35  
36
37 #include <math.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <ctype.h>
41
42 #ifndef WIN32
43 #include <unistd.h>
44 #else
45 #include <io.h>
46 #endif   
47
48 #include "MEM_guardedalloc.h"
49
50 #include "PIL_time.h"
51
52 #include "BLI_blenlib.h"
53 #include "BLI_arithb.h"
54
55 #include "DNA_color_types.h"
56 #include "DNA_key_types.h"
57 #include "DNA_packedFile_types.h"
58 #include "DNA_screen_types.h"
59 #include "DNA_space_types.h"
60 #include "DNA_texture_types.h"
61 #include "DNA_userdef_types.h"
62 #include "DNA_vec_types.h"
63 #include "DNA_vfont_types.h"
64
65 #include "BKE_blender.h"
66 #include "BKE_colortools.h"
67 #include "BKE_font.h"
68 #include "BKE_global.h"
69 #include "BKE_key.h"
70 #include "BKE_utildefines.h"
71
72 #include "datatoc.h"            /* std font */
73
74 #include "BIF_gl.h"
75 #include "BIF_graphics.h"
76 #include "BIF_keyval.h"
77 #include "BIF_mainqueue.h"
78
79 #include "BIF_screen.h"
80 #include "BIF_toolbox.h"
81 #include "BIF_mywindow.h"
82 #include "BIF_space.h"
83 #include "BIF_glutil.h"
84 #include "BIF_interface.h"
85 #include "BIF_interface_icons.h"
86 #include "BIF_butspace.h"
87 #include "BIF_language.h"
88
89 #include "BSE_view.h"
90
91 #ifdef INTERNATIONAL
92 #include "FTF_Api.h"
93 #endif
94
95 #include "mydevice.h"
96 #include "interface.h"
97 #include "blendef.h"
98
99 // globals
100 extern float UIwinmat[4][4];
101
102
103 /* ************** safe rasterpos for pixmap alignment with pixels ************* */
104
105 void ui_rasterpos_safe(float x, float y, float aspect)
106 {
107         float vals[4], remainder;
108         int doit=0;
109         
110         glRasterPos2f(x, y);
111         glGetFloatv(GL_CURRENT_RASTER_POSITION, vals);
112
113         remainder= vals[0] - floor(vals[0]);
114         if(remainder > 0.4 && remainder < 0.6) {
115                 if(remainder < 0.5) x -= 0.1*aspect;
116                 else x += 0.1*aspect;
117                 doit= 1;
118         }
119         remainder= vals[1] - floor(vals[1]);
120         if(remainder > 0.4 && remainder < 0.6) {
121                 if(remainder < 0.5) y -= 0.1*aspect;
122                 else y += 0.1*aspect;
123                 doit= 1;
124         }
125         
126         if(doit) glRasterPos2f(x, y);
127
128         BIF_RasterPos(x, y);
129         BIF_SetScale(aspect);
130 }
131
132 /* ************** generic embossed rect, for window sliders etc ************* */
133
134 void uiEmboss(float x1, float y1, float x2, float y2, int sel)
135 {
136         
137         /* below */
138         if(sel) glColor3ub(200,200,200);
139         else glColor3ub(50,50,50);
140         fdrawline(x1, y1, x2, y1);
141
142         /* right */
143         fdrawline(x2, y1, x2, y2);
144         
145         /* top */
146         if(sel) glColor3ub(50,50,50);
147         else glColor3ub(200,200,200);
148         fdrawline(x1, y2, x2, y2);
149
150         /* left */
151         fdrawline(x1, y1, x1, y2);
152         
153 }
154
155 /* ************** GENERIC ICON DRAW, NO THEME HERE ************* */
156
157 /* icons have been standardized... and this call draws in untransformed coordinates */
158 #define ICON_HEIGHT             16.0f
159
160 static void ui_draw_icon(uiBut *but, BIFIconID icon, int blend)
161 {
162         float xs=0, ys=0, aspect, height;
163
164         /* this icon doesn't need draw... */
165         if(icon==ICON_BLANK1) return;
166         
167         /* we need aspect from block, for menus... these buttons are scaled in uiPositionBlock() */
168         aspect= but->block->aspect;
169         if(aspect != but->aspect) {
170                 /* prevent scaling up icon in pupmenu */
171                 if (aspect < 1.0f) {                    
172                         height= ICON_HEIGHT;
173                         aspect = 1.0f;
174                         
175                 }
176                 else 
177                         height= ICON_HEIGHT/aspect;
178         }
179         else
180                 height= ICON_HEIGHT;
181         
182         if(but->flag & UI_ICON_LEFT) {
183                 if (but->type==BUT_TOGDUAL && but->drawstr[0]) {
184                         xs= but->x1-1.0;
185                 }
186                 else if (but->type==BUTM ) {
187                         xs= but->x1+1.0;
188                 }
189                 else if ((but->type==ICONROW) || (but->type==ICONTEXTROW)) {
190                         xs= but->x1+3.0;
191                 }
192                 else {
193                         xs= but->x1+4.0;
194                 }
195                 ys= (but->y1+but->y2- height)/2.0;
196         }
197         if(but->flag & UI_ICON_RIGHT) {
198                 xs= but->x2-17.0;
199                 ys= (but->y1+but->y2- height)/2.0;
200         }
201         if (!((but->flag & UI_ICON_RIGHT) || (but->flag & UI_ICON_LEFT))) {
202                 xs= (but->x1+but->x2- height)/2.0;
203                 ys= (but->y1+but->y2- height)/2.0;
204         }
205
206         glEnable(GL_BLEND);
207
208         /* calculate blend color */
209         if ELEM3(but->type, TOG, ROW, TOGN) {
210                 if(but->flag & UI_SELECT);
211                 else if(but->flag & UI_ACTIVE);
212                 else blend= -60;
213         }
214         BIF_icon_draw_aspect_blended(xs, ys, icon, aspect, blend);
215         
216         glDisable(GL_BLEND);
217
218 }
219
220
221 /* ************** DEFAULT THEME, SHADED BUTTONS ************* */
222
223
224 #define M_WHITE         BIF_ThemeColorShade(colorid, 80)
225
226 #define M_ACT_LIGHT     BIF_ThemeColorShade(colorid, 55)
227 #define M_LIGHT         BIF_ThemeColorShade(colorid, 45)
228 #define M_HILITE        BIF_ThemeColorShade(colorid, 25)
229 #define M_LMEDIUM       BIF_ThemeColorShade(colorid, 10)
230 #define M_MEDIUM        BIF_ThemeColor(colorid)
231 #define M_LGREY         BIF_ThemeColorShade(colorid, -20)
232 #define M_GREY          BIF_ThemeColorShade(colorid, -45)
233 #define M_DARK          BIF_ThemeColorShade(colorid, -80)
234
235 #define M_NUMTEXT                               BIF_ThemeColorShade(colorid, 25)
236 #define M_NUMTEXT_ACT_LIGHT             BIF_ThemeColorShade(colorid, 35)
237
238 #define MM_WHITE        BIF_ThemeColorShade(TH_BUT_NEUTRAL, 120)
239
240 /* Used for the subtle sunken effect around buttons.
241  * One option is to hardcode to white, with alpha, however it causes a 
242  * weird 'building up' efect, so it's commented out for now.
243  */
244  
245 /*
246 #define MM_WHITE_OP     glColor4ub(255, 255, 255, 60)
247 #define MM_WHITE_TR     glColor4ub(255, 255, 255, 0)
248  */
249
250 #define MM_WHITE_OP     BIF_ThemeColorShadeAlpha(TH_BACK, 55, -100)
251 #define MM_WHITE_TR     BIF_ThemeColorShadeAlpha(TH_BACK, 55, -255)
252
253 #define MM_LIGHT        BIF_ThemeColorShade(TH_BUT_OUTLINE, 45)
254 #define MM_MEDIUM       BIF_ThemeColor(TH_BUT_OUTLINE)
255 #define MM_GREY         BIF_ThemeColorShade(TH_BUT_OUTLINE, -45)
256 #define MM_DARK         BIF_ThemeColorShade(TH_BUT_OUTLINE, -80)
257
258 /* base shaded button */
259 static void shaded_button(float x1, float y1, float x2, float y2, float asp, int colorid, int flag, int mid)
260 {
261         /* 'mid' arg determines whether the button is in the middle of
262          * an alignment group or not. 0 = not middle, 1 = is in the middle.
263          * Done to allow cleaner drawing
264          */
265          
266         /* *** SHADED BUTTON BASE *** */
267         glShadeModel(GL_SMOOTH);
268         glBegin(GL_QUADS);
269         
270         if(flag & UI_SELECT) {
271                 if(flag & UI_ACTIVE) M_MEDIUM;
272                 else M_LGREY;
273         } else {
274                 if(flag & UI_ACTIVE) M_LIGHT;
275                 else M_HILITE;
276         }
277
278         glVertex2f(x1,y1);
279         glVertex2f(x2,y1);
280
281         if(flag & UI_SELECT) {
282                 if(flag & UI_ACTIVE) M_LGREY;
283                 else M_GREY;
284         } else {
285                 if(flag & UI_ACTIVE) M_ACT_LIGHT;
286                 else M_LIGHT;
287         }
288
289         glVertex2f(x2,(y2-(y2-y1)/3));
290         glVertex2f(x1,(y2-(y2-y1)/3));
291         glEnd();
292         
293
294         glShadeModel(GL_FLAT);
295         glBegin(GL_QUADS);
296         
297         if(flag & UI_SELECT) {
298                 if(flag & UI_ACTIVE) M_LGREY;
299                 else M_GREY;
300         } else {
301                 if(flag & UI_ACTIVE) M_ACT_LIGHT;
302                 else M_LIGHT;
303         }
304         
305         glVertex2f(x1,(y2-(y2-y1)/3));
306         glVertex2f(x2,(y2-(y2-y1)/3));
307         glVertex2f(x2,y2);
308         glVertex2f(x1,y2);
309
310         glEnd();
311         /* *** END SHADED BUTTON BASE *** */
312         
313         /* *** INNER OUTLINE *** */
314         /* left */
315         if(!(flag & UI_SELECT)) {
316                 glShadeModel(GL_SMOOTH);
317                 glBegin(GL_LINES);
318                 M_MEDIUM;
319                 glVertex2f(x1+1,y1+2);
320                 M_WHITE;
321                 glVertex2f(x1+1,y2);
322                 glEnd();
323         }
324         
325         /* right */
326                 if(!(flag & UI_SELECT)) {
327                 glShadeModel(GL_SMOOTH);
328                 glBegin(GL_LINES);
329                 M_MEDIUM;
330                 glVertex2f(x2-1,y1+2);
331                 M_WHITE;
332                 glVertex2f(x2-1,y2);
333                 glEnd();
334         }
335         
336         glShadeModel(GL_FLAT);
337         
338         /* top */
339         if(flag & UI_SELECT) {
340                 if(flag & UI_ACTIVE) M_LGREY;
341                 else M_GREY;
342         } else {
343                 if(flag & UI_ACTIVE) M_WHITE;
344                 else M_WHITE;
345         }
346
347         fdrawline(x1, (y2-1), x2, (y2-1));
348         
349         /* bottom */
350         if(flag & UI_SELECT) {
351                 if(flag & UI_ACTIVE) M_MEDIUM;
352                 else M_LGREY;
353         } else {
354                 if(flag & UI_ACTIVE) M_LMEDIUM;
355                 else M_MEDIUM;
356         }
357         fdrawline(x1, (y1+1), x2, (y1+1));
358         /* *** END INNER OUTLINE *** */
359         
360         /* *** OUTER OUTLINE *** */
361         if (mid) {
362                 // we draw full outline, its not AA, and it works better button mouse-over hilite
363                 MM_DARK;
364                 
365                 // left right
366                 fdrawline(x1, y1, x1, y2);
367                 fdrawline(x2, y1, x2, y2);
368         
369                 // top down
370                 fdrawline(x1, y2, x2, y2);
371                 fdrawline(x1, y1, x2, y1); 
372         } else {
373                 MM_DARK;
374                 gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, 1.5);
375         }
376         /* END OUTER OUTLINE */
377 }
378
379 /* base flat button */
380 static void flat_button(float x1, float y1, float x2, float y2, float asp, int colorid, int flag, int mid)
381 {
382         /* 'mid' arg determines whether the button is in the middle of
383          * an alignment group or not. 0 = not middle, 1 = is in the middle.
384          * Done to allow cleaner drawing
385          */
386          
387         /* *** FLAT TEXT/NUM FIELD *** */
388         glShadeModel(GL_FLAT);
389         if(flag & UI_SELECT) {
390                 if(flag & UI_ACTIVE) M_LGREY;
391                 else M_GREY;
392         }
393         else {
394                 if(flag & UI_ACTIVE) M_NUMTEXT_ACT_LIGHT;
395                 else M_NUMTEXT;
396         }
397
398         glRectf(x1, y1, x2, y2);
399         /* *** END FLAT TEXT/NUM FIELD *** */
400         
401         /* *** OUTER OUTLINE *** */
402         if (mid) {
403                 // we draw full outline, its not AA, and it works better button mouse-over hilite
404                 MM_DARK;
405                 
406                 // left right
407                 fdrawline(x1, y1, x1, y2);
408                 fdrawline(x2, y1, x2, y2);
409         
410                 // top down
411                 fdrawline(x1, y2, x2, y2);
412                 fdrawline(x1, y1, x2, y1); 
413         } else {
414                 MM_DARK;
415                 gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, 1.5);
416         }
417         /* END OUTER OUTLINE */
418 }
419
420 /* small side double arrow for iconrow */
421 static void ui_default_iconrow_arrows(float x1, float y1, float x2, float y2)
422 {
423         glEnable( GL_POLYGON_SMOOTH );
424         glEnable( GL_BLEND );
425         
426         glShadeModel(GL_FLAT);
427         glBegin(GL_TRIANGLES);
428         glVertex2f((short)x2-2,(short)(y2-(y2-y1)/2)+1);
429         glVertex2f((short)x2-6,(short)(y2-(y2-y1)/2)+1);
430         glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2)+4);
431         glEnd();
432                 
433         glBegin(GL_TRIANGLES);
434         glVertex2f((short)x2-2,(short)(y2-(y2-y1)/2) -1);
435         glVertex2f((short)x2-6,(short)(y2-(y2-y1)/2) -1);
436         glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2) -4);
437         glEnd();
438         
439         glDisable( GL_BLEND );
440         glDisable( GL_POLYGON_SMOOTH );
441 }
442
443 /* side double arrow for menu */
444 static void ui_default_menu_arrows(float x1, float y1, float x2, float y2)
445 {
446         glEnable( GL_POLYGON_SMOOTH );
447         glEnable( GL_BLEND );
448         
449         glShadeModel(GL_FLAT);
450         glBegin(GL_TRIANGLES);
451         glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2)+1);
452         glVertex2f((short)x2-12,(short)(y2-(y2-y1)/2)+1);
453         glVertex2f((short)x2-8,(short)(y2-(y2-y1)/2)+4);
454         glEnd();
455                 
456         glBegin(GL_TRIANGLES);
457         glVertex2f((short)x2-4,(short)(y2-(y2-y1)/2) -1);
458         glVertex2f((short)x2-12,(short)(y2-(y2-y1)/2) -1);
459         glVertex2f((short)x2-8,(short)(y2-(y2-y1)/2) -4);
460         glEnd();
461         
462         glDisable( GL_BLEND );
463         glDisable( GL_POLYGON_SMOOTH );
464 }
465
466 /* left/right arrows for number fields */
467 static void ui_default_num_arrows(float x1, float y1, float x2, float y2)
468 {
469         if( x2-x1 > 25) {       // 25 is a bit arbitrary, but small buttons cant have arrows
470
471                 glEnable( GL_POLYGON_SMOOTH );
472                 glEnable( GL_BLEND );
473                 
474                 glShadeModel(GL_FLAT);
475                 glBegin(GL_TRIANGLES);
476                 
477                 glVertex2f((short)x1+5,(short)(y2-(y2-y1)/2));
478                 glVertex2f((short)x1+10,(short)(y2-(y2-y1)/2)+4);
479                 glVertex2f((short)x1+10,(short)(y2-(y2-y1)/2)-4);
480                 glEnd();
481
482                 /* right */
483                 glShadeModel(GL_FLAT);
484                 glBegin(GL_TRIANGLES);
485
486                 glVertex2f((short)x2-5,(short)(y2-(y2-y1)/2));
487                 glVertex2f((short)x2-10,(short)(y2-(y2-y1)/2)-4);
488                 glVertex2f((short)x2-10,(short)(y2-(y2-y1)/2)+4);
489                 glEnd();
490                 
491                 glDisable( GL_BLEND );
492                 glDisable( GL_POLYGON_SMOOTH );
493         }
494 }
495
496 /* changing black/white for TOG3 buts */
497 static void ui_tog3_invert(float x1, float y1, float x2, float y2, int seltype)
498 {
499         short alpha = 30;
500         
501         if (seltype == 0) {
502                 glEnable(GL_BLEND);
503                 
504                 glColor4ub(0, 0, 0, alpha);
505                 glRectf(x2-6, y1, x2, (y1+(y2-y1)/2));
506                 
507                 glColor4ub(255, 255, 255, alpha);
508                 glRectf(x2-6, (y1+(y2-y1)/2), x2, y2);
509                 
510                 glDisable(GL_BLEND);
511         } else {
512                 glEnable(GL_BLEND);
513                 
514                 glColor4ub(255, 255, 255, alpha);
515                 glRectf(x2-6, y1, x2, (y1+(y2-y1)/2));
516                 
517                 glColor4ub(0, 0, 0, alpha);
518                 glRectf(x2-6, (y1+(y2-y1)/2), x2, y2);
519                 
520                 glDisable(GL_BLEND);
521         }
522 }
523
524 /* button/popup menu/iconrow drawing code */
525 static void ui_default_button(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
526 {
527         int align= (flag & UI_BUT_ALIGN);
528
529         if(align) {
530         
531                 /* *** BOTTOM OUTER SUNKEN EFFECT *** */
532                 if (!((align == UI_BUT_ALIGN_DOWN) ||
533                         (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT)) ||
534                         (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT)))) {
535                         glEnable(GL_BLEND);
536                         MM_WHITE_OP;
537                         fdrawline(x1, y1-1, x2, y1-1);  
538                         glDisable(GL_BLEND);
539                 }
540                 /* *** END BOTTOM OUTER SUNKEN EFFECT *** */
541                 
542                 switch(align) {
543                 case UI_BUT_ALIGN_TOP:
544                         uiSetRoundBox(12);
545                         
546                         /* last arg in shaded_button() determines whether the button is in the middle of
547                          * an alignment group or not. 0 = not middle, 1 = is in the middle.
548                          * Done to allow cleaner drawing
549                          */
550                          
551                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
552                         break;
553                 case UI_BUT_ALIGN_DOWN:
554                         uiSetRoundBox(3);
555                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
556                         break;
557                 case UI_BUT_ALIGN_LEFT:
558                         
559                         /* RIGHT OUTER SUNKEN EFFECT */
560                         glEnable(GL_BLEND);
561                         glShadeModel(GL_SMOOTH);
562                         glBegin(GL_LINES);
563                         MM_WHITE_OP;
564                         glVertex2f(x2+1,y1);
565                         MM_WHITE_TR;
566                         glVertex2f(x2+1,y2);
567                         glEnd();
568                         glDisable(GL_BLEND);
569                         
570                         uiSetRoundBox(6);
571                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
572                         break;
573                 case UI_BUT_ALIGN_RIGHT:
574                 
575                         /* LEFT OUTER SUNKEN EFFECT */
576                         glEnable(GL_BLEND);
577                         glShadeModel(GL_SMOOTH);
578                         glBegin(GL_LINES);
579                         MM_WHITE_OP;
580                         glVertex2f(x1-1,y1);
581                         MM_WHITE_TR;
582                         glVertex2f(x1-1,y2);
583                         glEnd();
584                         glDisable(GL_BLEND);
585                 
586                         uiSetRoundBox(9);
587                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
588                         break;
589                         
590                 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT:
591                         uiSetRoundBox(1);
592                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
593                         break;
594                 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT:
595                         uiSetRoundBox(2);
596                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
597                         break;
598                 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
599                 
600                         /* LEFT OUTER SUNKEN EFFECT */
601                         glEnable(GL_BLEND);
602                         glShadeModel(GL_SMOOTH);
603                         glBegin(GL_LINES);
604                         MM_WHITE_OP;
605                         glVertex2f(x1-1,y1);
606                         MM_WHITE_TR;
607                         glVertex2f(x1-1,y2);
608                         glEnd();
609                         glDisable(GL_BLEND);
610                 
611                         uiSetRoundBox(8);
612                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
613                         break;
614                 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
615                 
616                         /* RIGHT OUTER SUNKEN EFFECT */
617                         glEnable(GL_BLEND);
618                         glShadeModel(GL_SMOOTH);
619                         glBegin(GL_LINES);
620                         MM_WHITE_OP;
621                         glVertex2f(x2+1,y1);
622                         MM_WHITE_TR;
623                         glVertex2f(x2+1,y2);
624                         glEnd();
625                         glDisable(GL_BLEND);
626                         
627                         uiSetRoundBox(4);
628                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
629                         break;
630                         
631                 default:
632                         shaded_button(x1, y1, x2, y2, asp, colorid, flag, 1);
633                         break;
634                 }
635         } 
636         else {  
637                 glEnable(GL_BLEND);
638                 glShadeModel(GL_SMOOTH);
639                 
640                 /* BOTTOM OUTER SUNKEN EFFECT */
641                 MM_WHITE_OP;
642                 fdrawline(x1, y1-1, x2, y1-1);  
643                 
644                 /* LEFT OUTER SUNKEN EFFECT */
645                 glBegin(GL_LINES);
646                 MM_WHITE_OP;
647                 glVertex2f(x1-1,y1);
648                 MM_WHITE_TR;
649                 glVertex2f(x1-1,y2);
650                 glEnd();
651                 
652                 /* RIGHT OUTER SUNKEN EFFECT */
653                 glBegin(GL_LINES);
654                 MM_WHITE_OP;
655                 glVertex2f(x2+1,y1);
656                 MM_WHITE_TR;
657                 glVertex2f(x2+1,y2);
658                 glEnd();
659                 
660                 glDisable(GL_BLEND);
661         
662                 uiSetRoundBox(15);
663                 shaded_button(x1, y1, x2, y2, asp, colorid, flag, 0);
664         }
665         
666         /* *** EXTRA DRAWING FOR SPECIFIC CONTROL TYPES *** */
667         switch(type) {
668         case ICONROW:
669         case ICONTEXTROW:
670                 /* DARKENED AREA */
671                 glEnable(GL_BLEND);
672                 
673                 glColor4ub(0, 0, 0, 30);
674                 glRectf(x2-9, y1, x2, y2);
675         
676                 glDisable(GL_BLEND);
677                 /* END DARKENED AREA */
678         
679                 /* ICONROW DOUBLE-ARROW  */
680                 M_DARK;
681                 ui_default_iconrow_arrows(x1, y1, x2, y2);
682                 /* END ICONROW DOUBLE-ARROW */
683                 break;
684         case MENU:
685                 /* DARKENED AREA */
686                 glEnable(GL_BLEND);
687                 
688                 glColor4ub(0, 0, 0, 30);
689                 glRectf(x2-18, y1, x2, y2);
690         
691                 glDisable(GL_BLEND);
692                 /* END DARKENED AREA */
693         
694                 /* MENU DOUBLE-ARROW  */
695                 M_DARK;
696                 ui_default_menu_arrows(x1, y1, x2, y2);
697                 /* MENU DOUBLE-ARROW */
698                 break;
699         }       
700 }
701
702
703 /* number/text field drawing code */
704 static void ui_default_flat(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
705 {
706         int align= (flag & UI_BUT_ALIGN);
707
708         if(align) {
709         
710                 /* *** BOTTOM OUTER SUNKEN EFFECT *** */
711                 if (!((align == UI_BUT_ALIGN_DOWN) ||
712                         (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT)) ||
713                         (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT)))) {
714                         glEnable(GL_BLEND);
715                         MM_WHITE_OP;
716                         fdrawline(x1, y1-1, x2, y1-1);  
717                         glDisable(GL_BLEND);
718                 }
719                 /* *** END BOTTOM OUTER SUNKEN EFFECT *** */
720                 
721                 switch(align) {
722                 case UI_BUT_ALIGN_TOP:
723                         uiSetRoundBox(12);
724                         
725                         /* last arg in shaded_button() determines whether the button is in the middle of
726                          * an alignment group or not. 0 = not middle, 1 = is in the middle.
727                          * Done to allow cleaner drawing
728                          */
729                          
730                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
731                         break;
732                 case UI_BUT_ALIGN_DOWN:
733                         uiSetRoundBox(3);
734                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
735                         break;
736                 case UI_BUT_ALIGN_LEFT:
737                         
738                         /* RIGHT OUTER SUNKEN EFFECT */
739                         glEnable(GL_BLEND);
740                         glShadeModel(GL_SMOOTH);
741                         glBegin(GL_LINES);
742                         MM_WHITE_OP;
743                         glVertex2f(x2+1,y1);
744                         MM_WHITE_TR;
745                         glVertex2f(x2+1,y2);
746                         glEnd();
747                         glDisable(GL_BLEND);
748                         
749                         uiSetRoundBox(6);
750                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
751                         break;
752                 case UI_BUT_ALIGN_RIGHT:
753                 
754                         /* LEFT OUTER SUNKEN EFFECT */
755                         glEnable(GL_BLEND);
756                         glShadeModel(GL_SMOOTH);
757                         glBegin(GL_LINES);
758                         MM_WHITE_OP;
759                         glVertex2f(x1-1,y1);
760                         MM_WHITE_TR;
761                         glVertex2f(x1-1,y2);
762                         glEnd();
763                         glDisable(GL_BLEND);
764                 
765                         uiSetRoundBox(9);
766                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
767                         break;
768                         
769                 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT:
770                         uiSetRoundBox(1);
771                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
772                         break;
773                 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT:
774                         uiSetRoundBox(2);
775                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
776                         break;
777                 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
778                 
779                         /* LEFT OUTER SUNKEN EFFECT */
780                         glEnable(GL_BLEND);
781                         glShadeModel(GL_SMOOTH);
782                         glBegin(GL_LINES);
783                         MM_WHITE_OP;
784                         glVertex2f(x1-1,y1);
785                         MM_WHITE_TR;
786                         glVertex2f(x1-1,y2);
787                         glEnd();
788                         glDisable(GL_BLEND);
789                 
790                         uiSetRoundBox(8);
791                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
792                         break;
793                 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
794                 
795                         /* RIGHT OUTER SUNKEN EFFECT */
796                         glEnable(GL_BLEND);
797                         glShadeModel(GL_SMOOTH);
798                         glBegin(GL_LINES);
799                         MM_WHITE_OP;
800                         glVertex2f(x2+1,y1);
801                         MM_WHITE_TR;
802                         glVertex2f(x2+1,y2);
803                         glEnd();
804                         glDisable(GL_BLEND);
805                         
806                         uiSetRoundBox(4);
807                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
808                         break;
809                         
810                 default:
811                         flat_button(x1, y1, x2, y2, asp, colorid, flag, 1);
812                         break;
813                 }
814         } 
815         else {
816         
817                 glEnable(GL_BLEND);
818                 glShadeModel(GL_SMOOTH);
819                 
820                 /* BOTTOM OUTER SUNKEN EFFECT */
821                 MM_WHITE_OP;
822                 fdrawline(x1, y1-1, x2, y1-1);  
823                 
824                 /* LEFT OUTER SUNKEN EFFECT */
825                 glBegin(GL_LINES);
826                 MM_WHITE_OP;
827                 glVertex2f(x1-1,y1);
828                 MM_WHITE_TR;
829                 glVertex2f(x1-1,y2);
830                 glEnd();
831                 
832                 /* RIGHT OUTER SUNKEN EFFECT */
833                 glBegin(GL_LINES);
834                 MM_WHITE_OP;
835                 glVertex2f(x2+1,y1);
836                 MM_WHITE_TR;
837                 glVertex2f(x2+1,y2);
838                 glEnd();
839                 
840                 glDisable(GL_BLEND);
841
842                 uiSetRoundBox(15);
843                 flat_button(x1, y1, x2, y2, asp, colorid, flag, 0);
844         }
845         
846         /* *** EXTRA DRAWING FOR SPECIFIC CONTROL TYPES *** */
847         switch(type) {
848         case NUM:
849                 /* SIDE ARROWS */
850                 /* left */
851                 if(flag & UI_SELECT) {
852                         if(flag & UI_ACTIVE) M_DARK;
853                         else M_DARK;
854                 } else {
855                         if(flag & UI_ACTIVE) M_GREY;
856                         else M_LGREY;
857                 }
858                 
859                 ui_default_num_arrows(x1, y1, x2, y2);
860                 /* END SIDE ARROWS */
861         }
862 }
863
864 static void ui_default_slider(int colorid, float fac, float aspect, float x1, float y1, float x2, float y2, int flag)
865 {
866         float ymid, yc;
867
868         /* the slider background line */
869         ymid= (y1+y2)/2.0;
870         //yc= 2.5*aspect;       // height of center line
871         yc = 2.3; // height of center line
872         
873         if(flag & UI_SELECT) 
874                         BIF_ThemeColorShade(TH_BUT_NUM, -5);
875         else
876                 if(flag & UI_ACTIVE) 
877                         BIF_ThemeColorShade(TH_BUT_NUM, +35); 
878                 else
879                         BIF_ThemeColorShade(TH_BUT_NUM, +25); 
880
881         glRectf(x1, ymid-yc, x2, ymid+yc);
882         
883         /* top inner bevel */
884         if(flag & UI_SELECT) BIF_ThemeColorShade(TH_BUT_NUM, -40); 
885         else BIF_ThemeColorShade(TH_BUT_NUM, -5); 
886         fdrawline(x1+1, ymid+yc, x2, ymid+yc);
887         
888         /* bottom inner bevel */
889         if(flag & UI_SELECT) BIF_ThemeColorShade(TH_BUT_NUM, +15); 
890         else BIF_ThemeColorShade(TH_BUT_NUM, +45); 
891         fdrawline(x1+1, ymid-yc, x2, ymid-yc);
892         
893         
894         /* the movable slider */
895         if(flag & UI_SELECT) BIF_ThemeColorShade(TH_BUT_NUM, +80); 
896         else BIF_ThemeColorShade(TH_BUT_NUM, -45); 
897
898         glShadeModel(GL_SMOOTH);
899         glBegin(GL_QUADS);
900
901         BIF_ThemeColorShade(TH_BUT_NUM, -45); 
902
903         glVertex2f(x1,     y1+2.5);
904         glVertex2f(x1+fac, y1+2.5);
905
906         BIF_ThemeColor(TH_BUT_NUM); 
907
908         glVertex2f(x1+fac, y2-2.5);
909         glVertex2f(x1,     y2-2.5);
910
911         glEnd();
912         
913
914         /* slider handle center */
915         glShadeModel(GL_SMOOTH);
916         glBegin(GL_QUADS);
917
918         BIF_ThemeColor(TH_BUT_NUM); 
919         glVertex2f(x1+fac-3, y1+2);
920         glVertex2f(x1+fac, y1+4);
921         BIF_ThemeColorShade(TH_BUT_NUM, +80); 
922         glVertex2f(x1+fac, y2-2);
923         glVertex2f(x1+fac-3, y2-2);
924
925         glEnd();
926         
927         /* slider handle left bevel */
928         BIF_ThemeColorShade(TH_BUT_NUM, +70); 
929         fdrawline(x1+fac-3, y2-2, x1+fac-3, y1+2);
930         
931         /* slider handle right bevel */
932         BIF_ThemeColorShade(TH_BUT_NUM, -35); 
933         fdrawline(x1+fac, y2-2, x1+fac, y1+2);
934
935         glShadeModel(GL_FLAT);
936 }
937
938 /* default theme callback */
939 static void ui_draw_default(int type, int colorid, float aspect, float x1, float y1, float x2, float y2, int flag)
940 {
941
942         switch(type) {
943         case TEX:
944         case IDPOIN:
945         case NUM:
946                 ui_default_flat(type, colorid, aspect, x1, y1, x2, y2, flag);
947                 break;
948         case ICONROW: 
949         case ICONTEXTROW: 
950         case MENU: 
951         default: 
952                 ui_default_button(type, colorid, aspect, x1, y1, x2, y2, flag);
953         }
954
955 }
956
957
958 /* *************** OLDSKOOL THEME ***************** */
959
960 static void ui_draw_outlineX(float x1, float y1, float x2, float y2, float asp1)
961 {
962         float vec[2];
963         
964         glBegin(GL_LINE_LOOP);
965         vec[0]= x1+asp1; vec[1]= y1-asp1;
966         glVertex2fv(vec);
967         vec[0]= x2-asp1; 
968         glVertex2fv(vec);
969         vec[0]= x2+asp1; vec[1]= y1+asp1;
970         glVertex2fv(vec);
971         vec[1]= y2-asp1;
972         glVertex2fv(vec);
973         vec[0]= x2-asp1; vec[1]= y2+asp1;
974         glVertex2fv(vec);
975         vec[0]= x1+asp1;
976         glVertex2fv(vec);
977         vec[0]= x1-asp1; vec[1]= y2-asp1;
978         glVertex2fv(vec);
979         vec[1]= y1+asp1;
980         glVertex2fv(vec);
981         glEnd();                
982         
983 }
984
985
986 static void ui_draw_oldskool(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
987 {
988         /* paper */
989         if(flag & UI_SELECT) {
990                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, -40);
991                 else BIF_ThemeColorShade(colorid, -30);
992         }
993         else {
994                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, +30);
995                 else BIF_ThemeColorShade(colorid, +20);
996         }
997         
998         glRectf(x1+1, y1+1, x2-1, y2-1);
999
1000         x1+= asp;
1001         x2-= asp;
1002         y1+= asp;
1003         y2-= asp;
1004
1005         /* below */
1006         if(flag & UI_SELECT) BIF_ThemeColorShade(colorid, 0);
1007         else BIF_ThemeColorShade(colorid, -30);
1008         fdrawline(x1, y1, x2, y1);
1009
1010         /* right */
1011         fdrawline(x2, y1, x2, y2);
1012         
1013         /* top */
1014         if(flag & UI_SELECT) BIF_ThemeColorShade(colorid, -30);
1015         else BIF_ThemeColorShade(colorid, 0);
1016         fdrawline(x1, y2, x2, y2);
1017
1018         /* left */
1019         fdrawline(x1, y1, x1, y2);
1020         
1021         /* outline */
1022         glColor3ub(0,0,0);
1023         ui_draw_outlineX(x1, y1, x2, y2, asp);
1024         
1025         
1026         /* special type decorations */
1027         switch(type) {
1028         case NUM:
1029                 if(flag & UI_SELECT) BIF_ThemeColorShade(colorid, -60);
1030                 else BIF_ThemeColorShade(colorid, -30);
1031                 ui_default_num_arrows(x1, y1, x2, y2);
1032                 break;
1033
1034         case ICONROW: 
1035         case ICONTEXTROW: 
1036                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, 0);
1037                 else BIF_ThemeColorShade(colorid, -10);
1038                 glRectf(x2-9, y1+asp, x2-asp, y2-asp);
1039
1040                 BIF_ThemeColorShade(colorid, -50);
1041                 ui_default_iconrow_arrows(x1, y1, x2, y2);
1042                 break;
1043                 
1044         case MENU: 
1045                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, 0);
1046                 else BIF_ThemeColorShade(colorid, -10);
1047                 glRectf(x2-17, y1+asp, x2-asp, y2-asp);
1048
1049                 BIF_ThemeColorShade(colorid, -50);
1050                 ui_default_menu_arrows(x1, y1, x2, y2);
1051                 break;
1052         }
1053         
1054 }
1055
1056 /* *************** BASIC ROUNDED THEME ***************** */
1057
1058 static void round_button(float x1, float y1, float x2, float y2, float asp, 
1059                                                  int colorid, int round, int menudeco, int curshade)
1060 {
1061         float rad;
1062         char col[4];
1063         
1064         rad= (y2-y1)/2.0;
1065         if(rad>7.0) rad= 7.0;
1066         
1067         uiSetRoundBox(round);
1068         gl_round_box(GL_POLYGON, x1, y1, x2, y2, rad);
1069
1070         if(menudeco) {
1071                 uiSetRoundBox(round & ~9);
1072                 BIF_ThemeColorShade(colorid, curshade-20);
1073                 gl_round_box(GL_POLYGON, x2-menudeco, y1, x2, y2, rad);
1074         }
1075         
1076         /* fake AA */
1077         uiSetRoundBox(round);
1078         glEnable( GL_BLEND );
1079
1080         BIF_GetThemeColor3ubv(colorid, col);
1081                 
1082         if(col[0]<100) col[0]= 0; else col[0]-= 100;
1083         if(col[1]<100) col[1]= 0; else col[1]-= 100;
1084         if(col[2]<100) col[2]= 0; else col[2]-= 100;
1085         col[3]= 80;
1086         glColor4ubv((GLubyte *)col);
1087         gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, rad - asp);
1088         gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, rad + asp);
1089         col[3]= 180;
1090         glColor4ubv((GLubyte *)col);
1091         gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, rad);
1092
1093         glDisable( GL_BLEND );
1094 }
1095
1096 /* button in midst of alignment row */
1097 static void round_button_mid(float x1, float y1, float x2, float y2, float asp, 
1098                                                          int colorid, int align, int menudeco, int curshade)
1099 {
1100         glRectf(x1, y1, x2, y2);
1101         
1102         if(menudeco) {
1103                 BIF_ThemeColorShade(colorid, curshade-20);
1104                 glRectf(x2-menudeco, y1, x2, y2);
1105         }
1106         
1107         BIF_ThemeColorBlendShade(colorid, TH_BACK, 0.5, -70);
1108         // we draw full outline, its not AA, and it works better button mouse-over hilite
1109         
1110         // left right
1111         fdrawline(x1, y1, x1, y2);
1112         fdrawline(x2, y1, x2, y2);
1113
1114         // top down
1115         fdrawline(x1, y2, x2, y2);
1116         fdrawline(x1, y1, x2, y1);   
1117 }
1118
1119 static void ui_draw_round(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
1120 {
1121         int align= (flag & UI_BUT_ALIGN);
1122         int curshade= 0, menudeco= 0;
1123         
1124         if(type==ICONROW || type==ICONTEXTROW) menudeco= 9;
1125         else if((type==MENU || type==BLOCK) && x2-x1>24) menudeco= 16;
1126         
1127         /* paper */
1128         if(flag & UI_SELECT) {
1129                 if(flag & UI_ACTIVE) curshade= -40;
1130                 else curshade= -30;
1131         }
1132         else {
1133                 if(flag & UI_ACTIVE) curshade= 30;
1134                 else curshade= +20;
1135         }
1136         
1137         BIF_ThemeColorShade(colorid, curshade);
1138
1139         if(align) {
1140                 switch(align) {
1141                 case UI_BUT_ALIGN_TOP:
1142                         round_button(x1, y1, x2, y2, asp, colorid, 12, menudeco, curshade);
1143                         break;
1144                 case UI_BUT_ALIGN_DOWN:
1145                         round_button(x1, y1, x2, y2, asp, colorid, 3, menudeco, curshade);
1146                         break;
1147                 case UI_BUT_ALIGN_LEFT:
1148                         round_button(x1, y1, x2, y2, asp, colorid, 6, menudeco, curshade);
1149                         break;
1150                 case UI_BUT_ALIGN_RIGHT:
1151                         round_button(x1, y1, x2, y2, asp, colorid, 9, menudeco, curshade);
1152                         break;
1153                         
1154                 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT:
1155                         round_button(x1, y1, x2, y2, asp, colorid, 1, menudeco, curshade);
1156                         break;
1157                 case UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT:
1158                         round_button(x1, y1, x2, y2, asp, colorid, 2, menudeco, curshade);
1159                         break;
1160                 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
1161                         round_button(x1, y1, x2, y2, asp, colorid, 8, menudeco, curshade);
1162                         break;
1163                 case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
1164                         round_button(x1, y1, x2, y2, asp, colorid, 4, menudeco, curshade);
1165                         break;
1166                         
1167                 default:
1168                         round_button_mid(x1, y1, x2, y2, asp, colorid, align, menudeco, curshade);
1169                         break;
1170                 }
1171         } 
1172         else {
1173                 round_button(x1, y1, x2, y2, asp, colorid, 15, menudeco, curshade);
1174         }
1175
1176         /* special type decorations */
1177         switch(type) {
1178         case NUM:
1179                 BIF_ThemeColorShade(colorid, curshade-60);
1180                 ui_default_num_arrows(x1, y1, x2, y2);
1181                 break;
1182
1183         case ICONROW: 
1184         case ICONTEXTROW: 
1185                 BIF_ThemeColorShade(colorid, curshade-60);
1186                 ui_default_iconrow_arrows(x1, y1, x2, y2);
1187                 break;
1188                 
1189         case MENU: 
1190         case BLOCK: 
1191                 BIF_ThemeColorShade(colorid, curshade-60);
1192                 ui_default_menu_arrows(x1, y1, x2, y2);
1193                 break;
1194         }
1195 }
1196
1197 /* *************** MINIMAL THEME ***************** */
1198
1199 // theme can define an embosfunc and sliderfunc, text+icon drawing is standard, no theme.
1200
1201
1202
1203 /* super minimal button as used in logic menu */
1204 static void ui_draw_minimal(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
1205 {
1206         /* too much space between buttons */
1207         
1208         if (type==TEX || type==IDPOIN) {
1209                 x1+= asp;
1210                 x2-= (asp*2);
1211                 //y1+= asp;
1212                 y2-= asp;
1213         } else {
1214                 /* Less space between buttons looks nicer */
1215                 y2-= asp;
1216                 x2-= asp;
1217         }
1218         
1219         /* paper */
1220         if(flag & UI_SELECT) {
1221                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, -40);
1222                 else BIF_ThemeColorShade(colorid, -30);
1223         }
1224         else {
1225                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, +20);
1226                 else BIF_ThemeColorShade(colorid, +10);
1227         }
1228         
1229         glRectf(x1, y1, x2, y2);
1230         
1231         if (type==TEX || type==IDPOIN) {
1232                 BIF_ThemeColorShade(colorid, -60);
1233
1234                 /* top */
1235                 fdrawline(x1, y2, x2, y2);
1236                 /* left */
1237                 fdrawline(x1, y1, x1, y2);
1238                 
1239                 
1240                 /* text underline, some  */ 
1241                 BIF_ThemeColorShade(colorid, +50);
1242                 glEnable(GL_LINE_STIPPLE);
1243                 glLineStipple(1, 0x8888);
1244                 fdrawline(x1+(asp*2), y1+(asp*3), x2-(asp*2), y1+(asp*3));
1245                 glDisable(GL_LINE_STIPPLE);
1246                 
1247                 
1248                 BIF_ThemeColorShade(colorid, +60);
1249                 /* below */
1250                 fdrawline(x1, y1, x2, y1);
1251                 /* right */
1252                 fdrawline(x2, y1, x2, y2);
1253                 
1254         } else {
1255                 if(flag & UI_SELECT) {
1256                         BIF_ThemeColorShade(colorid, -60);
1257
1258                         /* top */
1259                         fdrawline(x1, y2, x2, y2);
1260                         /* left */
1261                         fdrawline(x1, y1, x1, y2);
1262                         BIF_ThemeColorShade(colorid, +40);
1263
1264                         /* below */
1265                         fdrawline(x1, y1, x2, y1);
1266                         /* right */
1267                         fdrawline(x2, y1, x2, y2);
1268                 }
1269                 else {
1270                         BIF_ThemeColorShade(colorid, +40);
1271
1272                         /* top */
1273                         fdrawline(x1, y2, x2, y2);
1274                         /* left */
1275                         fdrawline(x1, y1, x1, y2);
1276                         
1277                         BIF_ThemeColorShade(colorid, -60);
1278                         /* below */
1279                         fdrawline(x1, y1, x2, y1);
1280                         /* right */
1281                         fdrawline(x2, y1, x2, y2);
1282                 }
1283         }
1284         
1285         /* special type decorations */
1286         switch(type) {
1287         case NUM:
1288                 if(flag & UI_SELECT) BIF_ThemeColorShade(colorid, -60);
1289                 else BIF_ThemeColorShade(colorid, -30);
1290                 ui_default_num_arrows(x1, y1, x2, y2);
1291                 break;
1292
1293         case ICONROW: 
1294         case ICONTEXTROW: 
1295                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, 0);
1296                 else BIF_ThemeColorShade(colorid, -10);
1297                 glRectf(x2-9, y1+asp, x2-asp, y2-asp);
1298
1299                 BIF_ThemeColorShade(colorid, -50);
1300                 ui_default_iconrow_arrows(x1, y1, x2, y2);
1301                 break;
1302                 
1303         case MENU: 
1304         case BLOCK: 
1305                 if(flag & UI_ACTIVE) BIF_ThemeColorShade(colorid, 0);
1306                 else BIF_ThemeColorShade(colorid, -10);
1307                 glRectf(x2-17, y1+asp, x2-asp, y2-asp);
1308
1309                 BIF_ThemeColorShade(colorid, -50);
1310                 ui_default_menu_arrows(x1, y1, x2, y2);
1311                 break;
1312         }
1313         
1314         
1315 }
1316
1317
1318 /* fac is the slider handle position between x1 and x2 */
1319 static void ui_draw_slider(int colorid, float fac, float aspect, float x1, float y1, float x2, float y2, int flag)
1320 {
1321         float ymid, yc;
1322
1323         /* the slider background line */
1324         ymid= (y1+y2)/2.0;
1325         yc= 1.7*aspect; 
1326
1327         if(flag & UI_ACTIVE) 
1328                 BIF_ThemeColorShade(colorid, -50); 
1329         else 
1330                 BIF_ThemeColorShade(colorid, -40); 
1331
1332         /* left part */
1333         glRectf(x1, ymid-2.0*yc, x1+fac, ymid+2.0*yc);
1334         /* right part */
1335         glRectf(x1+fac, ymid-yc, x2, ymid+yc);
1336
1337         /* the movable slider */
1338         
1339         BIF_ThemeColorShade(colorid, +70); 
1340         glRectf(x1+fac-aspect, ymid-2.0*yc, x1+fac+aspect, ymid+2.0*yc);
1341
1342 }
1343
1344 /* ************** STANDARD MENU DRAWING FUNCTION ************* */
1345
1346
1347 static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
1348 {
1349         glEnable(GL_BLEND);
1350         glShadeModel(GL_SMOOTH);
1351         
1352         /* right quad */
1353         glBegin(GL_POLYGON);
1354         glColor4ub(0, 0, 0, alpha);
1355         glVertex2f(maxx, miny);
1356         glVertex2f(maxx, maxy-shadsize);
1357         glColor4ub(0, 0, 0, 0);
1358         glVertex2f(maxx+shadsize, maxy-shadsize-shadsize);
1359         glVertex2f(maxx+shadsize, miny);
1360         glEnd();
1361         
1362         /* corner shape */
1363         glBegin(GL_POLYGON);
1364         glColor4ub(0, 0, 0, alpha);
1365         glVertex2f(maxx, miny);
1366         glColor4ub(0, 0, 0, 0);
1367         glVertex2f(maxx+shadsize, miny);
1368         glVertex2f(maxx+0.7*shadsize, miny-0.7*shadsize);
1369         glVertex2f(maxx, miny-shadsize);
1370         glEnd();
1371         
1372         /* bottom quad */               
1373         glBegin(GL_POLYGON);
1374         glColor4ub(0, 0, 0, alpha);
1375         glVertex2f(minx+shadsize, miny);
1376         glVertex2f(maxx, miny);
1377         glColor4ub(0, 0, 0, 0);
1378         glVertex2f(maxx, miny-shadsize);
1379         glVertex2f(minx+shadsize+shadsize, miny-shadsize);
1380         glEnd();
1381         
1382         glDisable(GL_BLEND);
1383         glShadeModel(GL_FLAT);
1384 }
1385
1386 void uiDrawBoxShadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
1387 {
1388         /* accumulated outline boxes to make shade not linear, is more pleasant */
1389         ui_shadowbox(minx, miny, maxx, maxy, 6.0, (30*alpha)>>8);
1390         ui_shadowbox(minx, miny, maxx, maxy, 4.0, (70*alpha)>>8);
1391         ui_shadowbox(minx, miny, maxx, maxy, 2.0, (100*alpha)>>8);
1392         
1393 }
1394
1395 // background for pulldowns, pullups, and other drawing temporal menus....
1396 // has to be made themable still (now only color)
1397
1398 void uiDrawMenuBox(float minx, float miny, float maxx, float maxy, short flag)
1399 {
1400         char col[4];
1401         BIF_GetThemeColor4ubv(TH_MENU_BACK, col);
1402         
1403         if( (flag & UI_BLOCK_NOSHADOW)==0) {
1404                 /* accumulated outline boxes to make shade not linear, is more pleasant */
1405                 ui_shadowbox(minx, miny, maxx, maxy, 6.0, (30*col[3])>>8);
1406                 ui_shadowbox(minx, miny, maxx, maxy, 4.0, (70*col[3])>>8);
1407                 ui_shadowbox(minx, miny, maxx, maxy, 2.0, (100*col[3])>>8);
1408                 
1409                 glEnable(GL_BLEND);
1410                 glColor4ubv((GLubyte *)col);
1411                 glRectf(minx-1, miny, minx, maxy);      // 1 pixel on left, to distinguish sublevel menus
1412         }
1413         glEnable(GL_BLEND);
1414         glColor4ubv((GLubyte *)col);
1415         glRectf(minx, miny, maxx, maxy);
1416         glDisable(GL_BLEND);
1417 }
1418
1419
1420
1421 /* pulldown menu item */
1422 static void ui_draw_pulldown_item(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
1423 {
1424         char col[4];
1425         
1426         BIF_GetThemeColor4ubv(TH_MENU_BACK, col);
1427         if(col[3]!=255) {
1428                 glEnable(GL_BLEND);
1429         }
1430         
1431         if((flag & UI_ACTIVE) && type!=LABEL) {
1432                 BIF_ThemeColor4(TH_MENU_HILITE);
1433                 glRectf(x1, y1, x2, y2);
1434         
1435
1436         } else {
1437                 BIF_ThemeColor4(colorid);       // is set at TH_MENU_ITEM when pulldown opened.
1438                 glRectf(x1, y1, x2, y2);
1439         }
1440
1441         glDisable(GL_BLEND);
1442 }
1443
1444 /* pulldown menu calling button */
1445 static void ui_draw_pulldown_round(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
1446 {
1447         
1448         if(flag & UI_ACTIVE) {
1449                 BIF_ThemeColor(TH_MENU_HILITE);
1450
1451                 uiSetRoundBox(15);
1452                 gl_round_box(GL_POLYGON, x1, y1+3, x2, y2-3, 7.0);
1453
1454                 glEnable( GL_LINE_SMOOTH );
1455                 glEnable( GL_BLEND );
1456                 gl_round_box(GL_LINE_LOOP, x1, y1+3, x2, y2-3, 7.0);
1457                 glDisable( GL_LINE_SMOOTH );
1458                 glDisable( GL_BLEND );
1459                 
1460         } else {
1461                 BIF_ThemeColor(colorid);        // is set at TH_MENU_ITEM when pulldown opened.
1462                 glRectf(x1-1, y1+2, x2+1, y2-2);
1463         }
1464         
1465 }
1466
1467
1468 /* ************** TEXT AND ICON DRAWING FUNCTIONS ************* */
1469
1470
1471
1472 /* draws text and icons for buttons */
1473 static void ui_draw_text_icon(uiBut *but)
1474 {
1475         float x;
1476         int len;
1477         char *cpoin;
1478         short t, pos, ch;
1479         short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
1480         
1481         /* check for button text label */
1482         if (but->type == ICONTEXTROW) {
1483                 ui_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 0);
1484         }
1485         else {
1486
1487                 /* text button selection and cursor */
1488                 if(but->pos != -1) {
1489                 
1490                         if ((but->selend - but->selsta) > 0) {
1491                                 /* text button selection */
1492                                 selsta_tmp = but->selsta + strlen(but->str);
1493                                 selend_tmp = but->selend + strlen(but->str);
1494                                         
1495                                 if(but->drawstr[0]!=0) {
1496                                         ch= but->drawstr[selsta_tmp];
1497                                         but->drawstr[selsta_tmp]= 0;
1498                                         
1499                                         selsta_draw = but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, (U.transopts & USER_TR_BUTTONS)) + 3;
1500                                         
1501                                         but->drawstr[selsta_tmp]= ch;
1502                                         
1503                                         
1504                                         ch= but->drawstr[selend_tmp];
1505                                         but->drawstr[selend_tmp]= 0;
1506                                         
1507                                         selwidth_draw = but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, (U.transopts & USER_TR_BUTTONS)) + 3;
1508                                         
1509                                         but->drawstr[selend_tmp]= ch;
1510                                         
1511                                         BIF_ThemeColor(TH_BUT_TEXTFIELD_HI);
1512                                         glRects(but->x1+selsta_draw+1, but->y1+2, but->x1+selwidth_draw+1, but->y2-2);
1513                                 }
1514                         } else {
1515                                 /* text cursor */
1516                                 pos= but->pos+strlen(but->str);
1517                                 if(pos >= but->ofs) {
1518                                         if(but->drawstr[0]!=0) {
1519                                                 ch= but->drawstr[pos];
1520                                                 but->drawstr[pos]= 0;
1521                         
1522                                                 t= but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, (U.transopts & USER_TR_BUTTONS)) + 3;
1523                                                 
1524                                                 but->drawstr[pos]= ch;
1525                                         }
1526                                         else t= 3;
1527                                         
1528                                         glColor3ub(255,0,0);
1529                                         glRects(but->x1+t, but->y1+2, but->x1+t+2, but->y2-2);
1530                                 }
1531                         }
1532                 }
1533                 
1534                 if(but->type==BUT_TOGDUAL) {
1535                         int dualset= 0;
1536                         if(but->pointype==SHO)
1537                                 dualset= BTST( *(((short *)but->poin)+1), but->bitnr);
1538                         else if(but->pointype==INT)
1539                                 dualset= BTST( *(((int *)but->poin)+1), but->bitnr);
1540                         
1541                         ui_draw_icon(but, ICON_DOT, dualset?0:-100);
1542                 }
1543                 
1544                 if(but->drawstr[0]!=0) {
1545                         int transopts;
1546                         int tog3= 0;
1547                         
1548                         // cut string in 2 parts
1549                         cpoin= strchr(but->drawstr, '|');
1550                         if(cpoin) *cpoin= 0;
1551
1552                         /* If there's an icon too (made with uiDefIconTextBut) then draw the icon
1553                         and offset the text label to accomodate it */
1554                         
1555                         if ( (but->flag & UI_HAS_ICON) && (but->flag & UI_ICON_LEFT) ) {
1556                                 ui_draw_icon(but, but->icon, 0);
1557
1558                                 if(but->flag & UI_TEXT_LEFT) x= but->x1 + but->aspect*BIF_icon_get_width(but->icon)+5.0;
1559                                 else x= (but->x1+but->x2-but->strwidth+1)/2.0;
1560                         }
1561                         else {
1562                                 if(but->flag & UI_TEXT_LEFT) x= but->x1+4.0;
1563                                 else x= (but->x1+but->x2-but->strwidth+1)/2.0;
1564                         }
1565                         
1566                         /* tog3 button exception; draws with glColor! */
1567                         if(but->type==TOG3 && (but->flag & UI_SELECT)) {
1568                                 
1569                                 if( but->pointype==CHA ) {
1570                                         if( BTST( *(but->poin+2), but->bitnr )) tog3= 1;
1571                                 }
1572                                 else if( but->pointype ==SHO ) {
1573                                         short *sp= (short *)but->poin;
1574                                         if( BTST( sp[1], but->bitnr )) tog3= 1;
1575                                 }
1576                                 
1577                                 ui_tog3_invert(but->x1,but->y1,but->x2,but->y2, tog3);
1578                                 if (tog3) glColor3ub(255, 255, 0);
1579                         }
1580                         
1581                         /* text color, with pulldown item exception */
1582                         if(tog3);       // color already set
1583                         else if(but->dt==UI_EMBOSSP) {
1584                                 if((but->flag & (UI_SELECT|UI_ACTIVE)) && but->type!=LABEL) {   // LABEL = title in pulldowns
1585                                         BIF_ThemeColor(TH_MENU_TEXT_HI);
1586                                 } else {
1587                                         BIF_ThemeColor(TH_MENU_TEXT);
1588                                 }
1589                         }
1590                         else {
1591                                 if(but->flag & UI_SELECT) {             
1592                                         BIF_ThemeColor(TH_BUT_TEXT_HI);
1593                                 } else {
1594                                         BIF_ThemeColor(TH_BUT_TEXT);
1595                                 }
1596                         }
1597
1598                         /* LABEL button exception */
1599                         if(but->type==LABEL && but->min!=0.0) BIF_ThemeColor(TH_BUT_TEXT_HI);
1600                 
1601                         ui_rasterpos_safe(x, (but->y1+but->y2- 9.0)/2.0, but->aspect);
1602                         if(but->type==IDPOIN) transopts= 0;     // no translation, of course!
1603                         else transopts= (U.transopts & USER_TR_BUTTONS);
1604                         
1605                 #ifdef INTERNATIONAL
1606                         if (but->type == FTPREVIEW)
1607                                 FTF_DrawNewFontString (but->drawstr+but->ofs, FTF_INPUT_UTF8);
1608                         else
1609                                 BIF_DrawString(but->font, but->drawstr+but->ofs, transopts);
1610                 #else
1611                         BIF_DrawString(but->font, but->drawstr+but->ofs, transopts);
1612                 #endif
1613
1614                         /* part text right aligned */
1615                         if(cpoin) {
1616                                 len= BIF_GetStringWidth(but->font, cpoin+1, (U.transopts & USER_TR_BUTTONS));
1617                                 ui_rasterpos_safe( but->x2 - len*but->aspect-3, (but->y1+but->y2- 9.0)/2.0, but->aspect);
1618                                 BIF_DrawString(but->font, cpoin+1, (U.transopts & USER_TR_BUTTONS));
1619                                 *cpoin= '|';
1620                         }
1621                 }
1622                 /* if there's no text label, then check to see if there's an icon only and draw it */
1623                 else if( but->flag & UI_HAS_ICON ) {
1624                         ui_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 0);
1625                 }
1626         }
1627 }
1628
1629 static void ui_draw_but_COL(uiBut *but)
1630 {
1631         float *fp;
1632         char colr, colg, colb;
1633         
1634         if( but->pointype==FLO ) {
1635                 fp= (float *)but->poin;
1636                 colr= floor(255.0*fp[0]+0.5);
1637                 colg= floor(255.0*fp[1]+0.5);
1638                 colb= floor(255.0*fp[2]+0.5);
1639         }
1640         else {
1641                 char *cp= (char *)but->poin;
1642                 colr= cp[0];
1643                 colg= cp[1];
1644                 colb= cp[2];
1645         }
1646         
1647         /* exception... hrms, but can't simply use the emboss callback for this now. */
1648         /* this button type needs review, and nice integration with rest of API here */
1649         if(but->embossfunc == ui_draw_round) {
1650                 char *cp= BIF_ThemeGetColorPtr(U.themes.first, 0, TH_CUSTOM);
1651                 cp[0]= colr; cp[1]= colg; cp[2]= colb;
1652                 but->flag &= ~UI_SELECT;
1653                 but->embossfunc(but->type, TH_CUSTOM, but->aspect, but->x1, but->y1, but->x2, but->y2, but->flag);
1654         }
1655         else {
1656                 
1657                 glColor3ub(colr,  colg,  colb);
1658                 glRectf((but->x1), (but->y1), (but->x2), (but->y2));
1659                 glColor3ub(0,  0,  0);
1660                 fdrawbox((but->x1), (but->y1), (but->x2), (but->y2));
1661         }
1662 }
1663
1664 /* draws in resolution of 20x4 colors */
1665 static void ui_draw_but_HSVCUBE(uiBut *but)
1666 {
1667         int a;
1668         float h,s,v;
1669         float dx, dy, sx1, sx2, sy, x, y;
1670         float col0[4][3];       // left half, rect bottom to top
1671         float col1[4][3];       // right half, rect bottom to top
1672         
1673         h= but->hsv[0];
1674         s= but->hsv[1];
1675         v= but->hsv[2];
1676         
1677         /* draw series of gouraud rects */
1678         glShadeModel(GL_SMOOTH);
1679         
1680         if(but->a1==0) {        // H and V vary
1681                 hsv_to_rgb(0.0, s, 0.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1682                 hsv_to_rgb(0.0, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1683                 hsv_to_rgb(0.0, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1684                 hsv_to_rgb(0.0, s, 1.0,   &col1[3][0], &col1[3][1], &col1[3][2]);
1685                 x= h; y= v;
1686         }
1687         else if(but->a1==1) {   // H and S vary
1688                 hsv_to_rgb(0.0, 0.0, v,   &col1[0][0], &col1[0][1], &col1[0][2]);
1689                 hsv_to_rgb(0.0, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1690                 hsv_to_rgb(0.0, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1691                 hsv_to_rgb(0.0, 1.0, v,   &col1[3][0], &col1[3][1], &col1[3][2]);
1692                 x= h; y= s;
1693         }
1694         else if(but->a1==2) {   // S and V vary
1695                 hsv_to_rgb(h, 0.0, 0.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1696                 hsv_to_rgb(h, 0.333, 0.0, &col1[1][0], &col1[1][1], &col1[1][2]);
1697                 hsv_to_rgb(h, 0.666, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]);
1698                 hsv_to_rgb(h, 1.0, 0.0,   &col1[3][0], &col1[3][1], &col1[3][2]);
1699                 x= v; y= s;
1700         }
1701         else {          // only hue slider
1702                 hsv_to_rgb(0.0, 1.0, 1.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1703                 VECCOPY(col1[1], col1[0]);
1704                 VECCOPY(col1[2], col1[0]);
1705                 VECCOPY(col1[3], col1[0]);
1706                 x= h; y= 0.5;
1707         }
1708         
1709         for(dx=0.0; dx<1.0; dx+= 0.05) {
1710                 // previous color
1711                 VECCOPY(col0[0], col1[0]);
1712                 VECCOPY(col0[1], col1[1]);
1713                 VECCOPY(col0[2], col1[2]);
1714                 VECCOPY(col0[3], col1[3]);
1715
1716                 // new color
1717                 if(but->a1==0) {        // H and V vary
1718                         hsv_to_rgb(dx, s, 0.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1719                         hsv_to_rgb(dx, s, 0.333, &col1[1][0], &col1[1][1], &col1[1][2]);
1720                         hsv_to_rgb(dx, s, 0.666, &col1[2][0], &col1[2][1], &col1[2][2]);
1721                         hsv_to_rgb(dx, s, 1.0,   &col1[3][0], &col1[3][1], &col1[3][2]);
1722                 }
1723                 else if(but->a1==1) {   // H and S vary
1724                         hsv_to_rgb(dx, 0.0, v,   &col1[0][0], &col1[0][1], &col1[0][2]);
1725                         hsv_to_rgb(dx, 0.333, v, &col1[1][0], &col1[1][1], &col1[1][2]);
1726                         hsv_to_rgb(dx, 0.666, v, &col1[2][0], &col1[2][1], &col1[2][2]);
1727                         hsv_to_rgb(dx, 1.0, v,   &col1[3][0], &col1[3][1], &col1[3][2]);
1728                 }
1729                 else if(but->a1==2) {   // S and V vary
1730                         hsv_to_rgb(h, 0.0, dx,   &col1[0][0], &col1[0][1], &col1[0][2]);
1731                         hsv_to_rgb(h, 0.333, dx, &col1[1][0], &col1[1][1], &col1[1][2]);
1732                         hsv_to_rgb(h, 0.666, dx, &col1[2][0], &col1[2][1], &col1[2][2]);
1733                         hsv_to_rgb(h, 1.0, dx,   &col1[3][0], &col1[3][1], &col1[3][2]);
1734                 }
1735                 else {  // only H
1736                         hsv_to_rgb(dx, 1.0, 1.0,   &col1[0][0], &col1[0][1], &col1[0][2]);
1737                         VECCOPY(col1[1], col1[0]);
1738                         VECCOPY(col1[2], col1[0]);
1739                         VECCOPY(col1[3], col1[0]);
1740                 }
1741                 
1742                 // rect
1743                 sx1= but->x1 + dx*(but->x2-but->x1);
1744                 sx2= but->x1 + (dx+0.05)*(but->x2-but->x1);
1745                 sy= but->y1;
1746                 dy= (but->y2-but->y1)/3.0;
1747                 
1748                 glBegin(GL_QUADS);
1749                 for(a=0; a<3; a++, sy+=dy) {
1750                         glColor3fv(col0[a]);
1751                         glVertex2f(sx1, sy);
1752
1753                         glColor3fv(col1[a]);
1754                         glVertex2f(sx2, sy);
1755                         
1756                         glColor3fv(col1[a+1]);
1757                         glVertex2f(sx2, sy+dy);
1758                         
1759                         glColor3fv(col0[a+1]);
1760                         glVertex2f(sx1, sy+dy);
1761                 }
1762                 glEnd();
1763         }
1764
1765         glShadeModel(GL_FLAT);
1766
1767         /* cursor */
1768         x= but->x1 + x*(but->x2-but->x1);
1769         y= but->y1 + y*(but->y2-but->y1);
1770         CLAMP(x, but->x1+3.0, but->x2-3.0);
1771         CLAMP(y, but->y1+3.0, but->y2-3.0);
1772         
1773         fdrawXORcirc(x, y, 3.1);
1774
1775         /* outline */
1776         glColor3ub(0,  0,  0);
1777         fdrawbox((but->x1), (but->y1), (but->x2), (but->y2));
1778 }
1779
1780 #ifdef INTERNATIONAL
1781 static void ui_draw_but_CHARTAB(uiBut *but)
1782 {
1783         /* Some local variables */
1784         float sx, sy, ex, ey;
1785         float width, height;
1786         float butw, buth;
1787         int x, y, cs;
1788         wchar_t wstr[2];
1789         unsigned char ustr[16];
1790         PackedFile *pf;
1791         int result = 0;
1792         int charmax = G.charmax;
1793         
1794         /* <builtin> font in use. There are TTF <builtin> and non-TTF <builtin> fonts */
1795         if(!strcmp(G.selfont->name, "<builtin>"))
1796         {
1797                 if(G.ui_international == TRUE)
1798                 {
1799                         charmax = 0xff;
1800                 }
1801                 else
1802                 {
1803                         charmax = 0xff;
1804                 }
1805         }
1806
1807         /* Category list exited without selecting the area */
1808         if(G.charmax == 0)
1809                 charmax = G.charmax = 0xffff;
1810
1811         /* Calculate the size of the button */
1812         width = abs(but->x2 - but->x1);
1813         height = abs(but->y2 - but->y1);
1814         
1815         butw = floor(width / 12);
1816         buth = floor(height / 6);
1817         
1818         /* Initialize variables */
1819         sx = but->x1;
1820         ex = but->x1 + butw;
1821         sy = but->y1 + height - buth;
1822         ey = but->y1 + height;
1823
1824         cs = G.charstart;
1825
1826         /* Set the font, in case it is not <builtin> font */
1827         if(G.selfont && strcmp(G.selfont->name, "<builtin>"))
1828         {
1829                 char tmpStr[256];
1830
1831                 // Is the font file packed, if so then use the packed file
1832                 if(G.selfont->packedfile)
1833                 {
1834                         pf = G.selfont->packedfile;             
1835                         FTF_SetFont(pf->data, pf->size, 14.0);
1836                 }
1837                 else
1838                 {
1839                         int err;
1840
1841                         strcpy(tmpStr, G.selfont->name);
1842                         BLI_convertstringcode(tmpStr, G.sce);
1843                         err = FTF_SetFont((unsigned char *)tmpStr, 0, 14.0);
1844                 }
1845         }
1846         else
1847         {
1848                 if(G.ui_international == TRUE)
1849                 {
1850                         FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 14.0);
1851                 }
1852         }
1853
1854         /* Start drawing the button itself */
1855         glShadeModel(GL_SMOOTH);
1856
1857         glColor3ub(200,  200,  200);
1858         glRectf((but->x1), (but->y1), (but->x2), (but->y2));
1859
1860         glColor3ub(0,  0,  0);
1861         for(y = 0; y < 6; y++)
1862         {
1863                 // Do not draw more than the category allows
1864                 if(cs > charmax) break;
1865
1866                 for(x = 0; x < 12; x++)
1867                 {
1868                         // Do not draw more than the category allows
1869                         if(cs > charmax) break;
1870
1871                         // Draw one grid cell
1872                         glBegin(GL_LINE_LOOP);
1873                                 glVertex2f(sx, sy);
1874                                 glVertex2f(ex, sy);
1875                                 glVertex2f(ex, ey);
1876                                 glVertex2f(sx, ey);                             
1877                         glEnd();        
1878
1879                         // Draw character inside the cell
1880                         memset(wstr, 0, sizeof(wchar_t)*2);
1881                         memset(ustr, 0, 16);
1882
1883                         // Set the font to be either unicode or <builtin>                               
1884                         wstr[0] = cs;
1885                         if(strcmp(G.selfont->name, "<builtin>"))
1886                         {
1887                                 wcs2utf8s((char *)ustr, (wchar_t *)wstr);
1888                         }
1889                         else
1890                         {
1891                                 if(G.ui_international == TRUE)
1892                                 {
1893                                         wcs2utf8s((char *)ustr, (wchar_t *)wstr);
1894                                 }
1895                                 else
1896                                 {
1897                                         ustr[0] = cs;
1898                                         ustr[1] = 0;
1899                                 }
1900                         }
1901
1902                         if((G.selfont && strcmp(G.selfont->name, "<builtin>")) || (G.selfont && !strcmp(G.selfont->name, "<builtin>") && G.ui_international == TRUE))
1903                         {
1904                                 float wid;
1905                                 float llx, lly, llz, urx, ury, urz;
1906                                 float dx, dy;
1907                                 float px, py;
1908         
1909                                 // Calculate the position
1910                                 wid = FTF_GetStringWidth((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
1911                                 FTF_GetBoundingBox((char *) ustr, &llx,&lly,&llz,&urx,&ury,&urz, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
1912                                 dx = urx-llx;
1913                                 dy = ury-lly;
1914
1915                                 // This isn't fully functional since the but->aspect isn't working like I suspected
1916                                 px = sx + ((butw/but->aspect)-dx)/2;
1917                                 py = sy + ((buth/but->aspect)-dy)/2;
1918
1919                                 // Set the position and draw the character
1920                                 ui_rasterpos_safe(px, py, but->aspect);
1921                                 FTF_DrawString((char *) ustr, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
1922                         }
1923                         else
1924                         {
1925                                 ui_rasterpos_safe(sx + butw/2, sy + buth/2, but->aspect);
1926                                 BIF_DrawString(but->font, (char *) ustr, 0);
1927                         }
1928         
1929                         // Calculate the next position and character
1930                         sx += butw; ex +=butw;
1931                         cs++;
1932                 }
1933                 /* Add the y position and reset x position */
1934                 sy -= buth; 
1935                 ey -= buth;
1936                 sx = but->x1;
1937                 ex = but->x1 + butw;
1938         }       
1939         glShadeModel(GL_FLAT);
1940
1941         /* Return Font Settings to original */
1942         if(U.fontsize && U.fontname[0])
1943         {
1944                 result = FTF_SetFont((unsigned char *)U.fontname, 0, U.fontsize);
1945         }
1946         else if (U.fontsize)
1947         {
1948                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, U.fontsize);
1949         }
1950
1951         if (result == 0)
1952         {
1953                 result = FTF_SetFont((unsigned char *) datatoc_bfont_ttf, datatoc_bfont_ttf_size, 11);
1954         }
1955         
1956         /* resets the font size */
1957         if(G.ui_international == TRUE)
1958         {
1959                 uiSetCurFont(but->block, UI_HELV);
1960         }
1961 }
1962
1963 #endif // INTERNATIONAL
1964
1965 static void ui_draw_but_COLORBAND(uiBut *but)
1966 {
1967         ColorBand *coba= (ColorBand *)but->poin;
1968         CBData *cbd;
1969         float x1, y1, sizex, sizey;
1970         float dx, v3[2], v1[2], v2[2], v1a[2], v2a[2];
1971         int a;
1972                 
1973         if(coba==NULL) return;
1974         
1975         x1= but->x1;
1976         y1= but->y1;
1977         sizex= but->x2-x1;
1978         sizey= but->y2-y1;
1979         
1980         /* first background, to show tranparency */
1981         dx= sizex/12.0;
1982         v1[0]= x1;
1983         for(a=0; a<12; a++) {
1984                 if(a & 1) glColor3f(0.3, 0.3, 0.3); else glColor3f(0.8, 0.8, 0.8);
1985                 glRectf(v1[0], y1, v1[0]+dx, y1+0.5*sizey);
1986                 if(a & 1) glColor3f(0.8, 0.8, 0.8); else glColor3f(0.3, 0.3, 0.3);
1987                 glRectf(v1[0], y1+0.5*sizey, v1[0]+dx, y1+sizey);
1988                 v1[0]+= dx;
1989         }
1990         
1991         glShadeModel(GL_SMOOTH);
1992         glEnable(GL_BLEND);
1993         
1994         cbd= coba->data;
1995         
1996         v1[0]= v2[0]= x1;
1997         v1[1]= y1;
1998         v2[1]= y1+sizey;
1999         
2000         glBegin(GL_QUAD_STRIP);
2001         
2002         glColor4fv( &cbd->r );
2003         glVertex2fv(v1); glVertex2fv(v2);
2004         
2005         for(a=0; a<coba->tot; a++, cbd++) {
2006                 
2007                 v1[0]=v2[0]= x1+ cbd->pos*sizex;
2008                 
2009                 glColor4fv( &cbd->r );
2010                 glVertex2fv(v1); glVertex2fv(v2);
2011         }
2012         
2013         v1[0]=v2[0]= x1+ sizex;
2014         glVertex2fv(v1); glVertex2fv(v2);
2015         
2016         glEnd();
2017         glShadeModel(GL_FLAT);
2018         glDisable(GL_BLEND);
2019         
2020         /* outline */
2021         v1[0]= x1; v1[1]= y1;
2022         
2023         cpack(0x0);
2024         glBegin(GL_LINE_LOOP);
2025         glVertex2fv(v1);
2026         v1[0]+= sizex;
2027         glVertex2fv(v1);
2028         v1[1]+= sizey;
2029         glVertex2fv(v1);
2030         v1[0]-= sizex;
2031         glVertex2fv(v1);
2032         glEnd();
2033         
2034         
2035         /* help lines */
2036         v1[0]= v2[0]=v3[0]= x1;
2037         v1[1]= y1;
2038         v1a[1]= y1+0.25*sizey;
2039         v2[1]= y1+0.5*sizey;
2040         v2a[1]= y1+0.75*sizey;
2041         v3[1]= y1+sizey;
2042         
2043         
2044         cbd= coba->data;
2045         glBegin(GL_LINES);
2046         for(a=0; a<coba->tot; a++, cbd++) {
2047                 v1[0]=v2[0]=v3[0]=v1a[0]=v2a[0]= x1+ cbd->pos*sizex;
2048                 
2049                 if(a==coba->cur) {
2050                         glColor3ub(0, 0, 0);
2051                         glVertex2fv(v1);
2052                         glVertex2fv(v3);
2053                         glEnd();
2054                         
2055                         setlinestyle(2);
2056                         glBegin(GL_LINES);
2057                         glColor3ub(255, 255, 255);
2058                         glVertex2fv(v1);
2059                         glVertex2fv(v3);
2060                         glEnd();
2061                         setlinestyle(0);
2062                         glBegin(GL_LINES);
2063                         
2064                         /* glColor3ub(0, 0, 0);
2065                         glVertex2fv(v1);
2066                         glVertex2fv(v1a);
2067                         glColor3ub(255, 255, 255);
2068                         glVertex2fv(v1a);
2069                         glVertex2fv(v2);
2070                         glColor3ub(0, 0, 0);
2071                         glVertex2fv(v2);
2072                         glVertex2fv(v2a);
2073                         glColor3ub(255, 255, 255);
2074                         glVertex2fv(v2a);
2075                         glVertex2fv(v3);
2076                         */
2077                 }
2078                 else {
2079                         glColor3ub(0, 0, 0);
2080                         glVertex2fv(v1);
2081                         glVertex2fv(v2);
2082                         
2083                         glColor3ub(255, 255, 255);
2084                         glVertex2fv(v2);
2085                         glVertex2fv(v3);
2086                 }       
2087         }
2088         glEnd();
2089 }
2090
2091 static void ui_draw_but_NORMAL(uiBut *but)
2092 {
2093         static GLuint displist=0;
2094         int a, old[8];
2095         GLfloat diff[4], diffn[4]={1.0f, 1.0f, 1.0f, 1.0f};
2096         float vec0[4]={0.0f, 0.0f, 0.0f, 0.0f};
2097         float dir[4], size;
2098         
2099         /* store stuff */
2100         glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
2101                 
2102         /* backdrop */
2103         BIF_ThemeColor(TH_BUT_NEUTRAL);
2104         uiSetRoundBox(15);
2105         gl_round_box(GL_POLYGON, but->x1, but->y1, but->x2, but->y2, 5.0f);
2106         
2107         /* sphere color */
2108         glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn);
2109         glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
2110         
2111         /* disable blender light */
2112         for(a=0; a<8; a++) {
2113                 old[a]= glIsEnabled(GL_LIGHT0+a);
2114                 glDisable(GL_LIGHT0+a);
2115         }
2116         
2117         /* own light */
2118         glEnable(GL_LIGHT7);
2119         glEnable(GL_LIGHTING);
2120         
2121         VECCOPY(dir, (float *)but->poin);
2122         dir[3]= 0.0f;   /* glLight needs 4 args, 0.0 is sun */
2123         glLightfv(GL_LIGHT7, GL_POSITION, dir); 
2124         glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn); 
2125         glLightfv(GL_LIGHT7, GL_SPECULAR, vec0); 
2126         glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f);
2127         glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f);
2128         
2129         /* transform to button */
2130         glPushMatrix();
2131         glTranslatef(but->x1 + 0.5f*(but->x2-but->x1), but->y1+ 0.5f*(but->y2-but->y1), 0.0f);
2132         size= (but->x2-but->x1)/200.f;
2133         glScalef(size, size, size);
2134                          
2135         if(displist==0) {
2136                 GLUquadricObj   *qobj;
2137                 
2138                 displist= glGenLists(1);
2139                 glNewList(displist, GL_COMPILE_AND_EXECUTE);
2140                 
2141                 qobj= gluNewQuadric();
2142                 gluQuadricDrawStyle(qobj, GLU_FILL); 
2143                 glShadeModel(GL_SMOOTH);
2144                 gluSphere( qobj, 100.0, 32, 24);
2145                 glShadeModel(GL_FLAT);
2146                 gluDeleteQuadric(qobj);  
2147                 
2148                 glEndList();
2149         }
2150         else glCallList(displist);
2151         
2152         /* restore */
2153         glPopMatrix();
2154         glDisable(GL_LIGHTING);
2155         glDisable(GL_CULL_FACE);
2156         glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); 
2157         
2158         glDisable(GL_LIGHT7);
2159         
2160         /* enable blender light */
2161         for(a=0; a<8; a++) {
2162                 if(old[a])
2163                         glEnable(GL_LIGHT0+a);
2164         }
2165 }
2166
2167 static void ui_draw_but_curve_grid(uiBut *but, float zoomx, float zoomy, float offsx, float offsy, float step)
2168 {
2169         float dx, dy, fx, fy;
2170         
2171         glBegin(GL_LINES);
2172         dx= step*zoomx;
2173         fx= but->x1 + zoomx*(-offsx);
2174         if(fx > but->x1) fx -= dx*( floor(fx-but->x1));
2175         while(fx < but->x2) {
2176                 glVertex2f(fx, but->y1); 
2177                 glVertex2f(fx, but->y2);
2178                 fx+= dx;
2179         }
2180         
2181         dy= step*zoomy;
2182         fy= but->y1 + zoomy*(-offsy);
2183         if(fy > but->y1) fy -= dy*( floor(fy-but->y1));
2184         while(fy < but->y2) {
2185                 glVertex2f(but->x1, fy); 
2186                 glVertex2f(but->x2, fy);
2187                 fy+= dy;
2188         }
2189         glEnd();
2190         
2191 }
2192
2193 static void ui_draw_but_CURVE(uiBut *but)
2194 {
2195         CurveMapping *cumap= (CurveMapping *)but->poin;
2196         CurveMap *cuma= cumap->cm+cumap->cur;
2197         CurveMapPoint *cmp;
2198         float fx, fy, dx, dy, fac[2], zoomx, zoomy, offsx, offsy;
2199         GLint scissor[4];
2200         int a;
2201         
2202         /* need scissor test, curve can draw outside of boundary */
2203         glGetIntegerv(GL_VIEWPORT, scissor);
2204         fx= but->x1; fy= but->y1;
2205         ui_graphics_to_window(but->win, &fx, &fy);
2206         dx= but->x2; dy= but->y2;
2207         ui_graphics_to_window(but->win, &dx, &dy);
2208         glScissor((int)floor(fx), (int)floor(fy), (int)ceil(dx-fx), (int)ceil(dy-fy));
2209         
2210         /* calculate offset and zoom */
2211         zoomx= (but->x2-but->x1-2.0*but->aspect)/(cumap->curr.xmax - cumap->curr.xmin);
2212         zoomy= (but->y2-but->y1-2.0*but->aspect)/(cumap->curr.ymax - cumap->curr.ymin);
2213         offsx= cumap->curr.xmin-but->aspect/zoomx;
2214         offsy= cumap->curr.ymin-but->aspect/zoomy;
2215         
2216         /* backdrop */
2217         if(cumap->flag & CUMA_DO_CLIP) {
2218                 BIF_ThemeColorShade(TH_BUT_NEUTRAL, -20);
2219                 glRectf(but->x1, but->y1, but->x2, but->y2);
2220                 BIF_ThemeColor(TH_BUT_NEUTRAL);
2221                 glRectf(but->x1 + zoomx*(cumap->clipr.xmin-offsx),
2222                                 but->y1 + zoomy*(cumap->clipr.ymin-offsy),
2223                                 but->x1 + zoomx*(cumap->clipr.xmax-offsx),
2224                                 but->y1 + zoomy*(cumap->clipr.ymax-offsy));
2225         }
2226         else {
2227                 BIF_ThemeColor(TH_BUT_NEUTRAL);
2228                 glRectf(but->x1, but->y1, but->x2, but->y2);
2229         }
2230         
2231         /* grid, every .25 step */
2232         BIF_ThemeColorShade(TH_BUT_NEUTRAL, -16);
2233         ui_draw_but_curve_grid(but, zoomx, zoomy, offsx, offsy, 0.25f);
2234         /* grid, every 1.0 step */
2235         BIF_ThemeColorShade(TH_BUT_NEUTRAL, -24);
2236         ui_draw_but_curve_grid(but, zoomx, zoomy, offsx, offsy, 1.0f);
2237         /* axes */
2238         BIF_ThemeColorShade(TH_BUT_NEUTRAL, -50);
2239         glBegin(GL_LINES);
2240         glVertex2f(but->x1, but->y1 + zoomy*(-offsy));
2241         glVertex2f(but->x2, but->y1 + zoomy*(-offsy));
2242         glVertex2f(but->x1 + zoomx*(-offsx), but->y1);
2243         glVertex2f(but->x1 + zoomx*(-offsx), but->y2);
2244         glEnd();
2245         
2246         /* cfra option */
2247         if(cumap->flag & CUMA_DRAW_CFRA) {
2248                 glColor3ub(0x60, 0xc0, 0x40);
2249                 glBegin(GL_LINES);
2250                 glVertex2f(but->x1 + zoomx*(cumap->sample[0]-offsx), but->y1);
2251                 glVertex2f(but->x1 + zoomx*(cumap->sample[0]-offsx), but->y2);
2252                 glEnd();
2253         }
2254         /* sample option */
2255         if(cumap->flag & CUMA_DRAW_SAMPLE) {
2256                 if(cumap->cur==3) {
2257                         float lum= cumap->sample[0]*0.35f + cumap->sample[1]*0.45f + cumap->sample[2]*0.2f;
2258                         glColor3ub(240, 240, 240);
2259                         
2260                         glBegin(GL_LINES);
2261                         glVertex2f(but->x1 + zoomx*(lum-offsx), but->y1);
2262                         glVertex2f(but->x1 + zoomx*(lum-offsx), but->y2);
2263                         glEnd();
2264                 }
2265                 else {
2266                         if(cumap->cur==0)
2267                                 glColor3ub(240, 100, 100);
2268                         else if(cumap->cur==1)
2269                                 glColor3ub(100, 240, 100);
2270                         else
2271                                 glColor3ub(100, 100, 240);
2272                         
2273                         glBegin(GL_LINES);
2274                         glVertex2f(but->x1 + zoomx*(cumap->sample[cumap->cur]-offsx), but->y1);
2275                         glVertex2f(but->x1 + zoomx*(cumap->sample[cumap->cur]-offsx), but->y2);
2276                         glEnd();
2277                 }
2278         }
2279         
2280         /* the curve */
2281         BIF_ThemeColorBlend(TH_TEXT, TH_BUT_NEUTRAL, 0.35);
2282         glEnable(GL_LINE_SMOOTH);
2283         glEnable(GL_BLEND);
2284         glBegin(GL_LINE_STRIP);
2285         
2286         if(cuma->table==NULL)
2287                 curvemapping_changed(cumap, 0); /* 0 = no remove doubles */
2288         cmp= cuma->table;
2289         
2290         /* first point */
2291         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
2292                 glVertex2f(but->x1, but->y1 + zoomy*(cmp[0].y-offsy));
2293         else {
2294                 fx= but->x1 + zoomx*(cmp[0].x-offsx + cuma->ext_in[0]);
2295                 fy= but->y1 + zoomy*(cmp[0].y-offsy + cuma->ext_in[1]);
2296                 glVertex2f(fx, fy);
2297         }
2298         for(a=0; a<=CM_TABLE; a++) {
2299                 fx= but->x1 + zoomx*(cmp[a].x-offsx);
2300                 fy= but->y1 + zoomy*(cmp[a].y-offsy);
2301                 glVertex2f(fx, fy);
2302         }
2303         /* last point */
2304         if((cuma->flag & CUMA_EXTEND_EXTRAPOLATE)==0)
2305                 glVertex2f(but->x2, but->y1 + zoomy*(cmp[CM_TABLE].y-offsy));   
2306         else {
2307                 fx= but->x1 + zoomx*(cmp[CM_TABLE].x-offsx - cuma->ext_out[0]);
2308                 fy= but->y1 + zoomy*(cmp[CM_TABLE].y-offsy - cuma->ext_out[1]);
2309                 glVertex2f(fx, fy);
2310         }
2311         glEnd();
2312         glDisable(GL_LINE_SMOOTH);
2313         glDisable(GL_BLEND);
2314
2315         /* the points, use aspect to make them visible on edges */
2316         cmp= cuma->curve;
2317         glPointSize(3.0f);
2318         bglBegin(GL_POINTS);
2319         for(a=0; a<cuma->totpoint; a++) {
2320                 if(cmp[a].flag & SELECT)
2321                         BIF_ThemeColor(TH_TEXT_HI);
2322                 else
2323                         BIF_ThemeColor(TH_TEXT);
2324                 fac[0]= but->x1 + zoomx*(cmp[a].x-offsx);
2325                 fac[1]= but->y1 + zoomy*(cmp[a].y-offsy);
2326                 bglVertex2fv(fac);
2327         }
2328         bglEnd();
2329         glPointSize(1.0f);
2330         
2331         /* restore scissortest */
2332         glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
2333
2334         /* outline */
2335         BIF_ThemeColor(TH_BUT_OUTLINE);
2336         fdrawbox(but->x1, but->y1, but->x2, but->y2);
2337
2338 }
2339
2340 static void ui_draw_roundbox(uiBut *but)
2341 {
2342         glEnable(GL_BLEND);
2343         
2344         BIF_ThemeColorShadeAlpha(TH_PANEL, but->a2, but->a2);
2345
2346         uiSetRoundBox(but->a1);
2347         gl_round_box(GL_POLYGON, but->x1, but->y1, but->x2, but->y2, but->min);
2348
2349         glDisable(GL_BLEND);
2350 }
2351
2352
2353 /* nothing! */
2354 static void ui_draw_nothing(int type, int colorid, float asp, float x1, float y1, float x2, float y2, int flag)
2355 {
2356 }
2357
2358
2359 /* ************** EXTERN, called from interface.c ************* */
2360 /* ************** MAIN CALLBACK FUNCTION          ************* */
2361
2362 void ui_set_embossfunc(uiBut *but, int drawtype)
2363 {
2364         // this aded for evaluating textcolor for example
2365         but->dt= drawtype;
2366         
2367         // not really part of standard minimal themes, just make sure it is set
2368         but->sliderfunc= ui_draw_slider;
2369
2370         // standard builtin first:
2371         if(but->type==LABEL || but->type==ROUNDBOX) but->embossfunc= ui_draw_nothing;
2372         else if(but->type==PULLDOWN) but->embossfunc= ui_draw_pulldown_round;
2373         else if(drawtype==UI_EMBOSSM) but->embossfunc= ui_draw_minimal;
2374         else if(drawtype==UI_EMBOSSN) but->embossfunc= ui_draw_nothing;
2375         else if(drawtype==UI_EMBOSSP) but->embossfunc= ui_draw_pulldown_item;
2376         else if(drawtype==UI_EMBOSSR) but->embossfunc= ui_draw_round;
2377         else {
2378                 int theme= BIF_GetThemeValue(TH_BUT_DRAWTYPE);
2379                 
2380                 switch(theme) {
2381                 
2382                 case TH_ROUNDED:
2383                         but->embossfunc= ui_draw_round;
2384                         break;
2385                 case TH_OLDSKOOL:
2386                         but->embossfunc= ui_draw_oldskool;
2387                         break;
2388                 case TH_MINIMAL:
2389                         but->embossfunc= ui_draw_minimal;
2390                         break;
2391                 case TH_SHADED:
2392                 default:
2393                         but->embossfunc= ui_draw_default;
2394                         but->sliderfunc= ui_default_slider;
2395                         break;
2396                 }
2397         }
2398         
2399         // note: if you want aligning, adapt the call uiBlockEndAlign in interface.c 
2400 }
2401
2402 void ui_draw_but(uiBut *but)
2403 {
2404         double value;
2405         float x1, x2, y1, y2, fac;
2406         
2407         if(but==NULL) return;
2408
2409         /* signal for frontbuf flush buttons and menus, not when normal drawing */
2410         if(but->block->in_use) ui_block_set_flush(but->block, but);
2411                 
2412         switch (but->type) {
2413
2414         case NUMSLI:
2415         case HSVSLI:
2416         
2417                 but->embossfunc(but->type, but->themecol, but->aspect, but->x1, but->y1, but->x2, but->y2, but->flag);
2418                 ui_draw_text_icon(but);
2419
2420                 x1= (but->x1+but->x2)/2;
2421                 x2= but->x2 - 5.0*but->aspect;
2422                 y1= but->y1 + 2.0*but->aspect;
2423                 y2= but->y2 - 2.0*but->aspect;
2424                 
2425                 value= ui_get_but_val(but);
2426                 fac= (value-but->min)*(x2-x1)/(but->max - but->min);
2427                 
2428                 but->sliderfunc(but->themecol, fac, but->aspect, x1, y1, x2, y2, but->flag);
2429                 break;
2430                 
2431         case SEPR:
2432                 //  only background
2433                 break;
2434                 
2435         case COL:
2436                 ui_draw_but_COL(but);  // black box with color
2437                 break;
2438
2439         case HSVCUBE:
2440                 ui_draw_but_HSVCUBE(but);  // box for colorpicker, three types
2441                 break;
2442
2443 #ifdef INTERNATIONAL
2444         case CHARTAB:
2445                 value= ui_get_but_val(but);
2446                 ui_draw_but_CHARTAB(but);
2447                 break;
2448 #endif
2449
2450         case LINK:
2451         case INLINK:
2452                 ui_draw_icon(but, but->icon, 0);
2453                 break;
2454                 
2455         case ROUNDBOX:
2456                 ui_draw_roundbox(but);
2457                 break;
2458                 
2459         case BUT_COLORBAND:
2460                 ui_draw_but_COLORBAND(but);
2461                 break;
2462         case BUT_NORMAL:
2463                 ui_draw_but_NORMAL(but);
2464                 break;
2465         case BUT_CURVE:
2466                 ui_draw_but_CURVE(but);
2467                 break;
2468                 
2469         default:
2470                 but->embossfunc(but->type, but->themecol, but->aspect, but->x1, but->y1, but->x2, but->y2, but->flag);
2471                 ui_draw_text_icon(but);
2472         
2473         }
2474 }
2475
2476 void ui_dropshadow(rctf *rct, float radius, float aspect, int select)
2477 {
2478         float rad;
2479         float a;
2480         char alpha= 2;
2481         
2482         glEnable(GL_BLEND);
2483         
2484         if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f)
2485                 rad= (rct->ymax-rct->ymin-10.0f)/2.0f;
2486         else
2487                 rad= radius;
2488         
2489         if(select) a= 12.0f*aspect; else a= 12.0f*aspect;
2490         for(; a>0.0f; a-=aspect) {
2491                 /* alpha ranges from 2 to 20 or so */
2492                 glColor4ub(0, 0, 0, alpha);
2493                 alpha+= 2;
2494                 
2495                 gl_round_box(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a);
2496         }
2497         
2498         /* outline emphasis */
2499         glEnable( GL_LINE_SMOOTH );
2500         glColor4ub(0, 0, 0, 100);
2501         gl_round_box(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius);
2502         glDisable( GL_LINE_SMOOTH );
2503         
2504         glDisable(GL_BLEND);
2505 }