NLA SoC: Merge from 2.5 20441 to 20570 (HEAD)
[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
44 #include "DNA_curve_types.h"
45 #include "DNA_listBase.h"
46 #include "DNA_userdef_types.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_space_types.h"
49
50 #include "BLI_blenlib.h"
51
52 #include "IMB_imbuf.h"
53 #include "IMB_imbuf_types.h"
54
55 #include "BKE_DerivedMesh.h"
56 #include "BKE_global.h"
57 #include "BKE_main.h"
58 #include "BKE_texture.h"
59 #include "BKE_utildefines.h"
60
61 #include "BIF_gl.h"
62
63 #include "UI_interface.h"
64 #include "UI_resources.h"
65 #include "UI_interface_icons.h"
66
67 #include "interface_intern.h"
68
69 /* global for themes */
70 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
71
72 static bTheme *theme_active=NULL;
73 static int theme_spacetype= SPACE_VIEW3D;
74 static int theme_regionid= RGN_TYPE_WINDOW;
75
76 void ui_resources_init(void)
77 {
78         UI_icons_init(BIFICONID_LAST+1);
79 }
80
81 void ui_resources_free(void)
82 {
83         UI_icons_free();
84 }
85
86
87 /* ******************************************************** */
88 /*    THEMES */
89 /* ******************************************************** */
90
91 char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
92 {
93         ThemeSpace *ts= NULL;
94         static char error[4]={240, 0, 240, 255};
95         static char alert[4]={240, 60, 60, 255};
96         static char headerdesel[4]={0,0,0,255};
97         
98         char *cp= error;
99         
100         if(btheme) {
101         
102                 // first check for ui buttons theme
103                 if(colorid < TH_THEMEUI) {
104                 
105                         switch(colorid) {
106
107                         case TH_REDALERT:
108                                 cp= alert; break;
109                         }
110                 }
111                 else {
112                 
113                         switch(spacetype) {
114                         case SPACE_BUTS:
115                                 ts= &btheme->tbuts;
116                                 break;
117                         case SPACE_VIEW3D:
118                                 ts= &btheme->tv3d;
119                                 break;
120                         case SPACE_IPO:
121                                 ts= &btheme->tipo;
122                                 break;
123                         case SPACE_FILE:
124                                 ts= &btheme->tfile;
125                                 break;
126                         case SPACE_NLA:
127                                 ts= &btheme->tnla;
128                                 break;
129                         case SPACE_ACTION:
130                                 ts= &btheme->tact;
131                                 break;
132                         case SPACE_SEQ:
133                                 ts= &btheme->tseq;
134                                 break;
135                         case SPACE_IMAGE:
136                                 ts= &btheme->tima;
137                                 break;
138                         case SPACE_IMASEL:
139                                 ts= &btheme->timasel;
140                                 break;
141                         case SPACE_TEXT:
142                                 ts= &btheme->text;
143                                 break;
144                         case SPACE_OUTLINER:
145                                 ts= &btheme->toops;
146                                 break;
147                         case SPACE_SOUND:
148                                 ts= &btheme->tsnd;
149                                 break;
150                         case SPACE_INFO:
151                                 ts= &btheme->tinfo;
152                                 break;
153                         case SPACE_TIME:
154                                 ts= &btheme->ttime;
155                                 break;
156                         case SPACE_NODE:
157                                 ts= &btheme->tnode;
158                                 break;
159                         default:
160                                 ts= &btheme->tv3d;
161                                 break;
162                         }
163                         
164                         switch(colorid) {
165                         case TH_BACK:
166                                 if(theme_regionid==RGN_TYPE_WINDOW)
167                                         cp= ts->back;
168                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
169                                         cp= ts->list;
170                                 else if(theme_regionid==RGN_TYPE_HEADER)
171                                         cp= ts->header;
172                                 else
173                                         cp= ts->button; 
174                                 break;
175                         case TH_TEXT:
176                                 if(theme_regionid==RGN_TYPE_WINDOW)
177                                         cp= ts->text; 
178                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
179                                         cp= ts->list_text;
180                                 else if(theme_regionid==RGN_TYPE_HEADER)
181                                         cp= ts->header_text;
182                                 else
183                                         cp= ts->button_text; 
184                                 break;
185                         case TH_TEXT_HI:
186                                 if(theme_regionid==RGN_TYPE_WINDOW)
187                                         cp= ts->text_hi;
188                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
189                                         cp= ts->list_text_hi;
190                                 else if(theme_regionid==RGN_TYPE_HEADER)
191                                         cp= ts->header_text_hi;
192                                 else
193                                         cp= ts->button_text_hi; 
194                                 break;
195                         case TH_TITLE:
196                                 if(theme_regionid==RGN_TYPE_WINDOW)
197                                         cp= ts->title;
198                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
199                                         cp= ts->list_title;
200                                 else if(theme_regionid==RGN_TYPE_HEADER)
201                                         cp= ts->header_title;
202                                 else
203                                         cp= ts->button_title; 
204                                 break;
205                                 
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_HEADER_TEXT:
217                                 cp= ts->header_text; break;
218                         case TH_HEADER_TEXT_HI:
219                                 cp= ts->header_text_hi; break;
220                                 
221                         case TH_PANEL:
222                                 cp= ts->panel; break;
223                         case TH_PANEL_TEXT:
224                                 cp= ts->panel_text; break;
225                         case TH_PANEL_TEXT_HI:
226                                 cp= ts->panel_text_hi; break;
227                                 
228                         case TH_BUTBACK:
229                                 cp= ts->button; break;
230                         case TH_BUTBACK_TEXT:
231                                 cp= ts->button_text; break;
232                         case TH_BUTBACK_TEXT_HI:
233                                 cp= ts->button_text_hi; break;
234                                 
235                         case TH_SHADE1:
236                                 cp= ts->shade1; break;
237                         case TH_SHADE2:
238                                 cp= ts->shade2; break;
239                         case TH_HILITE:
240                                 cp= ts->hilite; break;
241                                 
242                         case TH_GRID:
243                                 cp= ts->grid; break;
244                         case TH_WIRE:
245                                 cp= ts->wire; break;
246                         case TH_LAMP:
247                                 cp= ts->lamp; break;
248                         case TH_SELECT:
249                                 cp= ts->select; break;
250                         case TH_ACTIVE:
251                                 cp= ts->active; break;
252                         case TH_GROUP:
253                                 cp= ts->group; break;
254                         case TH_GROUP_ACTIVE:
255                                 cp= ts->group_active; break;
256                         case TH_TRANSFORM:
257                                 cp= ts->transform; break;
258                         case TH_VERTEX:
259                                 cp= ts->vertex; break;
260                         case TH_VERTEX_SELECT:
261                                 cp= ts->vertex_select; break;
262                         case TH_VERTEX_SIZE:
263                                 cp= &ts->vertex_size; break;
264                         case TH_EDGE:
265                                 cp= ts->edge; break;
266                         case TH_EDGE_SELECT:
267                                 cp= ts->edge_select; break;
268                         case TH_EDGE_SEAM:
269                                 cp= ts->edge_seam; break;
270                         case TH_EDGE_SHARP:
271                                 cp= ts->edge_sharp; break;
272                         case TH_EDITMESH_ACTIVE:
273                                 cp= ts->editmesh_active; break;
274                         case TH_EDGE_FACESEL:
275                                 cp= ts->edge_facesel; break;
276                         case TH_FACE:
277                                 cp= ts->face; break;
278                         case TH_FACE_SELECT:
279                                 cp= ts->face_select; break;
280                         case TH_FACE_DOT:
281                                 cp= ts->face_dot; break;
282                         case TH_FACEDOT_SIZE:
283                                 cp= &ts->facedot_size; break;
284                         case TH_NORMAL:
285                                 cp= ts->normal; break;
286                         case TH_BONE_SOLID:
287                                 cp= ts->bone_solid; break;
288                         case TH_BONE_POSE:
289                                 cp= ts->bone_pose; break;
290                         case TH_STRIP:
291                                 cp= ts->strip; break;
292                         case TH_STRIP_SELECT:
293                                 cp= ts->strip_select; break;
294                         case TH_CFRAME:
295                                 cp= ts->cframe; break;
296                                 
297                         case TH_SYNTAX_B:
298                                 cp= ts->syntaxb; break;
299                         case TH_SYNTAX_V:
300                                 cp= ts->syntaxv; break;
301                         case TH_SYNTAX_C:
302                                 cp= ts->syntaxc; break;
303                         case TH_SYNTAX_L:
304                                 cp= ts->syntaxl; break;
305                         case TH_SYNTAX_N:
306                                 cp= ts->syntaxn; break;
307
308                         case TH_NODE:
309                                 cp= ts->syntaxl; break;
310                         case TH_NODE_IN_OUT:
311                                 cp= ts->syntaxn; break;
312                         case TH_NODE_OPERATOR:
313                                 cp= ts->syntaxb; break;
314                         case TH_NODE_CONVERTOR:
315                                 cp= ts->syntaxv; break;
316                         case TH_NODE_GROUP:
317                                 cp= ts->syntaxc; break;
318                                 
319                         case TH_SEQ_MOVIE:
320                                 cp= ts->movie; break;
321                         case TH_SEQ_IMAGE:
322                                 cp= ts->image; break;
323                         case TH_SEQ_SCENE:
324                                 cp= ts->scene; break;
325                         case TH_SEQ_AUDIO:
326                                 cp= ts->audio; break;
327                         case TH_SEQ_EFFECT:
328                                 cp= ts->effect; break;
329                         case TH_SEQ_PLUGIN:
330                                 cp= ts->plugin; break;
331                         case TH_SEQ_TRANSITION:
332                                 cp= ts->transition; break;
333                         case TH_SEQ_META:
334                                 cp= ts->meta; break;
335                                 
336                         case TH_HANDLE_VERTEX:
337                                 cp= ts->handle_vertex;
338                                 break;
339                         case TH_HANDLE_VERTEX_SELECT:
340                                 cp= ts->handle_vertex_select;
341                                 break;
342                         case TH_HANDLE_VERTEX_SIZE:
343                                 cp= &ts->handle_vertex_size;
344                                 break;
345                                 
346                         case TH_DOPESHEET_CHANNELOB:
347                                 cp= ts->ds_channel;
348                                 break;
349                         case TH_DOPESHEET_CHANNELSUBOB:
350                                 cp= ts->ds_subchannel;
351                                 break;  
352                                 
353                         }
354                 }
355         }
356         
357         return cp;
358 }
359
360 #define SETCOLTEST(col, r, g, b, a)  if(col[3]==0) {col[0]=r; col[1]=g; col[2]= b; col[3]= a;}
361
362 /* use this call to init new variables in themespace, if they're same for all */
363 static void ui_theme_init_new_do(ThemeSpace *ts)
364 {
365         SETCOLTEST(ts->header_text,             0, 0, 0, 255);
366         SETCOLTEST(ts->header_title,    0, 0, 0, 255);
367         SETCOLTEST(ts->header_text_hi,  255, 255, 255, 255);
368         
369         SETCOLTEST(ts->panel_text,              0, 0, 0, 255);
370         SETCOLTEST(ts->panel_title,             0, 0, 0, 255);
371         SETCOLTEST(ts->panel_text_hi,   255, 255, 255, 255);
372         
373         SETCOLTEST(ts->button,                  145, 145, 145, 245);
374         SETCOLTEST(ts->button_title,    0, 0, 0, 255);
375         SETCOLTEST(ts->button_text,             0, 0, 0, 255);
376         SETCOLTEST(ts->button_text_hi,  255, 255, 255, 255);
377         
378         SETCOLTEST(ts->list,                    165, 165, 165, 255);
379         SETCOLTEST(ts->list_title,              0, 0, 0, 255);
380         SETCOLTEST(ts->list_text,               0, 0, 0, 255);
381         SETCOLTEST(ts->list_text_hi,    255, 255, 255, 255);
382 }
383
384 static void ui_theme_init_new(bTheme *btheme)
385 {
386         ui_theme_init_new_do(&btheme->tbuts);
387         ui_theme_init_new_do(&btheme->tv3d);
388         ui_theme_init_new_do(&btheme->tfile);
389         ui_theme_init_new_do(&btheme->tipo);
390         ui_theme_init_new_do(&btheme->tinfo);
391         ui_theme_init_new_do(&btheme->tsnd);
392         ui_theme_init_new_do(&btheme->tact);
393         ui_theme_init_new_do(&btheme->tnla);
394         ui_theme_init_new_do(&btheme->tseq);
395         ui_theme_init_new_do(&btheme->tima);
396         ui_theme_init_new_do(&btheme->timasel);
397         ui_theme_init_new_do(&btheme->text);
398         ui_theme_init_new_do(&btheme->toops);
399         ui_theme_init_new_do(&btheme->ttime);
400         ui_theme_init_new_do(&btheme->tnode);
401         
402 }
403
404 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
405 #define SETCOLF(col, r, g, b, a)  col[0]=r*255; col[1]=g*255; col[2]= b*255; col[3]= a*255;
406
407 /* initialize default theme, can't be edited
408    Note: when you add new colors, created & saved themes need initialized
409    use function below, init_userdef_do_versions() 
410 */
411 void ui_theme_init_userdef(void)
412 {
413         bTheme *btheme= U.themes.first;
414         
415         /* we search for the theme with name Default */
416         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
417                 if(strcmp("Default", btheme->name)==0) break;
418         }
419         
420         if(btheme==NULL) {
421                 btheme= MEM_callocN(sizeof(bTheme), "theme");
422                 BLI_addtail(&U.themes, btheme);
423                 strcpy(btheme->name, "Default");
424         }
425         
426         UI_SetTheme(0, 0);      // make sure the global used in this file is set
427
428         /* UI buttons */
429         ui_widget_color_init(&btheme->tui);
430
431         /* common (new) variables */
432         ui_theme_init_new(btheme);
433         
434         /* space view3d */
435         SETCOLF(btheme->tv3d.back,       0.225, 0.225, 0.225, 1.0);
436         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
437         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
438         
439         SETCOLF(btheme->tv3d.header,    0.45, 0.45, 0.45, 1.0);
440         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
441         
442         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
443         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
444
445         SETCOLF(btheme->tv3d.grid,     0.251, 0.251, 0.251, 1.0);
446         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
447         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
448         SETCOL(btheme->tv3d.select, 241, 88, 0, 255);
449         SETCOL(btheme->tv3d.active, 255, 140, 25, 255);
450         SETCOL(btheme->tv3d.group,      16, 64, 16, 255);
451         SETCOL(btheme->tv3d.group_active, 85, 187, 85, 255);
452         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
453         SETCOL(btheme->tv3d.vertex, 0, 0, 0, 255);
454         SETCOL(btheme->tv3d.vertex_select, 255, 133, 0, 255);
455         btheme->tv3d.vertex_size= 3;
456         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
457         SETCOL(btheme->tv3d.edge_select, 255, 160, 0, 255);
458         SETCOL(btheme->tv3d.edge_seam, 219, 37, 18, 255);
459         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
460         SETCOL(btheme->tv3d.face,       0, 0, 0, 18);
461         SETCOL(btheme->tv3d.face_select, 255, 133, 0, 60);
462         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
463         SETCOL(btheme->tv3d.face_dot, 255, 133, 0, 255);
464         btheme->tv3d.facedot_size= 4;
465         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0,  0x40, 255);
466
467         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
468         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
469         
470         
471         /* space buttons */
472         /* to have something initialized */
473         btheme->tbuts= btheme->tv3d;
474
475         SETCOLF(btheme->tbuts.back,     0.45, 0.45, 0.45, 1.0);
476         SETCOL(btheme->tbuts.panel, 0x82, 0x82, 0x82, 255);
477
478         /* graph editor */
479         btheme->tipo= btheme->tv3d;
480         SETCOLF(btheme->tipo.back,      0.42, 0.42, 0.42, 1.0);
481         SETCOLF(btheme->tipo.list,      0.4, 0.4, 0.4, 1.0);
482         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
483         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
484         SETCOL(btheme->tipo.shade1,             150, 150, 150, 100);    /* scrollbars */
485         SETCOL(btheme->tipo.shade2,             0x70, 0x70, 0x70, 100);
486         SETCOL(btheme->tipo.vertex,             0, 0, 0, 255);
487         SETCOL(btheme->tipo.vertex_select, 255, 133, 0, 255);
488         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
489         btheme->tipo.vertex_size= 3;
490
491         SETCOL(btheme->tipo.handle_vertex,              0, 0, 0, 255);
492         SETCOL(btheme->tipo.handle_vertex_select, 255, 133, 0, 255);
493         btheme->tipo.handle_vertex_size= 3;
494         
495         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
496         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
497         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
498         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
499
500         /* dopesheet */
501         btheme->tact= btheme->tipo;
502         SETCOL(btheme->tact.strip,                      12, 10, 10, 128); 
503         SETCOL(btheme->tact.strip_select,       255, 140, 0, 255); 
504         
505         /* space nla */
506         btheme->tnla= btheme->tact;
507         
508         /* space file */
509         /* to have something initialized */
510         btheme->tfile= btheme->tv3d;
511         SETCOL(btheme->tfile.back,      90, 90, 90, 255);
512         SETCOL(btheme->tfile.text,      250, 250, 250, 255);
513         SETCOL(btheme->tfile.text_hi, 15, 15, 15, 255);
514         SETCOL(btheme->tfile.panel, 180, 180, 180, 255);        // bookmark/ui regions
515         SETCOL(btheme->tfile.active, 130, 130, 130, 255); // selected files
516         SETCOL(btheme->tfile.hilite, 255, 140, 25, 255); // selected files
517         
518         SETCOL(btheme->tfile.grid,      250, 250, 250, 255);
519         SETCOL(btheme->tfile.image,     250, 250, 250, 255);
520         SETCOL(btheme->tfile.movie,     250, 250, 250, 255);
521         SETCOL(btheme->tfile.scene,     250, 250, 250, 255);
522
523         
524         /* space seq */
525         btheme->tseq= btheme->tv3d;
526         SETCOL(btheme->tseq.back,       116, 116, 116, 255);
527         SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
528         SETCOL(btheme->tseq.image,      109, 88, 129, 255);
529         SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
530         SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
531         SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
532         SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
533         SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
534         SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
535         
536
537         /* space image */
538         btheme->tima= btheme->tv3d;
539         SETCOL(btheme->tima.back,       53, 53, 53, 255);
540         SETCOL(btheme->tima.vertex, 0, 0, 0, 255);
541         SETCOL(btheme->tima.vertex_select, 255, 133, 0, 255);
542         btheme->tima.vertex_size= 3;
543         btheme->tima.facedot_size= 3;
544         SETCOL(btheme->tima.face,   255, 255, 255, 10);
545         SETCOL(btheme->tima.face_select, 255, 133, 0, 60);
546         SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
547
548         /* space imageselect */
549         btheme->timasel= btheme->tv3d;
550         SETCOL(btheme->timasel.active,  195, 195, 195, 255); /* active tile */
551         SETCOL(btheme->timasel.grid,  94, 94, 94, 255); /* active file text */
552         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
553         SETCOL(btheme->timasel.shade1,  94, 94, 94, 255);       /* bar */
554         SETCOL(btheme->timasel.shade2,  172, 172, 172, 255); /* sliders */
555         SETCOL(btheme->timasel.hilite,  17, 27, 60, 100);       /* selected tile */
556         SETCOL(btheme->timasel.text,    0, 0, 0, 255);
557         SETCOL(btheme->timasel.text_hi, 255, 255, 255, 255);
558         SETCOL(btheme->timasel.panel,   132, 132, 132, 255);
559
560         /* space text */
561         btheme->text= btheme->tv3d;
562         SETCOL(btheme->text.back,       153, 153, 153, 255);
563         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
564         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
565         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
566         
567         /* syntax highlighting */
568         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
569         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
570         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
571         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
572         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
573         
574         /* space oops */
575         btheme->toops= btheme->tv3d;
576         SETCOLF(btheme->toops.back,     0.45, 0.45, 0.45, 1.0);
577         
578         /* space info */
579         btheme->tinfo= btheme->tv3d;
580         SETCOL(btheme->tinfo.back,      153, 153, 153, 255);
581
582         /* space sound */
583         btheme->tsnd= btheme->tv3d;
584         SETCOLF(btheme->tsnd.back,      0.45, 0.45, 0.45, 1.0);
585         SETCOLF(btheme->tsnd.grid,      0.36, 0.36, 0.36, 1.0);
586         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
587         
588         /* space time */
589         btheme->ttime= btheme->tsnd;    // same as sound space
590         
591         /* space node, re-uses syntax color storage */
592         btheme->tnode= btheme->tv3d;
593         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
594         SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
595         SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
596         SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
597         SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
598         SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
599
600 }
601
602
603 void UI_SetTheme(int spacetype, int regionid)
604 {
605         if(spacetype==0) {      // called for safety, when delete themes
606                 theme_active= U.themes.first;
607                 theme_spacetype= SPACE_VIEW3D;
608                 theme_regionid= RGN_TYPE_WINDOW;
609         }
610         else {
611                 // later on, a local theme can be found too
612                 theme_active= U.themes.first;
613                 theme_spacetype= spacetype;
614                 theme_regionid= regionid;
615         }
616 }
617
618 // for space windows only
619 void UI_ThemeColor(int colorid)
620 {
621         char *cp;
622         
623         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
624         glColor3ub(cp[0], cp[1], cp[2]);
625
626 }
627
628 // plus alpha
629 void UI_ThemeColor4(int colorid)
630 {
631         char *cp;
632         
633         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
634         glColor4ub(cp[0], cp[1], cp[2], cp[3]);
635
636 }
637
638 // set the color with offset for shades
639 void UI_ThemeColorShade(int colorid, int offset)
640 {
641         int r, g, b;
642         char *cp;
643         
644         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
645         r= offset + (int) cp[0];
646         CLAMP(r, 0, 255);
647         g= offset + (int) cp[1];
648         CLAMP(g, 0, 255);
649         b= offset + (int) cp[2];
650         CLAMP(b, 0, 255);
651         //glColor3ub(r, g, b);
652         glColor4ub(r, g, b, cp[3]);
653 }
654 void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
655 {
656         int r, g, b, a;
657         char *cp;
658         
659         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
660         r= coloffset + (int) cp[0];
661         CLAMP(r, 0, 255);
662         g= coloffset + (int) cp[1];
663         CLAMP(g, 0, 255);
664         b= coloffset + (int) cp[2];
665         CLAMP(b, 0, 255);
666         a= alphaoffset + (int) cp[3];
667         CLAMP(a, 0, 255);
668         glColor4ub(r, g, b, a);
669 }
670
671 // blend between to theme colors, and set it
672 void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
673 {
674         int r, g, b;
675         char *cp1, *cp2;
676         
677         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
678         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
679
680         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
681         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
682         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
683         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
684         
685         glColor3ub(r, g, b);
686 }
687
688 // blend between to theme colors, shade it, and set it
689 void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
690 {
691         int r, g, b;
692         char *cp1, *cp2;
693         
694         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
695         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
696
697         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
698         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
699         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
700         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
701         
702         CLAMP(r, 0, 255);
703         CLAMP(g, 0, 255);
704         CLAMP(b, 0, 255);
705         
706         glColor3ub(r, g, b);
707 }
708
709 // blend between to theme colors, shade it, and set it
710 void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
711 {
712         int r, g, b, a;
713         char *cp1, *cp2;
714         
715         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
716         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
717
718         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
719         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
720         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
721         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
722         a= alphaoffset+floor((1.0-fac)*cp1[3] + fac*cp2[3]);
723         
724         CLAMP(r, 0, 255);
725         CLAMP(g, 0, 255);
726         CLAMP(b, 0, 255);
727         CLAMP(a, 0, 255);
728
729         glColor4ub(r, g, b, a);
730 }
731
732
733 // get individual values, not scaled
734 float UI_GetThemeValuef(int colorid)
735 {
736         char *cp;
737         
738         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
739         return ((float)cp[0]);
740
741 }
742
743 // get individual values, not scaled
744 int UI_GetThemeValue(int colorid)
745 {
746         char *cp;
747         
748         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
749         return ((int) cp[0]);
750
751 }
752
753
754 // get the color, range 0.0-1.0
755 void UI_GetThemeColor3fv(int colorid, float *col)
756 {
757         char *cp;
758         
759         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
760         col[0]= ((float)cp[0])/255.0;
761         col[1]= ((float)cp[1])/255.0;
762         col[2]= ((float)cp[2])/255.0;
763 }
764
765 // get the color, in char pointer
766 void UI_GetThemeColor3ubv(int colorid, char *col)
767 {
768         char *cp;
769         
770         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
771         col[0]= cp[0];
772         col[1]= cp[1];
773         col[2]= cp[2];
774 }
775
776 // get the color, in char pointer
777 void UI_GetThemeColor4ubv(int colorid, char *col)
778 {
779         char *cp;
780         
781         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
782         col[0]= cp[0];
783         col[1]= cp[1];
784         col[2]= cp[2];
785         col[3]= cp[3];
786 }
787
788 void UI_GetThemeColorType4ubv(int colorid, int spacetype, char *col)
789 {
790         char *cp;
791         
792         cp= UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
793         col[0]= cp[0];
794         col[1]= cp[1];
795         col[2]= cp[2];
796         col[3]= cp[3];
797 }
798
799 // blends and shades between two char color pointers
800 void UI_ColorPtrBlendShade3ubv(char *cp1, char *cp2, float fac, int offset)
801 {
802         int r, g, b;
803         
804         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
805         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
806         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
807         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
808         
809         r= r<0?0:(r>255?255:r);
810         g= g<0?0:(g>255?255:g);
811         b= b<0?0:(b>255?255:b);
812         
813         glColor3ub(r, g, b);
814 }
815
816 // get a 3 byte color, blended and shaded between two other char color pointers
817 void UI_GetColorPtrBlendShade3ubv(char *cp1, char *cp2, char *col, float fac, int offset)
818 {
819         int r, g, b;
820         
821         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
822         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
823         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
824         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
825         
826         r= r<0?0:(r>255?255:r);
827         g= g<0?0:(g>255?255:g);
828         b= b<0?0:(b>255?255:b);
829         
830         col[0] = r;
831         col[1] = g;
832         col[2] = b;
833 }
834
835 void UI_make_axis_color(char *src_col, char *dst_col, char axis)
836 {
837         switch(axis)
838         {
839                 case 'x':
840                 case 'X':
841                         dst_col[0]= src_col[0]>219?255:src_col[0]+36;
842                         dst_col[1]= src_col[1]<26?0:src_col[1]-26;
843                         dst_col[2]= src_col[2]<26?0:src_col[2]-26;
844                         break;
845                 case 'y':
846                 case 'Y':
847                         dst_col[0]= src_col[0]<46?0:src_col[0]-36;
848                         dst_col[1]= src_col[1]>189?255:src_col[1]+66;
849                         dst_col[2]= src_col[2]<46?0:src_col[2]-36;
850                         break;
851                 default: 
852                         dst_col[0]= src_col[0]<26?0:src_col[0]-26; 
853                         dst_col[1]= src_col[1]<26?0:src_col[1]-26; 
854                         dst_col[2]= src_col[2]>209?255:src_col[2]+46;
855         }
856 }
857
858 /* ************************************************************* */
859
860 /* patching UserDef struct and Themes */
861 void init_userdef_do_versions(void)
862 {
863 //      countall();
864         
865         /* the UserDef struct is not corrected with do_versions() .... ugh! */
866         if(U.wheellinescroll == 0) U.wheellinescroll = 3;
867         if(U.menuthreshold1==0) {
868                 U.menuthreshold1= 5;
869                 U.menuthreshold2= 2;
870         }
871         if(U.tb_leftmouse==0) {
872                 U.tb_leftmouse= 5;
873                 U.tb_rightmouse= 5;
874         }
875         if(U.mixbufsize==0) U.mixbufsize= 2048;
876         if (BLI_streq(U.tempdir, "/")) {
877                 char *tmp= getenv("TEMP");
878                 
879                 strcpy(U.tempdir, tmp?tmp:"/tmp/");
880         }
881         if (U.savetime <= 0) {
882                 U.savetime = 1;
883 // XXX          error(".B.blend is buggy, please consider removing it.\n");
884         }
885         /* transform widget settings */
886         if(U.tw_hotspot==0) {
887                 U.tw_hotspot= 14;
888                 U.tw_size= 20;                  // percentage of window size
889                 U.tw_handlesize= 16;    // percentage of widget radius
890         }
891         if(U.pad_rot_angle==0)
892                 U.pad_rot_angle= 15;
893         
894         if(U.flag & USER_CUSTOM_RANGE) 
895                 vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
896         
897         if (G.main->versionfile <= 191) {
898                 strcpy(U.plugtexdir, U.textudir);
899                 strcpy(U.sounddir, "/");
900         }
901         
902         /* patch to set Dupli Armature */
903         if (G.main->versionfile < 220) {
904                 U.dupflag |= USER_DUP_ARM;
905         }
906         
907         /* added seam, normal color, undo */
908         if (G.main->versionfile <= 234) {
909                 bTheme *btheme;
910                 
911                 U.uiflag |= USER_GLOBALUNDO;
912                 if (U.undosteps==0) U.undosteps=32;
913                 
914                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
915                         /* check for alpha==0 is safe, then color was never set */
916                         if(btheme->tv3d.edge_seam[3]==0) {
917                                 SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
918                         }
919                         if(btheme->tv3d.normal[3]==0) {
920                                 SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
921                         }
922                         if(btheme->tv3d.face_dot[3]==0) {
923                                 SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
924                                 btheme->tv3d.facedot_size= 4;
925                         }
926                 }
927         }
928         if (G.main->versionfile <= 235) {
929                 /* illegal combo... */
930                 if (U.flag & USER_LMOUSESELECT) 
931                         U.flag &= ~USER_TWOBUTTONMOUSE;
932         }
933         if (G.main->versionfile <= 236) {
934                 bTheme *btheme;
935                 /* new space type */
936                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
937                         /* check for alpha==0 is safe, then color was never set */
938                         if(btheme->ttime.back[3]==0) {
939                                 btheme->ttime = btheme->tsnd;   // copy from sound
940                         }
941                         if(btheme->text.syntaxn[3]==0) {
942                                 SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
943                                 SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
944                                 SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
945                                 SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
946                                 SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
947                         }
948                 }
949         }
950         if (G.main->versionfile <= 237) {
951                 bTheme *btheme;
952                 /* bone colors */
953                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
954                         /* check for alpha==0 is safe, then color was never set */
955                         if(btheme->tv3d.bone_solid[3]==0) {
956                                 SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
957                                 SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
958                         }
959                 }
960         }
961         if (G.main->versionfile <= 238) {
962                 bTheme *btheme;
963                 /* bone colors */
964                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
965                         /* check for alpha==0 is safe, then color was never set */
966                         if(btheme->tnla.strip[3]==0) {
967                                 SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
968                                 SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
969                         }
970                 }
971         }
972         if (G.main->versionfile <= 239) {
973                 bTheme *btheme;
974                 
975                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
976                         /* Lamp theme, check for alpha==0 is safe, then color was never set */
977                         if(btheme->tv3d.lamp[3]==0) {
978                                 SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
979 /* TEMPORAL, remove me! (ton) */                                
980                                 U.uiflag |= USER_PLAINMENUS;
981                         }
982                         
983                 }
984                 if(U.obcenter_dia==0) U.obcenter_dia= 6;
985         }
986         if (G.main->versionfile <= 241) {
987                 bTheme *btheme;
988                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
989                         /* Node editor theme, check for alpha==0 is safe, then color was never set */
990                         if(btheme->tnode.syntaxn[3]==0) {
991                                 /* re-uses syntax color storage */
992                                 btheme->tnode= btheme->tv3d;
993                                 SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
994                                 SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
995                                 SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
996                                 SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
997                                 SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
998                                 SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
999                         }
1000                         /* Group theme colors */
1001                         if(btheme->tv3d.group[3]==0) {
1002                                 SETCOL(btheme->tv3d.group, 0x10, 0x40, 0x10, 255);
1003                                 SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
1004                         }
1005                         /* Sequence editor theme*/
1006                         if(btheme->tseq.movie[3]==0) {
1007                                 SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
1008                                 SETCOL(btheme->tseq.image,      109, 88, 129, 255);
1009                                 SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
1010                                 SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
1011                                 SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
1012                                 SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
1013                                 SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
1014                                 SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
1015                         }
1016                 }
1017                 
1018                 /* set defaults for 3D View rotating axis indicator */ 
1019                 /* since size can't be set to 0, this indicates it's not saved in .B.blend */
1020                 if (U.rvisize == 0) {
1021                         U.rvisize = 15;
1022                         U.rvibright = 8;
1023                         U.uiflag |= USER_SHOW_ROTVIEWICON;
1024                 }
1025                 
1026         }
1027         if (G.main->versionfile <= 242) {
1028                 bTheme *btheme;
1029                 
1030                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1031                         /* long keyframe color */
1032                         /* check for alpha==0 is safe, then color was never set */
1033                         if(btheme->tact.strip[3]==0) {
1034                                 SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
1035                                 SETCOL(btheme->tact.strip_select,       0xff, 0xff, 0xaa, 204);
1036                                 SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
1037                         }
1038                         
1039                         /* IPO-Editor - Vertex Size*/
1040                         if(btheme->tipo.vertex_size == 0) {
1041                                 btheme->tipo.vertex_size= 3;
1042                         }
1043                 }
1044         }
1045         if (G.main->versionfile <= 243) {
1046                 /* set default number of recently-used files (if not set) */
1047                 if (U.recent_files == 0) U.recent_files = 10;
1048         }
1049         if (G.main->versionfile < 245 || (G.main->versionfile == 245 && G.main->subversionfile < 3)) {
1050                 bTheme *btheme;
1051                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1052                         SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
1053                 }
1054                 if(U.coba_weight.tot==0)
1055                         init_colorband(&U.coba_weight, 1);
1056         }
1057         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
1058                 bTheme *btheme;
1059                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1060                         /* these should all use the same colour */
1061                         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1062                         SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1063                         SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1064                         SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1065                         SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1066                         SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
1067                         SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1068                 }
1069         }
1070         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
1071                 bTheme *btheme;
1072                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1073                         /* these should all use the same color */
1074                         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1075                         SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1076                         SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1077                         SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1078                         SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1079                         SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
1080                         SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1081                 }
1082         }
1083         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 13)) {
1084                 bTheme *btheme;
1085                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1086                         /* action channel groups (recolor anyway) */
1087                         SETCOL(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
1088                         SETCOL(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
1089                         
1090                         /* bone custom-color sets */
1091                         // FIXME: this check for initialised colors is bad
1092                         if (btheme->tarm[0].solid[3] == 0) {
1093                                         /* set 1 */
1094                                 SETCOL(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
1095                                 SETCOL(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
1096                                 SETCOL(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
1097                                         /* set 2 */
1098                                 SETCOL(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
1099                                 SETCOL(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
1100                                 SETCOL(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
1101                                         /* set 3 */
1102                                 SETCOL(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
1103                                 SETCOL(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
1104                                 SETCOL(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
1105                                         /* set 4 */
1106                                 SETCOL(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
1107                                 SETCOL(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
1108                                 SETCOL(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
1109                                         /* set 5 */
1110                                 SETCOL(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
1111                                 SETCOL(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
1112                                 SETCOL(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
1113                                         /* set 6 */
1114                                 SETCOL(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
1115                                 SETCOL(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
1116                                 SETCOL(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
1117                                         /* set 7 */
1118                                 SETCOL(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
1119                                 SETCOL(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
1120                                 SETCOL(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
1121                                         /* set 8 */
1122                                 SETCOL(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
1123                                 SETCOL(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
1124                                 SETCOL(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
1125                                         /* set 9 */
1126                                 SETCOL(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
1127                                 SETCOL(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
1128                                 SETCOL(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
1129                                         /* set 10 */
1130                                 SETCOL(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
1131                                 SETCOL(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
1132                                 SETCOL(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
1133                                         /* set 11 */
1134                                 SETCOL(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
1135                                 SETCOL(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
1136                                 SETCOL(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
1137                                         /* set 12 */
1138                                 SETCOL(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
1139                                 SETCOL(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
1140                                 SETCOL(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
1141                                         /* set 13 */
1142                                 SETCOL(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
1143                                 SETCOL(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
1144                                 SETCOL(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
1145                                         /* set 14 */
1146                                 SETCOL(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
1147                                 SETCOL(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
1148                                 SETCOL(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
1149                                         /* set 15 */
1150                                 SETCOL(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
1151                                 SETCOL(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
1152                                 SETCOL(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
1153                         }
1154                 }
1155         }
1156         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 16)) {
1157                 U.flag |= USER_ADD_VIEWALIGNED|USER_ADD_EDITMODE;
1158         }
1159         if ((G.main->versionfile < 247) || (G.main->versionfile == 247 && G.main->subversionfile <= 2)) {
1160                 bTheme *btheme;
1161                 
1162                 /* adjust themes */
1163                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1164                         char *col;
1165                         
1166                         /* IPO Editor: Handles/Vertices */
1167                         col = btheme->tipo.vertex;
1168                         SETCOL(btheme->tipo.handle_vertex, col[0], col[1], col[2], 255);
1169                         col = btheme->tipo.vertex_select;
1170                         SETCOL(btheme->tipo.handle_vertex_select, col[0], col[1], col[2], 255);
1171                         btheme->tipo.handle_vertex_size= btheme->tipo.vertex_size;
1172                         
1173                         /* Sequence/Image Editor: colors for GPencil text */
1174                         col = btheme->tv3d.bone_pose;
1175                         SETCOL(btheme->tseq.bone_pose, col[0], col[1], col[2], 255);
1176                         SETCOL(btheme->tima.bone_pose, col[0], col[1], col[2], 255);
1177                         col = btheme->tv3d.vertex_select;
1178                         SETCOL(btheme->tseq.vertex_select, col[0], col[1], col[2], 255);
1179                 }
1180         }
1181         if (G.main->versionfile < 250) {
1182                 bTheme *btheme;
1183                 
1184                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1185                         /* this was not properly initialized in 2.45 */
1186                         if(btheme->tima.face_dot[3]==0) {
1187                                 SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
1188                                 SETCOL(btheme->tima.face_dot, 255, 133, 0, 255);
1189                                 btheme->tima.facedot_size= 2;
1190                         }
1191                         
1192                         /* DopeSheet - (Object) Channel color */
1193                         SETCOL(btheme->tact.ds_channel,         82, 96, 110, 255);
1194                         SETCOL(btheme->tact.ds_subchannel,      124, 137, 150, 255);
1195                         /* DopeSheet - Group Channel color (saner version) */
1196                         SETCOL(btheme->tact.group, 79, 101, 73, 255);
1197                         SETCOL(btheme->tact.group_active, 135, 177, 125, 255);
1198                         
1199                         /* Graph Editor - (Object) Channel color */
1200                         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
1201                         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
1202                         /* Graph Editor - Group Channel color */
1203                         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
1204                         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
1205                 }
1206                 
1207                 /* adjust grease-pencil distances */
1208                 U.gp_manhattendist= 1;
1209                 U.gp_euclideandist= 2;
1210                 
1211                 /* adjust default interpolation for new IPO-curves */
1212                 U.ipo_new= BEZT_IPO_BEZ;
1213         }
1214         
1215         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 1)) {
1216                 bTheme *btheme;
1217
1218                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1219                         
1220                         /* common (new) variables, it checks for alpha==0 */
1221                         ui_theme_init_new(btheme);
1222
1223                         if(btheme->tui.wcol_num.outline[3]==0)
1224                                 ui_widget_color_init(&btheme->tui);
1225                 }
1226         }
1227         
1228         /* GL Texture Garbage Collection (variable abused above!) */
1229         if (U.textimeout == 0) {
1230                 U.texcollectrate = 60;
1231                 U.textimeout = 120;
1232         }
1233         if (U.memcachelimit <= 0) {
1234                 U.memcachelimit = 32;
1235         }
1236         if (U.frameserverport == 0) {
1237                 U.frameserverport = 8080;
1238         }
1239
1240         /* funny name, but it is GE stuff, moves userdef stuff to engine */
1241 // XXX  space_set_commmandline_options();
1242         /* this timer uses U */
1243 // XXX  reset_autosave();
1244
1245 }
1246
1247
1248