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