User Prefs: add new flag for app-template options
[blender-staging.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_screen_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_userdef_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_appdir.h"
49 #include "BKE_colorband.h"
50 #include "BKE_DerivedMesh.h"
51 #include "BKE_global.h"
52 #include "BKE_main.h"
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 /* be sure to keep 'bThemeState' in sync */
65 static struct bThemeState g_theme_state = {
66     NULL,
67     SPACE_VIEW3D,
68     RGN_TYPE_WINDOW,
69 };
70
71 #define theme_active g_theme_state.theme
72 #define theme_spacetype g_theme_state.spacetype
73 #define theme_regionid g_theme_state.regionid
74
75 void ui_resources_init(void)
76 {
77         UI_icons_init(BIFICONID_LAST);
78 }
79
80 void ui_resources_free(void)
81 {
82         UI_icons_free();
83 }
84
85
86 /* ******************************************************** */
87 /*    THEMES */
88 /* ******************************************************** */
89
90 const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
91 {
92         ThemeSpace *ts = NULL;
93         static char error[4] = {240, 0, 240, 255};
94         static char alert[4] = {240, 60, 60, 255};
95         static char headerdesel[4] = {0, 0, 0, 255};
96         static char setting = 0;
97         const char *cp = error;
98         
99         /* ensure we're not getting a color after running BKE_blender_userdef_free */
100         BLI_assert(BLI_findindex(&U.themes, theme_active) != -1);
101         BLI_assert(colorid != TH_UNDEFINED);
102
103         if (btheme) {
104         
105                 /* first check for ui buttons theme */
106                 if (colorid < TH_THEMEUI) {
107                 
108                         switch (colorid) {
109
110                                 case TH_REDALERT:
111                                         cp = alert; break;
112                         }
113                 }
114                 else {
115                 
116                         switch (spacetype) {
117                                 case SPACE_BUTS:
118                                         ts = &btheme->tbuts;
119                                         break;
120                                 case SPACE_VIEW3D:
121                                         ts = &btheme->tv3d;
122                                         break;
123                                 case SPACE_IPO:
124                                         ts = &btheme->tipo;
125                                         break;
126                                 case SPACE_FILE:
127                                         ts = &btheme->tfile;
128                                         break;
129                                 case SPACE_NLA:
130                                         ts = &btheme->tnla;
131                                         break;
132                                 case SPACE_ACTION:
133                                         ts = &btheme->tact;
134                                         break;
135                                 case SPACE_SEQ:
136                                         ts = &btheme->tseq;
137                                         break;
138                                 case SPACE_IMAGE:
139                                         ts = &btheme->tima;
140                                         break;
141                                 case SPACE_TEXT:
142                                         ts = &btheme->text;
143                                         break;
144                                 case SPACE_OUTLINER:
145                                         ts = &btheme->toops;
146                                         break;
147                                 case SPACE_INFO:
148                                         ts = &btheme->tinfo;
149                                         break;
150                                 case SPACE_USERPREF:
151                                         ts = &btheme->tuserpref;
152                                         break;
153                                 case SPACE_CONSOLE:
154                                         ts = &btheme->tconsole;
155                                         break;
156                                 case SPACE_TIME:
157                                         ts = &btheme->ttime;
158                                         break;
159                                 case SPACE_NODE:
160                                         ts = &btheme->tnode;
161                                         break;
162                                 case SPACE_LOGIC:
163                                         ts = &btheme->tlogic;
164                                         break;
165                                 case SPACE_CLIP:
166                                         ts = &btheme->tclip;
167                                         break;
168                                 default:
169                                         ts = &btheme->tv3d;
170                                         break;
171                         }
172
173                         switch (colorid) {
174                                 case TH_BACK:
175                                         if (theme_regionid == RGN_TYPE_WINDOW)
176                                                 cp = ts->back;
177                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
178                                                 cp = ts->list;
179                                         else if (theme_regionid == RGN_TYPE_HEADER)
180                                                 cp = ts->header;
181                                         else
182                                                 cp = ts->button;
183                                         break;
184                                 case TH_LOW_GRAD:
185                                         cp = ts->gradients.gradient;
186                                         break;
187                                 case TH_HIGH_GRAD:
188                                         cp = ts->gradients.high_gradient;
189                                         break;
190                                 case TH_SHOW_BACK_GRAD:
191                                         cp = &setting;
192                                         setting = ts->gradients.show_grad;
193                                         break;
194                                 case TH_TEXT:
195                                         if (theme_regionid == RGN_TYPE_WINDOW)
196                                                 cp = ts->text;
197                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
198                                                 cp = ts->list_text;
199                                         else if (theme_regionid == RGN_TYPE_HEADER)
200                                                 cp = ts->header_text;
201                                         else
202                                                 cp = ts->button_text;
203                                         break;
204                                 case TH_TEXT_HI:
205                                         if (theme_regionid == RGN_TYPE_WINDOW)
206                                                 cp = ts->text_hi;
207                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
208                                                 cp = ts->list_text_hi;
209                                         else if (theme_regionid == RGN_TYPE_HEADER)
210                                                 cp = ts->header_text_hi;
211                                         else
212                                                 cp = ts->button_text_hi;
213                                         break;
214                                 case TH_TITLE:
215                                         if (theme_regionid == RGN_TYPE_WINDOW)
216                                                 cp = ts->title;
217                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
218                                                 cp = ts->list_title;
219                                         else if (theme_regionid == RGN_TYPE_HEADER)
220                                                 cp = ts->header_title;
221                                         else
222                                                 cp = ts->button_title;
223                                         break;
224
225                                 case TH_HEADER:
226                                         cp = ts->header; break;
227                                 case TH_HEADERDESEL:
228                                         /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
229                                         cp = ts->header;
230                                         headerdesel[0] = cp[0] > 10 ? cp[0] - 10 : 0;
231                                         headerdesel[1] = cp[1] > 10 ? cp[1] - 10 : 0;
232                                         headerdesel[2] = cp[2] > 10 ? cp[2] - 10 : 0;
233                                         cp = headerdesel;
234                                         break;
235                                 case TH_HEADER_TEXT:
236                                         cp = ts->header_text; break;
237                                 case TH_HEADER_TEXT_HI:
238                                         cp = ts->header_text_hi; break;
239
240                                 case TH_PANEL_HEADER:
241                                         cp = ts->panelcolors.header; break;
242                                 case TH_PANEL_BACK:
243                                         cp = ts->panelcolors.back; break;
244                                 case TH_PANEL_SHOW_HEADER:
245                                         cp = &setting;
246                                         setting = ts->panelcolors.show_header;
247                                         break;
248                                 case TH_PANEL_SHOW_BACK:
249                                         cp = &setting;
250                                         setting = ts->panelcolors.show_back;
251                                         break;
252                                         
253                                 case TH_BUTBACK:
254                                         cp = ts->button; break;
255                                 case TH_BUTBACK_TEXT:
256                                         cp = ts->button_text; break;
257                                 case TH_BUTBACK_TEXT_HI:
258                                         cp = ts->button_text_hi; break;
259
260                                 case TH_TAB_ACTIVE:
261                                         cp = ts->tab_active; break;
262                                 case TH_TAB_INACTIVE:
263                                         cp = ts->tab_inactive; break;
264                                 case TH_TAB_BACK:
265                                         cp = ts->tab_back; break;
266                                 case TH_TAB_OUTLINE:
267                                         cp = ts->tab_outline; break;
268
269                                 case TH_SHADE1:
270                                         cp = ts->shade1; break;
271                                 case TH_SHADE2:
272                                         cp = ts->shade2; break;
273                                 case TH_HILITE:
274                                         cp = ts->hilite; break;
275                                 
276                                 case TH_GRID:
277                                         cp = ts->grid; break;
278                                 case TH_VIEW_OVERLAY:
279                                         cp = ts->view_overlay; break;
280                                 case TH_WIRE:
281                                         cp = ts->wire; break;
282                                 case TH_WIRE_INNER:
283                                         cp = ts->syntaxr; break;
284                                 case TH_WIRE_EDIT:
285                                         cp = ts->wire_edit; break;
286                                 case TH_LAMP:
287                                         cp = ts->lamp; break;
288                                 case TH_SPEAKER:
289                                         cp = ts->speaker; break;
290                                 case TH_CAMERA:
291                                         cp = ts->camera; break;
292                                 case TH_EMPTY:
293                                         cp = ts->empty; break;
294                                 case TH_SELECT:
295                                         cp = ts->select; break;
296                                 case TH_ACTIVE:
297                                         cp = ts->active; break;
298                                 case TH_GROUP:
299                                         cp = ts->group; break;
300                                 case TH_GROUP_ACTIVE:
301                                         cp = ts->group_active; break;
302                                 case TH_TRANSFORM:
303                                         cp = ts->transform; break;
304                                 case TH_VERTEX:
305                                         cp = ts->vertex; break;
306                                 case TH_VERTEX_SELECT:
307                                         cp = ts->vertex_select; break;
308                                 case TH_VERTEX_BEVEL:
309                                         cp = ts->vertex_bevel; break;
310                                 case TH_VERTEX_UNREFERENCED:
311                                         cp = ts->vertex_unreferenced; break;
312                                 case TH_VERTEX_SIZE:
313                                         cp = &ts->vertex_size; break;
314                                 case TH_OUTLINE_WIDTH:
315                                         cp = &ts->outline_width; break;
316                                 case TH_EDGE:
317                                         cp = ts->edge; break;
318                                 case TH_EDGE_SELECT:
319                                         cp = ts->edge_select; break;
320                                 case TH_EDGE_SEAM:
321                                         cp = ts->edge_seam; break;
322                                 case TH_EDGE_SHARP:
323                                         cp = ts->edge_sharp; break;
324                                 case TH_EDGE_CREASE:
325                                         cp = ts->edge_crease; break;
326                                 case TH_EDGE_BEVEL:
327                                         cp = ts->edge_bevel; break;
328                                 case TH_EDITMESH_ACTIVE:
329                                         cp = ts->editmesh_active; break;
330                                 case TH_EDGE_FACESEL:
331                                         cp = ts->edge_facesel; break;
332                                 case TH_FACE:
333                                         cp = ts->face; break;
334                                 case TH_FACE_SELECT:
335                                         cp = ts->face_select; break;
336                                 case TH_FACE_DOT:
337                                         cp = ts->face_dot; break;
338                                 case TH_FACEDOT_SIZE:
339                                         cp = &ts->facedot_size; break;
340                                 case TH_DRAWEXTRA_EDGELEN:
341                                         cp = ts->extra_edge_len; break;
342                                 case TH_DRAWEXTRA_EDGEANG:
343                                         cp = ts->extra_edge_angle; break;
344                                 case TH_DRAWEXTRA_FACEAREA:
345                                         cp = ts->extra_face_area; break;
346                                 case TH_DRAWEXTRA_FACEANG:
347                                         cp = ts->extra_face_angle; break;
348                                 case TH_NORMAL:
349                                         cp = ts->normal; break;
350                                 case TH_VNORMAL:
351                                         cp = ts->vertex_normal; break;
352                                 case TH_LNORMAL:
353                                         cp = ts->loop_normal; break;
354                                 case TH_BONE_SOLID:
355                                         cp = ts->bone_solid; break;
356                                 case TH_BONE_POSE:
357                                         cp = ts->bone_pose; break;
358                                 case TH_BONE_POSE_ACTIVE:
359                                         cp = ts->bone_pose_active; break;
360                                 case TH_STRIP:
361                                         cp = ts->strip; break;
362                                 case TH_STRIP_SELECT:
363                                         cp = ts->strip_select; break;
364                                 case TH_KEYTYPE_KEYFRAME:
365                                         cp = ts->keytype_keyframe; break;
366                                 case TH_KEYTYPE_KEYFRAME_SELECT:
367                                         cp = ts->keytype_keyframe_select; break;
368                                 case TH_KEYTYPE_EXTREME:
369                                         cp = ts->keytype_extreme; break;
370                                 case TH_KEYTYPE_EXTREME_SELECT:
371                                         cp = ts->keytype_extreme_select; break;
372                                 case TH_KEYTYPE_BREAKDOWN:
373                                         cp = ts->keytype_breakdown; break;
374                                 case TH_KEYTYPE_BREAKDOWN_SELECT:
375                                         cp = ts->keytype_breakdown_select; break;
376                                 case TH_KEYTYPE_JITTER:
377                                         cp = ts->keytype_jitter; break;
378                                 case TH_KEYTYPE_JITTER_SELECT:
379                                         cp = ts->keytype_jitter_select; break;
380                                 case TH_KEYBORDER:
381                                         cp = ts->keyborder; break;
382                                 case TH_KEYBORDER_SELECT:
383                                         cp = ts->keyborder_select; break;
384                                 case TH_CFRAME:
385                                         cp = ts->cframe; break;
386                                 case TH_TIME_KEYFRAME:
387                                         cp = ts->time_keyframe; break;
388                                 case TH_TIME_GP_KEYFRAME:
389                                         cp = ts->time_gp_keyframe; break;
390                                 case TH_NURB_ULINE:
391                                         cp = ts->nurb_uline; break;
392                                 case TH_NURB_VLINE:
393                                         cp = ts->nurb_vline; break;
394                                 case TH_NURB_SEL_ULINE:
395                                         cp = ts->nurb_sel_uline; break;
396                                 case TH_NURB_SEL_VLINE:
397                                         cp = ts->nurb_sel_vline; break;
398                                 case TH_ACTIVE_SPLINE:
399                                         cp = ts->act_spline; break;
400                                 case TH_ACTIVE_VERT:
401                                         cp = ts->lastsel_point; break;
402                                 case TH_HANDLE_FREE:
403                                         cp = ts->handle_free; break;
404                                 case TH_HANDLE_AUTO:
405                                         cp = ts->handle_auto; break;
406                                 case TH_HANDLE_AUTOCLAMP:
407                                         cp = ts->handle_auto_clamped; break;
408                                 case TH_HANDLE_VECT:
409                                         cp = ts->handle_vect; break;
410                                 case TH_HANDLE_ALIGN:
411                                         cp = ts->handle_align; break;
412                                 case TH_HANDLE_SEL_FREE:
413                                         cp = ts->handle_sel_free; break;
414                                 case TH_HANDLE_SEL_AUTO:
415                                         cp = ts->handle_sel_auto; break;
416                                 case TH_HANDLE_SEL_AUTOCLAMP:
417                                         cp = ts->handle_sel_auto_clamped; break;
418                                 case TH_HANDLE_SEL_VECT:
419                                         cp = ts->handle_sel_vect; break;
420                                 case TH_HANDLE_SEL_ALIGN:
421                                         cp = ts->handle_sel_align; break;
422                                 case TH_FREESTYLE_EDGE_MARK:
423                                         cp = ts->freestyle_edge_mark; break;
424                                 case TH_FREESTYLE_FACE_MARK:
425                                         cp = ts->freestyle_face_mark; break;
426
427                                 case TH_SYNTAX_B:
428                                         cp = ts->syntaxb; break;
429                                 case TH_SYNTAX_V:
430                                         cp = ts->syntaxv; break;
431                                 case TH_SYNTAX_C:
432                                         cp = ts->syntaxc; break;
433                                 case TH_SYNTAX_L:
434                                         cp = ts->syntaxl; break;
435                                 case TH_SYNTAX_D:
436                                         cp = ts->syntaxd; break;
437                                 case TH_SYNTAX_R:
438                                         cp = ts->syntaxr; break;
439                                 case TH_SYNTAX_N:
440                                         cp = ts->syntaxn; break;
441                                 case TH_SYNTAX_S:
442                                         cp = ts->syntaxs; break;
443
444                                 case TH_NODE:
445                                         cp = ts->syntaxl; break;
446                                 case TH_NODE_INPUT:
447                                         cp = ts->syntaxn; break;
448                                 case TH_NODE_OUTPUT:
449                                         cp = ts->nodeclass_output; break;
450                                 case TH_NODE_COLOR:
451                                         cp = ts->syntaxb; break;
452                                 case TH_NODE_FILTER:
453                                         cp = ts->nodeclass_filter; break;
454                                 case TH_NODE_VECTOR:
455                                         cp = ts->nodeclass_vector; break;
456                                 case TH_NODE_TEXTURE:
457                                         cp = ts->nodeclass_texture; break;
458                                 case TH_NODE_PATTERN:
459                                         cp = ts->nodeclass_pattern; break;
460                                 case TH_NODE_SCRIPT:
461                                         cp = ts->nodeclass_script; break;
462                                 case TH_NODE_LAYOUT:
463                                         cp = ts->nodeclass_layout; break;
464                                 case TH_NODE_SHADER:
465                                         cp = ts->nodeclass_shader; break;
466                                 case TH_NODE_CONVERTOR:
467                                         cp = ts->syntaxv; break;
468                                 case TH_NODE_GROUP:
469                                         cp = ts->syntaxc; break;
470                                 case TH_NODE_INTERFACE:
471                                         cp = ts->console_output; break;
472                                 case TH_NODE_FRAME:
473                                         cp = ts->movie; break;
474                                 case TH_NODE_MATTE:
475                                         cp = ts->syntaxs; break;
476                                 case TH_NODE_DISTORT:
477                                         cp = ts->syntaxd; break;
478                                 case TH_NODE_CURVING:
479                                         cp = &ts->noodle_curving; break;
480
481                                 case TH_SEQ_MOVIE:
482                                         cp = ts->movie; break;
483                                 case TH_SEQ_MOVIECLIP:
484                                         cp = ts->movieclip; break;
485                                 case TH_SEQ_MASK:
486                                         cp = ts->mask; break;
487                                 case TH_SEQ_IMAGE:
488                                         cp = ts->image; break;
489                                 case TH_SEQ_SCENE:
490                                         cp = ts->scene; break;
491                                 case TH_SEQ_AUDIO:
492                                         cp = ts->audio; break;
493                                 case TH_SEQ_EFFECT:
494                                         cp = ts->effect; break;
495                                 case TH_SEQ_TRANSITION:
496                                         cp = ts->transition; break;
497                                 case TH_SEQ_META:
498                                         cp = ts->meta; break;
499                                 case TH_SEQ_TEXT:
500                                         cp = ts->text_strip; break;
501                                 case TH_SEQ_PREVIEW:
502                                         cp = ts->preview_back; break;
503
504                                 case TH_CONSOLE_OUTPUT:
505                                         cp = ts->console_output; break;
506                                 case TH_CONSOLE_INPUT:
507                                         cp = ts->console_input; break;
508                                 case TH_CONSOLE_INFO:
509                                         cp = ts->console_info; break;
510                                 case TH_CONSOLE_ERROR:
511                                         cp = ts->console_error; break;
512                                 case TH_CONSOLE_CURSOR:
513                                         cp = ts->console_cursor; break;
514                                 case TH_CONSOLE_SELECT:
515                                         cp = ts->console_select; break;
516
517                                 case TH_HANDLE_VERTEX:
518                                         cp = ts->handle_vertex;
519                                         break;
520                                 case TH_HANDLE_VERTEX_SELECT:
521                                         cp = ts->handle_vertex_select;
522                                         break;
523                                 case TH_HANDLE_VERTEX_SIZE:
524                                         cp = &ts->handle_vertex_size;
525                                         break;
526                                         
527                                 case TH_GP_VERTEX:
528                                         cp = ts->gp_vertex;
529                                         break;
530                                 case TH_GP_VERTEX_SELECT:
531                                         cp = ts->gp_vertex_select;
532                                         break;
533                                 case TH_GP_VERTEX_SIZE:
534                                         cp = &ts->gp_vertex_size;
535                                         break;
536                                         
537                                 case TH_DOPESHEET_CHANNELOB:
538                                         cp = ts->ds_channel;
539                                         break;
540                                 case TH_DOPESHEET_CHANNELSUBOB:
541                                         cp = ts->ds_subchannel;
542                                         break;
543
544                                 case TH_PREVIEW_BACK:
545                                         cp = ts->preview_back;
546                                         break;
547
548                                 case TH_STITCH_PREVIEW_FACE:
549                                         cp = ts->preview_stitch_face;
550                                         break;
551
552                                 case TH_STITCH_PREVIEW_EDGE:
553                                         cp = ts->preview_stitch_edge;
554                                         break;
555
556                                 case TH_STITCH_PREVIEW_VERT:
557                                         cp = ts->preview_stitch_vert;
558                                         break;
559
560                                 case TH_STITCH_PREVIEW_STITCHABLE:
561                                         cp = ts->preview_stitch_stitchable;
562                                         break;
563
564                                 case TH_STITCH_PREVIEW_UNSTITCHABLE:
565                                         cp = ts->preview_stitch_unstitchable;
566                                         break;
567                                 case TH_STITCH_PREVIEW_ACTIVE:
568                                         cp = ts->preview_stitch_active;
569                                         break;
570
571                                 case TH_PAINT_CURVE_HANDLE:
572                                         cp = ts->paint_curve_handle;
573                                         break;
574                                 case TH_PAINT_CURVE_PIVOT:
575                                         cp = ts->paint_curve_pivot;
576                                         break;
577
578                                 case TH_METADATA_BG:
579                                         cp = ts->metadatabg;
580                                         break;
581                                 case TH_METADATA_TEXT:
582                                         cp = ts->metadatatext;
583                                         break;
584
585                                 case TH_UV_OTHERS:
586                                         cp = ts->uv_others;
587                                         break;
588                                 case TH_UV_SHADOW:
589                                         cp = ts->uv_shadow;
590                                         break;
591
592                                 case TH_MARKER_OUTLINE:
593                                         cp = ts->marker_outline; break;
594                                 case TH_MARKER:
595                                         cp = ts->marker; break;
596                                 case TH_ACT_MARKER:
597                                         cp = ts->act_marker; break;
598                                 case TH_SEL_MARKER:
599                                         cp = ts->sel_marker; break;
600                                 case TH_BUNDLE_SOLID:
601                                         cp = ts->bundle_solid; break;
602                                 case TH_DIS_MARKER:
603                                         cp = ts->dis_marker; break;
604                                 case TH_PATH_BEFORE:
605                                         cp = ts->path_before; break;
606                                 case TH_PATH_AFTER:
607                                         cp = ts->path_after; break;
608                                 case TH_CAMERA_PATH:
609                                         cp = ts->camera_path; break;
610                                 case TH_LOCK_MARKER:
611                                         cp = ts->lock_marker; break;
612
613                                 case TH_MATCH:
614                                         cp = ts->match;
615                                         break;
616
617                                 case TH_SELECT_HIGHLIGHT:
618                                         cp = ts->selected_highlight;
619                                         break;
620
621                                 case TH_SKIN_ROOT:
622                                         cp = ts->skin_root;
623                                         break;
624                                         
625                                 case TH_ANIM_ACTIVE:
626                                         cp = ts->anim_active;
627                                         break;
628                                 case TH_ANIM_INACTIVE:
629                                         cp = ts->anim_non_active;
630                                         break;
631                                 
632                                 case TH_NLA_TWEAK:
633                                         cp = ts->nla_tweaking;
634                                         break;
635                                 case TH_NLA_TWEAK_DUPLI:
636                                         cp = ts->nla_tweakdupli;
637                                         break;
638                                 
639                                 case TH_NLA_TRANSITION:
640                                         cp = ts->nla_transition;
641                                         break;
642                                 case TH_NLA_TRANSITION_SEL:
643                                         cp = ts->nla_transition_sel;
644                                         break;
645                                 case TH_NLA_META:
646                                         cp = ts->nla_meta;
647                                         break;
648                                 case TH_NLA_META_SEL:
649                                         cp = ts->nla_meta_sel;
650                                         break;
651                                 case TH_NLA_SOUND:
652                                         cp = ts->nla_sound;
653                                         break;
654                                 case TH_NLA_SOUND_SEL:
655                                         cp = ts->nla_sound_sel;
656                                         break;
657                                         
658                                 case TH_WIDGET_EMBOSS:
659                                         cp = btheme->tui.widget_emboss; break;
660
661                                 case TH_AXIS_X:
662                                         cp = btheme->tui.xaxis; break;
663                                 case TH_AXIS_Y:
664                                         cp = btheme->tui.yaxis; break;
665                                 case TH_AXIS_Z:
666                                         cp = btheme->tui.zaxis; break;
667
668                                 case TH_INFO_SELECTED:
669                                         cp = ts->info_selected;
670                                         break;
671                                 case TH_INFO_SELECTED_TEXT:
672                                         cp = ts->info_selected_text;
673                                         break;
674                                 case TH_INFO_ERROR:
675                                         cp = ts->info_error;
676                                         break;
677                                 case TH_INFO_ERROR_TEXT:
678                                         cp = ts->info_error_text;
679                                         break;
680                                 case TH_INFO_WARNING:
681                                         cp = ts->info_warning;
682                                         break;
683                                 case TH_INFO_WARNING_TEXT:
684                                         cp = ts->info_warning_text;
685                                         break;
686                                 case TH_INFO_INFO:
687                                         cp = ts->info_info;
688                                         break;
689                                 case TH_INFO_INFO_TEXT:
690                                         cp = ts->info_info_text;
691                                         break;
692                                 case TH_INFO_DEBUG:
693                                         cp = ts->info_debug;
694                                         break;
695                                 case TH_INFO_DEBUG_TEXT:
696                                         cp = ts->info_debug_text;
697                                         break;
698                                 case TH_V3D_CLIPPING_BORDER:
699                                         cp = ts->clipping_border_3d;
700                                         break;
701                         }
702                 }
703         }
704         
705         return (const unsigned char *)cp;
706 }
707
708 /* use this call to init new bone color sets in Theme */
709 static void ui_theme_init_boneColorSets(bTheme *btheme)
710 {
711         int i;
712         
713         /* define default color sets - currently we only define 15 of these, though that should be ample */
714         /* set 1 */
715         rgba_char_args_set(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
716         rgba_char_args_set(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
717         rgba_char_args_set(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
718         /* set 2 */
719         rgba_char_args_set(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
720         rgba_char_args_set(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
721         rgba_char_args_set(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
722         /* set 3 */
723         rgba_char_args_set(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
724         rgba_char_args_set(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
725         rgba_char_args_set(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
726         /* set 4 */
727         rgba_char_args_set(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
728         rgba_char_args_set(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
729         rgba_char_args_set(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
730         /* set 5 */
731         rgba_char_args_set(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
732         rgba_char_args_set(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
733         rgba_char_args_set(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
734         /* set 6 */
735         rgba_char_args_set(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
736         rgba_char_args_set(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
737         rgba_char_args_set(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
738         /* set 7 */
739         rgba_char_args_set(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
740         rgba_char_args_set(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
741         rgba_char_args_set(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
742         /* set 8 */
743         rgba_char_args_set(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
744         rgba_char_args_set(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
745         rgba_char_args_set(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
746         /* set 9 */
747         rgba_char_args_set(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
748         rgba_char_args_set(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
749         rgba_char_args_set(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
750         /* set 10 */
751         rgba_char_args_set(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
752         rgba_char_args_set(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
753         rgba_char_args_set(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
754         /* set 11 */
755         rgba_char_args_set(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
756         rgba_char_args_set(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
757         rgba_char_args_set(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
758         /* set 12 */
759         rgba_char_args_set(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
760         rgba_char_args_set(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
761         rgba_char_args_set(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
762         /* set 13 */
763         rgba_char_args_set(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
764         rgba_char_args_set(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
765         rgba_char_args_set(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
766         /* set 14 */
767         rgba_char_args_set(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
768         rgba_char_args_set(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
769         rgba_char_args_set(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
770         /* set 15 */
771         rgba_char_args_set(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
772         rgba_char_args_set(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
773         rgba_char_args_set(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
774         
775         /* reset flags too */
776         for (i = 0; i < 20; i++)
777                 btheme->tarm[i].flag = 0;
778 }
779
780 /* use this call to init new variables in themespace, if they're same for all */
781 static void ui_theme_init_new_do(ThemeSpace *ts)
782 {
783         rgba_char_args_set(ts->header_text,    0, 0, 0, 255);
784         rgba_char_args_set(ts->header_title,   0, 0, 0, 255);
785         rgba_char_args_set(ts->header_text_hi, 255, 255, 255, 255);
786
787 #if 0
788         rgba_char_args_set(ts->panel_text,     0, 0, 0, 255);
789         rgba_char_args_set(ts->panel_title,        0, 0, 0, 255);
790         rgba_char_args_set(ts->panel_text_hi,  255, 255, 255, 255);
791 #endif
792
793         ts->panelcolors.show_back = false;
794         ts->panelcolors.show_header = false;
795         rgba_char_args_set(ts->panelcolors.back,   114, 114, 114, 128);
796         rgba_char_args_set(ts->panelcolors.header, 0, 0, 0, 25);
797
798         rgba_char_args_set(ts->button,         145, 145, 145, 245);
799         rgba_char_args_set(ts->button_title,   0, 0, 0, 255);
800         rgba_char_args_set(ts->button_text,    0, 0, 0, 255);
801         rgba_char_args_set(ts->button_text_hi, 255, 255, 255, 255);
802
803         rgba_char_args_set(ts->list,           165, 165, 165, 255);
804         rgba_char_args_set(ts->list_title,     0, 0, 0, 255);
805         rgba_char_args_set(ts->list_text,      0, 0, 0, 255);
806         rgba_char_args_set(ts->list_text_hi,   255, 255, 255, 255);
807
808         rgba_char_args_set(ts->tab_active,     114, 114, 114, 255);
809         rgba_char_args_set(ts->tab_inactive,   83, 83, 83, 255);
810         rgba_char_args_set(ts->tab_back,       64, 64, 64, 255);
811         rgba_char_args_set(ts->tab_outline,    60, 60, 60, 255);
812 }
813
814 static void ui_theme_init_new(bTheme *btheme)
815 {
816         ThemeSpace *ts;
817
818         for (ts = UI_THEMESPACE_START(btheme); ts != UI_THEMESPACE_END(btheme); ts++) {
819                 ui_theme_init_new_do(ts);
820         }
821 }
822
823 static void ui_theme_space_init_handles_color(ThemeSpace *theme_space)
824 {
825         rgba_char_args_set(theme_space->handle_free, 0, 0, 0, 255);
826         rgba_char_args_set(theme_space->handle_auto, 0x90, 0x90, 0x00, 255);
827         rgba_char_args_set(theme_space->handle_vect, 0x40, 0x90, 0x30, 255);
828         rgba_char_args_set(theme_space->handle_align, 0x80, 0x30, 0x60, 255);
829         rgba_char_args_set(theme_space->handle_sel_free, 0, 0, 0, 255);
830         rgba_char_args_set(theme_space->handle_sel_auto, 0xf0, 0xff, 0x40, 255);
831         rgba_char_args_set(theme_space->handle_sel_vect, 0x40, 0xc0, 0x30, 255);
832         rgba_char_args_set(theme_space->handle_sel_align, 0xf0, 0x90, 0xa0, 255);
833         rgba_char_args_set(theme_space->handle_vertex, 0x00, 0x00, 0x00, 0xff);
834         rgba_char_args_set(theme_space->handle_vertex_select, 0xff, 0xff, 0, 0xff);
835         rgba_char_args_set(theme_space->act_spline, 0xdb, 0x25, 0x12, 255);
836 }
837
838 /**
839  * initialize default theme
840  * \note: when you add new colors, created & saved themes need initialized
841  * use function below, init_userdef_do_versions()
842  */
843 void ui_theme_init_default(void)
844 {
845         bTheme *btheme;
846         
847         /* we search for the theme with name Default */
848         btheme = BLI_findstring(&U.themes, "Default", offsetof(bTheme, name));
849         
850         if (btheme == NULL) {
851                 btheme = MEM_callocN(sizeof(bTheme), "theme");
852                 BLI_addtail(&U.themes, btheme);
853                 strcpy(btheme->name, "Default");
854         }
855         
856         UI_SetTheme(0, 0);  /* make sure the global used in this file is set */
857
858         /* UI buttons */
859         ui_widget_color_init(&btheme->tui);
860
861         btheme->tui.iconfile[0] = 0;
862         rgba_char_args_set(btheme->tui.wcol_tooltip.text, 255, 255, 255, 255);
863         rgba_char_args_set_fl(btheme->tui.widget_emboss, 1.0f, 1.0f, 1.0f, 0.02f);
864
865         rgba_char_args_set(btheme->tui.xaxis, 220,   0,   0, 255);
866         rgba_char_args_set(btheme->tui.yaxis,   0, 220,   0, 255);
867         rgba_char_args_set(btheme->tui.zaxis,   0,   0, 220, 255);
868
869         btheme->tui.menu_shadow_fac = 0.5f;
870         btheme->tui.menu_shadow_width = 12;
871         
872         /* Bone Color Sets */
873         ui_theme_init_boneColorSets(btheme);
874         
875         /* common (new) variables */
876         ui_theme_init_new(btheme);
877         
878         /* space view3d */
879         rgba_char_args_set_fl(btheme->tv3d.back,       0.225, 0.225, 0.225, 1.0);
880         rgba_char_args_set(btheme->tv3d.text,       0, 0, 0, 255);
881         rgba_char_args_set(btheme->tv3d.text_hi, 255, 255, 255, 255);
882         
883         rgba_char_args_set_fl(btheme->tv3d.header,  0.45, 0.45, 0.45, 1.0);
884         rgba_char_args_set_fl(btheme->tv3d.button,  0.45, 0.45, 0.45, 0.5);
885 //      rgba_char_args_set(btheme->tv3d.panel,      165, 165, 165, 127);
886         
887         rgba_char_args_set(btheme->tv3d.shade1,  160, 160, 160, 100);
888         rgba_char_args_set(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
889
890         rgba_char_args_set_fl(btheme->tv3d.grid,     0.251, 0.251, 0.251, 1.0);
891         rgba_char_args_set(btheme->tv3d.view_overlay, 0, 0, 0, 255);
892         rgba_char_args_set(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
893         rgba_char_args_set(btheme->tv3d.wire_edit,  0x0, 0x0, 0x0, 255);
894         rgba_char_args_set(btheme->tv3d.lamp,       0, 0, 0, 40);
895         rgba_char_args_set(btheme->tv3d.speaker,    0, 0, 0, 255);
896         rgba_char_args_set(btheme->tv3d.camera,    0, 0, 0, 255);
897         rgba_char_args_set(btheme->tv3d.empty,    0, 0, 0, 255);
898         rgba_char_args_set(btheme->tv3d.select, 241, 88, 0, 255);
899         rgba_char_args_set(btheme->tv3d.active, 255, 170, 64, 255);
900         rgba_char_args_set(btheme->tv3d.group,      8, 48, 8, 255);
901         rgba_char_args_set(btheme->tv3d.group_active, 85, 187, 85, 255);
902         rgba_char_args_set(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
903         rgba_char_args_set(btheme->tv3d.vertex, 0, 0, 0, 255);
904         rgba_char_args_set(btheme->tv3d.vertex_select, 255, 133, 0, 255);
905         rgba_char_args_set(btheme->tv3d.vertex_bevel, 0, 165, 255, 255);
906         rgba_char_args_set(btheme->tv3d.vertex_unreferenced, 0, 0, 0, 255);
907         btheme->tv3d.vertex_size = 3;
908         btheme->tv3d.outline_width = 1;
909         rgba_char_args_set(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
910         rgba_char_args_set(btheme->tv3d.edge_select, 255, 160, 0, 255);
911         rgba_char_args_set(btheme->tv3d.edge_seam, 219, 37, 18, 255);
912         rgba_char_args_set(btheme->tv3d.edge_bevel, 0, 165, 255, 255);
913         rgba_char_args_set(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
914         rgba_char_args_set(btheme->tv3d.face,       0, 0, 0, 18);
915         rgba_char_args_set(btheme->tv3d.face_select, 255, 133, 0, 60);
916         rgba_char_args_set(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
917         rgba_char_args_set(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
918         rgba_char_args_set(btheme->tv3d.loop_normal, 0xDD, 0x23, 0xDD, 255);
919         rgba_char_args_set(btheme->tv3d.face_dot, 255, 133, 0, 255);
920         rgba_char_args_set(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
921         rgba_char_args_set_fl(btheme->tv3d.edge_crease, 0.8, 0, 0.6, 1.0);
922         rgba_char_args_set(btheme->tv3d.edge_sharp, 0, 255, 255, 255);
923         rgba_char_args_set(btheme->tv3d.header_text, 0, 0, 0, 255);
924         rgba_char_args_set(btheme->tv3d.header_text_hi, 255, 255, 255, 255);
925         rgba_char_args_set(btheme->tv3d.button_text, 0, 0, 0, 255);
926         rgba_char_args_set(btheme->tv3d.button_text_hi, 255, 255, 255, 255);
927         rgba_char_args_set(btheme->tv3d.button_title, 0, 0, 0, 255);
928         rgba_char_args_set(btheme->tv3d.title, 0, 0, 0, 255);
929         rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
930         rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
931         rgba_char_args_set_fl(btheme->tv3d.paint_curve_handle, 0.5f, 1.0f, 0.5f, 0.5f);
932         rgba_char_args_set_fl(btheme->tv3d.paint_curve_pivot, 1.0f, 0.5f, 0.5f, 0.5f);
933         rgba_char_args_set(btheme->tv3d.gp_vertex, 0, 0, 0, 255);
934         rgba_char_args_set(btheme->tv3d.gp_vertex_select, 255, 133, 0, 255);
935         btheme->tv3d.gp_vertex_size = 3;
936
937         btheme->tv3d.facedot_size = 4;
938
939         rgba_char_args_set(btheme->tv3d.extra_edge_len, 32, 0, 0, 255);
940         rgba_char_args_set(btheme->tv3d.extra_edge_angle, 32, 32, 0, 255);
941         rgba_char_args_set(btheme->tv3d.extra_face_area, 0, 32, 0, 255);
942         rgba_char_args_set(btheme->tv3d.extra_face_angle, 0, 0, 128, 255);
943
944         rgba_char_args_set(btheme->tv3d.cframe, 0x60, 0xc0,  0x40, 255);
945
946         rgba_char_args_set(btheme->tv3d.nurb_uline, 0x90, 0x90, 0x00, 255);
947         rgba_char_args_set(btheme->tv3d.nurb_vline, 0x80, 0x30, 0x60, 255);
948         rgba_char_args_set(btheme->tv3d.nurb_sel_uline, 0xf0, 0xff, 0x40, 255);
949         rgba_char_args_set(btheme->tv3d.nurb_sel_vline, 0xf0, 0x90, 0xa0, 255);
950
951         ui_theme_space_init_handles_color(&btheme->tv3d);
952
953         rgba_char_args_set(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
954         rgba_char_args_set(btheme->tv3d.lastsel_point,  0xff, 0xff, 0xff, 255);
955
956         rgba_char_args_set(btheme->tv3d.bone_solid, 200, 200, 200, 255);
957         /* alpha 80 is not meant editable, used for wire+action draw */
958         rgba_char_args_set(btheme->tv3d.bone_pose, 80, 200, 255, 80);
959         rgba_char_args_set(btheme->tv3d.bone_pose_active, 140, 255, 255, 80);
960
961         rgba_char_args_set(btheme->tv3d.bundle_solid, 200, 200, 200, 255);
962         rgba_char_args_set(btheme->tv3d.camera_path, 0x00, 0x00, 0x00, 255);
963
964         rgba_char_args_set(btheme->tv3d.skin_root, 180, 77, 77, 255);
965         rgba_char_args_set(btheme->tv3d.gradients.gradient, 0, 0, 0, 0);
966         rgba_char_args_set(btheme->tv3d.gradients.high_gradient, 58, 58, 58, 255);
967         btheme->tv3d.gradients.show_grad = false;
968
969         rgba_char_args_set(btheme->tv3d.clipping_border_3d, 50, 50, 50, 255);
970
971         rgba_char_args_set(btheme->tv3d.time_keyframe, 0xDD, 0xD7, 0x00, 0xFF);
972         rgba_char_args_set(btheme->tv3d.time_gp_keyframe, 0xB5, 0xE6, 0x1D, 0xFF);
973
974         /* space buttons */
975         /* to have something initialized */
976         btheme->tbuts = btheme->tv3d;
977
978         rgba_char_args_set_fl(btheme->tbuts.back,   0.45, 0.45, 0.45, 1.0);
979 //      rgba_char_args_set(btheme->tbuts.panel, 0x82, 0x82, 0x82, 255);
980
981         /* graph editor */
982         btheme->tipo = btheme->tv3d;
983         rgba_char_args_set_fl(btheme->tipo.back,    0.42, 0.42, 0.42, 1.0);
984         rgba_char_args_set_fl(btheme->tipo.list,    0.4, 0.4, 0.4, 1.0);
985         rgba_char_args_set(btheme->tipo.grid,   94, 94, 94, 255);
986 //      rgba_char_args_set(btheme->tipo.panel,  255, 255, 255, 150);
987         rgba_char_args_set(btheme->tipo.shade1,     150, 150, 150, 100);    /* scrollbars */
988         rgba_char_args_set(btheme->tipo.shade2,     0x70, 0x70, 0x70, 100);
989         rgba_char_args_set(btheme->tipo.vertex,     0, 0, 0, 255);
990         rgba_char_args_set(btheme->tipo.vertex_select, 255, 133, 0, 255);
991         rgba_char_args_set(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255);
992         btheme->tipo.vertex_size = 6;
993
994         rgba_char_args_set(btheme->tipo.handle_vertex,      0, 0, 0, 255);
995         rgba_char_args_set(btheme->tipo.handle_vertex_select, 255, 133, 0, 255);
996         rgba_char_args_set(btheme->tipo.handle_auto_clamped, 0x99, 0x40, 0x30, 255);
997         rgba_char_args_set(btheme->tipo.handle_sel_auto_clamped, 0xf0, 0xaf, 0x90, 255);
998         btheme->tipo.handle_vertex_size = 5;
999         
1000         rgba_char_args_set(btheme->tipo.ds_channel,      82, 96, 110, 255);
1001         rgba_char_args_set(btheme->tipo.ds_subchannel,  124, 137, 150, 255);
1002         rgba_char_args_set(btheme->tipo.group,           79, 101, 73, 255);
1003         rgba_char_args_set(btheme->tipo.group_active,   135, 177, 125, 255);
1004
1005         /* dopesheet */
1006         btheme->tact = btheme->tipo;
1007         rgba_char_args_set(btheme->tact.strip,          12, 10, 10, 128);
1008         rgba_char_args_set(btheme->tact.strip_select,   255, 140, 0, 255);
1009         
1010         rgba_char_args_set(btheme->tact.anim_active,    204, 112, 26, 102);
1011         
1012         rgba_char_args_set(btheme->tact.keytype_keyframe,           232, 232, 232, 255);
1013         rgba_char_args_set(btheme->tact.keytype_keyframe_select,    255, 190,  50, 255);
1014         rgba_char_args_set(btheme->tact.keytype_extreme,            232, 179, 204, 255);
1015         rgba_char_args_set(btheme->tact.keytype_extreme_select,     242, 128, 128, 255);
1016         rgba_char_args_set(btheme->tact.keytype_breakdown,          179, 219, 232, 255);
1017         rgba_char_args_set(btheme->tact.keytype_breakdown_select,    84, 191, 237, 255);
1018         rgba_char_args_set(btheme->tact.keytype_jitter,             148, 229, 117, 255);
1019         rgba_char_args_set(btheme->tact.keytype_jitter_select,       97, 192,  66, 255);
1020         
1021         rgba_char_args_set(btheme->tact.keyborder,               0,   0,   0, 255);
1022         rgba_char_args_set(btheme->tact.keyborder_select,        0,   0,   0, 255);
1023         
1024         btheme->tact.keyframe_scale_fac = 1.0f;
1025         
1026         /* space nla */
1027         btheme->tnla = btheme->tact;
1028         
1029         rgba_char_args_set(btheme->tnla.anim_active,     204, 112, 26, 102); /* same as for dopesheet; duplicate here for easier reference */
1030         rgba_char_args_set(btheme->tnla.anim_non_active, 153, 135, 97, 77);
1031         
1032         rgba_char_args_set(btheme->tnla.nla_tweaking,   77, 243, 26, 77);
1033         rgba_char_args_set(btheme->tnla.nla_tweakdupli, 217, 0, 0, 255);
1034         
1035         rgba_char_args_set(btheme->tnla.nla_transition,     28, 38, 48, 255);
1036         rgba_char_args_set(btheme->tnla.nla_transition_sel, 46, 117, 219, 255);
1037         rgba_char_args_set(btheme->tnla.nla_meta,           51, 38, 66, 255);
1038         rgba_char_args_set(btheme->tnla.nla_meta_sel,       105, 33, 150, 255);
1039         rgba_char_args_set(btheme->tnla.nla_sound,          43, 61, 61, 255);
1040         rgba_char_args_set(btheme->tnla.nla_sound_sel,      31, 122, 122, 255);
1041         
1042         rgba_char_args_set(btheme->tnla.keyborder,               0,   0,   0, 255);
1043         rgba_char_args_set(btheme->tnla.keyborder_select,        0,   0,   0, 255);
1044         
1045         /* space file */
1046         /* to have something initialized */
1047         btheme->tfile = btheme->tv3d;
1048         rgba_char_args_set_fl(btheme->tfile.back, 0.3, 0.3, 0.3, 1);
1049 //      rgba_char_args_set_fl(btheme->tfile.panel, 0.3, 0.3, 0.3, 1);
1050         rgba_char_args_set_fl(btheme->tfile.list, 0.4, 0.4, 0.4, 1);
1051         rgba_char_args_set(btheme->tfile.text,  250, 250, 250, 255);
1052         rgba_char_args_set(btheme->tfile.text_hi, 15, 15, 15, 255);
1053 //      rgba_char_args_set(btheme->tfile.panel, 145, 145, 145, 255);  /* bookmark/ui regions */
1054         rgba_char_args_set(btheme->tfile.hilite, 255, 140, 25, 255);  /* selected files */
1055
1056         rgba_char_args_set(btheme->tfile.image, 250, 250, 250, 255);
1057         rgba_char_args_set(btheme->tfile.movie, 250, 250, 250, 255);
1058         rgba_char_args_set(btheme->tfile.scene, 250, 250, 250, 255);
1059
1060         
1061         /* space seq */
1062         btheme->tseq = btheme->tv3d;
1063         rgba_char_args_set(btheme->tseq.back,   116, 116, 116, 255);
1064         rgba_char_args_set(btheme->tseq.movie,  81, 105, 135, 255);
1065         rgba_char_args_set(btheme->tseq.movieclip,  32, 32, 143, 255);
1066         rgba_char_args_set(btheme->tseq.mask,   152, 78, 62, 255);
1067         rgba_char_args_set(btheme->tseq.image,  109, 88, 129, 255);
1068         rgba_char_args_set(btheme->tseq.scene,  78, 152, 62, 255);
1069         rgba_char_args_set(btheme->tseq.audio,  46, 143, 143, 255);
1070         rgba_char_args_set(btheme->tseq.effect,     169, 84, 124, 255);
1071         rgba_char_args_set(btheme->tseq.transition, 162, 95, 111, 255);
1072         rgba_char_args_set(btheme->tseq.meta,   109, 145, 131, 255);
1073         rgba_char_args_set(btheme->tseq.text_strip,   162, 151, 0, 255);
1074         rgba_char_args_set(btheme->tseq.preview_back,   0, 0, 0, 255);
1075         rgba_char_args_set(btheme->tseq.grid,   64, 64, 64, 255);
1076
1077         /* space image */
1078         btheme->tima = btheme->tv3d;
1079         rgba_char_args_set(btheme->tima.back,   53, 53, 53, 255);
1080         rgba_char_args_set(btheme->tima.vertex, 0, 0, 0, 255);
1081         rgba_char_args_set(btheme->tima.vertex_select, 255, 133, 0, 255);
1082         rgba_char_args_set(btheme->tima.wire_edit, 192, 192, 192, 255);
1083         rgba_char_args_set(btheme->tima.edge_select, 255, 133, 0, 255);
1084         btheme->tima.vertex_size = 3;
1085         btheme->tima.facedot_size = 3;
1086         rgba_char_args_set(btheme->tima.face,   255, 255, 255, 10);
1087         rgba_char_args_set(btheme->tima.face_select, 255, 133, 0, 60);
1088         rgba_char_args_set(btheme->tima.editmesh_active, 255, 255, 255, 128);
1089         rgba_char_args_set_fl(btheme->tima.preview_back,        0.0, 0.0, 0.0, 0.3);
1090         rgba_char_args_set_fl(btheme->tima.preview_stitch_face, 0.5, 0.5, 0.0, 0.2);
1091         rgba_char_args_set_fl(btheme->tima.preview_stitch_edge, 1.0, 0.0, 1.0, 0.2);
1092         rgba_char_args_set_fl(btheme->tima.preview_stitch_vert, 0.0, 0.0, 1.0, 0.2);
1093         rgba_char_args_set_fl(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
1094         rgba_char_args_set_fl(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
1095         rgba_char_args_set_fl(btheme->tima.preview_stitch_active, 0.886, 0.824, 0.765, 0.140);
1096
1097         rgba_char_args_test_set(btheme->tima.uv_others, 96, 96, 96, 255);
1098         rgba_char_args_test_set(btheme->tima.uv_shadow, 112, 112, 112, 255);
1099
1100         ui_theme_space_init_handles_color(&btheme->tima);
1101         btheme->tima.handle_vertex_size = 5;
1102
1103         /* space text */
1104         btheme->text = btheme->tv3d;
1105         rgba_char_args_set(btheme->text.back,   153, 153, 153, 255);
1106         rgba_char_args_set(btheme->text.shade1,     143, 143, 143, 255);
1107         rgba_char_args_set(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
1108         rgba_char_args_set(btheme->text.hilite,     255, 0, 0, 255);
1109         
1110         /* syntax highlighting */
1111         rgba_char_args_set(btheme->text.syntaxn,    0, 0, 200, 255);    /* Numbers  Blue*/
1112         rgba_char_args_set(btheme->text.syntaxl,    100, 0, 0, 255);    /* Strings  Red */
1113         rgba_char_args_set(btheme->text.syntaxc,    0, 100, 50, 255);   /* Comments  Greenish */
1114         rgba_char_args_set(btheme->text.syntaxv,    95, 95, 0, 255);    /* Special  Yellow*/
1115         rgba_char_args_set(btheme->text.syntaxd,    50, 0, 140, 255);   /* Decorator/Preprocessor Dir.  Blue-purple */
1116         rgba_char_args_set(btheme->text.syntaxr,    140, 60, 0, 255);   /* Reserved  Orange*/
1117         rgba_char_args_set(btheme->text.syntaxb,    128, 0, 80, 255);   /* Builtin  Red-purple */
1118         rgba_char_args_set(btheme->text.syntaxs,    76, 76, 76, 255);   /* Gray (mix between fg/bg) */
1119         
1120         /* space oops */
1121         btheme->toops = btheme->tv3d;
1122         rgba_char_args_set_fl(btheme->toops.back,   0.45, 0.45, 0.45, 1.0);
1123         
1124         rgba_char_args_set_fl(btheme->toops.match,  0.2, 0.5, 0.2, 0.3);    /* highlighting search match - soft green*/
1125         rgba_char_args_set_fl(btheme->toops.selected_highlight, 0.51, 0.53, 0.55, 0.3);
1126
1127         /* space info */
1128         btheme->tinfo = btheme->tv3d;
1129         rgba_char_args_set_fl(btheme->tinfo.back,   0.45, 0.45, 0.45, 1.0);
1130         rgba_char_args_set(btheme->tinfo.info_selected, 96, 128, 255, 255);
1131         rgba_char_args_set(btheme->tinfo.info_selected_text, 255, 255, 255, 255);
1132         rgba_char_args_set(btheme->tinfo.info_error, 220, 0, 0, 255);
1133         rgba_char_args_set(btheme->tinfo.info_error_text, 0, 0, 0, 255);
1134         rgba_char_args_set(btheme->tinfo.info_warning, 220, 128, 96, 255);
1135         rgba_char_args_set(btheme->tinfo.info_warning_text, 0, 0, 0, 255);
1136         rgba_char_args_set(btheme->tinfo.info_info, 0, 170, 0, 255);
1137         rgba_char_args_set(btheme->tinfo.info_info_text, 0, 0, 0, 255);
1138         rgba_char_args_set(btheme->tinfo.info_debug, 196, 196, 196, 255);
1139         rgba_char_args_set(btheme->tinfo.info_debug_text, 0, 0, 0, 255);
1140
1141         /* space user preferences */
1142         btheme->tuserpref = btheme->tv3d;
1143         rgba_char_args_set_fl(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
1144         
1145         /* space console */
1146         btheme->tconsole = btheme->tv3d;
1147         rgba_char_args_set(btheme->tconsole.back, 0, 0, 0, 255);
1148         rgba_char_args_set(btheme->tconsole.console_output, 96, 128, 255, 255);
1149         rgba_char_args_set(btheme->tconsole.console_input, 255, 255, 255, 255);
1150         rgba_char_args_set(btheme->tconsole.console_info, 0, 170, 0, 255);
1151         rgba_char_args_set(btheme->tconsole.console_error, 220, 96, 96, 255);
1152         rgba_char_args_set(btheme->tconsole.console_cursor, 220, 96, 96, 255);
1153         rgba_char_args_set(btheme->tconsole.console_select, 255, 255, 255, 48);
1154         
1155         /* space time */
1156         btheme->ttime = btheme->tv3d;
1157         rgba_char_args_set_fl(btheme->ttime.back,   0.45, 0.45, 0.45, 1.0);
1158         rgba_char_args_set_fl(btheme->ttime.grid,   0.36, 0.36, 0.36, 1.0);
1159         rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);      /* sliders */
1160         
1161         rgba_char_args_set(btheme->ttime.time_keyframe, 0xDD, 0xD7, 0x00, 0xFF);
1162         rgba_char_args_set(btheme->ttime.time_gp_keyframe, 0xB5, 0xE6, 0x1D, 0xFF);
1163         
1164         /* space node, re-uses syntax and console color storage */
1165         btheme->tnode = btheme->tv3d;
1166         rgba_char_args_set(btheme->tnode.syntaxr, 115, 115, 115, 255);  /* wire inner color */
1167         rgba_char_args_set(btheme->tnode.edge_select, 255, 255, 255, 255);  /* wire selected */
1168         rgba_char_args_set(btheme->tnode.syntaxl, 155, 155, 155, 160);  /* TH_NODE, backdrop */
1169         rgba_char_args_set(btheme->tnode.syntaxn, 100, 100, 100, 255);  /* in */
1170         rgba_char_args_set(btheme->tnode.nodeclass_output, 100, 100, 100, 255);  /* output */
1171         rgba_char_args_set(btheme->tnode.syntaxb, 108, 105, 111, 255);  /* operator */
1172         rgba_char_args_set(btheme->tnode.syntaxv, 104, 106, 117, 255);  /* generator */
1173         rgba_char_args_set(btheme->tnode.syntaxc, 105, 117, 110, 255);  /* group */
1174         rgba_char_args_set(btheme->tnode.nodeclass_texture, 108, 105, 111, 255);  /* operator */
1175         rgba_char_args_set(btheme->tnode.nodeclass_shader, 108, 105, 111, 255);  /* operator */
1176         rgba_char_args_set(btheme->tnode.nodeclass_filter, 108, 105, 111, 255);  /* operator */
1177         rgba_char_args_set(btheme->tnode.nodeclass_script, 108, 105, 111, 255);  /* operator */
1178         rgba_char_args_set(btheme->tnode.nodeclass_pattern, 108, 105, 111, 255);  /* operator */
1179         rgba_char_args_set(btheme->tnode.nodeclass_vector, 108, 105, 111, 255);  /* operator */
1180         rgba_char_args_set(btheme->tnode.nodeclass_layout, 108, 105, 111, 255);  /* operator */
1181         rgba_char_args_set(btheme->tnode.movie, 155, 155, 155, 160);  /* frame */
1182         rgba_char_args_set(btheme->tnode.syntaxs, 151, 116, 116, 255);  /* matte nodes */
1183         rgba_char_args_set(btheme->tnode.syntaxd, 116, 151, 151, 255);  /* distort nodes */
1184         rgba_char_args_set(btheme->tnode.console_output, 223, 202, 53, 255);  /* interface nodes */
1185         btheme->tnode.noodle_curving = 5;
1186
1187         /* space logic */
1188         btheme->tlogic = btheme->tv3d;
1189         rgba_char_args_set(btheme->tlogic.back, 100, 100, 100, 255);
1190         
1191         /* space clip */
1192         btheme->tclip = btheme->tv3d;
1193
1194         rgba_char_args_set(btheme->tclip.marker_outline, 0x00, 0x00, 0x00, 255);
1195         rgba_char_args_set(btheme->tclip.marker, 0x7f, 0x7f, 0x00, 255);
1196         rgba_char_args_set(btheme->tclip.act_marker, 0xff, 0xff, 0xff, 255);
1197         rgba_char_args_set(btheme->tclip.sel_marker, 0xff, 0xff, 0x00, 255);
1198         rgba_char_args_set(btheme->tclip.dis_marker, 0x7f, 0x00, 0x00, 255);
1199         rgba_char_args_set(btheme->tclip.lock_marker, 0x7f, 0x7f, 0x7f, 255);
1200         rgba_char_args_set(btheme->tclip.path_before, 0xff, 0x00, 0x00, 255);
1201         rgba_char_args_set(btheme->tclip.path_after, 0x00, 0x00, 0xff, 255);
1202         rgba_char_args_set(btheme->tclip.grid, 0x5e, 0x5e, 0x5e, 255);
1203         rgba_char_args_set(btheme->tclip.cframe, 0x60, 0xc0, 0x40, 255);
1204         rgba_char_args_set(btheme->tclip.list, 0x66, 0x66, 0x66, 0xff);
1205         rgba_char_args_set(btheme->tclip.strip, 0x0c, 0x0a, 0x0a, 0x80);
1206         rgba_char_args_set(btheme->tclip.strip_select, 0xff, 0x8c, 0x00, 0xff);
1207         btheme->tclip.handle_vertex_size = 5;
1208         ui_theme_space_init_handles_color(&btheme->tclip);
1209 }
1210
1211 void ui_style_init_default(void)
1212 {
1213         BLI_freelistN(&U.uistyles);
1214         /* gets automatically re-allocated */
1215         uiStyleInit();
1216 }
1217
1218
1219 void UI_SetTheme(int spacetype, int regionid)
1220 {
1221         if (spacetype) {
1222                 /* later on, a local theme can be found too */
1223                 theme_active = U.themes.first;
1224                 theme_spacetype = spacetype;
1225                 theme_regionid = regionid;
1226         }
1227         else if (regionid) {
1228                 /* popups */
1229                 theme_active = U.themes.first;
1230                 theme_spacetype = SPACE_BUTS;
1231                 theme_regionid = regionid;
1232         }
1233         else {
1234                 /* for safety, when theme was deleted */
1235                 theme_active = U.themes.first;
1236                 theme_spacetype = SPACE_VIEW3D;
1237                 theme_regionid = RGN_TYPE_WINDOW;
1238         }
1239 }
1240
1241 bTheme *UI_GetTheme(void)
1242 {
1243         return U.themes.first;
1244 }
1245
1246 /**
1247  * for the rare case we need to temp swap in a different theme (offscreen render)
1248  */
1249 void UI_Theme_Store(struct bThemeState *theme_state)
1250 {
1251         *theme_state = g_theme_state;
1252 }
1253 void UI_Theme_Restore(struct bThemeState *theme_state)
1254 {
1255         g_theme_state = *theme_state;
1256 }
1257
1258 /* for space windows only */
1259 void UI_ThemeColor(int colorid)
1260 {
1261         const unsigned char *cp;
1262         
1263         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1264         glColor3ubv(cp);
1265
1266 }
1267
1268 /* plus alpha */
1269 void UI_ThemeColor4(int colorid)
1270 {
1271         const unsigned char *cp;
1272         
1273         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1274         glColor4ubv(cp);
1275
1276 }
1277
1278 /* set the color with offset for shades */
1279 void UI_ThemeColorShade(int colorid, int offset)
1280 {
1281         int r, g, b;
1282         const unsigned char *cp;
1283         
1284         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1285         r = offset + (int) cp[0];
1286         CLAMP(r, 0, 255);
1287         g = offset + (int) cp[1];
1288         CLAMP(g, 0, 255);
1289         b = offset + (int) cp[2];
1290         CLAMP(b, 0, 255);
1291         glColor4ub(r, g, b, cp[3]);
1292 }
1293 void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
1294 {
1295         int r, g, b, a;
1296         const unsigned char *cp;
1297         
1298         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1299         r = coloffset + (int) cp[0];
1300         CLAMP(r, 0, 255);
1301         g = coloffset + (int) cp[1];
1302         CLAMP(g, 0, 255);
1303         b = coloffset + (int) cp[2];
1304         CLAMP(b, 0, 255);
1305         a = alphaoffset + (int) cp[3];
1306         CLAMP(a, 0, 255);
1307         glColor4ub(r, g, b, a);
1308 }
1309
1310 void UI_GetThemeColorBlend3ubv(int colorid1, int colorid2, float fac, unsigned char col[3])
1311 {
1312         const unsigned char *cp1, *cp2;
1313
1314         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
1315         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
1316
1317         CLAMP(fac, 0.0f, 1.0f);
1318         col[0] = floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1319         col[1] = floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1320         col[2] = floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
1321 }
1322
1323 /* blend between to theme colors, and set it */
1324 void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
1325 {
1326         unsigned char col[3];
1327         UI_GetThemeColorBlend3ubv(colorid1, colorid2, fac, col);
1328         glColor3ubv(col);
1329 }
1330
1331 /* blend between to theme colors, shade it, and set it */
1332 void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
1333 {
1334         int r, g, b;
1335         const unsigned char *cp1, *cp2;
1336         
1337         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
1338         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
1339
1340         CLAMP(fac, 0.0f, 1.0f);
1341         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1342         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1343         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
1344         
1345         CLAMP(r, 0, 255);
1346         CLAMP(g, 0, 255);
1347         CLAMP(b, 0, 255);
1348         
1349         glColor3ub(r, g, b);
1350 }
1351
1352 /* blend between to theme colors, shade it, and set it */
1353 void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
1354 {
1355         int r, g, b, a;
1356         const unsigned char *cp1, *cp2;
1357         
1358         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
1359         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
1360
1361         CLAMP(fac, 0.0f, 1.0f);
1362         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1363         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1364         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
1365         a = alphaoffset + floorf((1.0f - fac) * cp1[3] + fac * cp2[3]);
1366         
1367         CLAMP(r, 0, 255);
1368         CLAMP(g, 0, 255);
1369         CLAMP(b, 0, 255);
1370         CLAMP(a, 0, 255);
1371
1372         glColor4ub(r, g, b, a);
1373 }
1374
1375
1376 /* get individual values, not scaled */
1377 float UI_GetThemeValuef(int colorid)
1378 {
1379         const unsigned char *cp;
1380         
1381         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1382         return ((float)cp[0]);
1383 }
1384
1385 /* get individual values, not scaled */
1386 int UI_GetThemeValue(int colorid)
1387 {
1388         const unsigned char *cp;
1389         
1390         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1391         return ((int) cp[0]);
1392 }
1393
1394 /* versions of the function above, which take a space-type */
1395 float UI_GetThemeValueTypef(int colorid, int spacetype)
1396 {
1397         const unsigned char *cp;
1398
1399         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
1400         return ((float)cp[0]);
1401 }
1402
1403 int UI_GetThemeValueType(int colorid, int spacetype)
1404 {
1405         const unsigned char *cp;
1406
1407         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
1408         return ((int)cp[0]);
1409 }
1410
1411
1412 /* get the color, range 0.0-1.0 */
1413 void UI_GetThemeColor3fv(int colorid, float col[3])
1414 {
1415         const unsigned char *cp;
1416         
1417         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1418         col[0] = ((float)cp[0]) / 255.0f;
1419         col[1] = ((float)cp[1]) / 255.0f;
1420         col[2] = ((float)cp[2]) / 255.0f;
1421 }
1422
1423 void UI_GetThemeColor4fv(int colorid, float col[4])
1424 {
1425         const unsigned char *cp;
1426         
1427         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1428         col[0] = ((float)cp[0]) / 255.0f;
1429         col[1] = ((float)cp[1]) / 255.0f;
1430         col[2] = ((float)cp[2]) / 255.0f;
1431         col[3] = ((float)cp[3]) / 255.0f;
1432 }
1433
1434 /* get the color, range 0.0-1.0, complete with shading offset */
1435 void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
1436 {
1437         int r, g, b;
1438         const unsigned char *cp;
1439         
1440         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1441         
1442         r = offset + (int) cp[0];
1443         CLAMP(r, 0, 255);
1444         g = offset + (int) cp[1];
1445         CLAMP(g, 0, 255);
1446         b = offset + (int) cp[2];
1447         CLAMP(b, 0, 255);
1448         
1449         col[0] = ((float)r) / 255.0f;
1450         col[1] = ((float)g) / 255.0f;
1451         col[2] = ((float)b) / 255.0f;
1452 }
1453
1454 void UI_GetThemeColorShade3ubv(int colorid, int offset, unsigned char col[3])
1455 {
1456         int r, g, b;
1457         const unsigned char *cp;
1458
1459         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1460
1461         r = offset + (int) cp[0];
1462         CLAMP(r, 0, 255);
1463         g = offset + (int) cp[1];
1464         CLAMP(g, 0, 255);
1465         b = offset + (int) cp[2];
1466         CLAMP(b, 0, 255);
1467
1468         col[0] = r;
1469         col[1] = g;
1470         col[2] = b;
1471 }
1472
1473 /* get the color, in char pointer */
1474 void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
1475 {
1476         const unsigned char *cp;
1477         
1478         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1479         col[0] = cp[0];
1480         col[1] = cp[1];
1481         col[2] = cp[2];
1482 }
1483
1484 /* get the color, range 0.0-1.0, complete with shading offset */
1485 void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
1486 {
1487         int r, g, b, a;
1488         const unsigned char *cp;
1489         
1490         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1491         
1492         r = offset + (int) cp[0];
1493         CLAMP(r, 0, 255);
1494         g = offset + (int) cp[1];
1495         CLAMP(g, 0, 255);
1496         b = offset + (int) cp[2];
1497         CLAMP(b, 0, 255);
1498         
1499         a = (int) cp[3]; /* no shading offset... */
1500         CLAMP(a, 0, 255);
1501         
1502         col[0] = ((float)r) / 255.0f;
1503         col[1] = ((float)g) / 255.0f;
1504         col[2] = ((float)b) / 255.0f;
1505         col[3] = ((float)a) / 255.0f;
1506 }
1507
1508 /* get the color, in char pointer */
1509 void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
1510 {
1511         const unsigned char *cp;
1512         
1513         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1514         col[0] = cp[0];
1515         col[1] = cp[1];
1516         col[2] = cp[2];
1517         col[3] = cp[3];
1518 }
1519
1520 void UI_GetThemeColorType4ubv(int colorid, int spacetype, char col[4])
1521 {
1522         const unsigned char *cp;
1523         
1524         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
1525         col[0] = cp[0];
1526         col[1] = cp[1];
1527         col[2] = cp[2];
1528         col[3] = cp[3];
1529 }
1530
1531 /* blends and shades between two char color pointers */
1532 void UI_ColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], float fac, int offset)
1533 {
1534         int r, g, b;
1535         CLAMP(fac, 0.0f, 1.0f);
1536         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1537         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1538         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
1539
1540         r = r < 0 ? 0 : (r > 255 ? 255 : r);
1541         g = g < 0 ? 0 : (g > 255 ? 255 : g);
1542         b = b < 0 ? 0 : (b > 255 ? 255 : b);
1543         
1544         glColor3ub(r, g, b);
1545 }
1546
1547 void UI_GetColorPtrShade3ubv(const unsigned char cp[3], unsigned char col[3], int offset)
1548 {
1549         int r, g, b;
1550
1551         r = offset + (int)cp[0];
1552         g = offset + (int)cp[1];
1553         b = offset + (int)cp[2];
1554
1555         CLAMP(r, 0, 255);
1556         CLAMP(g, 0, 255);
1557         CLAMP(b, 0, 255);
1558
1559         col[0] = r;
1560         col[1] = g;
1561         col[2] = b;
1562 }
1563
1564 /* get a 3 byte color, blended and shaded between two other char color pointers */
1565 void UI_GetColorPtrBlendShade3ubv(
1566         const unsigned char cp1[3], const unsigned char cp2[3], unsigned char col[3],
1567         float fac, int offset)
1568 {
1569         int r, g, b;
1570
1571         CLAMP(fac, 0.0f, 1.0f);
1572         r = offset + floor((1.0f - fac) * cp1[0] + fac * cp2[0]);
1573         g = offset + floor((1.0f - fac) * cp1[1] + fac * cp2[1]);
1574         b = offset + floor((1.0f - fac) * cp1[2] + fac * cp2[2]);
1575
1576         CLAMP(r, 0, 255);
1577         CLAMP(g, 0, 255);
1578         CLAMP(b, 0, 255);
1579
1580         col[0] = r;
1581         col[1] = g;
1582         col[2] = b;
1583 }
1584
1585 void UI_ThemeClearColor(int colorid)
1586 {
1587         float col[3];
1588         
1589         UI_GetThemeColor3fv(colorid, col);
1590         glClearColor(col[0], col[1], col[2], 0.0f);
1591 }
1592
1593 void UI_ThemeClearColorAlpha(int colorid, float alpha)
1594 {
1595         float col[3];
1596         UI_GetThemeColor3fv(colorid, col);
1597         glClearColor(col[0], col[1], col[2], alpha);
1598 }
1599
1600
1601 int UI_ThemeMenuShadowWidth(void)
1602 {
1603         bTheme *btheme = UI_GetTheme();
1604         return (int)(btheme->tui.menu_shadow_width * UI_DPI_FAC);
1605 }
1606
1607 void UI_make_axis_color(const unsigned char src_col[3], unsigned char dst_col[3], const char axis)
1608 {
1609         unsigned char col[3];
1610         
1611         switch (axis) {
1612                 case 'X':
1613                         UI_GetThemeColor3ubv(TH_AXIS_X, col);
1614                         UI_GetColorPtrBlendShade3ubv(src_col, col, dst_col, 0.5f, -10);
1615                         break;
1616                 case 'Y':
1617                         UI_GetThemeColor3ubv(TH_AXIS_Y, col);
1618                         UI_GetColorPtrBlendShade3ubv(src_col, col, dst_col, 0.5f, -10);
1619                         break;
1620                 case 'Z':
1621                         UI_GetThemeColor3ubv(TH_AXIS_Z, col);
1622                         UI_GetColorPtrBlendShade3ubv(src_col, col, dst_col, 0.5f, -10);
1623                         break;
1624                 default:
1625                         BLI_assert(0);
1626                         break;
1627         }
1628 }
1629
1630 /* ************************************************************* */
1631
1632 /* patching UserDef struct and Themes */
1633 void init_userdef_do_versions(void)
1634 {
1635         Main *bmain = G.main;
1636         
1637 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(bmain, ver, subver)
1638
1639         /* the UserDef struct is not corrected with do_versions() .... ugh! */
1640         if (U.wheellinescroll == 0) U.wheellinescroll = 3;
1641         if (U.menuthreshold1 == 0) {
1642                 U.menuthreshold1 = 5;
1643                 U.menuthreshold2 = 2;
1644         }
1645         if (U.tb_leftmouse == 0) {
1646                 U.tb_leftmouse = 5;
1647                 U.tb_rightmouse = 5;
1648         }
1649         if (U.mixbufsize == 0) U.mixbufsize = 2048;
1650         if (STREQ(U.tempdir, "/")) {
1651                 BKE_tempdir_system_init(U.tempdir);
1652         }
1653         if (U.autokey_mode == 0) {
1654                 /* 'add/replace' but not on */
1655                 U.autokey_mode = 2;
1656         }
1657         if (U.savetime <= 0) {
1658                 U.savetime = 1;
1659 // XXX          error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n");
1660         }
1661         /* transform widget settings */
1662         if (U.tw_hotspot == 0) {
1663                 U.tw_hotspot = 14;
1664                 U.tw_size = 25;          /* percentage of window size */
1665                 U.tw_handlesize = 16;    /* percentage of widget radius */
1666         }
1667         if (U.pad_rot_angle == 0.0f)
1668                 U.pad_rot_angle = 15.0f;
1669         
1670         /* graph editor - unselected F-Curve visibility */
1671         if (U.fcu_inactive_alpha == 0) {
1672                 U.fcu_inactive_alpha = 0.25f;
1673         }
1674         
1675         /* signal for derivedmesh to use colorband */
1676         /* run in case this was on and is now off in the user prefs [#28096] */
1677         vDM_ColorBand_store((U.flag & USER_CUSTOM_RANGE) ? (&U.coba_weight) : NULL, UI_GetTheme()->tv3d.vertex_unreferenced);
1678
1679         if (!USER_VERSION_ATLEAST(192, 0)) {
1680                 strcpy(U.sounddir, "/");
1681         }
1682         
1683         /* patch to set Dupli Armature */
1684         if (!USER_VERSION_ATLEAST(220, 0)) {
1685                 U.dupflag |= USER_DUP_ARM;
1686         }
1687         
1688         /* added seam, normal color, undo */
1689         if (!USER_VERSION_ATLEAST(235, 0)) {
1690                 bTheme *btheme;
1691                 
1692                 U.uiflag |= USER_GLOBALUNDO;
1693                 if (U.undosteps == 0) U.undosteps = 32;
1694                 
1695                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1696                         /* check for (alpha == 0) is safe, then color was never set */
1697                         if (btheme->tv3d.edge_seam[3] == 0) {
1698                                 rgba_char_args_set(btheme->tv3d.edge_seam, 230, 150, 50, 255);
1699                         }
1700                         if (btheme->tv3d.normal[3] == 0) {
1701                                 rgba_char_args_set(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
1702                         }
1703                         if (btheme->tv3d.vertex_normal[3] == 0) {
1704                                 rgba_char_args_set(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
1705                         }
1706                         if (btheme->tv3d.face_dot[3] == 0) {
1707                                 rgba_char_args_set(btheme->tv3d.face_dot, 255, 138, 48, 255);
1708                                 btheme->tv3d.facedot_size = 4;
1709                         }
1710                 }
1711         }
1712         if (!USER_VERSION_ATLEAST(236, 0)) {
1713                 /* illegal combo... */
1714                 if (U.flag & USER_LMOUSESELECT) 
1715                         U.flag &= ~USER_TWOBUTTONMOUSE;
1716         }
1717         if (!USER_VERSION_ATLEAST(237, 0)) {
1718                 bTheme *btheme;
1719                 /* new space type */
1720                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1721                         /* check for (alpha == 0) is safe, then color was never set */
1722                         if (btheme->ttime.back[3] == 0) {
1723                                 /* copied from ui_theme_init_default */
1724                                 btheme->ttime = btheme->tv3d;
1725                                 rgba_char_args_set_fl(btheme->ttime.back,   0.45, 0.45, 0.45, 1.0);
1726                                 rgba_char_args_set_fl(btheme->ttime.grid,   0.36, 0.36, 0.36, 1.0);
1727                                 rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);  /* sliders */
1728                         }
1729                         if (btheme->text.syntaxn[3] == 0) {
1730                                 rgba_char_args_set(btheme->text.syntaxn,    0, 0, 200, 255);    /* Numbers  Blue*/
1731                                 rgba_char_args_set(btheme->text.syntaxl,    100, 0, 0, 255);    /* Strings  red */
1732                                 rgba_char_args_set(btheme->text.syntaxc,    0, 100, 50, 255);   /* Comments greenish */
1733                                 rgba_char_args_set(btheme->text.syntaxv,    95, 95, 0, 255);    /* Special */
1734                                 rgba_char_args_set(btheme->text.syntaxb,    128, 0, 80, 255);   /* Builtin, red-purple */
1735                         }
1736                 }
1737         }
1738         if (!USER_VERSION_ATLEAST(238, 0)) {
1739                 bTheme *btheme;
1740                 /* bone colors */
1741                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1742                         /* check for alpha==0 is safe, then color was never set */
1743                         if (btheme->tv3d.bone_solid[3] == 0) {
1744                                 rgba_char_args_set(btheme->tv3d.bone_solid, 200, 200, 200, 255);
1745                                 rgba_char_args_set(btheme->tv3d.bone_pose, 80, 200, 255, 80);
1746                         }
1747                 }
1748         }
1749         if (!USER_VERSION_ATLEAST(239, 0)) {
1750                 bTheme *btheme;
1751                 /* bone colors */
1752                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1753                         /* check for alpha==0 is safe, then color was never set */
1754                         if (btheme->tnla.strip[3] == 0) {
1755                                 rgba_char_args_set(btheme->tnla.strip_select,   0xff, 0xff, 0xaa, 255);
1756                                 rgba_char_args_set(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
1757                         }
1758                 }
1759         }
1760         if (!USER_VERSION_ATLEAST(240, 0)) {
1761                 bTheme *btheme;
1762                 
1763                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1764                         /* Lamp theme, check for alpha==0 is safe, then color was never set */
1765                         if (btheme->tv3d.lamp[3] == 0) {
1766                                 rgba_char_args_set(btheme->tv3d.lamp,   0, 0, 0, 40);
1767 /* TEMPORAL, remove me! (ton) */                                
1768                                 U.uiflag |= USER_PLAINMENUS;
1769                         }
1770                         
1771                 }
1772                 if (U.obcenter_dia == 0) U.obcenter_dia = 6;
1773         }
1774         if (!USER_VERSION_ATLEAST(242, 0)) {
1775                 bTheme *btheme;
1776                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1777                         /* Node editor theme, check for alpha==0 is safe, then color was never set */
1778                         if (btheme->tnode.syntaxn[3] == 0) {
1779                                 /* re-uses syntax color storage */
1780                                 btheme->tnode = btheme->tv3d;
1781                                 rgba_char_args_set(btheme->tnode.edge_select, 255, 255, 255, 255);
1782                                 rgba_char_args_set(btheme->tnode.syntaxl, 150, 150, 150, 255);  /* TH_NODE, backdrop */
1783                                 rgba_char_args_set(btheme->tnode.syntaxn, 129, 131, 144, 255);  /* in/output */
1784                                 rgba_char_args_set(btheme->tnode.syntaxb, 127, 127, 127, 255);  /* operator */
1785                                 rgba_char_args_set(btheme->tnode.syntaxv, 142, 138, 145, 255);  /* generator */
1786                                 rgba_char_args_set(btheme->tnode.syntaxc, 120, 145, 120, 255);  /* group */
1787                         }
1788                         /* Group theme colors */
1789                         if (btheme->tv3d.group[3] == 0) {
1790                                 rgba_char_args_set(btheme->tv3d.group, 0x0C, 0x30, 0x0C, 255);
1791                                 rgba_char_args_set(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
1792                         }
1793                         /* Sequence editor theme*/
1794                         if (btheme->tseq.movie[3] == 0) {
1795                                 rgba_char_args_set(btheme->tseq.movie,  81, 105, 135, 255);
1796                                 rgba_char_args_set(btheme->tseq.image,  109, 88, 129, 255);
1797                                 rgba_char_args_set(btheme->tseq.scene,  78, 152, 62, 255);
1798                                 rgba_char_args_set(btheme->tseq.audio,  46, 143, 143, 255);
1799                                 rgba_char_args_set(btheme->tseq.effect,     169, 84, 124, 255);
1800                                 rgba_char_args_set(btheme->tseq.transition, 162, 95, 111, 255);
1801                                 rgba_char_args_set(btheme->tseq.meta,   109, 145, 131, 255);
1802                         }
1803                 }
1804                 
1805                 /* set defaults for 3D View rotating axis indicator */ 
1806                 /* since size can't be set to 0, this indicates it's not saved in startup.blend */
1807                 if (U.rvisize == 0) {
1808                         U.rvisize = 15;
1809                         U.rvibright = 8;
1810                         U.uiflag |= USER_SHOW_ROTVIEWICON;
1811                 }
1812                 
1813         }
1814         if (!USER_VERSION_ATLEAST(243, 0)) {
1815                 bTheme *btheme;
1816                 
1817                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1818                         /* long keyframe color */
1819                         /* check for alpha==0 is safe, then color was never set */
1820                         if (btheme->tact.strip[3] == 0) {
1821                                 rgba_char_args_set(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
1822                                 rgba_char_args_set(btheme->tact.strip_select,   0xff, 0xff, 0xaa, 204);
1823                                 rgba_char_args_set(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
1824                         }
1825                         
1826                         /* IPO-Editor - Vertex Size*/
1827                         if (btheme->tipo.vertex_size == 0) {
1828                                 btheme->tipo.vertex_size = 3;
1829                         }
1830                 }
1831         }
1832         if (!USER_VERSION_ATLEAST(244, 0)) {
1833                 /* set default number of recently-used files (if not set) */
1834                 if (U.recent_files == 0) U.recent_files = 10;
1835         }
1836         if (!USER_VERSION_ATLEAST(245, 3)) {
1837                 bTheme *btheme;
1838                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1839                         rgba_char_args_set(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
1840                 }
1841                 if (U.coba_weight.tot == 0)
1842                         BKE_colorband_init(&U.coba_weight, true);
1843         }
1844         if (!USER_VERSION_ATLEAST(245, 3)) {
1845                 bTheme *btheme;
1846                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1847                         /* these should all use the same color */
1848                         rgba_char_args_set(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1849                         rgba_char_args_set(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1850                         rgba_char_args_set(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1851                         rgba_char_args_set(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1852                         rgba_char_args_set(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1853                         //rgba_char_args_set(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255); Not needed anymore
1854                         rgba_char_args_set(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1855                 }
1856         }
1857         if (!USER_VERSION_ATLEAST(245, 3)) {
1858                 bTheme *btheme;
1859                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1860                         /* action channel groups (recolor anyway) */
1861                         rgba_char_args_set(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
1862                         rgba_char_args_set(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
1863                         
1864                         /* bone custom-color sets */
1865                         if (btheme->tarm[0].solid[3] == 0)
1866                                 ui_theme_init_boneColorSets(btheme);
1867                 }
1868         }
1869         if (!USER_VERSION_ATLEAST(245, 3)) {
1870                 U.flag |= USER_ADD_VIEWALIGNED | USER_ADD_EDITMODE;
1871         }
1872         if (!USER_VERSION_ATLEAST(245, 3)) {
1873                 bTheme *btheme;
1874                 
1875                 /* adjust themes */
1876                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1877                         const char *col;
1878                         
1879                         /* IPO Editor: Handles/Vertices */
1880                         col = btheme->tipo.vertex;
1881                         rgba_char_args_set(btheme->tipo.handle_vertex, col[0], col[1], col[2], 255);
1882                         col = btheme->tipo.vertex_select;
1883                         rgba_char_args_set(btheme->tipo.handle_vertex_select, col[0], col[1], col[2], 255);
1884                         btheme->tipo.handle_vertex_size = btheme->tipo.vertex_size;
1885                         
1886                         /* Sequence/Image Editor: colors for GPencil text */
1887                         col = btheme->tv3d.bone_pose;
1888                         rgba_char_args_set(btheme->tseq.bone_pose, col[0], col[1], col[2], 255);
1889                         rgba_char_args_set(btheme->tima.bone_pose, col[0], col[1], col[2], 255);
1890                         col = btheme->tv3d.vertex_select;
1891                         rgba_char_args_set(btheme->tseq.vertex_select, col[0], col[1], col[2], 255);
1892                 }
1893         }
1894         if (!USER_VERSION_ATLEAST(250, 0)) {
1895                 bTheme *btheme;
1896                 
1897                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1898                         /* this was not properly initialized in 2.45 */
1899                         if (btheme->tima.face_dot[3] == 0) {
1900                                 rgba_char_args_set(btheme->tima.editmesh_active, 255, 255, 255, 128);
1901                                 rgba_char_args_set(btheme->tima.face_dot, 255, 133, 0, 255);
1902                                 btheme->tima.facedot_size = 2;
1903                         }
1904                         
1905                         /* DopeSheet - (Object) Channel color */
1906                         rgba_char_args_set(btheme->tact.ds_channel,     82, 96, 110, 255);
1907                         rgba_char_args_set(btheme->tact.ds_subchannel,  124, 137, 150, 255);
1908                         /* DopeSheet - Group Channel color (saner version) */
1909                         rgba_char_args_set(btheme->tact.group, 79, 101, 73, 255);
1910                         rgba_char_args_set(btheme->tact.group_active, 135, 177, 125, 255);
1911                         
1912                         /* Graph Editor - (Object) Channel color */
1913                         rgba_char_args_set(btheme->tipo.ds_channel,     82, 96, 110, 255);
1914                         rgba_char_args_set(btheme->tipo.ds_subchannel,  124, 137, 150, 255);
1915                         /* Graph Editor - Group Channel color */
1916                         rgba_char_args_set(btheme->tipo.group, 79, 101, 73, 255);
1917                         rgba_char_args_set(btheme->tipo.group_active, 135, 177, 125, 255);
1918                         
1919                         /* Nla Editor - (Object) Channel color */
1920                         rgba_char_args_set(btheme->tnla.ds_channel,     82, 96, 110, 255);
1921                         rgba_char_args_set(btheme->tnla.ds_subchannel,  124, 137, 150, 255);
1922                         /* NLA Editor - New Strip colors */
1923                         rgba_char_args_set(btheme->tnla.strip,          12, 10, 10, 128);
1924                         rgba_char_args_set(btheme->tnla.strip_select,   255, 140, 0, 255);
1925                 }
1926                 
1927                 /* adjust grease-pencil distances */
1928                 U.gp_manhattendist = 1;
1929                 U.gp_euclideandist = 2;
1930                 
1931                 /* adjust default interpolation for new IPO-curves */
1932                 U.ipo_new = BEZT_IPO_BEZ;
1933         }
1934         
1935         if (!USER_VERSION_ATLEAST(250, 1)) {
1936                 bTheme *btheme;
1937
1938                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1939                         
1940                         /* common (new) variables, it checks for alpha==0 */
1941                         ui_theme_init_new(btheme);
1942
1943                         if (btheme->tui.wcol_num.outline[3] == 0)
1944                                 ui_widget_color_init(&btheme->tui);
1945                         
1946                         /* Logic editor theme, check for alpha==0 is safe, then color was never set */
1947                         if (btheme->tlogic.syntaxn[3] == 0) {
1948                                 /* re-uses syntax color storage */
1949                                 btheme->tlogic = btheme->tv3d;
1950                                 rgba_char_args_set(btheme->tlogic.back, 100, 100, 100, 255);
1951                         }
1952
1953                         rgba_char_args_set_fl(btheme->tinfo.back, 0.45, 0.45, 0.45, 1.0);
1954                         rgba_char_args_set_fl(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
1955                 }
1956         }
1957
1958         if (!USER_VERSION_ATLEAST(250, 3)) {
1959                 /* new audio system */
1960                 if (U.audiochannels == 0)
1961                         U.audiochannels = 2;
1962                 if (U.audiodevice == 0) {
1963 #ifdef WITH_OPENAL
1964                         U.audiodevice = 2;
1965 #endif
1966 #ifdef WITH_SDL
1967                         U.audiodevice = 1;
1968 #endif
1969                 }
1970                 if (U.audioformat == 0)
1971                         U.audioformat = 0x24;
1972                 if (U.audiorate == 0)
1973                         U.audiorate = 48000;
1974         }
1975         
1976         if (!USER_VERSION_ATLEAST(250, 8)) {
1977                 wmKeyMap *km;
1978                 
1979                 for (km = U.user_keymaps.first; km; km = km->next) {
1980                         if (STREQ(km->idname, "Armature_Sketch"))
1981                                 strcpy(km->idname, "Armature Sketch");
1982                         else if (STREQ(km->idname, "View3D"))
1983                                 strcpy(km->idname, "3D View");
1984                         else if (STREQ(km->idname, "View3D Generic"))
1985                                 strcpy(km->idname, "3D View Generic");
1986                         else if (STREQ(km->idname, "EditMesh"))
1987                                 strcpy(km->idname, "Mesh");
1988                         else if (STREQ(km->idname, "TimeLine"))
1989                                 strcpy(km->idname, "Timeline");
1990                         else if (STREQ(km->idname, "UVEdit"))
1991                                 strcpy(km->idname, "UV Editor");
1992                         else if (STREQ(km->idname, "Animation_Channels"))
1993                                 strcpy(km->idname, "Animation Channels");
1994                         else if (STREQ(km->idname, "GraphEdit Keys"))
1995                                 strcpy(km->idname, "Graph Editor");
1996                         else if (STREQ(km->idname, "GraphEdit Generic"))
1997                                 strcpy(km->idname, "Graph Editor Generic");
1998                         else if (STREQ(km->idname, "Action_Keys"))
1999                                 strcpy(km->idname, "Dopesheet");
2000                         else if (STREQ(km->idname, "NLA Data"))
2001                                 strcpy(km->idname, "NLA Editor");
2002                         else if (STREQ(km->idname, "Node Generic"))
2003                                 strcpy(km->idname, "Node Editor");
2004                         else if (STREQ(km->idname, "Logic Generic"))
2005                                 strcpy(km->idname, "Logic Editor");
2006                         else if (STREQ(km->idname, "File"))
2007                                 strcpy(km->idname, "File Browser");
2008                         else if (STREQ(km->idname, "FileMain"))
2009                                 strcpy(km->idname, "File Browser Main");
2010                         else if (STREQ(km->idname, "FileButtons"))
2011                                 strcpy(km->idname, "File Browser Buttons");
2012                         else if (STREQ(km->idname, "Buttons Generic"))
2013                                 strcpy(km->idname, "Property Editor");
2014                 }
2015         }
2016         if (!USER_VERSION_ATLEAST(250, 16)) {
2017                 if (U.wmdrawmethod == USER_DRAW_TRIPLE)
2018                         U.wmdrawmethod = USER_DRAW_AUTOMATIC;
2019         }
2020         
2021         if (!USER_VERSION_ATLEAST(252, 3)) {
2022                 if (U.flag & USER_LMOUSESELECT) 
2023                         U.flag &= ~USER_TWOBUTTONMOUSE;
2024         }
2025         if (!USER_VERSION_ATLEAST(252, 4)) {
2026                 bTheme *btheme;
2027                 
2028                 /* default new handle type is auto handles */
2029                 U.keyhandles_new = HD_AUTO;
2030                 
2031                 /* init new curve colors */
2032                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2033                         ui_theme_space_init_handles_color(&btheme->tv3d);
2034                         ui_theme_space_init_handles_color(&btheme->tipo);
2035
2036                         /* edge crease */
2037                         rgba_char_args_set_fl(btheme->tv3d.edge_crease, 0.8, 0, 0.6, 1.0);
2038                 }
2039         }
2040         if (!USER_VERSION_ATLEAST(253, 0)) {
2041                 bTheme *btheme;
2042
2043                 /* init new curve colors */
2044                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2045                         if (btheme->tv3d.lastsel_point[3] == 0)
2046                                 rgba_char_args_set(btheme->tv3d.lastsel_point, 0xff, 0xff, 0xff, 255);
2047                 }
2048         }
2049         if (!USER_VERSION_ATLEAST(252, 5)) {
2050                 bTheme *btheme;
2051                 
2052                 /* interface_widgets.c */
2053                 struct uiWidgetColors wcol_progress = {
2054                         {0, 0, 0, 255},
2055                         {190, 190, 190, 255},
2056                         {100, 100, 100, 180},
2057                         {128, 128, 128, 255},
2058                         
2059                         {0, 0, 0, 255},
2060                         {255, 255, 255, 255},
2061                         
2062                         0,
2063                         5, -5
2064                 };
2065                 
2066                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2067                         /* init progress bar theme */
2068                         btheme->tui.wcol_progress = wcol_progress;
2069                 }
2070         }
2071
2072         if (!USER_VERSION_ATLEAST(255, 2)) {
2073                 bTheme *btheme;
2074                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2075                         rgba_char_args_set(btheme->tv3d.extra_edge_len, 32, 0, 0, 255);
2076                         rgba_char_args_set(btheme->tv3d.extra_face_angle, 0, 32, 0, 255);
2077                         rgba_char_args_set(btheme->tv3d.extra_face_area, 0, 0, 128, 255);
2078                 }
2079         }
2080         
2081         if (!USER_VERSION_ATLEAST(256, 4)) {
2082                 bTheme *btheme;
2083                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2084                         if ((btheme->tv3d.outline_width) == 0) btheme->tv3d.outline_width = 1;
2085                 }
2086         }
2087
2088         if (!USER_VERSION_ATLEAST(257, 0)) {
2089                 /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs,
2090                  * so that it doesn't linger around from old configs like a ghost */
2091                 U.autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET;
2092         }
2093
2094         if (!USER_VERSION_ATLEAST(258, 2)) {
2095                 bTheme *btheme;
2096                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2097                         btheme->tnode.noodle_curving = 5;
2098                 }
2099         }
2100
2101         if (!USER_VERSION_ATLEAST(259, 1)) {
2102                 bTheme *btheme;
2103                 
2104                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2105                         btheme->tv3d.speaker[3] = 255;
2106                 }
2107         }
2108
2109         if (!USER_VERSION_ATLEAST(260, 3)) {
2110                 bTheme *btheme;
2111                 
2112                 /* if new keyframes handle default is stuff "auto", make it "auto-clamped" instead 
2113                  * was changed in 260 as part of GSoC11, but version patch was wrong
2114                  */
2115                 if (U.keyhandles_new == HD_AUTO) 
2116                         U.keyhandles_new = HD_AUTO_ANIM;
2117                 
2118                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2119                         if (btheme->tv3d.bundle_solid[3] == 0)
2120                                 rgba_char_args_set(btheme->tv3d.bundle_solid, 200, 200, 200, 255);
2121                         
2122                         if (btheme->tv3d.camera_path[3] == 0)
2123                                 rgba_char_args_set(btheme->tv3d.camera_path, 0x00, 0x00, 0x00, 255);
2124                                 
2125                         if ((btheme->tclip.back[3]) == 0) {
2126                                 btheme->tclip = btheme->tv3d;
2127                                 
2128                                 rgba_char_args_set(btheme->tclip.marker_outline, 0x00, 0x00, 0x00, 255);
2129                                 rgba_char_args_set(btheme->tclip.marker, 0x7f, 0x7f, 0x00, 255);
2130                                 rgba_char_args_set(btheme->tclip.act_marker, 0xff, 0xff, 0xff, 255);
2131                                 rgba_char_args_set(btheme->tclip.sel_marker, 0xff, 0xff, 0x00, 255);
2132                                 rgba_char_args_set(btheme->tclip.dis_marker, 0x7f, 0x00, 0x00, 255);
2133                                 rgba_char_args_set(btheme->tclip.lock_marker, 0x7f, 0x7f, 0x7f, 255);
2134                                 rgba_char_args_set(btheme->tclip.path_before, 0xff, 0x00, 0x00, 255);
2135                                 rgba_char_args_set(btheme->tclip.path_after, 0x00, 0x00, 0xff, 255);
2136                                 rgba_char_args_set(btheme->tclip.grid, 0x5e, 0x5e, 0x5e, 255);
2137                                 rgba_char_args_set(btheme->tclip.cframe, 0x60, 0xc0, 0x40, 255);
2138                                 rgba_char_args_set(btheme->tclip.handle_vertex, 0x00, 0x00, 0x00, 0xff);
2139                                 rgba_char_args_set(btheme->tclip.handle_vertex_select, 0xff, 0xff, 0, 0xff);
2140                                 btheme->tclip.handle_vertex_size = 5;
2141                         }
2142                         
2143                         /* auto-clamped handles -> based on auto */
2144                         if (btheme->tipo.handle_auto_clamped[3] == 0)
2145                                 rgba_char_args_set(btheme->tipo.handle_auto_clamped, 0x99, 0x40, 0x30, 255);
2146                         if (btheme->tipo.handle_sel_auto_clamped[3] == 0)
2147                                 rgba_char_args_set(btheme->tipo.handle_sel_auto_clamped, 0xf0, 0xaf, 0x90, 255);
2148                 }
2149                 
2150                 /* enable (Cycles) addon by default */
2151                 if (!BLI_findstring(&U.addons, "cycles", offsetof(bAddon, module))) {
2152                         bAddon *baddon = MEM_callocN(sizeof(bAddon), "bAddon");
2153                         BLI_strncpy(baddon->module, "cycles", sizeof(baddon->module));
2154                         BLI_addtail(&U.addons, baddon);
2155                 }
2156         }
2157         
2158         if (!USER_VERSION_ATLEAST(260, 5)) {
2159                 bTheme *btheme;
2160                 
2161                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2162                         rgba_char_args_set(btheme->tui.panel.header, 0, 0, 0, 25);
2163                         btheme->tui.icon_alpha = 1.0;
2164                 }
2165         }
2166         
2167         if (!USER_VERSION_ATLEAST(261, 4)) {
2168                 bTheme *btheme;
2169                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2170                         rgba_char_args_set_fl(btheme->tima.preview_stitch_face, 0.071, 0.259, 0.694, 0.150);
2171                         rgba_char_args_set_fl(btheme->tima.preview_stitch_edge, 1.0, 0.522, 0.0, 0.7);
2172                         rgba_char_args_set_fl(btheme->tima.preview_stitch_vert, 1.0, 0.522, 0.0, 0.5);
2173                         rgba_char_args_set_fl(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
2174                         rgba_char_args_set_fl(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
2175                         rgba_char_args_set_fl(btheme->tima.preview_stitch_active, 0.886, 0.824, 0.765, 0.140);
2176                         
2177                         rgba_char_args_set_fl(btheme->toops.match, 0.2, 0.5, 0.2, 0.3);
2178                         rgba_char_args_set_fl(btheme->toops.selected_highlight, 0.51, 0.53, 0.55, 0.3);
2179                 }
2180                 
2181                 U.use_16bit_textures = true;
2182         }
2183
2184         if (!USER_VERSION_ATLEAST(262, 2)) {
2185                 bTheme *btheme;
2186                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2187                         if (btheme->tui.wcol_menu_item.item[3] == 255)
2188                                 rgba_char_args_set(btheme->tui.wcol_menu_item.item, 172, 172, 172, 128);
2189                 }
2190         }
2191
2192         if (!USER_VERSION_ATLEAST(262, 3)) {
2193                 bTheme *btheme;
2194                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2195                         if (btheme->tui.wcol_tooltip.inner[3] == 0) {
2196                                 btheme->tui.wcol_tooltip = btheme->tui.wcol_menu_back;
2197                         }
2198                         if (btheme->tui.wcol_tooltip.text[0] == 160) { /* hrmf */
2199                                 rgba_char_args_set(btheme->tui.wcol_tooltip.text, 255, 255, 255, 255);
2200                         }
2201                 }
2202         }
2203
2204         if (!USER_VERSION_ATLEAST(262, 4)) {
2205                 bTheme *btheme;
2206                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2207                         if (btheme->tseq.movieclip[3] == 0) {
2208                                 rgba_char_args_set(btheme->tseq.movieclip,  32, 32, 143, 255);
2209                         }
2210                 }
2211         }
2212
2213         if (!USER_VERSION_ATLEAST(263, 2)) {
2214                 bTheme *btheme;
2215                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2216                         if (btheme->tclip.strip[0] == 0) {
2217                                 rgba_char_args_set(btheme->tclip.list, 0x66, 0x66, 0x66, 0xff);
2218                                 rgba_char_args_set(btheme->tclip.strip, 0x0c, 0x0a, 0x0a, 0x80);
2219                                 rgba_char_args_set(btheme->tclip.strip_select, 0xff, 0x8c, 0x00, 0xff);
2220                         }
2221                 }
2222         }
2223
2224         if (!USER_VERSION_ATLEAST(263, 6)) {
2225                 bTheme *btheme;
2226                 for (btheme = U.themes.first; btheme; btheme = btheme->next)
2227                         rgba_char_args_set(btheme->tv3d.skin_root, 180, 77, 77, 255);
2228         }
2229         
2230         if (!USER_VERSION_ATLEAST(263, 7)) {
2231                 bTheme *btheme;
2232                 
2233                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2234                         /* DopeSheet Summary */
2235                         rgba_char_args_set(btheme->tact.anim_active,    204, 112, 26, 102); 
2236                         
2237                         /* NLA Colors */
2238                         rgba_char_args_set(btheme->tnla.anim_active,     204, 112, 26, 102); /* same as dopesheet above */
2239                         rgba_char_args_set(btheme->tnla.anim_non_active, 153, 135, 97, 77);
2240                         
2241                         rgba_char_args_set(btheme->tnla.nla_tweaking,   77, 243, 26, 77);
2242                         rgba_char_args_set(btheme->tnla.nla_tweakdupli, 217, 0, 0, 255);
2243                         
2244                         rgba_char_args_set(btheme->tnla.nla_transition,     28, 38, 48, 255);
2245                         rgba_char_args_set(btheme->tnla.nla_transition_sel, 46, 117, 219, 255);
2246                         rgba_char_args_set(btheme->tnla.nla_meta,           51, 38, 66, 255);
2247                         rgba_char_args_set(btheme->tnla.nla_meta_sel,       105, 33, 150, 255);
2248                         rgba_char_args_set(btheme->tnla.nla_sound,          43, 61, 61, 255);
2249                         rgba_char_args_set(btheme->tnla.nla_sound_sel,      31, 122, 122, 255);
2250                 }
2251         }
2252
2253         if (!USER_VERSION_ATLEAST(263, 11)) {
2254                 bTheme *btheme;
2255                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2256                         if (btheme->tseq.mask[3] == 0) {
2257                                 rgba_char_args_set(btheme->tseq.mask,  152, 78, 62, 255);
2258                         }
2259                 }
2260         }
2261
2262         if (!USER_VERSION_ATLEAST(263, 15)) {
2263                 bTheme *btheme;
2264                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2265                         rgba_char_args_set(btheme->tv3d.bone_pose_active, 140, 255, 255, 80);
2266                 }
2267         }
2268
2269         if (!USER_VERSION_ATLEAST(263, 16)) {
2270                 bTheme *btheme;
2271
2272                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2273                         if (btheme->tact.anim_active[3] == 0)
2274                                 rgba_char_args_set(btheme->tact.anim_active, 204, 112, 26, 102);
2275
2276                         if (btheme->tnla.anim_active[3] == 0)
2277                                 rgba_char_args_set(btheme->tnla.anim_active, 204, 112, 26, 102);
2278                 }
2279         }
2280
2281         if (!USER_VERSION_ATLEAST(263, 22)) {
2282                 bTheme *btheme;
2283
2284                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2285                         if (btheme->tipo.lastsel_point[3] == 0)
2286                                 rgba_char_args_set(btheme->tipo.lastsel_point, 0xff, 0xff, 0xff, 255);
2287
2288                         if (btheme->tv3d.skin_root[3] == 0)
2289                                 rgba_char_args_set(btheme->tv3d.skin_root, 180, 77, 77, 255);
2290                 }
2291         }
2292         
2293         if (!USER_VERSION_ATLEAST(264, 9)) {
2294                 bTheme *btheme;
2295                 
2296                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2297                         rgba_char_args_set(btheme->tui.xaxis, 220,   0,   0, 255);
2298                         rgba_char_args_set(btheme->tui.yaxis,   0, 220,   0, 255);
2299                         rgba_char_args_set(btheme->tui.zaxis,   0,   0, 220, 255);
2300                 }
2301         }
2302
2303         if (!USER_VERSION_ATLEAST(267, 0)) {
2304                 /* Freestyle color settings */
2305                 bTheme *btheme;
2306
2307                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2308                         /* check for alpha == 0 is safe, then color was never set */
2309                         if (btheme->tv3d.freestyle_edge_mark[3] == 0) {
2310                                 rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
2311                                 rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
2312                         }
2313
2314                         if (btheme->tv3d.wire_edit[3] == 0) {
2315                                 rgba_char_args_set(btheme->tv3d.wire_edit,  0x0, 0x0, 0x0, 255);
2316                         }
2317                 }
2318
2319                 /* GL Texture Garbage Collection */
2320                 if (U.textimeout == 0) {
2321                         U.texcollectrate = 60;
2322                         U.textimeout = 120;
2323                 }
2324                 if (U.memcachelimit <= 0) {
2325                         U.memcachelimit = 32;
2326                 }
2327                 if (U.frameserverport == 0) {
2328                         U.frameserverport = 8080;
2329                 }
2330                 if (U.dbl_click_time == 0) {
2331                         U.dbl_click_time = 350;
2332                 }
2333                 if (U.scrcastfps == 0) {
2334                         U.scrcastfps = 10;
2335                         U.scrcastwait = 50;
2336                 }
2337                 if (U.v2d_min_gridsize == 0) {
2338                         U.v2d_min_gridsize = 35;
2339                 }
2340                 if (U.dragthreshold == 0)
2341                         U.dragthreshold = 5;
2342                 if (U.widget_unit == 0)
2343                         U.widget_unit = 20;
2344                 if (U.anisotropic_filter <= 0)
2345                         U.anisotropic_filter = 1;
2346
2347                 if (U.ndof_sensitivity == 0.0f) {
2348                         U.ndof_sensitivity = 1.0f;
2349                         U.ndof_flag = (NDOF_LOCK_HORIZON | NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE);
2350                 }
2351                 
2352                 if (U.ndof_orbit_sensitivity == 0.0f) {
2353                         U.ndof_orbit_sensitivity = U.ndof_sensitivity;
2354
2355                         if (!(U.flag & USER_TRACKBALL))
2356                                 U.ndof_flag |= NDOF_TURNTABLE;
2357                 }
2358                 if (U.tweak_threshold == 0)
2359                         U.tweak_threshold = 10;
2360         }
2361
2362         if (!USER_VERSION_ATLEAST(265, 1)) {
2363                 bTheme *btheme;
2364                 
2365                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2366                         /* note: the toggle operator for transparent backdrops limits to these spacetypes */
2367                         if (btheme->tnode.button[3] == 255) {
2368                                 btheme->tv3d.button[3] = 128;
2369                                 btheme->tnode.button[3] = 128;
2370                                 btheme->tima.button[3] = 128;
2371                                 btheme->tseq.button[3] = 128;
2372                                 btheme->tclip.button[3] = 128;
2373                         }
2374                 }
2375         }
2376         
2377         /* panel header/backdrop supported locally per editor now */
2378         if (!USER_VERSION_ATLEAST(265, 2)) {
2379                 bTheme *btheme;
2380                 
2381                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2382                         ThemeSpace *ts;
2383                         
2384                         /* new color, panel backdrop. Not used anywhere yet, until you enable it */
2385                         copy_v3_v3_char(btheme->tui.panel.back, btheme->tbuts.button);
2386                         btheme->tui.panel.back[3] = 128;
2387                         
2388                         for (ts = UI_THEMESPACE_START(btheme); ts != UI_THEMESPACE_END(btheme); ts++) {
2389                                 ts->panelcolors = btheme->tui.panel;
2390                         }
2391                 }
2392         }
2393
2394         /* NOTE!! from now on use U.versionfile and U.subversionfile */
2395 #undef USER_VERSION_ATLEAST
2396 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST((&(U)), ver, subver)
2397
2398         if (!USER_VERSION_ATLEAST(266, 0)) {
2399                 bTheme *btheme;
2400                 
2401                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2402                         /* rna definition limits fac to 0.01 */
2403                         if (btheme->tui.menu_shadow_fac == 0.0f) {
2404                                 btheme->tui.menu_shadow_fac = 0.5f;
2405                                 btheme->tui.menu_shadow_width = 12;
2406                         }
2407                 }
2408         }
2409
2410         if (!USER_VERSION_ATLEAST(265, 4)) {
2411                 bTheme *btheme;
2412                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2413                         rgba_char_args_set(btheme->text.syntaxd,    50, 0, 140, 255);   /* Decorator/Preprocessor Dir.  Blue-purple */
2414                         rgba_char_args_set(btheme->text.syntaxr,    140, 60, 0, 255);   /* Reserved  Orange */
2415                         rgba_char_args_set(btheme->text.syntaxs,    76, 76, 76, 255);   /* Gray (mix between fg/bg) */
2416                 }
2417         }
2418
2419         if (!USER_VERSION_ATLEAST(265, 6)) {
2420                 bTheme *btheme;
2421                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2422                         copy_v4_v4_char(btheme->tv3d.gradients.high_gradient, btheme->tv3d.back);
2423                 }
2424         }
2425
2426         if (!USER_VERSION_ATLEAST(265, 9)) {
2427                 bTheme *btheme;
2428                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2429                         rgba_char_args_test_set(btheme->tnode.syntaxs, 151, 116, 116, 255);  /* matte nodes */
2430                         rgba_char_args_test_set(btheme->tnode.syntaxd, 116, 151, 151, 255);  /* distort nodes */
2431                 }
2432         }
2433
2434         if (!USER_VERSION_ATLEAST(265, 11)) {
2435                 bTheme *btheme;
2436                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2437                         rgba_char_args_test_set(btheme->tconsole.console_select, 255, 255, 255, 48);
2438                 }
2439         }
2440
2441         if (!USER_VERSION_ATLEAST(266, 2)) {
2442                 bTheme *btheme;
2443                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2444                         rgba_char_args_test_set(btheme->tnode.console_output, 223, 202, 53, 255);  /* interface nodes */
2445                 }
2446         }
2447
2448         if (!USER_VERSION_ATLEAST(268, 3)) {
2449                 bTheme *btheme;
2450                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2451                         rgba_char_args_test_set(btheme->tima.uv_others, 96, 96, 96, 255);
2452                         rgba_char_args_test_set(btheme->tima.uv_shadow, 112, 112, 112, 255);
2453                 }
2454         }
2455
2456         if (!USER_VERSION_ATLEAST(269, 5)) {
2457                 bTheme *btheme;
2458                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2459                         rgba_char_args_set(btheme->tima.wire_edit, 192, 192, 192, 255);
2460                         rgba_char_args_set(btheme->tima.edge_select, 255, 133, 0, 255);
2461                 }
2462         }
2463
2464         if (!USER_VERSION_ATLEAST(269, 6)) {
2465                 bTheme *btheme;
2466                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2467                         char r, g, b;
2468                         r = btheme->tnode.syntaxn[0];
2469                         g = btheme->tnode.syntaxn[1];
2470                         b = btheme->tnode.syntaxn[2];
2471                         rgba_char_args_test_set(btheme->tnode.nodeclass_output, r, g, b, 255);
2472                         r = btheme->tnode.syntaxb[0];
2473                         g = btheme->tnode.syntaxb[1];
2474                         b = btheme->tnode.syntaxb[2];
2475                         rgba_char_args_test_set(btheme->tnode.nodeclass_filter, r, g, b, 255);
2476                         rgba_char_args_test_set(btheme->tnode.nodeclass_vector, r, g, b, 255);
2477                         rgba_char_args_test_set(btheme->tnode.nodeclass_texture, r, g, b, 255);
2478                         rgba_char_args_test_set(btheme->tnode.nodeclass_shader, r, g, b, 255);
2479                         rgba_char_args_test_set(btheme->tnode.nodeclass_script, r, g, b, 255);
2480                         rgba_char_args_test_set(btheme->tnode.nodeclass_pattern, r, g, b, 255);
2481                         rgba_char_args_test_set(btheme->tnode.nodeclass_layout, r, g, b, 255);
2482                 }
2483         }
2484
2485         if (!USER_VERSION_ATLEAST(269, 8)) {
2486                 bTheme *btheme;
2487                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2488                         rgba_char_args_test_set(btheme->tinfo.info_selected, 96, 128, 255, 255);
2489                         rgba_char_args_test_set(btheme->tinfo.info_selected_text, 255, 255, 255, 255);
2490                         rgba_char_args_test_set(btheme->tinfo.info_error, 220, 0, 0, 255);
2491                         rgba_char_args_test_set(btheme->tinfo.info_error_text, 0, 0, 0, 255);
2492                         rgba_char_args_test_set(btheme->tinfo.info_warning, 220, 128, 96, 255);
2493                         rgba_char_args_test_set(btheme->tinfo.info_warning_text, 0, 0, 0, 255);
2494                         rgba_char_args_test_set(btheme->tinfo.info_info, 0, 170, 0, 255);
2495                         rgba_char_args_test_set(btheme->tinfo.info_info_text, 0, 0, 0, 255);
2496                         rgba_char_args_test_set(btheme->tinfo.info_debug, 196, 196, 196, 255);
2497                         rgba_char_args_test_set(btheme->tinfo.info_debug_text, 0, 0, 0, 255);
2498                 }
2499         }
2500         
2501         if (!USER_VERSION_ATLEAST(269, 9)) {
2502                 bTheme *btheme;
2503                 
2504                 U.tw_size = U.tw_size * 5.0f;
2505                 
2506                 /* Action Editor (and NLA Editor) - Keyframe Colors */
2507                 /* Graph Editor - larger vertex size defaults */
2508                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2509                         /* Action Editor ................. */
2510                         /* key types */
2511                         rgba_char_args_set(btheme->tact.keytype_keyframe,           232, 232, 232, 255);
2512                         rgba_char_args_set(btheme->tact.keytype_keyframe_select,    255, 190,  50, 255);
2513                         rgba_char_args_set(btheme->tact.keytype_extreme,            232, 179, 204, 255);
2514                         rgba_char_args_set(btheme->tact.keytype_extreme_select,     242, 128, 128, 255);
2515                         rgba_char_args_set(btheme->tact.keytype_breakdown,          179, 219, 232, 255);
2516                         rgba_char_args_set(btheme->tact.keytype_breakdown_select,    84, 191, 237, 255);
2517                         rgba_char_args_set(btheme->tact.keytype_jitter,             148, 229, 117, 255);
2518                         rgba_char_args_set(btheme->tact.keytype_jitter_select,       97, 192,  66, 255);
2519                         
2520                         /* key border */
2521                         rgba_char_args_set(btheme->tact.keyborder,               0,   0,   0, 255);
2522                         rgba_char_args_set(btheme->tact.keyborder_select,        0,   0,   0, 255);
2523                         
2524                         /* NLA ............................ */
2525                         /* key border */
2526                         rgba_char_args_set(btheme->tnla.keyborder,               0,   0,   0, 255);
2527                         rgba_char_args_set(btheme->tnla.keyborder_select,        0,   0,   0, 255);
2528                         
2529                         /* Graph Editor ................... */
2530                         btheme->tipo.vertex_size = 6;
2531                         btheme->tipo.handle_vertex_size = 5;
2532                 }
2533                 
2534                 /* grease pencil - new layer color */
2535                 if (U.gpencil_new_layer_col[3] < 0.1f) {
2536                         /* defaults to black, but must at least be visible! */
2537                         U.gpencil_new_layer_col[3] = 0.9f;
2538                 }
2539         }
2540
2541         if (!USER_VERSION_ATLEAST(269, 10)) {
2542                 bTheme *btheme;
2543                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2544                         ThemeSpace *ts;
2545
2546                         for (ts = UI_THEMESPACE_START(btheme); ts != UI_THEMESPACE_END(btheme); ts++) {
2547                                 rgba_char_args_set(ts->tab_active, 114, 114, 114, 255);
2548                                 rgba_char_args_set(ts->tab_inactive, 83, 83, 83, 255);
2549                                 rgba_char_args_set(ts->tab_back, 64, 64, 64, 255);
2550                                 rgba_char_args_set(ts->tab_outline, 60, 60, 60, 255);
2551                         }
2552                 }
2553         }
2554
2555         if (!USER_VERSION_ATLEAST(271, 0)) {
2556                 bTheme *btheme;
2557                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2558                         rgba_char_args_set(btheme->tui.wcol_tooltip.text, 255, 255, 255, 255);
2559                 }
2560         }
2561
2562         if (!USER_VERSION_ATLEAST(272, 2)) {
2563                 bTheme *btheme;
2564                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2565                         rgba_char_args_set_fl(btheme->tv3d.paint_curve_handle, 0.5f, 1.0f, 0.5f, 0.5f);
2566                         rgba_char_args_set_fl(btheme->tv3d.paint_curve_pivot, 1.0f, 0.5f, 0.5f, 0.5f);
2567                         rgba_char_args_set_fl(btheme->tima.paint_curve_handle, 0.5f, 1.0f, 0.5f, 0.5f);
2568                         rgba_char_args_set_fl(btheme->tima.paint_curve_pivot, 1.0f, 0.5f, 0.5f, 0.5f);
2569                         rgba_char_args_set(btheme->tnode.syntaxr, 115, 115, 115, 255);
2570                 }
2571         }
2572
2573         if (!USER_VERSION_ATLEAST(271, 5)) {
2574                 bTheme *btheme;
2575
2576                 struct uiWidgetColors wcol_pie_menu = {
2577                         {10, 10, 10, 200},
2578                         {25, 25, 25, 230},
2579                         {140, 140, 140, 255},
2580                         {45, 45, 45, 230},
2581
2582                         {160, 160, 160, 255},
2583                         {255, 255, 255, 255},
2584
2585                         1,
2586                         10, -10
2587                 };
2588
2589                 U.pie_menu_radius = 100;
2590                 U.pie_menu_threshold = 12;
2591                 U.pie_animation_timeout = 6;
2592
2593                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2594                         btheme->tui.wcol_pie_menu = wcol_pie_menu;
2595
2596                         ui_theme_space_init_handles_color(&btheme->tclip);
2597                         ui_theme_space_init_handles_color(&btheme->tima);
2598                         btheme->tima.handle_vertex_size = 5;
2599                         btheme->tclip.handle_vertex_size = 5;
2600                 }
2601         }
2602
2603         if (!USER_VERSION_ATLEAST(271, 6)) {
2604                 bTheme *btheme;
2605                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2606                         /* check for (alpha == 0) is safe, then color was never set */
2607                         if (btheme->tv3d.loop_normal[3] == 0) {
2608                                 rgba_char_args_set(btheme->tv3d.loop_normal, 0xDD, 0x23, 0xDD, 255);
2609                         }
2610                 }
2611         }
2612
2613         if (!USER_VERSION_ATLEAST(272, 3)) {
2614                 bTheme *btheme;
2615                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2616                         rgba_char_args_set_fl(btheme->tui.widget_emboss, 1.0f, 1.0f, 1.0f, 0.02f);
2617                 }
2618         }
2619         
2620         if (!USER_VERSION_ATLEAST(273, 1)) {
2621                 bTheme *btheme;
2622                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2623                         /* Grease Pencil vertex settings */
2624                         rgba_char_args_set(btheme->tv3d.gp_vertex, 0, 0, 0, 255);
2625                         rgba_char_args_set(btheme->tv3d.gp_vertex_select, 255, 133, 0, 255);
2626                         btheme->tv3d.gp_vertex_size = 3;
2627                         
2628                         rgba_char_args_set(btheme->tseq.gp_vertex, 0, 0, 0, 255);
2629                         rgba_char_args_set(btheme->tseq.gp_vertex_select, 255, 133, 0, 255);
2630                         btheme->tseq.gp_vertex_size = 3;
2631                         
2632                         rgba_char_args_set(btheme->tima.gp_vertex, 0, 0, 0, 255);
2633                         rgba_char_args_set(btheme->tima.gp_vertex_select, 255, 133, 0, 255);
2634                         btheme->tima.gp_vertex_size = 3;
2635                         
2636                         rgba_char_args_set(btheme->tnode.gp_vertex, 0, 0, 0, 255);
2637                         rgba_char_args_set(btheme->tnode.gp_vertex_select, 255, 133, 0, 255);
2638                         btheme->tnode.gp_vertex_size = 3;
2639                         
2640                         /* Timeline Keyframe Indicators */
2641                         rgba_char_args_set(btheme->ttime.time_keyframe, 0xDD, 0xD7, 0x00, 0xFF);
2642                         rgba_char_args_set(btheme->ttime.time_gp_keyframe, 0xB5, 0xE6, 0x1D, 0xFF);
2643                 }
2644         }
2645
2646         if (!USER_VERSION_ATLEAST(273, 5)) {
2647                 bTheme *btheme;
2648                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2649                         unsigned char *cp = (unsigned char *)btheme->tv3d.clipping_border_3d;
2650                         int c;
2651                         copy_v4_v4_char((char *)cp, btheme->tv3d.back);
2652                         c = cp[0] - 8;
2653                         CLAMP(c, 0, 255);
2654                         cp[0] = c;
2655                         c = cp[1] - 8;
2656                         CLAMP(c, 0, 255);
2657                         cp[1] = c;
2658                         c = cp[2] - 8;
2659                         CLAMP(c, 0, 255);
2660                         cp[2] = c;
2661                         cp[3] = 255;
2662                 }
2663         }
2664
2665         if (!USER_VERSION_ATLEAST(274, 5)) {
2666                 bTheme *btheme;
2667                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2668                         copy_v4_v4_char(btheme->tima.metadatatext, btheme->tima.text_hi);
2669                         copy_v4_v4_char(btheme->tseq.metadatatext, btheme->tseq.text_hi);
2670                 }
2671         }
2672
2673         if (!USER_VERSION_ATLEAST(275, 1)) {
2674                 bTheme *btheme;
2675                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2676                         copy_v4_v4_char(btheme->tclip.metadatatext, btheme->tseq.text_hi);
2677                 }
2678         }
2679
2680         if (!USER_VERSION_ATLEAST(275, 2)) {
2681                 U.ndof_deadzone = 0.1;
2682         }
2683
2684         if (!USER_VERSION_ATLEAST(275, 4)) {
2685                 U.node_margin = 80;
2686         }
2687
2688         if (!USER_VERSION_ATLEAST(276, 1)) {
2689                 bTheme *btheme;
2690                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2691                         rgba_char_args_set_fl(btheme->tima.preview_back, 0.0f, 0.0f, 0.0f, 0.3f);
2692                 }
2693         }
2694
2695         if (!USER_VERSION_ATLEAST(276, 2)) {
2696                 bTheme *btheme;
2697                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2698                         rgba_char_args_set(btheme->tclip.gp_vertex, 0, 0, 0, 255);
2699                         rgba_char_args_set(btheme->tclip.gp_vertex_select, 255, 133, 0, 255);
2700                         btheme->tclip.gp_vertex_size = 3;
2701                 }
2702         }
2703
2704         if (!USER_VERSION_ATLEAST(276, 3)) {
2705                 bTheme *btheme;
2706                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2707                         rgba_char_args_set(btheme->tseq.text_strip, 162, 151, 0, 255);
2708                 }
2709         }
2710
2711         if (!USER_VERSION_ATLEAST(276, 8)) {
2712                 bTheme *btheme;
2713                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2714                         rgba_char_args_set(btheme->tui.wcol_progress.item, 128, 128, 128, 255);
2715                 }
2716         }
2717
2718         if (!USER_VERSION_ATLEAST(276, 10)) {
2719                 bTheme *btheme;
2720                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2721                         /* 3dView Keyframe Indicators */
2722                         rgba_char_args_set(btheme->tv3d.time_keyframe, 0xDD, 0xD7, 0x00, 0xFF);
2723                         rgba_char_args_set(btheme->tv3d.time_gp_keyframe, 0xB5, 0xE6, 0x1D, 0xFF);
2724                 }
2725         }
2726
2727         if (!USER_VERSION_ATLEAST(277, 0)) {
2728                 bTheme *btheme;
2729                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2730                         if (memcmp(btheme->tui.wcol_list_item.item, btheme->tui.wcol_list_item.text_sel, sizeof(char) * 3) == 0) {
2731                                 copy_v4_v4_char(btheme->tui.wcol_list_item.item, btheme->tui.wcol_text.item);
2732                                 copy_v4_v4_char(btheme->tui.wcol_list_item.text_sel, btheme->tui.wcol_text.text_sel);
2733                         }
2734                 }
2735         }
2736         
2737         if (!USER_VERSION_ATLEAST(277, 2)) {
2738                 bTheme *btheme;
2739                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2740                         if (btheme->tact.keyframe_scale_fac < 0.1f)
2741                                 btheme->tact.keyframe_scale_fac = 1.0f;
2742                 }
2743         }
2744
2745         if (!USER_VERSION_ATLEAST(278, 2)) {
2746                 bTheme *btheme;
2747                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
2748                         rgba_char_args_set(btheme->tv3d.vertex_bevel, 0, 165, 255, 255);
2749                         rgba_char_args_set(btheme->tv3d.edge_bevel, 0, 165, 255, 255);
2750                 }
2751         }
2752
2753         if (!USER_VERSION_ATLEAST(278, 3)) {
2754                 for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) {
2755                         /* Keyframe Indicators (were using wrong alpha) */
2756                         btheme->tv3d.time_keyframe[3] = btheme->tv3d.time_gp_keyframe[3] = 255;
2757                         btheme->ttime.time_keyframe[3] = btheme->ttime.time_gp_keyframe[3] = 255;
2758                 }
2759         }
2760
2761         if (!USER_VERSION_ATLEAST(278, 6)) {
2762                 /* Clear preference flags for re-use. */
2763                 U.flag &= ~(
2764                     USER_FLAG_DEPRECATED_1 | USER_FLAG_DEPRECATED_2 | USER_FLAG_DEPRECATED_3 |
2765                     USER_FLAG_DEPRECATED_6 | USER_FLAG_DEPRECATED_7 |
2766                     USER_FLAG_DEPRECATED_9 | USER_FLAG_DEPRECATED_10);
2767                 U.uiflag &= ~(
2768                     USER_UIFLAG_DEPRECATED_7)