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