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