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