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