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