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