==Sequencer==
[blender-staging.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_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_FACESEL:
251                                 cp= ts->edge_facesel; break;
252                         case TH_FACE:
253                                 cp= ts->face; break;
254                         case TH_FACE_SELECT:
255                                 cp= ts->face_select; break;
256                         case TH_FACE_DOT:
257                                 cp= ts->face_dot; break;
258                         case TH_FACEDOT_SIZE:
259                                 cp= &ts->facedot_size; break;
260                         case TH_NORMAL:
261                                 cp= ts->normal; break;
262                         case TH_BONE_SOLID:
263                                 cp= ts->bone_solid; break;
264                         case TH_BONE_POSE:
265                                 cp= ts->bone_pose; break;
266                         case TH_STRIP:
267                                 cp= ts->strip; break;
268                         case TH_STRIP_SELECT:
269                                 cp= ts->strip_select; break;
270                                 
271                         case TH_SYNTAX_B:
272                                 cp= ts->syntaxb; break;
273                         case TH_SYNTAX_V:
274                                 cp= ts->syntaxv; break;
275                         case TH_SYNTAX_C:
276                                 cp= ts->syntaxc; break;
277                         case TH_SYNTAX_L:
278                                 cp= ts->syntaxl; break;
279                         case TH_SYNTAX_N:
280                                 cp= ts->syntaxn; break;
281
282                         case TH_NODE:
283                                 cp= ts->syntaxl; break;
284                         case TH_NODE_IN_OUT:
285                                 cp= ts->syntaxn; break;
286                         case TH_NODE_OPERATOR:
287                                 cp= ts->syntaxb; break;
288                         case TH_NODE_GENERATOR:
289                                 cp= ts->syntaxv; break;
290                         case TH_NODE_GROUP:
291                                 cp= ts->syntaxc; break;
292                                 
293                         case TH_SEQ_MOVIE:
294                                 cp= ts->movie; break;
295                         case TH_SEQ_IMAGE:
296                                 cp= ts->image; break;
297                         case TH_SEQ_SCENE:
298                                 cp= ts->scene; break;
299                         case TH_SEQ_AUDIO:
300                                 cp= ts->audio; break;
301                         case TH_SEQ_EFFECT:
302                                 cp= ts->effect; break;
303                         case TH_SEQ_PLUGIN:
304                                 cp= ts->plugin; break;
305                         case TH_SEQ_TRANSITION:
306                                 cp= ts->transition; break;
307                         case TH_SEQ_META:
308                                 cp= ts->meta; break;
309                                 
310                         }
311
312                 }
313         }
314         
315         return cp;
316 }
317
318 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
319
320 /* initialize
321    Note: when you add new colors, created & saved themes need initialized
322    in usiblender.c, search for "versionfile"
323 */
324 void BIF_InitTheme(void)
325 {
326         bTheme *btheme= U.themes.first;
327         
328         /* we search for the theme with name Default */
329         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
330                 if(strcmp("Default", btheme->name)==0) break;
331         }
332         
333         if(btheme==NULL) {
334                 btheme= MEM_callocN(sizeof(bTheme), "theme");
335                 BLI_addtail(&U.themes, btheme);
336                 strcpy(btheme->name, "Default");
337         }
338         
339         BIF_SetTheme(NULL);     // make sure the global used in this file is set
340
341         /* UI buttons (todo) */
342         SETCOL(btheme->tui.outline,     0xA0,0xA0,0xA0, 255);
343         SETCOL(btheme->tui.neutral,     0xA0,0xA0,0xA0, 255);
344         SETCOL(btheme->tui.action,              0xAD,0xA0,0x93, 255);
345         SETCOL(btheme->tui.setting,     0x8A,0x9E,0xA1, 255);
346         SETCOL(btheme->tui.setting1,    0xA1,0xA1,0xAE, 255);
347         SETCOL(btheme->tui.setting2,    0xA1,0x99,0xA7, 255);
348         SETCOL(btheme->tui.num,                 0x90,0x90,0x90, 255);
349         SETCOL(btheme->tui.textfield,   0x90,0x90,0x90, 255);
350         SETCOL(btheme->tui.textfield_hi,0xc6,0x77,0x77, 255);
351         SETCOL(btheme->tui.popup,               0xA0,0xA0,0xA0, 255);
352         
353         SETCOL(btheme->tui.text,                0,0,0, 255);
354         SETCOL(btheme->tui.text_hi,     255, 255, 255, 255);
355         
356         SETCOL(btheme->tui.menu_back,   0xD2,0xD2,0xD2, 255);
357         SETCOL(btheme->tui.menu_item,   0xDA,0xDA,0xDA, 255);
358         SETCOL(btheme->tui.menu_hilite, 0x7F,0x7F,0x7F, 255);
359         SETCOL(btheme->tui.menu_text,   0, 0, 0, 255);
360         SETCOL(btheme->tui.menu_text_hi, 255, 255, 255, 255);
361         btheme->tui.but_drawtype= 1;
362         
363         /* space view3d */
364         SETCOL(btheme->tv3d.back,       115, 115, 115, 255);
365         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
366         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
367         SETCOL(btheme->tv3d.header, 195, 195, 195, 255);
368         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
369         
370         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
371         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
372
373         SETCOL(btheme->tv3d.grid,       92, 92, 92, 255);
374         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
375         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
376         SETCOL(btheme->tv3d.select, 0xff, 0x88, 0xff, 255);
377         SETCOL(btheme->tv3d.active, 0xff, 0xbb, 0xff, 255);
378         SETCOL(btheme->tv3d.group, 0x10, 0x40, 0x10, 255);
379         SETCOL(btheme->tv3d.group_active, 0x55, 0xbb, 0x55, 255);
380         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
381         SETCOL(btheme->tv3d.vertex, 0xff, 0x70, 0xff, 255);
382         SETCOL(btheme->tv3d.vertex_select, 0xff, 0xff, 0x70, 255);
383         btheme->tv3d.vertex_size= 2;
384         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
385         SETCOL(btheme->tv3d.edge_select, 0xb0, 0xb0, 0x30, 255);
386         SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
387         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
388         SETCOL(btheme->tv3d.face,       0, 50, 150, 30);
389         SETCOL(btheme->tv3d.face_select, 200, 100, 200, 60);
390         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
391         SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
392         btheme->tv3d.facedot_size= 4;
393         
394         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
395         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
396         
397         
398         /* space buttons */
399         /* to have something initialized */
400         btheme->tbuts= btheme->tv3d;
401
402         SETCOL(btheme->tbuts.back,      180, 180, 180, 255);
403         SETCOL(btheme->tbuts.header, 195, 195, 195, 255);
404         SETCOL(btheme->tbuts.panel,  255, 255, 255, 40);
405
406         /* space ipo */
407         /* to have something initialized */
408         btheme->tipo= btheme->tv3d;
409
410         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
411         SETCOL(btheme->tipo.back,       120, 120, 120, 255);
412         SETCOL(btheme->tipo.header, 195, 195, 195, 255);
413         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
414         SETCOL(btheme->tipo.shade1,  172, 172, 172, 100);
415         SETCOL(btheme->tipo.shade2,  0x70, 0x70, 0x70, 100);
416         SETCOL(btheme->tipo.vertex, 0xff, 0x70, 0xff, 255);
417         SETCOL(btheme->tipo.vertex_select, 0xff, 0xff, 0x70, 255);
418         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
419
420         /* space file */
421         /* to have something initialized */
422         btheme->tfile= btheme->tv3d;
423         SETCOL(btheme->tfile.back,      128, 128, 128, 255);
424         SETCOL(btheme->tfile.text,      0, 0, 0, 255);
425         SETCOL(btheme->tfile.text_hi, 255, 255, 255, 255);
426         SETCOL(btheme->tfile.header, 182, 182, 182, 255);
427         SETCOL(btheme->tfile.hilite, 0xA0, 0xA0, 0xD0, 255); // selected files
428
429         
430         /* space action */
431         btheme->tact= btheme->tv3d;
432         SETCOL(btheme->tact.back,       116, 116, 116, 255);
433         SETCOL(btheme->tact.text,       0, 0, 0, 255);
434         SETCOL(btheme->tact.text_hi, 255, 255, 255, 255);
435         SETCOL(btheme->tact.header, 182, 182, 182, 255);
436         SETCOL(btheme->tact.grid,  94, 94, 94, 255);
437         SETCOL(btheme->tact.face,  166, 166, 166, 255); // RVK
438         SETCOL(btheme->tact.shade1,  172, 172, 172, 255);               // sliders
439         SETCOL(btheme->tact.shade2,  84, 44, 31, 100);  // bar
440         SETCOL(btheme->tact.hilite,  17, 27, 60, 100);  // bar
441
442         /* space nla */
443         btheme->tnla= btheme->tv3d;
444         SETCOL(btheme->tnla.back,       116, 116, 116, 255);
445         SETCOL(btheme->tnla.text,       0, 0, 0, 255);
446         SETCOL(btheme->tnla.text_hi, 255, 255, 255, 255);
447         SETCOL(btheme->tnla.header, 182, 182, 182, 255);
448         SETCOL(btheme->tnla.grid,  94, 94, 94, 255);    
449         SETCOL(btheme->tnla.shade1,  172, 172, 172, 255);               // sliders
450         SETCOL(btheme->tnla.shade2,  84, 44, 31, 100);  // bar
451         SETCOL(btheme->tnla.hilite,  17, 27, 60, 100);  // bar
452         SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
453         SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
454         
455         /* space seq */
456         btheme->tseq= btheme->tv3d;
457         SETCOL(btheme->tseq.back,       116, 116, 116, 255);
458         SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
459         SETCOL(btheme->tseq.image,      109, 88, 129, 255);
460         SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
461         SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
462         SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
463         SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
464         SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
465         SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
466         
467
468         /* space image */
469         btheme->tima= btheme->tv3d;
470         SETCOL(btheme->tima.back,       53, 53, 53, 255);
471         SETCOL(btheme->tima.vertex, 0xff, 0x70, 0xff, 255);
472         SETCOL(btheme->tima.vertex_select, 0xff, 0xff, 0x70, 255);
473         btheme->tima.vertex_size= 2;
474         SETCOL(btheme->tima.face,   0, 50, 150, 40);
475         SETCOL(btheme->tima.face_select, 200, 100, 200, 80);
476
477         /* space imageselect */
478         btheme->timasel= btheme->tv3d;
479         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
480         SETCOL(btheme->timasel.shade1,  0xaa, 0xaa, 0xba, 255);
481
482         /* space text */
483         btheme->text= btheme->tv3d;
484         SETCOL(btheme->text.back,       153, 153, 153, 255);
485         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
486         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
487         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
488         
489         /* syntax highlighting */
490         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
491         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
492         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
493         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
494         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
495         
496         /* space oops */
497         btheme->toops= btheme->tv3d;
498         SETCOL(btheme->toops.back,      153, 153, 153, 255);
499
500         /* space info */
501         btheme->tinfo= btheme->tv3d;
502         SETCOL(btheme->tinfo.back,      153, 153, 153, 255);
503
504         /* space sound */
505         btheme->tsnd= btheme->tv3d;
506         SETCOL(btheme->tsnd.back,       153, 153, 153, 255);
507         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
508         SETCOL(btheme->tsnd.grid, 140, 140, 140, 255);
509         
510         /* space time */
511         btheme->ttime= btheme->tsnd;    // same as sound space
512         
513         /* space node, re-uses syntax color storage */
514         btheme->tnode= btheme->tv3d;
515         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
516         SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
517         SETCOL(btheme->tnode.syntaxn, 95, 110, 145, 255);       /* in/output */
518         SETCOL(btheme->tnode.syntaxb, 135, 125, 120, 255);      /* operator */
519         SETCOL(btheme->tnode.syntaxv, 120, 120, 120, 255);      /* generator */
520         SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
521
522 }
523
524 char *BIF_ThemeColorsPup(int spacetype)
525 {
526         char *cp= MEM_callocN(32*32, "theme pup");
527         char *str = cp;
528         
529         if(spacetype==0) {
530                 str += sprintf(str, "Outline %%x%d|", TH_BUT_OUTLINE);
531                 str += sprintf(str, "Neutral %%x%d|", TH_BUT_NEUTRAL);
532                 str += sprintf(str, "Action %%x%d|", TH_BUT_ACTION);
533                 str += sprintf(str, "Setting %%x%d|", TH_BUT_SETTING);
534                 str += sprintf(str, "Special Setting 1%%x%d|", TH_BUT_SETTING1);
535                 str += sprintf(str, "Special Setting 2 %%x%d|", TH_BUT_SETTING2);
536                 str += sprintf(str, "Number Input %%x%d|", TH_BUT_NUM);
537                 str += sprintf(str, "Text Input %%x%d|", TH_BUT_TEXTFIELD);
538                 str += sprintf(str, "Text Input Highlight %%x%d|", TH_BUT_TEXTFIELD_HI);
539                 str += sprintf(str, "Popup %%x%d|", TH_BUT_POPUP);
540                 str += sprintf(str, "Text %%x%d|", TH_BUT_TEXT);
541                 str += sprintf(str, "Text Highlight %%x%d|", TH_BUT_TEXT_HI);
542                 str += sprintf(str, "%%l|");
543                 str += sprintf(str, "Menu Background %%x%d|", TH_MENU_BACK);
544                 str += sprintf(str, "Menu Item %%x%d|", TH_MENU_ITEM);
545                 str += sprintf(str, "Menu Item Highlight %%x%d|", TH_MENU_HILITE);
546                 str += sprintf(str, "Menu Text %%x%d|", TH_MENU_TEXT);
547                 str += sprintf(str, "Menu Text Highlight %%x%d|", TH_MENU_TEXT_HI);
548                 str += sprintf(str, "%%l|");
549                 str += sprintf(str, "Drawtype %%x%d|", TH_BUT_DRAWTYPE);
550         }
551         else {
552                 // first defaults for each space
553                 str += sprintf(str, "Background %%x%d|", TH_BACK);
554                 str += sprintf(str, "Text %%x%d|", TH_TEXT);
555                 str += sprintf(str, "Text Highlight %%x%d|", TH_TEXT_HI);
556                 str += sprintf(str, "Header %%x%d|", TH_HEADER);
557                 
558                 switch(spacetype) {
559                 case SPACE_VIEW3D:
560                         str += sprintf(str, "Panel %%x%d|", TH_PANEL);
561                         str += sprintf(str, "%%l|");
562                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
563                         str += sprintf(str, "Wire %%x%d|", TH_WIRE);
564                         str += sprintf(str, "Lamp %%x%d|", TH_LAMP);
565                         str += sprintf(str, "Object Selected %%x%d|", TH_SELECT);
566                         str += sprintf(str, "Object Active %%x%d|", TH_ACTIVE);
567                         str += sprintf(str, "Object Grouped %%x%d|", TH_GROUP);
568                         str += sprintf(str, "Object Grouped Active %%x%d|", TH_GROUP_ACTIVE);
569                         str += sprintf(str, "Transform %%x%d|", TH_TRANSFORM);
570                         str += sprintf(str, "%%l|");
571                         str += sprintf(str, "Vertex %%x%d|", TH_VERTEX);
572                         str += sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT);
573                         str += sprintf(str, "Vertex Size %%x%d|", TH_VERTEX_SIZE);
574                         str += sprintf(str, "Edge Selected %%x%d|", TH_EDGE_SELECT);
575                         str += sprintf(str, "Edge Seam %%x%d|", TH_EDGE_SEAM);
576                         str += sprintf(str, "Edge UV Face Select %%x%d|", TH_EDGE_FACESEL);
577                         str += sprintf(str, "Face (transp) %%x%d|", TH_FACE);
578                         str += sprintf(str, "Face Selected (transp) %%x%d|", TH_FACE_SELECT);
579                         str += sprintf(str, "Face Dot Selected %%x%d|", TH_FACE_DOT);
580                         str += sprintf(str, "Face Dot Size %%x%d|", TH_FACEDOT_SIZE);
581                         str += sprintf(str, "Normal %%x%d|", TH_NORMAL);
582                         str += sprintf(str, "Bone Solid %%x%d|", TH_BONE_SOLID);
583                         str += sprintf(str, "Bone Pose %%x%d", TH_BONE_POSE);
584                         break;
585                 case SPACE_IPO:
586                         str += sprintf(str, "Panel %%x%d|", TH_PANEL);
587                         str += sprintf(str, "%%l|");
588                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
589                         str += sprintf(str, "Window Sliders %%x%d|", TH_SHADE1);
590                         str += sprintf(str, "Ipo Channels %%x%d|", TH_SHADE2);
591                         str += sprintf(str, "Vertex %%x%d|", TH_VERTEX);
592                         str += sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT);
593                         break;
594                 case SPACE_FILE:
595                         str += sprintf(str, "Selected file %%x%d", TH_HILITE);
596                         break;
597                 case SPACE_NLA:
598                         //str += sprintf(str, "Panel %%x%d|", TH_PANEL);
599                         str += sprintf(str, "%%l|");
600                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
601                         str += sprintf(str, "View Sliders %%x%d|", TH_SHADE1);
602                         str += sprintf(str, "Bars %%x%d|", TH_SHADE2);
603                         str += sprintf(str, "Bars selected %%x%d|", TH_HILITE);
604                         str += sprintf(str, "Strips %%x%d|", TH_STRIP);
605                         str += sprintf(str, "Strips selected %%x%d|", TH_STRIP_SELECT);
606                         break;
607                 case SPACE_ACTION:
608                         //str += sprintf(str, "Panel %%x%d|", TH_PANEL);
609                         str += sprintf(str, "%%l|");
610                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
611                         str += sprintf(str, "RVK Sliders %%x%d|", TH_FACE);
612                         str += sprintf(str, "View Sliders %%x%d|", TH_SHADE1);
613                         str += sprintf(str, "Channels %%x%d|", TH_SHADE2);
614                         str += sprintf(str, "Channels Selected %%x%d|", TH_HILITE);
615                         break;
616                 case SPACE_IMAGE:
617                         str += sprintf(str, "%%l|");
618                         str += sprintf(str, "Vertex %%x%d|", TH_VERTEX);
619                         str += sprintf(str, "Vertex Selected %%x%d|", TH_VERTEX_SELECT);
620                         str += sprintf(str, "Vertex Size %%x%d|", TH_VERTEX_SIZE);
621                         str += sprintf(str, "Face %%x%d|", TH_FACE);
622                         str += sprintf(str, "Face Selected %%x%d", TH_FACE_SELECT);
623                         break;
624                 case SPACE_SEQ:
625                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
626                         str += sprintf(str, "Window Sliders %%x%d|", TH_SHADE1);
627                         str += sprintf(str, "%%l|");
628                         str += sprintf(str, "Movie Strip %%x%d|", TH_SEQ_MOVIE);
629                         str += sprintf(str, "Image Strip %%x%d|", TH_SEQ_IMAGE);
630                         str += sprintf(str, "Scene Strip %%x%d|", TH_SEQ_SCENE);
631                         str += sprintf(str, "Audio Strip %%x%d|", TH_SEQ_AUDIO);
632                         str += sprintf(str, "Effect Strip %%x%d|", TH_SEQ_EFFECT);
633                         str += sprintf(str, "Plugin Strip %%x%d|", TH_SEQ_PLUGIN);
634                         str += sprintf(str, "Transition Strip %%x%d|", TH_SEQ_TRANSITION);
635                         str += sprintf(str, "Meta Strip %%x%d|", TH_SEQ_META);
636                         break;
637                 case SPACE_SOUND:
638                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
639                         str += sprintf(str, "Window Slider %%x%d|", TH_SHADE1);
640                         break;
641                 case SPACE_BUTS:
642                         str += sprintf(str, "Panel %%x%d|", TH_PANEL);
643                         break;
644                 case SPACE_IMASEL:
645                         str += sprintf(str, "Main Shade %%x%d|", TH_SHADE1);
646                         break;
647                 case SPACE_TEXT:
648                         str += sprintf(str, "Scroll Bar %%x%d|", TH_SHADE1);
649                         str += sprintf(str, "Selected Text %%x%d|", TH_SHADE2);
650                         str += sprintf(str, "Cursor %%x%d|", TH_HILITE);
651                         str += sprintf(str, "%%l|");
652                         str += sprintf(str, "Syntax Builtin %%x%d|", TH_SYNTAX_B);
653                         str += sprintf(str, "Syntax Special %%x%d|", TH_SYNTAX_V);
654                         str += sprintf(str, "Syntax Comment %%x%d|", TH_SYNTAX_C);
655                         str += sprintf(str, "Syntax Strings %%x%d|", TH_SYNTAX_L);
656                         str += sprintf(str, "Syntax Numbers %%x%d|", TH_SYNTAX_N);
657                         break;
658                 case SPACE_TIME:
659                         str += sprintf(str, "Grid %%x%d|", TH_GRID);
660                         break;
661                 case SPACE_NODE:
662                         str += sprintf(str, "Wires %%x%d|", TH_WIRE);
663                         str += sprintf(str, "Wires Select %%x%d|", TH_EDGE_SELECT);
664                         str += sprintf(str, "%%l|");
665                         str += sprintf(str, "Node Backdrop %%x%d|", TH_NODE);
666                         str += sprintf(str, "In/Out Node %%x%d|", TH_NODE_IN_OUT);
667                         str += sprintf(str, "Generator Node %%x%d|", TH_NODE_GENERATOR);
668                         str += sprintf(str, "Operator Node %%x%d|", TH_NODE_OPERATOR);
669                         str += sprintf(str, "Group Node %%x%d|", TH_NODE_GROUP);
670                         break;
671                 }
672         }
673         return cp;
674 }
675
676 void BIF_SetTheme(ScrArea *sa)
677 {
678         if(sa==NULL) {  // called for safety, when delete themes
679                 theme_active= U.themes.first;
680                 theme_spacetype= SPACE_VIEW3D;
681         }
682         else {
683                 // later on, a local theme can be found too
684                 theme_active= U.themes.first;
685                 theme_spacetype= sa->spacetype;
686         
687         }
688 }
689
690 // for space windows only
691 void BIF_ThemeColor(int colorid)
692 {
693         char *cp;
694         
695         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
696         glColor3ub(cp[0], cp[1], cp[2]);
697
698 }
699
700 // plus alpha
701 void BIF_ThemeColor4(int colorid)
702 {
703         char *cp;
704         
705         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
706         glColor4ub(cp[0], cp[1], cp[2], cp[3]);
707
708 }
709
710 // set the color with offset for shades
711 void BIF_ThemeColorShade(int colorid, int offset)
712 {
713         int r, g, b;
714         char *cp;
715         
716         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
717         r= offset + (int) cp[0];
718         CLAMP(r, 0, 255);
719         g= offset + (int) cp[1];
720         CLAMP(g, 0, 255);
721         b= offset + (int) cp[2];
722         CLAMP(b, 0, 255);
723         //glColor3ub(r, g, b);
724         glColor4ub(r, g, b, cp[3]);
725 }
726 void BIF_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
727 {
728         int r, g, b, a;
729         char *cp;
730         
731         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
732         r= coloffset + (int) cp[0];
733         CLAMP(r, 0, 255);
734         g= coloffset + (int) cp[1];
735         CLAMP(g, 0, 255);
736         b= coloffset + (int) cp[2];
737         CLAMP(b, 0, 255);
738         a= alphaoffset + (int) cp[3];
739         CLAMP(a, 0, 255);
740         glColor4ub(r, g, b, a);
741 }
742
743 // blend between to theme colors, and set it
744 void BIF_ThemeColorBlend(int colorid1, int colorid2, float fac)
745 {
746         int r, g, b;
747         char *cp1, *cp2;
748         
749         cp1= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
750         cp2= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
751
752         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
753         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
754         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
755         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
756         
757         glColor3ub(r, g, b);
758 }
759
760 // blend between to theme colors, shade it, and set it
761 void BIF_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
762 {
763         int r, g, b;
764         char *cp1, *cp2;
765         
766         cp1= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
767         cp2= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
768
769         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
770         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
771         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
772         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
773         
774         r= r<0?0:(r>255?255:r);
775         g= g<0?0:(g>255?255:g);
776         b= b<0?0:(b>255?255:b);
777         
778         glColor3ub(r, g, b);
779 }
780
781 // get individual values, not scaled
782 float BIF_GetThemeValuef(int colorid)
783 {
784         char *cp;
785         
786         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
787         return ((float)cp[0]);
788
789 }
790
791 // get individual values, not scaled
792 int BIF_GetThemeValue(int colorid)
793 {
794         char *cp;
795         
796         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
797         return ((int) cp[0]);
798
799 }
800
801
802 // get the color, range 0.0-1.0
803 void BIF_GetThemeColor3fv(int colorid, float *col)
804 {
805         char *cp;
806         
807         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
808         col[0]= ((float)cp[0])/255.0;
809         col[1]= ((float)cp[1])/255.0;
810         col[2]= ((float)cp[2])/255.0;
811 }
812
813 // get the color, in char pointer
814 void BIF_GetThemeColor3ubv(int colorid, char *col)
815 {
816         char *cp;
817         
818         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
819         col[0]= cp[0];
820         col[1]= cp[1];
821         col[2]= cp[2];
822 }
823
824 // get the color, in char pointer
825 void BIF_GetThemeColor4ubv(int colorid, char *col)
826 {
827         char *cp;
828         
829         cp= BIF_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
830         col[0]= cp[0];
831         col[1]= cp[1];
832         col[2]= cp[2];
833         col[3]= cp[3];
834 }
835
836 void BIF_GetThemeColorType4ubv(int colorid, int spacetype, char *col)
837 {
838         char *cp;
839         
840         cp= BIF_ThemeGetColorPtr(theme_active, spacetype, colorid);
841         col[0]= cp[0];
842         col[1]= cp[1];
843         col[2]= cp[2];
844         col[3]= cp[3];
845 }
846
847 // blends and shades between two char color pointers
848 void BIF_ColorPtrBlendShade3ubv(char *cp1, char *cp2, float fac, int offset)
849 {
850         int r, g, b;
851         
852         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
853         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
854         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
855         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
856         
857         r= r<0?0:(r>255?255:r);
858         g= g<0?0:(g>255?255:g);
859         b= b<0?0:(b>255?255:b);
860         
861         glColor3ub(r, g, b);
862 }
863
864 // get a 3 byte color, blended and shaded between two other char color pointers
865 void BIF_GetColorPtrBlendShade3ubv(char *cp1, char *cp2, char *col, float fac, int offset)
866 {
867         int r, g, b;
868         
869         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
870         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
871         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
872         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
873         
874         r= r<0?0:(r>255?255:r);
875         g= g<0?0:(g>255?255:g);
876         b= b<0?0:(b>255?255:b);
877         
878         col[0] = r;
879         col[1] = g;
880         col[2] = b;
881 }