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