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