soc-2008-mxcurioni: foundations for Freestyle as a render layer - new UI buttons...
[blender.git] / source / blender / src / resources.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <math.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #include "MEM_guardedalloc.h"
39
40 #include "DNA_listBase.h"
41 #include "DNA_userdef_types.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_space_types.h"
44
45 #include "IMB_imbuf.h"
46 #include "IMB_imbuf_types.h"
47
48 #include "BKE_utildefines.h"
49
50 #include "BIF_gl.h"
51 #include "BIF_resources.h"
52 #include "BIF_interface_icons.h"
53
54 #include "BLI_blenlib.h"
55 #include "blendef.h"    // CLAMP
56 #include "datatoc.h"
57
58 /* global for themes */
59 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
60
61 static bTheme *theme_active=NULL;
62 static int theme_spacetype= SPACE_VIEW3D;
63
64
65 void BIF_resources_init(void)
66 {
67         BIF_icons_init(BIFICONID_LAST+1);
68 }
69
70 void BIF_resources_free(void)
71 {
72         BIF_icons_free();
73 }
74
75
76 /* ******************************************************** */
77 /*    THEMES */
78 /* ******************************************************** */
79
80 char *BIF_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
81 {
82         ThemeSpace *ts= NULL;
83         static char error[4]={240, 0, 240, 255};
84         static char alert[4]={240, 60, 60, 255};
85         static char headerdesel[4]={0,0,0,255};
86         static char custom[4]={0,0,0,255};
87         
88         char *cp= error;
89         
90         if(btheme) {
91         
92                 // first check for ui buttons theme
93                 if(colorid < TH_THEMEUI) {
94                 
95                         switch(colorid) {
96                         case TH_BUT_OUTLINE:
97                                 cp= btheme->tui.outline; break;
98                         case TH_BUT_NEUTRAL:
99                                 cp= btheme->tui.neutral; break;
100                         case TH_BUT_ACTION:
101                                 cp= btheme->tui.action; break;
102                         case TH_BUT_SETTING:
103                                 cp= btheme->tui.setting; break;
104                         case TH_BUT_SETTING1:
105                                 cp= btheme->tui.setting1; break;
106                         case TH_BUT_SETTING2:
107                                 cp= btheme->tui.setting2; break;
108                         case TH_BUT_NUM:
109                                 cp= btheme->tui.num; break;
110                         case TH_BUT_TEXTFIELD:
111                                 cp= btheme->tui.textfield; break;
112                         case TH_BUT_TEXTFIELD_HI:
113                                 cp= btheme->tui.textfield_hi; break;
114                         case TH_BUT_POPUP:
115                                 cp= btheme->tui.popup; break;
116                         case TH_BUT_TEXT:
117                                 cp= btheme->tui.text; break;
118                         case TH_BUT_TEXT_HI:
119                                 cp= btheme->tui.text_hi; break;
120                         case TH_MENU_BACK:
121                                 cp= btheme->tui.menu_back; break;
122                         case TH_MENU_ITEM:
123                                 cp= btheme->tui.menu_item; break;
124                         case TH_MENU_HILITE:
125                                 cp= btheme->tui.menu_hilite; break;
126                         case TH_MENU_TEXT:
127                                 cp= btheme->tui.menu_text; break;
128                         case TH_MENU_TEXT_HI:
129                                 cp= btheme->tui.menu_text_hi; break;
130                         
131                         case TH_BUT_DRAWTYPE:
132                                 cp= &btheme->tui.but_drawtype; break;
133
134                         case TH_ICONFILE:
135                                 cp= btheme->tui.iconfile; break;
136                                 
137                         case TH_REDALERT:
138                                 cp= alert; break;
139                         case TH_CUSTOM:
140                                 cp= custom; break;
141                         }
142                 }
143                 else {
144                 
145                         switch(spacetype) {
146                         case SPACE_BUTS:
147                                 ts= &btheme->tbuts;
148                                 break;
149                         case SPACE_VIEW3D:
150                                 ts= &btheme->tv3d;
151                                 break;
152                         case SPACE_IPO:
153                                 ts= &btheme->tipo;
154                                 break;
155                         case SPACE_FILE:
156                                 ts= &btheme->tfile;
157                                 break;
158                         case SPACE_NLA:
159                                 ts= &btheme->tnla;
160                                 break;
161                         case SPACE_ACTION:
162                                 ts= &btheme->tact;
163                                 break;
164                         case SPACE_SEQ:
165                                 ts= &btheme->tseq;
166                                 break;
167                         case SPACE_IMAGE:
168                                 ts= &btheme->tima;
169                                 break;
170                         case SPACE_IMASEL:
171                                 ts= &btheme->timasel;
172                                 break;
173                         case SPACE_TEXT:
174                                 ts= &btheme->text;
175                                 break;
176                         case SPACE_OOPS:
177                                 ts= &btheme->toops;
178                                 break;
179                         case SPACE_SOUND:
180                                 ts= &btheme->tsnd;
181                                 break;
182                         case SPACE_INFO:
183                                 ts= &btheme->tinfo;
184                                 break;
185                         case SPACE_TIME:
186                                 ts= &btheme->ttime;
187                                 break;
188                         case SPACE_NODE:
189                                 ts= &btheme->tnode;
190                                 break;
191                         default:
192                                 ts= &btheme->tv3d;
193                                 break;
194                         }
195                         
196                         switch(colorid) {
197                         case TH_BACK:
198                                 cp= ts->back; break;
199                         case TH_TEXT:
200                                 cp= ts->text; break;
201                         case TH_TEXT_HI:
202                                 cp= ts->text_hi; break;
203                         case TH_HEADER:
204                                 cp= ts->header; break;
205                         case TH_HEADERDESEL:
206                                 /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
207                                 cp= ts->header; 
208                                 headerdesel[0]= cp[0]>10?cp[0]-10:0;
209                                 headerdesel[1]= cp[1]>10?cp[1]-10:0;
210                                 headerdesel[2]= cp[2]>10?cp[2]-10:0;
211                                 cp= headerdesel;
212                                 break;
213                         case TH_PANEL:
214                                 cp= ts->panel; break;
215                         case TH_SHADE1:
216                                 cp= ts->shade1; break;
217                         case TH_SHADE2:
218                                 cp= ts->shade2; break;
219                         case TH_HILITE:
220                                 cp= ts->hilite; break;
221                                 
222                         case TH_GRID:
223                                 cp= ts->grid; break;
224                         case TH_WIRE:
225                                 cp= ts->wire; break;
226                         case TH_LAMP:
227                                 cp= ts->lamp; break;
228                         case TH_SELECT:
229                                 cp= ts->select; break;
230                         case TH_ACTIVE:
231                                 cp= ts->active; break;
232                         case TH_GROUP:
233                                 cp= ts->group; break;
234                         case TH_GROUP_ACTIVE:
235                                 cp= ts->group_active; break;
236                         case TH_TRANSFORM:
237                                 cp= ts->transform; break;
238                         case TH_VERTEX:
239                                 cp= ts->vertex; break;
240                         case TH_VERTEX_SELECT:
241                                 cp= ts->vertex_select; break;
242                         case TH_VERTEX_SIZE:
243                                 cp= &ts->vertex_size; break;
244                         case TH_EDGE:
245                                 cp= ts->edge; break;
246                         case TH_EDGE_SELECT:
247                                 cp= ts->edge_select; break;
248                         case TH_EDGE_SEAM:
249                                 cp= ts->edge_seam; break;
250                         case TH_EDGE_SHARP:
251                                 cp= ts->edge_sharp; break;
252                         case TH_EDITMESH_ACTIVE:
253                                 cp= ts->editmesh_active; break;
254                         case TH_EDGE_FACESEL:
255                                 cp= ts->edge_facesel; break;
256                         case TH_FACE:
257                                 cp= ts->face; break;
258                         case TH_FACE_SELECT:
259                                 cp= ts->face_select; break;
260                         case TH_FACE_DOT:
261                                 cp= ts->face_dot; break;
262                         case TH_FACEDOT_SIZE:
263                                 cp= &ts->facedot_size; break;
264                         case TH_NORMAL:
265                                 cp= ts->normal; break;
266                         case TH_BONE_SOLID:
267                                 cp= ts->bone_solid; break;
268                         case TH_BONE_POSE:
269                                 cp= ts->bone_pose; break;
270                         case TH_STRIP:
271                                 cp= ts->strip; break;
272                         case TH_STRIP_SELECT:
273                                 cp= ts->strip_select; break;
274                         case TH_CFRAME:
275                                 cp= ts->cframe; break;
276                                 
277                         case TH_SYNTAX_B:
278                                 cp= ts->syntaxb; break;
279                         case TH_SYNTAX_V:
280                                 cp= ts->syntaxv; break;
281                         case TH_SYNTAX_C:
282                                 cp= ts->syntaxc; break;
283                         case TH_SYNTAX_L:
284                                 cp= ts->syntaxl; break;
285                         case TH_SYNTAX_N:
286                                 cp= ts->syntaxn; break;
287
288                         case TH_NODE:
289                                 cp= ts->syntaxl; break;
290                         case TH_NODE_IN_OUT:
291                                 cp= ts->syntaxn; break;
292                         case TH_NODE_OPERATOR:
293                                 cp= ts->syntaxb; break;
294                         case TH_NODE_CONVERTOR:
295                                 cp= ts->syntaxv; break;
296                         case TH_NODE_GROUP:
297                                 cp= ts->syntaxc; break;
298                                 
299                         case TH_SEQ_MOVIE:
300                                 cp= ts->movie; break;
301                         case TH_SEQ_IMAGE:
302                                 cp= ts->image; break;
303                         case TH_SEQ_SCENE:
304                                 cp= ts->scene; break;
305                         case TH_SEQ_AUDIO:
306                                 cp= ts->audio; break;
307                         case TH_SEQ_EFFECT:
308                                 cp= ts->effect; break;
309                         case TH_SEQ_PLUGIN:
310                                 cp= ts->plugin; break;
311                         case TH_SEQ_TRANSITION:
312                                 cp= ts->transition; break;
313                         case TH_SEQ_META:
314                                 cp= ts->meta; break;
315                                 
316                         }
317
318                 }
319         }
320         
321         return cp;
322 }
323
324 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
325
326 /* initialize
327    Note: when you add new colors, created & saved themes need initialized
328    in usiblender.c, search for "versionfile"
329 */
330 void BIF_InitTheme(void)
331 {
332         bTheme *btheme= U.themes.first;
333         
334         /* we search for the theme with name Default */
335         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
336                 if(strcmp("Default", btheme->name)==0) break;
337         }
338         
339         if(btheme==NULL) {
340                 btheme= MEM_callocN(sizeof(bTheme), "theme");
341                 BLI_addtail(&U.themes, btheme);
342                 strcpy(btheme->name, "Default");
343         }
344         
345         BIF_SetTheme(NULL);     // make sure the global used in this file is set
346
347         /* UI buttons (todo) */
348         SETCOL(btheme->tui.outline,     0xA0,0xA0,0xA0, 255);
349         SETCOL(btheme->tui.neutral,     0xA0,0xA0,0xA0, 255);
350         SETCOL(btheme->tui.action,              0xAD,0xA0,0x93, 255);
351         SETCOL(btheme->tui.setting,     0x8A,0x9E,0xA1, 255);
352         SETCOL(btheme->tui.setting1,    0xA1,0xA1,0xAE, 255);
353         SETCOL(btheme->tui.setting2,    0xA1,0x99,0xA7, 255);
354         SETCOL(btheme->tui.num,                 0x90,0x90,0x90, 255);
355         SETCOL(btheme->tui.textfield,   0x90,0x90,0x90, 255);
356         SETCOL(btheme->tui.textfield_hi,0xc6,0x77,0x77, 255);
357         SETCOL(btheme->tui.popup,               0xA0,0xA0,0xA0, 255);
358         
359         SETCOL(btheme->tui.text,                0,0,0, 255);
360         SETCOL(btheme->tui.text_hi,     255, 255, 255, 255);
361         
362         SETCOL(btheme->tui.menu_back,   0xD2,0xD2,0xD2, 255);
363         SETCOL(btheme->tui.menu_item,   0xDA,0xDA,0xDA, 255);
364         SETCOL(btheme->tui.menu_hilite, 0x7F,0x7F,0x7F, 255);
365         SETCOL(btheme->tui.menu_text,   0, 0, 0, 255);
366         SETCOL(btheme->tui.menu_text_hi, 255, 255, 255, 255);
367         btheme->tui.but_drawtype= TH_SHADED;
368         
369         BLI_strncpy(btheme->tui.iconfile, "", sizeof(btheme->tui.iconfile));
370         
371         /* bone color sets */
372                 /* set 1 */
373         SETCOL(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
374         SETCOL(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
375         SETCOL(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
376                 /* set 2 */
377         SETCOL(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
378         SETCOL(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
379         SETCOL(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
380             /* set 3 */
381         SETCOL(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
382         SETCOL(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
383         SETCOL(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
384                 /* set 4 */
385         SETCOL(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
386         SETCOL(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
387         SETCOL(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
388                 /* set 5 */
389         SETCOL(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
390         SETCOL(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
391         SETCOL(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
392                 /* set 6 */
393         SETCOL(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
394         SETCOL(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
395         SETCOL(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
396                 /* set 7 */
397         SETCOL(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
398         SETCOL(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
399         SETCOL(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
400                 /* set 8 */
401         SETCOL(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
402         SETCOL(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
403         SETCOL(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
404                 /* set 9 */
405         SETCOL(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
406         SETCOL(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
407         SETCOL(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
408                 /* set 10 */
409         SETCOL(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
410         SETCOL(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
411         SETCOL(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
412                 /* set 11 */
413         SETCOL(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
414         SETCOL(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
415         SETCOL(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
416                 /* set 12 */
417         SETCOL(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
418         SETCOL(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
419         SETCOL(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
420                 /* set 13 */
421         SETCOL(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
422         SETCOL(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
423         SETCOL(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
424                 /* set 14 */
425         SETCOL(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
426         SETCOL(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
427         SETCOL(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
428                 /* set 15 */
429         SETCOL(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
430         SETCOL(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
431         SETCOL(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
432         
433         /* space view3d */
434         SETCOL(btheme->tv3d.back,       115, 115, 115, 255);
435         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
436         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
437         SETCOL(btheme->tv3d.header, 195, 195, 195, 255);
438         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
439         
440         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
441         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
442
443         SETCOL(btheme->tv3d.grid,       92, 92, 92, 255);
444         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
445         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
446         SETCOL(btheme->tv3d.select, 0xff, 0x88, 0xff, 255);
447         SETCOL(btheme->tv3d.active, 0xff, 0xbb, 0xff, 255);
448         SETCOL(btheme->tv3d.group, 0x10, 0x40, 0x10, 255);
449         SETCOL(btheme->tv3d.group_active, 0x55, 0xbb, 0x55, 255);
450         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
451         SETCOL(btheme->tv3d.vertex, 0xff, 0x70, 0xff, 255);
452         SETCOL(btheme->tv3d.vertex_select, 0xff, 0xff, 0x70, 255);
453         btheme->tv3d.vertex_size= 2;
454         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
455         SETCOL(btheme->tv3d.edge_select, 0xb0, 0xb0, 0x30, 255);
456         SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
457         SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
458         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
459         SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
460         
461         SETCOL(btheme->tv3d.face,       0, 50, 150, 30);
462         SETCOL(btheme->tv3d.face_select, 200, 100, 200, 60);
463         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
464         SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
465         btheme->tv3d.facedot_size= 4;
466         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
467         
468         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
469         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
470         
471         
472         /* space buttons */
473         /* to have something initialized */
474         btheme->tbuts= btheme->tv3d;
475
476         SETCOL(btheme->tbuts.back,      180, 180, 180, 255);
477         SETCOL(btheme->tbuts.header, 195, 195, 195, 255);
478         SETCOL(btheme->tbuts.panel,  255, 255, 255, 40);
479
480         /* space ipo */
481         /* to have something initialized */
482         btheme->tipo= btheme->tv3d;
483
484         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
485         SETCOL(btheme->tipo.back,       120, 120, 120, 255);
486         SETCOL(btheme->tipo.header, 195, 195, 195, 255);
487         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
488         SETCOL(btheme->tipo.shade1,  172, 172, 172, 100);
489         SETCOL(btheme->tipo.shade2,  0x70, 0x70, 0x70, 100);
490         SETCOL(btheme->tipo.vertex, 0xff, 0x70, 0xff, 255);
491         SETCOL(btheme->tipo.vertex_select, 0xff, 0xff, 0x70, 255);
492         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
493         btheme->tipo.vertex_size= 3;
494
495         /* space file */
496         /* to have something initialized */
497         btheme->tfile= btheme->tv3d;
498         SETCOL(btheme->tfile.back,      128, 128, 128, 255);
499         SETCOL(btheme->tfile.text,      0, 0, 0, 255);
500         SETCOL(btheme->tfile.text_hi, 255, 255, 255, 255);
501         SETCOL(btheme->tfile.header, 182, 182, 182, 255);
502         SETCOL(btheme->tfile.hilite, 0xA0, 0xA0, 0xD0, 255); // selected files
503
504         
505         /* space action */
506         btheme->tact= btheme->tv3d;
507         SETCOL(btheme->tact.back,       116, 116, 116, 255);
508         SETCOL(btheme->tact.text,       0, 0, 0, 255);
509         SETCOL(btheme->tact.text_hi, 255, 255, 255, 255);
510         SETCOL(btheme->tact.header, 182, 182, 182, 255);
511         SETCOL(btheme->tact.grid,  94, 94, 94, 255);
512         SETCOL(btheme->tact.face,  166, 166, 166, 255); // RVK
513         SETCOL(btheme->tact.shade1,  172, 172, 172, 255);               // sliders
514         SETCOL(btheme->tact.shade2,  84, 44, 31, 100);  // bar
515         SETCOL(btheme->tact.hilite,  17, 27, 60, 100);  // bar
516         SETCOL(btheme->tact.strip_select,       0xff, 0xff, 0xaa, 255);
517         SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 255);
518         SETCOL(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
519         SETCOL(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
520
521         /* space nla */
522         btheme->tnla= btheme->tv3d;
523         SETCOL(btheme->tnla.back,       116, 116, 116, 255);
524         SETCOL(btheme->tnla.text,       0, 0, 0, 255);
525         SETCOL(btheme->tnla.text_hi, 255, 255, 255, 255);
526         SETCOL(btheme->tnla.header, 182, 182, 182, 255);
527         SETCOL(btheme->tnla.grid,  94, 94, 94, 255);    
528         SETCOL(btheme->tnla.shade1,  172, 172, 172, 255);               // sliders
529         SETCOL(btheme->tnla.shade2,  84, 44, 31, 100);  // bar
530         SETCOL(btheme->tnla.hilite,  17, 27, 60, 100);  // bar
531         SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
532         SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
533         
534         /* space seq */
535         btheme->tseq= btheme->tv3d;
536         SETCOL(btheme->tseq.back,       116, 116, 116, 255);
537         SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
538         SETCOL(btheme->tseq.image,      109, 88, 129, 255);
539         SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
540         SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
541         SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
542         SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
543         SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
544         SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
545         
546
547         /* space image */
548         btheme->tima= btheme->tv3d;
549         SETCOL(btheme->tima.back,       53, 53, 53, 255);
550         SETCOL(btheme->tima.vertex, 0xff, 0x70, 0xff, 255);
551         SETCOL(btheme->tima.vertex_select, 0xff, 0xff, 0x70, 255);
552         btheme->tima.vertex_size= 2;
553         SETCOL(btheme->tima.face,   0, 50, 150, 40);
554         SETCOL(btheme->tima.face_select, 200, 100, 200, 80);
555
556         /* space imageselect */
557         btheme->timasel= btheme->tv3d;
558         SETCOL(btheme->timasel.active,  195, 195, 195, 255); /* active tile */
559         SETCOL(btheme->timasel.grid,  94, 94, 94, 255); /* active file text */
560         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
561         SETCOL(btheme->timasel.header,  195, 195, 195, 255);    
562         SETCOL(btheme->timasel.shade1,  94, 94, 94, 255);       /* bar */
563         SETCOL(btheme->timasel.shade2,  172, 172, 172, 255); /* sliders */
564         SETCOL(btheme->timasel.hilite,  17, 27, 60, 100);       /* selected tile */
565         SETCOL(btheme->timasel.text,    0, 0, 0, 255);
566         SETCOL(btheme->timasel.text_hi, 255, 255, 255, 255);
567         SETCOL(btheme->timasel.panel,   132, 132, 132, 255);
568
569         /* space text */
570         btheme->text= btheme->tv3d;
571         SETCOL(btheme->text.back,       153, 153, 153, 255);
572         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
573         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
574         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
575         
576         /* syntax highlighting */
577         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
578         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
579         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
580         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
581         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
582         
583         /* space oops */
584         btheme->toops= btheme->tv3d;
585         SETCOL(btheme->toops.back,      153, 153, 153, 255);
586
587         /* space info */
588         btheme->tinfo= btheme->tv3d;
589         SETCOL(btheme->tinfo.back,      153, 153, 153, 255);
590
591         /* space sound */
592         btheme->tsnd= btheme->tv3d;
593         SETCOL(btheme->tsnd.back,       153, 153, 153, 255);
594         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
595         SETCOL(btheme->tsnd.grid, 140, 140, 140, 255);
596         
597         /* space time */
598         btheme->ttime= btheme->tsnd;    // same as sound space
599         
600         /* space node, re-uses syntax color storage */
601         btheme->tnode= btheme->tv3d;
602         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
603         SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
604         SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
605         SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
606         SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
607         SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
608
609 }
610
611 char *BIF_ThemeColorsPup(int spacetype)
612 {
613         char *cp= MEM_callocN(32*64, "theme pup");
614         char *str = cp;
615         
616         if(spacetype==0) {
617                 str += sprintf(str, "Outline %%x%d|", TH_BUT_OUTLINE);
618                 str += sprintf(str, "Neutral %%x%d|", TH_BUT_NEUTRAL);
619                 str += sprintf(str, "Action %%x%d|", TH_BUT_ACTION);
620                 str += sprintf(str, "Setting %%x%d|", TH_BUT_SETTING);
621                 str += sprintf(str, "Special Setting 1%%x%d|", TH_BUT_SETTING1);
622                 str += sprintf(str, "Special Setting 2 %%x%d|", TH_BUT_SETTING2);
623                 str += sprintf(str, "Number Input %%x%d|", TH_BUT_NUM);
624                 str += sprintf(str, "Text Input %%x%d|", TH_BUT_TEXTFIELD);
625                 str += sprintf(str, "Text Input Highlight %%x%d|", TH_BUT_TEXTFIELD_HI);
626                 str += sprintf(str, "Popup %%x%d|", TH_BUT_POPUP);
627                 str += sprintf(str, "Text %%x%d|", TH_BUT_TEXT);
628                 str += sprintf(str, "Text Highlight %%x%d|", TH_BUT_TEXT_HI);
629                 str += sprintf(str, "%%l|");
630                 str += sprintf(str, "Menu Background %%x%d|", TH_MENU_BACK);
631                 str += sprintf(str, "Menu Item %%x%d|", TH_MENU_ITEM);
632                 str += sprintf(str, "Menu Item Highlight %%x%d|", TH_MENU_HILITE);
633                 str += sprintf(str, "Menu Text %%x%d|", TH_MENU_TEXT);
634                 str += sprintf(str, "Menu Text Highlight %%x%d|", TH_MENU_TEXT_HI);
635                 str += sprintf(str, "%%l|");
636                 str += sprintf(str, "Drawtype %%x%d|", TH_BUT_DRAWTYPE);
637                 str += sprintf(str, "%%l|");
638                 str += sprintf(str, "Icon File %%x%d|", TH_ICONFILE);
639         }
640         else {
641                 // first defaults for each space
642                 str += sprintf(str, "Background %%x%d|", TH_BACK);
643                 str += sprintf(str, "Text %%x%d|", TH_TEXT);
644                 str += sprintf(str, "Text Highlight %%x%d|", TH_TEXT_HI);
645                 str += sprintf(str, "Header %%x%d|", TH_HEADER);
646                 
647                 switch(spacetype) {
648                 case SPACE_VIEW3D:
649                         str += sprintf(str, "Panel %%x%d|", TH_PANEL);
650                         str += sprintf(str, "%%l|");
651                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
652                         str += sprintf(str, "Wire %%x%d|", TH_WIRE);
653                         str += sprintf(str, "Lamp %%x%d|", TH_LAMP);
654                         str += sprintf(str, "Object Selected %%x%d|", TH_SELECT);
655                         str += sprintf(str, "Object Active %%x%d|", TH_ACTIVE);
656                         str += sprintf(str, "Object Grouped %%x%d|", TH_GROUP);
657                         str += sprintf(str, "Object Grouped Active %%x%d|", TH_GROUP_ACTIVE);
658                         str += sprintf(str, "Transform %%x%d|", TH_TRANSFORM);
659                         str += sprintf(str, "%%l|");
660                         str += sprintf(str, "Vertex %%x%d|", TH_VERTEX);
661                         str += sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT);
662                         str += sprintf(str, "Vertex Size %%x%d|", TH_VERTEX_SIZE);
663                         str += sprintf(str, "Edge Selected %%x%d|", TH_EDGE_SELECT);
664                         str += sprintf(str, "Edge Seam %%x%d|", TH_EDGE_SEAM);
665                         str += sprintf(str, "Edge Sharp %%x%d|", TH_EDGE_SHARP);
666                         str += sprintf(str, "Edge UV Face Select %%x%d|", TH_EDGE_FACESEL);
667                         str += sprintf(str, "Face (transp) %%x%d|", TH_FACE);
668                         str += sprintf(str, "Face Selected (transp) %%x%d|", TH_FACE_SELECT);
669                         str += sprintf(str, "Face Dot Selected %%x%d|", TH_FACE_DOT);
670                         str += sprintf(str, "Face Dot Size %%x%d|", TH_FACEDOT_SIZE);
671                         str += sprintf(str, "Active Vert/Edge/Face %%x%d|", TH_EDITMESH_ACTIVE);
672                         str += sprintf(str, "Normal %%x%d|", TH_NORMAL);
673                         str += sprintf(str, "Bone Solid %%x%d|", TH_BONE_SOLID);
674                         str += sprintf(str, "Bone Pose %%x%d|", TH_BONE_POSE);
675                         str += sprintf(str, "Current Frame %%x%d", TH_CFRAME);
676                         break;
677                 case SPACE_IPO:
678                         str += sprintf(str, "Panel %%x%d|", TH_PANEL);
679                         str += sprintf(str, "%%l|");
680                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
681                         str += sprintf(str, "Window Sliders %%x%d|", TH_SHADE1);
682                         str += sprintf(str, "Ipo Channels %%x%d|", TH_SHADE2);
683                         str += sprintf(str, "Vertex %%x%d|", TH_VERTEX);
684                         str += sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT);
685                         str += sprintf(str, "Vertex Size %%x%d|", TH_VERTEX_SIZE);
686                         str += sprintf(str, "Current Frame %%x%d", TH_CFRAME);
687                         break;
688                 case SPACE_FILE:
689                         str += sprintf(str, "Selected file %%x%d", TH_HILITE);
690                         break;
691                 case SPACE_NLA:
692                         //str += sprintf(str, "Panel %%x%d|", TH_PANEL);
693                         str += sprintf(str, "%%l|");
694                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
695                         str += sprintf(str, "View Sliders %%x%d|", TH_SHADE1);
696                         str += sprintf(str, "Bars %%x%d|", TH_SHADE2);
697                         str += sprintf(str, "Bars selected %%x%d|", TH_HILITE);
698                         str += sprintf(str, "Strips %%x%d|", TH_STRIP);
699                         str += sprintf(str, "Strips selected %%x%d|", TH_STRIP_SELECT);
700                         str += sprintf(str, "Current Frame %%x%d", TH_CFRAME);
701                         break;
702                 case SPACE_ACTION:
703                         //str += sprintf(str, "Panel %%x%d|", TH_PANEL);
704                         str += sprintf(str, "%%l|");
705                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
706                         str += sprintf(str, "RVK Sliders %%x%d|", TH_FACE);
707                         str += sprintf(str, "View Sliders %%x%d|", TH_SHADE1);
708                         str += sprintf(str, "Channels %%x%d|", TH_SHADE2);
709                         str += sprintf(str, "Channels Selected %%x%d|", TH_HILITE);
710                         str += sprintf(str, "Channel Group %%x%d|", TH_GROUP);
711                         str += sprintf(str, "Active Channel Group %%x%d|", TH_GROUP_ACTIVE);
712                         str += sprintf(str, "Long Key %%x%d|", TH_STRIP);
713                         str += sprintf(str, "Long Key selected %%x%d|", TH_STRIP_SELECT);
714                         str += sprintf(str, "Current Frame %%x%d", TH_CFRAME);
715                         break;
716                 case SPACE_IMAGE:
717                         str += sprintf(str, "%%l|");
718                         str += sprintf(str, "Vertex %%x%d|", TH_VERTEX);
719                         str += sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT);
720                         str += sprintf(str, "Vertex Size %%x%d|", TH_VERTEX_SIZE);
721                         str += sprintf(str, "Face %%x%d|", TH_FACE);
722                         str += sprintf(str, "Face Selected %%x%d", TH_FACE_SELECT);
723                         str += sprintf(str, "Face Dot Selected %%x%d|", TH_FACE_DOT);
724                         str += sprintf(str, "Face Dot Size %%x%d|", TH_FACEDOT_SIZE);
725                         str += sprintf(str, "Active Vert/Edge/Face %%x%d|", TH_EDITMESH_ACTIVE);
726                         break;
727                 case SPACE_SEQ:
728                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
729                         str += sprintf(str, "Window Sliders %%x%d|", TH_SHADE1);
730                         str += sprintf(str, "%%l|");
731                         str += sprintf(str, "Movie Strip %%x%d|", TH_SEQ_MOVIE);
732                         str += sprintf(str, "Image Strip %%x%d|", TH_SEQ_IMAGE);
733                         str += sprintf(str, "Scene Strip %%x%d|", TH_SEQ_SCENE);
734                         str += sprintf(str, "Audio Strip %%x%d|", TH_SEQ_AUDIO);
735                         str += sprintf(str, "Effect Strip %%x%d|", TH_SEQ_EFFECT);
736                         str += sprintf(str, "Plugin Strip %%x%d|", TH_SEQ_PLUGIN);
737                         str += sprintf(str, "Transition Strip %%x%d|", TH_SEQ_TRANSITION);
738                         str += sprintf(str, "Meta Strip %%x%d|", TH_SEQ_META);
739                         str += sprintf(str, "Current Frame %%x%d", TH_CFRAME);
740                         break;
741                 case SPACE_SOUND:
742                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
743                         str += sprintf(str, "Window Slider %%x%d|", TH_SHADE1);
744                         str += sprintf(str, "Current Frame %%x%d", TH_CFRAME);
745                         break;
746                 case SPACE_BUTS:
747                         str += sprintf(str, "Panel %%x%d|", TH_PANEL);
748                         break;
749                 case SPACE_IMASEL:
750                         str += sprintf(str, "Tiles %%x%d|", TH_PANEL);
751                         str += sprintf(str, "Scrollbar %%x%d|", TH_SHADE1);
752                         str += sprintf(str, "Scroll Handle %%x%d|", TH_SHADE2);
753                         str += sprintf(str, "Selected File %%x%d|", TH_HILITE);
754                         str += sprintf(str, "Active File %%x%d|", TH_ACTIVE);
755                         str += sprintf(str, "Active File Text%%x%d|", TH_GRID);                 
756                         break;
757                 case SPACE_TEXT:
758                         str += sprintf(str, "Scroll Bar %%x%d|", TH_SHADE1);
759                         str += sprintf(str, "Selected Text %%x%d|", TH_SHADE2);
760                         str += sprintf(str, "Cursor %%x%d|", TH_HILITE);
761                         str += sprintf(str, "%%l|");
762                         str += sprintf(str, "Syntax Builtin %%x%d|", TH_SYNTAX_B);
763                         str += sprintf(str, "Syntax Special %%x%d|", TH_SYNTAX_V);
764                         str += sprintf(str, "Syntax Comment %%x%d|", TH_SYNTAX_C);
765                         str += sprintf(str, "Syntax Strings %%x%d|", TH_SYNTAX_L);
766                         str += sprintf(str, "Syntax Numbers %%x%d|", TH_SYNTAX_N);
767                         break;
768                 case SPACE_TIME:
769                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
770                         str += sprintf(str, "Current Frame %%x%d", TH_CFRAME);
771                         break;
772                 case SPACE_NODE:
773                         str += sprintf(str, "Wires %%x%d|", TH_WIRE);
774                         str += sprintf(str, "Wires Select %%x%d|", TH_EDGE_SELECT);
775                         str += sprintf(str, "%%l|");
776                         str += sprintf(str, "Node Backdrop %%x%d|", TH_NODE);
777                         str += sprintf(str, "In/Out Node %%x%d|", TH_NODE_IN_OUT);
778                         str += sprintf(str, "Convertor Node %%x%d|", TH_NODE_CONVERTOR);
779                         str += sprintf(str, "Operator Node %%x%d|", TH_NODE_OPERATOR);
780                         str += sprintf(str, "Group Node %%x%d|", TH_NODE_GROUP);
781                         break;
782                 }
783         }
784         return cp;
785 }
786
787 void BIF_SetTheme(ScrArea *sa)
788 {
789         if(sa==NULL) {  // called for safety, when delete themes
790                 theme_active= U.themes.first;
791                 theme_spacetype= SPACE_VIEW3D;
792         }
793         else {
794                 // later on, a local theme can be found too
795                 theme_active= U.themes.first;
796                 theme_spacetype= sa->spacetype;
797         
798         }
799 }
800
801 // for space windows only
802 void BIF_ThemeColor(int colorid)
803 {
804         char *cp;
805         
806         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
807         glColor3ub(cp[0], cp[1], cp[2]);
808
809 }
810
811 // plus alpha
812 void BIF_ThemeColor4(int colorid)
813 {
814         char *cp;
815         
816         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
817         glColor4ub(cp[0], cp[1], cp[2], cp[3]);
818
819 }
820
821 // set the color with offset for shades
822 void BIF_ThemeColorShade(int colorid, int offset)
823 {
824         int r, g, b;
825         char *cp;
826         
827         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
828         r= offset + (int) cp[0];
829         CLAMP(r, 0, 255);
830         g= offset + (int) cp[1];
831         CLAMP(g, 0, 255);
832         b= offset + (int) cp[2];
833         CLAMP(b, 0, 255);
834         //glColor3ub(r, g, b);
835         glColor4ub(r, g, b, cp[3]);
836 }
837 void BIF_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
838 {
839         int r, g, b, a;
840         char *cp;
841         
842         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
843         r= coloffset + (int) cp[0];
844         CLAMP(r, 0, 255);
845         g= coloffset + (int) cp[1];
846         CLAMP(g, 0, 255);
847         b= coloffset + (int) cp[2];
848         CLAMP(b, 0, 255);
849         a= alphaoffset + (int) cp[3];
850         CLAMP(a, 0, 255);
851         glColor4ub(r, g, b, a);
852 }
853
854 // blend between to theme colors, and set it
855 void BIF_ThemeColorBlend(int colorid1, int colorid2, float fac)
856 {
857         int r, g, b;
858         char *cp1, *cp2;
859         
860         cp1= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
861         cp2= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
862
863         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
864         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
865         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
866         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
867         
868         glColor3ub(r, g, b);
869 }
870
871 // blend between to theme colors, shade it, and set it
872 void BIF_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
873 {
874         int r, g, b;
875         char *cp1, *cp2;
876         
877         cp1= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
878         cp2= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
879
880         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
881         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
882         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
883         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
884         
885         r= r<0?0:(r>255?255:r);
886         g= g<0?0:(g>255?255:g);
887         b= b<0?0:(b>255?255:b);
888         
889         glColor3ub(r, g, b);
890 }
891
892 // get individual values, not scaled
893 float BIF_GetThemeValuef(int colorid)
894 {
895         char *cp;
896         
897         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
898         return ((float)cp[0]);
899
900 }
901
902 // get individual values, not scaled
903 int BIF_GetThemeValue(int colorid)
904 {
905         char *cp;
906         
907         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
908         return ((int) cp[0]);
909
910 }
911
912
913 // get the color, range 0.0-1.0
914 void BIF_GetThemeColor3fv(int colorid, float *col)
915 {
916         char *cp;
917         
918         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
919         col[0]= ((float)cp[0])/255.0;
920         col[1]= ((float)cp[1])/255.0;
921         col[2]= ((float)cp[2])/255.0;
922 }
923
924 // get the color, in char pointer
925 void BIF_GetThemeColor3ubv(int colorid, char *col)
926 {
927         char *cp;
928         
929         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
930         col[0]= cp[0];
931         col[1]= cp[1];
932         col[2]= cp[2];
933 }
934
935 // get the color, in char pointer
936 void BIF_GetThemeColor4ubv(int colorid, char *col)
937 {
938         char *cp;
939         
940         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
941         col[0]= cp[0];
942         col[1]= cp[1];
943         col[2]= cp[2];
944         col[3]= cp[3];
945 }
946
947 void BIF_GetThemeColorType4ubv(int colorid, int spacetype, char *col)
948 {
949         char *cp;
950         
951         cp= BIF_ThemeGetColorPtr(theme_active, spacetype, colorid);
952         col[0]= cp[0];
953         col[1]= cp[1];
954         col[2]= cp[2];
955         col[3]= cp[3];
956 }
957
958 // blends and shades between two char color pointers
959 void BIF_ColorPtrBlendShade3ubv(char *cp1, char *cp2, float fac, int offset)
960 {
961         int r, g, b;
962         
963         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
964         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
965         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
966         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
967         
968         r= r<0?0:(r>255?255:r);
969         g= g<0?0:(g>255?255:g);
970         b= b<0?0:(b>255?255:b);
971         
972         glColor3ub(r, g, b);
973 }
974
975 // get a 3 byte color, blended and shaded between two other char color pointers
976 void BIF_GetColorPtrBlendShade3ubv(char *cp1, char *cp2, char *col, float fac, int offset)
977 {
978         int r, g, b;
979         
980         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
981         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
982         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
983         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
984         
985         r= r<0?0:(r>255?255:r);
986         g= g<0?0:(g>255?255:g);
987         b= b<0?0:(b>255?255:b);
988         
989         col[0] = r;
990         col[1] = g;
991         col[2] = b;
992 }