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