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