Progress indicators for threaded jobs
[blender.git] / source / blender / editors / interface / resources.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <math.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #include "MEM_guardedalloc.h"
38
39
40 #include "DNA_curve_types.h"
41 #include "DNA_userdef_types.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_space_types.h"
44 #include "DNA_windowmanager_types.h"
45
46 #include "BLI_blenlib.h"
47
48
49 #include "BKE_DerivedMesh.h"
50 #include "BKE_global.h"
51 #include "BKE_main.h"
52 #include "BKE_texture.h"
53 #include "BKE_utildefines.h"
54
55 #include "BIF_gl.h"
56
57 #include "UI_interface.h"
58 #include "UI_interface_icons.h"
59
60 #include "interface_intern.h"
61
62 /* global for themes */
63 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
64
65 static bTheme *theme_active=NULL;
66 static int theme_spacetype= SPACE_VIEW3D;
67 static int theme_regionid= RGN_TYPE_WINDOW;
68
69 void ui_resources_init(void)
70 {
71         UI_icons_init(BIFICONID_LAST);
72 }
73
74 void ui_resources_free(void)
75 {
76         UI_icons_free();
77 }
78
79
80 /* ******************************************************** */
81 /*    THEMES */
82 /* ******************************************************** */
83
84 char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
85 {
86         ThemeSpace *ts= NULL;
87         static char error[4]={240, 0, 240, 255};
88         static char alert[4]={240, 60, 60, 255};
89         static char headerdesel[4]={0,0,0,255};
90         
91         char *cp= error;
92         
93         if(btheme) {
94         
95                 // first check for ui buttons theme
96                 if(colorid < TH_THEMEUI) {
97                 
98                         switch(colorid) {
99
100                         case TH_REDALERT:
101                                 cp= alert; break;
102                         }
103                 }
104                 else {
105                 
106                         switch(spacetype) {
107                         case SPACE_BUTS:
108                                 ts= &btheme->tbuts;
109                                 break;
110                         case SPACE_VIEW3D:
111                                 ts= &btheme->tv3d;
112                                 break;
113                         case SPACE_IPO:
114                                 ts= &btheme->tipo;
115                                 break;
116                         case SPACE_FILE:
117                                 ts= &btheme->tfile;
118                                 break;
119                         case SPACE_NLA:
120                                 ts= &btheme->tnla;
121                                 break;
122                         case SPACE_ACTION:
123                                 ts= &btheme->tact;
124                                 break;
125                         case SPACE_SEQ:
126                                 ts= &btheme->tseq;
127                                 break;
128                         case SPACE_IMAGE:
129                                 ts= &btheme->tima;
130                                 break;
131                         case SPACE_IMASEL:
132                                 ts= &btheme->timasel;
133                                 break;
134                         case SPACE_TEXT:
135                                 ts= &btheme->text;
136                                 break;
137                         case SPACE_OUTLINER:
138                                 ts= &btheme->toops;
139                                 break;
140                         case SPACE_SOUND:
141                                 ts= &btheme->tsnd;
142                                 break;
143                         case SPACE_INFO:
144                                 ts= &btheme->tinfo;
145                                 break;
146                         case SPACE_USERPREF:
147                                 ts= &btheme->tuserpref;
148                                 break;
149                         case SPACE_CONSOLE:
150                                 ts= &btheme->tconsole;
151                                 break;
152                         case SPACE_TIME:
153                                 ts= &btheme->ttime;
154                                 break;
155                         case SPACE_NODE:
156                                 ts= &btheme->tnode;
157                                 break;
158                         case SPACE_LOGIC:
159                                 ts= &btheme->tlogic;
160                                 break;
161                         default:
162                                 ts= &btheme->tv3d;
163                                 break;
164                         }
165                         
166                         switch(colorid) {
167                         case TH_BACK:
168                                 if(theme_regionid==RGN_TYPE_WINDOW)
169                                         cp= ts->back;
170                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
171                                         cp= ts->list;
172                                 else if(theme_regionid==RGN_TYPE_HEADER)
173                                         cp= ts->header;
174                                 else
175                                         cp= ts->button; 
176                                 break;
177                         case TH_TEXT:
178                                 if(theme_regionid==RGN_TYPE_WINDOW)
179                                         cp= ts->text; 
180                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
181                                         cp= ts->list_text;
182                                 else if(theme_regionid==RGN_TYPE_HEADER)
183                                         cp= ts->header_text;
184                                 else
185                                         cp= ts->button_text; 
186                                 break;
187                         case TH_TEXT_HI:
188                                 if(theme_regionid==RGN_TYPE_WINDOW)
189                                         cp= ts->text_hi;
190                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
191                                         cp= ts->list_text_hi;
192                                 else if(theme_regionid==RGN_TYPE_HEADER)
193                                         cp= ts->header_text_hi;
194                                 else
195                                         cp= ts->button_text_hi; 
196                                 break;
197                         case TH_TITLE:
198                                 if(theme_regionid==RGN_TYPE_WINDOW)
199                                         cp= ts->title;
200                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
201                                         cp= ts->list_title;
202                                 else if(theme_regionid==RGN_TYPE_HEADER)
203                                         cp= ts->header_title;
204                                 else
205                                         cp= ts->button_title; 
206                                 break;
207                                 
208                         case TH_HEADER:
209                                 cp= ts->header; break;
210                         case TH_HEADERDESEL:
211                                 /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
212                                 cp= ts->header; 
213                                 headerdesel[0]= cp[0]>10?cp[0]-10:0;
214                                 headerdesel[1]= cp[1]>10?cp[1]-10:0;
215                                 headerdesel[2]= cp[2]>10?cp[2]-10:0;
216                                 cp= headerdesel;
217                                 break;
218                         case TH_HEADER_TEXT:
219                                 cp= ts->header_text; break;
220                         case TH_HEADER_TEXT_HI:
221                                 cp= ts->header_text_hi; break;
222                                 
223                         case TH_PANEL:
224                                 cp= ts->panel; break;
225                         case TH_PANEL_TEXT:
226                                 cp= ts->panel_text; break;
227                         case TH_PANEL_TEXT_HI:
228                                 cp= ts->panel_text_hi; break;
229                                 
230                         case TH_BUTBACK:
231                                 cp= ts->button; break;
232                         case TH_BUTBACK_TEXT:
233                                 cp= ts->button_text; break;
234                         case TH_BUTBACK_TEXT_HI:
235                                 cp= ts->button_text_hi; break;
236                                 
237                         case TH_SHADE1:
238                                 cp= ts->shade1; break;
239                         case TH_SHADE2:
240                                 cp= ts->shade2; break;
241                         case TH_HILITE:
242                                 cp= ts->hilite; break;
243                                 
244                         case TH_GRID:
245                                 cp= ts->grid; break;
246                         case TH_WIRE:
247                                 cp= ts->wire; break;
248                         case TH_LAMP:
249                                 cp= ts->lamp; break;
250                         case TH_SELECT:
251                                 cp= ts->select; break;
252                         case TH_ACTIVE:
253                                 cp= ts->active; break;
254                         case TH_GROUP:
255                                 cp= ts->group; break;
256                         case TH_GROUP_ACTIVE:
257                                 cp= ts->group_active; break;
258                         case TH_TRANSFORM:
259                                 cp= ts->transform; break;
260                         case TH_VERTEX:
261                                 cp= ts->vertex; break;
262                         case TH_VERTEX_SELECT:
263                                 cp= ts->vertex_select; break;
264                         case TH_VERTEX_SIZE:
265                                 cp= &ts->vertex_size; break;
266                         case TH_EDGE:
267                                 cp= ts->edge; break;
268                         case TH_EDGE_SELECT:
269                                 cp= ts->edge_select; break;
270                         case TH_EDGE_SEAM:
271                                 cp= ts->edge_seam; break;
272                         case TH_EDGE_SHARP:
273                                 cp= ts->edge_sharp; break;
274                         case TH_EDGE_CREASE:
275                                 cp= ts->edge_crease; break;
276                         case TH_EDITMESH_ACTIVE:
277                                 cp= ts->editmesh_active; break;
278                         case TH_EDGE_FACESEL:
279                                 cp= ts->edge_facesel; break;
280                         case TH_FACE:
281                                 cp= ts->face; break;
282                         case TH_FACE_SELECT:
283                                 cp= ts->face_select; break;
284                         case TH_FACE_DOT:
285                                 cp= ts->face_dot; break;
286                         case TH_FACEDOT_SIZE:
287                                 cp= &ts->facedot_size; break;
288                         case TH_NORMAL:
289                                 cp= ts->normal; break;
290                         case TH_VNORMAL:
291                                 cp= ts->vertex_normal; break;
292                         case TH_BONE_SOLID:
293                                 cp= ts->bone_solid; break;
294                         case TH_BONE_POSE:
295                                 cp= ts->bone_pose; break;
296                         case TH_STRIP:
297                                 cp= ts->strip; break;
298                         case TH_STRIP_SELECT:
299                                 cp= ts->strip_select; break;
300                         case TH_CFRAME:
301                                 cp= ts->cframe; break;
302                         case TH_NURB_ULINE:
303                                 cp= ts->nurb_uline; break;
304                         case TH_NURB_VLINE:
305                                 cp= ts->nurb_vline; break;
306                         case TH_NURB_SEL_ULINE:
307                                 cp= ts->nurb_sel_uline; break;
308                         case TH_NURB_SEL_VLINE:
309                                 cp= ts->nurb_sel_vline; break;
310                         case TH_ACTIVE_SPLINE:
311                                 cp= ts->act_spline; break;
312                         case TH_LASTSEL_POINT:
313                                 cp= ts->lastsel_point; break;
314                         case TH_HANDLE_FREE:
315                                 cp= ts->handle_free; break;
316                         case TH_HANDLE_AUTO:
317                                 cp= ts->handle_auto; break;
318                         case TH_HANDLE_VECT:
319                                 cp= ts->handle_vect; break;
320                         case TH_HANDLE_ALIGN:
321                                 cp= ts->handle_align; break;
322                         case TH_HANDLE_SEL_FREE:
323                                 cp= ts->handle_sel_free; break;
324                         case TH_HANDLE_SEL_AUTO:
325                                 cp= ts->handle_sel_auto; break;
326                         case TH_HANDLE_SEL_VECT:
327                                 cp= ts->handle_sel_vect; break;
328                         case TH_HANDLE_SEL_ALIGN:
329                                 cp= ts->handle_sel_align; break;
330
331                         case TH_SYNTAX_B:
332                                 cp= ts->syntaxb; break;
333                         case TH_SYNTAX_V:
334                                 cp= ts->syntaxv; break;
335                         case TH_SYNTAX_C:
336                                 cp= ts->syntaxc; break;
337                         case TH_SYNTAX_L:
338                                 cp= ts->syntaxl; break;
339                         case TH_SYNTAX_N:
340                                 cp= ts->syntaxn; break;
341
342                         case TH_NODE:
343                                 cp= ts->syntaxl; break;
344                         case TH_NODE_IN_OUT:
345                                 cp= ts->syntaxn; break;
346                         case TH_NODE_OPERATOR:
347                                 cp= ts->syntaxb; break;
348                         case TH_NODE_CONVERTOR:
349                                 cp= ts->syntaxv; break;
350                         case TH_NODE_GROUP:
351                                 cp= ts->syntaxc; break;
352                                 
353                         case TH_SEQ_MOVIE:
354                                 cp= ts->movie; break;
355                         case TH_SEQ_IMAGE:
356                                 cp= ts->image; break;
357                         case TH_SEQ_SCENE:
358                                 cp= ts->scene; break;
359                         case TH_SEQ_AUDIO:
360                                 cp= ts->audio; break;
361                         case TH_SEQ_EFFECT:
362                                 cp= ts->effect; break;
363                         case TH_SEQ_PLUGIN:
364                                 cp= ts->plugin; break;
365                         case TH_SEQ_TRANSITION:
366                                 cp= ts->transition; break;
367                         case TH_SEQ_META:
368                                 cp= ts->meta; break;
369                                 
370                         case TH_CONSOLE_OUTPUT:
371                                 cp= ts->console_output; break;
372                         case TH_CONSOLE_INPUT:
373                                 cp= ts-> console_input; break;
374                         case TH_CONSOLE_INFO:
375                                 cp= ts->console_info; break;
376                         case TH_CONSOLE_ERROR:
377                                 cp= ts->console_error; break;
378                         case TH_CONSOLE_CURSOR:
379                                 cp= ts->console_cursor; break;
380
381                         case TH_HANDLE_VERTEX:
382                                 cp= ts->handle_vertex;
383                                 break;
384                         case TH_HANDLE_VERTEX_SELECT:
385                                 cp= ts->handle_vertex_select;
386                                 break;
387                         case TH_HANDLE_VERTEX_SIZE:
388                                 cp= &ts->handle_vertex_size;
389                                 break;
390                                 
391                         case TH_DOPESHEET_CHANNELOB:
392                                 cp= ts->ds_channel;
393                                 break;
394                         case TH_DOPESHEET_CHANNELSUBOB:
395                                 cp= ts->ds_subchannel;
396                                 break;  
397                                         
398                         case TH_PREVIEW_BACK:
399                                 cp= ts->preview_back;
400                                 break;  
401                         }
402                 }
403         }
404         
405         return cp;
406 }
407
408 #define SETCOLTEST(col, r, g, b, a)  if(col[3]==0) {col[0]=r; col[1]=g; col[2]= b; col[3]= a;}
409
410 /* use this call to init new variables in themespace, if they're same for all */
411 static void ui_theme_init_new_do(ThemeSpace *ts)
412 {
413         SETCOLTEST(ts->header_text,             0, 0, 0, 255);
414         SETCOLTEST(ts->header_title,    0, 0, 0, 255);
415         SETCOLTEST(ts->header_text_hi,  255, 255, 255, 255);
416         
417         SETCOLTEST(ts->panel_text,              0, 0, 0, 255);
418         SETCOLTEST(ts->panel_title,             0, 0, 0, 255);
419         SETCOLTEST(ts->panel_text_hi,   255, 255, 255, 255);
420         
421         SETCOLTEST(ts->button,                  145, 145, 145, 245);
422         SETCOLTEST(ts->button_title,    0, 0, 0, 255);
423         SETCOLTEST(ts->button_text,             0, 0, 0, 255);
424         SETCOLTEST(ts->button_text_hi,  255, 255, 255, 255);
425         
426         SETCOLTEST(ts->list,                    165, 165, 165, 255);
427         SETCOLTEST(ts->list_title,              0, 0, 0, 255);
428         SETCOLTEST(ts->list_text,               0, 0, 0, 255);
429         SETCOLTEST(ts->list_text_hi,    255, 255, 255, 255);
430 }
431
432 static void ui_theme_init_new(bTheme *btheme)
433 {
434         ui_theme_init_new_do(&btheme->tbuts);
435         ui_theme_init_new_do(&btheme->tv3d);
436         ui_theme_init_new_do(&btheme->tfile);
437         ui_theme_init_new_do(&btheme->tipo);
438         ui_theme_init_new_do(&btheme->tinfo);
439         ui_theme_init_new_do(&btheme->tsnd);
440         ui_theme_init_new_do(&btheme->tact);
441         ui_theme_init_new_do(&btheme->tnla);
442         ui_theme_init_new_do(&btheme->tseq);
443         ui_theme_init_new_do(&btheme->tima);
444         ui_theme_init_new_do(&btheme->timasel);
445         ui_theme_init_new_do(&btheme->text);
446         ui_theme_init_new_do(&btheme->toops);
447         ui_theme_init_new_do(&btheme->ttime);
448         ui_theme_init_new_do(&btheme->tnode);
449         ui_theme_init_new_do(&btheme->tlogic);
450         ui_theme_init_new_do(&btheme->tuserpref);
451         ui_theme_init_new_do(&btheme->tconsole);
452         
453 }
454
455 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
456 #define SETCOLF(col, r, g, b, a)  col[0]=r*255; col[1]=g*255; col[2]= b*255; col[3]= a*255;
457
458 /* initialize default theme
459    Note: when you add new colors, created & saved themes need initialized
460    use function below, init_userdef_do_versions() 
461 */
462 void ui_theme_init_default(void)
463 {
464         bTheme *btheme= U.themes.first;
465         
466         /* we search for the theme with name Default */
467         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
468                 if(strcmp("Default", btheme->name)==0) break;
469         }
470         
471         if(btheme==NULL) {
472                 btheme= MEM_callocN(sizeof(bTheme), "theme");
473                 BLI_addtail(&U.themes, btheme);
474                 strcpy(btheme->name, "Default");
475         }
476         
477         UI_SetTheme(0, 0);      // make sure the global used in this file is set
478
479         /* UI buttons */
480         ui_widget_color_init(&btheme->tui);
481
482         /* common (new) variables */
483         ui_theme_init_new(btheme);
484         
485         /* space view3d */
486         SETCOLF(btheme->tv3d.back,       0.225, 0.225, 0.225, 1.0);
487         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
488         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
489         
490         SETCOLF(btheme->tv3d.header,    0.45, 0.45, 0.45, 1.0);
491         SETCOLF(btheme->tv3d.button,    0.45, 0.45, 0.45, 1.0);
492         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
493         
494         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
495         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
496
497         SETCOLF(btheme->tv3d.grid,     0.251, 0.251, 0.251, 1.0);
498         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
499         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
500         SETCOL(btheme->tv3d.select, 241, 88, 0, 255);
501         SETCOL(btheme->tv3d.active, 255, 140, 25, 255);
502         SETCOL(btheme->tv3d.group,      8, 48, 8, 255);
503         SETCOL(btheme->tv3d.group_active, 85, 187, 85, 255);
504         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
505         SETCOL(btheme->tv3d.vertex, 0, 0, 0, 255);
506         SETCOL(btheme->tv3d.vertex_select, 255, 133, 0, 255);
507         btheme->tv3d.vertex_size= 3;
508         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
509         SETCOL(btheme->tv3d.edge_select, 255, 160, 0, 255);
510         SETCOL(btheme->tv3d.edge_seam, 219, 37, 18, 255);
511         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
512         SETCOL(btheme->tv3d.face,       0, 0, 0, 18);
513         SETCOL(btheme->tv3d.face_select, 255, 133, 0, 60);
514         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
515         SETCOL(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
516         SETCOL(btheme->tv3d.face_dot, 255, 133, 0, 255);
517         btheme->tv3d.facedot_size= 4;
518         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0,  0x40, 255);
519
520         SETCOL(btheme->tv3d.nurb_uline, 0x90, 0x90, 0x00, 255);
521         SETCOL(btheme->tv3d.nurb_vline, 0x80, 0x30, 0x60, 255);
522         SETCOL(btheme->tv3d.nurb_sel_uline, 0xf0, 0xff, 0x40, 255);
523         SETCOL(btheme->tv3d.nurb_sel_vline, 0xf0, 0x90, 0xa0, 255);
524
525         SETCOL(btheme->tv3d.handle_free, 0, 0, 0, 255);
526         SETCOL(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
527         SETCOL(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
528         SETCOL(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
529         SETCOL(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
530         SETCOL(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
531         SETCOL(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
532         SETCOL(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
533
534         SETCOL(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
535         SETCOL(btheme->tv3d.lastsel_point,  0xff, 0xff, 0xff, 255);
536
537         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
538         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
539         
540         
541         /* space buttons */
542         /* to have something initialized */
543         btheme->tbuts= btheme->tv3d;
544
545         SETCOLF(btheme->tbuts.back,     0.45, 0.45, 0.45, 1.0);
546         SETCOL(btheme->tbuts.panel, 0x82, 0x82, 0x82, 255);
547
548         /* graph editor */
549         btheme->tipo= btheme->tv3d;
550         SETCOLF(btheme->tipo.back,      0.42, 0.42, 0.42, 1.0);
551         SETCOLF(btheme->tipo.list,      0.4, 0.4, 0.4, 1.0);
552         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
553         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
554         SETCOL(btheme->tipo.shade1,             150, 150, 150, 100);    /* scrollbars */
555         SETCOL(btheme->tipo.shade2,             0x70, 0x70, 0x70, 100);
556         SETCOL(btheme->tipo.vertex,             0, 0, 0, 255);
557         SETCOL(btheme->tipo.vertex_select, 255, 133, 0, 255);
558         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
559         btheme->tipo.vertex_size= 3;
560
561         SETCOL(btheme->tipo.handle_vertex,              0, 0, 0, 255);
562         SETCOL(btheme->tipo.handle_vertex_select, 255, 133, 0, 255);
563         btheme->tipo.handle_vertex_size= 3;
564         
565         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
566         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
567         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
568         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
569
570         /* dopesheet */
571         btheme->tact= btheme->tipo;
572         SETCOL(btheme->tact.strip,                      12, 10, 10, 128); 
573         SETCOL(btheme->tact.strip_select,       255, 140, 0, 255); 
574         
575         /* space nla */
576         btheme->tnla= btheme->tact;
577         
578         /* space file */
579         /* to have something initialized */
580         btheme->tfile= btheme->tv3d;
581         SETCOLF(btheme->tfile.back, 0.3, 0.3, 0.3, 1);
582         SETCOLF(btheme->tfile.panel, 0.3, 0.3, 0.3, 1);
583         SETCOLF(btheme->tfile.list, 0.4, 0.4, 0.4, 1);
584         SETCOL(btheme->tfile.text,      250, 250, 250, 255);
585         SETCOL(btheme->tfile.text_hi, 15, 15, 15, 255);
586         SETCOL(btheme->tfile.panel, 145, 145, 145, 255);        // bookmark/ui regions
587         SETCOL(btheme->tfile.active, 130, 130, 130, 255); // selected files
588         SETCOL(btheme->tfile.hilite, 255, 140, 25, 255); // selected files
589         
590         SETCOL(btheme->tfile.grid,      250, 250, 250, 255);
591         SETCOL(btheme->tfile.image,     250, 250, 250, 255);
592         SETCOL(btheme->tfile.movie,     250, 250, 250, 255);
593         SETCOL(btheme->tfile.scene,     250, 250, 250, 255);
594
595         
596         /* space seq */
597         btheme->tseq= btheme->tv3d;
598         SETCOL(btheme->tseq.back,       116, 116, 116, 255);
599         SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
600         SETCOL(btheme->tseq.image,      109, 88, 129, 255);
601         SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
602         SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
603         SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
604         SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
605         SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
606         SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
607         
608
609         /* space image */
610         btheme->tima= btheme->tv3d;
611         SETCOL(btheme->tima.back,       53, 53, 53, 255);
612         SETCOL(btheme->tima.vertex, 0, 0, 0, 255);
613         SETCOL(btheme->tima.vertex_select, 255, 133, 0, 255);
614         btheme->tima.vertex_size= 3;
615         btheme->tima.facedot_size= 3;
616         SETCOL(btheme->tima.face,   255, 255, 255, 10);
617         SETCOL(btheme->tima.face_select, 255, 133, 0, 60);
618         SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
619         SETCOLF(btheme->tima.preview_back,      0.45, 0.45, 0.45, 1.0);
620
621         /* space imageselect */
622         btheme->timasel= btheme->tv3d;
623         SETCOL(btheme->timasel.active,  195, 195, 195, 255); /* active tile */
624         SETCOL(btheme->timasel.grid,  94, 94, 94, 255); /* active file text */
625         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
626         SETCOL(btheme->timasel.shade1,  94, 94, 94, 255);       /* bar */
627         SETCOL(btheme->timasel.shade2,  172, 172, 172, 255); /* sliders */
628         SETCOL(btheme->timasel.hilite,  17, 27, 60, 100);       /* selected tile */
629         SETCOL(btheme->timasel.text,    0, 0, 0, 255);
630         SETCOL(btheme->timasel.text_hi, 255, 255, 255, 255);
631         SETCOL(btheme->timasel.panel,   132, 132, 132, 255);
632
633         /* space text */
634         btheme->text= btheme->tv3d;
635         SETCOL(btheme->text.back,       153, 153, 153, 255);
636         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
637         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
638         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
639         
640         /* syntax highlighting */
641         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
642         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
643         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
644         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
645         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
646         
647         /* space oops */
648         btheme->toops= btheme->tv3d;
649         SETCOLF(btheme->toops.back,     0.45, 0.45, 0.45, 1.0);
650         
651         /* space info */
652         btheme->tinfo= btheme->tv3d;
653         SETCOLF(btheme->tinfo.back,     0.45, 0.45, 0.45, 1.0);
654
655         /* space user preferences */
656         btheme->tuserpref= btheme->tv3d;
657         SETCOLF(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
658         
659         /* space console */
660         btheme->tconsole= btheme->tv3d;
661         SETCOL(btheme->tconsole.back, 0, 0, 0, 255);
662         SETCOL(btheme->tconsole.console_output, 96, 128, 255, 255);
663         SETCOL(btheme->tconsole.console_input, 255, 255, 255, 255);
664         SETCOL(btheme->tconsole.console_info, 0, 170, 0, 255);
665         SETCOL(btheme->tconsole.console_error, 220, 96, 96, 255);
666         SETCOL(btheme->tconsole.console_cursor, 220, 96, 96, 255);
667         
668
669         /* space sound */
670         btheme->tsnd= btheme->tv3d;
671         SETCOLF(btheme->tsnd.back,      0.45, 0.45, 0.45, 1.0);
672         SETCOLF(btheme->tsnd.grid,      0.36, 0.36, 0.36, 1.0);
673         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
674         
675         /* space time */
676         btheme->ttime= btheme->tsnd;    // same as sound space
677         
678         /* space node, re-uses syntax color storage */
679         btheme->tnode= btheme->tv3d;
680         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
681         SETCOL(btheme->tnode.syntaxl, 155, 155, 155, 160);      /* TH_NODE, backdrop */
682         SETCOL(btheme->tnode.syntaxn, 100, 100, 100, 255);      /* in/output */
683         SETCOL(btheme->tnode.syntaxb, 108, 105, 111, 255);      /* operator */
684         SETCOL(btheme->tnode.syntaxv, 104, 106, 117, 255);      /* generator */
685         SETCOL(btheme->tnode.syntaxc, 105, 117, 110, 255);      /* group */
686
687         /* space logic */
688         btheme->tlogic= btheme->tv3d;
689         SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
690         
691 }
692
693
694 void UI_SetTheme(int spacetype, int regionid)
695 {
696         if(spacetype==0) {      // called for safety, when delete themes
697                 theme_active= U.themes.first;
698                 theme_spacetype= SPACE_VIEW3D;
699                 theme_regionid= RGN_TYPE_WINDOW;
700         }
701         else {
702                 // later on, a local theme can be found too
703                 theme_active= U.themes.first;
704                 theme_spacetype= spacetype;
705                 theme_regionid= regionid;
706         }
707 }
708
709 // for space windows only
710 void UI_ThemeColor(int colorid)
711 {
712         char *cp;
713         
714         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
715         glColor3ub(cp[0], cp[1], cp[2]);
716
717 }
718
719 // plus alpha
720 void UI_ThemeColor4(int colorid)
721 {
722         char *cp;
723         
724         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
725         glColor4ub(cp[0], cp[1], cp[2], cp[3]);
726
727 }
728
729 // set the color with offset for shades
730 void UI_ThemeColorShade(int colorid, int offset)
731 {
732         int r, g, b;
733         char *cp;
734         
735         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
736         r= offset + (int) cp[0];
737         CLAMP(r, 0, 255);
738         g= offset + (int) cp[1];
739         CLAMP(g, 0, 255);
740         b= offset + (int) cp[2];
741         CLAMP(b, 0, 255);
742         //glColor3ub(r, g, b);
743         glColor4ub(r, g, b, cp[3]);
744 }
745 void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
746 {
747         int r, g, b, a;
748         char *cp;
749         
750         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
751         r= coloffset + (int) cp[0];
752         CLAMP(r, 0, 255);
753         g= coloffset + (int) cp[1];
754         CLAMP(g, 0, 255);
755         b= coloffset + (int) cp[2];
756         CLAMP(b, 0, 255);
757         a= alphaoffset + (int) cp[3];
758         CLAMP(a, 0, 255);
759         glColor4ub(r, g, b, a);
760 }
761
762 // blend between to theme colors, and set it
763 void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
764 {
765         int r, g, b;
766         char *cp1, *cp2;
767         
768         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
769         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
770
771         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
772         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
773         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
774         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
775         
776         glColor3ub(r, g, b);
777 }
778
779 // blend between to theme colors, shade it, and set it
780 void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
781 {
782         int r, g, b;
783         char *cp1, *cp2;
784         
785         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
786         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
787
788         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
789         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
790         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
791         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
792         
793         CLAMP(r, 0, 255);
794         CLAMP(g, 0, 255);
795         CLAMP(b, 0, 255);
796         
797         glColor3ub(r, g, b);
798 }
799
800 // blend between to theme colors, shade it, and set it
801 void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
802 {
803         int r, g, b, a;
804         char *cp1, *cp2;
805         
806         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
807         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
808
809         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
810         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
811         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
812         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
813         a= alphaoffset+floor((1.0-fac)*cp1[3] + fac*cp2[3]);
814         
815         CLAMP(r, 0, 255);
816         CLAMP(g, 0, 255);
817         CLAMP(b, 0, 255);
818         CLAMP(a, 0, 255);
819
820         glColor4ub(r, g, b, a);
821 }
822
823
824 // get individual values, not scaled
825 float UI_GetThemeValuef(int colorid)
826 {
827         char *cp;
828         
829         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
830         return ((float)cp[0]);
831
832 }
833
834 // get individual values, not scaled
835 int UI_GetThemeValue(int colorid)
836 {
837         char *cp;
838         
839         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
840         return ((int) cp[0]);
841
842 }
843
844
845 // get the color, range 0.0-1.0
846 void UI_GetThemeColor3fv(int colorid, float *col)
847 {
848         char *cp;
849         
850         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
851         col[0]= ((float)cp[0])/255.0;
852         col[1]= ((float)cp[1])/255.0;
853         col[2]= ((float)cp[2])/255.0;
854 }
855
856 // get the color, range 0.0-1.0, complete with shading offset
857 void UI_GetThemeColorShade3fv(int colorid, int offset, float *col)
858 {
859         int r, g, b;
860         char *cp;
861         
862         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
863         
864         r= offset + (int) cp[0];
865         CLAMP(r, 0, 255);
866         g= offset + (int) cp[1];
867         CLAMP(g, 0, 255);
868         b= offset + (int) cp[2];
869         CLAMP(b, 0, 255);
870         
871         col[0]= ((float)r)/255.0;
872         col[1]= ((float)g)/255.0;
873         col[2]= ((float)b)/255.0;
874 }
875
876 // get the color, in char pointer
877 void UI_GetThemeColor3ubv(int colorid, char *col)
878 {
879         char *cp;
880         
881         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
882         col[0]= cp[0];
883         col[1]= cp[1];
884         col[2]= cp[2];
885 }
886
887 // get the color, in char pointer
888 void UI_GetThemeColor4ubv(int colorid, char *col)
889 {
890         char *cp;
891         
892         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
893         col[0]= cp[0];
894         col[1]= cp[1];
895         col[2]= cp[2];
896         col[3]= cp[3];
897 }
898
899 void UI_GetThemeColorType4ubv(int colorid, int spacetype, char *col)
900 {
901         char *cp;
902         
903         cp= UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
904         col[0]= cp[0];
905         col[1]= cp[1];
906         col[2]= cp[2];
907         col[3]= cp[3];
908 }
909
910 // blends and shades between two char color pointers
911 void UI_ColorPtrBlendShade3ubv(char *cp1, char *cp2, float fac, int offset)
912 {
913         int r, g, b;
914         
915         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
916         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
917         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
918         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
919         
920         r= r<0?0:(r>255?255:r);
921         g= g<0?0:(g>255?255:g);
922         b= b<0?0:(b>255?255:b);
923         
924         glColor3ub(r, g, b);
925 }
926
927 // get a 3 byte color, blended and shaded between two other char color pointers
928 void UI_GetColorPtrBlendShade3ubv(char *cp1, char *cp2, char *col, float fac, int offset)
929 {
930         int r, g, b;
931         
932         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
933         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
934         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
935         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
936         
937         r= r<0?0:(r>255?255:r);
938         g= g<0?0:(g>255?255:g);
939         b= b<0?0:(b>255?255:b);
940         
941         col[0] = r;
942         col[1] = g;
943         col[2] = b;
944 }
945
946 void UI_ThemeClearColor(int colorid)
947 {
948         float col[3];
949         
950         UI_GetThemeColor3fv(colorid, col);
951         glClearColor(col[0], col[1], col[2], 0.0);
952 }
953
954 void UI_make_axis_color(char *src_col, char *dst_col, char axis)
955 {
956         switch(axis)
957         {
958                 case 'x':
959                 case 'X':
960                         dst_col[0]= src_col[0]>219?255:src_col[0]+36;
961                         dst_col[1]= src_col[1]<26?0:src_col[1]-26;
962                         dst_col[2]= src_col[2]<26?0:src_col[2]-26;
963                         break;
964                 case 'y':
965                 case 'Y':
966                         dst_col[0]= src_col[0]<46?0:src_col[0]-36;
967                         dst_col[1]= src_col[1]>189?255:src_col[1]+66;
968                         dst_col[2]= src_col[2]<46?0:src_col[2]-36;
969                         break;
970                 default: 
971                         dst_col[0]= src_col[0]<26?0:src_col[0]-26; 
972                         dst_col[1]= src_col[1]<26?0:src_col[1]-26; 
973                         dst_col[2]= src_col[2]>209?255:src_col[2]+46;
974         }
975 }
976
977 /* ************************************************************* */
978
979 /* patching UserDef struct and Themes */
980 void init_userdef_do_versions(void)
981 {
982 //      countall();
983         
984         /* the UserDef struct is not corrected with do_versions() .... ugh! */
985         if(U.wheellinescroll == 0) U.wheellinescroll = 3;
986         if(U.menuthreshold1==0) {
987                 U.menuthreshold1= 5;
988                 U.menuthreshold2= 2;
989         }
990         if(U.tb_leftmouse==0) {
991                 U.tb_leftmouse= 5;
992                 U.tb_rightmouse= 5;
993         }
994         if(U.mixbufsize==0) U.mixbufsize= 2048;
995         if (BLI_streq(U.tempdir, "/")) {
996                 char *tmp= getenv("TEMP");
997                 
998                 strcpy(U.tempdir, tmp?tmp:"/tmp/");
999         }
1000         if (U.savetime <= 0) {
1001                 U.savetime = 1;
1002 // XXX          error(".B.blend is buggy, please consider removing it.\n");
1003         }
1004         /* transform widget settings */
1005         if(U.tw_hotspot==0) {
1006                 U.tw_hotspot= 14;
1007                 U.tw_size= 20;                  // percentage of window size
1008                 U.tw_handlesize= 16;    // percentage of widget radius
1009         }
1010         if(U.pad_rot_angle==0)
1011                 U.pad_rot_angle= 15;
1012         
1013         if(U.flag & USER_CUSTOM_RANGE) 
1014                 vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
1015         
1016         if (G.main->versionfile <= 191) {
1017                 strcpy(U.plugtexdir, U.textudir);
1018                 strcpy(U.sounddir, "/");
1019         }
1020         
1021         /* patch to set Dupli Armature */
1022         if (G.main->versionfile < 220) {
1023                 U.dupflag |= USER_DUP_ARM;
1024         }
1025         
1026         /* added seam, normal color, undo */
1027         if (G.main->versionfile <= 234) {
1028                 bTheme *btheme;
1029                 
1030                 U.uiflag |= USER_GLOBALUNDO;
1031                 if (U.undosteps==0) U.undosteps=32;
1032                 
1033                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1034                         /* check for alpha==0 is safe, then color was never set */
1035                         if(btheme->tv3d.edge_seam[3]==0) {
1036                                 SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
1037                         }
1038                         if(btheme->tv3d.normal[3]==0) {
1039                                 SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
1040                         }
1041                         if(btheme->tv3d.vertex_normal[3]==0) {
1042                                 SETCOL(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
1043                         }
1044                         if(btheme->tv3d.face_dot[3]==0) {
1045                                 SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
1046                                 btheme->tv3d.facedot_size= 4;
1047                         }
1048                 }
1049         }
1050         if (G.main->versionfile <= 235) {
1051                 /* illegal combo... */
1052                 if (U.flag & USER_LMOUSESELECT) 
1053                         U.flag &= ~USER_TWOBUTTONMOUSE;
1054         }
1055         if (G.main->versionfile <= 236) {
1056                 bTheme *btheme;
1057                 /* new space type */
1058                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1059                         /* check for alpha==0 is safe, then color was never set */
1060                         if(btheme->ttime.back[3]==0) {
1061                                 btheme->ttime = btheme->tsnd;   // copy from sound
1062                         }
1063                         if(btheme->text.syntaxn[3]==0) {
1064                                 SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
1065                                 SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
1066                                 SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
1067                                 SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
1068                                 SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
1069                         }
1070                 }
1071         }
1072         if (G.main->versionfile <= 237) {
1073                 bTheme *btheme;
1074                 /* bone colors */
1075                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1076                         /* check for alpha==0 is safe, then color was never set */
1077                         if(btheme->tv3d.bone_solid[3]==0) {
1078                                 SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
1079                                 SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
1080                         }
1081                 }
1082         }
1083         if (G.main->versionfile <= 238) {
1084                 bTheme *btheme;
1085                 /* bone colors */
1086                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1087                         /* check for alpha==0 is safe, then color was never set */
1088                         if(btheme->tnla.strip[3]==0) {
1089                                 SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
1090                                 SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
1091                         }
1092                 }
1093         }
1094         if (G.main->versionfile <= 239) {
1095                 bTheme *btheme;
1096                 
1097                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1098                         /* Lamp theme, check for alpha==0 is safe, then color was never set */
1099                         if(btheme->tv3d.lamp[3]==0) {
1100                                 SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
1101 /* TEMPORAL, remove me! (ton) */                                
1102                                 U.uiflag |= USER_PLAINMENUS;
1103                         }
1104                         
1105                 }
1106                 if(U.obcenter_dia==0) U.obcenter_dia= 6;
1107         }
1108         if (G.main->versionfile <= 241) {
1109                 bTheme *btheme;
1110                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1111                         /* Node editor theme, check for alpha==0 is safe, then color was never set */
1112                         if(btheme->tnode.syntaxn[3]==0) {
1113                                 /* re-uses syntax color storage */
1114                                 btheme->tnode= btheme->tv3d;
1115                                 SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
1116                                 SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
1117                                 SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
1118                                 SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
1119                                 SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
1120                                 SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
1121                         }
1122                         /* Group theme colors */
1123                         if(btheme->tv3d.group[3]==0) {
1124                                 SETCOL(btheme->tv3d.group, 0x0C, 0x30, 0x0C, 255);
1125                                 SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
1126                         }
1127                         /* Sequence editor theme*/
1128                         if(btheme->tseq.movie[3]==0) {
1129                                 SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
1130                                 SETCOL(btheme->tseq.image,      109, 88, 129, 255);
1131                                 SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
1132                                 SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
1133                                 SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
1134                                 SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
1135                                 SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
1136                                 SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
1137                         }
1138                 }
1139                 
1140                 /* set defaults for 3D View rotating axis indicator */ 
1141                 /* since size can't be set to 0, this indicates it's not saved in .B.blend */
1142                 if (U.rvisize == 0) {
1143                         U.rvisize = 15;
1144                         U.rvibright = 8;
1145                         U.uiflag |= USER_SHOW_ROTVIEWICON;
1146                 }
1147                 
1148         }
1149         if (G.main->versionfile <= 242) {
1150                 bTheme *btheme;
1151                 
1152                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1153                         /* long keyframe color */
1154                         /* check for alpha==0 is safe, then color was never set */
1155                         if(btheme->tact.strip[3]==0) {
1156                                 SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
1157                                 SETCOL(btheme->tact.strip_select,       0xff, 0xff, 0xaa, 204);
1158                                 SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
1159                         }
1160                         
1161                         /* IPO-Editor - Vertex Size*/
1162                         if(btheme->tipo.vertex_size == 0) {
1163                                 btheme->tipo.vertex_size= 3;
1164                         }
1165                 }
1166         }
1167         if (G.main->versionfile <= 243) {
1168                 /* set default number of recently-used files (if not set) */
1169                 if (U.recent_files == 0) U.recent_files = 10;
1170         }
1171         if (G.main->versionfile < 245 || (G.main->versionfile == 245 && G.main->subversionfile < 3)) {
1172                 bTheme *btheme;
1173                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1174                         SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
1175                 }
1176                 if(U.coba_weight.tot==0)
1177                         init_colorband(&U.coba_weight, 1);
1178         }
1179         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
1180                 bTheme *btheme;
1181                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1182                         /* these should all use the same colour */
1183                         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1184                         SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1185                         SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1186                         SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1187                         SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1188                         SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
1189                         SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1190                 }
1191         }
1192         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 13)) {
1193                 bTheme *btheme;
1194                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1195                         /* action channel groups (recolor anyway) */
1196                         SETCOL(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
1197                         SETCOL(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
1198                         
1199                         /* bone custom-color sets */
1200                         // FIXME: this check for initialised colors is bad
1201                         if (btheme->tarm[0].solid[3] == 0) {
1202                                         /* set 1 */
1203                                 SETCOL(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
1204                                 SETCOL(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
1205                                 SETCOL(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
1206                                         /* set 2 */
1207                                 SETCOL(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
1208                                 SETCOL(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
1209                                 SETCOL(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
1210                                         /* set 3 */
1211                                 SETCOL(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
1212                                 SETCOL(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
1213                                 SETCOL(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
1214                                         /* set 4 */
1215                                 SETCOL(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
1216                                 SETCOL(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
1217                                 SETCOL(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
1218                                         /* set 5 */
1219                                 SETCOL(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
1220                                 SETCOL(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
1221                                 SETCOL(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
1222                                         /* set 6 */
1223                                 SETCOL(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
1224                                 SETCOL(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
1225                                 SETCOL(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
1226                                         /* set 7 */
1227                                 SETCOL(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
1228                                 SETCOL(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
1229                                 SETCOL(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
1230                                         /* set 8 */
1231                                 SETCOL(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
1232                                 SETCOL(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
1233                                 SETCOL(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
1234                                         /* set 9 */
1235                                 SETCOL(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
1236                                 SETCOL(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
1237                                 SETCOL(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
1238                                         /* set 10 */
1239                                 SETCOL(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
1240                                 SETCOL(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
1241                                 SETCOL(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
1242                                         /* set 11 */
1243                                 SETCOL(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
1244                                 SETCOL(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
1245                                 SETCOL(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
1246                                         /* set 12 */
1247                                 SETCOL(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
1248                                 SETCOL(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
1249                                 SETCOL(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
1250                                         /* set 13 */
1251                                 SETCOL(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
1252                                 SETCOL(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
1253                                 SETCOL(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
1254                                         /* set 14 */
1255                                 SETCOL(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
1256                                 SETCOL(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
1257                                 SETCOL(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
1258                                         /* set 15 */
1259                                 SETCOL(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
1260                                 SETCOL(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
1261                                 SETCOL(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
1262                         }
1263                 }
1264         }
1265         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 16)) {
1266                 U.flag |= USER_ADD_VIEWALIGNED|USER_ADD_EDITMODE;
1267         }
1268         if ((G.main->versionfile < 247) || (G.main->versionfile == 247 && G.main->subversionfile <= 2)) {
1269                 bTheme *btheme;
1270                 
1271                 /* adjust themes */
1272                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1273                         char *col;
1274                         
1275                         /* IPO Editor: Handles/Vertices */
1276                         col = btheme->tipo.vertex;
1277                         SETCOL(btheme->tipo.handle_vertex, col[0], col[1], col[2], 255);
1278                         col = btheme->tipo.vertex_select;
1279                         SETCOL(btheme->tipo.handle_vertex_select, col[0], col[1], col[2], 255);
1280                         btheme->tipo.handle_vertex_size= btheme->tipo.vertex_size;
1281                         
1282                         /* Sequence/Image Editor: colors for GPencil text */
1283                         col = btheme->tv3d.bone_pose;
1284                         SETCOL(btheme->tseq.bone_pose, col[0], col[1], col[2], 255);
1285                         SETCOL(btheme->tima.bone_pose, col[0], col[1], col[2], 255);
1286                         col = btheme->tv3d.vertex_select;
1287                         SETCOL(btheme->tseq.vertex_select, col[0], col[1], col[2], 255);
1288                 }
1289         }
1290         if (G.main->versionfile < 250) {
1291                 bTheme *btheme;
1292                 
1293                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1294                         /* this was not properly initialized in 2.45 */
1295                         if(btheme->tima.face_dot[3]==0) {
1296                                 SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
1297                                 SETCOL(btheme->tima.face_dot, 255, 133, 0, 255);
1298                                 btheme->tima.facedot_size= 2;
1299                         }
1300                         
1301                         /* DopeSheet - (Object) Channel color */
1302                         SETCOL(btheme->tact.ds_channel,         82, 96, 110, 255);
1303                         SETCOL(btheme->tact.ds_subchannel,      124, 137, 150, 255);
1304                         /* DopeSheet - Group Channel color (saner version) */
1305                         SETCOL(btheme->tact.group, 79, 101, 73, 255);
1306                         SETCOL(btheme->tact.group_active, 135, 177, 125, 255);
1307                         
1308                         /* Graph Editor - (Object) Channel color */
1309                         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
1310                         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
1311                         /* Graph Editor - Group Channel color */
1312                         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
1313                         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
1314                         
1315                         /* Nla Editor - (Object) Channel color */
1316                         SETCOL(btheme->tnla.ds_channel,         82, 96, 110, 255);
1317                         SETCOL(btheme->tnla.ds_subchannel,      124, 137, 150, 255);
1318                         /* NLA Editor - New Strip colors */
1319                         SETCOL(btheme->tnla.strip,                      12, 10, 10, 128); 
1320                         SETCOL(btheme->tnla.strip_select,       255, 140, 0, 255);
1321                 }
1322                 
1323                 /* adjust grease-pencil distances */
1324                 U.gp_manhattendist= 1;
1325                 U.gp_euclideandist= 2;
1326                 
1327                 /* adjust default interpolation for new IPO-curves */
1328                 U.ipo_new= BEZT_IPO_BEZ;
1329         }
1330         
1331         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 1)) {
1332                 bTheme *btheme;
1333
1334                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1335                         
1336                         /* common (new) variables, it checks for alpha==0 */
1337                         ui_theme_init_new(btheme);
1338
1339                         if(btheme->tui.wcol_num.outline[3]==0)
1340                                 ui_widget_color_init(&btheme->tui);
1341                         
1342                         /* Logic editor theme, check for alpha==0 is safe, then color was never set */
1343                         if(btheme->tlogic.syntaxn[3]==0) {
1344                                 /* re-uses syntax color storage */
1345                                 btheme->tlogic= btheme->tv3d;
1346                                 SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
1347                         }
1348
1349                         SETCOLF(btheme->tinfo.back, 0.45, 0.45, 0.45, 1.0);
1350                         SETCOLF(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
1351                 }
1352         }
1353
1354         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 3)) {
1355                 /* new audio system */
1356                 if(U.audiochannels == 0)
1357                         U.audiochannels = 2;
1358                 if(U.audiodevice == 0) {
1359 #ifdef WITH_OPENAL
1360                         U.audiodevice = 2;
1361 #endif
1362 #ifdef WITH_SDL
1363                         U.audiodevice = 1;
1364 #endif
1365                 }
1366                 if(U.audioformat == 0)
1367                         U.audioformat = 0x24;
1368                 if(U.audiorate == 0)
1369                         U.audiorate = 44100;
1370         }
1371
1372         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 5))
1373                 U.gameflags |= USER_DISABLE_VBO;
1374         
1375         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 8)) {
1376                 wmKeyMap *km;
1377                 
1378                 for(km=U.keymaps.first; km; km=km->next) {
1379                         if (strcmp(km->idname, "Armature_Sketch")==0)
1380                                 strcpy(km->idname, "Armature Sketch");
1381                         else if (strcmp(km->idname, "View3D")==0)
1382                                 strcpy(km->idname, "3D View");
1383                         else if (strcmp(km->idname, "View3D Generic")==0)
1384                                 strcpy(km->idname, "3D View Generic");
1385                         else if (strcmp(km->idname, "EditMesh")==0)
1386                                 strcpy(km->idname, "Mesh");
1387                         else if (strcmp(km->idname, "TimeLine")==0)
1388                                 strcpy(km->idname, "Timeline");
1389                         else if (strcmp(km->idname, "UVEdit")==0)
1390                                 strcpy(km->idname, "UV Editor");
1391                         else if (strcmp(km->idname, "Animation_Channels")==0)
1392                                 strcpy(km->idname, "Animation Channels");
1393                         else if (strcmp(km->idname, "GraphEdit Keys")==0)
1394                                 strcpy(km->idname, "Graph Editor");
1395                         else if (strcmp(km->idname, "GraphEdit Generic")==0)
1396                                 strcpy(km->idname, "Graph Editor Generic");
1397                         else if (strcmp(km->idname, "Action_Keys")==0)
1398                                 strcpy(km->idname, "Dopesheet");
1399                         else if (strcmp(km->idname, "NLA Data")==0)
1400                                 strcpy(km->idname, "NLA Editor");
1401                         else if (strcmp(km->idname, "Node Generic")==0)
1402                                 strcpy(km->idname, "Node Editor");
1403                         else if (strcmp(km->idname, "Logic Generic")==0)
1404                                 strcpy(km->idname, "Logic Editor");
1405                         else if (strcmp(km->idname, "File")==0)
1406                                 strcpy(km->idname, "File Browser");
1407                         else if (strcmp(km->idname, "FileMain")==0)
1408                                 strcpy(km->idname, "File Browser Main");
1409                         else if (strcmp(km->idname, "FileButtons")==0)
1410                                 strcpy(km->idname, "File Browser Buttons");
1411                         else if (strcmp(km->idname, "Buttons Generic")==0)
1412                                 strcpy(km->idname, "Property Editor");
1413                 }
1414         }
1415         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 16)) {
1416                 if(U.wmdrawmethod == USER_DRAW_TRIPLE)
1417                         U.wmdrawmethod = USER_DRAW_AUTOMATIC;
1418         }
1419         
1420         if (G.main->versionfile < 252 || (G.main->versionfile == 252 && G.main->subversionfile < 3)) {
1421                 if (U.flag & USER_LMOUSESELECT) 
1422                         U.flag &= ~USER_TWOBUTTONMOUSE;
1423         }
1424         if (G.main->versionfile < 252 || (G.main->versionfile == 252 && G.main->subversionfile < 4)) {
1425                 bTheme *btheme;
1426                 
1427                 /* default new handle type is auto handles */
1428                 U.keyhandles_new = HD_AUTO;
1429                 
1430                 /* init new curve colors */
1431                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1432                         /* init colors used for handles in 3D-View  */
1433                         SETCOL(btheme->tv3d.handle_free, 0, 0, 0, 255);
1434                         SETCOL(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
1435                         SETCOL(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
1436                         SETCOL(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
1437                         SETCOL(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
1438                         SETCOL(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1439                         SETCOL(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1440                         SETCOL(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1441                         SETCOL(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
1442                         
1443                         /* same colors again for Graph Editor... */
1444                         SETCOL(btheme->tipo.handle_free, 0, 0, 0, 255);
1445                         SETCOL(btheme->tipo.handle_auto, 0x90, 0x90, 0x00, 255);
1446                         SETCOL(btheme->tipo.handle_vect, 0x40, 0x90, 0x30, 255);
1447                         SETCOL(btheme->tipo.handle_align, 0x80, 0x30, 0x60, 255);
1448                         SETCOL(btheme->tipo.handle_sel_free, 0, 0, 0, 255);
1449                         SETCOL(btheme->tipo.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1450                         SETCOL(btheme->tipo.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1451                         SETCOL(btheme->tipo.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1452                         
1453                         /* edge crease */
1454                         SETCOLF(btheme->tv3d.edge_crease, 0.8, 0, 0.6, 1.0);
1455                 }
1456         }
1457         if (G.main->versionfile <= 252) {
1458                 bTheme *btheme;
1459
1460                 /* init new curve colors */
1461                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1462                         if (btheme->tv3d.lastsel_point[3] == 0)
1463                                 SETCOL(btheme->tv3d.lastsel_point, 0xff, 0xff, 0xff, 255);
1464                 }
1465         }
1466         if (G.main->versionfile <= 252 || (G.main->versionfile == 252 && G.main->subversionfile < 5)) {
1467                 bTheme *btheme;
1468                 
1469                 /* interface_widgets.c */
1470                 struct uiWidgetColors wcol_progress= {
1471                         {0, 0, 0, 255},
1472                         {190, 190, 190, 255},
1473                         {100, 100, 100, 180},
1474                         {68, 68, 68, 255},
1475                         
1476                         {0, 0, 0, 255},
1477                         {255, 255, 255, 255},
1478                         
1479                         0,
1480                         5, -5
1481                 };
1482                 
1483                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1484                         /* init progress bar theme */
1485                         btheme->tui.wcol_progress= wcol_progress;
1486                 }
1487         }
1488         
1489         /* GL Texture Garbage Collection (variable abused above!) */
1490         if (U.textimeout == 0) {
1491                 U.texcollectrate = 60;
1492                 U.textimeout = 120;
1493         }
1494         if (U.memcachelimit <= 0) {
1495                 U.memcachelimit = 32;
1496         }
1497         if (U.frameserverport == 0) {
1498                 U.frameserverport = 8080;
1499         }
1500         if (U.dbl_click_time == 0) {
1501                 U.dbl_click_time = 350;
1502         }
1503         if (U.anim_player_preset == 0) {
1504                 U.anim_player_preset =1 ;
1505         }
1506         if (U.scrcastfps == 0) {
1507                 U.scrcastfps = 10;
1508                 U.scrcastwait = 50;
1509         }
1510         if (U.v2d_min_gridsize == 0) {
1511                 U.v2d_min_gridsize= 35;
1512         }
1513         
1514         /* Single Column UI Value */
1515         if (U.propwidth == 0) {
1516                 U.propwidth = 200;
1517         }
1518
1519         /* funny name, but it is GE stuff, moves userdef stuff to engine */
1520 // XXX  space_set_commmandline_options();
1521         /* this timer uses U */
1522 // XXX  reset_autosave();
1523
1524 }
1525
1526
1527