Merged changes in the trunk up to revision 47056.
[blender-staging.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_userdef_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_space_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_DerivedMesh.h"
49 #include "BKE_global.h"
50 #include "BKE_main.h"
51 #include "BKE_texture.h"
52
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 static bTheme *theme_active = NULL;
65 static int theme_spacetype = SPACE_VIEW3D;
66 static int theme_regionid = RGN_TYPE_WINDOW;
67
68 void ui_resources_init(void)
69 {
70         UI_icons_init(BIFICONID_LAST);
71 }
72
73 void ui_resources_free(void)
74 {
75         UI_icons_free();
76 }
77
78
79 /* ******************************************************** */
80 /*    THEMES */
81 /* ******************************************************** */
82
83 const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
84 {
85         ThemeSpace *ts = NULL;
86         static char error[4] = {240, 0, 240, 255};
87         static char alert[4] = {240, 60, 60, 255};
88         static char headerdesel[4] = {0, 0, 0, 255};
89         
90         const char *cp = error;
91         
92         if (btheme) {
93         
94                 // first check for ui buttons theme
95                 if (colorid < TH_THEMEUI) {
96                 
97                         switch (colorid) {
98
99                                 case TH_REDALERT:
100                                         cp = alert; break;
101                         }
102                 }
103                 else {
104                 
105                         switch (spacetype) {
106                                 case SPACE_BUTS:
107                                         ts = &btheme->tbuts;
108                                         break;
109                                 case SPACE_VIEW3D:
110                                         ts = &btheme->tv3d;
111                                         break;
112                                 case SPACE_IPO:
113                                         ts = &btheme->tipo;
114                                         break;
115                                 case SPACE_FILE:
116                                         ts = &btheme->tfile;
117                                         break;
118                                 case SPACE_NLA:
119                                         ts = &btheme->tnla;
120                                         break;
121                                 case SPACE_ACTION:
122                                         ts = &btheme->tact;
123                                         break;
124                                 case SPACE_SEQ:
125                                         ts = &btheme->tseq;
126                                         break;
127                                 case SPACE_IMAGE:
128                                         ts = &btheme->tima;
129                                         break;
130                                 case SPACE_TEXT:
131                                         ts = &btheme->text;
132                                         break;
133                                 case SPACE_OUTLINER:
134                                         ts = &btheme->toops;
135                                         break;
136                                 case SPACE_INFO:
137                                         ts = &btheme->tinfo;
138                                         break;
139                                 case SPACE_USERPREF:
140                                         ts = &btheme->tuserpref;
141                                         break;
142                                 case SPACE_CONSOLE:
143                                         ts = &btheme->tconsole;
144                                         break;
145                                 case SPACE_TIME:
146                                         ts = &btheme->ttime;
147                                         break;
148                                 case SPACE_NODE:
149                                         ts = &btheme->tnode;
150                                         break;
151                                 case SPACE_LOGIC:
152                                         ts = &btheme->tlogic;
153                                         break;
154                                 case SPACE_CLIP:
155                                         ts = &btheme->tclip;
156                                         break;
157                                 default:
158                                         ts = &btheme->tv3d;
159                                         break;
160                         }
161
162                         switch (colorid) {
163                                 case TH_BACK:
164                                         if (theme_regionid == RGN_TYPE_WINDOW)
165                                                 cp = ts->back;
166                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
167                                                 cp = ts->list;
168                                         else if (theme_regionid == RGN_TYPE_HEADER)
169                                                 cp = ts->header;
170                                         else
171                                                 cp = ts->button;
172                                         break;
173                                 case TH_TEXT:
174                                         if (theme_regionid == RGN_TYPE_WINDOW)
175                                                 cp = ts->text;
176                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
177                                                 cp = ts->list_text;
178                                         else if (theme_regionid == RGN_TYPE_HEADER)
179                                                 cp = ts->header_text;
180                                         else
181                                                 cp = ts->button_text;
182                                         break;
183                                 case TH_TEXT_HI:
184                                         if (theme_regionid == RGN_TYPE_WINDOW)
185                                                 cp = ts->text_hi;
186                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
187                                                 cp = ts->list_text_hi;
188                                         else if (theme_regionid == RGN_TYPE_HEADER)
189                                                 cp = ts->header_text_hi;
190                                         else
191                                                 cp = ts->button_text_hi;
192                                         break;
193                                 case TH_TITLE:
194                                         if (theme_regionid == RGN_TYPE_WINDOW)
195                                                 cp = ts->title;
196                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
197                                                 cp = ts->list_title;
198                                         else if (theme_regionid == RGN_TYPE_HEADER)
199                                                 cp = ts->header_title;
200                                         else
201                                                 cp = ts->button_title;
202                                         break;
203
204                                 case TH_HEADER:
205                                         cp = ts->header; break;
206                                 case TH_HEADERDESEL:
207                                         /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
208                                         cp = ts->header;
209                                         headerdesel[0] = cp[0] > 10 ? cp[0] - 10 : 0;
210                                         headerdesel[1] = cp[1] > 10 ? cp[1] - 10 : 0;
211                                         headerdesel[2] = cp[2] > 10 ? cp[2] - 10 : 0;
212                                         cp = headerdesel;
213                                         break;
214                                 case TH_HEADER_TEXT:
215                                         cp = ts->header_text; break;
216                                 case TH_HEADER_TEXT_HI:
217                                         cp = ts->header_text_hi; break;
218
219                                 case TH_PANEL:
220                                         cp = ts->panel; break;
221                                 case TH_PANEL_TEXT:
222                                         cp = ts->panel_text; break;
223                                 case TH_PANEL_TEXT_HI:
224                                         cp = ts->panel_text_hi; break;
225
226                                 case TH_BUTBACK:
227                                         cp = ts->button; break;
228                                 case TH_BUTBACK_TEXT:
229                                         cp = ts->button_text; break;
230                                 case TH_BUTBACK_TEXT_HI:
231                                         cp = ts->button_text_hi; break;
232
233                                 case TH_SHADE1:
234                                         cp = ts->shade1; break;
235                                 case TH_SHADE2:
236                                         cp = ts->shade2; break;
237                                 case TH_HILITE:
238                                         cp = ts->hilite; break;
239
240                                 case TH_GRID:
241                                         cp = ts->grid; break;
242                                 case TH_WIRE:
243                                         cp = ts->wire; break;
244                                 case TH_LAMP:
245                                         cp = ts->lamp; break;
246                                 case TH_SPEAKER:
247                                         cp = ts->speaker; break;
248                                 case TH_CAMERA:
249                                         cp = ts->camera; break;
250                                 case TH_EMPTY:
251                                         cp = ts->empty; break;
252                                 case TH_SELECT:
253                                         cp = ts->select; break;
254                                 case TH_ACTIVE:
255                                         cp = ts->active; break;
256                                 case TH_GROUP:
257                                         cp = ts->group; break;
258                                 case TH_GROUP_ACTIVE:
259                                         cp = ts->group_active; break;
260                                 case TH_TRANSFORM:
261                                         cp = ts->transform; break;
262                                 case TH_VERTEX:
263                                         cp = ts->vertex; break;
264                                 case TH_VERTEX_SELECT:
265                                         cp = ts->vertex_select; break;
266                                 case TH_VERTEX_SIZE:
267                                         cp = &ts->vertex_size; break;
268                                 case TH_OUTLINE_WIDTH:
269                                         cp = &ts->outline_width; break;
270                                 case TH_EDGE:
271                                         cp = ts->edge; break;
272                                 case TH_EDGE_SELECT:
273                                         cp = ts->edge_select; break;
274                                 case TH_EDGE_SEAM:
275                                         cp = ts->edge_seam; break;
276                                 case TH_EDGE_SHARP:
277                                         cp = ts->edge_sharp; break;
278                                 case TH_EDGE_CREASE:
279                                         cp = ts->edge_crease; break;
280                                 case TH_EDITMESH_ACTIVE:
281                                         cp = ts->editmesh_active; break;
282                                 case TH_EDGE_FACESEL:
283                                         cp = ts->edge_facesel; break;
284                                 case TH_FACE:
285                                         cp = ts->face; break;
286                                 case TH_FACE_SELECT:
287                                         cp = ts->face_select; break;
288                                 case TH_FACE_DOT:
289                                         cp = ts->face_dot; break;
290                                 case TH_FACEDOT_SIZE:
291                                         cp = &ts->facedot_size; break;
292                                 case TH_DRAWEXTRA_EDGELEN:
293                                         cp = ts->extra_edge_len; break;
294                                 case TH_DRAWEXTRA_FACEAREA:
295                                         cp = ts->extra_face_area; break;
296                                 case TH_DRAWEXTRA_FACEANG:
297                                         cp = ts->extra_face_angle; break;
298                                 case TH_NORMAL:
299                                         cp = ts->normal; break;
300                                 case TH_VNORMAL:
301                                         cp = ts->vertex_normal; break;
302                                 case TH_BONE_SOLID:
303                                         cp = ts->bone_solid; break;
304                                 case TH_BONE_POSE:
305                                         cp = ts->bone_pose; break;
306                                 case TH_STRIP:
307                                         cp = ts->strip; break;
308                                 case TH_STRIP_SELECT:
309                                         cp = ts->strip_select; break;
310                                 case TH_CFRAME:
311                                         cp = ts->cframe; break;
312                                 case TH_NURB_ULINE:
313                                         cp = ts->nurb_uline; break;
314                                 case TH_NURB_VLINE:
315                                         cp = ts->nurb_vline; break;
316                                 case TH_NURB_SEL_ULINE:
317                                         cp = ts->nurb_sel_uline; break;
318                                 case TH_NURB_SEL_VLINE:
319                                         cp = ts->nurb_sel_vline; break;
320                                 case TH_ACTIVE_SPLINE:
321                                         cp = ts->act_spline; break;
322                                 case TH_LASTSEL_POINT:
323                                         cp = ts->lastsel_point; break;
324                                 case TH_HANDLE_FREE:
325                                         cp = ts->handle_free; break;
326                                 case TH_HANDLE_AUTO:
327                                         cp = ts->handle_auto; break;
328                                 case TH_HANDLE_AUTOCLAMP:
329                                         cp = ts->handle_auto_clamped; break;
330                                 case TH_HANDLE_VECT:
331                                         cp = ts->handle_vect; break;
332                                 case TH_HANDLE_ALIGN:
333                                         cp = ts->handle_align; break;
334                                 case TH_HANDLE_SEL_FREE:
335                                         cp = ts->handle_sel_free; break;
336                                 case TH_HANDLE_SEL_AUTO:
337                                         cp = ts->handle_sel_auto; break;
338                                 case TH_HANDLE_SEL_AUTOCLAMP:
339                                         cp = ts->handle_sel_auto_clamped; break;
340                                 case TH_HANDLE_SEL_VECT:
341                                         cp = ts->handle_sel_vect; break;
342                                 case TH_HANDLE_SEL_ALIGN:
343                                         cp = ts->handle_sel_align; break;
344                                 case TH_FREESTYLE_EDGE_MARK:
345                                         cp = ts->freestyle_edge_mark; break;
346                                 case TH_FREESTYLE_FACE_MARK:
347                                         cp = ts->freestyle_face_mark; break;
348
349                                 case TH_SYNTAX_B:
350                                         cp = ts->syntaxb; break;
351                                 case TH_SYNTAX_V:
352                                         cp = ts->syntaxv; break;
353                                 case TH_SYNTAX_C:
354                                         cp = ts->syntaxc; break;
355                                 case TH_SYNTAX_L:
356                                         cp = ts->syntaxl; break;
357                                 case TH_SYNTAX_N:
358                                         cp = ts->syntaxn; break;
359
360                                 case TH_NODE:
361                                         cp = ts->syntaxl; break;
362                                 case TH_NODE_IN_OUT:
363                                         cp = ts->syntaxn; break;
364                                 case TH_NODE_OPERATOR:
365                                         cp = ts->syntaxb; break;
366                                 case TH_NODE_CONVERTOR:
367                                         cp = ts->syntaxv; break;
368                                 case TH_NODE_GROUP:
369                                         cp = ts->syntaxc; break;
370                                 case TH_NODE_CURVING:
371                                         cp = &ts->noodle_curving; break;
372
373                                 case TH_SEQ_MOVIE:
374                                         cp = ts->movie; break;
375                                 case TH_SEQ_MOVIECLIP:
376                                         cp = ts->movieclip; break;
377                                 case TH_SEQ_IMAGE:
378                                         cp = ts->image; break;
379                                 case TH_SEQ_SCENE:
380                                         cp = ts->scene; break;
381                                 case TH_SEQ_AUDIO:
382                                         cp = ts->audio; break;
383                                 case TH_SEQ_EFFECT:
384                                         cp = ts->effect; break;
385                                 case TH_SEQ_PLUGIN:
386                                         cp = ts->plugin; break;
387                                 case TH_SEQ_TRANSITION:
388                                         cp = ts->transition; break;
389                                 case TH_SEQ_META:
390                                         cp = ts->meta; break;
391                                 case TH_SEQ_PREVIEW:
392                                         cp = ts->preview_back; break;
393
394                                 case TH_CONSOLE_OUTPUT:
395                                         cp = ts->console_output; break;
396                                 case TH_CONSOLE_INPUT:
397                                         cp = ts->console_input; break;
398                                 case TH_CONSOLE_INFO:
399                                         cp = ts->console_info; break;
400                                 case TH_CONSOLE_ERROR:
401                                         cp = ts->console_error; break;
402                                 case TH_CONSOLE_CURSOR:
403                                         cp = ts->console_cursor; break;
404
405                                 case TH_HANDLE_VERTEX:
406                                         cp = ts->handle_vertex;
407                                         break;
408                                 case TH_HANDLE_VERTEX_SELECT:
409                                         cp = ts->handle_vertex_select;
410                                         break;
411                                 case TH_HANDLE_VERTEX_SIZE:
412                                         cp = &ts->handle_vertex_size;
413                                         break;
414
415                                 case TH_DOPESHEET_CHANNELOB:
416                                         cp = ts->ds_channel;
417                                         break;
418                                 case TH_DOPESHEET_CHANNELSUBOB:
419                                         cp = ts->ds_subchannel;
420                                         break;
421
422                                 case TH_PREVIEW_BACK:
423                                         cp = ts->preview_back;
424                                         break;
425
426                                 case TH_STITCH_PREVIEW_FACE:
427                                         cp = ts->preview_stitch_face;
428                                         break;
429
430                                 case TH_STITCH_PREVIEW_EDGE:
431                                         cp = ts->preview_stitch_edge;
432                                         break;
433
434                                 case TH_STITCH_PREVIEW_VERT:
435                                         cp = ts->preview_stitch_vert;
436                                         break;
437
438                                 case TH_STITCH_PREVIEW_STITCHABLE:
439                                         cp = ts->preview_stitch_stitchable;
440                                         break;
441
442                                 case TH_STITCH_PREVIEW_UNSTITCHABLE:
443                                         cp = ts->preview_stitch_unstitchable;
444                                         break;
445                                 case TH_STITCH_PREVIEW_ACTIVE:
446                                         cp = ts->preview_stitch_active;
447                                         break;
448                                 case TH_MARKER_OUTLINE:
449                                         cp = ts->marker_outline; break;
450                                 case TH_MARKER:
451                                         cp = ts->marker; break;
452                                 case TH_ACT_MARKER:
453                                         cp = ts->act_marker; break;
454                                 case TH_SEL_MARKER:
455                                         cp = ts->sel_marker; break;
456                                 case TH_BUNDLE_SOLID:
457                                         cp = ts->bundle_solid; break;
458                                 case TH_DIS_MARKER:
459                                         cp = ts->dis_marker; break;
460                                 case TH_PATH_BEFORE:
461                                         cp = ts->path_before; break;
462                                 case TH_PATH_AFTER:
463                                         cp = ts->path_after; break;
464                                 case TH_CAMERA_PATH:
465                                         cp = ts->camera_path; break;
466                                 case TH_LOCK_MARKER:
467                                         cp = ts->lock_marker; break;
468
469                                 case TH_MATCH:
470                                         cp = ts->match;
471                                         break;
472
473                                 case TH_SELECT_HIGHLIGHT:
474                                         cp = ts->selected_highlight;
475                                         break;
476
477                                 case TH_SKIN_ROOT:
478                                         cp = ts->skin_root;
479                                         break;
480                         }
481                 }
482         }
483         
484         return (unsigned char *)cp;
485 }
486
487 /* use this call to init new bone color sets in Theme */
488 static void ui_theme_init_boneColorSets(bTheme *btheme)
489 {
490         int i;
491         
492         /* define default color sets - currently we only define 15 of these, though that should be ample */
493         /* set 1 */
494         rgba_char_args_set(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
495         rgba_char_args_set(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
496         rgba_char_args_set(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
497         /* set 2 */
498         rgba_char_args_set(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
499         rgba_char_args_set(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
500         rgba_char_args_set(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
501         /* set 3 */
502         rgba_char_args_set(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
503         rgba_char_args_set(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
504         rgba_char_args_set(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
505         /* set 4 */
506         rgba_char_args_set(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
507         rgba_char_args_set(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
508         rgba_char_args_set(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
509         /* set 5 */
510         rgba_char_args_set(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
511         rgba_char_args_set(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
512         rgba_char_args_set(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
513         /* set 6 */
514         rgba_char_args_set(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
515         rgba_char_args_set(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
516         rgba_char_args_set(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
517         /* set 7 */
518         rgba_char_args_set(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
519         rgba_char_args_set(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
520         rgba_char_args_set(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
521         /* set 8 */
522         rgba_char_args_set(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
523         rgba_char_args_set(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
524         rgba_char_args_set(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
525         /* set 9 */
526         rgba_char_args_set(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
527         rgba_char_args_set(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
528         rgba_char_args_set(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
529         /* set 10 */
530         rgba_char_args_set(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
531         rgba_char_args_set(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
532         rgba_char_args_set(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
533         /* set 11 */
534         rgba_char_args_set(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
535         rgba_char_args_set(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
536         rgba_char_args_set(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
537         /* set 12 */
538         rgba_char_args_set(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
539         rgba_char_args_set(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
540         rgba_char_args_set(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
541         /* set 13 */
542         rgba_char_args_set(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
543         rgba_char_args_set(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
544         rgba_char_args_set(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
545         /* set 14 */
546         rgba_char_args_set(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
547         rgba_char_args_set(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
548         rgba_char_args_set(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
549         /* set 15 */
550         rgba_char_args_set(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
551         rgba_char_args_set(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
552         rgba_char_args_set(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
553         
554         /* reset flags too */
555         for (i = 0; i < 20; i++)
556                 btheme->tarm[i].flag = 0;
557 }
558
559 /* use this call to init new variables in themespace, if they're same for all */
560 static void ui_theme_init_new_do(ThemeSpace *ts)
561 {
562         rgba_char_args_test_set(ts->header_text,        0, 0, 0, 255);
563         rgba_char_args_test_set(ts->header_title,   0, 0, 0, 255);
564         rgba_char_args_test_set(ts->header_text_hi, 255, 255, 255, 255);
565
566         rgba_char_args_test_set(ts->panel_text,     0, 0, 0, 255);
567         rgba_char_args_test_set(ts->panel_title,        0, 0, 0, 255);
568         rgba_char_args_test_set(ts->panel_text_hi,  255, 255, 255, 255);
569
570         rgba_char_args_test_set(ts->button,         145, 145, 145, 245);
571         rgba_char_args_test_set(ts->button_title,   0, 0, 0, 255);
572         rgba_char_args_test_set(ts->button_text,        0, 0, 0, 255);
573         rgba_char_args_test_set(ts->button_text_hi, 255, 255, 255, 255);
574
575         rgba_char_args_test_set(ts->list,           165, 165, 165, 255);
576         rgba_char_args_test_set(ts->list_title,     0, 0, 0, 255);
577         rgba_char_args_test_set(ts->list_text,      0, 0, 0, 255);
578         rgba_char_args_test_set(ts->list_text_hi,   255, 255, 255, 255);
579 }
580
581 static void ui_theme_init_new(bTheme *btheme)
582 {
583         ui_theme_init_new_do(&btheme->tbuts);
584         ui_theme_init_new_do(&btheme->tv3d);
585         ui_theme_init_new_do(&btheme->tfile);
586         ui_theme_init_new_do(&btheme->tipo);
587         ui_theme_init_new_do(&btheme->tinfo);
588         ui_theme_init_new_do(&btheme->tact);
589         ui_theme_init_new_do(&btheme->tnla);
590         ui_theme_init_new_do(&btheme->tseq);
591         ui_theme_init_new_do(&btheme->tima);
592         ui_theme_init_new_do(&btheme->text);
593         ui_theme_init_new_do(&btheme->toops);
594         ui_theme_init_new_do(&btheme->ttime);
595         ui_theme_init_new_do(&btheme->tnode);
596         ui_theme_init_new_do(&btheme->tlogic);
597         ui_theme_init_new_do(&btheme->tuserpref);
598         ui_theme_init_new_do(&btheme->tconsole);
599         ui_theme_init_new_do(&btheme->tclip);
600         
601 }
602
603
604 /* initialize default theme
605  * Note: when you add new colors, created & saved themes need initialized
606  * use function below, init_userdef_do_versions()
607  */
608 void ui_theme_init_default(void)
609 {
610         bTheme *btheme;
611         
612         /* we search for the theme with name Default */
613         for (btheme = U.themes.first; btheme; btheme = btheme->next) {
614                 if (strcmp("Default", btheme->name) == 0) break;
615         }
616         
617         if (btheme == NULL) {
618                 btheme = MEM_callocN(sizeof(bTheme), "theme");
619                 BLI_addtail(&U.themes, btheme);
620                 strcpy(btheme->name, "Default");
621         }
622         
623         UI_SetTheme(0, 0);  // make sure the global used in this file is set
624
625         /* UI buttons */
626         ui_widget_color_init(&btheme->tui);
627         btheme->tui.iconfile[0] = 0;
628         btheme->tui.panel.show_header = FALSE;
629         rgba_char_args_set(btheme->tui.panel.header, 0, 0, 0, 25);
630
631         /* Bone Color Sets */
632         ui_theme_init_boneColorSets(btheme);
633         
634         /* common (new) variables */
635         ui_theme_init_new(btheme);
636         
637         /* space view3d */
638         rgba_char_args_set_fl(btheme->tv3d.back,       0.225, 0.225, 0.225, 1.0);
639         rgba_char_args_set(btheme->tv3d.text,       0, 0, 0, 255);
640         rgba_char_args_set(btheme->tv3d.text_hi, 255, 255, 255, 255);
641         
642         rgba_char_args_set_fl(btheme->tv3d.header,  0.45, 0.45, 0.45, 1.0);
643         rgba_char_args_set_fl(btheme->tv3d.button,  0.45, 0.45, 0.45, 1.0);
644         rgba_char_args_set(btheme->tv3d.panel,      165, 165, 165, 127);
645         
646         rgba_char_args_set(btheme->tv3d.shade1,  160, 160, 160, 100);
647         rgba_char_args_set(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
648
649         rgba_char_args_set_fl(btheme->tv3d.grid,     0.251, 0.251, 0.251, 1.0);
650         rgba_char_args_set(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
651         rgba_char_args_set(btheme->tv3d.lamp,       0, 0, 0, 40);
652         rgba_char_args_set(btheme->tv3d.speaker,    0, 0, 0, 255);
653         rgba_char_args_set(btheme->tv3d.camera,    0, 0, 0, 255);
654         rgba_char_args_set(btheme->tv3d.empty,    0, 0, 0, 255);
655         rgba_char_args_set(btheme->tv3d.select, 241, 88, 0, 255);
656         rgba_char_args_set(btheme->tv3d.active, 255, 170, 64, 255);
657         rgba_char_args_set(btheme->tv3d.group,      8, 48, 8, 255);
658         rgba_char_args_set(btheme->tv3d.group_active, 85, 187, 85, 255);
659         rgba_char_args_set(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
660         rgba_char_args_set(btheme->tv3d.vertex, 0, 0, 0, 255);
661         rgba_char_args_set(btheme->tv3d.vertex_select, 255, 133, 0, 255);
662         btheme->tv3d.vertex_size = 3;
663         btheme->tv3d.outline_width = 1;
664         rgba_char_args_set(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
665         rgba_char_args_set(btheme->tv3d.edge_select, 255, 160, 0, 255);
666         rgba_char_args_set(btheme->tv3d.edge_seam, 219, 37, 18, 255);
667         rgba_char_args_set(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
668         rgba_char_args_set(btheme->tv3d.face,       0, 0, 0, 18);
669         rgba_char_args_set(btheme->tv3d.face_select, 255, 133, 0, 60);
670         rgba_char_args_set(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
671         rgba_char_args_set(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
672         rgba_char_args_set(btheme->tv3d.face_dot, 255, 133, 0, 255);
673         rgba_char_args_set(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
674         rgba_char_args_set_fl(btheme->tv3d.edge_crease, 0.8, 0, 0.6, 1.0);
675         rgba_char_args_set(btheme->tv3d.edge_sharp, 0, 255, 255, 255);
676         rgba_char_args_set(btheme->tv3d.header_text, 0, 0, 0, 255);
677         rgba_char_args_set(btheme->tv3d.header_text_hi, 255, 255, 255, 255);
678         rgba_char_args_set(btheme->tv3d.button_text, 0, 0, 0, 255);
679         rgba_char_args_set(btheme->tv3d.button_text_hi, 255, 255, 255, 255);
680         rgba_char_args_set(btheme->tv3d.button_title, 0, 0, 0, 255);
681         rgba_char_args_set(btheme->tv3d.title, 0, 0, 0, 255);
682         rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
683         rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
684
685         btheme->tv3d.facedot_size = 4;
686
687         rgba_char_args_set(btheme->tv3d.extra_edge_len, 32, 0, 0, 255);
688         rgba_char_args_set(btheme->tv3d.extra_face_area, 0, 32, 0, 255);
689         rgba_char_args_set(btheme->tv3d.extra_face_angle, 0, 0, 128, 255);
690
691         rgba_char_args_set(btheme->tv3d.cframe, 0x60, 0xc0,  0x40, 255);
692
693         rgba_char_args_set(btheme->tv3d.nurb_uline, 0x90, 0x90, 0x00, 255);
694         rgba_char_args_set(btheme->tv3d.nurb_vline, 0x80, 0x30, 0x60, 255);
695         rgba_char_args_set(btheme->tv3d.nurb_sel_uline, 0xf0, 0xff, 0x40, 255);
696         rgba_char_args_set(btheme->tv3d.nurb_sel_vline, 0xf0, 0x90, 0xa0, 255);
697
698         rgba_char_args_set(btheme->tv3d.handle_free, 0, 0, 0, 255);
699         rgba_char_args_set(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
700         rgba_char_args_set(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
701         rgba_char_args_set(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
702         rgba_char_args_set(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
703         rgba_char_args_set(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
704         rgba_char_args_set(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
705         rgba_char_args_set(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
706
707         rgba_char_args_set(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
708         rgba_char_args_set(btheme->tv3d.lastsel_point,  0xff, 0xff, 0xff, 255);
709
710         rgba_char_args_set(btheme->tv3d.bone_solid, 200, 200, 200, 255);
711         rgba_char_args_set(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
712
713         rgba_char_args_set(btheme->tv3d.bundle_solid, 200, 200, 200, 255);
714         rgba_char_args_set(btheme->tv3d.camera_path, 0x00, 0x00, 0x00, 255);
715
716         rgba_char_args_set(btheme->tv3d.skin_root, 180, 77, 77, 255);
717         
718         /* space buttons */
719         /* to have something initialized */
720         btheme->tbuts = btheme->tv3d;
721
722         rgba_char_args_set_fl(btheme->tbuts.back,   0.45, 0.45, 0.45, 1.0);
723         rgba_char_args_set(btheme->tbuts.panel, 0x82, 0x82, 0x82, 255);
724
725         /* graph editor */
726         btheme->tipo = btheme->tv3d;
727         rgba_char_args_set_fl(btheme->tipo.back,    0.42, 0.42, 0.42, 1.0);
728         rgba_char_args_set_fl(btheme->tipo.list,    0.4, 0.4, 0.4, 1.0);
729         rgba_char_args_set(btheme->tipo.grid,   94, 94, 94, 255);
730         rgba_char_args_set(btheme->tipo.panel,  255, 255, 255, 150);
731         rgba_char_args_set(btheme->tipo.shade1,     150, 150, 150, 100);    /* scrollbars */
732         rgba_char_args_set(btheme->tipo.shade2,     0x70, 0x70, 0x70, 100);
733         rgba_char_args_set(btheme->tipo.vertex,     0, 0, 0, 255);
734         rgba_char_args_set(btheme->tipo.vertex_select, 255, 133, 0, 255);
735         rgba_char_args_set(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255);
736         btheme->tipo.vertex_size = 3;
737
738         rgba_char_args_set(btheme->tipo.handle_vertex,      0, 0, 0, 255);
739         rgba_char_args_set(btheme->tipo.handle_vertex_select, 255, 133, 0, 255);
740         rgba_char_args_set(btheme->tipo.handle_auto_clamped, 0x99, 0x40, 0x30, 255);
741         rgba_char_args_set(btheme->tipo.handle_sel_auto_clamped, 0xf0, 0xaf, 0x90, 255);
742         btheme->tipo.handle_vertex_size = 4;
743         
744         rgba_char_args_set(btheme->tipo.ds_channel,     82, 96, 110, 255);
745         rgba_char_args_set(btheme->tipo.ds_subchannel,  124, 137, 150, 255);
746         rgba_char_args_set(btheme->tipo.group, 79, 101, 73, 255);
747         rgba_char_args_set(btheme->tipo.group_active, 135, 177, 125, 255);
748
749         /* dopesheet */
750         btheme->tact = btheme->tipo;
751         rgba_char_args_set(btheme->tact.strip,          12, 10, 10, 128);
752         rgba_char_args_set(btheme->tact.strip_select,   255, 140, 0, 255);
753         
754         /* space nla */
755         btheme->tnla = btheme->tact;
756         
757         /* space file */
758         /* to have something initialized */
759         btheme->tfile = btheme->tv3d;
760         rgba_char_args_set_fl(btheme->tfile.back, 0.3, 0.3, 0.3, 1);
761         rgba_char_args_set_fl(btheme->tfile.panel, 0.3, 0.3, 0.3, 1);
762         rgba_char_args_set_fl(btheme->tfile.list, 0.4, 0.4, 0.4, 1);
763         rgba_char_args_set(btheme->tfile.text,  250, 250, 250, 255);
764         rgba_char_args_set(btheme->tfile.text_hi, 15, 15, 15, 255);
765         rgba_char_args_set(btheme->tfile.panel, 145, 145, 145, 255);    // bookmark/ui regions
766         rgba_char_args_set(btheme->tfile.active, 130, 130, 130, 255); // selected files
767         rgba_char_args_set(btheme->tfile.hilite, 255, 140, 25, 255); // selected files
768         
769         rgba_char_args_set(btheme->tfile.grid,  250, 250, 250, 255);
770         rgba_char_args_set(btheme->tfile.image, 250, 250, 250, 255);
771         rgba_char_args_set(btheme->tfile.movie, 250, 250, 250, 255);
772         rgba_char_args_set(btheme->tfile.scene, 250, 250, 250, 255);
773
774         
775         /* space seq */
776         btheme->tseq = btheme->tv3d;
777         rgba_char_args_set(btheme->tseq.back,   116, 116, 116, 255);
778         rgba_char_args_set(btheme->tseq.movie,  81, 105, 135, 255);
779         rgba_char_args_set(btheme->tseq.movieclip,  32, 32, 143, 255);
780         rgba_char_args_set(btheme->tseq.image,  109, 88, 129, 255);
781         rgba_char_args_set(btheme->tseq.scene,  78, 152, 62, 255);
782         rgba_char_args_set(btheme->tseq.audio,  46, 143, 143, 255);
783         rgba_char_args_set(btheme->tseq.effect,     169, 84, 124, 255);
784         rgba_char_args_set(btheme->tseq.plugin,     126, 126, 80, 255);
785         rgba_char_args_set(btheme->tseq.transition, 162, 95, 111, 255);
786         rgba_char_args_set(btheme->tseq.meta,   109, 145, 131, 255);
787         rgba_char_args_set(btheme->tseq.preview_back,   0, 0, 0, 255);
788
789         /* space image */
790         btheme->tima = btheme->tv3d;
791         rgba_char_args_set(btheme->tima.back,   53, 53, 53, 255);
792         rgba_char_args_set(btheme->tima.vertex, 0, 0, 0, 255);
793         rgba_char_args_set(btheme->tima.vertex_select, 255, 133, 0, 255);
794         btheme->tima.vertex_size = 3;
795         btheme->tima.facedot_size = 3;
796         rgba_char_args_set(btheme->tima.face,   255, 255, 255, 10);
797         rgba_char_args_set(btheme->tima.face_select, 255, 133, 0, 60);
798         rgba_char_args_set(btheme->tima.editmesh_active, 255, 255, 255, 128);
799         rgba_char_args_set_fl(btheme->tima.preview_back,    0.45, 0.45, 0.45, 1.0);
800         rgba_char_args_set_fl(btheme->tima.preview_stitch_face, 0.5, 0.5, 0.0, 0.2);
801         rgba_char_args_set_fl(btheme->tima.preview_stitch_edge, 1.0, 0.0, 1.0, 0.2);
802         rgba_char_args_set_fl(btheme->tima.preview_stitch_vert, 0.0, 0.0, 1.0, 0.2);
803         rgba_char_args_set_fl(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
804         rgba_char_args_set_fl(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
805
806         /* space text */
807         btheme->text = btheme->tv3d;
808         rgba_char_args_set(btheme->text.back,   153, 153, 153, 255);
809         rgba_char_args_set(btheme->text.shade1,     143, 143, 143, 255);
810         rgba_char_args_set(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
811         rgba_char_args_set(btheme->text.hilite,     255, 0, 0, 255);
812         
813         /* syntax highlighting */
814         rgba_char_args_set(btheme->text.syntaxn,    0, 0, 200, 255);    /* Numbers  Blue*/
815         rgba_char_args_set(btheme->text.syntaxl,    100, 0, 0, 255);    /* Strings  red */
816         rgba_char_args_set(btheme->text.syntaxc,    0, 100, 50, 255);   /* Comments greenish */
817         rgba_char_args_set(btheme->text.syntaxv,    95, 95, 0, 255);    /* Special */
818         rgba_char_args_set(btheme->text.syntaxb,    128, 0, 80, 255);   /* Builtin, red-purple */
819         
820         /* space oops */
821         btheme->toops = btheme->tv3d;
822         rgba_char_args_set_fl(btheme->toops.back,   0.45, 0.45, 0.45, 1.0);
823         
824         rgba_char_args_set_fl(btheme->toops.match,  0.2, 0.5, 0.2, 0.3);    /* highlighting search match - soft green*/
825         rgba_char_args_set_fl(btheme->toops.selected_highlight, 0.51, 0.53, 0.55, 0.3);
826
827         /* space info */
828         btheme->tinfo = btheme->tv3d;
829         rgba_char_args_set_fl(btheme->tinfo.back,   0.45, 0.45, 0.45, 1.0);
830
831         /* space user preferences */
832         btheme->tuserpref = btheme->tv3d;
833         rgba_char_args_set_fl(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
834         
835         /* space console */
836         btheme->tconsole = btheme->tv3d;
837         rgba_char_args_set(btheme->tconsole.back, 0, 0, 0, 255);
838         rgba_char_args_set(btheme->tconsole.console_output, 96, 128, 255, 255);
839         rgba_char_args_set(btheme->tconsole.console_input, 255, 255, 255, 255);
840         rgba_char_args_set(btheme->tconsole.console_info, 0, 170, 0, 255);
841         rgba_char_args_set(btheme->tconsole.console_error, 220, 96, 96, 255);
842         rgba_char_args_set(btheme->tconsole.console_cursor, 220, 96, 96, 255);
843         
844         /* space time */
845         btheme->ttime = btheme->tv3d;
846         rgba_char_args_set_fl(btheme->ttime.back,   0.45, 0.45, 0.45, 1.0);
847         rgba_char_args_set_fl(btheme->ttime.grid,   0.36, 0.36, 0.36, 1.0);
848         rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);      // sliders
849         
850         /* space node, re-uses syntax color storage */
851         btheme->tnode = btheme->tv3d;
852         rgba_char_args_set(btheme->tnode.edge_select, 255, 255, 255, 255);      /* wire selected */
853         rgba_char_args_set(btheme->tnode.syntaxl, 155, 155, 155, 160);  /* TH_NODE, backdrop */
854         rgba_char_args_set(btheme->tnode.syntaxn, 100, 100, 100, 255);  /* in/output */
855         rgba_char_args_set(btheme->tnode.syntaxb, 108, 105, 111, 255);  /* operator */
856         rgba_char_args_set(btheme->tnode.syntaxv, 104, 106, 117, 255);  /* generator */
857         rgba_char_args_set(btheme->tnode.syntaxc, 105, 117, 110, 255);  /* group */
858         btheme->tnode.noodle_curving = 5;
859
860         /* space logic */
861         btheme->tlogic = btheme->tv3d;
862         rgba_char_args_set(btheme->tlogic.back, 100, 100, 100, 255);
863         
864         /* space clip */
865         btheme->tclip = btheme->tv3d;
866
867         rgba_char_args_set(btheme->tclip.marker_outline, 0x00, 0x00, 0x00, 255);
868         rgba_char_args_set(btheme->tclip.marker, 0x7f, 0x7f, 0x00, 255);
869         rgba_char_args_set(btheme->tclip.act_marker, 0xff, 0xff, 0xff, 255);
870         rgba_char_args_set(btheme->tclip.sel_marker, 0xff, 0xff, 0x00, 255);
871         rgba_char_args_set(btheme->tclip.dis_marker, 0x7f, 0x00, 0x00, 255);
872         rgba_char_args_set(btheme->tclip.lock_marker, 0x7f, 0x7f, 0x7f, 255);
873         rgba_char_args_set(btheme->tclip.path_before, 0xff, 0x00, 0x00, 255);
874         rgba_char_args_set(btheme->tclip.path_after, 0x00, 0x00, 0xff, 255);
875         rgba_char_args_set(btheme->tclip.grid, 0x5e, 0x5e, 0x5e, 255);
876         rgba_char_args_set(btheme->tclip.cframe, 0x60, 0xc0, 0x40, 255);
877         rgba_char_args_set(btheme->tclip.handle_vertex, 0x00, 0x00, 0x00, 0xff);
878         rgba_char_args_set(btheme->tclip.handle_vertex_select, 0xff, 0xff, 0, 0xff);
879         rgba_char_args_set(btheme->tclip.list, 0x66, 0x66, 0x66, 0xff);
880         rgba_char_args_set(btheme->tclip.strip, 0x0c, 0x0a, 0x0a, 0x80);
881         rgba_char_args_set(btheme->tclip.strip_select, 0xff, 0x8c, 0x00, 0xff);
882         btheme->tclip.handle_vertex_size = 4;
883 }
884
885
886 void UI_SetTheme(int spacetype, int regionid)
887 {
888         if (spacetype == 0) { // called for safety, when delete themes
889                 theme_active = U.themes.first;
890                 theme_spacetype = SPACE_VIEW3D;
891                 theme_regionid = RGN_TYPE_WINDOW;
892         }
893         else {
894                 // later on, a local theme can be found too
895                 theme_active = U.themes.first;
896                 theme_spacetype = spacetype;
897                 theme_regionid = regionid;
898         }
899 }
900
901 bTheme *UI_GetTheme()
902 {
903         return U.themes.first;
904 }
905
906 // for space windows only
907 void UI_ThemeColor(int colorid)
908 {
909         const unsigned char *cp;
910         
911         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
912         glColor3ubv(cp);
913
914 }
915
916 // plus alpha
917 void UI_ThemeColor4(int colorid)
918 {
919         const unsigned char *cp;
920         
921         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
922         glColor4ubv(cp);
923
924 }
925
926 // set the color with offset for shades
927 void UI_ThemeColorShade(int colorid, int offset)
928 {
929         int r, g, b;
930         const unsigned char *cp;
931         
932         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
933         r = offset + (int) cp[0];
934         CLAMP(r, 0, 255);
935         g = offset + (int) cp[1];
936         CLAMP(g, 0, 255);
937         b = offset + (int) cp[2];
938         CLAMP(b, 0, 255);
939         //glColor3ub(r, g, b);
940         glColor4ub(r, g, b, cp[3]);
941 }
942 void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
943 {
944         int r, g, b, a;
945         const unsigned char *cp;
946         
947         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
948         r = coloffset + (int) cp[0];
949         CLAMP(r, 0, 255);
950         g = coloffset + (int) cp[1];
951         CLAMP(g, 0, 255);
952         b = coloffset + (int) cp[2];
953         CLAMP(b, 0, 255);
954         a = alphaoffset + (int) cp[3];
955         CLAMP(a, 0, 255);
956         glColor4ub(r, g, b, a);
957 }
958
959 // blend between to theme colors, and set it
960 void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
961 {
962         int r, g, b;
963         const unsigned char *cp1, *cp2;
964         
965         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
966         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
967
968         CLAMP(fac, 0.0f, 1.0f);
969         r = floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
970         g = floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
971         b = floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
972         
973         glColor3ub(r, g, b);
974 }
975
976 // blend between to theme colors, shade it, and set it
977 void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
978 {
979         int r, g, b;
980         const unsigned char *cp1, *cp2;
981         
982         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
983         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
984
985         CLAMP(fac, 0.0f, 1.0f);
986         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
987         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
988         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
989         
990         CLAMP(r, 0, 255);
991         CLAMP(g, 0, 255);
992         CLAMP(b, 0, 255);
993         
994         glColor3ub(r, g, b);
995 }
996
997 // blend between to theme colors, shade it, and set it
998 void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
999 {
1000         int r, g, b, a;
1001         const unsigned char *cp1, *cp2;
1002         
1003         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
1004         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
1005
1006         CLAMP(fac, 0.0f, 1.0f);
1007         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1008         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1009         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
1010         a = alphaoffset + floorf((1.0f - fac) * cp1[3] + fac * cp2[3]);
1011         
1012         CLAMP(r, 0, 255);
1013         CLAMP(g, 0, 255);
1014         CLAMP(b, 0, 255);
1015         CLAMP(a, 0, 255);
1016
1017         glColor4ub(r, g, b, a);
1018 }
1019
1020
1021 // get individual values, not scaled
1022 float UI_GetThemeValuef(int colorid)
1023 {
1024         const unsigned char *cp;
1025         
1026         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1027         return ((float)cp[0]);
1028
1029 }
1030
1031 // get individual values, not scaled
1032 int UI_GetThemeValue(int colorid)
1033 {
1034         const unsigned char *cp;
1035         
1036         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1037         return ((int) cp[0]);
1038
1039 }
1040
1041
1042 // get the color, range 0.0-1.0
1043 void UI_GetThemeColor3fv(int colorid, float col[3])
1044 {
1045         const unsigned char *cp;
1046         
1047         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1048         col[0] = ((float)cp[0]) / 255.0f;
1049         col[1] = ((float)cp[1]) / 255.0f;
1050         col[2] = ((float)cp[2]) / 255.0f;
1051 }
1052
1053 // get the color, range 0.0-1.0, complete with shading offset
1054 void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
1055 {
1056         int r, g, b;
1057         const unsigned char *cp;
1058         
1059         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1060         
1061         r = offset + (int) cp[0];
1062         CLAMP(r, 0, 255);
1063         g = offset + (int) cp[1];
1064         CLAMP(g, 0, 255);
1065         b = offset + (int) cp[2];
1066         CLAMP(b, 0, 255);
1067         
1068         col[0] = ((float)r) / 255.0f;
1069         col[1] = ((float)g) / 255.0f;
1070         col[2] = ((float)b) / 255.0f;
1071 }
1072
1073 void UI_GetThemeColorShade3ubv(int colorid, int offset, unsigned char col[3])
1074 {
1075         int r, g, b;
1076         const unsigned char *cp;
1077
1078         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1079
1080         r = offset + (int) cp[0];
1081         CLAMP(r, 0, 255);
1082         g = offset + (int) cp[1];
1083         CLAMP(g, 0, 255);
1084         b = offset + (int) cp[2];
1085         CLAMP(b, 0, 255);
1086
1087         col[0] = r;
1088         col[1] = g;
1089         col[2] = b;
1090 }
1091
1092 // get the color, in char pointer
1093 void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
1094 {
1095         const unsigned char *cp;
1096         
1097         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1098         col[0] = cp[0];
1099         col[1] = cp[1];
1100         col[2] = cp[2];
1101 }
1102
1103 // get the color, in char pointer
1104 void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
1105 {
1106         const unsigned char *cp;
1107         
1108         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1109         col[0] = cp[0];
1110         col[1] = cp[1];
1111         col[2] = cp[2];
1112         col[3] = cp[3];
1113 }
1114
1115 void UI_GetThemeColorType4ubv(int colorid, int spacetype, char col[4])
1116 {
1117         const unsigned char *cp;
1118         
1119         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
1120         col[0] = cp[0];
1121         col[1] = cp[1];
1122         col[2] = cp[2];
1123         col[3] = cp[3];
1124 }
1125
1126 // blends and shades between two char color pointers
1127 void UI_ColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], float fac, int offset)
1128 {
1129         int r, g, b;
1130         CLAMP(fac, 0.0f, 1.0f);
1131         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1132         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1133         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
1134
1135         r = r < 0 ? 0 : (r > 255 ? 255 : r);
1136         g = g < 0 ? 0 : (g > 255 ? 255 : g);
1137         b = b < 0 ? 0 : (b > 255 ? 255 : b);
1138         
1139         glColor3ub(r, g, b);
1140 }
1141
1142 void UI_GetColorPtrShade3ubv(const unsigned char cp[3], unsigned char col[3], int offset)
1143 {
1144         int r, g, b;
1145
1146         r = offset + (int)cp[0];
1147         g = offset + (int)cp[1];
1148         b = offset + (int)cp[2];
1149
1150         CLAMP(r, 0, 255);
1151         CLAMP(g, 0, 255);
1152         CLAMP(b, 0, 255);
1153
1154         col[0] = r;
1155         col[1] = g;
1156         col[2] = b;
1157 }
1158
1159 // get a 3 byte color, blended and shaded between two other char color pointers
1160 void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], unsigned char col[3], float fac, int offset)
1161 {
1162         int r, g, b;
1163
1164         CLAMP(fac, 0.0f, 1.0f);
1165         r = offset + floor((1.0f - fac) * cp1[0] + fac * cp2[0]);
1166         g = offset + floor((1.0f - fac) * cp1[1] + fac * cp2[1]);
1167         b = offset + floor((1.0f - fac) * cp1[2] + fac * cp2[2]);
1168
1169         CLAMP(r, 0, 255);
1170         CLAMP(g, 0, 255);
1171         CLAMP(b, 0, 255);
1172
1173         col[0] = r;
1174         col[1] = g;
1175         col[2] = b;
1176 }
1177
1178 void UI_ThemeClearColor(int colorid)
1179 {
1180         float col[3];
1181         
1182         UI_GetThemeColor3fv(colorid, col);
1183         glClearColor(col[0], col[1], col[2], 0.0);
1184 }
1185
1186 void UI_make_axis_color(const unsigned char src_col[3], unsigned char dst_col[3], const char axis)
1187 {
1188         switch (axis) {
1189                 case 'X':
1190                         dst_col[0] = src_col[0] > 219 ? 255 : src_col[0] + 36;
1191                         dst_col[1] = src_col[1] < 26 ? 0 : src_col[1] - 26;
1192                         dst_col[2] = src_col[2] < 26 ? 0 : src_col[2] - 26;
1193                         break;
1194                 case 'Y':
1195                         dst_col[0] = src_col[0] < 46 ? 0 : src_col[0] - 36;
1196                         dst_col[1] = src_col[1] > 189 ? 255 : src_col[1] + 66;
1197                         dst_col[2] = src_col[2] < 46 ? 0 : src_col[2] - 36;
1198                         break;
1199                 case 'Z':
1200                         dst_col[0] = src_col[0] < 26 ? 0 : src_col[0] - 26;
1201                         dst_col[1] = src_col[1] < 26 ? 0 : src_col[1] - 26;
1202                         dst_col[2] = src_col[2] > 209 ? 255 : src_col[2] + 46;
1203                         break;
1204                 default:
1205                         BLI_assert(!"invalid axis arg");
1206         }
1207 }
1208
1209 /* ************************************************************* */
1210
1211 /* patching UserDef struct and Themes */
1212 void init_userdef_do_versions(void)
1213 {
1214         Main *bmain = G.main;
1215 //      countall();
1216         
1217         /* the UserDef struct is not corrected with do_versions() .... ugh! */
1218         if (U.wheellinescroll == 0) U.wheellinescroll = 3;
1219         if (U.menuthreshold1 == 0) {
1220                 U.menuthreshold1 = 5;
1221                 U.menuthreshold2 = 2;
1222         }
1223         if (U.tb_leftmouse == 0) {
1224                 U.tb_leftmouse = 5;
1225                 U.tb_rightmouse = 5;
1226         }
1227         if (U.mixbufsize == 0) U.mixbufsize = 2048;
1228         if (strcmp(U.tempdir, "/") == 0) {
1229                 BLI_system_temporary_dir(U.tempdir);
1230         }
1231         if (U.autokey_mode == 0) {
1232                 /* 'add/replace' but not on */
1233                 U.autokey_mode = 2;
1234         }
1235         if (U.savetime <= 0) {
1236                 U.savetime = 1;
1237 // XXX          error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n");
1238         }
1239         /* transform widget settings */
1240         if (U.tw_hotspot == 0) {
1241                 U.tw_hotspot = 14;
1242                 U.tw_size = 20;          // percentage of window size
1243                 U.tw_handlesize = 16;    // percentage of widget radius
1244         }
1245         if (U.pad_rot_angle == 0)
1246                 U.pad_rot_angle = 15;
1247         /* graph editor - unselected F-Curve visibility */
1248         if (U.fcu_inactive_alpha == 0) {
1249                 U.fcu_inactive_alpha = 0.25f;
1250         }
1251         
1252         /* signal for derivedmesh to use colorband */
1253         /* run in case this was on and is now off in the user prefs [#28096] */
1254         vDM_ColorBand_store((U.flag & USER_CUSTOM_RANGE) ? (&U.coba_weight) : NULL);
1255
1256         if (bmain->versionfile <= 191) {
1257                 BLI_strncpy(U.plugtexdir, U.textudir, sizeof(U.plugtexdir));
1258                 strcpy(U.sounddir, "/");
1259         }
1260         
1261         /* patch to set Dupli Armature */
1262         if (bmain->versionfile < 220) {
1263                 U.dupflag |= USER_DUP_ARM;
1264         }
1265         
1266         /* added seam, normal color, undo */
1267         if (bmain->versionfile <= 234) {
1268                 bTheme *btheme;
1269                 
1270                 U.uiflag |= USER_GLOBALUNDO;
1271                 if (U.undosteps == 0) U.undosteps = 32;
1272                 
1273                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1274                         /* check for alpha==0 is safe, then color was never set */
1275                         if (btheme->tv3d.edge_seam[3] == 0) {
1276                                 rgba_char_args_set(btheme->tv3d.edge_seam, 230, 150, 50, 255);
1277                         }
1278                         if (btheme->tv3d.normal[3] == 0) {
1279                                 rgba_char_args_set(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
1280                         }
1281                         if (btheme->tv3d.vertex_normal[3] == 0) {
1282                                 rgba_char_args_set(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
1283                         }
1284                         if (btheme->tv3d.face_dot[3] == 0) {
1285                                 rgba_char_args_set(btheme->tv3d.face_dot, 255, 138, 48, 255);
1286                                 btheme->tv3d.facedot_size = 4;
1287                         }
1288                 }
1289         }
1290         if (bmain->versionfile <= 235) {
1291                 /* illegal combo... */
1292                 if (U.flag & USER_LMOUSESELECT) 
1293                         U.flag &= ~USER_TWOBUTTONMOUSE;
1294         }
1295         if (bmain->versionfile <= 236) {
1296                 bTheme *btheme;
1297                 /* new space type */
1298                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1299                         /* check for alpha==0 is safe, then color was never set */
1300                         if (btheme->ttime.back[3] == 0) {
1301                                 // copied from ui_theme_init_default
1302                                 btheme->ttime = btheme->tv3d;
1303                                 rgba_char_args_set_fl(btheme->ttime.back,   0.45, 0.45, 0.45, 1.0);
1304                                 rgba_char_args_set_fl(btheme->ttime.grid,   0.36, 0.36, 0.36, 1.0);
1305                                 rgba_char_args_set(btheme->ttime.shade1,  173, 173, 173, 255);      // sliders
1306                         }
1307                         if (btheme->text.syntaxn[3] == 0) {
1308                                 rgba_char_args_set(btheme->text.syntaxn,    0, 0, 200, 255);    /* Numbers  Blue*/
1309                                 rgba_char_args_set(btheme->text.syntaxl,    100, 0, 0, 255);    /* Strings  red */
1310                                 rgba_char_args_set(btheme->text.syntaxc,    0, 100, 50, 255);   /* Comments greenish */
1311                                 rgba_char_args_set(btheme->text.syntaxv,    95, 95, 0, 255);    /* Special */
1312                                 rgba_char_args_set(btheme->text.syntaxb,    128, 0, 80, 255);   /* Builtin, red-purple */
1313                         }
1314                 }
1315         }
1316         if (bmain->versionfile <= 237) {
1317                 bTheme *btheme;
1318                 /* bone colors */
1319                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1320                         /* check for alpha==0 is safe, then color was never set */
1321                         if (btheme->tv3d.bone_solid[3] == 0) {
1322                                 rgba_char_args_set(btheme->tv3d.bone_solid, 200, 200, 200, 255);
1323                                 rgba_char_args_set(btheme->tv3d.bone_pose, 80, 200, 255, 80);
1324                         }
1325                 }
1326         }
1327         if (bmain->versionfile <= 238) {
1328                 bTheme *btheme;
1329                 /* bone colors */
1330                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1331                         /* check for alpha==0 is safe, then color was never set */
1332                         if (btheme->tnla.strip[3] == 0) {
1333                                 rgba_char_args_set(btheme->tnla.strip_select,   0xff, 0xff, 0xaa, 255);
1334                                 rgba_char_args_set(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
1335                         }
1336                 }
1337         }
1338         if (bmain->versionfile <= 239) {
1339                 bTheme *btheme;
1340                 
1341                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1342                         /* Lamp theme, check for alpha==0 is safe, then color was never set */
1343                         if (btheme->tv3d.lamp[3] == 0) {
1344                                 rgba_char_args_set(btheme->tv3d.lamp,   0, 0, 0, 40);
1345 /* TEMPORAL, remove me! (ton) */                                
1346                                 U.uiflag |= USER_PLAINMENUS;
1347                         }
1348                         
1349                 }
1350                 if (U.obcenter_dia == 0) U.obcenter_dia = 6;
1351         }
1352         if (bmain->versionfile <= 241) {
1353                 bTheme *btheme;
1354                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1355                         /* Node editor theme, check for alpha==0 is safe, then color was never set */
1356                         if (btheme->tnode.syntaxn[3] == 0) {
1357                                 /* re-uses syntax color storage */
1358                                 btheme->tnode = btheme->tv3d;
1359                                 rgba_char_args_set(btheme->tnode.edge_select, 255, 255, 255, 255);
1360                                 rgba_char_args_set(btheme->tnode.syntaxl, 150, 150, 150, 255);  /* TH_NODE, backdrop */
1361                                 rgba_char_args_set(btheme->tnode.syntaxn, 129, 131, 144, 255);  /* in/output */
1362                                 rgba_char_args_set(btheme->tnode.syntaxb, 127, 127, 127, 255);  /* operator */
1363                                 rgba_char_args_set(btheme->tnode.syntaxv, 142, 138, 145, 255);  /* generator */
1364                                 rgba_char_args_set(btheme->tnode.syntaxc, 120, 145, 120, 255);  /* group */
1365                         }
1366                         /* Group theme colors */
1367                         if (btheme->tv3d.group[3] == 0) {
1368                                 rgba_char_args_set(btheme->tv3d.group, 0x0C, 0x30, 0x0C, 255);
1369                                 rgba_char_args_set(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
1370                         }
1371                         /* Sequence editor theme*/
1372                         if (btheme->tseq.movie[3] == 0) {
1373                                 rgba_char_args_set(btheme->tseq.movie,  81, 105, 135, 255);
1374                                 rgba_char_args_set(btheme->tseq.image,  109, 88, 129, 255);
1375                                 rgba_char_args_set(btheme->tseq.scene,  78, 152, 62, 255);
1376                                 rgba_char_args_set(btheme->tseq.audio,  46, 143, 143, 255);
1377                                 rgba_char_args_set(btheme->tseq.effect,     169, 84, 124, 255);
1378                                 rgba_char_args_set(btheme->tseq.plugin,     126, 126, 80, 255);
1379                                 rgba_char_args_set(btheme->tseq.transition, 162, 95, 111, 255);
1380                                 rgba_char_args_set(btheme->tseq.meta,   109, 145, 131, 255);
1381                         }
1382                 }
1383                 
1384                 /* set defaults for 3D View rotating axis indicator */ 
1385                 /* since size can't be set to 0, this indicates it's not saved in startup.blend */
1386                 if (U.rvisize == 0) {
1387                         U.rvisize = 15;
1388                         U.rvibright = 8;
1389                         U.uiflag |= USER_SHOW_ROTVIEWICON;
1390                 }
1391                 
1392         }
1393         if (bmain->versionfile <= 242) {
1394                 bTheme *btheme;
1395                 
1396                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1397                         /* long keyframe color */
1398                         /* check for alpha==0 is safe, then color was never set */
1399                         if (btheme->tact.strip[3] == 0) {
1400                                 rgba_char_args_set(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
1401                                 rgba_char_args_set(btheme->tact.strip_select,   0xff, 0xff, 0xaa, 204);
1402                                 rgba_char_args_set(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
1403                         }
1404                         
1405                         /* IPO-Editor - Vertex Size*/
1406                         if (btheme->tipo.vertex_size == 0) {
1407                                 btheme->tipo.vertex_size = 3;
1408                         }
1409                 }
1410         }
1411         if (bmain->versionfile <= 243) {
1412                 /* set default number of recently-used files (if not set) */
1413                 if (U.recent_files == 0) U.recent_files = 10;
1414         }
1415         if (bmain->versionfile < 245 || (bmain->versionfile == 245 && bmain->subversionfile < 3)) {
1416                 bTheme *btheme;
1417                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1418                         rgba_char_args_set(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
1419                 }
1420                 if (U.coba_weight.tot == 0)
1421                         init_colorband(&U.coba_weight, 1);
1422         }
1423         if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 11)) {
1424                 bTheme *btheme;
1425                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1426                         /* these should all use the same color */
1427                         rgba_char_args_set(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1428                         rgba_char_args_set(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1429                         rgba_char_args_set(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1430                         rgba_char_args_set(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1431                         rgba_char_args_set(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1432                         //rgba_char_args_set(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255); Not needed anymore
1433                         rgba_char_args_set(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1434                 }
1435         }
1436         if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 13)) {
1437                 bTheme *btheme;
1438                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1439                         /* action channel groups (recolor anyway) */
1440                         rgba_char_args_set(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
1441                         rgba_char_args_set(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
1442                         
1443                         /* bone custom-color sets */
1444                         if (btheme->tarm[0].solid[3] == 0)
1445                                 ui_theme_init_boneColorSets(btheme);
1446                 }
1447         }
1448         if ((bmain->versionfile < 245) || (bmain->versionfile == 245 && bmain->subversionfile < 16)) {
1449                 U.flag |= USER_ADD_VIEWALIGNED | USER_ADD_EDITMODE;
1450         }
1451         if ((bmain->versionfile < 247) || (bmain->versionfile == 247 && bmain->subversionfile <= 2)) {
1452                 bTheme *btheme;
1453                 
1454                 /* adjust themes */
1455                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1456                         char *col;
1457                         
1458                         /* IPO Editor: Handles/Vertices */
1459                         col = btheme->tipo.vertex;
1460                         rgba_char_args_set(btheme->tipo.handle_vertex, col[0], col[1], col[2], 255);
1461                         col = btheme->tipo.vertex_select;
1462                         rgba_char_args_set(btheme->tipo.handle_vertex_select, col[0], col[1], col[2], 255);
1463                         btheme->tipo.handle_vertex_size = btheme->tipo.vertex_size;
1464                         
1465                         /* Sequence/Image Editor: colors for GPencil text */
1466                         col = btheme->tv3d.bone_pose;
1467                         rgba_char_args_set(btheme->tseq.bone_pose, col[0], col[1], col[2], 255);
1468                         rgba_char_args_set(btheme->tima.bone_pose, col[0], col[1], col[2], 255);
1469                         col = btheme->tv3d.vertex_select;
1470                         rgba_char_args_set(btheme->tseq.vertex_select, col[0], col[1], col[2], 255);
1471                 }
1472         }
1473         if (bmain->versionfile < 250) {
1474                 bTheme *btheme;
1475                 
1476                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1477                         /* this was not properly initialized in 2.45 */
1478                         if (btheme->tima.face_dot[3] == 0) {
1479                                 rgba_char_args_set(btheme->tima.editmesh_active, 255, 255, 255, 128);
1480                                 rgba_char_args_set(btheme->tima.face_dot, 255, 133, 0, 255);
1481                                 btheme->tima.facedot_size = 2;
1482                         }
1483                         
1484                         /* DopeSheet - (Object) Channel color */
1485                         rgba_char_args_set(btheme->tact.ds_channel,     82, 96, 110, 255);
1486                         rgba_char_args_set(btheme->tact.ds_subchannel,  124, 137, 150, 255);
1487                         /* DopeSheet - Group Channel color (saner version) */
1488                         rgba_char_args_set(btheme->tact.group, 79, 101, 73, 255);
1489                         rgba_char_args_set(btheme->tact.group_active, 135, 177, 125, 255);
1490                         
1491                         /* Graph Editor - (Object) Channel color */
1492                         rgba_char_args_set(btheme->tipo.ds_channel,     82, 96, 110, 255);
1493                         rgba_char_args_set(btheme->tipo.ds_subchannel,  124, 137, 150, 255);
1494                         /* Graph Editor - Group Channel color */
1495                         rgba_char_args_set(btheme->tipo.group, 79, 101, 73, 255);
1496                         rgba_char_args_set(btheme->tipo.group_active, 135, 177, 125, 255);
1497                         
1498                         /* Nla Editor - (Object) Channel color */
1499                         rgba_char_args_set(btheme->tnla.ds_channel,     82, 96, 110, 255);
1500                         rgba_char_args_set(btheme->tnla.ds_subchannel,  124, 137, 150, 255);
1501                         /* NLA Editor - New Strip colors */
1502                         rgba_char_args_set(btheme->tnla.strip,          12, 10, 10, 128);
1503                         rgba_char_args_set(btheme->tnla.strip_select,   255, 140, 0, 255);
1504                 }
1505                 
1506                 /* adjust grease-pencil distances */
1507                 U.gp_manhattendist = 1;
1508                 U.gp_euclideandist = 2;
1509                 
1510                 /* adjust default interpolation for new IPO-curves */
1511                 U.ipo_new = BEZT_IPO_BEZ;
1512         }
1513         
1514         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 1)) {
1515                 bTheme *btheme;
1516
1517                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1518                         
1519                         /* common (new) variables, it checks for alpha==0 */
1520                         ui_theme_init_new(btheme);
1521
1522                         if (btheme->tui.wcol_num.outline[3] == 0)
1523                                 ui_widget_color_init(&btheme->tui);
1524                         
1525                         /* Logic editor theme, check for alpha==0 is safe, then color was never set */
1526                         if (btheme->tlogic.syntaxn[3] == 0) {
1527                                 /* re-uses syntax color storage */
1528                                 btheme->tlogic = btheme->tv3d;
1529                                 rgba_char_args_set(btheme->tlogic.back, 100, 100, 100, 255);
1530                         }
1531
1532                         rgba_char_args_set_fl(btheme->tinfo.back, 0.45, 0.45, 0.45, 1.0);
1533                         rgba_char_args_set_fl(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
1534                 }
1535         }
1536
1537         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 3)) {
1538                 /* new audio system */
1539                 if (U.audiochannels == 0)
1540                         U.audiochannels = 2;
1541                 if (U.audiodevice == 0) {
1542 #ifdef WITH_OPENAL
1543                         U.audiodevice = 2;
1544 #endif
1545 #ifdef WITH_SDL
1546                         U.audiodevice = 1;
1547 #endif
1548                 }
1549                 if (U.audioformat == 0)
1550                         U.audioformat = 0x24;
1551                 if (U.audiorate == 0)
1552                         U.audiorate = 44100;
1553         }
1554
1555         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 5))
1556                 U.gameflags |= USER_DISABLE_VBO;
1557         
1558         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 8)) {
1559                 wmKeyMap *km;
1560                 
1561                 for (km = U.user_keymaps.first; km; km = km->next) {
1562                         if (strcmp(km->idname, "Armature_Sketch") == 0)
1563                                 strcpy(km->idname, "Armature Sketch");
1564                         else if (strcmp(km->idname, "View3D") == 0)
1565                                 strcpy(km->idname, "3D View");
1566                         else if (strcmp(km->idname, "View3D Generic") == 0)
1567                                 strcpy(km->idname, "3D View Generic");
1568                         else if (strcmp(km->idname, "EditMesh") == 0)
1569                                 strcpy(km->idname, "Mesh");
1570                         else if (strcmp(km->idname, "TimeLine") == 0)
1571                                 strcpy(km->idname, "Timeline");
1572                         else if (strcmp(km->idname, "UVEdit") == 0)
1573                                 strcpy(km->idname, "UV Editor");
1574                         else if (strcmp(km->idname, "Animation_Channels") == 0)
1575                                 strcpy(km->idname, "Animation Channels");
1576                         else if (strcmp(km->idname, "GraphEdit Keys") == 0)
1577                                 strcpy(km->idname, "Graph Editor");
1578                         else if (strcmp(km->idname, "GraphEdit Generic") == 0)
1579                                 strcpy(km->idname, "Graph Editor Generic");
1580                         else if (strcmp(km->idname, "Action_Keys") == 0)
1581                                 strcpy(km->idname, "Dopesheet");
1582                         else if (strcmp(km->idname, "NLA Data") == 0)
1583                                 strcpy(km->idname, "NLA Editor");
1584                         else if (strcmp(km->idname, "Node Generic") == 0)
1585                                 strcpy(km->idname, "Node Editor");
1586                         else if (strcmp(km->idname, "Logic Generic") == 0)
1587                                 strcpy(km->idname, "Logic Editor");
1588                         else if (strcmp(km->idname, "File") == 0)
1589                                 strcpy(km->idname, "File Browser");
1590                         else if (strcmp(km->idname, "FileMain") == 0)
1591                                 strcpy(km->idname, "File Browser Main");
1592                         else if (strcmp(km->idname, "FileButtons") == 0)
1593                                 strcpy(km->idname, "File Browser Buttons");
1594                         else if (strcmp(km->idname, "Buttons Generic") == 0)
1595                                 strcpy(km->idname, "Property Editor");
1596                 }
1597         }
1598         if (bmain->versionfile < 250 || (bmain->versionfile == 250 && bmain->subversionfile < 16)) {
1599                 if (U.wmdrawmethod == USER_DRAW_TRIPLE)
1600                         U.wmdrawmethod = USER_DRAW_AUTOMATIC;
1601         }
1602         
1603         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 3)) {
1604                 if (U.flag & USER_LMOUSESELECT) 
1605                         U.flag &= ~USER_TWOBUTTONMOUSE;
1606         }
1607         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 4)) {
1608                 bTheme *btheme;
1609                 
1610                 /* default new handle type is auto handles */
1611                 U.keyhandles_new = HD_AUTO;
1612                 
1613                 /* init new curve colors */
1614                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1615                         /* init colors used for handles in 3D-View  */
1616                         rgba_char_args_set(btheme->tv3d.handle_free, 0, 0, 0, 255);
1617                         rgba_char_args_set(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
1618                         rgba_char_args_set(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
1619                         rgba_char_args_set(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
1620                         rgba_char_args_set(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
1621                         rgba_char_args_set(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1622                         rgba_char_args_set(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1623                         rgba_char_args_set(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1624                         rgba_char_args_set(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
1625                         
1626                         /* same colors again for Graph Editor... */
1627                         rgba_char_args_set(btheme->tipo.handle_free, 0, 0, 0, 255);
1628                         rgba_char_args_set(btheme->tipo.handle_auto, 0x90, 0x90, 0x00, 255);
1629                         rgba_char_args_set(btheme->tipo.handle_vect, 0x40, 0x90, 0x30, 255);
1630                         rgba_char_args_set(btheme->tipo.handle_align, 0x80, 0x30, 0x60, 255);
1631                         rgba_char_args_set(btheme->tipo.handle_sel_free, 0, 0, 0, 255);
1632                         rgba_char_args_set(btheme->tipo.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1633                         rgba_char_args_set(btheme->tipo.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1634                         rgba_char_args_set(btheme->tipo.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1635                         
1636                         /* edge crease */
1637                         rgba_char_args_set_fl(btheme->tv3d.edge_crease, 0.8, 0, 0.6, 1.0);
1638                 }
1639         }
1640         if (bmain->versionfile <= 252) {
1641                 bTheme *btheme;
1642
1643                 /* init new curve colors */
1644                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1645                         if (btheme->tv3d.lastsel_point[3] == 0)
1646                                 rgba_char_args_set(btheme->tv3d.lastsel_point, 0xff, 0xff, 0xff, 255);
1647                 }
1648         }
1649         if (bmain->versionfile < 252 || (bmain->versionfile == 252 && bmain->subversionfile < 5)) {
1650                 bTheme *btheme;
1651                 
1652                 /* interface_widgets.c */
1653                 struct uiWidgetColors wcol_progress = {
1654                         {0, 0, 0, 255},
1655                         {190, 190, 190, 255},
1656                         {100, 100, 100, 180},
1657                         {68, 68, 68, 255},
1658                         
1659                         {0, 0, 0, 255},
1660                         {255, 255, 255, 255},
1661                         
1662                         0,
1663                         5, -5
1664                 };
1665                 
1666                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1667                         /* init progress bar theme */
1668                         btheme->tui.wcol_progress = wcol_progress;
1669                 }
1670         }
1671
1672         if (bmain->versionfile < 255 || (bmain->versionfile == 255 && bmain->subversionfile < 2)) {
1673                 bTheme *btheme;
1674                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1675                         rgba_char_args_set(btheme->tv3d.extra_edge_len, 32, 0, 0, 255);
1676                         rgba_char_args_set(btheme->tv3d.extra_face_angle, 0, 32, 0, 255);
1677                         rgba_char_args_set(btheme->tv3d.extra_face_area, 0, 0, 128, 255);
1678                 }
1679         }
1680         
1681         if (bmain->versionfile < 256 || (bmain->versionfile == 256 && bmain->subversionfile < 4)) {
1682                 bTheme *btheme;
1683                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1684                         if ((btheme->tv3d.outline_width) == 0) btheme->tv3d.outline_width = 1;
1685                 }
1686         }
1687
1688         if (bmain->versionfile < 257) {
1689                 /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs, so that it doesn't linger around from old configs like a ghost */
1690                 U.autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET;
1691         }
1692
1693         if (bmain->versionfile < 258 || (bmain->versionfile == 258 && bmain->subversionfile < 2)) {
1694                 bTheme *btheme;
1695                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1696                         btheme->tnode.noodle_curving = 5;
1697                 }
1698         }
1699
1700         if (bmain->versionfile < 259 || (bmain->versionfile == 259 && bmain->subversionfile < 1)) {
1701                 bTheme *btheme;
1702                 
1703                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1704                         btheme->tv3d.speaker[3] = 255;
1705                 }
1706         }
1707
1708         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 3)) {
1709                 bTheme *btheme;
1710                 
1711                 /* if new keyframes handle default is stuff "auto", make it "auto-clamped" instead 
1712                  * was changed in 260 as part of GSoC11, but version patch was wrong
1713                  */
1714                 if (U.keyhandles_new == HD_AUTO) 
1715                         U.keyhandles_new = HD_AUTO_ANIM;
1716                 
1717                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1718                         if (btheme->tv3d.bundle_solid[3] == 0)
1719                                 rgba_char_args_set(btheme->tv3d.bundle_solid, 200, 200, 200, 255);
1720                         
1721                         if (btheme->tv3d.camera_path[3] == 0)
1722                                 rgba_char_args_set(btheme->tv3d.camera_path, 0x00, 0x00, 0x00, 255);
1723                                 
1724                         if ((btheme->tclip.back[3]) == 0) {
1725                                 btheme->tclip = btheme->tv3d;
1726                                 
1727                                 rgba_char_args_set(btheme->tclip.marker_outline, 0x00, 0x00, 0x00, 255);
1728                                 rgba_char_args_set(btheme->tclip.marker, 0x7f, 0x7f, 0x00, 255);
1729                                 rgba_char_args_set(btheme->tclip.act_marker, 0xff, 0xff, 0xff, 255);
1730                                 rgba_char_args_set(btheme->tclip.sel_marker, 0xff, 0xff, 0x00, 255);
1731                                 rgba_char_args_set(btheme->tclip.dis_marker, 0x7f, 0x00, 0x00, 255);
1732                                 rgba_char_args_set(btheme->tclip.lock_marker, 0x7f, 0x7f, 0x7f, 255);
1733                                 rgba_char_args_set(btheme->tclip.path_before, 0xff, 0x00, 0x00, 255);
1734                                 rgba_char_args_set(btheme->tclip.path_after, 0x00, 0x00, 0xff, 255);
1735                                 rgba_char_args_set(btheme->tclip.grid, 0x5e, 0x5e, 0x5e, 255);
1736                                 rgba_char_args_set(btheme->tclip.cframe, 0x60, 0xc0, 0x40, 255);
1737                                 rgba_char_args_set(btheme->tclip.handle_vertex, 0x00, 0x00, 0x00, 0xff);
1738                                 rgba_char_args_set(btheme->tclip.handle_vertex_select, 0xff, 0xff, 0, 0xff);
1739                                 btheme->tclip.handle_vertex_size = 4;
1740                         }
1741                         
1742                         /* auto-clamped handles -> based on auto */
1743                         if (btheme->tipo.handle_auto_clamped[3] == 0)
1744                                 rgba_char_args_set(btheme->tipo.handle_auto_clamped, 0x99, 0x40, 0x30, 255);
1745                         if (btheme->tipo.handle_sel_auto_clamped[3] == 0)
1746                                 rgba_char_args_set(btheme->tipo.handle_sel_auto_clamped, 0xf0, 0xaf, 0x90, 255);
1747                 }
1748                 
1749                 /* enable (Cycles) addon by default */
1750                 if (!BLI_findstring(&U.addons, "cycles", offsetof(bAddon, module))) {
1751                         bAddon *baddon = MEM_callocN(sizeof(bAddon), "bAddon");
1752                         BLI_strncpy(baddon->module, "cycles", sizeof(baddon->module));
1753                         BLI_addtail(&U.addons, baddon);
1754                 }
1755         }
1756         
1757         if (bmain->versionfile < 260 || (bmain->versionfile == 260 && bmain->subversionfile < 5)) {
1758                 bTheme *btheme;
1759                 
1760                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1761                         rgba_char_args_set(btheme->tui.panel.header, 0, 0, 0, 25);
1762                         btheme->tui.icon_alpha = 1.0;
1763                 }
1764         }
1765         
1766         if (bmain->versionfile < 261 || (bmain->versionfile == 261 && bmain->subversionfile < 4)) {
1767                 bTheme *btheme;
1768                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1769                         rgba_char_args_set_fl(btheme->tima.preview_stitch_face, 0.071, 0.259, 0.694, 0.150);
1770                         rgba_char_args_set_fl(btheme->tima.preview_stitch_edge, 1.0, 0.522, 0.0, 0.7);
1771                         rgba_char_args_set_fl(btheme->tima.preview_stitch_vert, 1.0, 0.522, 0.0, 0.5);
1772                         rgba_char_args_set_fl(btheme->tima.preview_stitch_stitchable, 0.0, 1.0, 0.0, 1.0);
1773                         rgba_char_args_set_fl(btheme->tima.preview_stitch_unstitchable, 1.0, 0.0, 0.0, 1.0);
1774                         rgba_char_args_set_fl(btheme->tima.preview_stitch_active, 0.886, 0.824, 0.765, 0.140);
1775                         
1776                         rgba_char_args_set_fl(btheme->toops.match, 0.2, 0.5, 0.2, 0.3);
1777                         rgba_char_args_set_fl(btheme->toops.selected_highlight, 0.51, 0.53, 0.55, 0.3);
1778                 }
1779                 
1780                 U.use_16bit_textures = TRUE;
1781         }
1782
1783         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 2)) {
1784                 bTheme *btheme;
1785                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1786                         if (btheme->tui.wcol_menu_item.item[3] == 255)
1787                                 rgba_char_args_set(btheme->tui.wcol_menu_item.item, 172, 172, 172, 128);
1788                 }
1789         }
1790
1791         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 3)) {
1792                 bTheme *btheme;
1793                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1794                         if (btheme->tui.wcol_tooltip.inner[3] == 0) {
1795                                 btheme->tui.wcol_tooltip = btheme->tui.wcol_menu_back;
1796                         }
1797                         if (btheme->tui.wcol_tooltip.text[0] == 160) { /* hrmf */
1798                                 rgba_char_args_set(btheme->tui.wcol_tooltip.text, 255, 255, 255, 255);
1799                         }
1800                 }
1801         }
1802
1803         if (bmain->versionfile < 262 || (bmain->versionfile == 262 && bmain->subversionfile < 4)) {
1804                 bTheme *btheme;
1805                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1806                         if (btheme->tseq.movieclip[0] == 0) {
1807                                 rgba_char_args_set(btheme->tseq.movieclip,  32, 32, 143, 255);
1808                         }
1809                 }
1810         }
1811
1812         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 2)) {
1813                 bTheme *btheme;
1814                 for (btheme = U.themes.first; btheme; btheme = btheme->next) {
1815                         if (btheme->tclip.strip[0] == 0) {
1816                                 rgba_char_args_set(btheme->tclip.list, 0x66, 0x66, 0x66, 0xff);
1817                                 rgba_char_args_set(btheme->tclip.strip, 0x0c, 0x0a, 0x0a, 0x80);
1818                                 rgba_char_args_set(btheme->tclip.strip_select, 0xff, 0x8c, 0x00, 0xff);
1819                         }
1820                 }
1821         }
1822
1823         if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 6)) {
1824                 bTheme *btheme;
1825                 for (btheme = U.themes.first; btheme; btheme = btheme->next)
1826                         rgba_char_args_set(btheme->tv3d.skin_root, 180, 77, 77, 255);
1827         }
1828
1829         /* Freestyle color settings */
1830         {
1831                 bTheme *btheme;
1832
1833                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1834                         /* check for alpha==0 is safe, then color was never set */
1835                         if(btheme->tv3d.freestyle_edge_mark[3]==0) {
1836                                 rgba_char_args_set(btheme->tv3d.freestyle_edge_mark, 0x7f, 0xff, 0x7f, 255);
1837                                 rgba_char_args_set(btheme->tv3d.freestyle_face_mark, 0x7f, 0xff, 0x7f, 51);
1838                         }
1839                 }
1840         }
1841
1842         /* GL Texture Garbage Collection (variable abused above!) */
1843         if (U.textimeout == 0) {
1844                 U.texcollectrate = 60;
1845                 U.textimeout = 120;
1846         }
1847         if (U.memcachelimit <= 0) {
1848                 U.memcachelimit = 32;
1849         }
1850         if (U.frameserverport == 0) {
1851                 U.frameserverport = 8080;
1852         }
1853         if (U.dbl_click_time == 0) {
1854                 U.dbl_click_time = 350;
1855         }
1856         if (U.anim_player_preset == 0) {
1857                 U.anim_player_preset = 1;
1858         }
1859         if (U.scrcastfps == 0) {
1860                 U.scrcastfps = 10;
1861                 U.scrcastwait = 50;
1862         }
1863         if (U.v2d_min_gridsize == 0) {
1864                 U.v2d_min_gridsize = 35;
1865         }
1866         if (U.dragthreshold == 0)
1867                 U.dragthreshold = 5;
1868         if (U.widget_unit == 0)
1869                 U.widget_unit = (U.dpi * 20 + 36) / 72;
1870         if (U.anisotropic_filter <= 0)
1871                 U.anisotropic_filter = 1;
1872
1873         if (U.ndof_sensitivity == 0.0f) {
1874                 U.ndof_sensitivity = 1.0f;
1875                 U.ndof_flag = NDOF_LOCK_HORIZON |
1876                               NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE;
1877         }
1878         if (U.tweak_threshold == 0)
1879                 U.tweak_threshold = 10;
1880
1881         /* funny name, but it is GE stuff, moves userdef stuff to engine */
1882 // XXX  space_set_commmandline_options();
1883         /* this timer uses U */
1884 // XXX  reset_autosave();
1885
1886 }