synched with trunk at revision 34793
[blender-staging.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #include "MEM_guardedalloc.h"
38
39 #include "DNA_curve_types.h"
40 #include "DNA_userdef_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_space_types.h"
43 #include "DNA_windowmanager_types.h"
44
45 #include "BLI_blenlib.h"
46 #include "BLI_utildefines.h"
47
48 #include "BKE_DerivedMesh.h"
49 #include "BKE_global.h"
50 #include "BKE_main.h"
51 #include "BKE_texture.h"
52
53
54 #include "BIF_gl.h"
55
56 #include "UI_interface.h"
57 #include "UI_interface_icons.h"
58
59 #include "interface_intern.h"
60
61 /* global for themes */
62 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
63
64 static bTheme *theme_active=NULL;
65 static int theme_spacetype= SPACE_VIEW3D;
66 static int theme_regionid= RGN_TYPE_WINDOW;
67
68 void ui_resources_init(void)
69 {
70         UI_icons_init(BIFICONID_LAST);
71 }
72
73 void ui_resources_free(void)
74 {
75         UI_icons_free();
76 }
77
78
79 /* ******************************************************** */
80 /*    THEMES */
81 /* ******************************************************** */
82
83 const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
84 {
85         ThemeSpace *ts= NULL;
86         static char error[4]={240, 0, 240, 255};
87         static char alert[4]={240, 60, 60, 255};
88         static char headerdesel[4]={0,0,0,255};
89         
90         const char *cp= error;
91         
92         if(btheme) {
93         
94                 // first check for ui buttons theme
95                 if(colorid < TH_THEMEUI) {
96                 
97                         switch(colorid) {
98
99                         case TH_REDALERT:
100                                 cp= alert; break;
101                         }
102                 }
103                 else {
104                 
105                         switch(spacetype) {
106                         case SPACE_BUTS:
107                                 ts= &btheme->tbuts;
108                                 break;
109                         case SPACE_VIEW3D:
110                                 ts= &btheme->tv3d;
111                                 break;
112                         case SPACE_IPO:
113                                 ts= &btheme->tipo;
114                                 break;
115                         case SPACE_FILE:
116                                 ts= &btheme->tfile;
117                                 break;
118                         case SPACE_NLA:
119                                 ts= &btheme->tnla;
120                                 break;
121                         case SPACE_ACTION:
122                                 ts= &btheme->tact;
123                                 break;
124                         case SPACE_SEQ:
125                                 ts= &btheme->tseq;
126                                 break;
127                         case SPACE_IMAGE:
128                                 ts= &btheme->tima;
129                                 break;
130                         case SPACE_IMASEL:
131                                 ts= &btheme->timasel;
132                                 break;
133                         case SPACE_TEXT:
134                                 ts= &btheme->text;
135                                 break;
136                         case SPACE_OUTLINER:
137                                 ts= &btheme->toops;
138                                 break;
139                         case SPACE_SOUND:
140                                 ts= &btheme->tsnd;
141                                 break;
142                         case SPACE_INFO:
143                                 ts= &btheme->tinfo;
144                                 break;
145                         case SPACE_USERPREF:
146                                 ts= &btheme->tuserpref;
147                                 break;
148                         case SPACE_CONSOLE:
149                                 ts= &btheme->tconsole;
150                                 break;
151                         case SPACE_TIME:
152                                 ts= &btheme->ttime;
153                                 break;
154                         case SPACE_NODE:
155                                 ts= &btheme->tnode;
156                                 break;
157                         case SPACE_LOGIC:
158                                 ts= &btheme->tlogic;
159                                 break;
160                         default:
161                                 ts= &btheme->tv3d;
162                                 break;
163                         }
164                         
165                         switch(colorid) {
166                         case TH_BACK:
167                                 if(theme_regionid==RGN_TYPE_WINDOW)
168                                         cp= ts->back;
169                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
170                                         cp= ts->list;
171                                 else if(theme_regionid==RGN_TYPE_HEADER)
172                                         cp= ts->header;
173                                 else
174                                         cp= ts->button; 
175                                 break;
176                         case TH_TEXT:
177                                 if(theme_regionid==RGN_TYPE_WINDOW)
178                                         cp= ts->text; 
179                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
180                                         cp= ts->list_text;
181                                 else if(theme_regionid==RGN_TYPE_HEADER)
182                                         cp= ts->header_text;
183                                 else
184                                         cp= ts->button_text; 
185                                 break;
186                         case TH_TEXT_HI:
187                                 if(theme_regionid==RGN_TYPE_WINDOW)
188                                         cp= ts->text_hi;
189                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
190                                         cp= ts->list_text_hi;
191                                 else if(theme_regionid==RGN_TYPE_HEADER)
192                                         cp= ts->header_text_hi;
193                                 else
194                                         cp= ts->button_text_hi; 
195                                 break;
196                         case TH_TITLE:
197                                 if(theme_regionid==RGN_TYPE_WINDOW)
198                                         cp= ts->title;
199                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
200                                         cp= ts->list_title;
201                                 else if(theme_regionid==RGN_TYPE_HEADER)
202                                         cp= ts->header_title;
203                                 else
204                                         cp= ts->button_title; 
205                                 break;
206                                 
207                         case TH_HEADER:
208                                 cp= ts->header; break;
209                         case TH_HEADERDESEL:
210                                 /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
211                                 cp= ts->header; 
212                                 headerdesel[0]= cp[0]>10?cp[0]-10:0;
213                                 headerdesel[1]= cp[1]>10?cp[1]-10:0;
214                                 headerdesel[2]= cp[2]>10?cp[2]-10:0;
215                                 cp= headerdesel;
216                                 break;
217                         case TH_HEADER_TEXT:
218                                 cp= ts->header_text; break;
219                         case TH_HEADER_TEXT_HI:
220                                 cp= ts->header_text_hi; break;
221                                 
222                         case TH_PANEL:
223                                 cp= ts->panel; break;
224                         case TH_PANEL_TEXT:
225                                 cp= ts->panel_text; break;
226                         case TH_PANEL_TEXT_HI:
227                                 cp= ts->panel_text_hi; break;
228                                 
229                         case TH_BUTBACK:
230                                 cp= ts->button; break;
231                         case TH_BUTBACK_TEXT:
232                                 cp= ts->button_text; break;
233                         case TH_BUTBACK_TEXT_HI:
234                                 cp= ts->button_text_hi; break;
235                                 
236                         case TH_SHADE1:
237                                 cp= ts->shade1; break;
238                         case TH_SHADE2:
239                                 cp= ts->shade2; break;
240                         case TH_HILITE:
241                                 cp= ts->hilite; break;
242                                 
243                         case TH_GRID:
244                                 cp= ts->grid; break;
245                         case TH_WIRE:
246                                 cp= ts->wire; break;
247                         case TH_LAMP:
248                                 cp= ts->lamp; break;
249                         case TH_SELECT:
250                                 cp= ts->select; break;
251                         case TH_ACTIVE:
252                                 cp= ts->active; break;
253                         case TH_GROUP:
254                                 cp= ts->group; break;
255                         case TH_GROUP_ACTIVE:
256                                 cp= ts->group_active; break;
257                         case TH_TRANSFORM:
258                                 cp= ts->transform; break;
259                         case TH_VERTEX:
260                                 cp= ts->vertex; break;
261                         case TH_VERTEX_SELECT:
262                                 cp= ts->vertex_select; break;
263                         case TH_VERTEX_SIZE:
264                                 cp= &ts->vertex_size; break;
265                         case TH_EDGE:
266                                 cp= ts->edge; break;
267                         case TH_EDGE_SELECT:
268                                 cp= ts->edge_select; break;
269                         case TH_EDGE_SEAM:
270                                 cp= ts->edge_seam; break;
271                         case TH_EDGE_SHARP:
272                                 cp= ts->edge_sharp; break;
273                         case TH_EDGE_CREASE:
274                                 cp= ts->edge_crease; 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_DRAWEXTRA_EDGELEN:
288                                 cp= ts->extra_edge_len; break;
289                         case TH_DRAWEXTRA_FACEAREA:
290                                 cp= ts->extra_face_area; break;
291                         case TH_DRAWEXTRA_FACEANG:
292                                 cp= ts->extra_face_angle; break;
293                         case TH_NORMAL:
294                                 cp= ts->normal; break;
295                         case TH_VNORMAL:
296                                 cp= ts->vertex_normal; break;
297                         case TH_BONE_SOLID:
298                                 cp= ts->bone_solid; break;
299                         case TH_BONE_POSE:
300                                 cp= ts->bone_pose; break;
301                         case TH_STRIP:
302                                 cp= ts->strip; break;
303                         case TH_STRIP_SELECT:
304                                 cp= ts->strip_select; break;
305                         case TH_CFRAME:
306                                 cp= ts->cframe; break;
307                         case TH_NURB_ULINE:
308                                 cp= ts->nurb_uline; break;
309                         case TH_NURB_VLINE:
310                                 cp= ts->nurb_vline; break;
311                         case TH_NURB_SEL_ULINE:
312                                 cp= ts->nurb_sel_uline; break;
313                         case TH_NURB_SEL_VLINE:
314                                 cp= ts->nurb_sel_vline; break;
315                         case TH_ACTIVE_SPLINE:
316                                 cp= ts->act_spline; break;
317                         case TH_LASTSEL_POINT:
318                                 cp= ts->lastsel_point; break;
319                         case TH_HANDLE_FREE:
320                                 cp= ts->handle_free; break;
321                         case TH_HANDLE_AUTO:
322                                 cp= ts->handle_auto; break;
323                         case TH_HANDLE_VECT:
324                                 cp= ts->handle_vect; break;
325                         case TH_HANDLE_ALIGN:
326                                 cp= ts->handle_align; break;
327                         case TH_HANDLE_SEL_FREE:
328                                 cp= ts->handle_sel_free; break;
329                         case TH_HANDLE_SEL_AUTO:
330                                 cp= ts->handle_sel_auto; break;
331                         case TH_HANDLE_SEL_VECT:
332                                 cp= ts->handle_sel_vect; break;
333                         case TH_HANDLE_SEL_ALIGN:
334                                 cp= ts->handle_sel_align; break;
335
336                         case TH_SYNTAX_B:
337                                 cp= ts->syntaxb; break;
338                         case TH_SYNTAX_V:
339                                 cp= ts->syntaxv; break;
340                         case TH_SYNTAX_C:
341                                 cp= ts->syntaxc; break;
342                         case TH_SYNTAX_L:
343                                 cp= ts->syntaxl; break;
344                         case TH_SYNTAX_N:
345                                 cp= ts->syntaxn; break;
346
347                         case TH_NODE:
348                                 cp= ts->syntaxl; break;
349                         case TH_NODE_IN_OUT:
350                                 cp= ts->syntaxn; break;
351                         case TH_NODE_OPERATOR:
352                                 cp= ts->syntaxb; break;
353                         case TH_NODE_CONVERTOR:
354                                 cp= ts->syntaxv; break;
355                         case TH_NODE_GROUP:
356                                 cp= ts->syntaxc; break;
357                                 
358                         case TH_SEQ_MOVIE:
359                                 cp= ts->movie; break;
360                         case TH_SEQ_IMAGE:
361                                 cp= ts->image; break;
362                         case TH_SEQ_SCENE:
363                                 cp= ts->scene; break;
364                         case TH_SEQ_AUDIO:
365                                 cp= ts->audio; break;
366                         case TH_SEQ_EFFECT:
367                                 cp= ts->effect; break;
368                         case TH_SEQ_PLUGIN:
369                                 cp= ts->plugin; break;
370                         case TH_SEQ_TRANSITION:
371                                 cp= ts->transition; break;
372                         case TH_SEQ_META:
373                                 cp= ts->meta; break;
374                                 
375                         case TH_CONSOLE_OUTPUT:
376                                 cp= ts->console_output; break;
377                         case TH_CONSOLE_INPUT:
378                                 cp= ts-> console_input; break;
379                         case TH_CONSOLE_INFO:
380                                 cp= ts->console_info; break;
381                         case TH_CONSOLE_ERROR:
382                                 cp= ts->console_error; break;
383                         case TH_CONSOLE_CURSOR:
384                                 cp= ts->console_cursor; break;
385
386                         case TH_HANDLE_VERTEX:
387                                 cp= ts->handle_vertex;
388                                 break;
389                         case TH_HANDLE_VERTEX_SELECT:
390                                 cp= ts->handle_vertex_select;
391                                 break;
392                         case TH_HANDLE_VERTEX_SIZE:
393                                 cp= &ts->handle_vertex_size;
394                                 break;
395                                 
396                         case TH_DOPESHEET_CHANNELOB:
397                                 cp= ts->ds_channel;
398                                 break;
399                         case TH_DOPESHEET_CHANNELSUBOB:
400                                 cp= ts->ds_subchannel;
401                                 break;  
402                                         
403                         case TH_PREVIEW_BACK:
404                                 cp= ts->preview_back;
405                                 break;  
406                         }
407                 }
408         }
409         
410         return (unsigned char *)cp;
411 }
412
413 #define SETCOLTEST(col, r, g, b, a)  if(col[3]==0) {col[0]=r; col[1]=g; col[2]= b; col[3]= a;}
414
415 /* use this call to init new variables in themespace, if they're same for all */
416 static void ui_theme_init_new_do(ThemeSpace *ts)
417 {
418         SETCOLTEST(ts->header_text,             0, 0, 0, 255);
419         SETCOLTEST(ts->header_title,    0, 0, 0, 255);
420         SETCOLTEST(ts->header_text_hi,  255, 255, 255, 255);
421         
422         SETCOLTEST(ts->panel_text,              0, 0, 0, 255);
423         SETCOLTEST(ts->panel_title,             0, 0, 0, 255);
424         SETCOLTEST(ts->panel_text_hi,   255, 255, 255, 255);
425         
426         SETCOLTEST(ts->button,                  145, 145, 145, 245);
427         SETCOLTEST(ts->button_title,    0, 0, 0, 255);
428         SETCOLTEST(ts->button_text,             0, 0, 0, 255);
429         SETCOLTEST(ts->button_text_hi,  255, 255, 255, 255);
430         
431         SETCOLTEST(ts->list,                    165, 165, 165, 255);
432         SETCOLTEST(ts->list_title,              0, 0, 0, 255);
433         SETCOLTEST(ts->list_text,               0, 0, 0, 255);
434         SETCOLTEST(ts->list_text_hi,    255, 255, 255, 255);
435 }
436
437 static void ui_theme_init_new(bTheme *btheme)
438 {
439         ui_theme_init_new_do(&btheme->tbuts);
440         ui_theme_init_new_do(&btheme->tv3d);
441         ui_theme_init_new_do(&btheme->tfile);
442         ui_theme_init_new_do(&btheme->tipo);
443         ui_theme_init_new_do(&btheme->tinfo);
444         ui_theme_init_new_do(&btheme->tsnd);
445         ui_theme_init_new_do(&btheme->tact);
446         ui_theme_init_new_do(&btheme->tnla);
447         ui_theme_init_new_do(&btheme->tseq);
448         ui_theme_init_new_do(&btheme->tima);
449         ui_theme_init_new_do(&btheme->timasel);
450         ui_theme_init_new_do(&btheme->text);
451         ui_theme_init_new_do(&btheme->toops);
452         ui_theme_init_new_do(&btheme->ttime);
453         ui_theme_init_new_do(&btheme->tnode);
454         ui_theme_init_new_do(&btheme->tlogic);
455         ui_theme_init_new_do(&btheme->tuserpref);
456         ui_theme_init_new_do(&btheme->tconsole);
457         
458 }
459
460 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
461 #define SETCOLF(col, r, g, b, a)  col[0]=r*255; col[1]=g*255; col[2]= b*255; col[3]= a*255;
462
463 /* initialize default theme
464    Note: when you add new colors, created & saved themes need initialized
465    use function below, init_userdef_do_versions() 
466 */
467 void ui_theme_init_default(void)
468 {
469         bTheme *btheme;
470         
471         /* we search for the theme with name Default */
472         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
473                 if(strcmp("Default", btheme->name)==0) break;
474         }
475         
476         if(btheme==NULL) {
477                 btheme= MEM_callocN(sizeof(bTheme), "theme");
478                 BLI_addtail(&U.themes, btheme);
479                 strcpy(btheme->name, "Default");
480         }
481         
482         UI_SetTheme(0, 0);      // make sure the global used in this file is set
483
484         /* UI buttons */
485         ui_widget_color_init(&btheme->tui);
486
487         /* common (new) variables */
488         ui_theme_init_new(btheme);
489         
490         /* space view3d */
491         SETCOLF(btheme->tv3d.back,       0.225, 0.225, 0.225, 1.0);
492         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
493         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
494         
495         SETCOLF(btheme->tv3d.header,    0.45, 0.45, 0.45, 1.0);
496         SETCOLF(btheme->tv3d.button,    0.45, 0.45, 0.45, 1.0);
497         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
498         
499         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
500         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
501
502         SETCOLF(btheme->tv3d.grid,     0.251, 0.251, 0.251, 1.0);
503         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
504         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
505         SETCOL(btheme->tv3d.select, 241, 88, 0, 255);
506         SETCOL(btheme->tv3d.active, 255, 140, 25, 255);
507         SETCOL(btheme->tv3d.group,      8, 48, 8, 255);
508         SETCOL(btheme->tv3d.group_active, 85, 187, 85, 255);
509         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
510         SETCOL(btheme->tv3d.vertex, 0, 0, 0, 255);
511         SETCOL(btheme->tv3d.vertex_select, 255, 133, 0, 255);
512         btheme->tv3d.vertex_size= 3;
513         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
514         SETCOL(btheme->tv3d.edge_select, 255, 160, 0, 255);
515         SETCOL(btheme->tv3d.edge_seam, 219, 37, 18, 255);
516         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
517         SETCOL(btheme->tv3d.face,       0, 0, 0, 18);
518         SETCOL(btheme->tv3d.face_select, 255, 133, 0, 60);
519         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
520         SETCOL(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
521         SETCOL(btheme->tv3d.face_dot, 255, 133, 0, 255);
522         btheme->tv3d.facedot_size= 4;
523
524         SETCOL(btheme->tv3d.extra_edge_len, 32, 0, 0, 255);
525         SETCOL(btheme->tv3d.extra_face_area, 0, 32, 0, 255);
526         SETCOL(btheme->tv3d.extra_face_angle, 0, 0, 128, 255);
527
528         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0,  0x40, 255);
529
530         SETCOL(btheme->tv3d.nurb_uline, 0x90, 0x90, 0x00, 255);
531         SETCOL(btheme->tv3d.nurb_vline, 0x80, 0x30, 0x60, 255);
532         SETCOL(btheme->tv3d.nurb_sel_uline, 0xf0, 0xff, 0x40, 255);
533         SETCOL(btheme->tv3d.nurb_sel_vline, 0xf0, 0x90, 0xa0, 255);
534
535         SETCOL(btheme->tv3d.handle_free, 0, 0, 0, 255);
536         SETCOL(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
537         SETCOL(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
538         SETCOL(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
539         SETCOL(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
540         SETCOL(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
541         SETCOL(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
542         SETCOL(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
543
544         SETCOL(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
545         SETCOL(btheme->tv3d.lastsel_point,  0xff, 0xff, 0xff, 255);
546
547         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
548         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
549         
550         
551         /* space buttons */
552         /* to have something initialized */
553         btheme->tbuts= btheme->tv3d;
554
555         SETCOLF(btheme->tbuts.back,     0.45, 0.45, 0.45, 1.0);
556         SETCOL(btheme->tbuts.panel, 0x82, 0x82, 0x82, 255);
557
558         /* graph editor */
559         btheme->tipo= btheme->tv3d;
560         SETCOLF(btheme->tipo.back,      0.42, 0.42, 0.42, 1.0);
561         SETCOLF(btheme->tipo.list,      0.4, 0.4, 0.4, 1.0);
562         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
563         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
564         SETCOL(btheme->tipo.shade1,             150, 150, 150, 100);    /* scrollbars */
565         SETCOL(btheme->tipo.shade2,             0x70, 0x70, 0x70, 100);
566         SETCOL(btheme->tipo.vertex,             0, 0, 0, 255);
567         SETCOL(btheme->tipo.vertex_select, 255, 133, 0, 255);
568         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
569         btheme->tipo.vertex_size= 3;
570
571         SETCOL(btheme->tipo.handle_vertex,              0, 0, 0, 255);
572         SETCOL(btheme->tipo.handle_vertex_select, 255, 133, 0, 255);
573         btheme->tipo.handle_vertex_size= 3;
574         
575         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
576         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
577         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
578         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
579
580         /* dopesheet */
581         btheme->tact= btheme->tipo;
582         SETCOL(btheme->tact.strip,                      12, 10, 10, 128); 
583         SETCOL(btheme->tact.strip_select,       255, 140, 0, 255); 
584         
585         /* space nla */
586         btheme->tnla= btheme->tact;
587         
588         /* space file */
589         /* to have something initialized */
590         btheme->tfile= btheme->tv3d;
591         SETCOLF(btheme->tfile.back, 0.3, 0.3, 0.3, 1);
592         SETCOLF(btheme->tfile.panel, 0.3, 0.3, 0.3, 1);
593         SETCOLF(btheme->tfile.list, 0.4, 0.4, 0.4, 1);
594         SETCOL(btheme->tfile.text,      250, 250, 250, 255);
595         SETCOL(btheme->tfile.text_hi, 15, 15, 15, 255);
596         SETCOL(btheme->tfile.panel, 145, 145, 145, 255);        // bookmark/ui regions
597         SETCOL(btheme->tfile.active, 130, 130, 130, 255); // selected files
598         SETCOL(btheme->tfile.hilite, 255, 140, 25, 255); // selected files
599         
600         SETCOL(btheme->tfile.grid,      250, 250, 250, 255);
601         SETCOL(btheme->tfile.image,     250, 250, 250, 255);
602         SETCOL(btheme->tfile.movie,     250, 250, 250, 255);
603         SETCOL(btheme->tfile.scene,     250, 250, 250, 255);
604
605         
606         /* space seq */
607         btheme->tseq= btheme->tv3d;
608         SETCOL(btheme->tseq.back,       116, 116, 116, 255);
609         SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
610         SETCOL(btheme->tseq.image,      109, 88, 129, 255);
611         SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
612         SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
613         SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
614         SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
615         SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
616         SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
617         
618
619         /* space image */
620         btheme->tima= btheme->tv3d;
621         SETCOL(btheme->tima.back,       53, 53, 53, 255);
622         SETCOL(btheme->tima.vertex, 0, 0, 0, 255);
623         SETCOL(btheme->tima.vertex_select, 255, 133, 0, 255);
624         btheme->tima.vertex_size= 3;
625         btheme->tima.facedot_size= 3;
626         SETCOL(btheme->tima.face,   255, 255, 255, 10);
627         SETCOL(btheme->tima.face_select, 255, 133, 0, 60);
628         SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
629         SETCOLF(btheme->tima.preview_back,      0.45, 0.45, 0.45, 1.0);
630
631         /* space imageselect */
632         btheme->timasel= btheme->tv3d;
633         SETCOL(btheme->timasel.active,  195, 195, 195, 255); /* active tile */
634         SETCOL(btheme->timasel.grid,  94, 94, 94, 255); /* active file text */
635         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
636         SETCOL(btheme->timasel.shade1,  94, 94, 94, 255);       /* bar */
637         SETCOL(btheme->timasel.shade2,  172, 172, 172, 255); /* sliders */
638         SETCOL(btheme->timasel.hilite,  17, 27, 60, 100);       /* selected tile */
639         SETCOL(btheme->timasel.text,    0, 0, 0, 255);
640         SETCOL(btheme->timasel.text_hi, 255, 255, 255, 255);
641         SETCOL(btheme->timasel.panel,   132, 132, 132, 255);
642
643         /* space text */
644         btheme->text= btheme->tv3d;
645         SETCOL(btheme->text.back,       153, 153, 153, 255);
646         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
647         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
648         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
649         
650         /* syntax highlighting */
651         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
652         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
653         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
654         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
655         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
656         
657         /* space oops */
658         btheme->toops= btheme->tv3d;
659         SETCOLF(btheme->toops.back,     0.45, 0.45, 0.45, 1.0);
660         
661         /* space info */
662         btheme->tinfo= btheme->tv3d;
663         SETCOLF(btheme->tinfo.back,     0.45, 0.45, 0.45, 1.0);
664
665         /* space user preferences */
666         btheme->tuserpref= btheme->tv3d;
667         SETCOLF(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
668         
669         /* space console */
670         btheme->tconsole= btheme->tv3d;
671         SETCOL(btheme->tconsole.back, 0, 0, 0, 255);
672         SETCOL(btheme->tconsole.console_output, 96, 128, 255, 255);
673         SETCOL(btheme->tconsole.console_input, 255, 255, 255, 255);
674         SETCOL(btheme->tconsole.console_info, 0, 170, 0, 255);
675         SETCOL(btheme->tconsole.console_error, 220, 96, 96, 255);
676         SETCOL(btheme->tconsole.console_cursor, 220, 96, 96, 255);
677         
678
679         /* space sound */
680         btheme->tsnd= btheme->tv3d;
681         SETCOLF(btheme->tsnd.back,      0.45, 0.45, 0.45, 1.0);
682         SETCOLF(btheme->tsnd.grid,      0.36, 0.36, 0.36, 1.0);
683         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
684         
685         /* space time */
686         btheme->ttime= btheme->tsnd;    // same as sound space
687         
688         /* space node, re-uses syntax color storage */
689         btheme->tnode= btheme->tv3d;
690         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
691         SETCOL(btheme->tnode.syntaxl, 155, 155, 155, 160);      /* TH_NODE, backdrop */
692         SETCOL(btheme->tnode.syntaxn, 100, 100, 100, 255);      /* in/output */
693         SETCOL(btheme->tnode.syntaxb, 108, 105, 111, 255);      /* operator */
694         SETCOL(btheme->tnode.syntaxv, 104, 106, 117, 255);      /* generator */
695         SETCOL(btheme->tnode.syntaxc, 105, 117, 110, 255);      /* group */
696
697         /* space logic */
698         btheme->tlogic= btheme->tv3d;
699         SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
700         
701 }
702
703
704 void UI_SetTheme(int spacetype, int regionid)
705 {
706         if(spacetype==0) {      // called for safety, when delete themes
707                 theme_active= U.themes.first;
708                 theme_spacetype= SPACE_VIEW3D;
709                 theme_regionid= RGN_TYPE_WINDOW;
710         }
711         else {
712                 // later on, a local theme can be found too
713                 theme_active= U.themes.first;
714                 theme_spacetype= spacetype;
715                 theme_regionid= regionid;
716         }
717 }
718
719 // for space windows only
720 void UI_ThemeColor(int colorid)
721 {
722         const unsigned char *cp;
723         
724         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
725         glColor3ubv(cp);
726
727 }
728
729 // plus alpha
730 void UI_ThemeColor4(int colorid)
731 {
732         const unsigned char *cp;
733         
734         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
735         glColor4ubv(cp);
736
737 }
738
739 // set the color with offset for shades
740 void UI_ThemeColorShade(int colorid, int offset)
741 {
742         int r, g, b;
743         const unsigned char *cp;
744         
745         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
746         r= offset + (int) cp[0];
747         CLAMP(r, 0, 255);
748         g= offset + (int) cp[1];
749         CLAMP(g, 0, 255);
750         b= offset + (int) cp[2];
751         CLAMP(b, 0, 255);
752         //glColor3ub(r, g, b);
753         glColor4ub(r, g, b, cp[3]);
754 }
755 void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
756 {
757         int r, g, b, a;
758         const unsigned char *cp;
759         
760         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
761         r= coloffset + (int) cp[0];
762         CLAMP(r, 0, 255);
763         g= coloffset + (int) cp[1];
764         CLAMP(g, 0, 255);
765         b= coloffset + (int) cp[2];
766         CLAMP(b, 0, 255);
767         a= alphaoffset + (int) cp[3];
768         CLAMP(a, 0, 255);
769         glColor4ub(r, g, b, a);
770 }
771
772 // blend between to theme colors, and set it
773 void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
774 {
775         int r, g, b;
776         const unsigned char *cp1, *cp2;
777         
778         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
779         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
780
781         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
782         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
783         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
784         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
785         
786         glColor3ub(r, g, b);
787 }
788
789 // blend between to theme colors, shade it, and set it
790 void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
791 {
792         int r, g, b;
793         const unsigned char *cp1, *cp2;
794         
795         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
796         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
797
798         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
799         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
800         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
801         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
802         
803         CLAMP(r, 0, 255);
804         CLAMP(g, 0, 255);
805         CLAMP(b, 0, 255);
806         
807         glColor3ub(r, g, b);
808 }
809
810 // blend between to theme colors, shade it, and set it
811 void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
812 {
813         int r, g, b, a;
814         const unsigned char *cp1, *cp2;
815         
816         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
817         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
818
819         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
820         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
821         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
822         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
823         a= alphaoffset+floor((1.0-fac)*cp1[3] + fac*cp2[3]);
824         
825         CLAMP(r, 0, 255);
826         CLAMP(g, 0, 255);
827         CLAMP(b, 0, 255);
828         CLAMP(a, 0, 255);
829
830         glColor4ub(r, g, b, a);
831 }
832
833
834 // get individual values, not scaled
835 float UI_GetThemeValuef(int colorid)
836 {
837         const unsigned char *cp;
838         
839         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
840         return ((float)cp[0]);
841
842 }
843
844 // get individual values, not scaled
845 int UI_GetThemeValue(int colorid)
846 {
847         const unsigned char *cp;
848         
849         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
850         return ((int) cp[0]);
851
852 }
853
854
855 // get the color, range 0.0-1.0
856 void UI_GetThemeColor3fv(int colorid, float *col)
857 {
858         const unsigned char *cp;
859         
860         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
861         col[0]= ((float)cp[0])/255.0;
862         col[1]= ((float)cp[1])/255.0;
863         col[2]= ((float)cp[2])/255.0;
864 }
865
866 // get the color, range 0.0-1.0, complete with shading offset
867 void UI_GetThemeColorShade3fv(int colorid, int offset, float *col)
868 {
869         int r, g, b;
870         const unsigned char *cp;
871         
872         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
873         
874         r= offset + (int) cp[0];
875         CLAMP(r, 0, 255);
876         g= offset + (int) cp[1];
877         CLAMP(g, 0, 255);
878         b= offset + (int) cp[2];
879         CLAMP(b, 0, 255);
880         
881         col[0]= ((float)r)/255.0;
882         col[1]= ((float)g)/255.0;
883         col[2]= ((float)b)/255.0;
884 }
885
886 // get the color, in char pointer
887 void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
888 {
889         const unsigned char *cp;
890         
891         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
892         col[0]= cp[0];
893         col[1]= cp[1];
894         col[2]= cp[2];
895 }
896
897 // get the color, in char pointer
898 void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
899 {
900         const unsigned char *cp;
901         
902         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
903         col[0]= cp[0];
904         col[1]= cp[1];
905         col[2]= cp[2];
906         col[3]= cp[3];
907 }
908
909 void UI_GetThemeColorType4ubv(int colorid, int spacetype, char col[4])
910 {
911         const unsigned char *cp;
912         
913         cp= UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
914         col[0]= cp[0];
915         col[1]= cp[1];
916         col[2]= cp[2];
917         col[3]= cp[3];
918 }
919
920 // blends and shades between two char color pointers
921 void UI_ColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], float fac, int offset)
922 {
923         int r, g, b;
924         
925         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
926         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
927         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
928         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
929         
930         r= r<0?0:(r>255?255:r);
931         g= g<0?0:(g>255?255:g);
932         b= b<0?0:(b>255?255:b);
933         
934         glColor3ub(r, g, b);
935 }
936
937 // get a 3 byte color, blended and shaded between two other char color pointers
938 void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], unsigned char col[3], float fac, int offset)
939 {
940         int r, g, b;
941         
942         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
943         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
944         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
945         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
946         
947         r= r<0?0:(r>255?255:r);
948         g= g<0?0:(g>255?255:g);
949         b= b<0?0:(b>255?255:b);
950         
951         col[0] = r;
952         col[1] = g;
953         col[2] = b;
954 }
955
956 void UI_ThemeClearColor(int colorid)
957 {
958         float col[3];
959         
960         UI_GetThemeColor3fv(colorid, col);
961         glClearColor(col[0], col[1], col[2], 0.0);
962 }
963
964 void UI_make_axis_color(const unsigned char src_col[3], unsigned char dst_col[3], const char axis)
965 {
966         switch(axis)
967         {
968                 case 'X':
969                         dst_col[0]= src_col[0]>219?255:src_col[0]+36;
970                         dst_col[1]= src_col[1]<26?0:src_col[1]-26;
971                         dst_col[2]= src_col[2]<26?0:src_col[2]-26;
972                         break;
973                 case 'Y':
974                         dst_col[0]= src_col[0]<46?0:src_col[0]-36;
975                         dst_col[1]= src_col[1]>189?255:src_col[1]+66;
976                         dst_col[2]= src_col[2]<46?0:src_col[2]-36;
977                         break;
978                 case 'Z':
979                         dst_col[0]= src_col[0]<26?0:src_col[0]-26; 
980                         dst_col[1]= src_col[1]<26?0:src_col[1]-26; 
981                         dst_col[2]= src_col[2]>209?255:src_col[2]+46;
982                         break;
983                 default:
984                         BLI_assert(!"invalid axis arg");
985         }
986 }
987
988 /* ************************************************************* */
989
990 /* patching UserDef struct and Themes */
991 void init_userdef_do_versions(void)
992 {
993         Main *bmain= G.main;
994 //      countall();
995         
996         /* the UserDef struct is not corrected with do_versions() .... ugh! */
997         if(U.wheellinescroll == 0) U.wheellinescroll = 3;
998         if(U.menuthreshold1==0) {
999                 U.menuthreshold1= 5;
1000                 U.menuthreshold2= 2;
1001         }
1002         if(U.tb_leftmouse==0) {
1003                 U.tb_leftmouse= 5;
1004                 U.tb_rightmouse= 5;
1005         }
1006         if(U.mixbufsize==0) U.mixbufsize= 2048;
1007         if (BLI_streq(U.tempdir, "/")) {
1008                 char *tmp= getenv("TEMP");
1009                 
1010                 strcpy(U.tempdir, tmp?tmp:"/tmp/");
1011         }
1012         if (U.autokey_mode == 0) {
1013                 /* 'add/replace' but not on */
1014                 U.autokey_mode = 2;
1015         }
1016         if (U.savetime <= 0) {
1017                 U.savetime = 1;
1018 // XXX          error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n");
1019         }
1020         /* transform widget settings */
1021         if(U.tw_hotspot==0) {
1022                 U.tw_hotspot= 14;
1023                 U.tw_size= 20;                  // percentage of window size
1024                 U.tw_handlesize= 16;    // percentage of widget radius
1025         }
1026         if(U.pad_rot_angle==0)
1027                 U.pad_rot_angle= 15;
1028         
1029         if(U.flag & USER_CUSTOM_RANGE) 
1030                 vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
1031         
1032         if (bmain->versionfile <= 191) {
1033                 strcpy(U.plugtexdir, U.textudir);
1034                 strcpy(U.sounddir, "/");
1035         }
1036         
1037         /* patch to set Dupli Armature */
1038         if (bmain->versionfile < 220) {
1039                 U.dupflag |= USER_DUP_ARM;
1040         }
1041         
1042         /* added seam, normal color, undo */
1043         if (bmain->versionfile <= 234) {
1044                 bTheme *btheme;
1045                 
1046                 U.uiflag |= USER_GLOBALUNDO;
1047                 if (U.undosteps==0) U.undosteps=32;
1048                 
1049                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1050                         /* check for alpha==0 is safe, then color was never set */
1051                         if(btheme->tv3d.edge_seam[3]==0) {
1052                                 SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
1053                         }
1054                         if(btheme->tv3d.normal[3]==0) {
1055                                 SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
1056                         }
1057                         if(btheme->tv3d.vertex_normal[3]==0) {
1058                                 SETCOL(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
1059                         }
1060                         if(btheme->tv3d.face_dot[3]==0) {
1061                                 SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
1062                                 btheme->tv3d.facedot_size= 4;
1063                         }
1064                 }
1065         }
1066         if (bmain->versionfile <= 235) {
1067                 /* illegal combo... */
1068                 if (U.flag & USER_LMOUSESELECT) 
1069                         U.flag &= ~USER_TWOBUTTONMOUSE;
1070         }
1071         if (bmain->versionfile <= 236) {
1072                 bTheme *btheme;
1073                 /* new space type */
1074                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1075                         /* check for alpha==0 is safe, then color was never set */
1076                         if(btheme->ttime.back[3]==0) {
1077                                 btheme->ttime = btheme->tsnd;   // copy from sound
1078                         }
1079                         if(btheme->text.syntaxn[3]==0) {
1080                                 SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
1081                                 SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
1082                                 SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
1083                                 SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
1084                                 SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
1085                         }
1086                 }
1087         }
1088         if (bmain->versionfile <= 237) {
1089                 bTheme *btheme;
1090                 /* bone colors */
1091                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1092                         /* check for alpha==0 is safe, then color was never set */
1093                         if(btheme->tv3d.bone_solid[3]==0) {
1094                                 SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
1095                                 SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
1096                         }
1097                 }
1098         }
1099         if (bmain->versionfile <= 238) {
1100                 bTheme *btheme;
1101                 /* bone colors */
1102                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1103                         /* check for alpha==0 is safe, then color was never set */
1104                         if(btheme->tnla.strip[3]==0) {
1105                                 SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
1106                                 SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
1107                         }
1108                 }
1109         }
1110         if (bmain->versionfile <= 239) {
1111                 bTheme *btheme;
1112                 
1113                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1114                         /* Lamp theme, check for alpha==0 is safe, then color was never set */
1115                         if(btheme->tv3d.lamp[3]==0) {
1116                                 SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
1117 /* TEMPORAL, remove me! (ton) */                                
1118                                 U.uiflag |= USER_PLAINMENUS;
1119                         }
1120                         
1121                 }
1122                 if(U.obcenter_dia==0) U.obcenter_dia= 6;
1123         }
1124         if (bmain->versionfile <= 241) {
1125                 bTheme *btheme;
1126                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1127                         /* Node editor theme, check for alpha==0 is safe, then color was never set */
1128                         if(btheme->tnode.syntaxn[3]==0) {
1129                                 /* re-uses syntax color storage */
1130                                 btheme->tnode= btheme->tv3d;
1131                                 SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
1132                                 SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
1133                                 SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
1134                                 SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
1135                                 SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
1136                                 SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
1137                         }
1138                         /* Group theme colors */
1139                         if(btheme->tv3d.group[3]==0) {
1140                                 SETCOL(btheme->tv3d.group, 0x0C, 0x30, 0x0C, 255);
1141                                 SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
1142                         }
1143                         /* Sequence editor theme*/
1144                         if(btheme->tseq.movie[3]==0) {
1145                                 SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
1146                                 SETCOL(btheme->tseq.image,      109, 88, 129, 255);
1147                                 SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
1148                                 SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
1149                                 SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
1150                                 SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
1151                                 SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
1152                                 SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
1153                         }
1154                 }
1155                 
1156                 /* set defaults for 3D View rotating axis indicator */ 
1157                 /* since size can't be set to 0, this indicates it's not saved in startup.blend */
1158                 if (U.rvisize == 0) {
1159                         U.rvisize = 15;
1160                         U.rvibright = 8;
1161                         U.uiflag |= USER_SHOW_ROTVIEWICON;
1162                 }
1163                 
1164         }
1165         if (bmain->versionfile <= 242) {
1166                 bTheme *btheme;
1167                 
1168                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1169                         /* long keyframe color */
1170                         /* check for alpha==0 is safe, then color was never set */
1171                         if(btheme->tact.strip[3]==0) {
1172                                 SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
1173                                 SETCOL(btheme->tact.strip_select,       0xff, 0xff, 0xaa, 204);
1174                                 SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
1175                         }
1176                         
1177                         /* IPO-Editor - Vertex Size*/
1178                         if(btheme->tipo.vertex_size == 0) {
1179                                 btheme->tipo.vertex_size= 3;
1180                         }
1181                 }
1182         }
1183         if (bmain->versionfile <= 243) {
1184                 /* set default number of recently-used files (if not set) */
1185                 if (U.recent_files == 0) U.recent_files = 10;
1186         }
1187         if (bmain->versionfile < 245 || (bmain->versionfile == 245 && bmain->subversionfile < 3)) {
1188                 bTheme *btheme;
1189                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1190                         SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
1191                 }
1192                 if(U.coba_weight.tot==0)
1193                         init_colorband(&U.coba_weight, 1);
1194         }
1195         if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 11)) {
1196                 bTheme *btheme;
1197                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1198                         /* these should all use the same color */
1199                         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1200                         SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1201                         SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1202                         SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1203                         SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1204                         SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
1205                         SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1206                 }
1207         }
1208         if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 13)) {
1209                 bTheme *btheme;
1210                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1211                         /* action channel groups (recolor anyway) */
1212                         SETCOL(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
1213                         SETCOL(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
1214                         
1215                         /* bone custom-color sets */
1216                         // FIXME: this check for initialised colors is bad
1217                         if (btheme->tarm[0].solid[3] == 0) {
1218                                         /* set 1 */
1219                                 SETCOL(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
1220                                 SETCOL(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
1221                                 SETCOL(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
1222                                         /* set 2 */
1223                                 SETCOL(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
1224                                 SETCOL(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
1225                                 SETCOL(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
1226                                         /* set 3 */
1227                                 SETCOL(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
1228                                 SETCOL(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
1229                                 SETCOL(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
1230                                         /* set 4 */
1231                                 SETCOL(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
1232                                 SETCOL(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
1233                                 SETCOL(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
1234                                         /* set 5 */
1235                                 SETCOL(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
1236                                 SETCOL(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
1237                                 SETCOL(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
1238                                         /* set 6 */
1239                                 SETCOL(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
1240                                 SETCOL(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
1241                                 SETCOL(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
1242                                         /* set 7 */
1243                                 SETCOL(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
1244                                 SETCOL(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
1245                                 SETCOL(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
1246                                         /* set 8 */
1247                                 SETCOL(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
1248                                 SETCOL(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
1249                                 SETCOL(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
1250                                         /* set 9 */
1251                                 SETCOL(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
1252                                 SETCOL(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
1253                                 SETCOL(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
1254                                         /* set 10 */
1255                                 SETCOL(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
1256                                 SETCOL(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
1257                                 SETCOL(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
1258                                         /* set 11 */
1259                                 SETCOL(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
1260                                 SETCOL(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
1261                                 SETCOL(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
1262                                         /* set 12 */
1263                                 SETCOL(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
1264                                 SETCOL(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
1265                                 SETCOL(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
1266                                         /* set 13 */
1267                                 SETCOL(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
1268                                 SETCOL(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
1269                                 SETCOL(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
1270                                         /* set 14 */
1271                                 SETCOL(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
1272                                 SETCOL(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
1273                                 SETCOL(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
1274                                         /* set 15 */
1275                                 SETCOL(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
1276                                 SETCOL(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
1277                                 SETCOL(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
1278                         }
1279                 }
1280         }
1281         if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 16)) {
1282                 U.flag |= USER_ADD_VIEWALIGNED|USER_ADD_EDITMODE;
1283         }
1284         if ((bmain->versionfile < 247) || (bmain->versionfile == 247 && bmain->subversionfile <= 2)) {
1285                 bTheme *btheme;
1286                 
1287                 /* adjust themes */
1288                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1289                         char *col;
1290                         
1291                         /* IPO Editor: Handles/Vertices */
1292                         col = btheme->tipo.vertex;
1293                         SETCOL(btheme->tipo.handle_vertex, col[0], col[1], col[2], 255);
1294                         col = btheme->tipo.vertex_select;
1295                         SETCOL(btheme->tipo.handle_vertex_select, col[0], col[1], col[2], 255);
1296                         btheme->tipo.handle_vertex_size= btheme->tipo.vertex_size;
1297                         
1298                         /* Sequence/Image Editor: colors for GPencil text */
1299                         col = btheme->tv3d.bone_pose;
1300                         SETCOL(btheme->tseq.bone_pose, col[0], col[1], col[2], 255);
1301                         SETCOL(btheme->tima.bone_pose, col[0], col[1], col[2], 255);
1302                         col = btheme->tv3d.vertex_select;
1303                         SETCOL(btheme->tseq.vertex_select, col[0], col[1], col[2], 255);
1304                 }
1305         }
1306         if (bmain->versionfile < 250) {
1307                 bTheme *btheme;
1308                 
1309                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1310                         /* this was not properly initialized in 2.45 */
1311                         if(btheme->tima.face_dot[3]==0) {
1312                                 SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
1313                                 SETCOL(btheme->tima.face_dot, 255, 133, 0, 255);
1314                                 btheme->tima.facedot_size= 2;
1315                         }
1316                         
1317                         /* DopeSheet - (Object) Channel color */
1318                         SETCOL(btheme->tact.ds_channel,         82, 96, 110, 255);
1319                         SETCOL(btheme->tact.ds_subchannel,      124, 137, 150, 255);
1320                         /* DopeSheet - Group Channel color (saner version) */
1321                         SETCOL(btheme->tact.group, 79, 101, 73, 255);
1322                         SETCOL(btheme->tact.group_active, 135, 177, 125, 255);
1323                         
1324                         /* Graph Editor - (Object) Channel color */
1325                         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
1326                         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
1327                         /* Graph Editor - Group Channel color */
1328                         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
1329                         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
1330                         
1331                         /* Nla Editor - (Object) Channel color */
1332                         SETCOL(btheme->tnla.ds_channel,         82, 96, 110, 255);
1333                         SETCOL(btheme->tnla.ds_subchannel,      124, 137, 150, 255);
1334                         /* NLA Editor - New Strip colors */
1335                         SETCOL(btheme->tnla.strip,                      12, 10, 10, 128); 
1336                         SETCOL(btheme->tnla.strip_select,       255, 140, 0, 255);
1337                 }
1338                 
1339                 /* adjust grease-pencil distances */
1340                 U.gp_manhattendist= 1;
1341                 U.gp_euclideandist= 2;
1342                 
1343                 /* adjust default interpolation for new IPO-curves */
1344                 U.ipo_new= BEZT_IPO_BEZ;
1345         }
1346         
1347         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 1)) {
1348                 bTheme *btheme;
1349
1350                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1351                         
1352                         /* common (new) variables, it checks for alpha==0 */
1353                         ui_theme_init_new(btheme);
1354
1355                         if(btheme->tui.wcol_num.outline[3]==0)
1356                                 ui_widget_color_init(&btheme->tui);
1357                         
1358                         /* Logic editor theme, check for alpha==0 is safe, then color was never set */
1359                         if(btheme->tlogic.syntaxn[3]==0) {
1360                                 /* re-uses syntax color storage */
1361                                 btheme->tlogic= btheme->tv3d;
1362                                 SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
1363                         }
1364
1365                         SETCOLF(btheme->tinfo.back, 0.45, 0.45, 0.45, 1.0);
1366                         SETCOLF(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
1367                 }
1368         }
1369
1370         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 3)) {
1371                 /* new audio system */
1372                 if(U.audiochannels == 0)
1373                         U.audiochannels = 2;
1374                 if(U.audiodevice == 0) {
1375 #ifdef WITH_OPENAL
1376                         U.audiodevice = 2;
1377 #endif
1378 #ifdef WITH_SDL
1379                         U.audiodevice = 1;
1380 #endif
1381                 }
1382                 if(U.audioformat == 0)
1383                         U.audioformat = 0x24;
1384                 if(U.audiorate == 0)
1385                         U.audiorate = 44100;
1386         }
1387
1388         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 5))
1389                 U.gameflags |= USER_DISABLE_VBO;
1390         
1391         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 8)) {
1392                 wmKeyMap *km;
1393                 
1394                 for(km=U.keymaps.first; km; km=km->next) {
1395                         if (strcmp(km->idname, "Armature_Sketch")==0)
1396                                 strcpy(km->idname, "Armature Sketch");
1397                         else if (strcmp(km->idname, "View3D")==0)
1398                                 strcpy(km->idname, "3D View");
1399                         else if (strcmp(km->idname, "View3D Generic")==0)
1400                                 strcpy(km->idname, "3D View Generic");
1401                         else if (strcmp(km->idname, "EditMesh")==0)
1402                                 strcpy(km->idname, "Mesh");
1403                         else if (strcmp(km->idname, "TimeLine")==0)
1404                                 strcpy(km->idname, "Timeline");
1405                         else if (strcmp(km->idname, "UVEdit")==0)
1406                                 strcpy(km->idname, "UV Editor");
1407                         else if (strcmp(km->idname, "Animation_Channels")==0)
1408                                 strcpy(km->idname, "Animation Channels");
1409                         else if (strcmp(km->idname, "GraphEdit Keys")==0)
1410                                 strcpy(km->idname, "Graph Editor");
1411                         else if (strcmp(km->idname, "GraphEdit Generic")==0)
1412                                 strcpy(km->idname, "Graph Editor Generic");
1413                         else if (strcmp(km->idname, "Action_Keys")==0)
1414                                 strcpy(km->idname, "Dopesheet");
1415                         else if (strcmp(km->idname, "NLA Data")==0)
1416                                 strcpy(km->idname, "NLA Editor");
1417                         else if (strcmp(km->idname, "Node Generic")==0)
1418                                 strcpy(km->idname, "Node Editor");
1419                         else if (strcmp(km->idname, "Logic Generic")==0)
1420                                 strcpy(km->idname, "Logic Editor");
1421                         else if (strcmp(km->idname, "File")==0)
1422                                 strcpy(km->idname, "File Browser");
1423                         else if (strcmp(km->idname, "FileMain")==0)
1424                                 strcpy(km->idname, "File Browser Main");
1425                         else if (strcmp(km->idname, "FileButtons")==0)
1426                                 strcpy(km->idname, "File Browser Buttons");
1427                         else if (strcmp(km->idname, "Buttons Generic")==0)
1428                                 strcpy(km->idname, "Property Editor");
1429                 }
1430         }
1431         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 16)) {
1432                 if(U.wmdrawmethod == USER_DRAW_TRIPLE)
1433                         U.wmdrawmethod = USER_DRAW_AUTOMATIC;
1434         }
1435         
1436         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 3)) {
1437                 if (U.flag & USER_LMOUSESELECT) 
1438                         U.flag &= ~USER_TWOBUTTONMOUSE;
1439         }
1440         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 4)) {
1441                 bTheme *btheme;
1442                 
1443                 /* default new handle type is auto handles */
1444                 U.keyhandles_new = HD_AUTO;
1445                 
1446                 /* init new curve colors */
1447                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1448                         /* init colors used for handles in 3D-View  */
1449                         SETCOL(btheme->tv3d.handle_free, 0, 0, 0, 255);
1450                         SETCOL(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
1451                         SETCOL(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
1452                         SETCOL(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
1453                         SETCOL(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
1454                         SETCOL(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1455                         SETCOL(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1456                         SETCOL(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1457                         SETCOL(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
1458                         
1459                         /* same colors again for Graph Editor... */
1460                         SETCOL(btheme->tipo.handle_free, 0, 0, 0, 255);
1461                         SETCOL(btheme->tipo.handle_auto, 0x90, 0x90, 0x00, 255);
1462                         SETCOL(btheme->tipo.handle_vect, 0x40, 0x90, 0x30, 255);
1463                         SETCOL(btheme->tipo.handle_align, 0x80, 0x30, 0x60, 255);
1464                         SETCOL(btheme->tipo.handle_sel_free, 0, 0, 0, 255);
1465                         SETCOL(btheme->tipo.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1466                         SETCOL(btheme->tipo.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1467                         SETCOL(btheme->tipo.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1468                         
1469                         /* edge crease */
1470                         SETCOLF(btheme->tv3d.edge_crease, 0.8, 0, 0.6, 1.0);
1471                 }
1472         }
1473         if (bmain->versionfile <= 252) {
1474                 bTheme *btheme;
1475
1476                 /* init new curve colors */
1477                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1478                         if (btheme->tv3d.lastsel_point[3] == 0)
1479                                 SETCOL(btheme->tv3d.lastsel_point, 0xff, 0xff, 0xff, 255);
1480                 }
1481         }
1482         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 5)) {
1483                 bTheme *btheme;
1484                 
1485                 /* interface_widgets.c */
1486                 struct uiWidgetColors wcol_progress= {
1487                         {0, 0, 0, 255},
1488                         {190, 190, 190, 255},
1489                         {100, 100, 100, 180},
1490                         {68, 68, 68, 255},
1491                         
1492                         {0, 0, 0, 255},
1493                         {255, 255, 255, 255},
1494                         
1495                         0,
1496                         5, -5
1497                 };
1498                 
1499                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1500                         /* init progress bar theme */
1501                         btheme->tui.wcol_progress= wcol_progress;
1502                 }
1503         }
1504
1505         if (bmain->versionfile < 255 || (bmain->versionfile == 255 && bmain->subversionfile < 2)) {
1506                 bTheme *btheme;
1507                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1508                         SETCOL(btheme->tv3d.extra_edge_len, 32, 0, 0, 255);
1509                         SETCOL(btheme->tv3d.extra_face_angle, 0, 32, 0, 255);
1510                         SETCOL(btheme->tv3d.extra_face_area, 0, 0, 128, 255);
1511                 }
1512         }
1513         
1514         if (bmain->versionfile < 257) {
1515                 /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs, so that it doesn't linger around from old configs like a ghost */
1516                 U.autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET;
1517         }
1518         
1519         /* GL Texture Garbage Collection (variable abused above!) */
1520         if (U.textimeout == 0) {
1521                 U.texcollectrate = 60;
1522                 U.textimeout = 120;
1523         }
1524         if (U.memcachelimit <= 0) {
1525                 U.memcachelimit = 32;
1526         }
1527         if (U.frameserverport == 0) {
1528                 U.frameserverport = 8080;
1529         }
1530         if (U.dbl_click_time == 0) {
1531                 U.dbl_click_time = 350;
1532         }
1533         if (U.anim_player_preset == 0) {
1534                 U.anim_player_preset = 1 ;
1535         }
1536         if (U.scrcastfps == 0) {
1537                 U.scrcastfps = 10;
1538                 U.scrcastwait = 50;
1539         }
1540         if (U.v2d_min_gridsize == 0) {
1541                 U.v2d_min_gridsize= 35;
1542         }
1543         if (U.dragthreshold == 0 )
1544                 U.dragthreshold= 5;
1545
1546         /* funny name, but it is GE stuff, moves userdef stuff to engine */
1547 // XXX  space_set_commmandline_options();
1548         /* this timer uses U */
1549 // XXX  reset_autosave();
1550
1551 }