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