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