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