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