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