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