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