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