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