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