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