Final merge of HEAD (bf-blender) into the orange branch.
[blender.git] / source / blender / src / resources.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <math.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 #include "MEM_guardedalloc.h"
42
43 #include "DNA_listBase.h"
44 #include "DNA_userdef_types.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_space_types.h"
47
48 #include "IMB_imbuf.h"
49 #include "IMB_imbuf_types.h"
50
51 #include "BKE_utildefines.h"
52
53 #include "BIF_gl.h"
54 #include "BIF_resources.h"
55 #include "BIF_interface_icons.h"
56
57 #include "BLI_blenlib.h"
58 #include "blendef.h"    // CLAMP
59 #include "datatoc.h"
60
61 /* global for themes */
62 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
63
64 static bTheme *theme_active=NULL;
65 static int theme_spacetype= SPACE_VIEW3D;
66
67
68 void BIF_resources_init(void)
69 {
70         BIF_icons_init(BIFICONID_LAST+1);
71 }
72
73 void BIF_resources_free(void)
74 {
75         BIF_icons_free();
76 }
77
78
79 /* ******************************************************** */
80 /*    THEMES */
81 /* ******************************************************** */
82
83 char *BIF_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
84 {
85         ThemeSpace *ts= NULL;
86         static char error[4]={240, 0, 240, 255};
87         static char alert[4]={240, 60, 60, 255};
88         static char headerdesel[4]={0,0,0,255};
89         static char custom[4]={0,0,0,255};
90         
91         char *cp= error;
92         
93         if(btheme) {
94         
95                 // first check for ui buttons theme
96                 if(colorid < TH_THEMEUI) {
97                 
98                         switch(colorid) {
99                         case TH_BUT_OUTLINE:
100                                 cp= btheme->tui.outline; break;
101                         case TH_BUT_NEUTRAL:
102                                 cp= btheme->tui.neutral; break;
103                         case TH_BUT_ACTION:
104                                 cp= btheme->tui.action; break;
105                         case TH_BUT_SETTING:
106                                 cp= btheme->tui.setting; break;
107                         case TH_BUT_SETTING1:
108                                 cp= btheme->tui.setting1; break;
109                         case TH_BUT_SETTING2:
110                                 cp= btheme->tui.setting2; break;
111                         case TH_BUT_NUM:
112                                 cp= btheme->tui.num; break;
113                         case TH_BUT_TEXTFIELD:
114                                 cp= btheme->tui.textfield; break;
115                         case TH_BUT_TEXTFIELD_HI:
116                                 cp= btheme->tui.textfield_hi; break;
117                         case TH_BUT_POPUP:
118                                 cp= btheme->tui.popup; break;
119                         case TH_BUT_TEXT:
120                                 cp= btheme->tui.text; break;
121                         case TH_BUT_TEXT_HI:
122                                 cp= btheme->tui.text_hi; break;
123                         case TH_MENU_BACK:
124                                 cp= btheme->tui.menu_back; break;
125                         case TH_MENU_ITEM:
126                                 cp= btheme->tui.menu_item; break;
127                         case TH_MENU_HILITE:
128                                 cp= btheme->tui.menu_hilite; break;
129                         case TH_MENU_TEXT:
130                                 cp= btheme->tui.menu_text; break;
131                         case TH_MENU_TEXT_HI:
132                                 cp= btheme->tui.menu_text_hi; break;
133                         
134                         case TH_BUT_DRAWTYPE:
135                                 cp= &btheme->tui.but_drawtype; 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_TRANSFORM:
233                                 cp= ts->transform; break;
234                         case TH_VERTEX:
235                                 cp= ts->vertex; break;
236                         case TH_VERTEX_SELECT:
237                                 cp= ts->vertex_select; break;
238                         case TH_VERTEX_SIZE:
239                                 cp= &ts->vertex_size; break;
240                         case TH_EDGE:
241                                 cp= ts->edge; break;
242                         case TH_EDGE_SELECT:
243                                 cp= ts->edge_select; break;
244                         case TH_EDGE_SEAM:
245                                 cp= ts->edge_seam; break;
246                         case TH_EDGE_FACESEL:
247                                 cp= ts->edge_facesel; break;
248                         case TH_FACE:
249                                 cp= ts->face; break;
250                         case TH_FACE_SELECT:
251                                 cp= ts->face_select; break;
252                         case TH_FACE_DOT:
253                                 cp= ts->face_dot; break;
254                         case TH_FACEDOT_SIZE:
255                                 cp= &ts->facedot_size; break;
256                         case TH_NORMAL:
257                                 cp= ts->normal; break;
258                         case TH_BONE_SOLID:
259                                 cp= ts->bone_solid; break;
260                         case TH_BONE_POSE:
261                                 cp= ts->bone_pose; break;
262                         case TH_STRIP:
263                                 cp= ts->strip; break;
264                         case TH_STRIP_SELECT:
265                                 cp= ts->strip_select; break;
266                                 
267                         case TH_SYNTAX_B:
268                                 cp= ts->syntaxb; break;
269                         case TH_SYNTAX_V:
270                                 cp= ts->syntaxv; break;
271                         case TH_SYNTAX_C:
272                                 cp= ts->syntaxc; break;
273                         case TH_SYNTAX_L:
274                                 cp= ts->syntaxl; break;
275                         case TH_SYNTAX_N:
276                                 cp= ts->syntaxn; break;
277
278                         case TH_NODE:
279                                 cp= ts->syntaxl; break;
280                         case TH_NODE_IN_OUT:
281                                 cp= ts->syntaxn; break;
282                         case TH_NODE_OPERATOR:
283                                 cp= ts->syntaxb; break;
284                         case TH_NODE_GENERATOR:
285                                 cp= ts->syntaxv; break;
286                         case TH_NODE_GROUP:
287                                 cp= ts->syntaxc; break;
288                                 
289                         }
290
291                 }
292         }
293         
294         return cp;
295 }
296
297 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
298
299 /* initialize
300    Note: when you add new colors, created & saved themes need initialized
301    in usiblender.c, search for "versionfile"
302 */
303 void BIF_InitTheme(void)
304 {
305         bTheme *btheme= U.themes.first;
306         
307         /* we search for the theme with name Default */
308         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
309                 if(strcmp("Default", btheme->name)==0) break;
310         }
311         
312         if(btheme==NULL) {
313                 btheme= MEM_callocN(sizeof(bTheme), "theme");
314                 BLI_addtail(&U.themes, btheme);
315                 strcpy(btheme->name, "Default");
316         }
317         
318         BIF_SetTheme(NULL);     // make sure the global used in this file is set
319
320         /* UI buttons (todo) */
321         SETCOL(btheme->tui.outline,     0xA0,0xA0,0xA0, 255);
322         SETCOL(btheme->tui.neutral,     0xA0,0xA0,0xA0, 255);
323         SETCOL(btheme->tui.action,              0xAD,0xA0,0x93, 255);
324         SETCOL(btheme->tui.setting,     0x8A,0x9E,0xA1, 255);
325         SETCOL(btheme->tui.setting1,    0xA1,0xA1,0xAE, 255);
326         SETCOL(btheme->tui.setting2,    0xA1,0x99,0xA7, 255);
327         SETCOL(btheme->tui.num,                 0x90,0x90,0x90, 255);
328         SETCOL(btheme->tui.textfield,   0x90,0x90,0x90, 255);
329         SETCOL(btheme->tui.textfield_hi,0xc6,0x77,0x77, 255);
330         SETCOL(btheme->tui.popup,               0xA0,0xA0,0xA0, 255);
331         
332         SETCOL(btheme->tui.text,                0,0,0, 255);
333         SETCOL(btheme->tui.text_hi,     255, 255, 255, 255);
334         
335         SETCOL(btheme->tui.menu_back,   0xD2,0xD2,0xD2, 255);
336         SETCOL(btheme->tui.menu_item,   0xDA,0xDA,0xDA, 255);
337         SETCOL(btheme->tui.menu_hilite, 0x7F,0x7F,0x7F, 255);
338         SETCOL(btheme->tui.menu_text,   0, 0, 0, 255);
339         SETCOL(btheme->tui.menu_text_hi, 255, 255, 255, 255);
340         btheme->tui.but_drawtype= 1;
341         
342         /* space view3d */
343         SETCOL(btheme->tv3d.back,       115, 115, 115, 255);
344         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
345         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
346         SETCOL(btheme->tv3d.header, 195, 195, 195, 255);
347         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
348         
349         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
350         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
351
352         SETCOL(btheme->tv3d.grid,       92, 92, 92, 255);
353         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
354         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
355         SETCOL(btheme->tv3d.select, 0xff, 0x88, 0xff, 255);
356         SETCOL(btheme->tv3d.active, 0xff, 0xbb, 0xff, 255);
357         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
358         SETCOL(btheme->tv3d.vertex, 0xff, 0x70, 0xff, 255);
359         SETCOL(btheme->tv3d.vertex_select, 0xff, 0xff, 0x70, 255);
360         btheme->tv3d.vertex_size= 2;
361         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
362         SETCOL(btheme->tv3d.edge_select, 0xb0, 0xb0, 0x30, 255);
363         SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
364         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
365         SETCOL(btheme->tv3d.face,       0, 50, 150, 30);
366         SETCOL(btheme->tv3d.face_select, 200, 100, 200, 60);
367         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
368         SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
369         btheme->tv3d.facedot_size= 4;
370         
371         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
372         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
373         
374         
375         /* space buttons */
376         /* to have something initialized */
377         btheme->tbuts= btheme->tv3d;
378
379         SETCOL(btheme->tbuts.back,      180, 180, 180, 255);
380         SETCOL(btheme->tbuts.header, 195, 195, 195, 255);
381         SETCOL(btheme->tbuts.panel,  255, 255, 255, 40);
382
383         /* space ipo */
384         /* to have something initialized */
385         btheme->tipo= btheme->tv3d;
386
387         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
388         SETCOL(btheme->tipo.back,       120, 120, 120, 255);
389         SETCOL(btheme->tipo.header, 195, 195, 195, 255);
390         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
391         SETCOL(btheme->tipo.shade1,  172, 172, 172, 100);
392         SETCOL(btheme->tipo.shade2,  0x70, 0x70, 0x70, 100);
393         SETCOL(btheme->tipo.vertex, 0xff, 0x70, 0xff, 255);
394         SETCOL(btheme->tipo.vertex_select, 0xff, 0xff, 0x70, 255);
395         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
396
397         /* space file */
398         /* to have something initialized */
399         btheme->tfile= btheme->tv3d;
400         SETCOL(btheme->tfile.back,      128, 128, 128, 255);
401         SETCOL(btheme->tfile.text,      0, 0, 0, 255);
402         SETCOL(btheme->tfile.text_hi, 255, 255, 255, 255);
403         SETCOL(btheme->tfile.header, 182, 182, 182, 255);
404         SETCOL(btheme->tfile.hilite, 0xA0, 0xA0, 0xD0, 255); // selected files
405
406         
407         /* space action */
408         btheme->tact= btheme->tv3d;
409         SETCOL(btheme->tact.back,       116, 116, 116, 255);
410         SETCOL(btheme->tact.text,       0, 0, 0, 255);
411         SETCOL(btheme->tact.text_hi, 255, 255, 255, 255);
412         SETCOL(btheme->tact.header, 182, 182, 182, 255);
413         SETCOL(btheme->tact.grid,  94, 94, 94, 255);
414         SETCOL(btheme->tact.face,  166, 166, 166, 255); // RVK
415         SETCOL(btheme->tact.shade1,  172, 172, 172, 255);               // sliders
416         SETCOL(btheme->tact.shade2,  84, 44, 31, 100);  // bar
417         SETCOL(btheme->tact.hilite,  17, 27, 60, 100);  // bar
418
419         /* space nla */
420         btheme->tnla= btheme->tv3d;
421         SETCOL(btheme->tnla.back,       116, 116, 116, 255);
422         SETCOL(btheme->tnla.text,       0, 0, 0, 255);
423         SETCOL(btheme->tnla.text_hi, 255, 255, 255, 255);
424         SETCOL(btheme->tnla.header, 182, 182, 182, 255);
425         SETCOL(btheme->tnla.grid,  94, 94, 94, 255);    
426         SETCOL(btheme->tnla.shade1,  172, 172, 172, 255);               // sliders
427         SETCOL(btheme->tnla.shade2,  84, 44, 31, 100);  // bar
428         SETCOL(btheme->tnla.hilite,  17, 27, 60, 100);  // bar
429         SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
430         SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
431         
432         /* space seq */
433         btheme->tseq= btheme->tv3d;
434         SETCOL(btheme->tnla.back,       116, 116, 116, 255);
435
436         /* space image */
437         btheme->tima= btheme->tv3d;
438         SETCOL(btheme->tima.back,       53, 53, 53, 255);
439         SETCOL(btheme->tima.vertex, 0xff, 0x70, 0xff, 255);
440         SETCOL(btheme->tima.vertex_select, 0xff, 0xff, 0x70, 255);
441         btheme->tima.vertex_size= 2;
442         SETCOL(btheme->tima.face,   0, 50, 150, 40);
443         SETCOL(btheme->tima.face_select, 200, 100, 200, 80);
444
445         /* space imageselect */
446         btheme->timasel= btheme->tv3d;
447         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
448         SETCOL(btheme->timasel.shade1,  0xaa, 0xaa, 0xba, 255);
449
450         /* space text */
451         btheme->text= btheme->tv3d;
452         SETCOL(btheme->text.back,       153, 153, 153, 255);
453         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
454         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
455         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
456         
457         /* syntax highlighting */
458         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
459         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
460         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
461         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
462         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
463         
464         /* space oops */
465         btheme->toops= btheme->tv3d;
466         SETCOL(btheme->toops.back,      153, 153, 153, 255);
467
468         /* space info */
469         btheme->tinfo= btheme->tv3d;
470         SETCOL(btheme->tinfo.back,      153, 153, 153, 255);
471
472         /* space sound */
473         btheme->tsnd= btheme->tv3d;
474         SETCOL(btheme->tsnd.back,       153, 153, 153, 255);
475         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
476         SETCOL(btheme->tsnd.grid, 140, 140, 140, 255);
477         
478         /* space time */
479         btheme->ttime= btheme->tsnd;    // same as sound space
480         
481         /* space node, re-uses syntax color storage */
482         btheme->tnode= btheme->tv3d;
483         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
484         SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
485         SETCOL(btheme->tnode.syntaxn, 95, 110, 145, 255);       /* in/output */
486         SETCOL(btheme->tnode.syntaxb, 135, 125, 120, 255);      /* operator */
487         SETCOL(btheme->tnode.syntaxv, 120, 120, 120, 255);      /* generator */
488         SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
489
490 }
491
492 char *BIF_ThemeColorsPup(int spacetype)
493 {
494         char *cp= MEM_callocN(32*32, "theme pup");
495         char str[32];
496         
497         if(spacetype==0) {
498                 sprintf(str, "Outline %%x%d|", TH_BUT_OUTLINE); strcat(cp, str);
499                 sprintf(str, "Neutral %%x%d|", TH_BUT_NEUTRAL); strcat(cp, str);
500                 sprintf(str, "Action %%x%d|", TH_BUT_ACTION); strcat(cp, str);
501                 sprintf(str, "Setting %%x%d|", TH_BUT_SETTING); strcat(cp, str);
502                 sprintf(str, "Special Setting 1%%x%d|", TH_BUT_SETTING1); strcat(cp, str);
503                 sprintf(str, "Special Setting 2 %%x%d|", TH_BUT_SETTING2); strcat(cp, str);
504                 sprintf(str, "Number Input %%x%d|", TH_BUT_NUM); strcat(cp, str);
505                 sprintf(str, "Text Input %%x%d|", TH_BUT_TEXTFIELD); strcat(cp, str);
506                 sprintf(str, "Text Input Highlight %%x%d|", TH_BUT_TEXTFIELD_HI); strcat(cp, str);
507                 sprintf(str, "Popup %%x%d|", TH_BUT_POPUP); strcat(cp, str);
508                 sprintf(str, "Text %%x%d|", TH_BUT_TEXT); strcat(cp, str);
509                 sprintf(str, "Text Highlight %%x%d|", TH_BUT_TEXT_HI); strcat(cp, str);
510                         strcat(cp,"%l|");
511                 sprintf(str, "Menu Background %%x%d|", TH_MENU_BACK); strcat(cp, str);
512                 sprintf(str, "Menu Item %%x%d|", TH_MENU_ITEM); strcat(cp, str);
513                 sprintf(str, "Menu Item Highlight %%x%d|", TH_MENU_HILITE); strcat(cp, str);
514                 sprintf(str, "Menu Text %%x%d|", TH_MENU_TEXT); strcat(cp, str);
515                 sprintf(str, "Menu Text Highlight %%x%d|", TH_MENU_TEXT_HI); strcat(cp, str);
516                 strcat(cp,"%l|");
517                 sprintf(str, "Drawtype %%x%d|", TH_BUT_DRAWTYPE); strcat(cp, str);
518         }
519         else {
520                 // first defaults for each space
521                 sprintf(str, "Background %%x%d|", TH_BACK); strcat(cp, str);
522                 sprintf(str, "Text %%x%d|", TH_TEXT); strcat(cp, str);
523                 sprintf(str, "Text Highlight %%x%d|", TH_TEXT_HI); strcat(cp, str);
524                 sprintf(str, "Header %%x%d|", TH_HEADER); strcat(cp, str);
525                 
526                 if(spacetype==SPACE_VIEW3D) {
527                         sprintf(str, "Panel %%x%d|", TH_PANEL); strcat(cp, str);
528                         strcat(cp,"%l|");
529                         sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
530                         sprintf(str, "Wire %%x%d|", TH_WIRE); strcat(cp, str);
531                         sprintf(str, "Lamp %%x%d|", TH_LAMP); strcat(cp, str);
532                         sprintf(str, "Object Selected %%x%d|", TH_SELECT); strcat(cp, str);
533                         sprintf(str, "Object Active %%x%d|", TH_ACTIVE); strcat(cp, str);
534                         sprintf(str, "Transform %%x%d|", TH_TRANSFORM); strcat(cp, str);
535                         strcat(cp,"%l|");
536                         sprintf(str, "Vertex %%x%d|", TH_VERTEX); strcat(cp, str);
537                         sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT); strcat(cp, str);
538                         sprintf(str, "Vertex Size %%x%d|", TH_VERTEX_SIZE); strcat(cp, str);
539                         sprintf(str, "Edge Selected %%x%d|", TH_EDGE_SELECT); strcat(cp, str);
540                         sprintf(str, "Edge Seam %%x%d|", TH_EDGE_SEAM); strcat(cp, str);
541                         sprintf(str, "Edge UV Face Select %%x%d|", TH_EDGE_FACESEL); strcat(cp, str);
542                         sprintf(str, "Face (transp) %%x%d|", TH_FACE); strcat(cp, str);
543                         sprintf(str, "Face Selected (transp) %%x%d|", TH_FACE_SELECT); strcat(cp, str);
544                         sprintf(str, "Face Dot Selected %%x%d|", TH_FACE_DOT); strcat(cp, str);
545                         sprintf(str, "Face Dot Size %%x%d|", TH_FACEDOT_SIZE); strcat(cp, str);
546                         sprintf(str, "Normal %%x%d|", TH_NORMAL); strcat(cp, str);
547                         sprintf(str, "Bone Solid %%x%d|", TH_BONE_SOLID); strcat(cp, str);
548                         sprintf(str, "Bone Pose %%x%d", TH_BONE_POSE); strcat(cp, str);
549                 }
550                 else if(spacetype==SPACE_IPO) {
551                         sprintf(str, "Panel %%x%d|", TH_PANEL); strcat(cp, str);
552                         strcat(cp,"%l|");
553                         sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
554                         sprintf(str, "Window Sliders %%x%d|", TH_SHADE1); strcat(cp, str);
555                         sprintf(str, "Ipo Channels %%x%d|", TH_SHADE2); strcat(cp, str);
556                         sprintf(str, "Vertex %%x%d|", TH_VERTEX); strcat(cp, str);
557                         sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT); strcat(cp, str);
558                 }
559                 else if(spacetype==SPACE_FILE) {
560                         sprintf(str, "Selected file %%x%d", TH_HILITE); strcat(cp, str);
561                 }
562                 else if(spacetype==SPACE_NLA) {
563                         //sprintf(str, "Panel %%x%d|", TH_PANEL); strcat(cp, str);
564                         strcat(cp,"%l|");
565                         sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
566                         sprintf(str, "View Sliders %%x%d|", TH_SHADE1); strcat(cp, str);
567                         sprintf(str, "Bars %%x%d|", TH_SHADE2); strcat(cp, str);
568                         sprintf(str, "Bars selected %%x%d|", TH_HILITE); strcat(cp, str);
569                         sprintf(str, "Strips %%x%d|", TH_STRIP); strcat(cp, str);
570                         sprintf(str, "Strips selected %%x%d|", TH_STRIP_SELECT); strcat(cp, str);
571                 }
572                 else if(spacetype==SPACE_ACTION) {
573                         //sprintf(str, "Panel %%x%d|", TH_PANEL); strcat(cp, str);
574                         strcat(cp,"%l|");
575                         sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
576                         sprintf(str, "RVK Sliders %%x%d|", TH_FACE); strcat(cp, str);
577                         sprintf(str, "View Sliders %%x%d|", TH_SHADE1); strcat(cp, str);
578                         sprintf(str, "Channels %%x%d|", TH_SHADE2); strcat(cp, str);
579                         sprintf(str, "Channels Selected %%x%d|", TH_HILITE); strcat(cp, str);
580                 }
581                 else if(spacetype==SPACE_IMAGE) {
582                         strcat(cp,"%l|");
583                         sprintf(str, "Vertex %%x%d|", TH_VERTEX); strcat(cp, str);
584                         sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT); strcat(cp, str);
585                         sprintf(str, "Vertex Size %%x%d|", TH_VERTEX_SIZE); strcat(cp, str);
586                         sprintf(str, "Face %%x%d|", TH_FACE); strcat(cp, str);
587                         sprintf(str, "Face Selected %%x%d", TH_FACE_SELECT); strcat(cp, str);
588                 }
589                 else if(spacetype==SPACE_SEQ) {
590                         sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
591                         sprintf(str, "Window Sliders %%x%d|", TH_SHADE1); strcat(cp, str);
592                 }
593                 else if(spacetype==SPACE_SOUND) {
594                         sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
595                         sprintf(str, "Window Slider %%x%d|", TH_SHADE1); strcat(cp, str);
596                 }
597                 else if(spacetype==SPACE_BUTS) {
598                         sprintf(str, "Panel %%x%d|", TH_PANEL); strcat(cp, str);
599                 }
600                 else if(spacetype==SPACE_IMASEL) {
601                         sprintf(str, "Main Shade %%x%d|", TH_SHADE1); strcat(cp, str);
602                 }
603                 else if(spacetype==SPACE_TEXT) {
604                         sprintf(str, "Scroll Bar %%x%d|", TH_SHADE1); strcat(cp, str);
605                         sprintf(str, "Selected Text %%x%d|", TH_SHADE2); strcat(cp, str);
606                         sprintf(str, "Cursor %%x%d|", TH_HILITE); strcat(cp, str);
607                         strcat(cp,"%l|");
608                         sprintf(str, "Syntax Builtin %%x%d|", TH_SYNTAX_B); strcat(cp, str);
609                         sprintf(str, "Syntax Special %%x%d|", TH_SYNTAX_V); strcat(cp, str);
610                         sprintf(str, "Syntax Comment %%x%d|", TH_SYNTAX_C); strcat(cp, str);
611                         sprintf(str, "Syntax Strings %%x%d|", TH_SYNTAX_L); strcat(cp, str);
612                         sprintf(str, "Syntax Numbers %%x%d|", TH_SYNTAX_N); strcat(cp, str);
613                 }
614                 else if(spacetype==SPACE_TIME) {
615                         sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
616                 }
617                 else if(spacetype==SPACE_NODE) {
618                         sprintf(str, "Wires %%x%d|", TH_WIRE); strcat(cp, str);
619                         sprintf(str, "Wires Select %%x%d|", TH_EDGE_SELECT); strcat(cp, str);
620                         strcat(cp,"%l|");
621                         sprintf(str, "Node Backdrop %%x%d|", TH_NODE); strcat(cp, str);
622                         sprintf(str, "In/Out Node %%x%d|", TH_NODE_IN_OUT); strcat(cp, str);
623                         sprintf(str, "Generator Node %%x%d|", TH_NODE_GENERATOR); strcat(cp, str);
624                         sprintf(str, "Operator Node %%x%d|", TH_NODE_OPERATOR); strcat(cp, str);
625                         sprintf(str, "Group Node %%x%d|", TH_NODE_GROUP); strcat(cp, str);
626                 }
627         }
628         return cp;
629 }
630
631 void BIF_SetTheme(ScrArea *sa)
632 {
633         if(sa==NULL) {  // called for safety, when delete themes
634                 theme_active= U.themes.first;
635                 theme_spacetype= SPACE_VIEW3D;
636         }
637         else {
638                 // later on, a local theme can be found too
639                 theme_active= U.themes.first;
640                 theme_spacetype= sa->spacetype;
641         
642         }
643 }
644
645 // for space windows only
646 void BIF_ThemeColor(int colorid)
647 {
648         char *cp;
649         
650         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
651         glColor3ub(cp[0], cp[1], cp[2]);
652
653 }
654
655 // plus alpha
656 void BIF_ThemeColor4(int colorid)
657 {
658         char *cp;
659         
660         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
661         glColor4ub(cp[0], cp[1], cp[2], cp[3]);
662
663 }
664
665 // set the color with offset for shades
666 void BIF_ThemeColorShade(int colorid, int offset)
667 {
668         int r, g, b;
669         char *cp;
670         
671         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
672         r= offset + (int) cp[0];
673         CLAMP(r, 0, 255);
674         g= offset + (int) cp[1];
675         CLAMP(g, 0, 255);
676         b= offset + (int) cp[2];
677         CLAMP(b, 0, 255);
678         //glColor3ub(r, g, b);
679         glColor4ub(r, g, b, cp[3]);
680 }
681 void BIF_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
682 {
683         int r, g, b, a;
684         char *cp;
685         
686         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
687         r= coloffset + (int) cp[0];
688         CLAMP(r, 0, 255);
689         g= coloffset + (int) cp[1];
690         CLAMP(g, 0, 255);
691         b= coloffset + (int) cp[2];
692         CLAMP(b, 0, 255);
693         a= alphaoffset + (int) cp[3];
694         CLAMP(a, 0, 255);
695         glColor4ub(r, g, b, a);
696 }
697
698 // blend between to theme colors, and set it
699 void BIF_ThemeColorBlend(int colorid1, int colorid2, float fac)
700 {
701         int r, g, b;
702         char *cp1, *cp2;
703         
704         cp1= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
705         cp2= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
706
707         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
708         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
709         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
710         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
711         
712         glColor3ub(r, g, b);
713 }
714
715 // blend between to theme colors, shade it, and set it
716 void BIF_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
717 {
718         int r, g, b;
719         char *cp1, *cp2;
720         
721         cp1= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
722         cp2= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
723
724         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
725         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
726         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
727         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
728         
729         r= r<0?0:(r>255?255:r);
730         g= g<0?0:(g>255?255:g);
731         b= b<0?0:(b>255?255:b);
732         
733         glColor3ub(r, g, b);
734 }
735
736
737 // get individual values, not scaled
738 float BIF_GetThemeValuef(int colorid)
739 {
740         char *cp;
741         
742         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
743         return ((float)cp[0]);
744
745 }
746
747 // get individual values, not scaled
748 int BIF_GetThemeValue(int colorid)
749 {
750         char *cp;
751         
752         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
753         return ((int) cp[0]);
754
755 }
756
757
758 // get the color, range 0.0-1.0
759 void BIF_GetThemeColor3fv(int colorid, float *col)
760 {
761         char *cp;
762         
763         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
764         col[0]= ((float)cp[0])/255.0;
765         col[1]= ((float)cp[1])/255.0;
766         col[2]= ((float)cp[2])/255.0;
767 }
768
769 // get the color, in char pointer
770 void BIF_GetThemeColor3ubv(int colorid, char *col)
771 {
772         char *cp;
773         
774         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
775         col[0]= cp[0];
776         col[1]= cp[1];
777         col[2]= cp[2];
778 }
779
780 // get the color, in char pointer
781 void BIF_GetThemeColor4ubv(int colorid, char *col)
782 {
783         char *cp;
784         
785         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
786         col[0]= cp[0];
787         col[1]= cp[1];
788         col[2]= cp[2];
789         col[3]= cp[3];
790 }
791
792 void BIF_GetThemeColorType4ubv(int colorid, int spacetype, char *col)
793 {
794         char *cp;
795         
796         cp= BIF_ThemeGetColorPtr(theme_active, spacetype, colorid);
797         col[0]= cp[0];
798         col[1]= cp[1];
799         col[2]= cp[2];
800         col[3]= cp[3];
801 }