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