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