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