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